Project

General

Profile

Revision 1202

Station/server communication:
- Implemented backspace handling
- Implemented all test starting commands with parameter
Tests:
- Added functions for testing only one component of a kind
- Made function names consistent with server commands

View differences:

trunk/code/projects/diagnostic_station/station/test_rangefinders.c
3 3

  
4 4
#include "comm_robot.h"
5 5

  
6
void test_rangefinders (void)
6

  
7
void test_rangefinder (uint8_t num)
7 8
{
8
	usb_puts("# Testing rangefinders" NL);
9
	if (num>4) return;
9 10
	
10
	for (int n=0; n<5; ++n)
11
	{
12
		usb_puts("# Testing rangefinder ");
13
		usb_puti(n);
14
		usb_puts(NL);
15

  
16
		
11
	usb_puts("# Testing rangefinder ");
12
	usb_puti(num);
13
	usb_puts(NL);
14
	
17 15
	//	rotate to position
18 16
	//	
19 17
	//	for (wall positions up/down)
......
22 20
	//		send (read)
23 21
	//		receive (data)
24 22
	//	}
25
	}
23
	//send data
24
}
26 25

  
27
	//send data
26

  
27
void test_rangefinder_all (void)
28
{
29
	usb_puts("# Testing rangefinders" NL);
28 30
	
31
	for (int n=0; n<5; ++n)
32
		test_rangefinder (n);
33
	
29 34
	usb_puts("# Testing rangefinders finished" NL);
30 35
}
31

  
trunk/code/projects/diagnostic_station/station/test_rangefinders.h
3 3

  
4 4
#include <dragonfly_lib.h>
5 5

  
6
void test_rangefinders (void);
6
void test_rangefinder (uint8_t num);
7
void test_rangefinder_all (void);
7 8

  
8 9

  
9 10

  
trunk/code/projects/diagnostic_station/station/test_bom.c
1 1
#include "test_bom.h"
2 2
#include "global.h"
3 3

  
4
void test_bom (bool test_emitters, bool test_detectors)
4
void test_bom_bitmask (uint16_t emitter_bitmask, uint16_t detector_bitmask)
5 5
{
6 6
	usb_puts("# Testing BOM" NL);
7 7
	
8
	for (uint8_t n=0; n<15; ++n)
8
	for (uint8_t n=0; n<16; ++n, emitter_bitmask>>=1, detector_bitmask>>=1)
9 9
	{
10
		if (test_emitters)
10
		if (emitter_bitmask&1)
11 11
		{
12 12
			usb_puts("# Testing BOM emitter ");
13 13
			usb_puti(n);
......
20 20
	//		wait (done)
21 21
		}
22 22
		
23
		if (test_detectors)
23
		if (detector_bitmask&1)
24 24
		{
25 25
			usb_puts("# Testing BOM detector ");
26 26
			usb_puti(n);
......
42 42

  
43 43
	usb_puts("# Testing BOM finished" NL);
44 44
}
45

  
46
void test_bom (uint8_t num, bool test_emitter, bool test_detector)
47
{
48
	uint16_t emitter_bitmask=0, detector_bitmask=0;
49
	
50
	if (test_emitter  && num<16) emitter_bitmask =1<<num;
51
	if (test_detector && num<16) detector_bitmask=1<<num;
52
	
53
	test_bom_bitmask (emitter_bitmask, detector_bitmask);
54
}
55

  
56
void test_bom_all (bool test_emitters, bool test_detectors)
57
{
58
	uint16_t emitter_bitmask=0, detector_bitmask=0;
59
	
60
	if (test_emitters ) emitter_bitmask =0xFFFF;
61
	if (test_detectors) detector_bitmask=0xFFFF;
62
	
63
	test_bom_bitmask (emitter_bitmask, detector_bitmask);
64
}
trunk/code/projects/diagnostic_station/station/test_bom.h
3 3

  
4 4
#include <dragonfly_lib.h>
5 5

  
6
void test_bom (bool test_emitters, bool test_detectors);
6
void test_bom_bitmask (uint16_t emitter_bitmask, uint16_t detector_bitmask);
7
void test_bom (uint8_t num, bool test_emitter, bool test_detector);
8
void test_bom_all (bool test_emitters, bool test_detectors);
7 9

  
8

  
9

  
10 10
#endif
trunk/code/projects/diagnostic_station/station/test_motors.c
37 37
		test_motors_direction_velocity (direction1, direction2, vel);
38 38
}
39 39

  
40
void test_motors (void)
40
void test_motor_all (void)
41 41
{
42 42
	usb_puts("# Testing motors" NL);
43 43

  
......
51 51
	
52 52
	usb_puts("# Testing motors finished" NL);
53 53
}
54

  
55
void test_motor (uint8_t num)
56
{
57
	// TODO implement single motor testing
58
	if (!(num==1 || num==2)) return;
59
	
60
	test_motor_all ();
61
}
trunk/code/projects/diagnostic_station/station/test_motors.h
3 3

  
4 4
#include <dragonfly_lib.h>
5 5

  
6
void test_motors (void);
6
void test_motor (uint8_t num);
7
void test_motor_all (void);
7 8

  
8 9

  
9 10

  
trunk/code/projects/diagnostic_station/station/test_encoders.c
34 34

  
35 35
}
36 36

  
37

  
38
void test_encoders (void)
37
void test_encoder_all (void)
39 38
{
40 39
	usb_puts("# Testing encoders" NL);
41 40

  
......
47 46
	usb_puts("# Testing encoders finished" NL);
48 47
}
49 48

  
49
void test_encoder (uint8_t num)
50
{
51
	if (!(num==1 || num==2)) return;
52
	
53
	// TODO implement single encoder testing
54
	test_encoder_all ();
55
}
trunk/code/projects/diagnostic_station/station/tests.c
26 26
		return;
