Changeset - 74f10f4bb48e
[Not reviewed]
default
0 6 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-22 15:05:21
ethanzonca@CL-ENS241-08.cedarville.edu
Slave sensor data now transmitted via APRS along with robust error logging/transmitting support
6 files changed with 82 insertions and 18 deletions:
0 comments (0 inline, 0 general)
master/master/lib/gps.c
Show inline comments
 
@@ -177,20 +177,20 @@ ISR(USART1_RX_vect)
 
	nmeaBuffer[nmeaBufferDataPosition % NMEABUFFER_SIZE] = UDR1;
 
	nmeaBufferDataPosition = (nmeaBufferDataPosition + 1) % NMEABUFFER_SIZE;
 
}
 

	
 
void gps_setup() 
 
{
 
	snprintf(timestamp,2, "0");
 
	snprintf(latitude,2, "0");
 
	snprintf(longitude,2, "0");
 
	snprintf(numSatellites,2, "0");
 
	snprintf(hdop,2, "0");
 
	snprintf(knots,2, "0");
 
	snprintf(course,2, "0");
 
	snprintf(dayofmonth,2, "0");
 
	timestamp[0] = 0x00;
 
	latitude[0] = 0x00;
 
	longitude[0] = 0x00;
 
	numSatellites[0] = 0x00;
 
	hdop[0] = 0x00;
 
	knots[0] = 0x00;
 
	course[0] = 0x00;
 
	dayofmonth[0] = 0x00;
 
}
 

	
 

	
 
// Could inline if program space available
 
static void setParserState(uint8_t state)
 
{
master/master/lib/logger.c
Show inline comments
 
@@ -212,23 +212,45 @@ void error_log(uint8_t errNo, bool flash
 
	if(flashLED) 
 
	{
 
		led_errorcode(errNo);
 
	}	
 
}
 
 
 
char aprsInfoText[64];
 
bool aprsInfoTextAvailable = false;
 
char* logger_getAprsInfoText() 
 
{
 
	return aprsInfoText;	
 
}
 
 
bool logger_aprsInfoTextAvailable() 
 
{
 
	return aprsInfoTextAvailable;
 
}
 
 
void logger_aprsInfoTextConsumed() 
 
{
 
	aprsInfoTextAvailable = false;
 
}
 
 
void error_log_msg(uint8_t errNo, bool flashLED, char* infoText)
 
{
 
	char labelBuffer[32];
 
	labelBuffer[0] = 0x00;
 
	
 
	if(errNo <= MAX_ERRNO)
 
	{
 
		strncpy_P(labelBuffer,(char*)pgm_read_word(&(errorMessageLookup[errNo])),32);
 
	}
 
	char errorLine[256];
 
	snprintf(errorLine, 256, "%lu,%u,%s,%s,\r\n", time_millis(), errNo, labelBuffer, infoText);
 
 
	snprintf(aprsInfoText, 64, "e[%u,%s,%s]", errNo, labelBuffer, infoText);
 
 
	aprsInfoTextAvailable = true;
 
	error_log_rawwrite(errorLine);
 
	
 
	led_on(LED_ERROR);
 
	if(flashLED)
 
	{
 
		led_errorcode(errNo);
 
@@ -236,12 +258,14 @@ void error_log_msg(uint8_t errNo, bool f
 
}
 
 
void info_log_msg(char* infoText)
 
{
 
	char errorLine[256];
 
	snprintf(errorLine, 256, "%lu,8,infotext,%s,\r\n", time_millis(), infoText);
 
	snprintf(aprsInfoText, 64, "i[%s]", infoText);
 
	aprsInfoTextAvailable = true;
 
	error_log_rawwrite(errorLine);
 
}
 
 
 
void error_log_rawwrite(char *buffer) 
 
{
master/master/lib/logger.h
Show inline comments
 
@@ -18,12 +18,15 @@
 
 
void logger_setup();
 
uint8_t logger_writeLine(char* dateLine, uint8_t length);
 
struct fat_file_struct* open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name);
 
uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry);
 
void error_log(uint8_t errNo, bool flashLED);
 
char* logger_getAprsInfoText();
 
bool logger_aprsInfoTextAvailable();
 
void logger_aprsInfoTextConsumed();
 
void error_log_msg(uint8_t errNo, bool flashLED, char* infoText);
 
void info_log_msg(char* infoText);
 
void error_log_rawwrite(char *buffer);
 
void logger_log(char *buffer);
 
void logger_closeLog();
 
master/master/lib/sensordata.c
Show inline comments
 
@@ -58,16 +58,48 @@ int32_t sensordata_get(uint8_t nodeID, u
 
	}
 
}
 
 
 
// Generate APRS comment
 
// TODO: Can we move this buffer to a local scope of this function?
 
char commentBuffer[128];
 
#define COMMENTBUFFER_SIZE 128
 
char commentBuffer[COMMENTBUFFER_SIZE];
 
char* slavesensors_getAPRScomment() 
 
{
 
	snprintf(commentBuffer,128, "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());
 
	
 
	// Find slave sensors to include in this log
 
	for(int i=0; i<MAX_NUM_SLAVES; i++)
 
	{
 
		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);
 
		}
 
		
 
		val = sensordata_get(i, SENSOR_PRESSURE);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " P%li",val);
 
		}
 
		
 
		val = sensordata_get(i, SENSOR_AIRTEMP);
 
		if(val != -2111111111) {
 
			uint16_t len = strlen(commentBuffer);
 
			snprintf(commentBuffer + len, COMMENTBUFFER_SIZE-len, " C%li",val);
 
		}
 
	}
 
	
 
	if(logger_aprsInfoTextAvailable())
 
	{
 
		uint16_t len = strlen(commentBuffer);
 
		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;
master/master/lib/slavesensors.c
Show inline comments
 
@@ -24,12 +24,15 @@
 
#include "slavesensors.h"
 
#include "sensordata.h"
 
#include "led.h"
 
#include "looptime.h"
 
#include "logger.h"
 

	
 

	
 
// !!! Remember to update the ENUM in slavesensors.h when changing things here
 

	
 
// Label lookup table
 
// Make sure there are never more labels than there are MAX_NUM_SENSORS! 
 
const char label_0[] PROGMEM = "BoardTemp";
 
const char label_1[] PROGMEM = "HeaterStatus";
 
const char label_2[] PROGMEM = "BatteryLevel";
 
const char label_3[] PROGMEM = "AirTemp";
master/master/lib/slavesensors.h
Show inline comments
 
@@ -17,20 +17,22 @@
 
#include <stdbool.h>
 
#include <inttypes.h>
 
 
// Serial Commands
 
enum sensorTypes // CMD ID#
 
{
 
	NONE = 0,
 
	BOARDTEMP,
 
	PRESSURE,
 
	GEIGER,
 
	TEMPERATURE,
 
	HUMIDITY,
 
	AMBIENTLIGHT,
 
	CAMERA,
 
	SENSOR_BOARDTEMP = 0,
 
	SENSOR_HEATERSTATUS,
 
	SENSOR_BATTERYLEVEL,
 
	SENSOR_AIRTEMP,
 
	SENSOR_AMBIENTLIGHT,
 
	SENSOR_HUMIDITY,
 
	SENSOR_PRESSURE,
 
	SENSOR_ALTITUDE,
 
	SENSOR_CPM_RADIATION,
 
	SENSOR_NONE
 
};
 
 
bool waitTimeout(uint32_t timeout);
 
char* slavesensors_getLabel(uint8_t sensorID);
 
char* slavesensors_slavename(uint8_t id);
 
bool slavesensors_dataReady();
0 comments (0 inline, 0 general)