# HG changeset patch # User ethanzonca@CL-ENS241-08.cedarville.edu # Date 2013-02-05 17:01:36 # Node ID 5c3e3bff1c5618e0276d7bfaf07495428c5cd339 # Parent 0568291d2d64cfe9f5be63cca35b0bb816033844 Code formatting and additional commenting diff --git a/master/master/lib/gps.c b/master/master/lib/gps.c --- a/master/master/lib/gps.c +++ b/master/master/lib/gps.c @@ -46,29 +46,34 @@ int numBytes = 0; char tramsmissionType[7]; char timestamp[12]; //hhmmss.ss -char* get_timestamp() { +char* get_timestamp() +{ return timestamp; } char latitude[14]; //lllll.lla -char* get_latitude() { +char* get_latitude() +{ return latitude; } char longitude[14]; //yyyyy.yyb -char* get_longitude() { +char* get_longitude() +{ return longitude; } char quality; //quality for GGA and validity for RMC char numSatellites[4]; -char* get_sv() { +char* get_sv() +{ return numSatellites; } char hdop[6]; //xx.x -char* get_hdop() { +char* get_hdop() +{ return hdop; } @@ -79,21 +84,25 @@ char stationID[8]; //blank - included fo char checksum[3]; //xx char knots[8]; //xxx.xx -char* get_speedKnots() { +char* get_speedKnots() +{ return knots; } char course[8]; //xxx.x -char* get_course() { +char* get_course() +{ return course; } char dayofmonth[9]; //ddmmyy -char* get_dayofmonth() { +char* get_dayofmonth() +{ return dayofmonth; } -bool gps_hasfix() { +bool gps_hasfix() +{ return strcmp("99.99", get_hdop()); } @@ -176,14 +185,16 @@ void parse_gps_transmission(void){ - while(nmeaBufferDataPosition != nmeaBufferParsePosition) { - led_on(LED_ACTIVITY); + while(nmeaBufferDataPosition != nmeaBufferParsePosition) + { + led_on(LED_ACTIVITY); byte = nmeaBuffer[nmeaBufferParsePosition]; if(decodeState == INITIALIZE) //start of transmission sentence { - if(byte == '$') { + if(byte == '$') + { #ifdef DEBUG_NMEA serial0_sendString("found $\r\n"); #endif @@ -194,7 +205,8 @@ void parse_gps_transmission(void){ calculatedChecksum = 0; } - else { + else + { setParserState(INITIALIZE); } } diff --git a/master/master/lib/led.c b/master/master/lib/led.c --- a/master/master/lib/led.c +++ b/master/master/lib/led.c @@ -19,7 +19,8 @@ // Configure port direction and initial state of LEDs void led_setup() { - for(int i=0; i= 240 && pulseUp) pulseUp = false; else if(OCR0B <= 12 && !pulseUp); @@ -114,5 +122,4 @@ void led_pulsate() { OCR0B+=5; else OCR0B-=5; - } \ No newline at end of file diff --git a/master/master/lib/logger.c b/master/master/lib/logger.c --- a/master/master/lib/logger.c +++ b/master/master/lib/logger.c @@ -87,7 +87,8 @@ void logger_setup() snprintf(filename, 16, "data%d.csv",++logid); // TODO: Catch errors here - if(fat_create_file(dd, filename, &directory) == 0) { + if(fat_create_file(dd, filename, &directory) == 0) + { led_errorcode(ERROR_SD_FILE); } diff --git a/master/master/lib/sensordata.c b/master/master/lib/sensordata.c --- a/master/master/lib/sensordata.c +++ b/master/master/lib/sensordata.c @@ -21,55 +21,65 @@ #include "gps.h" #include "logger.h" +// Slave sensor reading storage int32_t slaves[MAX_NUM_SLAVES][MAX_NUM_SENSORS]; void sensordata_setup() { - for(int i=0; i MAX_PAYLOAD_LEN) { + if(payloadLength > MAX_PAYLOAD_LEN) + { #ifdef DEBUG serial0_sendString("ovf\r\n"); #endif setParserState(STATE_RESET); return PARSERESULT_FAIL; } - else { + else + { // Set state. MUST call even though state is maintained to update parse position setParserState(STATE_GETDATA); return PARSERESULT_STILLPARSING; @@ -181,14 +178,16 @@ int serparser_parse(void) else if(STATE_GETCHECKSUM) { // TODO: Compare checksums - if(byte == checksumCalc) { + if(byte == checksumCalc) + { #ifdef DEBUG serial0_sendString("check\r\n"); #endif setParserState(STATE_RESET); return PARSERESULT_PARSEOK; } - else { + else + { #ifdef DEBUG serial0_sendString("bcheck\r\n"); #endif diff --git a/master/master/lib/slavesensors.c b/master/master/lib/slavesensors.c --- a/master/master/lib/slavesensors.c +++ b/master/master/lib/slavesensors.c @@ -52,14 +52,16 @@ const char *const labelLookup[] PROGMEM }; char labelBuffer[15]; // Size to length of label -char* slavesensors_getLabel(uint8_t sensorID) { +char* slavesensors_getLabel(uint8_t sensorID) +{ if(sensorID < 9) { strncpy_P(labelBuffer,(char*)pgm_read_word(&(labelLookup[sensorID])),15); return labelBuffer; } - else { + else + { return NULL; } } @@ -87,11 +89,13 @@ uint8_t loggerIndex = 255; uint8_t nodeCount = 0; bool dataReady = false; -char* slavesensors_slavename(uint8_t id) { +char* slavesensors_slavename(uint8_t id) +{ return slaveNames[id]; } -void slavesensors_network_scan() { +void slavesensors_network_scan() +{ serial0_ioff(); int atOK; @@ -116,8 +120,10 @@ void slavesensors_network_scan() { // wait for scan to complete uint16_t scanStart = time_millis(); - while(!serial0_hasChar()) { - if(time_millis() - scanStart > 7000) { + while(!serial0_hasChar()) + { + if(time_millis() - scanStart > 7000) + { led_errorcode(ERROR_XBEETIMEOUT); return; } @@ -126,31 +132,38 @@ void slavesensors_network_scan() { // Scan data end when newline by itself ("") int lineCount = 0; - while(1) { + while(1) + { bufPtr = serial0_readLine(); // If we're starting a new block but got a newline instead, we're done! - if(lineCount == 0 && strcmp(bufPtr, "") == 0) { + if(lineCount == 0 && strcmp(bufPtr, "") == 0) + { break; } - if(lineCount == 1) { + if(lineCount == 1) + { strncpy(slaveAddressHigh[nodeCount],bufPtr, 9); } - else if(lineCount == 2) { + else if(lineCount == 2) + { strncpy(slaveAddressLow[nodeCount],bufPtr, 9); } - else if(lineCount == 3) { + else if(lineCount == 3) + { strncpy(slaveNames[nodeCount], bufPtr, 15); } // If we've finished one chunk (including the newline after it). Can't be else if because it controls increment. - if(lineCount == 9) { + if(lineCount == 9) + { // bufPtr should be null at this point, because we read in a newline after one chunk nodeCount++; lineCount = 0; } - else { + else + { lineCount++; } @@ -161,7 +174,8 @@ void slavesensors_network_scan() { } // Display number of found nodes on spinning indicator - switch(nodeCount) { + switch(nodeCount) + { case 0: break; case 3: @@ -183,12 +197,14 @@ void slavesensors_network_scan() { char debugBuf[64]; serial0_sendString("Discovered: \r\n"); - for(int i=0; i= (nodeCount)) { + if(currentSlave >= (nodeCount)) + { slavesensors_selectlogger(); return; } @@ -381,14 +406,16 @@ uint8_t numReadingsToExpect = 0; // numb // TODO: needs to skip logger! void slavesensors_process(uint8_t parseResult) { - if(!requesting) { + if(!requesting) + { // we got a command when we didn't request anything. probably skip it. return; } // TODO: timeout. If we're at NODATA for a long time and we are requesting, that's an issue. // TODO: If we time out, WE NEED TO RESET THE PARSER. It could be in a bad state. - else if(parseResult == PARSERESULT_NODATA) { + else if(parseResult == PARSERESULT_NODATA) + { // Wait for data } @@ -410,7 +437,8 @@ void slavesensors_process(uint8_t parseR int32_t parsedVal = strtol(load, NULL, 10);//atoi(load); // Special case for slave telling us how many things we're about to get - if(type + 0x30 == '@') { + if(type + 0x30 == '@') + { #ifdef DEBUG_GETSLAVEDATA serial0_sendString("Got an awesome count!\r\n"); @@ -422,7 +450,8 @@ void slavesensors_process(uint8_t parseR currentSlaveSensor = 0; requesting = true; } - else { + else + { // Store data in structure sensordata_set(currentSlave,type,parsedVal); @@ -456,8 +485,10 @@ void slavesensors_process(uint8_t parseR currentSlaveSensor = 0; requesting = true; - if(currentSlave == loggerIndex) { - if(currentSlave >= (nodeCount-1)) { + if(currentSlave == loggerIndex) + { + if(currentSlave >= (nodeCount-1)) + { // We hit the last one, we're done. dataReady = true; currentSlave = 0; @@ -466,7 +497,8 @@ void slavesensors_process(uint8_t parseR led_alert(); return; } - else { + else + { currentSlave++; // increment to the next slave after the logger } } @@ -490,8 +522,10 @@ void slavesensors_process(uint8_t parseR // If fail, try retransmit. Or we could skip and hit it next time. // TODO: Maximum number of retransmissions - else if(parseResult == PARSERESULT_FAIL) { - if(requesting) { + else if(parseResult == PARSERESULT_FAIL) + { + if(requesting) + { slavesensors_request(); // re-request } } @@ -501,7 +535,8 @@ void slavesensors_process(uint8_t parseR { return; // do nothing } - else { + else + { // something is terribly wrong! return; } diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -72,7 +72,8 @@ int main(void) { // Periodic: LED execution indicator - if(time_millis() - lastLedCycle > LEDCYCLE_RATE) { + if(time_millis() - lastLedCycle > LEDCYCLE_RATE) + { led_spin(); // Enable GPS serial interrupts if we aren't doing AFSK @@ -90,10 +91,12 @@ int main(void) heater_regulateTemp(); // Turn on sideboard LED if we have a fix - if(gps_hasfix()) { + if(gps_hasfix()) + { led_on(LED_SIDEBOARD); } - else { + else + { led_off(LED_SIDEBOARD); } @@ -108,7 +111,8 @@ int main(void) // Periodic: Data Request - if(time_millis() - lastDataReq > DATAREQUEST_RATE) { + if(time_millis() - lastDataReq > DATAREQUEST_RATE) + { // Start getting values for next transmission if(slavesensors_isrequesting())