Project

General

Profile

Revision 1621

Made Wireless_test compile and run. Report so far:
Initialization works.
Function registration works.
XBee functions fail (David is fixing this).
Sending packets in fast mode works.
Termination fails with -2. Probably XBee related.

View differences:

wireless_test.c
1 1
#include <stdlib.h>
2 2
#include <stdio.h>
3 3
#include <string.h>
4
#include "wireless.h"
4
#include <wireless.h>
5
#include <lights.h>
6
#include <dragonfly_lib.h>
7
#include <xbee.h>
5 8

  
6
uint8_t group_1_function();
7
uint8_t group_2_function();
8
uint8_t group_3_function();
9
uint8_t group_4_function();
9
uint8_t group_1_function(void);
10
uint8_t group_2_function(void);
11
uint8_t group_3_function(void);
12
uint8_t group_4_function(void);
10 13

  
11 14
/* This function tests out the full functionality of the new wireless library.
12 15
 * It must be run on two colony bots simultaneously to properly test all funtions.
13 16
*/
14
int main(char argsc, char* argv[])
17
int main(int argsc, char* argv[])
15 18
{
16 19
	orb_init();
17 20
	usb_init();
18 21
	int status = 0;
19 22

  
20
	usb_puts("New Wireless Library Test Suite\n";
23
	usb_puts("New Wireless Library Test Suite\r\n");
21 24
		
22 25
	/*Initialize the wirelss library*/
23
	usb_puts("Initializing library...\n\t");
26
	usb_puts("Initializing library...\r\n");
24 27
	orb1_set_color(BLUE);
25 28
	status = wl_init();
26 29
	switch(status){
27 30
		case 0:
28
			usb_puts("Library initialization successful\n\n");
31
			usb_puts("Library initialization successful\r\n\r\n");
29 32
			orb1_set_color(GREEN);
30 33
			break;
31 34
		case -1:
32
			usb_puts("Initialization failed: already initialized\n\n");
35
			usb_puts("Initialization failed: already initialized\r\n\r\n");
33 36
			orb1_set_color(GREEN);
34 37
			break;
35 38
		case -2:
36
			usb_puts("Initialization failed: XBEE initialization failed\n\n");
39
			usb_puts("Initialization failed: XBEE initialization failed\r\n\r\n");
37 40
			orb1_set_color(RED);
38 41
			break;
39 42
		default:
40
			usb_puts("Error: Unreconnized status code: %d\n\n", status);
43
			usb_puts("Error: Unreconnized status code: ");
44
			usb_puti(status);
45
			usb_puts("\r\n\r\n");
41 46
			orb1_set_color(RED);
42 47
			break;
43 48
	}
......
48 53
	usb_puts("Testing constants...");
49 54
	orb2_set_color(GREEN);
50 55
	if(GLOBAL!=0){
51
		usb_puts("\nGLOBAL defined as %d", GLOBAL);
56
		usb_puts("\r\nGLOBAL defined as ");
57
		usb_puti(GLOBAL);
52 58
		status++;
53 59
	}
54 60
	usb_puts(".");
55 61
	if(PAN!=1){
56
		usb_puts("\nPAN defined as %d", PAN);
62
		usb_puts("\r\nPAN defined as ");
63
		usb_puti(PAN);
57 64
		status++;
58 65
	}
59 66
	usb_puts(".");
60 67
	if(BROADCAST!=0xFFFF){
61
		usb_puts("\nBROADCAST defined as %d", BROADCAST);
68
		usb_puts("\r\nBROADCAST defined as ");
69
		usb_puti(BROADCAST);
62 70
		status++;
63 71
	}
64 72
	usb_puts(".");
65 73
	if(RELIABLE!=0){
66
		usb_puts("\nRELIABLE defined as %d", RELIABLE);
74
		usb_puts("\r\nRELIABLE defined as ");
75
		usb_puti(RELIABLE);
67 76
		status++;
68 77
	}
69 78
	usb_puts(".");
70 79
	if(FAST!=1){
71
		usb_puts("\nFAST defined as %d", FAST);
80
		usb_puts("\r\nFAST defined as ");
81
		usb_puti(FAST);
72 82
		status++;
73 83
	}
74 84
	usb_puts(".");
75 85
	if(NORMAL_PRIORITY!=0){
76
		usb_put=s("\nNORMAL_PRIORITY defined as %d", NORMAL_PRIORITY);
86
		usb_puts("\r\nNORMAL_PRIORITY defined as ");
87
		usb_puti(NORMAL_PRIORITY);
77 88
		status++;
78 89
	}
79 90
	usb_puts(".");
80 91
	if(HIGH_PRIORITY!=1){
81
		usb_puts("\nHIGH_PRIORITY defined as %d", HIGH_PRIORITY);
92
		usb_puts("\r\nHIGH_PRIORITY defined as ");
93
		usb_puti(HIGH_PRIORITY);
82 94
		status++;
83 95
	}
84
	usb_puts(".\nConstant test complete. There were %d errors", status);
96
	usb_puts(".\r\nConstant test complete. There were ");
97
	usb_puti(status);
98
	usb_puts(" errors\r\n");
85 99
	if(status!=0){
86 100
		orb2_set_color(ORANGE);
87 101
		delay_ms(500);
88

  
102
	}
89 103
	/*Tests function registration*/
90
	usb_puts("\nTesting function registration\n");
104
	usb_puts("\r\nTesting function registration");
91 105
	int registers[8], count;
92 106
	status = 0;
93 107
	orb2_set_color(GREEN);
......
101 115
	registers[7] = wl_register_handler(-1, group_4_function(), 0);
102 116
	for(count=0; count<=3; count++){
103 117
		if(registers[count] != 0){
104
			usb_puts("Function registration error: attempt %d returned %d instead of success\n", count, registers[count]);
118
			usb_puts("\r\nFunction registration error: attempt ");
119
			usb_puti(count);
120
			usb_puts(" returned ");
121
			usb_puti(registers[count]);
122
			usb_puts(" instead of success\r\n");
105 123
			orb2_set_color(ORANGE);
106 124
			status++;
107 125
		}
108 126
	}
109 127
	for(count=4; count<=6; count++){
110 128
		if(registers[count] == 0){
111
			usb_puts("Function registration error: attempt %d succeeded instead of failing\n", count);
129
			usb_puts("\r\nFunction registration error: attempt ");
130
			usb_puti(count);
131
			usb_puts(" succeeded instead of failing\r\n");
112 132
			orb2_set_color(ORANGE);
113 133
			status++;
114 134
		}
115 135
		if(registers[count] != 0 && registers[count] != -5){
116
			usb_puts("Function registration error: attempt %d returned %d instead of -5\n", count, registers[count]);
136
			usb_puts("\r\nFunction registration error: attempt ");
137
			usb_puti(count);
138
			usb_puts(" returned ");
139
			usb_puti(registers[count]);
140
			usb_puts(" instead of -5\r\n");
117 141
			orb2_set_color(ORANGE);
118 142
			status++;
119 143
		}
120 144
	}
121 145
	if(registers[7] == 0){
122
		usb_puts("Congrats, you let an array write to index -1\n");
146
		usb_puts("\r\nCongrats, you let an array write to index -1\r\n");
123 147
		orb2_set_color(RED);
124 148
		status++;
125
		while(1);
126 149
	}
127
	usb_puts("Registration test completed. There were %d errors", status);
150
	usb_puts("Registration test completed. There were ");
151
	usb_puti(status);
152
	usb_puts(" errors\r\n");
128 153
	delay_ms(500);
129 154
	
130 155
	/*Tests XBee functions*/
131
	usb_puts("Testing XBee fuctions...\n");
156
	usb_puts("\r\nTesting XBee fuctions...\r\n");
132 157
	status = 0;
133 158
	orb2_set_color(GREEN);
134 159
	unsigned int pan = xbee_get_pan_id();
135 160
	if(pan != 0){
136
		usb_puts("Pan error: defaulted to non-default Pan id #%d\n", pan);
161
		usb_puts("Pan error: defaulted to non-default Pan id :");
162
		usb_puti(pan);
137 163
		orb2_set_color(ORANGE);
138 164
		status++;
139 165
	}
140 166
	pan = xbee_set_pan_id(1);
141 167
	if(pan != 0){
142
		usb_puts("Pan error: error setting Pan id\n", pan);
168
		usb_puts("\r\nPan error: error setting Pan id: ");
169
		usb_puti(pan);
143 170
		orb2_set_color(ORANGE);
144 171
		status++;
145 172
	}
146 173
	pan = xbee_get_pan_id();
147 174
	if(pan != 0){
148
		usb_puts("Pan error: Pan id reads different %d than set value 1\n", pan);
175
		usb_puts("\r\nPan error: Pan id reads different than set value 1: ");
176
		usb_puti(pan);
149 177
		orb2_set_color(ORANGE);
150 178
		status++;
151 179
	}
152 180
	
153
	usb_puts("XBee tests completed. There were %d errors", status);
154
	usb_puts("XBee tests completed. There were %d errors", status);
181
	usb_puts("\r\nXBee tests completed. There were ");
182
	usb_puti(status);
183
	usb_puts(" errors.\r\n");
155 184

  
156 185
	/*Tests sending in fast mode*/
157
	usb_puts("Tests sending basic packets in fast mode...\n
186
	usb_puts("\r\nTests sending basic packets in fast mode...\r\n");
158 187
	status = 0;
159
	uint_16 data = xbee_get_address();
188
	uint16_t data = xbee_get_address();
160 189
	status = wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST);
161
	usb_puts("Global fast broadcast basic send exit code %d\n", status);
190
	usb_puts("Global fast broadcast basic send exit code ");
191
	usb_puti(status);
162 192
	status = wl_send(data, 2, 0, GLOBAL, PAN, FAST);
163
	usb_puts("Global fast pan send basic exit code %d\n", status);
193
	usb_puts("\r\nGlobal fast pan send basic exit code ");
194
	usb_puti(status);
164 195
	status = wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST);
165
	usb_puts("Global fast broadcast basic send exit code %d\n", status);
196
	usb_puts("\r\nGlobal fast broadcast basic send exit code ");
197
	usb_puti(status);
166 198
	status = wl_send(data, 2, 0, GLOBAL, PAN, FAST);
167
	usb_puts("Global fast pan send basic exit code %d\n", status);
199
	usb_puts("\r\nGlobal fast pan send basic exit code ");
200
	usb_puti(status);
168 201
	status = wl_send(data, 2, 1, GLOBAL, BROADCAST, FAST);
169
	usb_puts("Global fast broadcast group 1 send exit code %d\n", status);
202
	usb_puts("\r\nGlobal fast broadcast group 1 send exit code ");
203
	usb_puti(status);
170 204
	status = wl_send(data, 2, 2, GLOBAL, PAN, FAST);
171
	usb_puts("Global fast pan send group 2 exit code %d\n", status);
205
	usb_puts("\r\nGlobal fast pan send group 2 exit code ");
206
	usb_puti(status);
172 207
	status = wl_send(data, 2, 1, GLOBAL, BROADCAST, FAST);
173
	usb_puts("Global fast broadcast group 3 send exit code %d\n", status);
208
	usb_puts("\r\nGlobal fast broadcast group 3 send exit code ");
209
	usb_puti(status);
174 210
	status = wl_send(data, 2, 2, GLOBAL, PAN, FAST);
175
	usb_puts("Global fast pan send group 4 exit code %d\n", status);
176
	usb_puts("Fast send tests successful\n");
211
	usb_puts("\r\nGlobal fast pan send group 4 exit code ");
212
	usb_puti(status);
213
	usb_puts("\r\nFast send tests successful\r\n");
177 214

  
178 215
	/*Sends packets in fast mode until other robot responds*/
179 216
	usb_puts("Sending basic packets until other robot responds");
180 217
	status = 0;
181 218
	char *packet = 0; /*will contain a 16 bit address, so length always 2*/
182
	while(status == 0){
183
		wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST);
184
		status = wl_get_basic(packet, 2);
219
//	while(status == 0){
220
//		wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST);
221
	//	status = wl_get_basic(packet, 2);
185 222
		
186
	}	
