# HG changeset patch # User ethanzonca@CL-ENS241-08.cedarville.edu # Date 2013-02-11 16:12:28 # Node ID a7b5f3ac92adcd971f158579d9561a7727168f42 # Parent f1ded7817da797545ae9e10e3d87707db5232ad5 Complete XBee timeout checking implemented 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 @@ -117,30 +117,16 @@ void slavesensors_network_scan() led_on(LED_CYCLE); 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(); + return; } 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) { 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 @@ -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();