diff --git a/master/master/config.h b/master/master/config.h --- a/master/master/config.h +++ b/master/master/config.h @@ -60,8 +60,8 @@ // USART config (serial.c) // -------------------------------------------------------------------------- -#define USART0_BAUDRATE 115200 -#define USART1_BAUDRATE 115200 +#define USART0_BAUDRATE 9600 +#define USART1_BAUDRATE 9600 // -------------------------------------------------------------------------- diff --git a/master/master/lib/serial.c b/master/master/lib/serial.c --- a/master/master/lib/serial.c +++ b/master/master/lib/serial.c @@ -11,26 +11,41 @@ */ #include "serial.h" +#include "led.h" #include "../config.h" #include +#include -// NOTE: USART ISRs for charachter reception are included in serparser.c +// NOTE: USART ISRs for character reception are included in serparser.c void serial0_setup() { - PORTD &= ~(1<>8); UBRR0L = (unsigned char)USART0_BAUD_PRESCALE; - UCSR0A |= (1<>8); diff --git a/master/master/lib/serparser.c b/master/master/lib/serparser.c --- a/master/master/lib/serparser.c +++ b/master/master/lib/serparser.c @@ -12,10 +12,11 @@ #include +#include #include "../config.h" #include "serial.h" #include "serparser.h" - +#include "led.h" // Circular buffer for incoming data uint8_t buffer[BUFFER_SIZE]; @@ -60,16 +61,26 @@ static void setParserState(uint8_t state } // Receive data on USART -ISR(USART0_RX_vect) + +char buffmeh[16]; + +ISR(USART0__RX_vect) { + led_on(POWER); buffer[bufferDataPosition % BUFFER_SIZE] = UDR0; bufferDataPosition = (bufferDataPosition + 1) % BUFFER_SIZE; + sprintf(buffmeh, "bdp: %d, bpp: %d \r\n", bufferDataPosition, bufferParsePosition); + serial0_sendString((buffmeh)); } + +#define DEBUG + // Parse data from circular buffer int serparser_parse(void) { + char byte; // Process first command (if any) on the circular buffer @@ -82,12 +93,16 @@ int serparser_parse(void) { if(byte == '[') // Start of frame; keep parsing { - serial0_sendString("PARSER: start ok\r\n"); + #ifdef DEBUG + serial0_sendString("start ok\r\n"); + #endif setParserState(STATE_GETID); } else // Not start of frame, reset { - serial0_sendString("PARSER: not start, reset\r\n"); + #ifdef DEBUG + serial0_sendString("not start\r\n"); + #endif setParserState(STATE_RESET); return PARSERESULT_NODATA; // no valid start bit; better luck next time. run the function the next time around the main loop. } @@ -98,13 +113,17 @@ int serparser_parse(void) { if(byte == MODULE_ID) // Message intended for this module; keep parsing { - serial0_sendString("SER: dest ok\r\n"); + #ifdef DEBUG + serial0_sendString("dest ok\r\n"); + #endif checksumCalc += byte; setParserState(STATE_GETDATATYPE); } else // Transmission is intended for another module; reset { - serial0_sendString("SER: bad dest, reset\r\n"); + #ifdef DEBUG + serial0_sendString("bad dest\r\n"); + #endif setParserState(STATE_RESET); } } @@ -112,7 +131,9 @@ int serparser_parse(void) // Get payload type ID else if(parserState == STATE_GETDATATYPE) { - serial0_sendString("SER: type ok\r\n"); + #ifdef DEBUG + serial0_sendString("type ok\r\n"); + #endif receivedDataType = byte; // Store the type of data receiving checksumCalc += byte; setParserState(STATE_GETDATA); @@ -123,7 +144,9 @@ int serparser_parse(void) { if (byte == ']') // End of frame { - serial0_sendString("SER: eof ok\r\n"); + #ifdef DEBUG + serial0_sendString("eof ok\r\n"); + #endif if(bufferParsePosition == bufferDataPosition) { // We are at the end of the line. No more data to parse. @@ -140,14 +163,18 @@ int serparser_parse(void) } else // Still receiving data { - serial0_sendString("SER: data ok\r\n"); + #ifdef DEBUG + serial0_sendString("data ok\r\n"); + #endif receivedPayload[dataLength] = byte; dataLength++; checksumCalc += byte; // Data buffer overrun protection if(dataLength > MAX_PAYLOAD_LEN) { - serial0_sendString("SER: buf overflow, reset\r\n"); + #ifdef DEBUG + serial0_sendString("buf ovf\r\n"); + #endif setParserState(STATE_RESET); return PARSERESULT_FAIL; } diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -54,7 +54,7 @@ int main(void) serial0_sendString("HAB Controller 1.0 - Initialized!\r\n"); serial0_sendString("---------------------------------\r\n\r\n"); - led_on(POWER); + //led_on(POWER); // Buffer for string operations char logbuf[32]; @@ -92,8 +92,8 @@ int main(void) led_on(STAT); snprintf(logbuf, 32, "%lu,%lu,%lu,\r\n", time_millis(), lastAprsBroadcast,lastLog); logger_log(logbuf); - serial0_sendString("SD Logger: "); - serial0_sendString(logBufPtr); + //serial0_sendString("SD Logger: "); + //serial0_sendString(logBufPtr); led_off(STAT); lastLog = time_millis(); } @@ -103,7 +103,7 @@ int main(void) { while(afsk_busy()); aprs_send(); // non-blocking - serial0_sendString("Initiating APRS transmission...\r\n"); + //serial0_sendString("Initiating APRS transmission...\r\n"); // Start getting values for next transmission isProcessing = true; @@ -115,10 +115,10 @@ int main(void) // TODO: If we receive a command, we should still process it even if we aren't isProcessing, right? // Maybe we should isolate the received command handling ("Execution") and the issuing of requests. - if(isProcessing) - { - isProcessing = slavesensors_process(parseResult); - } + //if(isProcessing) + //{ + // isProcessing = slavesensors_process(parseResult); + //} wdt_reset(); } } \ No newline at end of file