Skip to content

Instantly share code, notes, and snippets.

@zepinto
Last active November 23, 2016 14:19
Show Gist options
  • Save zepinto/7f91463824d29eed69e9 to your computer and use it in GitHub Desktop.
Save zepinto/7f91463824d29eed69e9 to your computer and use it in GitHub Desktop.
IMC Groovy Example
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