Changeset - a7b5f3ac92ad
[Not reviewed]
default
0 2 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-11 16:12:28
ethanzonca@CL-ENS241-08.cedarville.edu
Complete XBee timeout checking implemented
2 files changed with 47 insertions and 36 deletions:
0 comments (0 inline, 0 general)
master/master/lib/slavesensors.c
Show inline comments
 
@@ -118,30 +118,16 @@ void slavesensors_network_scan()
 
		serial0_sendString("ATND");
 
		serial0_sendChar(0x0D);
 
		
 
		// wait for scan to complete
 
		uint32_t scanStart = time_millis();
 
		uint32_t lastBlink = 0;
 
		
 
		// Scan data end when newline by itself ("")	
 
		int lineCount = 0;	
 
	
 
		while(1) 
 
		{
 
			while(!serial0_hasChar())
 
			// Wait for scan to complete. If we timeout, return.
 
			if(waitTimeout()) 
 
			{
 
				if(time_millis() - scanStart > 7000)
 
				{
 
					led_errorcode(ERROR_XBEETIMEOUT);
 
					return;
 
				}
 
				if(time_millis() - lastBlink > 50)
 
				{
 
					led_spin();
 
					
 
					lastBlink = time_millis();
 
				}
 
				wdt_reset();
 
			}
 
			
 
			bufPtr = serial0_readLine();
 

	
 
@@ -327,26 +313,42 @@ void slavesensors_exitAT()
 
	serial0_sendString("ATCN");
 
	serial0_sendChar(0x0D);
 
	_delay_ms(2);
 
	//// Wait until we get "OK"
 
	//int atStart = time_millis();
 
	//while(!serial0_hasChar()) {
 
		//if(time_millis() - atStart > 500) {
 
			//led_errorcode(ERROR_EXITAT);
 
			//wdt_reset();
 
			//return 1;
 
		//}
 
	//};
 
 
	if(waitTimeout()) 
 
	{
 
		return;
 
	}
 
	
 
	xbeeIsOk();
 
}
 
 
bool waitTimeout() {
 
	uint32_t scanStart = time_millis();
 
	uint32_t lastBlink = 0;
 
	while(!serial0_hasChar())
 
	{
 
		if(time_millis() - scanStart > 7000)
 
		{
 
			led_errorcode(ERROR_XBEETIMEOUT);
 
			return true;
 
		}
 
		if(time_millis() - lastBlink > 50)
 
		{
 
			led_spin();
 
			
 
			lastBlink = time_millis();
 
		}
 
		wdt_reset();
 
	}
 
	return false;
 
}
 
 
// Enter AT mode. Leaves "OK" on the buffer.
 
int slavesensors_enterAT() 
 
{
 
	// Delay guard time
 
	_delay_ms(2);
 
 
 
	serial0_ioff(); // interrupts MUST be off
 
	
 
	// Enter AT mode
 
@@ -354,22 +356,30 @@ int slavesensors_enterAT()
 
	serial0_sendChar('+');
 
	serial0_sendChar('+');
 
	_delay_ms(2);
 
	// Wait 1ms until we get "OK"
 
	//int atStart = time_millis();
 
	//while(!serial0_hasChar()) {
 
		//if(time_millis() - atStart > 500) {
 
			//led_errorcode(ERROR_ATFAIL);
 
			//wdt_reset();
 
			//return 1;
 
		//}
 
	//};	
 
	
 
	return xbeeIsOk();
 
 
}
 
 
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();
 
	}
 
	
 
	char* tmppntr = serial0_readLine();
 
	if(strcmp(tmppntr, "OK") == 0)
 
	{
master/master/lib/slavesensors.h
Show inline comments
 
@@ -30,6 +30,7 @@ enum sensorTypes // CMD ID#
 
	CAMERA,
 
};
 
 
bool waitTimeout();
 
char* slavesensors_getLabel(uint8_t sensorID);
 
char* slavesensors_slavename(uint8_t id);
 
bool slavesensors_dataReady();
0 comments (0 inline, 0 general)