Changeset - 6b1e328f8883
[Not reviewed]
default
0 7 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-05 16:41:38
ethanzonca@CL-ENS241-08.cedarville.edu
Trimmed significant amount of memory usage, fixed scope issues and downsized fixed arrays.
7 files changed with 31 insertions and 38 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -38,25 +38,25 @@
 
#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 20 // Maximum number of unique types of sensors in the system
 
#define MAX_NUM_SENSORS 10 // Maximum number of unique types of sensors in the system
 
 
// Node identifier of log destination xbee
 
#define XBEE_LOGDEST_NAME "HAB-LOGGER"
 
 
#define DATAREQUEST_RATE 3000
 
 
// --------------------------------------------------------------------------
 
// Command Parser config (serparser.c)
 
// --------------------------------------------------------------------------
 
 
// Maximum payload size of command
 
#define MAX_PAYLOAD_LEN 16
 
@@ -108,29 +108,24 @@
 

	
 
// Destination callsign: APRS (with SSID=0) is usually okay.
 
#define D_CALLSIGN      "APRS"
 
#define D_CALLSIGN_ID   0
 

	
 
// Digipeating paths:
 
// (read more about digipeating paths here: http://wa8lmf.net/DigiPaths/ )
 
// The recommended digi path for a balloon is WIDE2-1 or pathless. The default
 
// is pathless. Uncomment the following two lines for WIDE2-1 path:
 
#define DIGI_PATH1      "WIDE2"
 
#define DIGI_PATH1_TTL  1
 

	
 
// APRS comment: this goes in the comment portion of the APRS message. You
 
// might want to keep this short. The longer the packet, the more vulnerable
 
// it is to noise.
 
#define APRS_COMMENT    "[A-30.5 B45.64 C99542]"
 
 
// Transmit the APRS sentence every X milliseconds
 
#define APRS_TRANSMIT_PERIOD 20000
 

	
 

	
 
// --------------------------------------------------------------------------
 
// Logger config (logger.c)
 
// --------------------------------------------------------------------------
 
 
#define LOGGER_ID_EEPROM_ADDR 0x10
 
 
// Written to the beginning of every log file
 
#define LOGGER_HEADERTEXT "HAB Control Master - 1.0\n"
master/master/lib/aprs.c
Show inline comments
 
@@ -8,80 +8,75 @@
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include "../config.h"
 
#include "aprs.h"
 
#include "ax25.h"
 
#include "gps.h"
 
#include "sensordata.h"
 
#include <stdio.h>
 

	
 
const char *gps_aprs_lat = "39.74744N";
 
const char *gps_aprs_lon = "-83.81249W";
 
const char *gps_time = "081533/";
 
float gps_altitude = 123.5;
 
int gps_course = 5;
 
int gps_speed = 13;
 

	
 
float meters_to_feet(float m)
 
{
 
  // 10000 ft = 3048 m
 
  return m / 0.3048;
 
}
 

	
 
void aprs_send()
 
