Changeset - e3153d5a767c
[Not reviewed]
default
0 6 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-21 20:59:15
ethanzonca@CL-ENS241-08.cedarville.edu
Implemented new serial protocol and slave sensor data storage technique, appears to be functional.
6 files changed with 74 insertions and 87 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -43,20 +43,8 @@
 
// 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
 
#define MAX_NUM_SLAVES 5  // Maximum number of nodes in the system
 
#define MAX_NUM_SENSORS 20 // Maximum number of unique types of sensors in the system
 
 
// Node identifier of log destination xbee
 
#define XBEE_LOGDEST_NAME "HAB-LOGGER"
master/master/lib/gps.c
Show inline comments
 
@@ -120,15 +120,10 @@ enum decodeState {
 
}decodeState;
 

	
 

	
 
char debugBuff[128];
 

	
 
ISR(USART1_RX_vect)
 
{
 
	nmeaBuffer[nmeaBufferDataPosition % NMEABUFFER_SIZE] = UDR1;
 
	nmeaBufferDataPosition = (nmeaBufferDataPosition + 1) % NMEABUFFER_SIZE;
 
	//serial0_sendChar(UDR1);
 
	//snprintf(debugBuff, 32, "GPS: bdp: %d, bpp: %d decodestate: %u \r\n", nmeaBufferDataPosition, nmeaBufferParsePosition, decodeState);
 
	//serial0_sendString((debugBuff));
 
}
 

	
 

	
 
