Changeset - 73066872237e
[Not reviewed]
default
0 3 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-17 20:48:21
ethanzonca@CL-ENS241-08.cedarville.edu
Completed network scanning functionality
3 files changed with 67 insertions and 31 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -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
master/master/lib/slavesensors.c
Show inline comments
 
@@ -60,30 +60,39 @@ void slavesensors_setup()
 
	
 
}
 
 
 
#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,15 +108,38 @@ 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;
 
			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");
 
		serial0_sendChar(0x0D);
 
@@ -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<nodeCount; i++) {
 
		snprintf(debugBuf, 64, "  %s - %s%s\r\n", slaveNames[i],slaveAddressHigh,slaveAddressLow[i]);
 
		serial0_sendString(debugBuf);
 
	}
 
	
 
	if(atOK != 1) {
 
		serial0_sendString("AT mode failed \r\n");
 
	}
 
	#endif
 
	
 
	
 
	// Wait for response
master/master/master.c
Show inline comments
 
@@ -39,7 +39,7 @@
 

	
 
int main(void)
 
{
 
    _delay_ms(1500); // warmup
 
	led_on(LED_POWER);
 
	
 
	// Initialize libraries
 
	time_setup();
 
@@ -58,10 +58,7 @@ int main(void)
 
	serial0_sendString("---------------------------------\r\n");
 
	serial0_sendString("\r\nHello.\r\n\r\n");
 
	
 
	slavesensors_network_scan();
 
	
 
	led_on(LED_POWER);
 
	led_off(LED_SIDEBOARD);
 
	slavesensors_network_scan(); // This can take a little while
 
	
 
	// Buffer for string operations
 
	char logbuf[128];
 
@@ -129,18 +126,25 @@ int main(void)
 
			
 
			
 
			// Print out GPS debug
 
			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());
 
			//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();
0 comments (0 inline, 0 general)