Changeset - e68fbe17cd36
[Not reviewed]
default
0 2 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-17 21:59:23
ethanzonca@CL-ENS241-08.cedarville.edu
Added XBEE log destination recognized by node identifier
2 files changed with 20 insertions and 1 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -33,48 +33,51 @@
 
#define ERROR_XBEETIMEOUT 5
 
#define ERROR_NOXBEE 6
 
 
#define ERROR_CRAP 15
 
 
// --------------------------------------------------------------------------
 
// Slave Sensors config (slavesensors.c)
 
// --------------------------------------------------------------------------
 
 
// NOT USED. Could integrate into slavesensors.c setup function for configurability eventually.
 
// Currently manual configuration of sensors is done in slavesensors.c
 
#define SLAVE0_SENSORS BOARDTEMP
 
#define SLAVE1_SENSORS BOARDTEMP | HUMIDITY | TEMPERATURE | PRESSURE | AMBIENTLIGHT
 
#define SLAVE2_SENSORS BOARDTEMP | GEIGER
 
#define SLAVE3_SENSORS BOARDTEMP | CAMERA
 
#define SLAVE4_SENSORS NONE
 
#define SLAVE5_SENSORS NONE
 
#define SLAVE6_SENSORS NONE
 
#define SLAVE7_SENSORS NONE
 
 
// MAX_SLAVES should be one more than the number of slaves we actually have (loop ends when next slave first sensor is NONE)
 
#define MAX_SLAVES 8
 
#define MAX_SLAVE_SENSORS 8
 
 
// Node identifier of log destination xbee
 
#define XBEE_LOGDEST_NAME "HAB-LOGGER"
 
 
// --------------------------------------------------------------------------
 
// Command Parser config (serparser.c)
 
// --------------------------------------------------------------------------
 
 
// Maximum payload size of command
 
#define MAX_PAYLOAD_LEN 16
 
 
// Circular serial buffer size. Must be at least MAX_CMD_LEN + 5
 
#define BUFFER_SIZE 32 
 
 
// Public broadcast address
 
#define BROADCAST_ADDR 0 
 
 
 
// --------------------------------------------------------------------------
 
// GPS config (xxx.c)
 
// --------------------------------------------------------------------------
 
#define NMEABUFFER_SIZE 150
 
 
// --------------------------------------------------------------------------
 
// USART config (serial.c)
 
// --------------------------------------------------------------------------
 
 
#define USART0_BAUDRATE 115200
master/master/lib/slavesensors.c
Show inline comments
 
@@ -46,48 +46,49 @@ void slavesensors_setup()
 
	// slave 1
 
	slaves[1][0] = BOARDTEMP;
 
	slaves[1][1] = HUMIDITY;
 
	slaves[1][2] = TEMPERATURE;
 
	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];
 
uint8_t loggerIndex = 255;
 

	
 
void slavesensors_network_scan() {
 
	serial0_ioff();
 
	
 
	int atOK;
 
	
 
	serial0_sendString("Beginning network scan...\r\n\r\n");
 
	
 
	_delay_ms(500); // xbee warmup
 
	wdt_reset();
 
	
 
	atOK = slavesensors_enterAT();
 
		
 
	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 
 
	
 
	uint8_t nodeCount = 0;
 
	
 
	// wait for OK
 
	//todo
 
	if(atOK == 0)
 
	{
 
		serial0_sendString("ATND");
 
@@ -143,53 +144,68 @@ void slavesensors_network_scan() {
 
	
 
	led_on(LED_SIDEBOARD);
 
	_delay_ms(200);
 
	led_off(LED_SIDEBOARD);
 

	
 
	#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);
 
	}
 
	serial0_sendString("\r\n");
 
	if(atOK != 0) {
 
		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
 
	
 
	slavesensors_selectnode(1);
 
	for(int i=0; i<nodeCount; i++) 
 
	{
 
		if(strcmp(slaveNames[i], XBEE_LOGDEST_NAME) == 0) 
 
		{
 
			loggerIndex = i;
 
		}
 
	}
 
	
 
	slavesensors_loggerdest();
 
	
 
	serial0_ion();
 
}
 
 
void slavesensors_loggerdest() 
 
{
 
	if(loggerIndex != 255) {
 
		slavesensors_selectnode(loggerIndex);
 
	}	
 
}
 
 
void slavesensors_exitAT() 
 
{
 
	// Exit AT
 
	serial0_sendString("ATCN");
 
	serial0_sendChar(0x0D);
 
	xbeeIsOk(); // wait for OK
 
}
 
 
// Enter AT mode. Leaves "OK" on the buffer.
 
int slavesensors_enterAT() 
 
{
 
	// Delay guard time
 
	_delay_ms(1);
 
	
 
	// Enter AT mode
 
	serial0_sendChar('+'); // Enter AT mode
 
	serial0_sendChar('+');
 
	serial0_sendChar('+');
 
	
 
	// Wait 1ms until we get "OK"
 
	int atStart = time_millis();
 
	while(!serial0_hasChar()) {
 
		if(time_millis() - atStart > 500) {
 
			led_errorcode(ERROR_XBEETIMEOUT);
0 comments (0 inline, 0 general)