#include "parser.h" #include "output.h" #include "application.h" #include "usart.h" // this method parses the data, // which came in via USART // later it might as well parse the data from ethernet. void parse_ascii() { usart_rx_buffer[USART_RX_BUFFER_SIZE-1] = 0; usart_write_str((pU08)"got:"); usart_write_str(usart_rx_buffer); // look at first byte // I hope, I can manage to use one byte commands switch (usart_rx_buffer[0]) { case 'E': // AD7719 enable bitmaps may be set set_ad7719_enable_register(); break; case 'e': // ATmega internal ADC enable bitmaps may be set // not supported yet. set_adc_enable_register(); break; case 'h': usart_write_str((pU08)"\nheartbeat "); heartbeat_enable = true; if (usart_rx_buffer[1] == '0'){ heartbeat_enable = false; usart_write_str((pU08)"off\n"); } else { usart_write_str((pU08)"on\n"); } break; case 'G': // GET the Temperature channels, which are enabled once_told_you = false; for ( U08 i=0; i0) { switch (usart_rx_buffer[0]) { case 'E': // user wants to enable/disable something case 'e': enable = true; case 'D': case 'd': if (usart_received_chars>=1) { // let's see what. if ( usart_rx_buffer[1] != 'r' && usart_rx_buffer[1] != 'v' && usart_rx_buffer[1] != 'h' && usart_rx_buffer[1] != 'p' ) { //print_invalid_enable_statement(); break; } } input_number = 0; if (usart_received_chars >2) { // lets check the first digit if ( usart_rx_buffer[2] >= '0' && usart_rx_buffer[2] <= '9' ) { input_number = usart_rx_buffer[2] - '0'; } else { //print_invalid_enable_statement(); break; } } if (usart_received_chars >3) { // lets check the 2nd digit if ( usart_rx_buffer[3] >= '0' && usart_rx_buffer[3] <= '9' ) { input_number = 10*input_number + usart_rx_buffer[3] - '0'; } else { // okay as well ... if the second digit is missing .. // we might have trailing spaces // that's okay .. we just accept the first number. } } if (usart_received_chars>2) { usart_write_str((pU08)"\n I will switch "); if (enable) usart_write_str((pU08)"on "); else usart_write_str((pU08)"off "); // now we know, what the user wanted ... and we need to do it. switch (usart_rx_buffer[1]) { case 'r': if (enable) ad7719_enables[input_number/8] |= (1<<(input_number%8)); else { ad7719_enables[input_number/8] &= ~(1<<(input_number%8)); ad7719_channels_ready[input_number/8] &= ~(1<<(input_number%8)); } usart_write_str((pU08)" resistance channel "); usart_write_U08(input_number,2); usart_write_char('\n'); break; case 'v': if (enable) adc_enables[input_number/8] |= (1<<(input_number%8)); else { adc_enables[input_number/8] &= ~(1<<(input_number%8)); adc_channels_ready[input_number/8] &= ~(1<<(input_number%8)); } usart_write_str((pU08)" voltage channel "); usart_write_U08(input_number,2); usart_write_char('\n'); break; case 'h': if (enable) adc_enables[1] |= (1<<(input_number%4)); else { adc_enables[1] &= ~(1<<(input_number%4)); adc_channels_ready[1] &= ~(1<<(input_number%4)); } usart_write_str((pU08)" humidity channel "); usart_write_U08(input_number,2); usart_write_char('\n'); break; case 'p': if (enable) adc_enables[1] |= (1<<((input_number%4) + 4)); else { adc_enables[1] &= ~(1<<((input_number%4) + 4)); adc_channels_ready[1] &= ~(1<<((input_number%4) + 4)); } usart_write_str((pU08)" pressure channel "); usart_write_U08(input_number,2); usart_write_char('\n'); break; default: usart_write_str((pU08)"\n DAMN! this should never happen" "- enable/disable switch-case!\n"); break; } }// end of if usart_received_chars>2 --> this should not be necessary at all break; case 'b': usart_write_str((pU08)"\nheartbeat "); heartbeat_enable = true; if (usart_rx_buffer[1] == '0'){ heartbeat_enable = false; usart_write_str((pU08)"off\n"); } else { usart_write_str((pU08)"on\n"); } break; case 'G': // GET the Temperature channels, which are enabled ad7719_values_printed = false; for ( U08 i=0; i