223
//	}	
187 224
	
188 225

  
189 226
	/*Terminates wireless functions*/
190
	usb_puts("\nTerminating wireless...\n\t");
227
	usb_puts("\r\n\r\nTerminating wireless...\r\n");
191 228
	status = wl_init();
192 229
	switch(status){
193 230
		case 0:
194
			usb_puts("Wireless termination successful\n\n");
231
			usb_puts("Wireless termination successful\r\n\r\n");
195 232
			orb1_set_color(BLUE);
196
			break;Tech19n0
233
			break;
197 234
		case -3:
198
			usb_puts("Termination failed: library not initialized\n\n");
235
			usb_puts("Termination failed: library not initialized\r\n\r\n");
199 236
			orb1_set_color(BLUE);
200 237
			break;
201 238
		case -5:
202
			usb_puts("Termination failed\n\n");
239
			usb_puts("Termination failed\r\n\r\n");
203 240
			orb1_set_color(RED);
204 241
			break;
205 242
		case -6:
206
			usb_puts("Termination failed: function unregistration failed\n\n");
243
			usb_puts("Termination failed: function unregistration failed\r\n\r\n");
207 244
			orb1_set_color(ORANGE);
208 245
			break;
209 246
		default:
210
			usb_puts("Error: Unreconnized status code: %d\n\n", status);
247
			usb_puts("Error: Unreconnized status code: ");
248
			usb_puti(status);
211 249
			orb1_set_color(RED);
212 250
			break;
213 251
	}
214 252

  
215
	usb_puts("Wireless Library tests completed");
216
	while(1);
253
	usb_puts("\r\n\r\nWireless Library tests completed");
254
	while(1){}
217 255
}
256

  
257
uint8_t group_1_function(void){
258
	usb_puts("\r\nFunction 1 called");
259
	return 0;
260
}
261
uint8_t group_2_function(void){
262
	usb_puts("\r\nFunction 2 called");
263
	return 0;
264
}
265
uint8_t group_3_function(void){
266
	usb_puts("\r\nFunction 3 called");
267
	return 0;
268
}
269
uint8_t group_4_function(void){
270
	usb_puts("\r\nFunction 4 called");
271
	return 0;
272
}

Also available in: Unified diff