Skip to content

Instantly share code, notes, and snippets.

@dschanoeh
Created April 30, 2011 14:11
Show Gist options
  • Save dschanoeh/949696 to your computer and use it in GitHub Desktop.
Save dschanoeh/949696 to your computer and use it in GitHub Desktop.
public class KayakLibraryTest {
/* FrameReceiver that will print out every Frame it receives */
private static FrameReceiver receiver = new FrameReceiver() {
public void newFrame(Frame frame) {
System.out.println(frame.toLogFileNotation());
}
};
public static void main( String[] args ) {
BusURL url = new BusURL("127.0.0.1", 28600, "vcan0"); /* Connection to the socketcand */
TimeSource timeSource = new TimeSource(); /* TimeSource to control the bus */
/* Create a bus and configure it */
Bus bus = new Bus();
bus.setConnection(url);
bus.setTimeSource(timeSource);
/* A Subscription is the link between a Bus and a FrameReceiver.
* We are only interested in ID 0x12. The Subscription manages that
* only Frames with this ID get delivered.
*/
Subscription subscription = new Subscription(receiver, bus);
subscription.subscribe(0x12);
/* Starting the TimeSource will make the Bus connect to the socketcand
* and deliver Frames. After two seconds the connections are terminated.
*/
timeSource.play();
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {}
timeSource.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment