# HG changeset patch # User ethanzonca@CL-ENS241-08.cedarville.edu # Date 2013-02-11 17:05:35 # Node ID f12f7ddbf2320881f146928b450f9c1d3036eacd # Parent 887fa9c3d9686724d1087875f03ccf9d6630db08 Slave data aquisition fully functional with multiple slaves, fault-tolerant if slaves do not respond within timeout period 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 @@ -360,24 +360,10 @@ int slavesensors_enterAT() int xbeeIsOk() { - uint32_t scanStart = time_millis(); - uint32_t lastBlink = 0; - while(!serial0_hasChar()) - { - if(time_millis() - scanStart > 7000) - { - led_errorcode(ERROR_XBEETIMEOUT); - return; - } - if(time_millis() - lastBlink > 50) - { - led_spin(); - - lastBlink = time_millis(); - } - wdt_reset(); + if(waitTimeout(2000)) { + led_errorcode(ERROR_XBEETIMEOUT); + return 1; } - char* tmppntr = serial0_readLine(); if(strcmp(tmppntr, "OK") == 0) { @@ -407,6 +393,7 @@ void slavesensors_startprocess() } // TODO: inline. static. +uint32_t beginRequest = 0; void slavesensors_request() { if(currentSlave == loggerIndex) @@ -419,11 +406,77 @@ void slavesensors_request() } } slavesensors_selectnode(currentSlave); + beginRequest = time_millis(); serial_sendCommand("@"); // Request data! } -uint8_t numReadingsToExpect = 0; // number of values that the slave is about to send (testing) +uint8_t numReadingsToExpect = 0; // number of values that the slave is about to send + +void gotoNextSlaveOrSensor(bool fail) { + // If we finished all sensors for all slaves + + if(currentSlave >= (nodeCount-1) && currentSlaveSensor >= (numReadingsToExpect-1)) + { + #ifdef DEBUG_GETSLAVEDATA + serial0_sendString("We got all data for all slaves!\r\n"); + #endif + + dataReady = true; + currentSlave = 0; + currentSlaveSensor = 0; + requesting = false; + + if(!fail) + { + led_alert(); + } + + } + // If we finished up one slave, go to the next + else if(currentSlaveSensor >= (numReadingsToExpect-1)) + { + #ifdef DEBUG_GETSLAVEDATA + serial0_sendString("Finished up one slave, go to another.\r\n"); + #endif + + currentSlave++; + currentSlaveSensor = 0; + requesting = true; + + if(currentSlave == loggerIndex) + { + if(currentSlave >= (nodeCount-1)) + { + // We hit the last one, we're done. + dataReady = true; + currentSlave = 0; + currentSlaveSensor = 0; + requesting = false; + led_alert(); + return; + } + else + { + currentSlave++; // increment to the next slave after the logger + } + } + + slavesensors_request(); + } + // If we haven't finished a slave (or all of them), just get the next sensor of the current slave + else + { + #ifdef DEBUG_GETSLAVEDATA + serial0_sendString("Give me another sensor value..."); + #endif + + // request data for the current sensor of the current slave + currentSlaveSensor++; + requesting = true; + //slavesensors_request(); slaves now send all values at once, we don't need to keep requesting + } +} // TODO: needs to skip logger! @@ -440,6 +493,10 @@ void slavesensors_process(uint8_t parseR else if(parseResult == PARSERESULT_NODATA) { // Wait for data + if(requesting && time_millis() - beginRequest > 1000) { + // if we're requesting, we have no data, and we're over the timeout, this is bad! + gotoNextSlaveOrSensor(true); + } } // Finished reception of a message (one sensor data value). If not finished, send out command to get the next one @@ -483,63 +540,7 @@ void slavesensors_process(uint8_t parseR serial0_sendString("Stored some sexy data!\r\n"); #endif - // If we finished all sensors for all slaves - - if(currentSlave >= (nodeCount-1) && currentSlaveSensor >= (numReadingsToExpect-1)) - { - #ifdef DEBUG_GETSLAVEDATA - serial0_sendString("We got all data for all slaves!\r\n"); - #endif - - dataReady = true; - currentSlave = 0; - currentSlaveSensor = 0; - requesting = false; - led_alert(); - } - // If we finished up one slave, go to the next - else if(currentSlaveSensor >= (numReadingsToExpect-1)) - { - #ifdef DEBUG_GETSLAVEDATA - serial0_sendString("Finished up one slave, go to another.\r\n"); - #endif - - currentSlave++; - currentSlaveSensor = 0; - requesting = true; - - if(currentSlave == loggerIndex) - { - if(currentSlave >= (nodeCount-1)) - { - // We hit the last one, we're done. - dataReady = true; - currentSlave = 0; - currentSlaveSensor = 0; - requesting = false; - led_alert(); - return; - } - else - { - currentSlave++; // increment to the next slave after the logger - } - } - - slavesensors_request(); - } - // If we haven't finished a slave (or all of them), just get the next sensor of the current slave - else - { - #ifdef DEBUG_GETSLAVEDATA - serial0_sendString("Give me another sensor value..."); - #endif - - // request data for the current sensor of the current slave - currentSlaveSensor++; - requesting = true; - //slavesensors_request(); slaves now send all values at once, we don't need to keep requesting - } + gotoNextSlaveOrSensor(false); } } diff --git a/master/master/lib/slavesensors.h b/master/master/lib/slavesensors.h --- a/master/master/lib/slavesensors.h +++ b/master/master/lib/slavesensors.h @@ -41,6 +41,7 @@ uint8_t slavesensors_getselectednode(); void slavesensors_selectnode(uint8_t nodeIndex); void slavesensors_startprocess(); void slavesensors_request(); +void gotoNextSlaveOrSensor(bool fail); void slavesensors_process(uint8_t parseResult); int xbeeIsOk(); void slavesensors_selectlogger();