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 68 insertions and 32 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -108,25 +108,25 @@
 
#define D_CALLSIGN_ID   0
 

	
 
// Digipeating paths:
 
// (read more about digipeating paths here: http://wa8lmf.net/DigiPaths/ )
 
// The recommended digi path for a balloon is WIDE2-1 or pathless. The default
 
// is pathless. Uncomment the following two lines for WIDE2-1 path:
 
#define DIGI_PATH1      "WIDE2"
 
#define DIGI_PATH1_TTL  1
 

	
 
// 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
 

	
 

	
 
// --------------------------------------------------------------------------
 
// Logger config (logger.c)
 
// --------------------------------------------------------------------------
 
 
#define LOGGER_ID_EEPROM_ADDR 0x10
 
 
// Written to the beginning of every log file
master/master/lib/slavesensors.c
Show inline comments
 
@@ -50,96 +50,128 @@ void slavesensors_setup()
 
	slaves[1][3] = PRESSURE;
 
	slaves[1][4] = AMBIENTLIGHT;
 
	
 
	// slave 2
 
	slaves[2][0] = BOARDTEMP;
 
	slaves[2][1] = GEIGER;
 
	
 
	// slave 3
 
	slaves[3][0] = BOARDTEMP;
 
	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)
 
	{
 
		atOK = 1;
 
		
 
		serial0_sendString("ATND");
 
		serial0_sendChar(0x0D);
 
		// wait for scan to complete
 
		while(!serial0_hasChar()) {
 
			wdt_reset();
 
		}
 
		
 
		// 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");
 
		serial0_sendChar(0x0D);
 

	
 
	}
 
	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
 
	// will be multiple values separated by <CR>
 
	// 9 data lines per node, <CR> terminated, followed by a new line with only <CR> at the end of all nodes.
 
	
 
	// <CR> followed by another <CR> signifies end of scan data
 
	serial0_ion();
 
}
 
 
bool slavesensors_isrequesting() 
 
{
master/master/master.c
Show inline comments
 
@@ -30,47 +30,44 @@
 
#include "lib/trackuinoGPS/gpsMKa.h"
 

	
 
#include "lib/i2c.h"
 
#include "lib/boardtemp.h"
 

	
 
#include "lib/looptime.h"
 
#include "lib/slavesensors.h"
 
#include "lib/serparser.h"
 
#include "lib/sensordata.h"
 

	
 
int main(void)
 
{
 
    _delay_ms(1500); // warmup
 
	led_on(LED_POWER);
 
	
 
	// Initialize libraries
 
	time_setup();
 
	watchdog_setup(); // enables interrupts
 
	led_setup();	
 
	serial0_setup();
 
	serial1_setup();
 
	i2c_init();
 
	sensordata_setup(); // must happen before sensors/logger/afsk
 
	slavesensors_setup();
 
	logger_setup();
 
	afsk_setup();
 
	//\f
 
	serial0_sendString("\r\n---------------------------------\r\n");
 
	serial0_sendString("HAB Controller 1.0 - Initialized!\r\n");
 
	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];
 
	char debugBuf[128];
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	
 
	// Result of last parser run
 
	int parseResult = PARSERESULT_NODATA;
 
@@ -120,36 +117,43 @@ int main(void)
 
			if(!afsk_busy())
 
				serial1_ion();
 
			lastLedCycle = time_millis();	
 
		}
 
		
 
		// Periodic: Logging
 
		if(time_millis() - lastLog > LOGGER_RATE) 
 
		{
 
			led_on(LED_CYCLE);
 
			
 
			
 
			// 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();
 
		}		
 
		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
 
			while(afsk_busy());
 
			serial1_ioff();
 
			aprs_send(); // non-blocking
0 comments (0 inline, 0 general)