Changeset - 6ab6b1fe2314
[Not reviewed]
default
0 6 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-21 16:37:15
ethanzonca@CL-ENS241-08.cedarville.edu
Added InfoText logger for generic informational messages, GPS fix light now reports 3d location fixes, log is made when fix is acquired/lost. Added maximum retransmission limit.
6 files changed with 60 insertions and 33 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -46,6 +46,8 @@
 
#define ERROR_ATFAIL 6
 
#define ERROR_EXITAT 7
 
 
#define ERROR_INFOTEXT 8
 
 
// !!! Please specify detailed messages for these error codes in logger.c
 
 
// --------------------------------------------------------------------------
 
@@ -60,6 +62,15 @@
 
 
#define DATAREQUEST_RATE 3000
 
 
// Timeouts
 
#define TIMEOUT_SLAVEREQUEST 1000
 
#define TIMEOUT_NETWORKSCAN 7000
 
#define TIMEOUT_EXITAT 2000
 
#define TIMEOUT_XBEERESPONSE 2000
 
 
// Retries
 
#define MAX_SLAVEREQUEST_RETRIES 2
 
 
// --------------------------------------------------------------------------
 
// Command Parser config (serparser.c)
 
// --------------------------------------------------------------------------
master/master/lib/gps.c
Show inline comments
 
@@ -119,9 +119,22 @@ char* get_dayofmonth()
 
	return dayofmonth;
 
}
 

	
 

	
 
bool gps_hadfix = false;
 

	
 
bool gps_hasfix() 
 
{
 
	return strcmp("99.99", get_hdop());
 
	bool hasFix = get_latitudeTrimmed()[0] != 0x00;
 
	
 
	if(hasFix && !gps_hadfix) {
 
		info_log_msg("Lost GPS fix");
 
	}
 
	else if(!hasFix && gps_hadfix) {
 
		info_log_msg("Acquired GPS fix");
 
	}
 
	
 
	gps_hadfix = hasFix;
 
	return hasFix;
 
}
 

	
 
char variation[9];	//xxx.xb
master/master/lib/logger.c
Show inline comments
 
@@ -28,7 +28,7 @@
 
#include "led.h"
 
#include "looptime.h"
 

	
 
#define MAX_ERRNO 7
 
#define MAX_ERRNO 8
 

	
 
// Label lookup table
 
// Make sure there are never more labels than there are MAX_NUM_SENSORS!
 
@@ -40,6 +40,7 @@ const char err_4[] PROGMEM = "XBee timeo
 
const char err_5[] PROGMEM = "FATAL UNHANDLED ERROR";
 
const char err_6[] PROGMEM = "enter AT mode failed";
 
const char err_7[] PROGMEM = "exit AT mode failed";
 
const char err_8[] PROGMEM = "infotext";
 

	
 
const char *const errorMessageLookup[] PROGMEM =
 
{
 
@@ -51,6 +52,7 @@ const char *const errorMessageLookup[] P
 
	err_5,
 
	err_6,
 
	err_7,
 
	err_8,
 
};
 
 
 
@@ -233,6 +235,13 @@ 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);
 
	error_log_rawwrite(errorLine);
 
}
 
 
 
void error_log_rawwrite(char *buffer) 
 
{
master/master/lib/logger.h
Show inline comments
 
@@ -22,6 +22,7 @@ struct fat_file_struct* open_file_in_dir
 
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);
 
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
 
@@ -64,7 +64,7 @@ int32_t sensordata_get(uint8_t nodeID, u
 
char commentBuffer[128];
 
char* slavesensors_getAPRScomment() 
 
{
 
	snprintf(commentBuffer,128, "T%d S%s V%s H%s _%s |%s", sensors_getBoardTemp(), get_sv(), get_speedKnots(), get_hdop(), get_latitudeLSBs(), get_longitudeLSBs());
 
	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());
 
	return commentBuffer;
 
}
 
master/master/lib/slavesensors.c
Show inline comments
 
