Changeset 10674 for firmware/FSC/src/parser.c
- Timestamp:
- 05/12/11 10:15:41 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/parser.c
r10667 r10674 105 105 106 106 } 107 108 109 // this is the recent MSR parser 110 ///////////////////////////////////////////////////////////////////////////////////////////////////// 111 /////////////// P A R S E R ///////////////////////////////////////////////////////////////////////// 112 ///////////////////////////////////////////////////////////////////////////////////////////////////// 113 // this method parses the data, 114 // which came in via USART 115 // later it might as well parse the data from ethernet. 116 void MSR_parser() { 117 118 U08 input_number = 0; 119 bool enable = false; 120 // look at first byte 121 // I hope, I can manage to use one byte commands 122 usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0; 123 usart_write_char(' '); 124 usart_write_str(usart_rx_buffer); 125 usart_write_char('\n'); 126 //usart_write_str((pU08)"\n received number of bytes:"); 127 //usart_write_U08(usart_rx_buffer_index,3); 128 129 if (usart_rx_buffer_index >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_rx_buffer_index>=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_rx_buffer_index >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_rx_buffer_index >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_rx_buffer_index>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_rx_buffer_index>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<CHANNEL_BITMAP; ++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<V_BITMAP; ++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_rx_buffer_index = 0; 304 usart_rx_ready = false; 305 } // END of MSR_parser(); 306
Note:
See TracChangeset
for help on using the changeset viewer.