Project

General

Profile

Revision 1658

wireless: fixed debug statements and flash memory

View differences:

test_wireless2.c
1
#include <stdlib.h>
2
#include <stdio.h>
1
#include <wl_defs.h>
3 2
#include <string.h>
4 3
#include <wireless.h>
5 4
#include <lights.h>
6 5
#include <dragonfly_lib.h>
7 6
#include <xbee.h>
8
#include <avr/pgmspace.h>
9 7

  
8

  
10 9
void group_1_function(uint8_t* data,uint8_t length,uint8_t source);
11 10
void group_2_function(uint8_t* data,uint8_t length,uint8_t source);
12 11
void group_3_function(uint8_t* data,uint8_t length,uint8_t source);
......
26 25
	usb_init();
27 26
	int status = 0;
28 27

  
29
	usb_puts("New Wireless Library Test Suite\r\n");
28
	WL_DEBUG_PRINT_P("New Wireless Library Test Suite\r\n");
30 29
		
31 30
	/*Initialize the wirelss library*/
32
	usb_puts("Initializing library...\r\n");
31
	WL_DEBUG_PRINT_P("Initializing library...\r\n");
33 32
	orb1_set_color(BLUE);
34 33
	status = wl_init();
35 34
	switch(status){
36 35
		case 0:
37
			usb_puts("Library initialization successful\r\n\r\n");
36
			WL_DEBUG_PRINT_P("Library initialization successful\r\n\r\n");
38 37
			orb1_set_color(GREEN);
39 38
			break;
40 39
		case -1:
41
			usb_puts("Initialization failed: already initialized\r\n\r\n");
40
			WL_DEBUG_PRINT_P("Initialization failed: already initialized\r\n\r\n");
42 41
			orb1_set_color(GREEN);
43 42
			break;
44 43
		case -2:
45
			usb_puts("Initialization failed: XBEE initialization failed\r\n\r\n");
44
			WL_DEBUG_PRINT_P("Initialization failed: XBEE initialization failed\r\n\r\n");
46 45
			orb1_set_color(RED);
47 46
			break;
48 47
		default:
49
			usb_puts("Error: Unreconnized status code: ");
48
			WL_DEBUG_PRINT_P("Error: Unreconnized status code: ");
50 49
			usb_puti(status);
51
			usb_puts("\r\n\r\n");
50
			WL_DEBUG_PRINT_P("\r\n\r\n");
52 51
			orb1_set_color(RED);
53 52
			break;
54 53
	}
......
56 55

  
57 56
	/*Test all constants defined correctly*/
58 57
	status = 0;
59
	usb_puts("Testing constants...");
58
	WL_DEBUG_PRINT_P("Testing constants...");
60 59
	orb2_set_color(GREEN);
61 60
	if(GLOBAL!=0){
62
		usb_puts("\r\nGLOBAL defined as ");
61
		WL_DEBUG_PRINT_P("\r\nGLOBAL defined as ");
63 62
		usb_puti(GLOBAL);
64 63
		status++;
65 64
	}
66
	usb_puts(".");
65
	WL_DEBUG_PRINT_P(".");
67 66
	if(PAN!=1){
68
		usb_puts("\r\nPAN defined as ");
67
		WL_DEBUG_PRINT_P("\r\nPAN defined as ");
69 68
		usb_puti(PAN);
70 69
		status++;
71 70
	}
72
	usb_puts(".");
71
	WL_DEBUG_PRINT_P(".");
73 72
	if(BROADCAST!=0xFFFF){
74
		usb_puts("\r\nBROADCAST defined as ");
73
		WL_DEBUG_PRINT_P("\r\nBROADCAST defined as ");
75 74
		usb_puti(BROADCAST);
76 75
		status++;
77 76
	}
78
	usb_puts(".");
77
	WL_DEBUG_PRINT_P(".");
79 78
	if(RELIABLE!=0){
80
		usb_puts("\r\nRELIABLE defined as ");
79
		WL_DEBUG_PRINT_P("\r\nRELIABLE defined as ");
81 80
		usb_puti(RELIABLE);
82 81
		status++;
83 82
	}
84
	usb_puts(".");
83
	WL_DEBUG_PRINT_P(".");
