Changeset - 67b079a4703e
[Not reviewed]
default
0 3 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-18 16:50:15
ethanzonca@CL-ENS241-08.cedarville.edu
Fixed corrupted header line issue by doing incremental SD card writing of header line.
3 files changed with 25 insertions and 23 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -2,49 +2,49 @@
 
 * Master Firmware: Configuration
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#ifndef CONFIG_H_
 
#define CONFIG_H_
 
 
// --------------------------------------------------------------------------
 
// Module config (master.c)
 
// --------------------------------------------------------------------------
 
 
//#define DEBUG_OUTPUT
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
#define BOARDTEMP_ADDR 0x90
 
 
#define HEATER_THRESHOLD 25
 
#define HEATER_THRESHOLD 60
 
 
// --------------------------------------------------------------------------
 
// Error Codes config (led.c, used throughout code)
 
// --------------------------------------------------------------------------
 
 
// SD Card
 
#define ERROR_SD_INIT 2
 
#define ERROR_SD_PARTITION 3
 
#define ERROR_SD_FILE 4
 
 
#define ERROR_XBEETIMEOUT 5
 
#define ERROR_NOXBEE 6
 
 
#define ERROR_CRAP 15
 
 
#define ERROR_ATFAIL 3
 
#define ERROR_EXITAT 8
 
 
// --------------------------------------------------------------------------
 
// Slave Sensors config (slavesensors.c)
 
// --------------------------------------------------------------------------
 
 
#define MAX_NUM_SLAVES 5  // Maximum number of nodes in the system
 
#define MAX_NUM_SENSORS 10 // Maximum number of unique types of sensors in the system
master/master/lib/sensordata.c
Show inline comments
 
@@ -59,80 +59,88 @@ 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];
 
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());
 
	return commentBuffer;
 
}
 
 
 
// Generates CSV headers on first run and logs values to the SD card (if data available)
 
bool dataWasReady = false;
 
void sensordata_logvalues() 
 
{
 
	// Generate CSV header after we have queried all slaves once
 
	if(slavesensors_dataReady()) 
 
	{
 
	
 
		// Only generate/write header the first time data is ready
 
		if(!dataWasReady) 
 
		{
 
			#define CSV_HEADER_SIZE 512
 
			char csvHeader[CSV_HEADER_SIZE];
 
			#define CSV_BUFFER_SIZE 64
 
			char csvHeader[CSV_BUFFER_SIZE];
 
			csvHeader[0] = 0x00;
 
		
 
			// Add master data headers
 
			snprintf(csvHeader, CSV_HEADER_SIZE, "Time,BoardTemp,GPSTime,GPSLat,GPSLon,GPSSpeed,GPSHDOP,GPSCourse,GPSSV,");
 
		
 
			
 
			slavesensors_selectlogger();
 
			
 
			// Add master data headers
 
			logger_log("Time,BoardTemp,GPSTime,GPSLat,GPSLon,GPSSpeed,GPSHDOP,GPSCourse,GPSSV,");
 
			serial0_sendString("Time,BoardTemp,GPSTime,GPSLat,GPSLon,GPSSpeed,GPSHDOP,GPSCourse,GPSSV,");
 
			
 
			// Add slave data headers
 
			for(uint8_t i=0; i<MAX_NUM_SLAVES; i++) 
 
			{
 
				for(uint8_t j=0; j<MAX_NUM_SENSORS; j++) 
 
				{
 
					int32_t tmp = sensordata_get(i, j);
 
					
 
					// If a sensor value exists, write a header for it
 
					if(tmp != -2111111111) 
 
					{
 
						snprintf(csvHeader + strlen(csvHeader), CSV_HEADER_SIZE-strlen(csvHeader),"%s-%s,", slavesensors_slavename(i), slavesensors_getLabel(j));
 
						snprintf(csvHeader, CSV_BUFFER_SIZE,"%s-%s,", slavesensors_slavename(i), slavesensors_getLabel(j));
 
						logger_log(csvHeader);
 
						serial0_sendString(csvHeader);
 
					}
 
				}
 
			}
 
		
 
			// End line and write to SD card
 
			snprintf(csvHeader + strlen(csvHeader), CSV_HEADER_SIZE-strlen(csvHeader),"\r\n");
 
			snprintf(csvHeader, CSV_BUFFER_SIZE,"\r\n");
 
			logger_log(csvHeader);
 

	
 
			serial0_sendString(csvHeader);
 
			dataWasReady = true;
 
		}
 
	
 
		// Write CSV sensor values to SD card
 
		char logbuf[256];
 
		#define CSV_LOGLINE_SIZE 512
 
		char logbuf[CSV_LOGLINE_SIZE];
 
		logbuf[0] = 0x00;
 
		
 
		// Write master sensor values
 
		snprintf(logbuf, 256, "%lu,%d,%s,%s,%s,%s,%s,%s,%s,", time_millis(), sensors_getBoardTemp(),get_timestamp(),get_latitudeTrimmed(),get_longitudeTrimmed(),get_speedKnots(),get_hdop(), get_course(), get_sv());
 
		snprintf(logbuf, CSV_LOGLINE_SIZE, "%lu,%d,%s,%s,%s,%s,%s,%s,%s,", time_millis(), sensors_getBoardTemp(),get_timestamp(),get_latitudeTrimmed(),get_longitudeTrimmed(),get_speedKnots(),get_hdop(), get_course(), get_sv());
 
		
 
		// Write slave sensor values
 
		for(int i=0; i<MAX_NUM_SLAVES; i++) 
 
		{
 
			for(int j=0; j<MAX_NUM_SENSORS; j++) 
 
			{
 
				int32_t tmp = sensordata_get(i, j);
 
				
 
				// If a sensor value exists, log the data
 
				if(tmp != -2111111111) 
 
				{
 
					snprintf(logbuf + strlen(logbuf),256-strlen(logbuf)," %ld,", tmp);
 
					snprintf(logbuf + strlen(logbuf),CSV_LOGLINE_SIZE-strlen(logbuf)," %ld,", tmp);
 
				}
 
			
 
			}
 
		}
 
		
 
		// End line and write to log
 
		snprintf(logbuf + strlen(logbuf),256-strlen(logbuf),"\r\n");
 
		snprintf(logbuf + strlen(logbuf),CSV_LOGLINE_SIZE-strlen(logbuf),"\r\n");
 
		logger_log(logbuf);
 
	}
 
}
 
