Project

General

Profile

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.

View differences:

branches/autonomous_recharging/code/projects/libwireless/bayboardTest/main.c
5 5
int main(int argc, char** argv)
6 6
{
7 7
	bayboard_init(ALL_ON);
8
	usb_puts("Start.\n");
8
	usb_puts("Start.\n\r");
9 9
	set_orb(0, 0, 200);
10 10
	wl_init();
11
	//wl_set_channel(0xf);
11 12
	set_orb(0, 200, 0);
12
	/*if (wl_token_ring_register() < 0)
13
		usb_puts("Failed to register token ring.\n");
13
	if (wl_token_ring_register() < 0)
14
		usb_puts("Failed to register token ring.\n\r");
14 15
	if (wl_token_ring_join() < 0)
15
		usb_puts("Failed to join token ring.\n");*/
16
	usb_puts("Wireless initialized.\n");
17
	//while (1)
18
	//	wl_do();
16
		usb_puts("Failed to join token ring.\n\r");
17
	usb_puts("Wireless initialized.\n\r");
18
	while (1)
19
		wl_do();
19 20
	return 0;
20 21
}
21 22

  
branches/autonomous_recharging/code/projects/libwireless/bayboardTest/Makefile
14 14
USE_WIRELESS = 1
15 15

  
16 16
# com1 = serial port. Use lpt1 to connect to parallel port.
17
AVRDUDE_PORT = /dev/ttyUSB1
17
AVRDUDE_PORT = COM3
18 18
#
19 19
#
20 20
###################################
......
230 230
# to submit bug reports.
231 231
#AVRDUDE_VERBOSE = -v -v
232 232

  
233
AVRDUDE_FLAGS = -p m164p -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
233
AVRDUDE_FLAGS = -p m164 -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
234 234
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
235 235
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
236 236
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
branches/autonomous_recharging/code/projects/libwireless/lib/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
	}
branches/autonomous_recharging/code/projects/libwireless/lib/sensor_matrix.h
64 64
	 **/
65 65
	int numJoined;
66 66
	/**
67
	 * The matrix. Each row represents the readings of one
68
	 * robot.
69
	 **/
70
	unsigned char matrix[MAXIMUM_XBEE_ID][MAXIMUM_XBEE_ID];
71
	/**
72 67
	 * The element representing a robot is true if that robot
73 68
	 * is in the token ring and false otherwise.
74 69
	 **/
branches/autonomous_recharging/code/projects/libwireless/lib/xbee.c
476 476
		// check if buffer is empty
477 477
		if (buffer_last != buffer_first) {
478 478
			char c = arrival_buf[buffer_first++];
479
			usb_putc(c);
480
			usb_putc('\n');
481 479
			if (buffer_first == XBEE_BUFFER_SIZE) {
482 480
				buffer_first = 0;
483 481
			}
......
736 734
				buffer_first = 0;
737 735
			// check if buffer is empty
738 736
			if (buffer_first == buffer_last) {
739
				return 0;
737
				return -1;
740 738
			}
741 739
		} while (arrival_buf[buffer_first++] != XBEE_FRAME_START);
742 740

  
......
768 766

  
769 767
		// check if buffer is empty
770 768
		if (buffer_first == buffer_last) {
771
			return 0;
769
			return -1;
772 770
		}
773 771
		xbee_buf[currentBufPos++] = arrival_buf[buffer_first++];
774 772
		if (buffer_first == XBEE_BUFFER_SIZE) {
......
778 776

  
779 777
	currentBufPos = 0;
780 778

  
779
	usb_puts("Got packet.\n\r");
781 780
	if (!xbee_verify_checksum(xbee_buf, len + 4))
782 781
	{
782
		usb_puts("Checksum failed.\n\r");
783 783
		WL_DEBUG_PRINT("XBee checksum failed.\r\n");
784 784
		return -1;
785 785
	}
786 786

  
787 787
	//we will take care of the packet
788 788
	if (xbee_handle_packet(xbee_buf + 3, len) != 0) {
789
		return 0;
789
		usb_puts("We handled a packet.\n\r");
790
		return -1;
790 791
	}
791 792

  
792 793
	if (dest == NULL) {
793
		return 0;
794
		usb_puts("dest == NULL");
795
		return -1;
794 796
	}
795 797

  
796 798
	int i;
branches/autonomous_recharging/code/projects/libwireless/lib/sensor_matrix.c
55 55
	for (i = 0; i < MAXIMUM_XBEE_ID; i++)
56 56
	{
57 57
		m.joined[i] = 0;
58
		for (j = 0; j < MAXIMUM_XBEE_ID; j++)
59
			m.matrix[i][j] = READING_UNKNOWN;
60 58
	}
61 59
}
62 60

  
......
69 67
 */
70 68
void sensor_matrix_set_reading(int observer, int robot, int reading)
71 69
{
72
	if (robot >= MAXIMUM_XBEE_ID || observer >= MAXIMUM_XBEE_ID)
73
	{
74
		WL_DEBUG_PRINT("ID too large.");
75
		return;
76
	}
77 70

  
78
	m.matrix[observer][robot] = (unsigned char)reading;
79 71
}
80 72

  
81 73
/**
......
88 80
 **/
89 81
int sensor_matrix_get_reading(int observer, int robot)
90 82
{
91
	if (observer >= MAXIMUM_XBEE_ID || robot >= MAXIMUM_XBEE_ID)
92
		return -1;
93

  
94
	return (int)m.matrix[observer][robot];
83
	return -1;
95 84
}
96 85

  
97 86
/**
......
104 93
{
105 94
	if (robot >= MAXIMUM_XBEE_ID)
106 95
	{
96
		usb_puts("ID too large.\n\r");
107 97
		WL_DEBUG_PRINT("ID too large.");
108 98
		return;
109 99
	}
branches/autonomous_recharging/code/projects/libwireless/lib/wireless.c
115 115
#ifdef FIREFLY
116 116
	rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
117 117
#else
118
	rtc_init(HALF_SECOND, &timer_handler);
118
	//TODO: FIX THIS
119
	rtc_init(10 * HALF_SECOND, &timer_handler);
119 120
#endif
120 121
#else
121 122

  
......
428 429
	}
429 430
	else if (wl_buf[0] == XBEE_RX)
430 431
	{
432
		usb_puti(len);
433
		usb_puts("Got packet!\n\r");
431 434
    //TODO: what does this 7 represent?  It shouldn't be hardcoded.  It should be set as a define
432 435
		if (len < 7)
433 436
		{

Also available in: Unified diff