{
 
  char temp[12];                   // Temperature (int/ext)
 
  const struct s_address addresses[] = { 
 
    {D_CALLSIGN, D_CALLSIGN_ID},  // Destination callsign
 
    {S_CALLSIGN, S_CALLSIGN_ID},  // Source callsign (-11 = balloon, -9 = car)
 
#ifdef DIGI_PATH1
 
    {DIGI_PATH1, DIGI_PATH1_TTL}, // Digi1 (first digi in the chain)
 
#endif
 
#ifdef DIGI_PATH2
 
    {DIGI_PATH2, DIGI_PATH2_TTL}, // Digi2 (second digi in the chain)
 
#endif
 
  };
 

	
 
	// emz: modified this to get the size of the first address rather than the size of the struct itself, which fails
 
  ax25_send_header(addresses, sizeof(addresses)/sizeof(addresses[0]));
 
  ax25_send_byte('/');                // Report w/ timestamp, no APRS messaging. $ = NMEA raw data
 
  // ax25_send_string("021709z");     // 021709z = 2nd day of the month, 17:09 zulu (UTC/GMT)
 
  ax25_send_string(get_dayofmonth()); ///! Needs to be day hour minute        // 170915 = 17h:09m:15s zulu (not allowed in Status Reports)
 
  ax25_send_string(get_timestamp()); 
 
  ax25_send_byte('z'); // zulu time. h for nonzulu
 
  ax25_send_string(get_latitude());     // Lat: 38deg and 22.20 min (.20 are NOT seconds, but 1/100th of minutes)
 
  ax25_send_byte('N');
 
  ax25_send_byte('/');                // Symbol table
 
  ax25_send_string(get_longitude());     // Lon: 000deg and 25.80 min
 
  ax25_send_byte('W');
 
  ax25_send_byte('O');                // Symbol: O=balloon, -=QTH
 
  snprintf(temp, 4, "%03d", (int)(gps_course + 0.5)); 
 
  ax25_send_string(temp);             // Course (degrees)
 
  
 
  //snprintf(temp, 4, "%03d", (int)(get_course() + 0.5));  
 
  // !!!TODO: ENSURE THAT THE COURSE IS FORMATTED CORRECTLY!
 
  ax25_send_string(get_course());             // Course (degrees)
 
  
 
  ax25_send_byte('/');                // and
 
  
 
  // !!!TODO: Check the speed!
 
  //snprintf(temp, 4, "%03d", (int)(gps_speed + 0.5));
 
  ax25_send_string(get_speedKnots());             // speed (knots)
 
  
 
  /*
 
  ax25_send_string("/A=");            // Altitude (feet). Goes anywhere in the comment area
 
  snprintf(temp, 7, "%06ld", (long)(meters_to_feet(gps_altitude) + 0.5));
 
  ax25_send_string(temp);
 
  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(APRS_COMMENT);     // Comment
 
  ax25_send_string(slavesensors_getAPRScomment());
 
  ax25_send_footer();
 

	
 
  ax25_flush_frame();                 // Tell the modem to go
 
}
master/master/lib/i2c.c
Show inline comments
 
/*
 
 * i2c.c
 
 * Master Firmware: I2C
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 *
 
 * Created: 11/7/2012 7:18:23 PM
 
 *  Author: kripperger
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */ 
 
 
#include <inttypes.h>
 
#include <compat/twi.h>
 
#include "../config.h"
 
#include "i2c.h"
 
 
 
/* I2C clock in Hz */
 
#define SCL_CLOCK  100000L
 
 
master/master/lib/i2c.h
Show inline comments
 
/*
 
 * i2c.h
 
 * Master Firmware: I2C
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 *
 
 * Created: 11/7/2012 7:18:33 PM
 
 *  Author: kripperger
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */ 
 
 
 
#ifndef I2C_H_
 
#define I2C_H_
 
 
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
 
#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
 
#endif
 
 
#include <avr/io.h>
 
 
 
/** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */
 
#define I2C_READ    1
master/master/lib/led.h
Show inline comments
 
@@ -32,34 +32,28 @@ enum leds {
 
	LED_BUZZ,
 
};
 
 
typedef struct {uint8_t* direction; uint8_t* port; uint8_t pin;} led_t;
 
 
// Match order of leds enum
 
static led_t ledList[] = {
 
	{&DDRA, &PORTA, PA1}, // ACT0
 
	{&DDRA, &PORTA, PA2}, // ACT1
 
	{&DDRA, &PORTA, PA3}, // ACT2
 
	{&DDRA, &PORTA, PA4}, // ACT3
 
 
//pcb:
 
	{&DDRB, &PORTB, PB4}, // POWER
 
	{&DDRB, &PORTB, PB3}, // STATUS
 
	{&DDRB, &PORTB, PB2}, // ERROR
 
 
//breadboard:
 
//	{&DDRA, &PORTA, PA2}, // POWER
 
//	{&DDRA, &PORTA, PA0}, // STATUS
 
//	{&DDRA, &PORTA, PA1}, // ERROR
 
 
	{&DDRD, &PORTD, PD6}, // SIDEBOARD
 
	{&DDRD, &PORTD, PD5}, // ACTIVITY
 
	{&DDRD, &PORTD, PD4}, // CYCLE
 
	
 
	{&DDRA, &PORTA, PA6}, // HEAT
 
	{&DDRA, &PORTA, PA7}, // BUZZER
 
};
 
 
#define NUM_LEDS 12
 
 
void led_setup();
 
void led_on(uint8_t led);
master/master/lib/sensordata.c
Show inline comments
 
@@ -52,25 +52,25 @@ int32_t sensordata_get(uint8_t nodeID, u
 
 
 
char commentBuffer[128];
 
 
 
// [A-30.5 B45.64 C99542]"
 
char* slavesensors_getAPRScomment() {
 
	snprintf(commentBuffer,128, "T%d S%s V%s H%s", sensors_getBoardTemp(), get_sv(), get_speedKnots(), get_hdop());
 
	return commentBuffer;
 
}
 
 

	
 
char logbuf[256];
 
 
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];
 
			csvHeader[0] = 0x00;
 
		
 
@@ -86,24 +86,25 @@ void sensordata_logvalues() {
 
						snprintf(csvHeader + strlen(csvHeader), CSV_HEADER_SIZE-strlen(csvHeader),"%s-%s,", slavesensors_slavename(i), slavesensors_getLabel(j));
 
					}
 
				}
 
			}
 
		
 
			// Terminate header string and write to SD card
 
			snprintf(csvHeader + strlen(csvHeader), CSV_HEADER_SIZE-strlen(csvHeader),"\r\n");
 
			logger_log(csvHeader);
 
			dataWasReady = true;
 
		}
 
	
 
		// Write CSV sensor values to SD card
 
		char logbuf[256];
 
		logbuf[0] = 0x00;
 
		snprintf(logbuf, 256, "%lu,%d,%s,%s,%s,%s,%s,%s,%s,", time_millis(), sensors_getBoardTemp(),get_timestamp(),get_latitude(),get_longitude(),get_speedKnots(),get_hdop(), get_course(), get_sv());
 
		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(tmp != -2111111111) {
 
					snprintf(logbuf + strlen(logbuf),256-strlen(logbuf)," %ld,", tmp);
 
				}
 
			
 
			}
 
		}
 
		snprintf(logbuf + strlen(logbuf),256-strlen(logbuf),"\r\n");
