root / trunk / code / projects / diagnostic_station / robot / main.c @ 1159
History | View | Annotate | Download (1.75 KB)
1 |
#include <dragonfly_lib.h> |
---|---|
2 |
#include <wireless.h> |
3 |
#include <xbee.h> |
4 |
|
5 |
#include "../common/comm_station_robot.h" |
6 |
|
7 |
static void message_set_orbs (int length, uint8_t *data) |
8 |
{ |
9 |
if (length>=6) |
10 |
{ |
11 |
orbs_set (data[0], data[1], data[2], data[3], data[4], data[5]); |
12 |
} |
13 |
} |
14 |
|
15 |
static void message_set_motors (int length, uint8_t *data) |
16 |
{ |
17 |
if (length>=4) |
18 |
{ |
19 |
motor1_set (data[0], data[1]); |
20 |
motor2_set (data[2], data[3]); |
21 |
} |
22 |
} |
23 |
|
24 |
static void message_set_bom (int length, uint8_t *data) |
25 |
{ |
26 |
// TODO test
|
27 |
if (length>=2) |
28 |
{ |
29 |
uint16_t bitmask=WORD(data[0], data[1]); |
30 |
|
31 |
bom_set_leds (bitmask); |
32 |
|
33 |
if (bitmask==0) |
34 |
bom_off (); |
35 |
else
|
36 |
bom_on (); |
37 |
} |
38 |
} |
39 |
|
40 |
void station_robot_receive(char type, int source, unsigned char* packet, int length) |
41 |
{ |
42 |
switch (type)
|
43 |
{ |
44 |
case station_robot_set_orbs: message_set_orbs (length, packet); break; |
45 |
case station_robot_set_motors: message_set_motors (length, packet); break; |
46 |
case station_robot_set_bom: message_set_bom (length, packet); break; |
47 |
// TODO default: error message, red orbs, pause. Test!
|
48 |
// TODO: error signal in the individual handlers if the number of parameters is too low. Test!
|
49 |
} |
50 |
} |
51 |
|
52 |
|
53 |
int main(void) { |
54 |
dragonfly_init(ALL_ON); |
55 |
|
56 |
usb_init (); |
57 |
usb_puts ("Diagnostic station robot starting up\r\n");
|
58 |
|
59 |
orb_init_pwm (); |
60 |
xbee_init (); |
61 |
|
62 |
orb1_set (255, 127, 0); |
63 |
wl_init(); |
64 |
orb2_set (255, 127, 0); |
65 |
|
66 |
//usb_puts ("PAN ID: "); usb_puti (xbee_get_pan_id ()); usb_puts ("\r\n"); // -1
|
67 |
//usb_puts ("Channel: "); usb_puti (xbee_get_channel ()); usb_puts ("\r\n"); // 0
|
68 |
//usb_puts ("Address: "); usb_puti (xbee_get_address ()); usb_puts ("\r\n"); // 4/8
|
69 |
|
70 |
PacketGroupHandler receive_handler = {station_robot_group, NULL, NULL, &station_robot_receive, NULL}; |
71 |
wl_register_packet_group(&receive_handler); |
72 |
|
73 |
while (1) |
74 |
{ |
75 |
wl_do(); |
76 |
} |
77 |
} |