@@ -163,9 +158,6 @@ void parse_gps_transmission(void){
 
		
 
		byte = nmeaBuffer[nmeaBufferParsePosition];
 
		
 
		//snprintf(debugBuff, 64, "GPSParse: byte [%c] decodestate: %u bp: %u pp: %u\r\n",  byte, decodeState, nmeaBufferDataPosition, nmeaBufferParsePosition);
 
		//serial0_sendString((debugBuff));
 
		
 
		if(decodeState == INITIALIZE) //start of transmission sentence
 
		{
 
			if(byte == '$') {
 
@@ -642,9 +634,8 @@ void parse_gps_transmission(void){
 
				}
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("OMG GOT TO CHECKSUM!\r\n");
 
				#endif
 
				#endif
 
				
 
				serial0_sendString((debugBuff));
 
				setParserState(INITIALIZE);
 
				numBytes = 0; //prep for next phase of parse
 
			}
master/master/lib/sensordata.c
Show inline comments
 
@@ -13,33 +13,31 @@
 
#include "../config.h"
 
#include "sensordata.h"
 

	
 
int16_t boardTemps[MAX_SLAVES];
 
uint16_t variousSensors[MAX_SLAVES * (MAX_SLAVE_SENSORS - 1)];
 
int16_t slaves[MAX_NUM_SLAVES][MAX_NUM_SENSORS];
 

	
 
void sensordata_setup() 
 
{
 
	for(int i=0; i<MAX_SLAVES; i++)
 
	{
 
		boardTemps[i] = 0;
 
	for(int i=0; i<MAX_NUM_SLAVES; i++) {
 
		for(int j=0; j<MAX_NUM_SLAVES; j++) {
 
			slaves[i][j] = -32768; // minimum value of 16 bit integer
 
		}
 
	}
 
}
 
 
void sensordata_set(uint8_t type, uint16_t value) 
 
void sensordata_set(uint8_t nodeID, uint8_t type, uint16_t value)
 
{
 
	variousSensors[type] = value;
 
}
 
 
uint16_t sensordata_get(uint8_t type) 
 
{
 
	return variousSensors[type];
 
	if(nodeID < MAX_NUM_SLAVES) {
 
		slaves[nodeID][type] = value;
 
	}	
 
}
 
 
void sensordata_setBoardTemp(uint8_t slaveID, int16_t value) 
 
uint16_t sensordata_get(uint8_t nodeID, uint8_t type) 
 
{
 
	boardTemps[slaveID] = value;
 
	// Avoid reading out of bad places!
 
	if(nodeID < MAX_NUM_SLAVES) {
 
		return slaves[nodeID][type];
 
	}
 
	else {
 
		return 0;
 
	}
 
}
 
 
int16_t sensordata_getBoardTemp(uint8_t slaveID)
 
{
 
	return boardTemps[slaveID];
 
}
 
\ No newline at end of file
master/master/lib/sensordata.h
Show inline comments
 
@@ -17,8 +17,8 @@
 
#include "slavesensors.h"
 
 
void sensordata_setup();
 
void sensordata_set(uint8_t type, uint16_t value);
 
uint16_t sensordata_get(uint8_t type);
 
void sensordata_set(uint8_t nodeID, uint8_t type, uint16_t value);
 
uint16_t sensordata_get(uint8_t nodeID, uint8_t type);
 
void sensordata_setBoardTemp(uint8_t slaveID, int16_t value);
 
int16_t sensordata_getBoardTemp(uint8_t slaveID);
 
master/master/lib/serparser.c
Show inline comments
 
@@ -90,7 +90,7 @@ ISR(USART0_RX_vect)
 
 
 
 
#define DEBUG
 
//#define DEBUG
 
 
// Parse data from circular buffer
 
int serparser_parse(void)
 
@@ -129,7 +129,7 @@ int serparser_parse(void)
 
			#ifdef DEBUG
 
			serial0_sendString("type\r\n");
 
			#endif
 
			receivedPayloadType = byte; // Store the type of data receiving
 
			receivedPayloadType = byte - 0x30; // Store the type of data receiving
 
			checksumCalc += byte;
 
			setParserState(STATE_GETDATA);
 
		}
 
@@ -194,7 +194,8 @@ int serparser_parse(void)
 
				#endif
 
				setParserState(STATE_RESET);
 
				
 
				return PARSERESULT_FAIL;
 
				return PARSERESULT_PARSEOK;
 
				// !!!!!!!!!!!!!DEBUGGGGG ignore checksum ///// return PARSERESULT_FAIL;
 
			}
 
			
 
			/*
master/master/lib/slavesensors.c
Show inline comments
 
@@ -24,22 +24,18 @@
 
uint8_t currentSlave = 0;
 
uint8_t currentSlaveSensor = 0;
 
 
uint16_t slaves[MAX_SLAVES][MAX_SLAVE_SENSORS];
 
 
bool requesting = false;
 
 
void slavesensors_setup() 
 
{
 
 
	
 
}
 

	
 
 
#define DEBUG_NETWORKSCAN
 
 
char* bufPtr = 0x00;
 
char debugBuf[64];
 
char slaveAddressLow[6][9];
 
char slaveAddressHigh[6][9];
 
char slaveAddressLow[MAX_NUM_SLAVES][9];
 
char slaveAddressHigh[MAX_NUM_SLAVES][9];
 
uint8_t loggerIndex = 255;
 
uint8_t nodeCount = 0;
 

	
 
@@ -60,12 +56,9 @@ void slavesensors_network_scan() {
 

	
 
	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 
 
	
 
	
 
	char slaveNames[MAX_NUM_SLAVES][16]; // Hold 16-char addresses of max MAX_NUM_SLAVES nodes, local so the memory can be reused
 
	
 
	// wait for OK
 
	//todo
 
	if(atOK == 0)
 
	{
 
		led_on(LED_CYCLE);
 
@@ -105,7 +98,7 @@ void slavesensors_network_scan() {
 
			
 
			// 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
 
				// bufPtr should be null at this point, because we read in a newline after one chunk
 
				nodeCount++;
 
				lineCount = 0;
 
			}
 
@@ -139,6 +132,8 @@ void slavesensors_network_scan() {
 
	led_off(LED_SIDEBOARD);
 

	
 
	#ifdef DEBUG_OUTPUT
 
	
 
	char debugBuf[64];
 
	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]);
 
@@ -148,6 +143,7 @@ void slavesensors_network_scan() {
 
	if(atOK != 0) {
 
		serial0_sendString("AT mode failed \r\n");
 
	}
 
	
 
	#endif
 
	
 
	for(int i=0; i<nodeCount; i++) 
 
@@ -245,6 +241,8 @@ int xbeeIsOk()
 
	}
 
}
 
 
 
 
bool slavesensors_isrequesting() 
 
{
 
	return requesting;	
 
@@ -264,7 +262,7 @@ void slavesensors_request()
 
}
 
 
 
int numValues = 0; // number of values that the slave is about to send (testing)
 
int numReadingsToExpect = 0; // number of values that the slave is about to send (testing)
 
 
 
// TODO: needs to skip logger!
 
@@ -287,37 +285,48 @@ void slavesensors_process(uint8_t parseR
 
		// ASCII payload
 
		uint8_t len = getPayloadLength();
 
		uint8_t* load = getPayload();
 
		
 
		uint8_t type = getPayloadType();
 

	
 
		
 
		uint16_t parsedVal = atoi(load);
 
		
 
		// Store data in structure
 
		//sensordata_set(slaves[currentSlave][currentSlaveSensor], parsedVal);
 
		
 
		// If we finished all sensors for all slaves
 
		if(currentSlave >= nodeCount && currentSlaveSensor >= numValues)
 
		{
 

	
 
		// Special case for slave telling us how many things we're about to get		
 
		if(type + 0x30 == '@') {
 
			serial0_sendString("Got an awesome count!\r\n");
 
			serial0_sendChar(parsedVal + 0x30);
 
			serial0_sendString("\r\n");
 
			numReadingsToExpect = parsedVal;
 
			currentSlave = 0;
 
			currentSlaveSensor = 0;
 
			requesting = false;
 
			requesting = true;
 
		}
 
		// If we finished up one slave, go to the next
 
		else if(currentSlaveSensor >= numValues) 
 
		{
 
			currentSlave++;
 
			currentSlaveSensor = 0;
 
			requesting = true;
 
			slavesensors_request();
 
		}
 
		// If we haven't finished a slave (or all of them), just get the next sensor of the current slave
 
		else
 
		{
 
			// request data for the current sensor of the current slave
 
			currentSlaveSensor++;
 
			requesting = true;
 
			slavesensors_request();	
 
		else {
 
		
 
			// Store data in structure
 
			sensordata_set(currentSlave,type,parsedVal);
 
			serial0_sendString("Stored some sexy data!\r\n");
 
		
 
			// If we finished all sensors for all slaves
 
			if(currentSlave >= nodeCount && currentSlaveSensor >= numReadingsToExpect)
 
			{
 
				currentSlave = 0;
 
				currentSlaveSensor = 0;
 
				requesting = false;
 
			}
 
			// If we finished up one slave, go to the next
 
			else if(currentSlaveSensor >= (numReadingsToExpect-1)) 
 
			{
 
				currentSlave++;
 
				currentSlaveSensor = 0;
 
				requesting = true;
 
				slavesensors_request();
 
			}
 
			// If we haven't finished a slave (or all of them), just get the next sensor of the current slave
 
			else
 
			{
 
				// request data for the current sensor of the current slave
 
				currentSlaveSensor++;
 
				requesting = true;
 
				//slavesensors_request();	 slaves now send all values at once, we don't need to keep requesting
 
			}
 
		}
 
	}
 
	
0 comments (0 inline, 0 general)