Changeset - 91a9664e6fd0
[Not reviewed]
default
0 9 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-24 15:10:36
ethanzonca@CL-ENS241-08.cedarville.edu
Adaptive logging system now fully functional
9 files changed with 126 insertions and 44 deletions:
0 comments (0 inline, 0 general)
master/master/lib/gps.c
Show inline comments
 
/*
 
* gpsMKa.c
 
 * Master Firmware: NMEA Parser
 
 *
 
 * Wireless Observational Modular Aerial Network
 
*
 
* Created: 11/15/2012 12:02:38 PM
 
*  Author: mkanning
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
*/
 
 
#include <stdbool.h>
 
#include <string.h>
 
#include <stdio.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "gps.h"
 
@@ -128,14 +135,14 @@ ISR(USART1_RX_vect)
 

	
 
void gps_setup() 
 
{
 
	sprintf(timestamp, "0");
 
	sprintf(latitude, "0");
 
	sprintf(longitude, "0");
 
	sprintf(numSatellites, "0");
 
	sprintf(hdop, "0");
 
	sprintf(knots, "0");
 
	sprintf(course, "0");
 
	sprintf(dayofmonth, "0");
 
	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");
 
}
 

	
 

	
 
@@ -674,7 +681,8 @@ void parse_gps_transmission(void){
 
}
 
/// MKa GPS transmission parser END
 

	
 