\ No newline at end of file
master/master/lib/slavesensors.c
Show inline comments
 
@@ -375,111 +375,105 @@ int xbeeIsOk()
 
		return 1;
 
	}
 
}
 
 
bool slavesensors_dataReady() 
 
{
 
	return dataReady;
 
}
 
 
bool slavesensors_isrequesting() 
 
{
 
	return requesting;	
 
}
 
 
void slavesensors_startprocess() 
 
{
 
	requesting = true;
 
	slavesensors_request();		
 
}
 
 
// TODO: inline. static.
 
uint32_t beginRequest = 0;
 
void slavesensors_request() 
 
{
 
	if(currentSlave == loggerIndex) 
 
	{
 
		currentSlave++;
 
		if(currentSlave >= (nodeCount)) 
 
		{
 
			slavesensors_selectlogger();
 
			return;
 
		}
 
	if(currentSlave == loggerIndex) {
 
		gotoNextSlaveOrSensor(true);
 
		return;
 
	}
 
	slavesensors_selectnode(currentSlave);
 
	beginRequest = time_millis();
 
	serial_sendCommand("@"); // Request data!
 
}
 
 
 
uint8_t numReadingsToExpect = 0; // number of values that the slave is about to send
 
 
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;
 
		
 
		if(!fail) 
 
		{
 
			led_alert();	
 
		}
 
		
 
	}
 
	// If we finished up one slave, go to the next
 
	else if(currentSlaveSensor >= (numReadingsToExpect-1))
 
	{
 
		#ifdef DEBUG_GETSLAVEDATA
 
		serial0_sendString("Finished up one slave, go to another.\r\n");
 
		#endif
 
		
 
		currentSlave++;
 
		currentSlaveSensor = 0;
 
		requesting = true;
 
		
 
		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++; // increment to the next slave after the logger
 
				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
 
	else
 
	{
 
		#ifdef DEBUG_GETSLAVEDATA
 
		serial0_sendString("Give me another sensor value...");
 
		#endif
 
		
 
		// 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!
 
void slavesensors_process(uint8_t parseResult) 
 
{
 
	if(!requesting) 
0 comments (0 inline, 0 general)