Page 1 of 2

NXC: Keep Alive

Posted: 18 Aug 2011, 01:57
by fuzzball27
How does the Keep Alive function work in NXC? I looked it up in the .defs and poked around with it, but I couldn't figure it out. :?

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 03:46
by mattallen37
I don't know, but I am guessing it has to do with the shutoff timer that the NXT uses. Normally if you don't use the NXT for a set amount of time (10 minutes for example), then it shuts off. Pressing the buttons seems to reset the 10 minute timer, and probably that command does the same thing.

BTW, it is by no means limited to just a 10 minute timer with Lego FW.

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 03:57
by linusa
Yep, exactly what mattallen37 said!

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 12:57
by fuzzball27
Alright so I'm guessing if I did something like this would it do the job:

Code: Select all

task main () {
    while(true) {
        KeepAlive();
        Wait(10*6000);
    }
}
I wonder if receiving Remote BT firmware commands still works? (eg. Master sends "RemoteSetOutputState" to brick running "KeepAlive" Function.)

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 13:00
by fuzzball27
Never mind! I found a better way to do it in the .defs "RemoteKeepAlive" :D
But I'm getting a strange error...
Here's my code segment:

Code: Select all

while (true) {
	Wait(6000*5)
	Acquire (BT_Mutex);
	RemoteKeepAlive(CONN_BT0);
	Release (BT_Mutex);
}
Here's the error:

Code: Select all

#Error: Preprocessor macro function does not match instance (__connectionSCDCWrite(_conn,__DCKeepAlivePacket,_result))

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 14:32
by linusa
fuzzball27 wrote: I wonder if receiving Remote BT firmware commands still works? (eg. Master sends "RemoteSetOutputState" to brick running "KeepAlive" Function.)
If by "remote BT firmware commands" you mean the "direct commands", then yes: This still works while RXE programs (produced by e.g. NXC or NXT-G) are running. This is true for all direct commands. And from my tests, the direct commands don't even afffect the running RXE's performance...


Btw, you don't really need the keep alive if you set the NXT's sleep timer / auto off to "never", then it stays always on...

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 14:44
by h-g-t
I think that if you set the sleep timer value to 0 within the NXC program it never goes off.

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 15:42
by afanofosc
fuzzball27 wrote:

Code: Select all

#Error: Preprocessor macro function does not match instance (__connectionSCDCWrite(_conn,__DCKeepAlivePacket,_result))
I believe that this has been fixed in one of the more recently posted test releases. The fix will be in the next official release as well. Once I get my boolean expression code generation up to par I should be about ready for an official release.

John Hansen

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 15:48
by afanofosc
fuzzball27 wrote:How does the Keep Alive function work in NXC? I looked it up in the .defs and poked around with it, but I couldn't figure it out. :?
If you want to have an NXC program keep *this* brick awake regardless of its user-configured sleep timer value then you have your program call ResetSleepTimer() periodically (i.e., in a loop that executes throughout the lifespan of your program's execution). Or you can call SysKeepAlive. See the help for these two functions.

If you want to have an NXC program keep some other brick awake by sending it a direct command (KeepAlive) via Bluetooth then you have your program call RemoteKeepAlive. You do not use RemoteKeepAlive to keep *this* brick awake.

John Hansen

Re: NXC: Keep Alive

Posted: 18 Aug 2011, 19:30
by fuzzball27
If you want to have an NXC program keep *this* brick awake regardless of its user-configured sleep timer...
My intention was to Keep a Separate brick alive.