root / trunk / code / projects / libwireless / jni / lib / org / roboticsclub / colony / Wireless.java @ 940
History | View | Annotate | Download (2.24 KB)
1 |
package org.roboticsclub.colony; |
---|---|
2 |
|
3 |
import java.util.Timer; |
4 |
import java.util.TimerTask; |
5 |
|
6 |
public class Wireless |
7 |
{ |
8 |
public static native int wl_init(); |
9 |
public static native void wl_terminate(); |
10 |
public static native void wl_do(); |
11 |
public static native void wl_register_packet_group(PacketGroupHandler pgh); |
12 |
public static native void wl_unregister_packet_group(PacketGroupHandler pgh); |
13 |
public static native int wl_send_robot_to_robot_global_packet(byte group, byte type, byte[] data, int dest, byte frame); |
14 |
public static native int wl_send_robot_to_robot_packet(byte group, byte type, byte[] data, int dest, byte frame); |
15 |
public static native int wl_send_global_packet(byte group, byte type, byte[] data, byte frame); |
16 |
public static native void wl_send_pan_packet(byte group, byte type, byte[] data, byte frame); |
17 |
public static native int wl_set_pan(int pan); |
18 |
public static native int wl_get_pan(); |
19 |
public static native int wl_set_channel(int channel); |
20 |
public static native int wl_get_channel(); |
21 |
public static native int wl_get_xbee_id(); |
22 |
public static native void wl_set_com_port(String port); |
23 |
|
24 |
public static TimerTask wireless_thread; |
25 |
|
26 |
public static void startWirelessThread(int rate) |
27 |
{ |
28 |
if (wireless_thread==null) |
29 |
{ |
30 |
wireless_thread = new TimerTask() { |
31 |
public void run() |
32 |
{ |
33 |
wl_do(); |
34 |
} |
35 |
}; |
36 |
} |
37 |
|
38 |
new Timer("Colony Wireless Monitor", true).scheduleAtFixedRate(wireless_thread, 0, rate); |
39 |
} |
40 |
|
41 |
static
|
42 |
{ |
43 |
Runtime.getRuntime().addShutdownHook(new Thread() { |
44 |
public void run() |
45 |
{ |
46 |
wl_terminate(); |
47 |
System.out.println("Wireless terminated"); |
48 |
} |
49 |
}); |
50 |
} |
51 |
|
52 |
static
|
53 |
{ |
54 |
System.loadLibrary("jniwireless"); |
55 |
} |
56 |
|
57 |
public static interface PacketGroupHandler |
58 |
{ |
59 |
public abstract int getGroupCode(); |
60 |
public abstract void timeout_handler(); |
61 |
public abstract void handle_response(int frame, int received); |
62 |
public abstract void handle_received(byte type, int source, byte[] packet); |
63 |
public abstract void unregister(); |
64 |
} |
65 |
} |