Changeset - 5696a474fa0f
[Not reviewed]
default
0 2 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-26 14:36:48
ethanzonca@CL-ENS241-08.cedarville.edu
Added support for standalone master operation (no slaves)
2 files changed with 28 insertions and 8 deletions:
0 comments (0 inline, 0 general)
master/master/lib/sensordata.c
Show inline comments
 
@@ -49,84 +49,93 @@ int32_t sensordata_get(uint8_t nodeID, u
 
{
 
	// Avoid reading out of bad places!
 
	if(nodeID < MAX_NUM_SLAVES) 
 
	{
 
		return slaves[nodeID][type];
 
	}
 
	else 
 
	{
 
		return 0;
 
	}
 
}
 
 
bool isEven = false;
 
 
// Generate APRS comment
 
// TODO: Can we move this buffer to a local scope of this function?
 
#define COMMENTBUFFER_SIZE 128
 
char commentBuffer[COMMENTBUFFER_SIZE];
 
char* slavesensors_getAPRScomment() 
 
{
 
	snprintf(commentBuffer,COMMENTBUFFER_SIZE, "t9%d s%s v%s h%s _%s |%s ", sensors_getBoardTemp(), get_sv(), get_speedKnots(), get_hdop(), get_latitudeLSBs(), get_longitudeLSBs());
 
	snprintf(commentBuffer,COMMENTBUFFER_SIZE, "t9%d~s%s~v%s~h%s~_%s~|%s", sensors_getBoardTemp(), get_sv(), get_speedKnots(), get_hdop(), get_latitudeLSBs(), get_longitudeLSBs());
 
	
 
	if(isEven) 
 
	{
 
	// Find slave sensors to include in this log
 
	for(int i=0; i<MAX_NUM_SLAVES; i++)
 
	{
 
		// Board temperature sensors (all slaves)
 
		uint32_t val = sensordata_get(i, SENSOR_BOARDTEMP);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " t%u%li",i,val);
 
				snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, "~t%u%li",i,val);
 
		}
 
		
 
		// Battery voltages (all slaves)
 
		val = sensordata_get(i, SENSOR_BATTERYLEVEL);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " l%u%li",i,val);
 
				snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, "~l%u%li",i,val);
 
		}
 
		
 
		// Pressure
 
		val = sensordata_get(i, SENSOR_PRESSURE);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " P%li",val);
 
				snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, "~P%li",val);
 
		}
 
		
 
		// Air Temperature
 
		val = sensordata_get(i, SENSOR_AIRTEMP);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " C%li",val);
 
				snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, "~C%li",val);
 
		}
 
		
 
		// Altitude
 
		val = sensordata_get(i, SENSOR_ALTITUDE);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " A%li",val);
 
				snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, "~A%li",val);
 
		}
 
		
 
		// Radiation
 
		val = sensordata_get(i, SENSOR_CPM_RADIATION);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " R%li",val);
 
				snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, "~R%li",val);
 
		}
 
		
 
	}
 
		isEven = false;
 
	}
 
	else {
 
		// odd does nothing
 
		isEven = true;
 
	}	
 
	
 
	if(logger_aprsInfoTextAvailable())
 
	{
 
		uint16_t len = strlen(commentBuffer);
 
		snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " %s",logger_getAprsInfoText());
 
		snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, "~%s",logger_getAprsInfoText());
 
		logger_aprsInfoTextConsumed();
 
	}
 
	
 
	
 
	return commentBuffer;
 
}
 
 
 
// Generates CSV headers on first run and logs values to the SD card (if data available)
 
bool dataWasReady = false;
 
void sensordata_logvalues() 
 
{
master/master/lib/slavesensors.c
Show inline comments
 
@@ -227,24 +227,30 @@ void slavesensors_network_scan()
 
	}
 
	
 
	#endif
 
	
 
	char infobuf[25];
 
	snprintf(infobuf, 25, "discovered %u nodes", nodeCount);
 
	info_log_msg(infobuf);
 

	
 
	_delay_ms(100);
 
	
 
	slavesensors_selectlogger();
 
	
 
	// If we don't have slaves to worry about, we're good to go
 
	if(nodeCount == 0)
 
	{
 
		dataReady = true;
 
	}		
 
	
 
	serial0_ion();
 
}
 
 
//#define DEBUG_CONTEXTSWITCH
 
//#define DEBUG_SELECTNODE
 
 
uint8_t selectedNode = 255;
 
uint8_t slavesensors_getselectednode() 
 
{
 
	return selectedNode;
 
}
 
 
@@ -401,42 +407,47 @@ int xbeeIsOk()
 
bool slavesensors_dataReady() 
 
{
 
	return dataReady;
 
}
 
 
bool slavesensors_isrequesting() 
 
{
 
	return requesting;	
 
}
 
 
void slavesensors_startprocess() 
 
{
 
	if(nodeCount == 0)
 
	{
 
		return;
 
	}		
 
	requesting = true;
 
	slavesensors_request();		
 
}
 
 
// TODO: inline. static.
 
uint32_t beginRequest = 0;
 
void slavesensors_request() 
 
{
 
	slavesensors_selectnode(currentSlave);
 
	beginRequest = time_millis();
 
	serial_sendCommand("@"); // Request data!
 
}
 
 
 
uint8_t numReadingsToExpect = 0; // number of values that the slave is about to send
 
uint8_t numRetries = 0;
 
 
void gotoNextSlaveOrSensor(bool fail) {
 
	
 
	// If we finished all sensors for all slaves
 
	if(currentSlave >= (nodeCount-1) && currentSlaveSensor >= (numReadingsToExpect-1))
 
	{
 
		#ifdef DEBUG_GETSLAVEDATA
 
		serial0_sendString("We got all data for all slaves!\r\n");
 
		#endif
 
		
 
		dataReady = true;
 
		currentSlave = 0;
 
		currentSlaveSensor = 0;
 
		requesting = false;
 
		
0 comments (0 inline, 0 general)