Skip to content

Instantly share code, notes, and snippets.

@dschanoeh
Created October 10, 2011 13:00
Show Gist options
  • Save dschanoeh/1275255 to your computer and use it in GitHub Desktop.
Save dschanoeh/1275255 to your computer and use it in GitHub Desktop.
EchoService
public class EchoService {
/* Configuration settings */
private static final String HOST = "192.168.0.21";
private static final int PORT = 28602;
private static final String BUS = "vcan0";
private static final int REQUEST_ID = 0x12;
private static final int RESPONSE_ID = 0x13;
private static Bus bus = new Bus();
/*
* This FrameReceiver gets notified about incoming frames and sends
* a response.
*/
private static FrameReceiver receiver = new FrameReceiver() {
private final Frame response = new Frame(RESPONSE_ID, new byte[] {0x11});
public void newFrame(Frame frame) {
if(frame.getIdentifier() == REQUEST_ID) {
response.setData(frame.getData());
bus.sendFrame(response);
}
}
};
public static void main( String[] args ) throws InterruptedException {
/* Create a bus and connect all components */
BusURL url = new BusURL(HOST, PORT, BUS);
TimeSource ts = new TimeSource();
bus.setConnection(url);
bus.setTimeSource(ts);
/* Only receive frames with the REQUEST_ID */
Subscription s = new Subscription(receiver, bus);
s.subscribe(REQUEST_ID);
ts.play(); /* Start simulation time and open connections */
while(true) /* Infinite loop */
Thread.sleep(1000000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment