Revision 883
Wireless for bayboard sort of works. I still left in all my debugging information though, and it doesn't seem to work quite as well as the other two. Some more work is needed.
wl_token_ring.c | ||
---|---|---|
232 | 232 |
**/ |
233 | 233 |
static void wl_token_ring_timeout_handler() |
234 | 234 |
{ |
235 |
usb_putc('t'); |
|
235 | 236 |
//someone is not responding, assume they are dead |
236 | 237 |
if (deathDelay == 0) |
237 | 238 |
{ |
... | ... | |
239 | 240 |
//also, declare that person dead, as long as it isn't us |
240 | 241 |
if (wl_token_next_robot != wl_get_xbee_id()) |
241 | 242 |
{ |
243 |
usb_puts("Death.\n\r"); |
|
244 |
usb_puti(wl_token_next_robot); |
|
245 |
usb_puts("\n\r"); |
|
242 | 246 |
sensor_matrix_set_in_ring(wl_token_next_robot, 0); |
243 | 247 |
WL_DEBUG_PRINT("Robot "); |
244 | 248 |
WL_DEBUG_PRINT_INT(wl_token_next_robot); |
... | ... | |
258 | 262 |
{ |
259 | 263 |
if (sensor_matrix_get_joined() == 0) |
260 | 264 |
{ |
265 |
usb_puts("Gave up.\n\r"); |
|
261 | 266 |
WL_DEBUG_PRINT("Creating our own token ring, no robots seem to exist.\r\n"); |
262 | 267 |
sensor_matrix_set_in_ring(wl_get_xbee_id(), 1); |
263 | 268 |
ringState = MEMBER; |
... | ... | |
314 | 319 |
switch (type) |
315 | 320 |
{ |
316 | 321 |
case WL_TOKEN_PASS: |
322 |
usb_puts("Got token.\n\r"); |
|
317 | 323 |
wl_token_pass_receive(source); |
318 | 324 |
break; |
319 | 325 |
case WL_TOKEN_SENSOR_MATRIX: |
326 |
usb_puts("Got sensor matrix.\n\r"); |
|
320 | 327 |
wl_token_sensor_matrix_receive(source, packet, length); |
321 | 328 |
break; |
322 | 329 |
case WL_TOKEN_BOM_ON: |
330 |
usb_puts("Got BOM on.\n\r"); |
|
323 | 331 |
//add the robot to the sensor matrix if it is not already there |
324 | 332 |
wl_token_bom_on_receive(source); |
325 | 333 |
break; |
326 | 334 |
case WL_TOKEN_JOIN: |
335 |
usb_puts("Got join request.\n\r"); |
|
327 | 336 |
wl_token_join_receive(source); |
328 | 337 |
break; |
329 | 338 |
case WL_TOKEN_JOIN_ACCEPT: |
339 |
usb_puts("Got join accept.\n\r"); |
|
330 | 340 |
wl_token_join_accept_receive(source); |
331 | 341 |
break; |
332 | 342 |
default: |
... | ... | |
505 | 515 |
WL_DEBUG_PRINT_INT(wl_token_next_robot); |
506 | 516 |
WL_DEBUG_PRINT(".\n"); |
507 | 517 |
// this prevents two tokens from being passed around at a time (second clause is in case we are joining) |
518 |
usb_puti(source); usb_putc(' '); usb_puti(wl_token_next_robot); usb_putc(' '); usb_puti(wl_get_xbee_id()); |
|
519 |
usb_putc(' '); usb_puti(bom_on_count); usb_putc(' '); usb_puti(ringState); usb_putc(' '); usb_puts("\n\r"); |
|
508 | 520 |
if ((source != wl_token_next_robot && wl_get_xbee_id() != wl_token_next_robot) && bom_on_count <= DEATH_DELAY / 2 && |
509 | 521 |
ringState != ACCEPTED) |
510 | 522 |
{ |
... | ... | |
693 | 705 |
} |
694 | 706 |
else |
695 | 707 |
{ |
708 |
usb_puts("Accepting.\n\r"); |
|
696 | 709 |
WL_DEBUG_PRINT("Accepting new robot, sending it the token.\r\n"); |
697 | 710 |
//add a new robot to the token ring |
698 | 711 |
sensor_matrix_set_in_ring(accepted, 1); |
... | ... | |
711 | 724 |
buf[2*j] = i; |
712 | 725 |
buf[2*j + 1] = sensor_matrix_get_reading(wl_get_xbee_id(), i); |
713 | 726 |
j++; |
727 |
usb_puti(i); |
|
728 |
usb_puts("\n\r"); |
|
714 | 729 |
} |
715 | 730 |
} |
716 |
|
|
731 |
usb_puts("\n\r"); |
|
717 | 732 |
int packetSize = 2 * j * sizeof(char); |
718 | 733 |
WL_DEBUG_PRINT("Passing the token to robot "); |
719 | 734 |
WL_DEBUG_PRINT_INT(nextRobot); |
720 | 735 |
WL_DEBUG_PRINT(".\r\n"); |
736 |
usb_puts("Passing token "); |
|
737 |
usb_puti(nextRobot); |
|
738 |
usb_puts("\n\r"); |
|
721 | 739 |
if (wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_SENSOR_MATRIX, buf, packetSize, 0) != 0) |
722 | 740 |
return -1; |
723 | 741 |
if (wl_send_robot_to_robot_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_PASS, NULL, 0, nextRobot, WL_TOKEN_PASS_FRAME)) |
724 | 742 |
return -1; |
725 | 743 |
|
726 | 744 |
wl_token_next_robot = nextRobot; |
745 |
usb_puti(nextRobot); |
|
727 | 746 |
deathDelay = DEATH_DELAY; |
728 | 747 |
|
729 | 748 |
return 0; |
... | ... | |
779 | 798 |
WL_DEBUG_PRINT("Our BOM has been flashed.\r\n"); |
780 | 799 |
wl_send_global_packet(WL_TOKEN_RING_GROUP, WL_TOKEN_BOM_ON, NULL, 0, 0); |
781 | 800 |
|
782 |
bom_on_function(); |
|
783 |
#ifdef ROBOT |
|
801 |
//bom_on_function(); |
|
802 |
//#ifdef ROBOT |
|
803 |
usb_puts("BOM ON!\n\r"); |
|
784 | 804 |
delay_ms(BOM_DELAY); |
785 |
#endif |
|
786 |
bom_off_function(); |
|
805 |
usb_puts("BOM OFF!\n\r"); |
|
806 |
//#endif |
|
807 |
//bom_off_function(); |
|
787 | 808 |
|
788 | 809 |
if (!sensor_matrix_get_in_ring(wl_get_xbee_id())) |
789 | 810 |
{ |
811 |
usb_puts("FAIL\n\r"); |
|
790 | 812 |
WL_DEBUG_PRINT("Removed from sensor matrix while flashing BOM.\r\n"); |
791 | 813 |
return; |
792 | 814 |
} |
Also available in: Unified diff