85 84
	if(FAST!=1){
86
		usb_puts("\r\nFAST defined as ");
85
		WL_DEBUG_PRINT_P("\r\nFAST defined as ");
87 86
		usb_puti(FAST);
88 87
		status++;
89 88
	}
90
	usb_puts(".");
89
	WL_DEBUG_PRINT_P(".");
91 90
	if(NORMAL_PRIORITY!=0){
92
		usb_puts("\r\nNORMAL_PRIORITY defined as ");
91
		WL_DEBUG_PRINT_P("\r\nNORMAL_PRIORITY defined as ");
93 92
		usb_puti(NORMAL_PRIORITY);
94 93
		status++;
95 94
	}
96
	usb_puts(".");
95
	WL_DEBUG_PRINT_P(".");
97 96
	if(HIGH_PRIORITY!=1){
98
		usb_puts("\r\nHIGH_PRIORITY defined as ");
97
		WL_DEBUG_PRINT_P("\r\nHIGH_PRIORITY defined as ");
99 98
		usb_puti(HIGH_PRIORITY);
100 99
		status++;
101 100
	}
102
	usb_puts(".\r\nConstant test complete. There were ");
101
	WL_DEBUG_PRINT_P(".\r\nConstant test complete. There were ");
103 102
	usb_puti(status);
104
	usb_puts(" errors\r\n");
103
	WL_DEBUG_PRINT_P(" errors\r\n");
105 104
	if(status!=0){
106 105
		orb2_set_color(ORANGE);
107 106
		delay_ms(500);
108 107
	}
109 108
	/*Tests function registration*/
110
	usb_puts("\r\nTesting function registration");
109
	WL_DEBUG_PRINT_P("\r\nTesting function registration");
111 110
	int registers[8], count;
112 111
	status = 0;
113 112
	orb2_set_color(GREEN);
......
121 120
	registers[7] = wl_register_handler(-1, group_4_function, 0);
122 121
	for(count=0; count<=3; count++){
123 122
		if(registers[count] != 0){
124
			usb_puts("\r\nFunction registration error: attempt ");
123
			WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
125 124
			usb_puti(count);
126
			usb_puts(" returned ");
125
			WL_DEBUG_PRINT_P(" returned ");
127 126
			usb_puti(registers[count]);
128
			usb_puts(" instead of success\r\n");
127
			WL_DEBUG_PRINT_P(" instead of success\r\n");
129 128
			orb2_set_color(ORANGE);
130 129
			status++;
131 130
		}
132 131
	}
133 132
	for(count=4; count<=6; count++){
134 133
		if(registers[count] == 0){
135
			usb_puts("\r\nFunction registration error: attempt ");
134
			WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
136 135
			usb_puti(count);
137
			usb_puts(" succeeded instead of failing\r\n");
136
			WL_DEBUG_PRINT_P(" succeeded instead of failing\r\n");
138 137
			orb2_set_color(ORANGE);
139 138
			status++;
140 139
		}
141 140
		if(registers[count] != 0 && registers[count] != -5){
142
			usb_puts("\r\nFunction registration error: attempt ");
141
			WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
143 142
			usb_puti(count);
144
			usb_puts(" returned ");
143
			WL_DEBUG_PRINT_P(" returned ");
145 144
			usb_puti(registers[count]);
146
			usb_puts(" instead of -5\r\n");
145
			WL_DEBUG_PRINT_P(" instead of -5\r\n");
147 146
			orb2_set_color(ORANGE);
148 147
			status++;
149 148
		}
150 149
	}
151 150
	if(registers[7] == 0){
152
		usb_puts("\r\nCongrats, you let an array write to index -1\r\n");
151
		WL_DEBUG_PRINT_P("\r\nCongrats, you let an array write to index -1\r\n");
153 152
		orb2_set_color(RED);
154 153
		status++;
155 154
	}
156
	usb_puts("Registration test completed. There were ");
155
	WL_DEBUG_PRINT_P("Registration test completed. There were ");
157 156
	usb_puti(status);
158
	usb_puts(" errors\r\n");
157
	WL_DEBUG_PRINT_P(" errors\r\n");
159 158
	delay_ms(500);
160 159
	
161 160
	/*Tests XBee functions*/
162
	usb_puts("\r\nTesting XBee fuctions...\r\n");
161
	WL_DEBUG_PRINT_P("\r\nTesting XBee fuctions...\r\n");
