*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdarg.h>
+#ifndef AO_APRS_TEST
+#include <ao.h>
+#endif
+
#include <ao_aprs.h>
typedef int bool_t;
// Public methods, constants, and data structures for each class.
-/// Operational modes of the AD9954 DDS for the ddsSetMode function.
-typedef enum
-{
- /// Device has not been initialized.
- DDS_MODE_NOT_INITIALIZED,
-
- /// Device in lowest power down mode.
- DDS_MODE_POWERDOWN,
-
- /// Generate FM modulated audio tones.
- DDS_MODE_AFSK,
-
- /// Generate true FSK tones.
- DDS_MODE_FSK
-} DDS_MODE;
-
void ddsInit();
void ddsSetAmplitude (uint8_t amplitude);
void ddsSetOutputScale (uint16_t amplitude);
void ddsSetFSKFreq (uint32_t ftw0, uint32_t ftw1);
void ddsSetFreq (uint32_t freq);
void ddsSetFTW (uint32_t ftw);
-void ddsSetMode (DDS_MODE mode);
-
-/// Type of GPS fix.
-typedef enum
-{
- /// No GPS FIX
- GPS_NO_FIX,
-
- /// 2D (Latitude/Longitude) fix.
- GPS_2D_FIX,
-
- /// 3D (Latitude/Longitude/Altitude) fix.
- GPS_3D_FIX
-} GPS_FIX_TYPE;
-
-/// GPS Position information.
-typedef struct
-{
- /// Flag that indicates the position information has been updated since it was last checked.
- bool_t updateFlag;
-
- /// Month in UTC time.
- uint8_t month;
-
- /// Day of month in UTC time.
- uint8_t day;
-
- /// Hours in UTC time.
- uint8_t hours;
-
- /// Minutes in UTC time.
- uint8_t minutes;
-
- /// Seconds in UTC time.
- uint8_t seconds;
-
- /// Year in UTC time.
- uint16_t year;
-
- /// Latitude in milli arc-seconds where + is North, - is South.
- int32_t latitude;
-
- /// Longitude in milli arc-seconds where + is East, - is West.
- int32_t longitude;
-
- /// Altitude in cm
- int32_t altitudeCM;
-
- /// Calculated altitude in feet
- int32_t altitudeFeet;
-
- /// 3D speed in cm/second.
- uint16_t vSpeed;
-
- /// 2D speed in cm/second.
- uint16_t hSpeed;
-
- /// Heading units of 0.1 degrees.
- uint16_t heading;
-
- /// DOP (Dilution of Precision)
- uint16_t dop;
-
- /// 16-bit number that represents status of GPS engine.
- uint16_t status;
-
- /// Number of tracked satellites used in the fix position.
- uint8_t trackedSats;
-
- /// Number of visible satellites.
- uint8_t visibleSats;
-} GPSPOSITION_STRUCT;
-
-GPSPOSITION_STRUCT gpsPosition;
-
-void gpsInit();
-bool_t gpsIsReady();
-GPS_FIX_TYPE gpsGetFixType();
-int32_t gpsGetPeakAltitude();
-void gpsPowerOn();
-bool_t gpsSetup();
-void gpsUpdate();
uint16_t sysCRC16(uint8_t *buffer, uint8_t length, uint16_t crc);
void timeSetDutyCycle (uint8_t dutyCycle);
void timeUpdate();
-/// Operational modes of the TNC for the tncSetMode function.
-typedef enum
-{
- /// No operation waiting for setup and configuration.
- TNC_MODE_STANDBY,
-
- /// 1200 bps using A-FSK (Audio FSK) tones.
- TNC_MODE_1200_AFSK,
-
- /// 9600 bps using true FSK tones.
- TNC_MODE_9600_FSK
-} TNC_DATA_MODE;
-
void tncInit();
bool_t tncIsFree();
void tncHighRate(bool_t state);
-void tncSetMode (TNC_DATA_MODE dataMode);
void tnc1200TimerTick();
-void tnc9600TimerTick();
void tncTxByte (uint8_t value);
-void tncTxPacket(TNC_DATA_MODE dataMode);
+void tncTxPacket(void);
/** @} */
* @{
*/
-/// AD9954 CFR1 - Control functions including RAM, profiles, OSK, sync, sweep, SPI, and power control settings.
-#define DDS_AD9954_CFR1 0x00
-
-/// AD9954 CFR2 - Control functions including sync, PLL multiplier, VCO range, and charge pump current.
-#define DDS_AD9954_CFR2 0x01
-
-/// AD9954 ASF - Auto ramp rate speed control and output scale factor (0x0000 to 0x3fff).
-#define DDS_AD9954_ASF 0x02
-
-/// AD9954 ARR - Amplitude ramp rate for OSK function.
-#define DDS_AD9954_ARR 0x03
-
-/// AD9954 FTW0 - Frequency tuning word 0.
-#define DDS_AD9954_FTW0 0x04
-
-/// AD9954 FTW1 - Frequency tuning word 1
-#define DDS_AD9954_FTW1 0x06
-
-/// AD9954 NLSCW - Negative Linear Sweep Control Word used for spectral shaping in FSK mode
-#define DDS_AD9954_NLSCW 0x07
-
-/// AD9954 PLSCW - Positive Linear Sweep Control Word used for spectral shaping in FSK mode
-#define DDS_AD9954_PLSCW 0x08
-
-/// AD9954 RSCW0 - RAM Segment Control Word 0
-#define DDS_AD9954_RWCW0 0x07
-
-/// AD9954 RSCW0 - RAM Segment Control Word 1
-#define DDS_AD9954_RWCW1 0x08
-
-/// AD9954 RAM segment
-#define DDS_RAM 0x0b
-
-/// Current operational mode.
-DDS_MODE ddsMode;
-
/// Number of digits in DDS frequency to FTW conversion.
#define DDS_FREQ_TO_FTW_DIGITS 9
*/
void ddsSetFTW (uint32_t ftw)
{
- static int id;
int x = ftw - freqTable[0];
- putchar (x > 0 ? 0xff : 0x0);
-// printf ("%d %d\n", id++, x > 0 ? 1 : 0);
-}
-
-/**
- * Convert frequency in hertz to 32-bit DDS FTW (Frequency Tune Word).
- *
- * @param freq frequency in Hertz
- *
- */
-void ddsSetFreq(uint32_t freq)
-{
- uint8_t i;
- uint32_t ftw;
-
- // To avoid rounding errors with floating point math, we do a long multiply on the data.
- ftw = freq * DDS_MULT[0];
-
- for (i = 0; i < DDS_FREQ_TO_FTW_DIGITS - 1; ++i)
- ftw += (freq * DDS_MULT[i+1]) / DDS_DIVISOR[i];
-
- ddsSetFTW (ftw);
-}
-
-/**
- * Set DDS frequency tuning word for the FSK 0 and 1 values. The output frequency is equal
- * to RefClock * (ftw / 2 ^ 32).
- *
- * @param ftw0 frequency tuning word for the FSK 0 value
- * @param ftw1 frequency tuning word for the FSK 1 value
- */
-void ddsSetFSKFreq (uint32_t ftw0, uint32_t ftw1)
-{
-// printf ("ftw0 %d ftw1 %d\n", ftw0, ftw1);
-}
-
-/**
- * Set the DDS to run in A-FSK, FSK, or PSK31 mode
- *
- * @param mode DDS_MODE_APRS, DDS_MODE_PSK31, or DDS_MODE_HF_APRS constant
- */
-void ddsSetMode (DDS_MODE mode)
-{
-// printf ("mode %d\n", mode);
+ putchar (x > 0 ? 0xc0 : 0x40);
}
/** @} */
-/**
- * @defgroup GPS Motorola M12+ GPS Engine
- *
- * Functions to control the Motorola M12+ GPS engine in native binary protocol mode.
- *
- * @{
- */
-
-/// The maximum length of a binary GPS engine message.
-#define GPS_BUFFER_SIZE 50
-
-/// GPS parse engine state machine values.
-typedef enum
-{
- /// 1st start character '@'
- GPS_START1,
-
- /// 2nd start character '@'
- GPS_START2,
-
- /// Upper case 'A' - 'Z' message type
- GPS_COMMAND1,
-
- /// Lower case 'a' - 'z' message type
- GPS_COMMAND2,
-
- /// 0 - xx bytes based on message type 'Aa'
- GPS_READMESSAGE,
-
- /// 8-bit checksum
- GPS_CHECKSUMMESSAGE,
-
- /// End of message - Carriage Return
- GPS_EOMCR,
-
- /// End of message - Line Feed
- GPS_EOMLF
-} GPS_PARSE_STATE_MACHINE;
-
-/// Index into gpsBuffer used to store message data.
-uint8_t gpsIndex;
-
-/// State machine used to parse the GPS message stream.
-GPS_PARSE_STATE_MACHINE gpsParseState;
-
-/// Buffer to store data as it is read from the GPS engine.
-uint8_t gpsBuffer[GPS_BUFFER_SIZE];
-
-/// Peak altitude detected while GPS is in 3D fix mode.
-int32_t gpsPeakAltitude;
-
-/// Checksum used to verify binary message from GPS engine.
-uint8_t gpsChecksum;
-
-/// Last verified GPS message received.
-GPSPOSITION_STRUCT gpsPosition;
-
-/**
- * Get the type of fix.
- *
- * @return gps fix type enumeration
- */
-GPS_FIX_TYPE gpsGetFixType()
-{
- // The upper 3-bits determine the fix type.
- switch (gpsPosition.status & 0xe000)
- {
- case 0xe000:
- return GPS_3D_FIX;
-
- case 0xc000:
- return GPS_2D_FIX;
-
- default:
- return GPS_NO_FIX;
- } // END switch
-}
-
-/**
- * Peak altitude detected while GPS is in 3D fix mode since the system was booted.
- *
- * @return altitude in feet
- */
-int32_t gpsGetPeakAltitude()
-{
- return gpsPeakAltitude;
-}
-
-/**
- * Initialize the GPS subsystem.
- */
-void gpsInit()
-{
- // Initial parse state.
- gpsParseState = GPS_START1;
-
- // Assume we start at sea level.
- gpsPeakAltitude = 0;
-
- // Clear the structure that stores the position message.
- memset (&gpsPosition, 0, sizeof(GPSPOSITION_STRUCT));
-
- // Setup the timers used to measure the 1-PPS time period.
-// setup_timer_3(T3_INTERNAL | T3_DIV_BY_1);
-// setup_ccp2 (CCP_CAPTURE_RE | CCP_USE_TIMER3);
-}
-
-/**
- * Determine if new GPS message is ready to process. This function is a one shot and
- * typically returns true once a second for each GPS position fix.
- *
- * @return true if new message available; otherwise false
- */
-bool_t gpsIsReady()
-{
- return true;
- if (gpsPosition.updateFlag)
- {
- gpsPosition.updateFlag = false;
- return true;
- } // END if
-
- return false;
-}
-
-/**
- * Calculate NMEA-0183 message checksum of buffer that is length bytes long.
- *
- * @param buffer pointer to data buffer.
- * @param length number of bytes in buffer.
- *
- * @return checksum of buffer
- */
-uint8_t gpsNMEAChecksum (uint8_t *buffer, uint8_t length)
-{
- uint8_t i, checksum;
-
- checksum = 0;
-
- for (i = 0; i < length; ++i)
- checksum ^= buffer[i];
-
- return checksum;
-}
-
-/**
- * Verify the GPS engine is sending the @@Hb position report message. If not,
- * configure the GPS engine to send the desired report.
- *
- * @return true if GPS engine operation; otherwise false
- */
-bool_t gpsSetup()
-{
- uint8_t startTime, retryCount;
-
- // We wait 10 seconds for the GPS engine to respond to our message request.
- startTime = timeGetTicks();
- retryCount = 0;
-
- while (++retryCount < 10)
- {
- // Read the serial FIFO and process the GPS messages.
-// gpsUpdate();
-
- // If a GPS data set is available, then GPS is operational.
- if (gpsIsReady())
- {
-// timeSetDutyCycle (TIME_DUTYCYCLE_10);
- return true;
- }
-
- if (timeGetTicks() > startTime)
- {
- puts ("@@Hb\001\053\015\012");
- startTime += 10;
- } // END if
-
- } // END while
-
- return false;
-}
-
-/**
- * Parse the Motorola @@Hb (Short position/message) report.
- */
-void gpsParsePositionMessage()
-{
- // Convert the binary stream into data elements. We will scale to the desired units
- // as the values are used.
- gpsPosition.updateFlag = true;
-
- gpsPosition.month = gpsBuffer[0];
- gpsPosition.day = gpsBuffer[1];
- gpsPosition.year = ((uint16_t) gpsBuffer[2] << 8) | gpsBuffer[3];
- gpsPosition.hours = gpsBuffer[4];
- gpsPosition.minutes = gpsBuffer[5];
- gpsPosition.seconds = gpsBuffer[6];
- gpsPosition.latitude = ((int32) gpsBuffer[11] << 24) | ((int32) gpsBuffer[12] << 16) | ((int32) gpsBuffer[13] << 8) | (int32) gpsBuffer[14];
- gpsPosition.longitude = ((int32) gpsBuffer[15] << 24) | ((int32) gpsBuffer[16] << 16) | ((int32) gpsBuffer[17] << 8) | gpsBuffer[18];
- gpsPosition.altitudeCM = ((int32) gpsBuffer[19] << 24) | ((int32) gpsBuffer[20] << 16) | ((int32) gpsBuffer[21] << 8) | gpsBuffer[22];
- gpsPosition.altitudeFeet = gpsPosition.altitudeCM * 100l / 3048l;
- gpsPosition.vSpeed = ((uint16_t) gpsBuffer[27] << 8) | gpsBuffer[28];
- gpsPosition.hSpeed = ((uint16_t) gpsBuffer[29] << 8) | gpsBuffer[30];
- gpsPosition.heading = ((uint16_t) gpsBuffer[31] << 8) | gpsBuffer[32];
- gpsPosition.dop = ((uint16_t) gpsBuffer[33] << 8) | gpsBuffer[34];
- gpsPosition.visibleSats = gpsBuffer[35];
- gpsPosition.trackedSats = gpsBuffer[36];
- gpsPosition.status = ((uint16_t) gpsBuffer[37] << 8) | gpsBuffer[38];
-
- // Update the peak altitude if we have a valid 3D fix.
- if (gpsGetFixType() == GPS_3D_FIX)
- if (gpsPosition.altitudeFeet > gpsPeakAltitude)
- gpsPeakAltitude = gpsPosition.altitudeFeet;
-}
-
-/**
- * Turn on the GPS engine power and serial interface.
- */
-void gpsPowerOn()
-{
- // 3.0 VDC LDO control line.
-// output_high (IO_GPS_PWR);
-
-}
-
-/**
- * Turn off the GPS engine power and serial interface.
- */
-void gpsPowerOff()
-{
- // 3.0 VDC LDO control line.
-// output_low (IO_GPS_PWR);
-}
-
-/** @} */
-
-
/**
* @defgroup sys System Library Functions
*
/// Counter used to deciminate down from the 104uS to 833uS interrupt rate. (9600 to 1200 baud)
uint8_t timeLowRateCount;
-/// Current TNC mode (standby, 1200bps A-FSK, or 9600bps FSK)
-TNC_DATA_MODE tncDataMode;
-
/// Flag set true once per second.
bool_t timeUpdateFlag;
timeNCO = 0x00;
timeLowRateCount = 0;
timeNCOFreq = 0x2000;
- tncDataMode = TNC_MODE_STANDBY;
timeRunFlag = false;
}
{
// Setup the next interrupt for the operational mode.
timeCompare += TIME_RATE;
-// CCP_1 = timeCompare;
-
- switch (tncDataMode)
- {
- case TNC_MODE_STANDBY:
- break;
-
- case TNC_MODE_1200_AFSK:
- ddsSetFTW (freqTable[timeNCO >> 8]);
- timeNCO += timeNCOFreq;
+ ddsSetFTW (freqTable[timeNCO >> 8]);
- if (++timeLowRateCount == 8)
- {
- timeLowRateCount = 0;
- tnc1200TimerTick();
- } // END if
- break;
+ timeNCO += timeNCOFreq;
- case TNC_MODE_9600_FSK:
- tnc9600TimerTick();
- break;
- } // END switch
+ if (++timeLowRateCount == 8)
+ {
+ timeLowRateCount = 0;
+ tnc1200TimerTick();
+ } // END if
}
/** @} */
tncHighRateFlag = state;
}
-/**
- * Configure the TNC for the desired data mode.
- *
- * @param dataMode enumerated type that specifies 1200bps A-FSK or 9600bps FSK
- */
-void tncSetMode(TNC_DATA_MODE dataMode)
-{
- switch (dataMode)
- {
- case TNC_MODE_1200_AFSK:
- ddsSetMode (DDS_MODE_AFSK);
- break;
-
- case TNC_MODE_9600_FSK:
- ddsSetMode (DDS_MODE_FSK);
-
- // FSK tones at 445.947 and 445.953 MHz
- ddsSetFSKFreq (955382980, 955453621);
- break;
- } // END switch
-
- tncDataMode = dataMode;
-}
-
/**
* Determine if the seconds value timeSeconds is a valid time slot to transmit
* a message. Time seconds is in UTC.
case TNC_TX_SYNC:
// The variable tncShift contains the lastest data byte.
// NRZI enocde the data stream.
- if ((tncShift & 0x01) == 0x00)
+ if ((tncShift & 0x01) == 0x00) {
if (tncTxBit == 0)
tncTxBit = 1;
else
tncTxBit = 0;
+ }
// When the flag is done, determine if we need to send more or data.
if (++tncBitCount == 8)
// The variable tncShift contains the lastest data byte.
// NRZI enocde the data stream.
- if ((tncShift & 0x01) == 0x00)
+ if ((tncShift & 0x01) == 0x00) {
if (tncTxBit == 0)
tncTxBit = 1;
else
tncTxBit = 0;
+ }
// Save the data stream so we can determine if bit stuffing is
// required on the next bit time.
// The variable tncShift contains the lastest data byte.
// NRZI enocde the data stream.
- if ((tncShift & 0x01) == 0x00)
+ if ((tncShift & 0x01) == 0x00) {
if (tncTxBit == 0)
tncTxBit = 1;
else
tncTxBit = 0;
+ }
// Save the data stream so we can determine if bit stuffing is
// required on the next bit time.
case TNC_TX_END:
// The variable tncShift contains the lastest data byte.
// NRZI enocde the data stream.
- if ((tncShift & 0x01) == 0x00)
+ if ((tncShift & 0x01) == 0x00) {
if (tncTxBit == 0)
tncTxBit = 1;
else
tncTxBit = 0;
+ }
// If all the bits were shifted, get the next one.
if (++tncBitCount == 8)
{
tncMode = TNC_TX_READY;
- // Tell the TNC time interrupt to stop generating the frequency words.
- tncDataMode = TNC_MODE_STANDBY;
-
- // Key off the DDS.
-// output_low (IO_OSK);
-// output_low (IO_PTT);
- ddsSetMode (DDS_MODE_POWERDOWN);
-
return;
} // END if
} else
}
/**
- * Write character to the TNC buffer. Maintain the pointer
- * and length to the buffer. The pointer tncBufferPnt and tncLength
- * must be set before calling this function for the first time.
- *
- * @param character to save to telemetry buffer
+ * Generate the plain text position packet. Data is written through the tncTxByte
+ * callback function
*/
-void tncTxByte (uint8_t character)
+void tncPositionPacket(void)
{
- *tncBufferPnt++ = character;
- ++tncLength;
-}
-
-static void
-tncPrintf(char *fmt, ...)
-{
- va_list ap;
+ int32_t latitude = 45.4694766 * 10000000;
+ int32_t longitude = -122.7376250 * 10000000;
+ uint32_t altitude = 10000;
+ uint16_t lat_deg;
+ uint16_t lon_deg;
+ uint16_t lat_min;
+ uint16_t lat_frac;
+ uint16_t lon_min;
+ uint16_t lon_frac;
int c;
- va_start(ap, fmt);
- c = vsprintf(tncBufferPnt, fmt, ap);
- va_end(ap);
- tncBufferPnt += c;
- tncLength += c;
-}
-
-/**
- * Generate the GPS NMEA standard UTC time stamp. Data is written through the tncTxByte
- * callback function.
- */
-void tncNMEATime()
-{
- // UTC of position fix.
- tncPrintf ("%02d%02d%02d,", gpsPosition.hours, gpsPosition.minutes, gpsPosition.seconds);
-}
-
-/**
- * Generate the GPS NMEA standard latitude/longitude fix. Data is written through the tncTxByte
- * callback function.
- */
-void tncNMEAFix()
-{
- uint8_t dirChar;
- uint32_t coord, coordMin;
+ char lat_sign = 'N', lon_sign = 'E';
- // Latitude value.
- coord = gpsPosition.latitude;
-
- if (gpsPosition.latitude < 0)
- {
- coord = gpsPosition.latitude * -1;
- dirChar = 'S';
- } else {
- coord = gpsPosition.latitude;
- dirChar = 'N';
+ if (latitude < 0) {
+ lat_sign = 'S';
+ latitude = -latitude;
}
- coordMin = (coord % 3600000) / 6;
- tncPrintf ("%02ld%02ld.%04ld,%c,", (uint32_t) (coord / 3600000), (uint32_t) (coordMin / 10000), (uint32_t) (coordMin % 10000), dirChar);
-
-
- // Longitude value.
- if (gpsPosition.longitude < 0)
- {
- coord = gpsPosition.longitude * - 1;
- dirChar = 'W';
- } else {
- coord = gpsPosition.longitude;
- dirChar = 'E';
+ if (longitude < 0) {
+ lon_sign = 'W';
+ longitude = -longitude;
}
- coordMin = (coord % 3600000) / 6;
- tncPrintf ("%03ld%02ld.%04ld,%c,", (uint32_t) (coord / 3600000), (uint32_t) (coordMin / 10000), (uint32_t) (coordMin % 10000), dirChar);
-
-}
-
-/**
- * Generate the GPS NMEA-0183 $GPGGA packet. Data is written through the tncTxByte
- * callback function.
- */
-void tncGPGGAPacket()
-{
- // Generate the GPGGA message.
- tncPrintf ("$GPGGA,");
-
- // Standard NMEA time.
- tncNMEATime();
-
- // Standard NMEA-0183 latitude/longitude.
- tncNMEAFix();
-
- // GPS status where 0: not available, 1: available
- if (gpsGetFixType() != GPS_NO_FIX)
- tncPrintf ("1,");
- else
- tncPrintf ("0,");
-
- // Number of visible birds.
- tncPrintf ("%02d,", gpsPosition.trackedSats);
-
- // DOP
- tncPrintf ("%ld.%01ld,", gpsPosition.dop / 10, gpsPosition.dop % 10);
-
- // Altitude in meters.
- tncPrintf ("%ld.%02ld,M,,M,,", (int32_t) (gpsPosition.altitudeCM / 100l), (int32_t) (gpsPosition.altitudeCM % 100));
-
- // Checksum, we add 1 to skip over the $ character.
- tncPrintf ("*%02X", gpsNMEAChecksum(tncBuffer + 1, tncLength - 1));
-}
-
-/**
- * Generate the GPS NMEA-0183 $GPRMC packet. Data is written through the tncTxByte
- * callback function.
- */
-void tncGPRMCPacket()
-{
- uint32_t temp;
-
- // Generate the GPRMC message.
- tncPrintf ("$GPRMC,");
-
- // Standard NMEA time.
- tncNMEATime();
-
- // GPS status.
- if (gpsGetFixType() != GPS_NO_FIX)
- tncPrintf ("A,");
- else
- tncPrintf ("V,");
-
- // Standard NMEA-0183 latitude/longitude.
- tncNMEAFix();
-
- // Speed knots and heading.
- temp = (int32_t) gpsPosition.hSpeed * 75000 / 385826;
- tncPrintf ("%ld.%ld,%ld.%ld,", (int16_t) (temp / 10), (int16_t) (temp % 10), gpsPosition.heading / 10, gpsPosition.heading % 10);
-
- // Date
- tncPrintf ("%02d%02d%02ld,,", gpsPosition.day, gpsPosition.month, gpsPosition.year % 100);
-
- // Checksum, skip over the $ character.
- tncPrintf ("*%02X", gpsNMEAChecksum(tncBuffer + 1, tncLength - 1));
+ lat_deg = latitude / 10000000;
+ latitude -= lat_deg * 10000000;
+ latitude *= 60;
+ lat_min = latitude / 10000000;
+ latitude -= lat_min * 10000000;
+ lat_frac = (latitude + 50000) / 100000;
+
+ lon_deg = longitude / 10000000;
+ longitude -= lon_deg * 10000000;
+ longitude *= 60;
+ lon_min = longitude / 10000000;
+ longitude -= lon_min * 10000000;
+ lon_frac = (longitude + 50000) / 100000;
+
+ c = sprintf ((char *) tncBufferPnt, "=%02u%02u.%02u%c\\%03u%02u.%02u%cO /A=%06u\015",
+ lat_deg, lat_min, lat_frac, lat_sign,
+ lon_deg, lon_min, lon_frac, lon_sign,
+ altitude * 100 / 3048);
+ tncBufferPnt += c;
+ tncLength += c;
}
-/**
- * Generate the plain text status packet. Data is written through the tncTxByte
- * callback function.
- */
-void tncStatusPacket(int16_t temperature)
-{
- uint16_t voltage;
-
- // Plain text telemetry.
- tncPrintf (">ANSR ");
-
- // Display the flight time.
- tncPrintf ("%02U:%02U:%02U ", timeHours, timeMinutes, timeSeconds);
-
- // Altitude in feet.
- tncPrintf ("%ld' ", gpsPosition.altitudeFeet);
-
- // Peak altitude in feet.
- tncPrintf ("%ld'pk ", gpsGetPeakAltitude());
-
- // GPS hdop or pdop
- tncPrintf ("%lu.%lu", gpsPosition.dop / 10, gpsPosition.dop % 10);
-
- // The text 'pdop' for a 3D fix, 'hdop' for a 2D fix, and 'dop' for no fix.
- switch (gpsGetFixType())
- {
- case GPS_NO_FIX:
- tncPrintf ("dop ");
- break;
-
- case GPS_2D_FIX:
- tncPrintf ("hdop ");
- break;
-
-
- case GPS_3D_FIX:
- tncPrintf ("pdop ");
- break;
- } // END switch
-
- // Number of satellites in the solution.
- tncPrintf ("%utrk ", gpsPosition.trackedSats);
-
- // Display main bus voltage.
-// voltage = adcGetMainBusVolt();
-// tncPrintf ("%lu.%02luvdc ", voltage / 100, voltage % 100);
-
- // Display internal temperature.
-// tncPrintf ("%ld.%01ldF ", temperature / 10, abs(temperature % 10));
-
- // Print web address link.
- tncPrintf ("www.altusmetrum.org");
-}
-
/**
* Prepare an AX.25 data packet. Each time this method is called, it automatically
* rotates through 1 of 3 messages.
*
* @param dataMode enumerated type that specifies 1200bps A-FSK or 9600bps FSK
*/
-void tncTxPacket(TNC_DATA_MODE dataMode)
+void tncTxPacket(void)
{
- int16_t temperature;
uint16_t crc;
- // Only transmit if there is not another message in progress.
- if (tncMode != TNC_TX_READY)
- return;
-
- // Configure the DDS for the desired operational.
- tncSetMode (dataMode);
-
// Set a pointer to our TNC output buffer.
tncBufferPnt = tncBuffer;
// Set the message length counter.
tncLength = 0;
- // Determine the contents of the packet.
- switch (tncPacketType)
- {
- case TNC_BOOT_MESSAGE:
- tncPrintf (">MegaMetrum v1.0 Beacon");
-
- // Select the next packet we will generate.
- tncPacketType = TNC_STATUS;
- break;
-
- case TNC_STATUS:
- tncStatusPacket(temperature);
-
- // Select the next packet we will generate.
- tncPacketType = TNC_GGA;
- break;
-
- case TNC_GGA:
- tncGPGGAPacket();
-
- // Select the next packet we will generate.
- tncPacketType = TNC_RMC;
- break;
-
- case TNC_RMC:
- tncGPRMCPacket();
-
- // Select the next packet we will generate.
- tncPacketType = TNC_STATUS;
- break;
- }
-
- // Add the end of message character.
- tncPrintf ("\015");
+ tncPositionPacket();
// Calculate the CRC for the header and message.
crc = sysCRC16(TNC_AX25_HEADER, sizeof(TNC_AX25_HEADER), 0xffff);
}
/** @} */
-
-#if 0
-uint32_t counter;
-
-uint8_t bitIndex;
-uint8_t streamIndex;
-uint8_t value;
-
-uint8_t bitStream[] = { 0x10, 0x20, 0x30 };
-
-void init()
-{
- counter = 0;
- bitIndex = 0;
- streamIndex = 0;
- value = bitStream[0];
-}
-
-void test()
-{
- counter += 0x10622d;
-
-// CCP_1 = (uint16_t) ((counter >> 16) & 0xffff);
-
- if ((value & 0x80) == 0x80)
- setup_ccp1 (CCP_COMPARE_SET_ON_MATCH);
- else
- setup_ccp1 (CCP_COMPARE_CLR_ON_MATCH);
-
- if (++bitIndex == 8)
- {
- bitIndex = 0;
-
- if (++streamIndex == sizeof(bitStream))
- {
- streamIndex = 0;
- }
-
- value = bitStream[streamIndex];
- } else
- value = value << 1;
-}
-#endif
-
-// This is where we go after reset.
-int main(int argc, char **argv)
-{
- uint8_t i, utcSeconds, lockLostCounter;
-
-//test();
-
- // Configure the basic systems.
-// sysInit();
-
- // Wait for the power converter chains to stabilize.
-// delay_ms (100);
-
- // Setup the subsystems.
-// adcInit();
-// flashInit();
- gpsInit();
-// logInit();
-// timeInit();
-// serialInit();
- tncInit();
-
- // Program the DDS.
-// ddsInit();
-
- // Transmit software version packet on start up.
- tncTxPacket(TNC_MODE_1200_AFSK);
-
- exit(0);
- // Counters to send packets if the GPS time stamp is not available.
- lockLostCounter = 5;
- utcSeconds = 55;
-
- // This is the main loop that process GPS data and waits for the once per second timer tick.
- for (;;)
- {
- // Read the GPS engine serial port FIFO and process the GPS data.
-// gpsUpdate();
-
- if (gpsIsReady())
- {
- // Start the flight timer when we get a valid 3D fix.
- if (gpsGetFixType() == GPS_3D_FIX)
- timeSetRunFlag();
-
- // Generate our packets based on the GPS time.
- if (tncIsTimeSlot(gpsPosition.seconds))
- tncTxPacket(TNC_MODE_1200_AFSK);
-
- // Sync the internal clock to GPS UTC time.
- utcSeconds = gpsPosition.seconds;
-
- // This counter is reset every time we receive the GPS message.
- lockLostCounter = 0;
-
- // Log the data to flash.
-// sysLogGPSData();
- } // END if gpsIsReady
-
- // Processing that occurs once a second.
- if (timeIsUpdate())
- {
- // We maintain the UTC time in seconds if we shut off the GPS engine or it fails.
- if (++utcSeconds == 60)
- utcSeconds = 0;
-
- // If we loose information for more than 5 seconds,
- // we will determine when to send a packet based on internal time.
- if (lockLostCounter == 5)
- {
- if (tncIsTimeSlot(utcSeconds))
- tncTxPacket(TNC_MODE_1200_AFSK);
- } else
- ++lockLostCounter;
-
- // Update the ADC filters.
-// adcUpdate();
-
- if (timeHours == 5 && timeMinutes == 0 && timeSeconds == 0)
- gpsPowerOff();
-
- } // END if timeIsUpdate
-
- } // END for
-}
-
-
-