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;
-
- // Latitude value.
- coord = gpsPosition.latitude;
-
- if (gpsPosition.latitude < 0)
- {
- coord = gpsPosition.latitude * -1;
- dirChar = 'S';
- } else {
- coord = gpsPosition.latitude;
- dirChar = 'N';
- }
-
- 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';
- }
-
- 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));
-}
-
/**
* Generate the plain text position packet. Data is written through the tncTxByte
* callback function
tncPrintf (" /A=%06u", altitude * 100 / 3048);
}
-
-
-/**
- * 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.
*/
void tncTxPacket(TNC_DATA_MODE dataMode)
{
- int16_t temperature = 20;
uint16_t crc;
// Only transmit if there is not another message in progress.
// 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:
- tncPositionPacket();
-// 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;
- }
+ tncPositionPacket();
// Add the end of message character.
tncPrintf ("\015");
// This is where we go after reset.
int main(int argc, char **argv)
{
- uint8_t utcSeconds, lockLostCounter, i;
gpsInit();
tncInit();
audio_gap(1);
- // Transmit software version packet on start up.
+
+ /* Transmit one packet */
tncTxPacket(TNC_MODE_1200_AFSK);
- // 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 (i = 0; i < 3; i++)
- {
- audio_gap(10);
- // 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
- return 0;
+ exit(0);
}