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

Last change on this file since 10686 was 10677, checked in by neise, 14 years ago
File size: 8.2 KB
Line 
1#include "parser.h"
2#include "output.h"
3#include "application.h"
4#include "usart.h"
5// this method parses the data,
6// which came in via USART
7// later it might as well parse the data from ethernet.
8void parse_ascii() {
9 usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0;
10 usart_write_str((pU08)"got:");
11 usart_write_str(usart_rx_buffer);
12
13// look at first byte
14// I hope, I can manage to use one byte commands
15 switch (usart_rx_buffer[0]) {
16 case 'E': // AD7719 enable bitmaps may be set
17 set_ad7719_enable_register();
18 break;
19 case 'e': // ATmega internal ADC enable bitmaps may be set
20 // not supported yet.
21 set_adc_enable_register();
22 break;
23 case 'h':
24 usart_write_str((pU08)"\nheartbeat ");
25 heartbeat_enable = true;
26 if (usart_rx_buffer[1] == '0'){
27 heartbeat_enable = false;
28 usart_write_str((pU08)"off\n");
29 } else {
30 usart_write_str((pU08)"on\n");
31 }
32 break;
33 case 'G': // GET the Temperature channels, which are enabled
34 once_told_you = false;
35 for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) {
36 ad7719_channels_ready[i]=0;
37 }
38 break;
39
40 case 'g': // GET the voltage/current/humidity channels, which are enabled
41 once_told_you = false;
42 for ( U08 i=0; i<VOLTAGE_CHANNELS/8; ++i ) {
43 adc_channels_ready[i]=0;
44 }
45 break;
46
47 case 'P':
48 print_ad7719_nicely();
49 break;
50
51 case 'p':
52 print_adc_nicely();
53 break;
54
55 case 's':
56 print_status();
57 break;
58
59 case 'd':
60 usart_write_str((pU08)"\ndebug mode ");
61 debug_mode = true;
62 if (usart_rx_buffer[1] == '0'){
63 debug_mode = false;
64 usart_write_str((pU08)"off\n");
65 } else {
66 usart_write_str((pU08)"on\n");
67 }
68 break;
69 }
70
71
72 usart_write_str((pU08)"\nready?");
73 for (U08 i=0; i<USART_RX_BUFFER_SIZE; ++i)
74 usart_rx_buffer[i] = 0;
75}
76
77void parse_non_human_readable_input() {
78
79
80}
81
82// this guy checks, if an incoming byte is:
83// to be stored, because it belongs to a command
84// to be discarded, because something went wrong, and the bytemade no sense...
85// the end of a commmand, and so the 'real parser' may do his work.
86/*
87void incoming_byte_parser() {
88 static bool receiving_command = false;
89 U08 current_byte = UDR;
90
91 if (!receiving_command) {
92 switch (current_byte) {
93 case 0x01:
94 receiving_command = true;
95 break;
96 }
97 }
98
99 if (receiving_command)
100 {
101 usart_rx_buffer[usart_received_chars] = usart_last_char;
102 usart_received_chars++;
103 }
104
105
106}
107*/
108/*
109
110// this is the recent MSR parser
111/////////////////////////////////////////////////////////////////////////////////////////////////////
112/////////////// P A R S E R /////////////////////////////////////////////////////////////////////////
113/////////////////////////////////////////////////////////////////////////////////////////////////////
114// this method parses the data,
115// which came in via USART
116// later it might as well parse the data from ethernet.
117void MSR_parser() {
118
119U08 input_number = 0;
120bool enable = false;
121// look at first byte
122// I hope, I can manage to use one byte commands
123 usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0;
124 usart_write_char(' ');
125 usart_write_str(usart_rx_buffer);
126 usart_write_char('\n');
127
128
129 if (usart_received_chars >0) {
130 switch (usart_rx_buffer[0]) {
131 case 'E': // user wants to enable/disable something
132 case 'e':
133 enable = true;
134 case 'D':
135 case 'd':
136
137 if (usart_received_chars>=1) { // let's see what.
138 if ( usart_rx_buffer[1] != 'r' &&
139 usart_rx_buffer[1] != 'v' &&
140 usart_rx_buffer[1] != 'h' &&
141 usart_rx_buffer[1] != 'p' )
142 {
143 //print_invalid_enable_statement();
144 break;
145 }
146 }
147
148 input_number = 0;
149 if (usart_received_chars >2) { // lets check the first digit
150 if ( usart_rx_buffer[2] >= '0' && usart_rx_buffer[2] <= '9' ) {
151 input_number = usart_rx_buffer[2] - '0';
152 } else {
153 //print_invalid_enable_statement();
154 break;
155 }
156 }
157 if (usart_received_chars >3) { // lets check the 2nd digit
158 if ( usart_rx_buffer[3] >= '0' && usart_rx_buffer[3] <= '9' ) {
159 input_number = 10*input_number + usart_rx_buffer[3] - '0';
160 } else {
161 // okay as well ... if the second digit is missing ..
162 // we might have trailing spaces
163 // that's okay .. we just accept the first number.
164 }
165 }
166 if (usart_received_chars>2) {
167 usart_write_str((pU08)"\n I will switch ");
168 if (enable)
169 usart_write_str((pU08)"on ");
170 else
171 usart_write_str((pU08)"off ");
172
173 // now we know, what the user wanted ... and we need to do it.
174 switch (usart_rx_buffer[1]) {
175 case 'r':
176 if (enable)
177 ad7719_enables[input_number/8] |= (1<<(input_number%8));
178 else {
179 ad7719_enables[input_number/8] &= ~(1<<(input_number%8));
180 ad7719_channels_ready[input_number/8] &= ~(1<<(input_number%8));
181 }
182 usart_write_str((pU08)" resistance channel ");
183 usart_write_U08(input_number,2);
184 usart_write_char('\n');
185 break;
186 case 'v':
187 if (enable)
188 adc_enables[input_number/8] |= (1<<(input_number%8));
189 else {
190 adc_enables[input_number/8] &= ~(1<<(input_number%8));
191 adc_channels_ready[input_number/8] &= ~(1<<(input_number%8));
192 }
193 usart_write_str((pU08)" voltage channel ");
194 usart_write_U08(input_number,2);
195 usart_write_char('\n');
196 break;
197
198 case 'h':
199 if (enable)
200 adc_enables[1] |= (1<<(input_number%4));
201 else {
202 adc_enables[1] &= ~(1<<(input_number%4));
203 adc_channels_ready[1] &= ~(1<<(input_number%4));
204 }
205 usart_write_str((pU08)" humidity channel ");
206 usart_write_U08(input_number,2);
207 usart_write_char('\n');
208 break;
209 case 'p':
210 if (enable)
211 adc_enables[1] |= (1<<((input_number%4) + 4));
212 else {
213 adc_enables[1] &= ~(1<<((input_number%4) + 4));
214 adc_channels_ready[1] &= ~(1<<((input_number%4) + 4));
215 }
216 usart_write_str((pU08)" pressure channel ");
217 usart_write_U08(input_number,2);
218 usart_write_char('\n');
219 break;
220 default:
221 usart_write_str((pU08)"\n DAMN! this should never happen"
222 "- enable/disable switch-case!\n");
223 break;
224 }
225
226
227
228 }// end of if usart_received_chars>2 --> this should not be necessary at all
229 break;
230
231 case 'b':
232 usart_write_str((pU08)"\nheartbeat ");
233 heartbeat_enable = true;
234 if (usart_rx_buffer[1] == '0'){
235 heartbeat_enable = false;
236 usart_write_str((pU08)"off\n");
237 } else {
238 usart_write_str((pU08)"on\n");
239 }
240 break;
241 case 'G': // GET the Temperature channels, which are enabled
242 ad7719_values_printed = false;
243 for ( U08 i=0; i<RESISTANCE_CHANNELS/8; ++i ) {
244 ad7719_channels_ready[i]=0;
245 }
246 break;
247 case 'g': // GET the voltage/current/humidity channels, which are enabled
248 adc_values_printed = false;
249 for ( U08 i=0; i<VOLTAGE_CHANNELS/8; ++i ) {
250 adc_channels_ready[i]=0;
251 }
252 break;
253
254 case 'p':
255 adc_print_endless = true;
256 if (usart_rx_buffer[1] == '0')
257 adc_print_endless = false;
258 break;
259
260 case 'P':
261 ad7719_print_endless = true;
262 if (usart_rx_buffer[1] == '0')
263 ad7719_print_endless = false;
264 break;
265
266
267 case 's':
268 print_adc_enable_status(true);
269 usart_write_char('\n');
270
271 print_ad7719_enable_status(true);
272 usart_write_char('\n');
273
274 usart_write_str((pU08)"time:");
275 usart_write_float((float)local_ms/1000 , 1,7);
276 usart_write_str((pU08)" sec.\n");
277 break;
278
279 case '!':
280 usart_write_str((pU08)"\ndebug mode ");
281 debug_mode = true;
282 if (usart_rx_buffer[1] == '0'){
283 debug_mode = false;
284 usart_write_str((pU08)"off\n");
285 } else {
286 usart_write_str((pU08)"on\n");
287 }
288 break;
289
290 case 'h':
291 case 'H':
292 print_help();
293 break;
294 }
295 } else
296 {
297 // zero bytes received
298 }
299
300
301 for (U08 i=0; i<USART_RX_BUFFER_SIZE; ++i)
302 usart_rx_buffer[i] = 0;
303 usart_received_chars = 0;
304 usart_rx_ready = false;
305} // END of MSR_parser();
306
307*/
Note: See TracBrowser for help on using the repository browser.