# HG changeset patch # User ethanzonca@CL-ENS241-08.cedarville.edu # Date 2013-01-17 20:48:21 # Node ID 73066872237e6e5b062acacde1cb88c9431165f3 # Parent b68fde48a3b774d9dd0b048484fd63fd05c6814a Completed network scanning functionality diff --git a/master/master/config.h b/master/master/config.h --- a/master/master/config.h +++ b/master/master/config.h @@ -117,7 +117,7 @@ // APRS comment: this goes in the comment portion of the APRS message. You // might want to keep this short. The longer the packet, the more vulnerable // it is to noise. -#define APRS_COMMENT "CU HAB TEST" +#define APRS_COMMENT "[A-30.5 B45.64 C99542]" // Transmit the APRS sentence every X milliseconds #define APRS_TRANSMIT_PERIOD 20000 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 @@ -59,31 +59,40 @@ void slavesensors_setup() slaves[3][1] = CAMERA; } + + +#define DEBUG_NETWORKSCAN char* bufPtr = 0x00; +char debugBuf[64]; +char slaveAddressLow[6][9]; +char slaveAddressHigh[6][9]; + void slavesensors_network_scan() { serial0_ioff(); int atOK; - serial0_sendString("Beginning network scan...\r\n"); + serial0_sendString("Beginning network scan...\r\n\r\n"); - // Delay guard period - _delay_ms(500); - _delay_ms(500); + _delay_ms(500); // xbee warmup // Enter AT mode serial0_sendChar('+'); // Enter AT mode serial0_sendChar('+'); serial0_sendChar('+'); - while(!serial0_hasChar()) { - wdt_reset(); - } + // Wait 1ms until we get "OK" + while(!serial0_hasChar()); + bufPtr = serial0_readLine(); char nameString[20] = "NONE"; + char slaveNames[6][16]; // Hold 16-char addresses of max 6 nodes, we only need them for debug so they are local + + int nodeCount = 0; + // wait for OK //todo if(strcmp(bufPtr, "OK") == 0) @@ -99,14 +108,37 @@ void slavesensors_network_scan() { // Scan data end when newline by itself ("") int lineCount = 0; + while(1) { bufPtr = serial0_readLine(); - if(lineCount == 3) { - strcpy(nameString, bufPtr); + + // If we're starting a new block but got a newline instead, we're done! + if(lineCount == 0 && strcmp(bufPtr, "") == 0) { + break; + } + + if(lineCount == 1) { + strcpy(slaveAddressHigh[nodeCount], bufPtr); + } + else if(lineCount == 2) { + strcpy(slaveAddressLow[nodeCount], bufPtr); } - if(strcmp(bufPtr, "") == 0) - break; - lineCount++; + else if(lineCount == 3) { + strcpy(nameString, bufPtr); + strcpy(slaveNames[nodeCount], bufPtr); + } + + // If we've finished one chunk (including the newline after it). Can't be else if because it controls increment. + if(lineCount == 9) { + // bufPtr should be null at this point, because we read in a newlinem after one chunk + nodeCount++; + lineCount = 0; + } + else { + lineCount++; + } + + } // Exit AT serial0_sendString("ATCN"); @@ -116,21 +148,21 @@ void slavesensors_network_scan() { else { atOK = 0; } + led_on(LED_SIDEBOARD); _delay_ms(200); - //serial0_sendString("ATND"); // Scan all nodes - + led_off(LED_SIDEBOARD); - - led_on(LED_SIDEBOARD); - _delay_ms(500); - - serial0_sendString("First found node is: "); - serial0_sendString(nameString); - serial0_sendString("\r\n"); + #ifdef DEBUG_NETWORKSCAN + serial0_sendString("Discovered: \r\n"); + for(int i=0; i time: %s lat: %s lon: %s speed: %s hdop: %s course: %s\r\n", - get_timestamp(),get_latitude(),get_longitude(),get_speedKnots(),get_hdop(), get_course()); + //snprintf(debugBuf, 128, "GPS> time: %s lat: %s lon: %s speed: %s hdop: %s course: %s\r\n", + //get_timestamp(),get_latitude(),get_longitude(),get_speedKnots(),get_hdop(), get_course()); //serial0_sendString(debugBuf); + // Turn on sideboard LED if we have a fix + if(strcmp("99.99", get_hdop()) == 0) { + led_off(LED_SIDEBOARD); + } + else { + led_on(LED_SIDEBOARD); + } sensors_readBoardTemp(); // i2c read, 400k - snprintf(logbuf, 128, "%lu,%d,%uF,%s,%s,%s,%s,%s\r\n", time_millis(), sensors_getBoardTemp(),get_timestamp(),get_latitude(),get_longitude(),get_speedKnots(),get_hdop(), get_course()); + snprintf(logbuf, 128, "%lu,%d,%u,%s,%s,%s,%s,%s\r\n", time_millis(), sensors_getBoardTemp(),get_timestamp(),get_latitude(),get_longitude(),get_speedKnots(),get_hdop(), get_course()); logger_log(logbuf); // Print out logger debug - //serial0_sendString("LOG> "); - //serial0_sendString(logbuf); + serial0_sendString("LOG> "); + serial0_sendString(logbuf); led_off(LED_CYCLE); lastLog = time_millis();