Project

General

Profile

Revision 166

Recharging now works, wireless has been updated.

View differences:

trunk/code/lib/include/libwireless/wl_defs.h
22 22
#define WL_TOKEN_JOIN_ACCEPT 6
23 23

  
24 24
// timing constants
25
#ifndef FIREFLY
25 26
#define BOM_DELAY 100
27
#else
28
#define BOM_DELAY 200
29
#endif
30

  
26 31
#define DEATH_DELAY 4
27 32
#define JOIN_DELAY 8
28 33

  
trunk/code/lib/src/libwireless/wl_token_ring.c
585 585
	if (!sensor_matrix_get_in_ring(sensorMatrix, wl_get_xbee_id()))
586 586
	{
587 587
		WL_DEBUG_PRINT("Removed from sensor matrix while flashing BOM.\r\n");
588
		return;
588 589
	}
589 590
	
590 591
	wl_token_pass_token();
trunk/code/lib/src/libwireless/wireless.c
50 50
	}
51 51
	return;
52 52
}
53
#else
54

  
55
//called when the timer ticks
56
void timer_handler(void)
57
{
58
	wl_timeout = 1;
59
}
60

  
53 61
#endif
54 62

  
55 63
/**
......
67 75
	//begin timeout timer
68 76
	#ifdef ROBOT
69 77
	#ifdef FIREFLY
70
	rtc_init(PRESCALE_DIV_128, 32, &wl_do_timeout);
78
	rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
71 79
	#else
72
	rtc_init(HALF_SECOND, &wl_do_timeout); 
80
	rtc_init(HALF_SECOND, &timer_handler); 
73 81
	#endif
74 82
	#else
75 83
  
trunk/code/projects/libwireless/test/test.c
31 31
					0);
32 32
	}
33 33
	xbee_terminate();*/
34
	printf("Beginning.\n");
34 35
	wl_init();
35 36
	printf("Wireless initialized.\n");
36 37
	wl_error_register();
trunk/code/projects/libwireless/lib/wl_token_ring.c
585 585
	if (!sensor_matrix_get_in_ring(sensorMatrix, wl_get_xbee_id()))
586 586
	{
587 587
		WL_DEBUG_PRINT("Removed from sensor matrix while flashing BOM.\r\n");
588
		return;
588 589
	}
589 590
	
590 591
	wl_token_pass_token();
trunk/code/projects/libwireless/lib/wl_defs.h
5 5
//#define ROBOT
6 6

  
7 7
//uncomment this line for debug information
8
//#define WL_DEBUG
8
#define WL_DEBUG
9 9

  
10 10
// Packet Groups and Types
11 11

  
......
25 25
#define WL_TOKEN_JOIN_ACCEPT 6
26 26

  
27 27
// timing constants
28
#ifndef FIREFLY
28 29
#define BOM_DELAY 100
30
#else
31
#define BOM_DELAY 200
32
#endif
33

  
29 34
#define DEATH_DELAY 4
30 35
#define JOIN_DELAY 8
31 36

  
trunk/code/projects/libwireless/lib/wireless.c
50 50
	}
51 51
	return;
52 52
}
53
#else
54

  
55
//called when the timer ticks
56
void timer_handler(void)
57
{
58
	wl_timeout = 1;
59
}
60

  
53 61
#endif
54 62

  
55 63
/**
......
67 75
	//begin timeout timer
68 76
	#ifdef ROBOT
69 77
	#ifdef FIREFLY
70
	rtc_init(PRESCALE_DIV_128, 32, &wl_do_timeout);
78
	rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
71 79
	#else
72
	rtc_init(HALF_SECOND, &wl_do_timeout); 
80
	rtc_init(HALF_SECOND, &timer_handler); 
73 81
	#endif
74 82
	#else
75 83
  
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/xbee.c
144 144
	#endif
145 145
	sei();
146 146
	#else
147
	xbee_stream = open("/dev/ttyUSB0", O_RDWR);
147
	xbee_stream = open(XBEE_PORT, O_RDWR);
148 148
	if (xbee_stream == -1 || lockf(xbee_stream, F_TEST, 0) != 0)
149
		xbee_stream = open("/dev/ttyUSB1", O_RDWR);
149
		xbee_stream = open(XBEE_PORT2, O_RDWR);
150 150
	if (xbee_stream == -1 || lockf(xbee_stream, F_TEST, 0) != 0)
151 151
	{
152 152
		printf("Failed to open connection to XBee.\r\n");
......
165 165
		exit(0);
166 166
	}
167 167
	#endif
168
	usb_puts("Entering command mode.\n");
169 168
	xbee_enter_command_mode();
170
	usb_puts("Entered command mode.\n");
171 169
	xbee_enter_api_mode();
172 170
	xbee_exit_command_mode();
173 171
	xbee_send_read_at_command("MY");
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/xbee.h
11 11
 **/