163 162
	status = 0;
164 163
	orb2_set_color(GREEN);
165 164
	unsigned int pan = xbee_get_pan();
166 165
	if(pan != 0){
167
		usb_puts("Pan error: defaulted to non-default Pan id :");
166
		WL_DEBUG_PRINT_P("Pan error: defaulted to non-default Pan id :");
168 167
		usb_puti(pan);
169 168
		orb2_set_color(ORANGE);
170 169
		status++;
171 170
	}
172 171
	pan = xbee_set_pan(1);
173 172
	if(pan != 0){
174
		usb_puts("\r\nPan error: error setting Pan id: ");
173
		WL_DEBUG_PRINT_P("\r\nPan error: error setting Pan id: ");
175 174
		usb_puti(pan);
176 175
		orb2_set_color(ORANGE);
177 176
		status++;
178 177
	}
179 178
	pan = xbee_get_pan();
180 179
	if(pan != 0){
181
		usb_puts("\r\nPan error: Pan id reads different than set value 1: ");
180
		WL_DEBUG_PRINT_P("\r\nPan error: Pan id reads different than set value 1: ");
182 181
		usb_puti(pan);
183 182
		orb2_set_color(ORANGE);
184 183
		status++;
185 184
	}
186 185
	
187
	usb_puts("\r\nXBee tests completed. There were ");
186
	WL_DEBUG_PRINT_P("\r\nXBee tests completed. There were ");
188 187
	usb_puti(status);
189
	usb_puts(" errors.\r\n");
188
	WL_DEBUG_PRINT_P(" errors.\r\n");
190 189

  
191 190
	/*Tests sending in fast mode*/
192
	usb_puts("\r\nTests sending basic packets in fast mode...\r\n");
191
	WL_DEBUG_PRINT_P("\r\nTests sending basic packets in fast mode...\r\n");
193 192
	status = 0;
194 193
	uint16_t data = xbee_get_address();
195 194
	status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, BROADCAST, FAST);
196
	usb_puts("Global fast broadcast basic send exit code ");
195
	WL_DEBUG_PRINT_P("Global fast broadcast basic send exit code ");
197 196
	usb_puti(status);
198 197
	status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, PAN, FAST);
199
	usb_puts("\r\nGlobal fast pan send basic exit code ");
198
	WL_DEBUG_PRINT_P("\r\nGlobal fast pan send basic exit code ");
200 199
	usb_puti(status);
201 200
	status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, BROADCAST, FAST);
202
	usb_puts("\r\nGlobal fast broadcast basic send exit code ");
201
	WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast basic send exit code ");
203 202
	usb_puti(status);
204 203
	status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, PAN, FAST);
205
	usb_puts("\r\nGlobal fast pan send basic exit code ");
204
	WL_DEBUG_PRINT_P("\r\nGlobal fast pan send basic exit code ");
206 205
	usb_puti(status);
207 206
	status = wl_send((uint8_t*)&data, 2, 1, GLOBAL, BROADCAST, FAST);
208
	usb_puts("\r\nGlobal fast broadcast group 1 send exit code ");
207
	WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast group 1 send exit code ");
209 208
	usb_puti(status);
210 209
	status = wl_send((uint8_t*)&data, 2, 2, GLOBAL, PAN, FAST);
211
	usb_puts("\r\nGlobal fast pan send group 2 exit code ");
210
	WL_DEBUG_PRINT_P("\r\nGlobal fast pan send group 2 exit code ");
212 211
	usb_puti(status);
213 212
	status = wl_send((uint8_t*)&data, 2, 1, GLOBAL, BROADCAST, FAST);
214
	usb_puts("\r\nGlobal fast broadcast group 3 send exit code ");
213
	WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast group 3 send exit code ");
215 214
	usb_puti(status);
216 215
	status = wl_send((uint8_t*)&data, 2, 2, GLOBAL, PAN, FAST);
217
	usb_puts("\r\nGlobal fast pan send group 4 exit code ");
216
	WL_DEBUG_PRINT_P("\r\nGlobal fast pan send group 4 exit code ");
218 217
	usb_puti(status);
219
	usb_puts("\r\nFast send tests successful\r\n");
218
	WL_DEBUG_PRINT_P("\r\nFast send tests successful\r\n");
220 219

  
221 220
	/*Sends packets in fast mode until other robot responds*/