master/master/lib/slavesensors.c
Show inline comments
 
@@ -18,54 +18,53 @@
 
#include <string.h>
 
#include <util/delay.h>
 
#include <avr/wdt.h>
 
#include <avr/pgmspace.h>
 
#include "serial.h"
 
#include "serparser.h"
 
#include "slavesensors.h"
 
#include "sensordata.h"
 
#include "led.h"
 
#include "looptime.h"
 

	
 
// 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";
 
const char label_4[] PROGMEM = "AmbientLight";
 
const char label_5[] PROGMEM = "Humidity";
 
const char label_6[] PROGMEM = "Pressure";
 
const char label_7[] PROGMEM = "Altitude";
 
const char label_8[] PROGMEM = "CPM-Radiation";
 

	
 
const char *const labelLookup[] PROGMEM =
 
{
 
	label_0,
 
	label_1,
 
	label_2,
 
	label_3,
 
	label_4,
 
	label_5,
 
	label_6,
 
	label_7,
 
	label_8,
 
};
 

	
 
char labelBuffer[25]; // Size to length of label
 
char labelBuffer[15]; // Size to length of label
 
char* slavesensors_getLabel(uint8_t sensorID) {
 
	//snprintf(labelBuffer, 25, "[%u]", sensorID);
 
	//return labelBuffer;
 
	if(sensorID < 9)
 
	{
 
		strncpy_P(labelBuffer,(char*)pgm_read_word(&(labelLookup[sensorID])),25);
 
		strncpy_P(labelBuffer,(char*)pgm_read_word(&(labelLookup[sensorID])),15);
 
		
 
		return labelBuffer;
 
	}
 
	else {
 
		return NULL;
 
	}
 
}
 

	
 
uint8_t currentSlave = 0;
 
uint8_t currentSlaveSensor = 0;
 
 
bool requesting = false;
 
@@ -73,25 +72,25 @@ bool requesting = false;
 
void slavesensors_setup() 
 
{
 
	
 
}
 

	
 
//#define DEBUG_NETWORKSCAN
 
//#define DEBUG_GETSLAVEDATA
 
 
char* bufPtr = 0x00;
 

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

	
 
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();
 
	
 
@@ -133,25 +132,25 @@ void slavesensors_network_scan() {
 
			// If we're starting a new block but got a newline instead, we're done!
 
			if(lineCount == 0 && strcmp(bufPtr, "") == 0) {
 
				break;			
 
			}
 
			
 
			if(lineCount == 1) {
 
				strncpy(slaveAddressHigh[nodeCount],bufPtr, 9);
 
			}
 
			else if(lineCount == 2) {
 
				strncpy(slaveAddressLow[nodeCount],bufPtr, 9);
 
			}
 
			else if(lineCount == 3) {
 
				strncpy(slaveNames[nodeCount], bufPtr, 20);
 
				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(lineCount == 9) {
 
				// bufPtr should be null at this point, because we read in a newline after one chunk
 
				nodeCount++;
 
				lineCount = 0;
 
			}
 
			else {
 
				lineCount++;
 
			}
 

	
0 comments (0 inline, 0 general)