12 12

  
13 13
/**
14
 * The port to use the XBee from on the computer.
15
 * Also, a backup port if the other is used.
16
 **/
17
#ifndef ROBOT
18
#ifndef XBEE_PORT
19
#define XBEE_PORT "/dev/ttyUSB0"
20
#endif
21
#define XBEE_PORT2 "/dev/tty/USB1"
22
#endif
23

  
24
/**
14 25
 * @defgroup xbee XBee
15 26
 * @brief Interface with the XBee module
16 27
 *
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_token_ring.c
346 346
	int i, j;
347 347
	deathDelay = -1;
348 348

  
349
	WL_DEBUG_PRINT("Received the token, next robot is ");
349
	WL_DEBUG_PRINT("Received the token from robot");
350
	WL_DEBUG_PRINT_INT(source);
351
	WL_DEBUG_PRINT(", next robot is ");
350 352
	WL_DEBUG_PRINT_INT((int)nextRobot);
351 353
	WL_DEBUG_PRINT(" \r\n");
352 354
	sensor_matrix_set_in_ring(sensorMatrix, source, 1);
......
516 518
	WL_DEBUG_PRINT("Robot ");
517 519
	WL_DEBUG_PRINT_INT(source);
518 520
	WL_DEBUG_PRINT(" has flashed its bom.\r\n");
521

  
522
	//make sure we don't declare the robot dead if it's
523
	//flashing its BOM
524
	if (source == wl_token_next_robot)
525
		deathDelay = DEATH_DELAY;
519 526
	sensor_matrix_set_reading(sensorMatrix, wl_get_xbee_id(), 
520 527
		source, get_max_bom_function());
521 528
}
......
578 585
	if (!sensor_matrix_get_in_ring(sensorMatrix, wl_get_xbee_id()))
579 586
	{
580 587
		WL_DEBUG_PRINT("Removed from sensor matrix while flashing BOM.\r\n");
588
		return;
581 589
	}
582 590
	
583 591
	wl_token_pass_token();
......
752 760
		i++;
753 761
	if (i == sensor_matrix_get_size(sensorMatrix))
754 762
		i = -1;
763
	iteratorCount = i;
755 764
}
756 765

  
757 766
/**
......
765 774
 **/