void XORbyteWithChecksum(uint8_t byte){
 
void XORbyteWithChecksum(uint8_t byte)
 
{
 
	calculatedChecksum ^= (int)byte; //this may need to be re-coded
 
}
 

	
master/master/lib/gps.h
Show inline comments
 
/*
 
 * gpsMKa.h
 
 * Master Firmware: NMEA Parser
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 *
 
 * Created: 11/15/2012 12:02:53 PM
 
 *  Author: mkanning
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */ 
 
 
 
@@ -21,5 +26,7 @@ char* get_course();
 
char* get_hdop();
 
char* get_sv();
 
char* get_dayofmonth();
 
void parse_gps_transmission(void);
 
void XORbyteWithChecksum(uint8_t byte);
 
 
#endif /* GPSMKA_H_ */
 
\ No newline at end of file
master/master/lib/heater.c
Show inline comments
 
@@ -12,6 +12,7 @@
 
 
#include "../config.h"
 
#include "led.h"
 
#include "boardtemp.h"
 
 
 
 void heater_regulateTemp()
 
 {
master/master/lib/logger.c
Show inline comments
 
@@ -23,6 +23,7 @@
 
#include "sdcard/partition.h"
 
#include "sdcard/sd_raw.h"
 
#include "sdcard/sd_raw_config.h"
 
#include "serial.h"
 
#include "logger.h"
 
#include "led.h"
 
master/master/lib/sensordata.c
Show inline comments
 
@@ -11,6 +11,7 @@
 
 */
 

	
 
#include "../config.h"
 
#include <stdio.h>
 
#include "sensordata.h"
 
#include "boardtemp.h"
 
#include "gps.h"
master/master/lib/serial.h
Show inline comments
 
@@ -35,6 +35,10 @@ char* serial0_readLine();
 
void serial_sendCommand( char* data );
 
void serial_sendResponseData();
 
 
 
void serial0_ion();
 
void serial0_ioff();
 
 
void serial1_ion();
 
void serial1_ioff();
 
master/master/lib/slavesensors.c
Show inline comments
 
@@ -10,17 +10,20 @@
 
 *
 
 */
 
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <stdbool.h>
 
#include "../config.h"
 
#include <stdlib.h>
 
#include <stdio.h>
 
#include <string.h>
 
#include <util/delay.h>
 
#include <avr/wdt.h>
 
#include "serial.h"
 
#include "serparser.h"
 
#include "slavesensors.h"
 
#include "sensordata.h"
 
#include "led.h"
 
#include "looptime.h"
 
#include <util/delay.h>
 
#include <avr/wdt.h>
 

	
 
uint8_t currentSlave = 0;
 
uint8_t currentSlaveSensor = 0;
 
@@ -32,13 +35,22 @@ void slavesensors_setup()
 
	
 
}
 

	
 
#define DEBUG_NETWORKSCAN
 
//#define DEBUG_NETWORKSCAN
 
//#define DEBUG_GETSLAVEDATA
 
 
char* bufPtr = 0x00;
 
char slaveAddressLow[MAX_NUM_SLAVES][9];
 
char slaveAddressHigh[MAX_NUM_SLAVES][9];
 

	
 
static char slaveAddressLow[MAX_NUM_SLAVES][9];
 
static char slaveAddressHigh[MAX_NUM_SLAVES][9];
 
static char slaveNames[MAX_NUM_SLAVES][20];
 

	
 
uint8_t loggerIndex = 255;
 
uint8_t nodeCount = 0;
 
bool dataReady = false;
 

	
 
char* slavesensors_slavename(uint8_t id) {
 
	return slaveNames[id];
 
}
 

	
 
void slavesensors_network_scan() {
 
	serial0_ioff();
 
@@ -55,10 +67,6 @@ void slavesensors_network_scan() {
 
	led_on(LED_ACTIVITY);
 
	atOK = slavesensors_enterAT();
 

	
 
	char nameString[20] = "NONE";
 
	
 
	char slaveNames[MAX_NUM_SLAVES][16]; // Hold 16-char addresses of max MAX_NUM_SLAVES nodes, local so the memory can be reused
 
	
 
	// wait for OK
 
	if(atOK == 0)
 
	{
 
@@ -69,7 +77,7 @@ void slavesensors_network_scan() {
 
		// wait for scan to complete
 
		uint16_t scanStart = time_millis(); 		
 
		while(!serial0_hasChar()) {
 
			if(time_millis() - scanStart > 5000) {
 
			if(time_millis() - scanStart > 7000) {
 
				led_errorcode(ERROR_XBEETIMEOUT);
 
				return;
 
			}
 
@@ -87,14 +95,13 @@ void slavesensors_network_scan() {
 
			}
 
			
 
			if(lineCount == 1) {
 
				strcpy(slaveAddressHigh[nodeCount], bufPtr);
 
				strncpy(slaveAddressHigh[nodeCount],bufPtr, 9);
 
			}
 
			else if(lineCount == 2) {
 
				strcpy(slaveAddressLow[nodeCount], bufPtr);
 
				strncpy(slaveAddressLow[nodeCount],bufPtr, 9);
 
			}
 
			else if(lineCount == 3) {
 
				strcpy(nameString, bufPtr);
 
				strcpy(slaveNames[nodeCount], bufPtr);
 
				strncpy(slaveNames[nodeCount], bufPtr, 20);
 
			}
 
			
 
			// If we've finished one chunk (including the newline after it). Can't be else if because it controls increment.
 
@@ -137,7 +144,7 @@ void slavesensors_network_scan() {
 
	char debugBuf[64];
 
	serial0_sendString("Discovered: \r\n");
 
	for(int i=0; i<nodeCount; i++) {
 
		snprintf(debugBuf, 64, "  %s - %s%s\r\n", slaveNames[i],slaveAddressHigh,slaveAddressLow[i]);
 
		snprintf(debugBuf, 64, "  %s - %s%s (%u)\r\n", slaveNames[i],slaveAddressHigh,slaveAddressLow[i], nodeCount);
 
		serial0_sendString(debugBuf);
 
	}
 
	serial0_sendString("\r\n");
 
@@ -154,7 +161,7 @@ void slavesensors_network_scan() {
 
			loggerIndex = i;
 
		}
 
	}
 
	>
 
	_delay_ms(100);
 
	slavesensors_selectlogger();
 
	
 
	serial0_ion();
 
@@ -242,6 +249,9 @@ int xbeeIsOk()
 
	}
 
}
 
 
bool slavesensors_dataReady() {
 
	return dataReady;
 
}
 
 
bool slavesensors_isrequesting() 
 
{
 
@@ -262,7 +272,7 @@ void slavesensors_request()
 
}
 
 
 
int numReadingsToExpect = 0; // number of values that the slave is about to send (testing)
 
uint8_t numReadingsToExpect = 0; // number of values that the slave is about to send (testing)
 
 
 
// TODO: needs to skip logger!
 
@@ -281,6 +291,13 @@ void slavesensors_process(uint8_t parseR
 
	// Finished reception of a message (one sensor data value). If not finished, send out command to get the next one
 
	else if(parseResult == PARSERESULT_PARSEOK)
 
	{
 
		
 
		#ifdef DEBUG_GETSLAVEDATA
 
		char debug[50];
 
		snprintf(debug, 50, "Slave %u sensor %u of total nodes %u\r\n", currentSlave, currentSlaveSensor,nodeCount);
 
		serial0_sendString(debug);
 
		#endif
 
		
 
		// We got some data, let's handle it
 
		// ASCII payload
 
		uint8_t len = getPayloadLength();
 
@@ -290,11 +307,14 @@ void slavesensors_process(uint8_t parseR
 

	
 
		// 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_sendChar(parsedVal + 0x30);
 
			serial0_sendString("\r\n");
 
			#endif
 
			
 
			numReadingsToExpect = parsedVal;
 
			currentSlave = 0;
 
			currentSlaveSensor = 0;
 
			requesting = true;
 
		}
 
@@ -303,11 +323,19 @@ void slavesensors_process(uint8_t parseR
 
			// Store data in structure
 
			sensordata_set(currentSlave,type,parsedVal);
 
			
 
			#ifdef DEBUG_GETSLAVEDATA
 
			serial0_sendString("Stored some sexy data!\r\n");
 
			#endif 
 
		
 
			// If we finished all sensors for all slaves
 
			if(currentSlave >= nodeCount && currentSlaveSensor >= numReadingsToExpect)
 
			
 
			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;
 
@@ -315,6 +343,10 @@ void slavesensors_process(uint8_t parseR
 
			// 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;
 
@@ -323,6 +355,10 @@ void slavesensors_process(uint8_t parseR
 
			// 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;
master/master/lib/slavesensors.h
Show inline comments
 
@@ -30,11 +30,17 @@ enum sensorTypes // CMD ID#
 
	CAMERA,
 
};
 
 
char* slavesensors_slavename(uint8_t id);
 
bool slavesensors_dataReady();
 
bool slavesensors_isrequesting();
 
void slavesensors_setup();
 
void slavesensors_network_scan();
 
void slavesensors_startprocess();
 
void slavesensors_request();
 
void slavesensors_process(uint8_t parseResult);
 
int xbeeIsOk();
 
void slavesensors_selectlogger();
 
void slavesensors_exitAT();
 
int slavesensors_enterAT();
 
 
#endif /* SLAVESENSORS_H_ */
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
@@ -19,6 +19,7 @@
 
#include <avr/interrupt.h>
 
#include <stdio.h>
 
#include <stdbool.h>
 
#include <string.h>
 

	
 
#include "lib/serial.h"
 
#include "lib/aprs.h"
 
@@ -31,7 +32,7 @@
 

	
 
#include "lib/i2c.h"
 
#include "lib/boardtemp.h"
 

	
 
#include "lib/heater.h"
 
#include "lib/looptime.h"
 
#include "lib/slavesensors.h"
 
#include "lib/serparser.h"
 
@@ -67,20 +68,16 @@ int main(void)
 
	
 
	// Buffer for string operations
 
	char logbuf[128];
 
	char debugBuf[128];
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	bool dataWasReady = false;
 
	
 
	// Result of last parser run
 
	int parseResult = PARSERESULT_NODATA;
 
	
 
	// Write CSV header to SD card
 
	logger_log("ProgramTime,LastAprsBroadcast,LastLog\n");
 
	
 
	
 
	serial1_ioff();
 
	
 
	while(1)
 
@@ -117,22 +114,43 @@ int main(void)
 
			
 
			sensors_readBoardTemp(); // i2c read, 400k
 
		
 
			// If we've gotten data from all slaves once, we're ready to make a CSV header and start logging
 
			if(slavesensors_dataReady()) {
 
				if(!dataWasReady) {
 
					char csvHeader[128];
 
					csvHeader[0] = 0x00;
 
					
 
					for(uint8_t i=0; i<MAX_NUM_SLAVES; i++) {
 
						for(uint8_t j=0; j<MAX_NUM_SENSORS; j++) {
 
							int16_t tmp = sensordata_get(i, j);
 
							if(tmp != -32768) {
 
								// FIXME: will the 128 here really provide safety? might want to subtract the strlen
 
								snprintf(csvHeader + strlen(csvHeader), 128,"%s-Sensor%u,", slavesensors_slavename(i), j);	
 
							}
 
						}
 
					}
 
					snprintf(csvHeader + strlen(csvHeader), 128,"\r\n");	
 
					serial0_sendString(csvHeader);
 
					logger_log(csvHeader);
 
					dataWasReady = true;
 
				}
 
		
 
			logbuf[0] = 0x00;
 
			//snprintf(logbuf, 128, "%lu,%d,%u,%s,%s,%s,%s,%s\r\n", time_millis(), sensors_getBoardTemp(),get_timestamp(),get_latitude(),get_longitude(),get_speedKnots(),get_hdop(), get_course());
 
			for(int i=0; i<MAX_NUM_SLAVES; i++) {
 
				for(int j=0; j<MAX_NUM_SENSORS; j++) {
 
					int16_t tmp = sensordata_get(i, j);
 
					if(tmp != -32768) {
 
						//serial0_sendString("OH GOSH DATUM\r\n");
 
						snprintf(logbuf + strlen(logbuf),128," %d,", tmp);
 
						serial0_sendString(logbuf);
 
					}
 
					
 
				}
 
			}
 
			snprintf(logbuf + strlen(logbuf),128,"\r\n");
 
				serial0_sendString(logbuf);			
 
				logger_log(logbuf);
 
			
 
			logger_log(logbuf);
 
			}			
 
			
 
			// Print out logger debug
 
			#ifdef DEBUG_OUTPUT
0 comments (0 inline, 0 general)