27 27
	}
28 28
	
29
	test_bom (true, true);
30
	test_rangefinders ();
31
	test_encoders ();
32
	test_motors ();
29
	test_bom_all (true, true);
30
	test_rangefinder_all ();
31
	test_encoder_all ();
32
	test_motor_all ();
33 33
}
34 34

  
35 35

  
trunk/code/projects/diagnostic_station/station/test_encoders.h
3 3

  
4 4
#include <dragonfly_lib.h>
5 5

  
6
void test_encoders (void);
6
void test_encoder (uint8_t num);
7
void test_encoder_all (void);
7 8

  
8 9

  
9 10

  
10 11

  
11 12

  
12 13

  
13

  
14 14
#endif
trunk/code/projects/diagnostic_station/station/comm_server.c
104 104
	return false;
105 105
}
106 106

  
107
static bool serial_number_u8 (uint8_t *num, const char *buffer)
108
{
109
	uint8_t result=0;
110
	
111
	// Iterate over the buffer
112
	while (1)
113
	{
114
		// Look at the character
115
		char c=*buffer;
107 116

  
117
		if (c>='0' && c<='9')
118
		{
119
			// It's a digit. Process it.
120
			result*=10;
121
			result+=(c-'0');
122
		}
123
		else if (c==' ' || c==0)
124
		{
125
			// It's a space or a terminating zero, which means that the paramter is a valid number.
126
			*num=result;
127
			return true;
128
		}
129
		else
130
		{
131
			// It's a different character, which means that the parameter is not a number.
132
			return false;
133
		}
134
		
135
		// Move to the next byte
136
		buffer++;
137
	}
138
}
108 139

  
109 140

  
110 141

  
111 142

  
143

  
144

  
112 145
// ########################
113 146
// ## Messages (sending) ##
114 147
// ########################
......
118 151
	usb_puts ("finished");