766 775
int wl_token_iterator_has_next(void)
767 776
{
768
	return iteratorCount == -1;
777
	return iteratorCount != -1;
769 778
}
770 779

  
771 780
/**
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/queue.c
24 24
Queue* queue_create()
25 25
{
26 26
	Queue* q = (Queue*)malloc(sizeof(Queue));
27
	
28
	if (q == NULL)
29
	{
30
		WL_DEBUG_PRINT("Out of memory.\r\n");
31
		return NULL;
32
	}
33
	
27 34
	q->head = NULL;
28 35
	q->size = 0;
29 36
	return q;
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_defs.h
22 22
#define WL_TOKEN_JOIN_ACCEPT 6
23 23

  
24 24
// timing constants
25
#ifndef FIREFLY
26
#define BOM_DELAY 100
27
#else
25 28
#define BOM_DELAY 200
26
#define DEATH_DELAY 5
29
#endif
30

  
31
#define DEATH_DELAY 4
27 32
#define JOIN_DELAY 8
28 33

  
29 34
// Recharging group
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wireless.c
6 6
#include "wl_defs.h"
7 7

  
8 8
#ifndef ROBOT
9
#include <time.h>
9
#include <sys/time.h>
10 10
#include <signal.h>
11 11
#else
12 12
#include <time.h>
......
34 34
PacketGroupHandler* wl_packet_groups[WL_MAX_PACKET_GROUPS];
35 35

  
36 36
#ifndef ROBOT
37
timer_t wl_timeout_timer;
38 37

  
39 38
//called when we time out, or receive interrupt
40 39
void sig_handler(int signo)
......
51 50
	}
52 51
	return;
53 52
}
53
#else
54

  
55
//called when the timer ticks
56
void timer_handler(void)
57
{
58
	wl_timeout = 1;
59
}
60

  
54 61
#endif
55 62

  
56 63
/**
......
68 75
	//begin timeout timer
69 76
	#ifdef ROBOT
70 77
	#ifdef FIREFLY
71
	rtc_init(PRESCALE_DIV_256, 32, &wl_do_timeout);
78
	rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
72 79
	#else
73
	rtc_init(HALF_SECOND, &wl_do_timeout); 
80
	rtc_init(HALF_SECOND, &timer_handler); 
74 81
	#endif
75 82
	#else
76
	//create a timer to trigger every half second
77
	struct sigevent evp;
78
	evp.sigev_signo = SIGALRM;
79
	evp.sigev_notify = SIGEV_SIGNAL;
80
	if (timer_create(CLOCK_REALTIME, &evp, &wl_timeout_timer) == -1)
81
	{ 
83
  
84
	//create our timer
85
	struct itimerval timer_val;
86
	struct timeval interval;
87
	interval.tv_sec = 0;
88
	interval.tv_usec = 500000;
89
	struct timeval first_time;
90
	first_time.tv_sec = 0;
91
	first_time.tv_usec = 500000;
92
	timer_val.it_interval = interval;
93
	timer_val.it_value = first_time;
94
	if(setitimer(ITIMER_REAL,&timer_val,NULL)==-1)
95
	{
82 96
		WL_DEBUG_PRINT("Error creating a timer.\r\n"); 
97
		perror("Failure's cause");
83 98
		exit(1); 
84 99
	}
100

  
101
	//create signal handler
85 102
	struct sigaction wl_sig_act;
86 103
	wl_sig_act.sa_handler = (void *)sig_handler;
87 104
	wl_sig_act.sa_flags = 0;
88 105
	sigemptyset(&wl_sig_act.sa_mask);
89 106
	sigaction(SIGALRM, &wl_sig_act, 0);
90 107
	sigaction(SIGINT, &wl_sig_act, 0);
91
	struct itimerspec wl_timeout_time;
92
	wl_timeout_time.it_interval.tv_sec = 0;
93
	wl_timeout_time.it_interval.tv_nsec = 500000000;
94
	wl_timeout_time.it_value.tv_sec = 0;
95
	wl_timeout_time.it_value.tv_nsec = 500000000;
96
	timer_settime(wl_timeout_timer, 0,
97
                        &wl_timeout_time, NULL);
98 108
	#endif
99 109
}
100 110

  
......
103 113
 **/
104 114
void wl_terminate()
105 115
{
106
	#ifndef ROBOT
107
	timer_delete(wl_timeout_timer);
108
	#endif
109
	
110 116
	int i;
111 117
	for (i = 0; i < WL_MAX_PACKET_GROUPS; i++)
112 118
		if (wl_packet_groups[i] != NULL &&
......
350 356
		{
351 357
			WL_DEBUG_PRINT("No response received.\r\n");
352 358
			if (wl_buf[2] == 2)
359
			{
353 360
				WL_DEBUG_PRINT("CCA Failure\r\n");
361
			}
354 362
			if (wl_buf[2] == 3)
363
			{
355 364
				WL_DEBUG_PRINT("Purged\r\n");
365
			}
356 366
		}
357 367
		
358 368
		if (wl_packet_groups[group] != NULL &&
......
390 400
		return;
391 401
	}
392 402
	
393
	usb_puts("Unexpected packet received.\n");
394
	//WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n");
403
	WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n");
395 404
	return;
396 405
}
397 406

  

Also available in: Unified diff