source: firmware/FSC/src/parser.c@ 10895

Last change on this file since 10895 was 10697, checked in by neise, 14 years ago
File size: 10.3 KB
Line 
1#include "parser.h"
2#include "output.h"
3#include "application.h"
4#include "usart.h"
5#include "w5100_spi_interface.h"
6// this method parses the data,
7// which came in via USART
8// later it might as well parse the data from ethernet.
9void parse_ascii() {
10 usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0;
11 usart_write_str((pU08)"got:");
12 usart_write_str(usart_rx_buffer);
13
14// look at first byte
15// I hope, I can manage to use one byte commands
16 switch (usart_rx_buffer[0]) {
17 case 'E': // AD7719 enable bitmaps may be set
18 set_ad7719_enable_register();
19 break;
20 case 'e': // ATmega internal ADC enable bitmaps may be set
21 // not supported yet.
22 set_adc_enable_register();
23 break;
24 case 'h':
25 usart_write_str((pU08)"\nheartbeat ");
26 heartbeat_enable = true;
27 if (usart_rx_buffer[1] == '0'){
28 heartbeat_enable = false;
29 usart_write_str((pU08)"off\n");
30 } else {
31 usart_write_str((pU08)"on\n");
32 }
33 break;
34 case 'G': // GET the Temperature channels, which are enabled
35 once_told_you = false;
36 for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) {
37 ad7719_channels_ready[i]=0;
38 }
39 break;
40
41 case 'g': // GET the voltage/current/humidity channels, which are enabled
42 once_told_you = false;
43 for ( U08 i=0; i<VOLTAGE_CHANNELS/8; ++i ) {
44 adc_channels_ready[i]=0;
45 }
46 break;
47
48 case 'P':
49 print_ad7719_nicely();
50 break;
51
52 case 'p':
53 print_adc_nicely();
54 break;
55
56 case 's':
57 print_status();
58 break;
59
60 case 'd':
61 usart_write_str((pU08)"\ndebug mode ");
62 debug_mode = true;
63 if (usart_rx_buffer[1] == '0'){
64 debug_mode = false;
65 usart_write_str((pU08)"off\n");
66 } else {
67 usart_write_str((pU08)"on\n");
68 }
69 break;
70 }
71
72
73 usart_write_str((pU08)"\nready?");
74 for (U08 i=0; i<USART_RX_BUFFER_SIZE; ++i)
75 usart_rx_buffer[i] = 0;
76}
77
78void parse_non_human_readable_input() {
79
80
81}
82
83// this guy checks, if an incoming byte is:
84// to be stored, because it belongs to a command
85// to be discarded, because something went wrong, and the bytemade no sense...
86// the end of a commmand, and so the 'real parser' may do his work.
87/*
88void incoming_byte_parser() {
89 static bool receiving_command = false;
90 U08 current_byte = UDR;
91
92 if (!receiving_command) {
93 switch (current_byte) {
94 case 0x01:
95 receiving_command = true;
96 break;
97 }
98 }
99
100 if (receiving_command)
101 {
102 usart_rx_buffer[usart_received_chars] = usart_last_char;
103 usart_received_chars++;
104 }
105
106
107}
108*/
109/*
110
111// this is the recent MSR parser
112/////////////////////////////////////////////////////////////////////////////////////////////////////
113/////////////// P A R S E R /////////////////////////////////////////////////////////////////////////
114/////////////////////////////////////////////////////////////////////////////////////////////////////
115// this method parses the data,
116// which came in via USART
117// later it might as well parse the data from ethernet.
118void MSR_parser() {
119
120U08 input_number = 0;
121bool enable = false;
122// look at first byte
123// I hope, I can manage to use one byte commands
124 usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0;
125 usart_write_char(' ');
126 usart_write_str(usart_rx_buffer);
127 usart_write_char('\n');
128
129
130 if (usart_received_chars >0) {
131 switch (usart_rx_buffer[0]) {
132 case 'E': // user wants to enable/disable something
133 case 'e':
134 enable = true;
135 case 'D':
136 case 'd':
137
138 if (usart_received_chars>=1) { // let's see what.
139 if ( usart_rx_buffer[1] != 'r' &&
140 usart_rx_buffer[1] != 'v' &&
141 usart_rx_buffer[1] != 'h' &&
142 usart_rx_buffer[1] != 'p' )
143 {
144 //print_invalid_enable_statement();
145 break;
146 }
147 }
148
149 input_number = 0;
150 if (usart_received_chars >2) { // lets check the first digit
151 if ( usart_rx_buffer[2] >= '0' && usart_rx_buffer[2] <= '9' ) {
152 input_number = usart_rx_buffer[2] - '0';
153 } else {
154 //print_invalid_enable_statement();
155 break;
156 }
157 }
158 if (usart_received_chars >3) { // lets check the 2nd digit
159 if ( usart_rx_buffer[3] >= '0' && usart_rx_buffer[3] <= '9' ) {
160 input_number = 10*input_number + usart_rx_buffer[3] - '0';
161 } else {
162 // okay as well ... if the second digit is missing ..
163 // we might have trailing spaces
164 // that's okay .. we just accept the first number.
165 }
166 }
167 if (usart_received_chars>2) {
168 usart_write_str((pU08)"\n I will switch ");
169 if (enable)
170 usart_write_str((pU08)"on ");
171 else
172 usart_write_str((pU08)"off ");
173
174 // now we know, what the user wanted ... and we need to do it.
175 switch (usart_rx_buffer[1]) {
176 case 'r':
177 if (enable)
178 ad7719_enables[input_number/8] |= (1<<(input_number%8));
179 else {
180 ad7719_enables[input_number/8] &= ~(1<<(input_number%8));
181 ad7719_channels_ready[input_number/8] &= ~(1<<(input_number%8));
182 }
183 usart_write_str((pU08)" resistance channel ");
184 usart_write_U08(input_number,2);
185 usart_write_char('\n');
186 break;
187 case 'v':
188 if (enable)
189 adc_enables[input_number/8] |= (1<<(input_number%8));
190 else {
191 adc_enables[input_number/8] &= ~(1<<(input_number%8));
192 adc_channels_ready[input_number/8] &= ~(1<<(input_number%8));
193 }
194 usart_write_str((pU08)" voltage channel ");
195 usart_write_U08(input_number,2);
196 usart_write_char('\n');
197 break;
198
199 case 'h':
200 if (enable)
201 adc_enables[1] |= (1<<(input_number%4));
202 else {
203 adc_enables[1] &= ~(1<<(input_number%4));
204 adc_channels_ready[1] &= ~(1<<(input_number%4));
205 }
206 usart_write_str((pU08)" humidity channel ");
207 usart_write_U08(input_number,2);
208 usart_write_char('\n');
209 break;
210 case 'p':
211 if (enable)
212 adc_enables[1] |= (1<<((input_number%4) + 4));
213 else {
214 adc_enables[1] &= ~(1<<((input_number%4) + 4));
215 adc_channels_ready[1] &= ~(1<<((input_number%4) + 4));
216 }
217 usart_write_str((pU08)" pressure channel ");
218 usart_write_U08(input_number,2);
219 usart_write_char('\n');
220 break;
221 default:
222 usart_write_str((pU08)"\n DAMN! this should never happen"
223 "- enable/disable switch-case!\n");
224 break;
225 }
226
227
228
229 }// end of if usart_received_chars>2 --> this should not be necessary at all
230 break;
231
232 case 'b':
233 usart_write_str((pU08)"\nheartbeat ");
234 heartbeat_enable = true;
235 if (usart_rx_buffer[1] == '0'){
236 heartbeat_enable = false;
237 usart_write_str((pU08)"off\n");
238 } else {
239 usart_write_str((pU08)"on\n");
240 }
241 break;
242 case 'G': // GET the Temperature channels, which are enabled
243 ad7719_values_printed = false;
244 for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) {
245 ad7719_channels_ready[i]=0;
246 }
247 break;
248 case 'g': // GET the voltage/current/humidity channels, which are enabled
249 adc_values_printed = false;
250 for ( U08 i=0; i<VOLTAGE_CHANNELS/8; ++i ) {
251 adc_channels_ready[i]=0;
252 }
253 break;
254
255 case 'p':
256 adc_print_endless = true;
257 if (usart_rx_buffer[1] == '0')
258 adc_print_endless = false;
259 break;
260
261 case 'P':
262 ad7719_print_endless = true;
263 if (usart_rx_buffer[1] == '0')
264 ad7719_print_endless = false;
265 break;
266
267
268 case 's':
269 print_adc_enable_status(true);
270 usart_write_char('\n');
271
272 print_ad7719_enable_status(true);
273 usart_write_char('\n');
274
275 usart_write_str((pU08)"time:");
276 usart_write_float((float)local_ms/1000 , 1,7);
277 usart_write_str((pU08)" sec.\n");
278 break;
279
280 case '!':
281 usart_write_str((pU08)"\ndebug mode ");
282 debug_mode = true;
283 if (usart_rx_buffer[1] == '0'){
284 debug_mode = false;
285 usart_write_str((pU08)"off\n");
286 } else {
287 usart_write_str((pU08)"on\n");
288 }
289 break;
290
291 case 'h':
292 case 'H':
293 print_help();
294 break;
295 }
296 } else
297 {
298 // zero bytes received
299 }
300
301
302 for (U08 i=0; i<USART_RX_BUFFER_SIZE; ++i)
303 usart_rx_buffer[i] = 0;
304 usart_received_chars = 0;
305 usart_rx_ready = false;
306} // END of MSR_parser();
307
308*/
309
310///////////////////////////////////////////////////////////////////////////////////////
311// W5300 incoming commands parser
312void parse_w5300_incoming( U08 bytes_in_w5100_rx_buffer ) {
313
314 if (bytes_in_w5100_rx_buffer == 0) // it was stupid to call this parser without having any bytes downloaded
315 return;
316
317 switch (eth_read_buffer[0]) {
318 case 'w': // *w*rite to register command
319 write_FSC_register();
320 read_FSC_register();
321 break;
322
323 case 'r': // *r*ead from register command
324 read_FSC_register();
325 break;
326
327 case 't': // measure *t*emperature (resistance) channels only
328 reset_resistance_done();
329 simple_acknowledge();
330 break;
331
332 case 'v': // measure *v*oltage channels only
333 reset_voltage_done();
334 simple_acknowledge();
335 break;
336
337 case 'm': // *m*easure active channels commands
338 reset_done();
339 simple_acknowledge();
340 break;
341
342 case 's': // return *s*tatus information
343 // this might take a lot of time... about... 25us per byte .. --> less than 25ms
344 w5100_set_TX(FSCregister, FSC_REGISTER_LENGTH);
345 break;
346
347 case 'z': // re*z*et ATmega32 and peripherals
348 eth_write_buffer[0]='!';
349 eth_write_buffer[1]='!';
350 w5100_set_TX(eth_write_buffer, 2);
351 // let watchdog occur!
352 // gotta read, how this works...
353 break;
354 }
355}
356
357void write_FSC_register() {
358 FSCregister[eth_read_buffer[2]]=eth_read_buffer[3];
359}
360
361void read_FSC_register() {
362 eth_write_buffer[0]=eth_read_buffer[0];
363 eth_write_buffer[1]=eth_read_buffer[1];
364 eth_write_buffer[2]=eth_read_buffer[2];
365 eth_write_buffer[3]=FSCregister[eth_read_buffer[2]];
366 w5100_set_TX(eth_write_buffer, 4);
367}
368
369void reset_resistance_done(){
370 for (U08 i=0; i < (RESISTANCE_CHANNELS/8); i++){
371 ad7719_channels_ready[i] = 0;
372 }
373}
374void reset_voltage_done(){
375 for (U08 i=0; i < (VOLTAGE_CHANNELS/8); i++){
376 adc_channels_ready[i] = 0;
377 }
378}
379void reset_done(){
380 reset_resistance_done();
381 reset_voltage_done();
382}
383
384void simple_acknowledge(){
385 eth_write_buffer[0]=eth_read_buffer[0];
386 eth_write_buffer[1]=eth_read_buffer[1];
387 w5100_set_TX(eth_write_buffer, 2);
388}
Note: See TracBrowser for help on using the repository browser.