119 152
}
120 153

  
154
// ##########################
155
// ## Messages (Receiving) ##
156
// ##########################
121 157

  
158
static void unhandled_parameters (char *buffer)
159
{
160
	usb_puts ("# Warning: unhandled parameters: [");
161
	usb_puts (buffer);
162
	usb_puts ("]" NL);
163
}
164

  
165
static void parameter_missing (void)
166
{
167
	usb_puts ("# Parameter missing" NL);
168
}
169

  
170

  
122 171
// ######################
123 172
// ## Message handlers ##
124 173
// ######################
125 174

  
175

  
126 176
static void handle_message_ping (char *buffer)
127 177
{
128 178
	usb_puts ("pong" NL);
......
131 181
	orbs_set (0, 255, 0, 255, 127, 0);
132 182
}
133 183

  
134
static void handle_message_start_test (char *buffer)
184
static void handle_message_start_test_all (char *buffer)
135 185
{
136
	// FIXME parameter handling
137
	// Parameters: all/rangefinder/motor/encoder all/<num>
138
	
186
	test_all ();
187
}
188

  
189
static void handle_message_start_test_comm (char *buffer)
190
{
191
	// TODO handle all/number
192
	test_comm ();
193
}
194

  
195
static void handle_message_start_test_component (char *buffer, void (*test_all_fn)(void), void (*test_one_fn)(uint8_t))
196
{
197
	// Find the next parameter
139 198
	buffer=find_next_parameter (buffer);
140 199

  
200
	// Initialize a buffer for the component number
201
	uint8_t num=0;
202

  
141 203
	if (!buffer)
142
		usb_puts ("# Parameter missing" NL);
204
		// No paramter found (we could also interpret that as implicit "all")
205
		parameter_missing ();
143 206
	else if (serial_match (command_all, buffer))
144
	{
145
		usb_puts ("# Doing all tests" NL);
146
		test_all ();
147
	}
207
		// The paramter is "all". Call the all-tests function
208
		test_all_fn ();
209
	else if (serial_number_u8 (&num, buffer))
210
		// The paramter is a number. Call the one-test function 
211
		test_one_fn (num);
148 212
	else
149
	{
150
		usb_puts ("# Warning: unhandled parameters: [");
151
		usb_puts (buffer);
152
		usb_puts ("]" NL);
153
	}
213
		// Unknwon parameter
214
		unhandled_parameters (buffer);
154 215
}
155 216

  
217
static void test_bom_helper (uint8_t num)
218
{
219
	test_bom (num, true, true);
220
}
221

  
222
static void test_bom_all_helper (void)
223
{
224
	test_bom_all (true, true);
225
}
226

  
227
static void handle_message_start_test_bom (char *buffer)
228
{
229
	handle_message_start_test_component (buffer, test_bom_all_helper, test_bom_helper);
230
}
231

  
232
static void handle_message_start_test_rangefinder (char *buffer)
233
{
234
	handle_message_start_test_component (buffer, test_rangefinder_all, test_rangefinder);
235
}
236

  
237
static void handle_message_start_test_motor (char *buffer)
238
{
239
	handle_message_start_test_component (buffer, test_motor_all, test_motor);
240
}
241

  
242
static void handle_message_start_test_encoder (char *buffer)
243
{
244
	handle_message_start_test_component (buffer, test_encoder_all, test_encoder);
245
}
246

  
247
static void handle_message_start_test (char *buffer)
248
{
249
	// FIXME parameter handling
250
	// Parameters: all/rangefinder/motor/encoder all/<num>
251
	
252

  
253
	// TODO add required comm test
254
	buffer=find_next_parameter (buffer);
255
	if (!buffer)                                         parameter_missing ();
256
	else if (serial_match (command_all        , buffer)) handle_message_start_test_all         (buffer);
257
	else if (serial_match (command_comm       , buffer)) handle_message_start_test_comm        (buffer);
258
	else if (serial_match (command_bom        , buffer)) handle_message_start_test_bom         (buffer);
259
	else if (serial_match (command_rangefinder, buffer)) handle_message_start_test_rangefinder (buffer);
260
	else if (serial_match (command_motor      , buffer)) handle_message_start_test_motor       (buffer);
261
	else if (serial_match (command_encoder    , buffer)) handle_message_start_test_encoder     (buffer);
262
	else                                                 unhandled_parameters (buffer);
263
}
264

  
156 265
static void handle_message_help (char *buffer)
157 266
{
158 267
	serial_send_string_P (help_text);
......
246 355
				buffer_fill=0;
247 356
			}
248 357
		}
358
		else if (c==8)
359
		{
360
			// Backspace
361
			// Of course, the server will never send one, but it's convenient to have for debugging.
362
			if (buffer_fill>0) --buffer_fill;
363
		}
249 364
		else
250 365
		{
251 366
			// If there is enough space left in the buffer, add the character we just received. Leave one byte for a
trunk/code/projects/diagnostic_station/station/main.c
24 24

  
25 25
		char choice = usb_getc ();
26 26
		switch (choice) {
27
			case 'c': case 'C': test_comm ();                               break;
28
			case 'a': case 'A': test_all ();                                break; // test_all will test comm itself
29
			case 'b': case 'B': if (require_comm ()) test_bom (true, true); break;
30
			case 'r': case 'R': if (require_comm ()) test_rangefinders ();  break;
31
			case 'm': case 'M': if (require_comm ()) test_motors ();        break;
32
			case 'e': case 'E': if (require_comm ()) test_encoders ();      break;
33
			case 's': case 'S': self_test ();                               break;
27
			case 'c': case 'C': test_comm ();                                   break;
28
			case 'a': case 'A': test_all ();                                    break; // test_all will test comm itself
29
			case 'b': case 'B': if (require_comm ()) test_bom_all (true, true); break;
30
			case 'r': case 'R': if (require_comm ()) test_rangefinder_all ();   break;
31
			case 'm': case 'M': if (require_comm ()) test_motor_all ();         break;
32
			case 'e': case 'E': if (require_comm ()) test_encoder_all ();       break;
33
			case 's': case 'S': self_test ();                                   break;
34 34
			default: break; // ignore it
35 35
		}
36 36
	}

Also available in: Unified diff