222 221
	status = 0;
......
228 227
		wl_get_basic(address, 2);
229 228
		if(address != 0){
230 229
			orb2_set_color(GREEN);
231
			usb_puts("\r\nFriend address: ");
230
			WL_DEBUG_PRINT_P("\r\nFriend address: ");
232 231
			usb_puti((uint16_t)address);
233 232
			friendAddress = *address;
234 233
		}
......
244 243
	
245 244

  
246 245
	/*Terminates wireless functions*/
247
	usb_puts("\r\n\r\nTerminating wireless...\r\n");
246
	WL_DEBUG_PRINT_P("\r\n\r\nTerminating wireless...\r\n");
248 247
	status = wl_init();
249 248
	switch(status){
250 249
		case 0:
251
			usb_puts("Wireless termination successful\r\n\r\n");
250
			WL_DEBUG_PRINT_P("Wireless termination successful\r\n\r\n");
252 251
			orb1_set_color(BLUE);
253 252
			break;
254 253
		case -3:
255
			usb_puts("Termination failed: library not initialized\r\n\r\n");
254
			WL_DEBUG_PRINT_P("Termination failed: library not initialized\r\n\r\n");
256 255
			orb1_set_color(BLUE);
257 256
			break;
258 257
		case -5:
259
			usb_puts("Termination failed\r\n\r\n");
258
			WL_DEBUG_PRINT_P("Termination failed\r\n\r\n");
260 259
			orb1_set_color(RED);
261 260
			break;
262 261
		case -6:
263
			usb_puts("Termination failed: function unregistration failed\r\n\r\n");
262
			WL_DEBUG_PRINT_P("Termination failed: function unregistration failed\r\n\r\n");
264 263
			orb1_set_color(ORANGE);
265 264
			break;
266 265
		default:
267
			usb_puts("Error: Unreconnized status code: ");
266
			WL_DEBUG_PRINT_P("Error: Unreconnized status code: ");
268 267
			usb_puti(status);
269 268
			orb1_set_color(RED);
270 269
			break;
271 270
	}
272 271

  
273
	usb_puts("\r\n\r\nWireless Library tests completed");
272
	WL_DEBUG_PRINT_P("\r\n\r\nWireless Library tests completed");
274 273
	while(1){}
275 274
}
276 275

  
......
343 342
		usb_puti(wl_send_robot(&count, 1, 4, friendAddress, RELIABLE));
344 343
		delay_ms(count * 10);
345 344
	}
346
	usb_puts("ACK Errors: ");
345
	WL_DEBUG_PRINT_P("ACK Errors: ");
347 346
	usb_puti(wl_ack_error());
348 347
	wl_ack_reset();
349 348
	usb_puti(wl_ack_error());
......
352 351
		usb_puti(wl_send_robot(&count, 1, 0, friendAddress + 1, RELIABLE));
353 352
		delay_ms(count * 10);
354 353
	}
355
	usb_puts("ACK Errors: ");
354
	WL_DEBUG_PRINT_P("ACK Errors: ");
356 355
	usb_puti(wl_ack_error());
357 356
}
358 357

  
......
368 367
}
369 368

  
370 369
void group_1_function(uint8_t* data,uint8_t length,uint8_t source){
371
	usb_puts("\r\nFunction 1 called");
370
	WL_DEBUG_PRINT_P("\r\nFunction 1 called");
372 371
	return 0;
373 372
}
374 373
void group_2_function(uint8_t* data,uint8_t length,uint8_t source){
375
	usb_puts("\r\nFunction 2 called");
374
	WL_DEBUG_PRINT_P("\r\nFunction 2 called");
376 375
	return 0;
377 376
}
378 377
void group_3_function(uint8_t* data,uint8_t length,uint8_t source){
379
	usb_puts("\r\nFunction 3 called");
378
	WL_DEBUG_PRINT_P("\r\nFunction 3 called");
380 379
	return 0;
381 380
}
382 381
void group_4_function(uint8_t* data,uint8_t length,uint8_t source){
383
	usb_puts("\r\nFunction 4 called");
382
	WL_DEBUG_PRINT_P("\r\nFunction 4 called");
384 383
	return 0;
385 384
}
386 385
//The first robot to receive the address of another robot will trigger this function.

Also available in: Unified diff