Changeset - 156fa380821c
[Not reviewed]
default
0 4 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-26 17:04:14
ethanzonca@CL-ENS241-08.cedarville.edu
Moved APRS comment buffer to caller, minor changes.
4 files changed with 20 insertions and 17 deletions:
0 comments (0 inline, 0 general)
master/master/lib/aprs.c
Show inline comments
 
@@ -67,16 +67,20 @@ void aprs_send()
 
  ax25_send_string("/Ti=");
 
  snprintf(temp, 6, "%d", 122);//sensors_int_lm60()); -- PUT SENSOR DATA HERE
 
  ax25_send_string(temp);
 
  ax25_send_string("/Te=");
 
  snprintf(temp, 6, "%d", 123);//sensors_ext_lm60());
 
  ax25_send_string(temp);
 
  ax25_send_string("/V=");
 
  snprintf(temp, 6, "%d", 123);//sensors_vin());
 
  ax25_send_string(temp);
 
  */
 
  
 
  ax25_send_byte(' ');
 
  ax25_send_string(slavesensors_getAPRScomment());
 
  
 
  #define COMMENTBUFFER_SIZE 128
 
  char commentBuffer[COMMENTBUFFER_SIZE];
 
  ax25_send_string(slavesensors_getAPRScomment(commentBuffer, COMMENTBUFFER_SIZE));
 
  
 
  ax25_send_footer();
 
  ax25_flush_frame();                 // Tell the modem to go
 
}
master/master/lib/sensordata.c
Show inline comments
 
@@ -53,89 +53,88 @@ int32_t sensordata_get(uint8_t nodeID, u
 
		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() 
 
 
char* slavesensors_getAPRScomment(char* commentBuffer, uint16_t bufferSize) 
 
{
 
	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,bufferSize, "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, bufferSize-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, bufferSize-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, bufferSize-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, bufferSize-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, bufferSize-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, bufferSize-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, bufferSize-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/sensordata.h
Show inline comments
 
@@ -10,18 +10,18 @@
 
 *
 
 */
 
 
 
#ifndef SENSORDATA_H_
 
#define SENSORDATA_H_
 
 
#include "slavesensors.h"
 
 
void sensordata_setup();
 
void sensordata_set(uint8_t nodeID, uint8_t type, int32_t value);
 
int32_t sensordata_get(uint8_t nodeID, uint8_t type);
 
char* slavesensors_getAPRScomment();
 
char* slavesensors_getAPRScomment(char* commentBuffer, uint16_t bufferSize);
 
void sensordata_logvalues();
 
bool sensordata_isTouchdown();
 
void sensordata_checkTouchdown();
 
 
#endif /* SENSORDATA_H_ */
 
\ No newline at end of file
master/master/lib/slavesensors.c
Show inline comments
 
@@ -415,25 +415,25 @@ bool slavesensors_isrequesting()
 
}
 
 
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;
 
 
@@ -522,41 +522,41 @@ void slavesensors_process(uint8_t parseR
 
		// We got some data, let's handle it
 
		// ASCII payload
 
		uint8_t len = getPayloadLength();
 
		char* load = getPayload();
 
		uint8_t type = getPayloadType();
 
		int32_t parsedVal = strtol(load, NULL, 10);//atoi(load);
 

	
 
		// Special case for slave telling us how many things we're about to get		
 
		if(type + 0x30 == '@')
 
		{
 
			
 
			#ifdef DEBUG_GETSLAVEDATA
 
			serial0_sendString("Got an awesome count!\r\n");
 
			serial0_sendString("Got count!\r\n");
 
			serial0_sendChar(parsedVal + 0x30);
 
			serial0_sendString("\r\n");
 
			#endif
 
			
 
			numReadingsToExpect = parsedVal;
 
			currentSlaveSensor = 0;
 
			requesting = true;
 
		}
 
		else 
 
		{
 
		
 
			// Store data in structure
 
			sensordata_set(currentSlave,type,parsedVal);
 
			
 
			#ifdef DEBUG_GETSLAVEDATA
 
			serial0_sendString("Stored some sexy data!\r\n");
 
			serial0_sendString("Stored data!\r\n");
 
			#endif 
 
			
 
			gotoNextSlaveOrSensor(false);
 
		}
 
	}
 
	
 
	// If fail, try retransmit. Or we could skip and hit it next time.
 
	// TODO: Maximum number of retransmissions
 
	else if(parseResult == PARSERESULT_FAIL) 
 
	{
 
		if(requesting) 
 
		{
 
@@ -569,16 +569,16 @@ void slavesensors_process(uint8_t parseR
 
				gotoNextSlaveOrSensor(true);
 
			}
 
		}			
 
	}
 
	
 
	
 
	else if(parseResult == PARSERESULT_STILLPARSING)
 
	{
 
		return; // do nothing
 
	}
 
	else 
 
	{
 
		error_log_msg(ERROR_FATAL, true, "parseResult is invalid!");
 
		error_log_msg(ERROR_FATAL, true, "parseResult invalid!");
 
		return;
 
	}
 
}		
 
\ No newline at end of file
0 comments (0 inline, 0 general)