Last active
November 23, 2016 14:19
-
-
Save zepinto/7f91463824d29eed69e9 to your computer and use it in GitHub Desktop.
IMC Groovy Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pt.lsts.imc.* | |
import pt.lsts.imc.net.* | |
import pt.lsts.neptus.messages.listener.* | |
// store handle to IMCProtocol globally | |
class Globals { | |
static proto = new IMCProtocol(); | |
} | |
// This method will be called every 5 seconds | |
@Periodic(5000) | |
public void ooops() { | |
println "periodic callback at " + new Date() | |
} | |
// This method will be called whenever a message of type EstimatedMessage comes in | |
@Consume | |
public void on(EstimatedState state) { | |
def src = state.getSourceName() | |
println "got state from $src" | |
// Sending messages to named destinations is simple | |
Globals.proto.sendMessage(src, new Abort()) | |
} | |
// This is required for activating @Consume methods | |
Globals.proto.register(this) | |
// Whenever a new node announces itself, start sending Heartbeats to it | |
Globals.proto.setAutoConnect(".*") | |
// Alternatively if interested to connect to just 1 system: | |
// Globals.proto.connect("lauv-xplore-1") | |
while (true) { | |
// For each connected system... | |
Globals.proto.systems().each { | |
def state = Globals.proto.state(it).last(EstimatedState.class) | |
// If we have received an EstimatedState message | |
if (state) | |
println "$it is at depth $state.depth" | |
} | |
Thread.sleep(3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment