Skip to content
Browse files

Fixing for Jon's work.

  • Loading branch information...
1 parent 0bcd450 commit 0edd69802ecc1bcf08f777fa4b1f7b61e6fa177d unknown committed Feb 27, 2012
Showing with 521 additions and 520 deletions.
  1. +512 −511 main.c
  2. +9 −9 parsing/gps.c
View
1,023 main.c
@@ -23,7 +23,7 @@
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
-#include <string.h>
+#include <string.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
@@ -66,10 +66,10 @@
#define XCLR_P PORTA
#define TAKEOFFPINPORT PORTD
-#define TAKEOFFPIN 5
-
-#define POWERPORT PORTB
-#define I2C9PT 0
+#define TAKEOFFPIN 5
+
+#define POWERPORT PORTB
+#define I2C9PT 0
#define I2C10PT 1
#define TMP100FC 0b10011110
@@ -113,16 +113,16 @@ void calculateVspeed(uint32_t);
void timedCutdown(uint32_t);
void autoBallast(uint32_t);
void collectData(uint32_t);
-void transmitSamples(uint32_t);
+void transmitSamples(uint32_t);
void transmitShortReport(uint32_t);
void updateCommHFTelemetry(uint32_t);
void rapidHFXmit(uint32_t);
void ballastStaticTickle(uint32_t);
-void flightPhaseLogic(uint32_t);
-void resetWatchdog(uint32_t);
-void turnHfOn(uint32_t);
-void turnHfOff(uint32_t);
-void incrementEpoch(uint32_t);
+void flightPhaseLogic(uint32_t);
+void resetWatchdog(uint32_t);
+void turnHfOn(uint32_t);
+void turnHfOff(uint32_t);
+void incrementEpoch(uint32_t);
void updateSpeedDial(uint16_t speedDial);
//Vspeed Calculation Variables
@@ -134,23 +134,23 @@ extern int16_t EEMEM EEvSpeedHolderSamples;
//Globals
uint8_t enableReports = 1;
-uint8_t reportCounterL=0;
+uint8_t reportCounterL=0;
uint8_t reportCounterH=0;
-uint16_t statusCode = 0x00;
-uint8_t hfSema = 0;
-
+uint16_t statusCode = 0x00;
+uint8_t hfSema = 0;
+
uint32_t epochOffset;
//HOLY CRAP YOU ARE STUPID PUT THESE SOMEWHERE THAT MAKES SENSE SO YOU DON'T HAVE TO EXTERN THEM
-//IN YOUR FREAKING MAIN ROUTINE
+//IN YOUR FREAKING MAIN ROUTINE
extern uint32_t EEMEM EEepochOffset;
extern uint16_t EEMEM EEbatchSampleEnd;
extern int16_t EEMEM EEballastTargetPositiveVSpeed;
extern int16_t EEMEM EEballastTargetNegativeVSpeed;
extern uint16_t EEMEM EEballastTargetAltitude;
extern uint16_t EEMEM EEballastSafetyAltThresh;
extern uint16_t EEMEM EEmaxAllowableTXInterval;
-extern uint16_t EEMEM EEdataTransmitInterval;
+extern uint16_t EEMEM EEdataTransmitInterval;
extern uint16_t EEMEM EEshortDataTransmitInterval;
extern uint8_t EEMEM EEhfRapidTransmit;
extern uint8_t EEMEM EEflightPhase;
@@ -171,15 +171,15 @@ extern uint8_t EEMEM EEepochStartSeconds;
extern uint8_t EEMEM EEepochStartMinutes;
extern uint8_t EEMEM EEepochStartHours;
extern uint8_t EEMEM EEepochStartDays;
-extern uint8_t EEMEM EEEpochLock;
-extern uint16_t EEMEM EEhfTimeToTx;
+extern uint8_t EEMEM EEEpochLock;
+extern uint16_t EEMEM EEhfTimeToTx;
extern uint8_t EEMEM EEhfLenngthToTx;
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
-//Watchdog Vars
-uint8_t mcusr_mirror __attribute__ ((section (".noinit")));
-void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3")));
-
+//Watchdog Vars
+uint8_t mcusr_mirror __attribute__ ((section (".noinit")));
+void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3")));
+
//======================
@@ -188,8 +188,8 @@ int main (void)
{
uint8_t seconds, minutes, hours, days;
uint8_t error;
-
- //wdt_disable();
+
+ //wdt_disable();
ioinit(); //Setup IO pins and defaults
i2cSetTheDamnTWBRMyself(10);
@@ -201,34 +201,34 @@ int main (void)
_delay_ms(500);
- lprintf("WSB CPU Alive\n");
-
+ lprintf("WSB CPU Alive");
+
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Set Epoch\n"));
- #endif
+ lprintf_P(PSTR("Set Epoch"));
+ #endif
wdt_enable(WDTO_8S);
if(eeprom_read_byte(&EEEpochLock) == 0)
{
eeprom_write_dword(&EEepochOffset, 0);
- }
+ }
//error = getTime(&seconds, &minutes, &hours, &days);
-
- uint32_t offset = eeprom_read_dword(&EEepochOffset);
- uint8_t offsetDays = offset / 86400;
- uint8_t offsetHours = (offset - (offsetDays * 86400)) / 3600;
- uint8_t offsetMinutes = (offset - (offsetDays * 86400) - (offsetHours * 3600)) / 60;
- uint8_t offsetSeconds = (offset - (offsetDays * 86400) - (offsetHours * 3600) - (offsetMinutes * 60));
- ds3231write(0x00, offsetSeconds);
- ds3231write(0x01, offsetMinutes);
- ds3231write(0x02, offsetHours);
- ds3231write(0x03, offsetDays);
-
- eeprom_write_word(&EEcurrentBatchNumber, 0);
- eeprom_write_word(&EEbatchSampleStart, 0);
+
+ uint32_t offset = eeprom_read_dword(&EEepochOffset);
+ uint8_t offsetDays = offset / 86400;
+ uint8_t offsetHours = (offset - (offsetDays * 86400)) / 3600;
+ uint8_t offsetMinutes = (offset - (offsetDays * 86400) - (offsetHours * 3600)) / 60;
+ uint8_t offsetSeconds = (offset - (offsetDays * 86400) - (offsetHours * 3600) - (offsetMinutes * 60));
+ ds3231write(0x00, offsetSeconds);
+ ds3231write(0x01, offsetMinutes);
+ ds3231write(0x02, offsetHours);
+ ds3231write(0x03, offsetDays);
+
+ eeprom_write_word(&EEcurrentBatchNumber, 0);
+ eeprom_write_word(&EEbatchSampleStart, 0);
eeprom_write_word(&EEbatchSampleEnd, 0);
writeEpochStart(0, 0, 0, 0);
- lprintf("Still Alive\n");
+ lprintf("Still Alive");
// TMP100
setTMP100config(TMP100FC, 0xE0);
@@ -245,25 +245,25 @@ int main (void)
}
- lprintf("SSAlive\n");
-
- if((mcusr_mirror & 0x08) == 0x08)
- {
- //lprintf("WDTReset\n");
- }
-
+ lprintf("SSAlive");
+
+ if((mcusr_mirror & 0x08) == 0x08)
+ {
+ //lprintf("WDTReset");
+ }
- uint32_t rnow = now();
- scheduleQueueAdd(&resetWatchdog, rnow);
+
+ uint32_t rnow = now();
+ scheduleQueueAdd(&resetWatchdog, rnow);
scheduleQueueAdd(&incrementEpoch, rnow);
scheduleQueueAdd(&processMonitor, rnow);
scheduleQueueAdd(&calculateVspeed, rnow);
scheduleQueueAdd(&collectData, rnow);
- scheduleQueueAdd(&transmitSamples, rnow);
+ scheduleQueueAdd(&transmitSamples, rnow);
scheduleQueueAdd(&transmitShortReport, rnow+20); //Special case to give the comm controller a chance
scheduleQueueAdd(&ballastStaticTickle, rnow);
scheduleQueueAdd(&autoBallast, rnow);
- scheduleQueueAdd(&flightPhaseLogic, rnow);
+ scheduleQueueAdd(&flightPhaseLogic, rnow);
while(1)
{
@@ -273,18 +273,18 @@ int main (void)
volatile uint32_t rightNow = now();
error = scheduleQueueGetTop(&thisFunction, &scheduleTime);
- //lprintf("PTR: %p time: %lud now: %lud\n", ptrToFunction, scheduleTime, rightNow);
+ //lprintf("PTR: %p time: %lud now: %lud", ptrToFunction, scheduleTime, rightNow);
if(error == 0 && scheduleTime <= rightNow)
{
/*#ifdef FCPUDEBUG
- lprintf_P(PSTR("Running some function\n"));
+ lprintf_P(PSTR("Running some function"));
#endif*/
thisFunction(rightNow);
} else if (error == 0 && scheduleTime > rightNow)
{
/*#ifdef FCPUDEBUG
- lprintf_P(PSTR("ReScheduling some function\n"));
+ lprintf_P(PSTR("ReScheduling some function"));
#endif*/
scheduleQueueAdd(thisFunction, scheduleTime);
} else {
@@ -308,15 +308,15 @@ int main (void)
uint8_t cutdownStatus = 0;
uint8_t rapidHFEnable=0;
void receiveCommandHandler(uint8_t receiveDataLength, uint8_t* recieveData)
-{
- uint8_t temp;
-
- lprintf_P(PSTR("CPU I2C\n"));
- for(int i=0; i < receiveDataLength; i++)
- {
- lprintf("%x ", recieveData[i]);
- }
- lprintf("\n");
+{
+ uint8_t temp;
+
+ lprintf_P(PSTR("CPU I2C"));
+ for(int i=0; i < receiveDataLength; i++)
+ {
+ lprintf("%x ", recieveData[i]);
+ }
+ lprintf("");
switch(recieveData[0])
{
@@ -386,21 +386,21 @@ void receiveCommandHandler(uint8_t receiveDataLength, uint8_t* recieveData)
//if(receiveDataLength == 3)
{
uint16_t holder = ((uint16_t)recieveData[1]<<8) + recieveData[2];
- eeprom_write_word(&EEcurrentTelemetryVersion, holder);
+ eeprom_write_word(&EEcurrentTelemetryVersion, holder);
updateSpeedDial(holder);
}
break;
case 0x09:
//set Custom Bitmask Select
//if(receiveDataLength == 13)
- {
- uint32_t holder1 = (((uint32_t)recieveData[1])<<24) + (((uint32_t)recieveData[2])<<16) + (((uint32_t)recieveData[3])<<8) + ((uint32_t)recieveData[4]);
- uint32_t holder2 = (((uint32_t)recieveData[5])<<24) + (((uint32_t)recieveData[6])<<16) + (((uint32_t)recieveData[7])<<8) + ((uint32_t)recieveData[8]);
+ {
+ uint32_t holder1 = (((uint32_t)recieveData[1])<<24) + (((uint32_t)recieveData[2])<<16) + (((uint32_t)recieveData[3])<<8) + ((uint32_t)recieveData[4]);
+ uint32_t holder2 = (((uint32_t)recieveData[5])<<24) + (((uint32_t)recieveData[6])<<16) + (((uint32_t)recieveData[7])<<8) + ((uint32_t)recieveData[8]);
uint32_t holder3 = (((uint32_t)recieveData[9])<<24) + (((uint32_t)recieveData[10])<<16) + (((uint32_t)recieveData[11])<<8) + ((uint32_t)recieveData[12]);
- //eeprom_write_block((uint8_t*)recieveData[1], &EEcurrentTelemetryBitmap, sizeof(uint32_t)*3);
- lprintf("BM: %lx %lx %lx\n", holder1, holder2, ((uint32_t)recieveData[1])<<24);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], holder1 );
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], holder2 );
+ //eeprom_write_block((uint8_t*)recieveData[1], &EEcurrentTelemetryBitmap, sizeof(uint32_t)*3);
+ lprintf("BM: %lx %lx %lx", holder1, holder2, ((uint32_t)recieveData[1])<<24);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], holder1 );
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], holder2 );
eeprom_write_dword(&EEcurrentTelemetryBitmap[2], holder3 );
}
break;
@@ -423,7 +423,7 @@ void receiveCommandHandler(uint8_t receiveDataLength, uint8_t* recieveData)
#ifdef GSPDEBUG
if(error != 0)
{
- //lprintf_P(PSTR("Error Setting thermometer\n"));
+ //lprintf_P(PSTR("Error Setting thermometer"));
}
#endif
//Should probably set a status code here BEFORE FLIGHT
@@ -459,15 +459,15 @@ void receiveCommandHandler(uint8_t receiveDataLength, uint8_t* recieveData)
{
//It Looks Like You're trying to Schedule a cutdown!
//uint32_t time = ((uint32_t)recieveData[0] << 24) + ((uint32_t)recieveData[1] << 16) + ((uint32_t)recieveData[2] << 8) + recieveData[3];
- uint32_t time = ((((uint32_t)recieveData[1])<<8) + (recieveData[2]))*60;
- lprintf("Schd 4 %lu", time);
+ uint32_t time = ((((uint32_t)recieveData[1])<<8) + (recieveData[2]))*60;
+ lprintf("Schd 4 %lu", time);
scheduleQueueAdd(&timedCutdown, time);
}
break;
case 0x11:
//if(receiveDataLength == 3)
{
- //Send Ballast Controller the ballast command
+ //Send Ballast Controller the ballast command
uint8_t retVal;
uint8_t dataToSend[3] = {20,recieveData[0],recieveData[1]};
uint8_t errorTolerance = 0;
@@ -480,10 +480,10 @@ void receiveCommandHandler(uint8_t receiveDataLength, uint8_t* recieveData)
break;
case 0x12:
//set Disarm Auto Ballast
- //lprintf_P(PSTR("bdis\n"));
- temp = eeprom_read_byte(&EEautoBallastDisable);
- //lprintf_P(PSTR("bptr %p\n"), &EEautoBallastDisable);
- eeprom_write_byte(&EEautoBallastDisable, 1);
+ //lprintf_P(PSTR("bdis"));
+ temp = eeprom_read_byte(&EEautoBallastDisable);
+ //lprintf_P(PSTR("bptr %p"), &EEautoBallastDisable);
+ eeprom_write_byte(&EEautoBallastDisable, 1);
temp = eeprom_read_byte(&EEautoBallastDisable);
break;
case 0x13:
@@ -527,48 +527,48 @@ void receiveCommandHandler(uint8_t receiveDataLength, uint8_t* recieveData)
break;
case 0x1A:
enableReports = 0;
- break;
- case 0x1B:
- {
- int16_t holder = ((uint16_t)recieveData[1]<<8) + recieveData[2];
+ break;
+ case 0x1B:
+ {
+ int16_t holder = ((uint16_t)recieveData[1]<<8) + recieveData[2];
eeprom_write_word(&EEshortDataTransmitInterval, holder);
- }
- break;
- case 0x1C:
- {
- int16_t holder = ((uint16_t)recieveData[1]<<8) + recieveData[2];
- eeprom_write_word(&EEhfTimeToTx, holder);
- }
- break;
- case 0x1D:
- {
- eeprom_write_byte(&EEhfLenngthToTx, recieveData[0]);
- }
- break;
- case 0xf1:
- transmitSamples(0xFFFFFFFF);
- break;
- case 0xf2:
- transmitShortReport(0xFFFFFFFF);
- break;
- case 0xf4:
- while(1);
- break;
- case 0xF5:
- POWERPORT &= ~_BV(I2C9PT);
- hfSema = 0;
- lprintf("HFOFF\n");
- break;
- case 0xF6:
- POWERPORT |= _BV(I2C9PT);
- hfSema = 2;
- lprintf("HFON\n");
- break;
+ }
+ break;
+ case 0x1C:
+ {
+ int16_t holder = ((uint16_t)recieveData[1]<<8) + recieveData[2];
+ eeprom_write_word(&EEhfTimeToTx, holder);
+ }
+ break;
+ case 0x1D:
+ {
+ eeprom_write_byte(&EEhfLenngthToTx, recieveData[0]);
+ }
+ break;
+ case 0xf1:
+ transmitSamples(0xFFFFFFFF);
+ break;
+ case 0xf2:
+ transmitShortReport(0xFFFFFFFF);
+ break;
+ case 0xf4:
+ while(1);
+ break;
+ case 0xF5:
+ POWERPORT &= ~_BV(I2C9PT);
+ hfSema = 0;
+ lprintf("HFOFF");
+ break;
+ case 0xF6:
+ POWERPORT |= _BV(I2C9PT);
+ hfSema = 2;
+ lprintf("HFON");
+ break;
case 0xF7:
eeprom_write_byte(&EEEpochLock, recieveData[1]);
break;
case 0xFB:
- //lprintf_P(PSTR("Defaulting the EEPROM...\n"));
+ //lprintf_P(PSTR("Defaulting the EEPROM..."));
defaultEEPROM();
break;
case 0xFC:
@@ -584,181 +584,181 @@ void receiveCommandHandler(uint8_t receiveDataLength, uint8_t* recieveData)
dumpVarsToGSP();
break;
}
-}
-
-void updateSpeedDial(uint16_t speedDial)
-{
- #ifdef FCPUDEBUG
- lprintf_P(PSTR("SpdDial\n"));
- #endif
- switch(speedDial)
- {
- case 0x00:
- {
- //Default 1 minute collect, 15 minute batch
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01000000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 60);
- eeprom_write_word(&EEdataTransmitInterval, 900);
- }
- break;
- case 0x01:
- {
- //10 minute collect, 20 minute transmit
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 600);
- eeprom_write_word(&EEdataTransmitInterval, 1200);
- }
- break;
- case 0x02:
- {
- //5 minute collect, 15 minute transmit
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 300);
- eeprom_write_word(&EEdataTransmitInterval, 900);
- }
- break;
- case 0x03:
- {
- //15 minute collect, 15 minute transmit
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 900);
- eeprom_write_word(&EEdataTransmitInterval, 900);
- }
- break;
- case 0x04:
- {
- //15 minute collect, 30 minute transmit
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 900);
- eeprom_write_word(&EEdataTransmitInterval, 1800);
- }
- break;
- case 0x05:
- {
- //15 minute collect, 1 hour transmit
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 900);
- eeprom_write_word(&EEdataTransmitInterval, 3600);
- }
- break;
- case 0x06:
- {
- //1 minute collect, 1 minute transmit
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 60);
- eeprom_write_word(&EEdataTransmitInterval, 60);
- }
- break;
- case 0x07:
- {
- //1 minute collect, 5 minute transmit
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 60);
- eeprom_write_word(&EEdataTransmitInterval, 300);
- }
- break;
- /*case 0x08:
- {
- //Need Data Now!
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b00000000000010101010000100001000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b00000000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 60);
- eeprom_write_word(&EEdataTransmitInterval, 60);
- }
- break;
- case 0x09:
- {
- //Need Science Data now!
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010101011010101010000101011111);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
- eeprom_write_word(&EEdataCollectionInterval, 60);
- eeprom_write_word(&EEdataTransmitInterval, 60);
- }
- break;*/
-
- }
+}
+
+void updateSpeedDial(uint16_t speedDial)
+{
+ #ifdef FCPUDEBUG
+ lprintf_P(PSTR("SpdDial"));
+ #endif
+ switch(speedDial)
+ {
+ case 0x00:
+ {
+ //Default 1 minute collect, 15 minute batch
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01000000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 60);
+ eeprom_write_word(&EEdataTransmitInterval, 900);
+ }
+ break;
+ case 0x01:
+ {
+ //10 minute collect, 20 minute transmit
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 600);
+ eeprom_write_word(&EEdataTransmitInterval, 1200);
+ }
+ break;
+ case 0x02:
+ {
+ //5 minute collect, 15 minute transmit
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 300);
+ eeprom_write_word(&EEdataTransmitInterval, 900);
+ }
+ break;
+ case 0x03:
+ {
+ //15 minute collect, 15 minute transmit
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 900);
+ eeprom_write_word(&EEdataTransmitInterval, 900);
+ }
+ break;
+ case 0x04:
+ {
+ //15 minute collect, 30 minute transmit
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 900);
+ eeprom_write_word(&EEdataTransmitInterval, 1800);
+ }
+ break;
+ case 0x05:
+ {
+ //15 minute collect, 1 hour transmit
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 900);
+ eeprom_write_word(&EEdataTransmitInterval, 3600);
+ }
+ break;
+ case 0x06:
+ {
+ //1 minute collect, 1 minute transmit
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 60);
+ eeprom_write_word(&EEdataTransmitInterval, 60);
+ }
+ break;
+ case 0x07:
+ {
+ //1 minute collect, 5 minute transmit
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010100011010101010100001011001);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 60);
+ eeprom_write_word(&EEdataTransmitInterval, 300);
+ }
+ break;
+ /*case 0x08:
+ {
+ //Need Data Now!
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b00000000000010101010000100001000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b00000000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 60);
+ eeprom_write_word(&EEdataTransmitInterval, 60);
+ }
+ break;
+ case 0x09:
+ {
+ //Need Science Data now!
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], 0b01010101011010101010000101011111);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], 0b01100000000000000000000000000000);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], 0);
+ eeprom_write_word(&EEdataCollectionInterval, 60);
+ eeprom_write_word(&EEdataTransmitInterval, 60);
+ }
+ break;*/
+
+ }
}
void dumpVarsToGSP(void)
{
- //lprintf_P(PSTR("epochStartSec: %d\n"), eeprom_read_byte(&EEepochStartSeconds));
- //lprintf_P(PSTR("epochStartMin: %d\n"), eeprom_read_byte(&EEepochStartMinutes));
- //lprintf_P(PSTR("epochStartHrs: %d\n"), eeprom_read_byte(&EEepochStartHours));
- //lprintf_P(PSTR("epochStartDays: %d\n"), eeprom_read_byte(&EEepochStartDays));
+ //lprintf_P(PSTR("epochStartSec: %d"), eeprom_read_byte(&EEepochStartSeconds));
+ //lprintf_P(PSTR("epochStartMin: %d"), eeprom_read_byte(&EEepochStartMinutes));
+ //lprintf_P(PSTR("epochStartHrs: %d"), eeprom_read_byte(&EEepochStartHours));
+ //lprintf_P(PSTR("epochStartDays: %d"), eeprom_read_byte(&EEepochStartDays));
_delay_ms(500);
- lprintf_P(PSTR("ballastTrgtAlt: %u\n"), eeprom_read_word(&EEballastTargetAltitude));
- lprintf_P(PSTR("ballastTrgt +Vspd: %d\n"), eeprom_read_word(&EEballastTargetPositiveVSpeed));
- lprintf_P(PSTR("ballastTrgt -Vspd: %d\n"), eeprom_read_word(&EEballastTargetNegativeVSpeed));
+ lprintf_P(PSTR("ballastTrgtAlt: %u"), eeprom_read_word(&EEballastTargetAltitude));
+ lprintf_P(PSTR("ballastTrgt +Vspd: %d"), eeprom_read_word(&EEballastTargetPositiveVSpeed));
+ lprintf_P(PSTR("ballastTrgt -Vspd: %d"), eeprom_read_word(&EEballastTargetNegativeVSpeed));
- lprintf_P(PSTR("maydayAlt: %ud\n"), eeprom_read_word(&EEmaydayAltitude));
- lprintf_P(PSTR("maydayVSpd: %d\n"), eeprom_read_word(&EEmaydayVSpeed));
+ lprintf_P(PSTR("maydayAlt: %ud"), eeprom_read_word(&EEmaydayAltitude));
+ lprintf_P(PSTR("maydayVSpd: %d"), eeprom_read_word(&EEmaydayVSpeed));
_delay_ms(500);
- lprintf_P(PSTR("ballastSftyAlt: %u\n"), eeprom_read_word(&EEballastSafetyAltThresh));
- uint8_t variable = (volatile)eeprom_read_byte(&EEautoBallastDisable);
- lprintf_P(PSTR("autoBallast dsbled?: %d\n"), variable);
+ lprintf_P(PSTR("ballastSftyAlt: %u"), eeprom_read_word(&EEballastSafetyAltThresh));
+ uint8_t variable = (volatile)eeprom_read_byte(&EEautoBallastDisable);
+ lprintf_P(PSTR("autoBallast dsbled?: %d"), variable);
- //lprintf_P(PSTR("overOcean? %d\n"), eeprom_read_byte(&EEoverOceanFlag));
+ //lprintf_P(PSTR("overOcean? %d"), eeprom_read_byte(&EEoverOceanFlag));
- //lprintf_P(PSTR("nightTempForecast: %d\n"), eeprom_read_byte(&EEnightTemperatureForecast));
- //lprintf_P(PSTR("sunriseAntcpation: %ld\n"), eeprom_read_dword(&EEsunriseAnticipation));
+ //lprintf_P(PSTR("nightTempForecast: %d"), eeprom_read_byte(&EEnightTemperatureForecast));
+ //lprintf_P(PSTR("sunriseAntcpation: %ld"), eeprom_read_dword(&EEsunriseAnticipation));
_delay_ms(500);
- lprintf_P(PSTR("maxAllowedTXInterval: %u\n"), eeprom_read_word(&EEmaxAllowableTXInterval));
+ lprintf_P(PSTR("maxAllowedTXInterval: %u"), eeprom_read_word(&EEmaxAllowableTXInterval));
- lprintf_P(PSTR("batteryHeaterSet: %d\n"), eeprom_read_byte(&EEbatteryHeaterSetpoint));
+ lprintf_P(PSTR("batteryHeaterSet: %d"), eeprom_read_byte(&EEbatteryHeaterSetpoint));
- lprintf_P(PSTR("dataSampleInterval: %u\n"), eeprom_read_word(&EEdataCollectionInterval));
- lprintf_P(PSTR("batchTXInterval: %u\n"), eeprom_read_word(&EEdataTransmitInterval));
- lprintf_P(PSTR("shortTXInterval: %u\n"), eeprom_read_word(&EEshortDataTransmitInterval));
+ lprintf_P(PSTR("dataSampleInterval: %u"), eeprom_read_word(&EEdataCollectionInterval));
+ lprintf_P(PSTR("batchTXInterval: %u"), eeprom_read_word(&EEdataTransmitInterval));
+ lprintf_P(PSTR("shortTXInterval: %u"), eeprom_read_word(&EEshortDataTransmitInterval));
_delay_ms(500);
- lprintf_P(PSTR("HFdataXmitInterval: %u\n"), eeprom_read_word(&EEhfDataTransmitInterval));
- lprintf_P(PSTR("HFrapidXmitInterval: %u\n"), eeprom_read_byte(&EEhfRapidTransmit));
+ lprintf_P(PSTR("HFdataXmitInterval: %u"), eeprom_read_word(&EEhfDataTransmitInterval));
+ lprintf_P(PSTR("HFrapidXmitInterval: %u"), eeprom_read_byte(&EEhfRapidTransmit));
- //lprintf_P(PSTR("epochOfLastBatchTX: %ld\n"), eeprom_read_dword(&EEepochOfLastBatchTransmit));
+ //lprintf_P(PSTR("epochOfLastBatchTX: %ld"), eeprom_read_dword(&EEepochOfLastBatchTransmit));
- lprintf_P(PSTR("curBatchNumber: %u\n"), eeprom_read_word(&EEcurrentBatchNumber));
- lprintf_P(PSTR("batchSampleStart: %u\n"), eeprom_read_word(&EEbatchSampleStart));
- lprintf_P(PSTR("batchSampleEnd: %u\n"), eeprom_read_word(&EEbatchSampleEnd));
+ lprintf_P(PSTR("curBatchNumber: %u"), eeprom_read_word(&EEcurrentBatchNumber));
+ lprintf_P(PSTR("batchSampleStart: %u"), eeprom_read_word(&EEbatchSampleStart));
+ lprintf_P(PSTR("batchSampleEnd: %u"), eeprom_read_word(&EEbatchSampleEnd));
_delay_ms(500);
- //lprintf_P(PSTR("commEEPROMStart: %d\n"), eeprom_read_word(&EEcommPromStart));
- //lprintf_P(PSTR("commEEPROMEnd: %d\n"), eeprom_read_word(&EEcommPromEnd));
+ //lprintf_P(PSTR("commEEPROMStart: %d"), eeprom_read_word(&EEcommPromStart));
+ //lprintf_P(PSTR("commEEPROMEnd: %d"), eeprom_read_word(&EEcommPromEnd));
- //lprintf_P(PSTR("flightComputerResetCount: %d\n"), eeprom_read_byte(&EEflightComputerResetCount));
- //lprintf_P(PSTR("commModuleResetCount: %d\n"), eeprom_read_byte(&EEcommModuleResetCount));
+ //lprintf_P(PSTR("flightComputerResetCount: %d"), eeprom_read_byte(&EEflightComputerResetCount));
+ //lprintf_P(PSTR("commModuleResetCount: %d"), eeprom_read_byte(&EEcommModuleResetCount));
- lprintf_P(PSTR("Phase: %d\n"), eeprom_read_byte(&EEflightPhase));
+ lprintf_P(PSTR("Phase: %d"), eeprom_read_byte(&EEflightPhase));
_delay_ms(500);
- lprintf_P(PSTR("TelemBitmap: %lx "), eeprom_read_dword(&EEcurrentTelemetryBitmap[0]));
- lprintf_P(PSTR("%lx "), eeprom_read_dword(&EEcurrentTelemetryBitmap[1]));
- lprintf_P(PSTR("%lx\n"), eeprom_read_dword(&EEcurrentTelemetryBitmap[2]));
- lprintf_P(PSTR("telemetrySpeedDial: %d\n"), eeprom_read_word(&EEcurrentTelemetryVersion));
-
- lprintf_P(PSTR("epLoc: %d\n"), eeprom_read_byte(&EEEpochLock));
+ lprintf_P(PSTR("TelemBitmap: %lx "), eeprom_read_dword(&EEcurrentTelemetryBitmap[0]));
+ lprintf_P(PSTR("%lx "), eeprom_read_dword(&EEcurrentTelemetryBitmap[1]));
+ lprintf_P(PSTR("%lx"), eeprom_read_dword(&EEcurrentTelemetryBitmap[2]));
+ lprintf_P(PSTR("telemetrySpeedDial: %d"), eeprom_read_word(&EEcurrentTelemetryVersion));
+
+ lprintf_P(PSTR("epLoc: %d"), eeprom_read_byte(&EEEpochLock));
//int16_t EEMEM EEvSpeedHolderSamples[VSPEEDSAMPLESDESIRED];
//Maybe should print this for debug...
@@ -771,38 +771,38 @@ uint8_t ballastBabySit =0;
void processMonitor(uint32_t time)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("In Proc Mon\n"));
+ lprintf_P(PSTR("In Proc Mon"));
#endif
uint32_t currentBitmask[3];
currentBitmask[0] = eeprom_read_dword(&EEcurrentTelemetryBitmap[0]);
currentBitmask[1] = eeprom_read_dword(&EEcurrentTelemetryBitmap[1]);
currentBitmask[2] = eeprom_read_dword(&EEcurrentTelemetryBitmap[2]);
- uint16_t hfTimeToTx = eeprom_read_word(&EEhfTimeToTx);
- uint8_t hfLengthToTx = eeprom_read_byte(&EEhfLenngthToTx);
-
- if(((time/60) > hfTimeToTx) && hfSema == 0)
- {
- scheduleQueueAdd(&turnHfOn, time);
- scheduleQueueAdd(&turnHfOff, time+hfLengthToTx);
- eeprom_write_word(&EEhfTimeToTx, time+eeprom_read_byte(&EEhfDataTransmitInterval));
- }
-
- getGPS(&currentPositionData);
+ uint16_t hfTimeToTx = eeprom_read_word(&EEhfTimeToTx);
+ uint8_t hfLengthToTx = eeprom_read_byte(&EEhfLenngthToTx);
+
+ if(((time/60) > hfTimeToTx) && hfSema == 0)
+ {
+ scheduleQueueAdd(&turnHfOn, time);
+ scheduleQueueAdd(&turnHfOff, time+hfLengthToTx);
+ eeprom_write_word(&EEhfTimeToTx, time+eeprom_read_byte(&EEhfDataTransmitInterval));
+ }
+
+ getGPS(&currentPositionData);
if(currentPositionData.status == 0)
{
gpsFailures = 0;
} else {
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Bad GPS Data\n"));
+ lprintf_P(PSTR("Bad GPS Data"));
#endif
#ifndef OSHITDISABLE
//flush Vspeed
numberOfVSpeedSamples=0;
gpsFailures++;
- //turn on GPS status telemetry channel
- //lprintf_P(PSTR("CBM1\n"));
+ //turn on GPS status telemetry channel
+ //lprintf_P(PSTR("CBM1"));
currentBitmask[0] |= _BV(8);
#endif
}
@@ -811,7 +811,7 @@ void processMonitor(uint32_t time)
{
//Setting altitude to 0 will kick us into flight phase 3
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Critical GPS Failure\n"));
+ lprintf_P(PSTR("Critical GPS Failure"));
#endif
gpsFailures = CRITGPSFAIL + 1;
currentPositionData.altitude = 0;
@@ -832,7 +832,7 @@ void processMonitor(uint32_t time)
currentBitmask[0] |= (uint32_t)(1<<24);
}
- //GET RAW PACK VOLTAGE, If below Nominal, transmit
+ //GET RAW PACK VOLTAGE, If below Nominal, transmit
//get raw pack voltage
//AD7998 Interfacing
i2cSendStart();
@@ -842,7 +842,7 @@ void processMonitor(uint32_t time)
i2cSendByte(0x10);
i2cWaitForComplete();
i2cSendStop();
-
+
_delay_ms(5);
i2cSendStart();
@@ -864,19 +864,19 @@ void processMonitor(uint32_t time)
//(3.3 volts / 4096) * (24.07/4.07) = 0.0047647
//Multiply by 10 to get bigger value.
batteryValue = (uint16_t)((((float)batteryValue*0.0047647))*10.);
- uint8_t outputVoltage = (uint8_t)batteryValue;
+ uint8_t outputVoltage = (uint8_t)batteryValue;
if(batteryValue < 15)
{
currentBitmask[0] |= _BV(1);
}
- eeprom_write_dword(&EEcurrentTelemetryBitmap[0], currentBitmask[0]);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[1], currentBitmask[1]);
- eeprom_write_dword(&EEcurrentTelemetryBitmap[2], currentBitmask[2]);
-
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[0], currentBitmask[0]);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[1], currentBitmask[1]);
+ eeprom_write_dword(&EEcurrentTelemetryBitmap[2], currentBitmask[2]);
- scheduleQueueAdd(&processMonitor, time+5);
+
+ scheduleQueueAdd(&processMonitor, time+5);
}
@@ -889,7 +889,7 @@ void processMonitor(uint32_t time)
void calculateVspeed(uint32_t time)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("In Vspeed Calculator\n"));
+ lprintf_P(PSTR("In Vspeed Calculator"));
#endif
struct gpsData myGPS = currentPositionData;
@@ -912,7 +912,7 @@ void calculateVspeed(uint32_t time)
//int16_t thisVspeed = (int16_t)((thisAltitude - lastAltitude) / ((float)(time - lastRunTime)/60.));
int16_t thisVspeed = 30*(thisAltitude - lastAltitude);
vSpeedInstant[numberOfVSpeedSamples-1] = thisVspeed;
- lprintf_P(PSTR("This Vspeed: %d\n"), thisVspeed);
+ lprintf_P(PSTR("This Vspeed: %d"), thisVspeed);
int32_t vSpeedAdder=0;
for(int i = 0; i < numberOfVSpeedSamples; i++)
{
@@ -930,15 +930,15 @@ void calculateVspeed(uint32_t time)
}
void timedCutdown(uint32_t time)
-{
- lprintf_P(PSTR("Cutdown\n"));
- //BEFORE FLIGHT
+{
+ lprintf_P(PSTR("Cutdown"));
+ //BEFORE FLIGHT
i2cSendStart();
i2cWaitForComplete();
i2cSendByte(0x10);
i2cWaitForComplete();
i2cSendByte(0x99);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendStop();
//Send Comm Controller the cutdown command
//In response, will I receive the Cutdown Now command?
@@ -951,12 +951,12 @@ uint32_t lastBallastTime;
void autoBallast(uint32_t time)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("In autoBallast\n"));
+ lprintf_P(PSTR("In autoBallast"));
#endif
uint8_t retVal;
uint16_t targetAltitude = eeprom_read_word(&EEballastTargetAltitude);
uint16_t ballastSafety = eeprom_read_word(&EEballastSafetyAltThresh);
- uint8_t ballastDisabled = eeprom_read_byte(&EEautoBallastDisable);
+ uint8_t ballastDisabled = eeprom_read_byte(&EEautoBallastDisable);
struct gpsData myGPS = currentPositionData;
@@ -966,12 +966,12 @@ void autoBallast(uint32_t time)
if(ballastBabySit == 1)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Babysit Enable!\n"));
+ lprintf_P(PSTR("Babysit Enable!"));
#endif
if(vSpeedAvg > (currentTargetVspeed + babySitVertSpeed)/2)
{
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("Babysit: 1/2 T\n"));
+ //lprintf_P(PSTR("Babysit: 1/2 T"));
#endif
//Close ballast
//Send i2c address 0x09, 0d18
@@ -985,7 +985,7 @@ void autoBallast(uint32_t time)
if(errorTolerance >= CRITCOMFAIL)
{
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("Blst Error\n"));
+ //lprintf_P(PSTR("Blst Error"));
#endif
statusCode = (statusCode & 0xFFFD) | (1 << 1);
} else {
@@ -995,14 +995,14 @@ void autoBallast(uint32_t time)
ballastBabySit = 0;
} else {
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("Babysit: Waiting\n"));
+ //lprintf_P(PSTR("Babysit: Waiting"));
#endif
scheduleQueueAdd(&autoBallast, time+10);
}
} else {
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("No babysity\n"));
+ //lprintf_P(PSTR("No babysity"));
#endif
//If we're above the safety threshold
@@ -1019,19 +1019,19 @@ void autoBallast(uint32_t time)
if(thisAltitude <= targetAltitude)
{
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("Ballast: TVSpeed+\n"));
+ //lprintf_P(PSTR("Ballast: TVSpeed+"));
#endif
currentTargetVspeed = eeprom_read_word(&EEballastTargetPositiveVSpeed);
} else if(thisAltitude > targetAltitude)
{
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("Ballast: TVSpeed-\n"));
+ //lprintf_P(PSTR("Ballast: TVSpeed-"));
#endif
currentTargetVspeed = eeprom_read_word(&EEballastTargetNegativeVSpeed);
} /*else if(thisAltitude < targetAltitude && vSpeedAvg < currentTargetVspeed)
{
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("Ballast: TVSpeed0\n"));
+ //lprintf_P(PSTR("Ballast: TVSpeed0"));
#endif
currentTargetVspeed = 0;
}*/
@@ -1057,7 +1057,7 @@ void autoBallast(uint32_t time)
if(errorTolerance >= CRITCOMFAIL)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Blst Error\n"));
+ lprintf_P(PSTR("Blst Error"));
#endif
statusCode = (statusCode & 0xFFFD) | (1 << 1);
} else {
@@ -1070,7 +1070,7 @@ void autoBallast(uint32_t time)
} else {
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Ballast Disabled\n"));
+ lprintf_P(PSTR("Ballast Disabled"));
#endif
//turn off the ballast
@@ -1098,36 +1098,36 @@ void autoBallast(uint32_t time)
void collectData(uint32_t time)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("In Data Collect\n"));
+ lprintf_P(PSTR("In Data Collect"));
#endif
char sampleString[SAMPLESTRINGSIZEINCHARS];
memset(sampleString, 0x00, SAMPLESTRINGSIZEINCHARS);
//get time
- uint32_t epochNow = now();
- //lprintf("1 ");
+ uint32_t epochNow = now();
+ lprintf("1 ");
//get ambient pressure
long myPressure;
long myTemp;
- bmp085Convert(&myTemp, &myPressure);
- //lprintf("2 ");
+ bmp085Convert(&myTemp, &myPressure);
+ lprintf("2 ");
//get FC temp
uint16_t rawFCTemp;
int8_t internalTemp;
rawFCTemp = tmp100rawTemp(TMP100FC)>>4;
int16_t fctinm = get12bit2scomp(rawFCTemp);
- internalTemp = (int8_t)(fctinm/16);
+ internalTemp = (int8_t)(fctinm/16);
//Convert to 8 bit
-//lprintf("3 ");
+ lprintf("3 ");
//get ext temp
uint16_t rawExtTemp = tmp100rawTemp(TMP100EXT)>>4;
- int16_t externalTemperature = get12bit2scomp(rawExtTemp);
+ int16_t externalTemperature = get12bit2scomp(rawExtTemp);
lprintf("4 ");
//get battetry temp
uint16_t rawBattTemp = tmp100rawTemp(TMP101BH)>>4;
int16_t btinm = get12bit2scomp(rawBattTemp);
int8_t batteryTemperature = (int8_t)(btinm/16);
- //conver to 8 bit
- //lprintf("5 ");
+ //conver to 8 bit
+ lprintf("5 ");
//get humidity
//NEED COMMANDS FROM TIM
@@ -1158,7 +1158,7 @@ void collectData(uint32_t time)
i2cSendStop();
humFinal = ((uint16_t)humidity[0] << 8) | humidity[1];
- //lprintf("6 ");
+ lprintf("6 ");
//get coud sensor value
uint8_t cloudVal[2]= {0,0};
uint8_t cloudFinal;
@@ -1185,8 +1185,8 @@ void collectData(uint32_t time)
cloudVal[1] += i2cGetReceivedByte();
i2cWaitForComplete();
i2cSendStop();
- cloudFinal = (cloudVal[0] << 6) | (cloudVal[1] >> 2);
- //lprintf("7 ");
+ cloudFinal = (cloudVal[0] << 6) | (cloudVal[1] >> 2);
+ lprintf("7 ");
//NEED COMMANDS FROM TIM
//get longitude
//get latitude
@@ -1233,7 +1233,7 @@ void collectData(uint32_t time)
//Multiply by 10 to get bigger value.
batteryValue = (uint16_t)((((float)batteryValue*0.0047647))*10.);
uint8_t outputVoltage = (uint8_t)batteryValue;
- //lprintf("8 "); POTENTIAL FREEZE SPOT AFTER THIS.
+ lprintf("8 "); //POTENTIAL FREEZE SPOT AFTER THIS.
//get ballast valve state
uint8_t ballastError = 0;
i2cSendStart();
@@ -1262,7 +1262,7 @@ void collectData(uint32_t time)
ballastError |= i2cWaitForComplete();
i2cSendStop();
//1 = open, 0 = closed
- //lprintf("9 ");
+ lprintf("9 ");
//get ballast remaining
i2cSendStart();
ballastError |= i2cWaitForComplete();
@@ -1291,12 +1291,12 @@ void collectData(uint32_t time)
i2cSendStop();
statusCode = (statusCode & 0xFFFD) | (ballastError << 1);
//16 bit grams remaining
- //lprintf("10 ");
+ lprintf("10 ");
//get status code
- //variable StatusCode
-
- //Get Helium temperature
- int16_t heliumTemperature;
+ //variable StatusCode
+
+ //Get Helium temperature
+ /*int16_t heliumTemperature;
uint8_t helVal[2]= {0,0};
i2cSendStart();
i2cWaitForComplete();
@@ -1321,8 +1321,9 @@ void collectData(uint32_t time)
helVal[1] += i2cGetReceivedByte();
i2cWaitForComplete();
i2cSendStop();
- heliumTemperature = (int16_t)(((uint16_t)helVal[0] * 256) + (helVal[1]));
- //lprintf("11 ");
+ heliumTemperature = (int16_t)(((uint16_t)helVal[0] * 256) + (helVal[1]));*/
+ int16_t heliumTemperature = 10;
+ lprintf("11 ");
//NEED COMMANDS FROM TIM
//format into string
sprintf_P(sampleString, PSTR("%ld," //Epoch
@@ -1345,7 +1346,7 @@ void collectData(uint32_t time)
"%d," //Voltage
"%d,%d," //Ballast Valve State and Amount Remaining
"%d," //Dewpoint
- "%d," //status Code
+ "%d," //status Code
"%d,"), //Helium Temperature
epochNow,
myPressure, myPressure/2, //Ambient Pressure Raw and Calculate, NO RAW YET
@@ -1371,35 +1372,35 @@ void collectData(uint32_t time)
ballastRemaining,
-14,
statusCode, heliumTemperature);
- //Pad with spaces
+ //Pad with spaces
// lprintf("12 ");
- uint8_t ssLen = strlen(sampleString);
+ uint8_t ssLen = strlen(sampleString);
uint8_t k;
for(k = ssLen; k < (SAMPLESTRINGSIZEINCHARS - 2); k++)
{
sampleString[k] = '.';
- }
- //lprintf("pw: %d\n", k);
+ }
+ //lprintf("pw: %d", k);
lprintf("13 ");
sampleString[SAMPLESTRINGSIZEINCHARS-2] = '\r';
sampleString[SAMPLESTRINGSIZEINCHARS-1] = '\n';
sampleString[SAMPLESTRINGSIZEINCHARS] = '\0';
//store in openlog
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Sample String: \n"));
+ lprintf_P(PSTR("Sample String: "));
for(int i=0; i < SAMPLESTRINGSIZEINCHARS; i++)
{
- lprintf("%c", sampleString[i]);
+ lprintf("%s", sampleString);
}
#endif
- putDataSample(sampleString);
-
-
-
- //Here is where we increment the batch so that things actually get transmitted.
- uint16_t batchSampleEnd = eeprom_read_word(&EEbatchSampleEnd);
- eeprom_write_word(&EEbatchSampleEnd, ++batchSampleEnd);
+ putDataSample(sampleString);
+
+
+
+ //Here is where we increment the batch so that things actually get transmitted.
+ uint16_t batchSampleEnd = eeprom_read_word(&EEbatchSampleEnd);
+ eeprom_write_word(&EEbatchSampleEnd, ++batchSampleEnd);
//reschedule myself
if(time != 0xFFFFFFFF)
@@ -1408,126 +1409,126 @@ void collectData(uint32_t time)
} else {
//Bogus time means testing time!
}
-}
-
-void transmitShortReport(uint32_t time)
-{
+}
+
+void transmitShortReport(uint32_t time)
+{
if(enableReports)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Generating Report\n"));
- #endif
- uint16_t desiredTX = eeprom_read_word(&EEshortDataTransmitInterval);
+ lprintf_P(PSTR("Generating Report"));
+ #endif
+ uint16_t desiredTX = eeprom_read_word(&EEshortDataTransmitInterval);
uint8_t packet1[6];
- uint8_t packet2[6];
-
- float tmp1;
- uint32_t lon_code, lat_code;
- if(currentPositionData.longitude < 0.0 )
- {
- /* west */
- tmp1 = (currentPositionData.longitude + 360.0)/360.0;
- }
- else
- {
- /* east */
- tmp1 = currentPositionData.longitude/360.0;
- }
- lon_code = (uint32_t) (tmp1 * 0x0FFFFFF) & 0x0FFFFFF;
- tmp1 = -(currentPositionData.latitude - 90.0)/180.0;
- lat_code = (uint32_t) (tmp1 * 0x0FFFFFF) & 0x0FFFFFF;
-
- if((reportCounterH & 0x03) == 0)
- {
- reportCounterH++;
- }
- if((reportCounterL & 0x03) == 0)
- {
- reportCounterL++;
- }
-
- uint32_t rightNow = now();
- packet1[0] = lon_code>>16;
- packet1[1] = lon_code>>8;
+ uint8_t packet2[6];
+
+ float tmp1;
+ uint32_t lon_code, lat_code;
+ if(currentPositionData.longitude < 0.0 )
+ {
+ /* west */
+ tmp1 = (currentPositionData.longitude + 360.0)/360.0;
+ }
+ else
+ {
+ /* east */
+ tmp1 = currentPositionData.longitude/360.0;
+ }
+ lon_code = (uint32_t) (tmp1 * 0x0FFFFFF) & 0x0FFFFFF;
+ tmp1 = -(currentPositionData.latitude - 90.0)/180.0;
+ lat_code = (uint32_t) (tmp1 * 0x0FFFFFF) & 0x0FFFFFF;
+
+ if((reportCounterH & 0x03) == 0)
+ {
+ reportCounterH++;
+ }
+ if((reportCounterL & 0x03) == 0)
+ {
+ reportCounterL++;
+ }
+
+ uint32_t rightNow = now();
+ packet1[0] = lon_code>>16;
+ packet1[1] = lon_code>>8;
packet1[2] = lon_code;
packet1[3] = (currentPositionData.altitude/50) >> 2;
packet1[4] = (((currentPositionData.altitude/50) << 6) & 0xC0) | (((rightNow / 60) >> 8) & 0x0F);
packet1[5] = (rightNow/60);
-
- packet2[0] = lat_code>>16;
- packet2[1] = lat_code>>8;
+
+ packet2[0] = lat_code>>16;
+ packet2[1] = lat_code>>8;
packet2[2] = lat_code;
packet2[3] = currentPositionData.speed;
packet2[4] = (1<<4) | (((rightNow / 60) >> 8) & 0x0F);
- packet2[5] = (rightNow/60);
-
- if(currentPositionData.status != 0)
- {
- packet2[4] |= _BV(5);
- }
-
- //lprintf("N: %lu\n", rightNow);
- //lprintf("T1: %u T2: %u\n", ((packet1[4] & 0xF) <<8) + packet1[5], ((packet2[4] & 0xF)<<8) + packet2[5]);
-
- reportCounterL++;
- reportCounterH++;
-
+ packet2[5] = (rightNow/60);
+
+ if(currentPositionData.status != 0)
+ {
+ packet2[4] |= _BV(5);
+ }
+
+ //lprintf("N: %lu", rightNow);
+ //lprintf("T1: %u T2: %u", ((packet1[4] & 0xF) <<8) + packet1[5], ((packet2[4] & 0xF)<<8) + packet2[5]);
+
+ reportCounterL++;
+ reportCounterH++;
+
i2cSendStart();
i2cWaitForComplete();
i2cSendByte(0x10);
i2cWaitForComplete();
i2cSendByte(0x0);
- i2cWaitForComplete();
-
+ i2cWaitForComplete();
+
i2cSendByte(packet1[0]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet1[1]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet1[2]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet1[3]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet1[4]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet1[5]);
- i2cWaitForComplete();
-
+ i2cWaitForComplete();
+
i2cSendByte(packet2[0]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet2[1]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet2[2]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet2[3]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet2[4]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
i2cSendByte(packet2[5]);
- i2cWaitForComplete();
+ i2cWaitForComplete();
- i2cSendStop();
- if(time != 0xFFFFFFFF)
- {
- scheduleQueueAdd(&transmitShortReport, time+desiredTX);
+ i2cSendStop();
+ if(time != 0xFFFFFFFF)
+ {
+ scheduleQueueAdd(&transmitShortReport, time+desiredTX);
}
- }
+ }
}
void transmitSamples(uint32_t time)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Sample TX\n"));
+ lprintf_P(PSTR("Sample TX"));
#endif
loadBatch();
flushSatQueue();
uint16_t maxTX = eeprom_read_word(&EEmaxAllowableTXInterval);
uint16_t desiredTX = eeprom_read_word(&EEdataTransmitInterval);
-
- if(time == 0xFFFFFFFF)
- {
-
+
+ if(time == 0xFFFFFFFF)
+ {
+
} else{
if(maxTX > desiredTX)
scheduleQueueAdd(&transmitSamples, time+desiredTX);
@@ -1543,25 +1544,25 @@ void transmitSamples(uint32_t time)
void rapidHFXmit(uint32_t time)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Rapid HF TX\n"));
+ lprintf_P(PSTR("Rapid HF TX"));
#endif
if(rapidHFEnable == 1 && hfSema != 2)
{
- //send comm controller rapid HF command
- POWERPORT |= _BV(I2C9PT);
+ //send comm controller rapid HF command
+ POWERPORT |= _BV(I2C9PT);
hfSema = 1;
scheduleQueueAdd(&rapidHFXmit, time+eeprom_read_byte(&EEhfRapidTransmit));
- } else {
- POWERPORT &= ~_BV(I2C9PT);
- hfSema = 0;
+ } else {
+ POWERPORT &= ~_BV(I2C9PT);
+ hfSema = 0;
}
}
void ballastStaticTickle(uint32_t time)
{
#ifdef FCPUDEBUG
- lprintf_P(PSTR("bllst tckl\n"));
+ lprintf_P(PSTR("bllst tckl"));
#endif
if((time - lastBallastTime) > 1800)
{
@@ -1576,7 +1577,7 @@ void ballastStaticTickle(uint32_t time)
if(errorTolerance >= CRITCOMFAIL)
{
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("Ballast Error\n"));
+ //lprintf_P(PSTR("Ballast Error"));
#endif
statusCode = (statusCode & 0xFFFD) | (1 << 1);
} else {
@@ -1591,7 +1592,7 @@ void ballastStaticTickle(uint32_t time)
void flightPhaseLogic(uint32_t time)
{
#ifdef FCPUDEBUG
- //lprintf_P(PSTR("In Phase Logic\n"));
+ //lprintf_P(PSTR("In Phase Logic"));
#endif
uint8_t currentPhase = eeprom_read_byte(&EEflightPhase);
struct gpsData myGPS = currentPositionData;
@@ -1612,21 +1613,21 @@ void flightPhaseLogic(uint32_t time)
{
#ifdef FCPUDEBUG
_delay_ms(500);
- //lprintf_P(PSTR("Where am I going?! Entering Phase 1\n"));
+ //lprintf_P(PSTR("Where am I going?! Entering Phase 1"));
#endif
myPhase = 1;
_delay_ms(500);
//Save time
}
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Phase 0: Pre\n"));
+ lprintf_P(PSTR("Phase 0: Pre"));
#endif
//reschedule 1 second from now
scheduleQueueAdd(&flightPhaseLogic, time+1);
break;
case 1:
- //change sample time to 30 seconds
+ //change sample time to 30 seconds
//this is really stupid. change this BEFORE FLIGHT
//eeprom_write_word(&EEdataCollectionInterval, 30);
//schedule rapid hf xmit
@@ -1645,25 +1646,25 @@ void flightPhaseLogic(uint32_t time)
}
scheduleQueueAdd(&flightPhaseLogic, time+10);
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Phase 1: Climb\n"));
+ lprintf_P(PSTR("Phase 1: Climb"));
#endif
break;
case 2:
//disable rapid hf xmit
rapidHFEnable = 0;
//make sure sat is enabled in here! BEFORE FLIGHT
if((vSpeedAvg < maydayVSpeed) || (thisAltitude < maydayAltitude) || (cutdownStatus == 1) && (myFlags & 1 == 1))
- {
+ {
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Phase 3 Criteria\n"));
- //lprintf_P(PSTR("VS: %d A: %d\n"), vSpeedAvg, thisAltitude);
+ lprintf_P(PSTR("Phase 3 Criteria"));
+ //lprintf_P(PSTR("VS: %d A: %d"), vSpeedAvg, thisAltitude);
#endif
myPhase = 3;
}
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Phase 2: Cruise\n"));
+ lprintf_P(PSTR("Phase 2: Cruise"));
#endif
- scheduleQueueAdd(&flightPhaseLogic, time+30);
+ scheduleQueueAdd(&flightPhaseLogic, time+30);
break;
case 3:
//disable sat in here! BEFORE FLIGHT
@@ -1678,81 +1679,81 @@ void flightPhaseLogic(uint32_t time)
myPhase = 2;
}
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Phase 3: FALLING\n"));
+ lprintf_P(PSTR("Phase 3: FALLING"));
#endif
scheduleQueueAdd(&flightPhaseLogic, time+1);
break;
case 4:
//reset HF and Sat Sample and Transmit Intervals to 1 hour
scheduleQueueAdd(&flightPhaseLogic, time+3600);
#ifdef FCPUDEBUG
- lprintf_P(PSTR("Phase 4: Land\n"));
+ lprintf_P(PSTR("Phase 4: Land"));
#endif
break;
default:
#ifdef FCPUDEBUG
- lprintf_P(PSTR("ERR!\n"));
+ lprintf_P(PSTR("ERR!"));
#endif
break;
}
eeprom_write_byte(&EEflightPhase, (myFlags << 4) + myPhase);
-}
-
-void resetWatchdog(uint32_t time)
-{
-
- wdt_reset();
-
- #ifdef FCPUDEBUG
- //lprintf_P(PSTR("Reset WDT\n"));
- #endif
-
- scheduleQueueAdd(&resetWatchdog, time+1);
-
-}
-
-void turnHfOff(uint32_t time)
-{
- POWERPORT &= ~_BV(I2C9PT);
-
- #ifdef FCPUDEBUG
- lprintf_P(PSTR("HF ON\n"));
- #endif
-
-}
-
-void turnHfOn(uint32_t time)
-{
-
- POWERPORT |= _BV(I2C9PT);
- #ifdef FCPUDEBUG
- lprintf_P(PSTR("HF OFF\n"));
- #endif
-
-}
-
-void incrementEpoch(uint32_t time)
-{
- eeprom_write_dword(&EEepochOffset, time);
-
- scheduleQueueAdd(&incrementEpoch, time+1);
+}
+
+void resetWatchdog(uint32_t time)
+{
+
+ wdt_reset();
+
+ #ifdef FCPUDEBUG
+ //lprintf_P(PSTR("Reset WDT"));
+ #endif
+
+ scheduleQueueAdd(&resetWatchdog, time+1);
+
+}
+
+void turnHfOff(uint32_t time)
+{
+ POWERPORT &= ~_BV(I2C9PT);
+
+ #ifdef FCPUDEBUG
+ lprintf_P(PSTR("HF ON"));
+ #endif
+
+}
+
+void turnHfOn(uint32_t time)
+{
+
+ POWERPORT |= _BV(I2C9PT);
+ #ifdef FCPUDEBUG
+ lprintf_P(PSTR("HF OFF"));
+ #endif
+
+}
+
+void incrementEpoch(uint32_t time)
+{
+ eeprom_write_dword(&EEepochOffset, time);
+
+ scheduleQueueAdd(&incrementEpoch, time+1);
}
inline uint32_t now(void)
{
- uint8_t seconds, minutes, hours, days;
- uint8_t error;
- error = getTime(&seconds, &minutes, &hours, &days);
- while(error != 0)
- {
- _delay_ms(50);
- error = getTime(&seconds, &minutes, &hours, &days);
- }
- //lprintf("Now: %lu\n", getEpochSeconds(seconds, minutes, hours, days));
- return getEpochSeconds(seconds, minutes, hours, days);
+ uint8_t seconds, minutes, hours, days;
+ uint8_t error;
+ error = getTime(&seconds, &minutes, &hours, &days);
+ while(error != 0)
+ {
+ _delay_ms(50);
+ error = getTime(&seconds, &minutes, &hours, &days);
+ }
+ //lprintf("Now: %lu", getEpochSeconds(seconds, minutes, hours, days));
+ return getEpochSeconds(seconds, minutes, hours, days);
}
@@ -1799,13 +1800,13 @@ uint8_t uart_getchar(void)
while( !(UCSR1A & (1<<RXC1)) && (errorCounter > 100))
{
errorCounter--;
- }
- if(errorCounter <= 101)
- {
- return 0xff;
- } else {
- return UDR1;
- }
+ }
+ if(errorCounter <= 101)
+ {
+ return 0xff;
+ } else {
+ return UDR1;
+ }
}
@@ -1826,7 +1827,7 @@ int lprintf(char *str, ...)
return 1;
} else {
int i=0;
- i2cSend[0] = 0x05;
+ i2cSend[0] = 'F';
for(i=0; i <=chars; i++)
{
i2cSend[i+1] = (uint8_t)lstr[i];
@@ -1860,7 +1861,7 @@ int lprintf_P(const char *str, ...)
return 1;
} else {
int i=0;
- i2cSend[0] = 0x05;
+ i2cSend[0] = 'F';
for(i=0; i <=chars; i++)
{
i2cSend[i+1] = (uint8_t)lstr[i];
@@ -1876,10 +1877,10 @@ int lprintf_P(const char *str, ...)
}
_delay_ms(100);
}
-
-void get_mcusr(void)
-{
- mcusr_mirror = MCUSR;
- MCUSR = 0;
- wdt_disable();
-}
+
+void get_mcusr(void)
+{
+ mcusr_mirror = MCUSR;
+ MCUSR = 0;
+ wdt_disable();
+}
View
18 parsing/gps.c
@@ -60,13 +60,13 @@ void getGPS(struct gpsData *outputData)
} while((strncmp("$GPRMC", lineBuff, 6) != 0) && errorTracker < 100);
// End GPRMC Acquisition Section
- //lprintf("et: %d\n", errorTracker);
+ //lprintf("et: %d", errorTracker);
wdt_reset();
//If something is wrong, return before we try to parse the data.
//Set the output status to "Loco".
if(errorTracker >= 100)
{
- lprintf_P(PSTR("ERR\n"));
+ lprintf_P(PSTR("ERR"));
outputData->status = 3;
return;
}
@@ -272,7 +272,7 @@ void debugPrintRawStrings(void)
//Needed so the first comparison works out correctly
memset(lineBuff, 0x00, 100);
- lprintf_P(PSTR("In Ur GPS Debug\n"));
+ lprintf_P(PSTR("In Ur GPS Debug"));
do
{
@@ -301,15 +301,15 @@ void debugPrintRawStrings(void)
checksum = checksum ^ lineBuff[j];
}
- lprintf_P(PSTR("CS: %x TCS: %x\n"), checksum, tSum);
+ lprintf_P(PSTR("CS: %x TCS: %x"), checksum, tSum);
for(uint8_t j = 0; j < i; j++)
{
lprintf("%c", lineBuff[j]);
}
if(tSum == checksum)
{
- lprintf_P(PSTR("Checksum Valid\n"));
+ lprintf_P(PSTR("Checksum Valid"));
}
memset(lineBuff, 0x00, 100);
@@ -337,15 +337,15 @@ void debugPrintRawStrings(void)
checksum = checksum ^ lineBuff[j];
}
- lprintf_P(PSTR("CS: %x TCS: %x\n"), checksum, tSum);
+ lprintf_P(PSTR("CS: %x TCS: %x"), checksum, tSum);
for(uint8_t j = 0; j < i; j++)
{
lprintf("%c", lineBuff[j]);
}
if(tSum == checksum)
{
- lprintf_P(PSTR("Checksum Valid\n"));
+ lprintf_P(PSTR("Checksum Valid"));
}
memset(lineBuff, 0x00, 100);
@@ -372,15 +372,15 @@ void debugPrintRawStrings(void)
checksum = checksum ^ lineBuff[j];
}
- lprintf_P(PSTR("CS: %x TCS: %x\n"), checksum, tSum);
+ lprintf_P(PSTR("CS: %x TCS: %x"), checksum, tSum);
for(uint8_t j = 0; j < i; j++)
{
lprintf("%c", lineBuff[j]);
}
if(tSum == checksum)
{
- lprintf_P(PSTR("Checksum Valid\n"));
+ lprintf_P(PSTR("Checksum Valid"));
}
}

0 comments on commit 0edd698

Please sign in to comment.
Something went wrong with that request. Please try again.