@@ -128,7 +128,7 @@ void slavesensors_network_scan()
 
		while(1) 
 
		{
 
			// Wait for scan to complete. If we timeout, return.
 
			if(waitTimeout(7000)) 
 
			if(waitTimeout(TIMEOUT_NETWORKSCAN)) 
 
			{
 
				return;
 
			}
 
@@ -154,7 +154,7 @@ void slavesensors_network_scan()
 
				strncpy(slaveNames[nodeCount], bufPtr, 15);
 
			}
 
			
 
			// If we've finished one chunk (including the newline after it). Can't be else if because it controls increment.
 
			// If we finished one chunk (including the newline after it). Can't be else if because it controls increment.
 
			if(lineCount == 9) 
 
			{
 
				if(strcmp(slaveNames[nodeCount], XBEE_LOGDEST_NAME) == 0)
 
@@ -225,6 +225,9 @@ void slavesensors_network_scan()
 
	
 
	#endif
 
	
 
	char infobuf[25];
 
	snprintf(infobuf, 25, "discovered %u nodes", nodeCount);
 
	info_log_msg(infobuf);
 

	
 
	_delay_ms(100);
 
	
 
@@ -329,7 +332,7 @@ void slavesensors_exitAT()
 
	serial0_sendString("ATCN");
 
	serial0_sendChar(0x0D);
 
 
	if(waitTimeout(2000)) 
 
	if(waitTimeout(TIMEOUT_EXITAT)) 
 
	{
 
		return;
 
	}
 
@@ -376,7 +379,7 @@ int slavesensors_enterAT()
 
 
int xbeeIsOk() 
 
{
 
	if(waitTimeout(2000)) {
 
	if(waitTimeout(TIMEOUT_XBEERESPONSE)) {
 
		error_log(ERROR_XBEETIMEOUT, true);
 
		return 1;
 
	}
 
@@ -419,6 +422,7 @@ void slavesensors_request()
 
 
 
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
 
@@ -450,25 +454,6 @@ void gotoNextSlaveOrSensor(bool fail) {
 
		currentSlaveSensor = 0;
 
		requesting = true;
 
		
 
		// EXPECT PROBLEMS HERE FROM NOT INCREMENTING
 
		//if(currentSlave == loggerIndex)
 
		//{
 
			//if(currentSlave >= (nodeCount-1))
 
			//{
 
				//// We hit the last one, we're done.
 
				//dataReady = true;
 
				//currentSlave = 0;
 
				//currentSlaveSensor = 0;
 
				//requesting = false;
 
				//led_alert();
 
				//return;
 
			//}
 
			//else
 
			//{
 
				//currentSlave++; // Skip the logger: increment to the next slave after the logger
 
			//}
 
		//}
 
		
 
		slavesensors_request();
 
	}
 
	// If we haven't finished a slave (or all of them), just get the next sensor of the current slave
 
@@ -481,17 +466,15 @@ void gotoNextSlaveOrSensor(bool fail) {
 
		// 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
 
	}
 
}
 
 
 
// TODO: needs to skip logger!
 
// Request data from slave modules
 
void slavesensors_process(uint8_t parseResult) 
 
{
 
	if(!requesting) 
 
	{
 
		// we got a command when we didn't request anything. probably skip it.
 
		// we got a command when we didn't request anything. skip it.
 
		return;
 
	}
 
	
 
@@ -499,7 +482,7 @@ void slavesensors_process(uint8_t parseR
 
	else if(parseResult == PARSERESULT_NODATA) 
 
	{
 
		// Wait for data
 
		if(requesting && time_millis() - beginRequest > 1000) {
 
		if(requesting && time_millis() - beginRequest > TIMEOUT_SLAVEREQUEST) {
 
			// if we're requesting, we have no data, and we're over the timeout, this is bad!
 
			// setParserState(STATE_RESET); - meh, can't do this because it freaking increments the cirbufptr
 
			gotoNextSlaveOrSensor(true);
 
@@ -519,6 +502,9 @@ void slavesensors_process(uint8_t parseR
 
		serial0_sendString(debug);
 
		#endif
 
		
 
		// We got data, reset retries
 
		numRetries = 0;
 
		
 
		// We got some data, let's handle it
 
		// ASCII payload
 
		uint8_t len = getPayloadLength();
 
@@ -560,7 +546,14 @@ void slavesensors_process(uint8_t parseR
 
	{
 
		if(requesting) 
 
		{
 
			slavesensors_request();	// re-request
 
			if(numRetries < MAX_SLAVEREQUEST_RETRIES) 
 
			{
 
				slavesensors_request();	// re-request
 
			}
 
			else {
 
				numRetries = 0;
 
				gotoNextSlaveOrSensor(true);
 
			}
 
		}			
 
	}
 
	
 
@@ -571,7 +564,7 @@ void slavesensors_process(uint8_t parseR
 
	}
 
	else 
 
	{
 
		// something is terribly wrong!
 
		error_log_msg(ERROR_FATAL, true, "parseResult is invalid!");
 
		return;
 
	}
 
}		
 
\ No newline at end of file
0 comments (0 inline, 0 general)