Changeset - ecf8bc28f289
[Not reviewed]
default
0 1 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-29 17:08:39
ethanzonca@CL-ENS241-08.cedarville.edu
Fixed issue from previous commit where logger skipping was improprerly handled, freezing the microcontroller if the logger was the last discovered node.
1 file changed with 15 insertions and 0 deletions:
0 comments (0 inline, 0 general)
master/master/lib/slavesensors.c
Show inline comments
 
@@ -344,83 +344,98 @@ void slavesensors_process(uint8_t parseR
 
		uint8_t type = getPayloadType();
 
		uint16_t parsedVal = atoi(load);
 

	
 
		// Special case for slave telling us how many things we're about to get		
 
		if(type + 0x30 == '@') {
 
			
 
			#ifdef DEBUG_GETSLAVEDATA
 
			serial0_sendString("Got an awesome count!\r\n");
 
			serial0_sendChar(parsedVal + 0x30);
 
			serial0_sendString("\r\n");
 
			#endif
 
			
 
			numReadingsToExpect = parsedVal;
 
			currentSlaveSensor = 0;
 
			requesting = true;
 
		}
 
		else {
 
		
 
			// Store data in structure
 
			sensordata_set(currentSlave,type,parsedVal);
 
			
 
			#ifdef DEBUG_GETSLAVEDATA
 
			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;
 
			}
 
			// 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;
 
						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
 
			}
 
		}
 
	}
 
	
 
	// 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) {
 
			slavesensors_request();	// re-request
 
		}			
 
	}
 
	
 
	
 
	else if(parseResult == PARSERESULT_STILLPARSING)
 
	{
 
		return; // do nothing
 
	}
 
	else {
 
		// something is terribly wrong!
 
		return;
 
	}
 
}		
 
\ No newline at end of file
0 comments (0 inline, 0 general)