From cd464951522d1eff61506104f0c9ddd103c19f30 Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Sun, 12 Jul 2015 00:17:04 +0100 Subject: [PATCH] Fixed a couple of APRS timing/format issues. APRS txes after rtty, on 144.8 when geofence is disabled --- firmware/inc/location.h | 2 +- firmware/src/aprs.c | 22 ++++++--- firmware/src/cron.c | 67 +++++++++++++++------------ firmware/src/location.c | 5 +- firmware/src/main.c | 9 ++-- firmware/test/tc/location_aprs.h | 2 +- firmware/test/tc/location_aprs_file.h | 2 +- 7 files changed, 63 insertions(+), 46 deletions(-) diff --git a/firmware/inc/location.h b/firmware/inc/location.h index 487589c..9522c62 100644 --- a/firmware/inc/location.h +++ b/firmware/inc/location.h @@ -32,6 +32,6 @@ bool latlon_in_aprs_zone(int32_t aprs_zone, int32_t aprs_zone_outline, float lon bool aprs_location_tx_allow(void); int32_t aprs_location_frequency(void); -void aprs_location_update(float lon, float lat, uint32_t altitude); +void aprs_location_update(float lon, float lat); #endif /* LOCATION_H */ diff --git a/firmware/src/aprs.c b/firmware/src/aprs.c index 34047a6..3e5f065 100644 --- a/firmware/src/aprs.c +++ b/firmware/src/aprs.c @@ -112,10 +112,15 @@ void encode_backlog(char* str, tracker_datapoint* dp) char compressed_altitude[3]; char telemetry[TELEMETRY_FIELD_LEN]; + /* Process lat/lon/alt */ + float lat = (float)dp->latitude / 10000000.0; /* degrees */ + float lon = (float)dp->longitude / 10000000.0; /* degrees */ + uint32_t altitude = dp->altitude / 1000; /* meters */ + /* Prepare the aprs position report */ - encode_latitude(compressed_lat, dp->latitude); - encode_longitude(compressed_lon, dp->longitude); - encode_altitude(compressed_altitude, dp->altitude); + encode_latitude(compressed_lat, lat); + encode_longitude(compressed_lon, lon); + encode_altitude(compressed_altitude, altitude); /* Encode telemetry string */ encode_telemetry(telemetry, dp); @@ -168,6 +173,11 @@ uint8_t aprs_start(void) /* Don't run without a valid position */ if (!_dp || (_dp->latitude == 0 && _dp->longitude == 0)) return 0; + /* Process lat/lon/alt */ + float lat = (float)_dp->latitude / 10000000.0; /* degrees */ + float lon = (float)_dp->longitude / 10000000.0; /* degrees */ + uint32_t altitude = _dp->altitude / 1000; /* meters */ + /* Encode the destination / source / path addresses */ uint32_t addresses_len = sprintf(addresses, "%-6s%c%-6s%c%-6s%c", "APRS", 0, @@ -175,9 +185,9 @@ uint8_t aprs_start(void) "WIDE2", 1); /* Prepare the aprs position report */ - encode_latitude(compressed_lat, _dp->latitude); - encode_longitude(compressed_lon, _dp->longitude); - uint32_t altitude_feet = _dp->altitude * 3.2808; /* Oh yeah feet! Everyone loves feet */ + encode_latitude(compressed_lat, lat); + encode_longitude(compressed_lon, lon); + uint32_t altitude_feet = altitude * 3.2808; /* Oh yeah feet! Everyone loves feet */ /* Encode telemetry string */ encode_telemetry(telemetry, _dp); diff --git a/firmware/src/cron.c b/firmware/src/cron.c index a769c3e..f647f28 100644 --- a/firmware/src/cron.c +++ b/firmware/src/cron.c @@ -40,7 +40,7 @@ struct tracker_time time = {0}; struct tracker_datapoint* dp; /* Low Power Mode */ -#define LOW_POWER(d) (d->solar < 0.2) +#define LOW_POWER(d) ((d->solar < 0.2) || (d->solar < 1.1)) void rtty_telemetry(struct tracker_datapoint* dp); void contestia_telemetry(struct tracker_datapoint* dp); @@ -74,6 +74,40 @@ void read_gps_time(void) /* TODO calculate epoch time here */ } +/** + * Pars of cron job that handles telemetry + */ +void cron_telemetry(struct tracker_time* t) +{ + /* ---- Telemetry output ---- */ + /* RTTY */ + if (t->second == 0 && !LOW_POWER(dp)) { + rtty_telemetry(dp); + + /* Contestia */ + } else if (t->second == 30 && !LOW_POWER(dp)) { + contestia_telemetry(dp); + + /* Low Power */ + } else if (t->second == 0 && LOW_POWER(dp)) { + if ((t->minute % 2) == 0) { + rtty_telemetry(dp); + } else { + contestia_telemetry(dp); + } + + /* Pip */ + } else if ((t->second % 1) == 0) { + pips_telemetry(); + } + + /* APRS */ +#ifdef APRS_ENABLE + if ((t->minute % 2) == 0 && t->second == 0) { + aprs_telemetry(dp); + } +#endif +} /** * Cron job for the system. * @@ -93,38 +127,11 @@ void do_cron(void) collect_data_async(); } - /* ---- Telemetry output ---- */ - /* RTTY */ - if (t.second == 0 && !LOW_POWER(dp)) { - rtty_telemetry(dp); - - /* Contestia */ - } else if (t.second == 30 && !LOW_POWER(dp)) { - contestia_telemetry(dp); - - /* Low Power */ - } else if (t.second == 0 && LOW_POWER(dp)) { - if ((t.minute % 2) == 0) { - rtty_telemetry(dp); - } else { - contestia_telemetry(dp); - } - - /* APRS */ -#ifdef APRS_ENABLE - } else if ((t.minute % 2) == 0 && t.second == 0) { - aprs_telemetry(dp); -#endif - - /* Pips */ - } else if ((t.second % 1) == 0) { - pips_telemetry(); - - } + cron_telemetry(&t); /* ---- Record for backlog ---- */ - if ((t.minute % 1 == 0) && (t.second == 0)) { + if ((t.minute == 0) && (t.second == 0)) { /* Once per hour */ kick_the_watchdog(); diff --git a/firmware/src/location.c b/firmware/src/location.c index 160164b..4127367 100644 --- a/firmware/src/location.c +++ b/firmware/src/location.c @@ -119,13 +119,10 @@ int32_t aprs_location_frequency(void) { /** * Updates the aprs location based on the current lat/lon */ -void aprs_location_update(float lon, float lat, uint32_t altitude) { +void aprs_location_update(float lon, float lat) { uint32_t z, outline; - /* Record altitude */ - _altitude = altitude; - /* Were we in an aprs zone last time? */ if (current_aprs_zone >= 0 && current_aprs_zone_outline >= 0) { diff --git a/firmware/src/main.c b/firmware/src/main.c index efc2930..3ce242e 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -166,10 +166,9 @@ void aprs_telemetry(struct tracker_datapoint* dp) { float lat = (float)dp->latitude / 10000000.0; /* degrees */ float lon = (float)dp->longitude / 10000000.0; /* degrees */ - uint32_t altitude = dp->altitude / 1000; /* meters */ /* Update location */ - aprs_location_update(lon, lat, altitude); + aprs_location_update(lon, lat); #if APRS_USE_GEOFENCE /* aprs okay here? */ @@ -180,7 +179,7 @@ void aprs_telemetry(struct tracker_datapoint* dp) { aprs_set_datapoint(dp); /* Set comment */ - if ((dp->time.hour % 2) == 0) { + if ((dp->time.minute % 4) == 0) { aprs_set_comment(APRS_COMMENT); } else { backlog_dp_ptr = get_backlog(); @@ -193,7 +192,11 @@ void aprs_telemetry(struct tracker_datapoint* dp) { } /* Set frequency */ +#if APRS_USE_GEOFENCE telemetry_aprs_set_frequency(aprs_location_frequency()); +#else + telemetry_aprs_set_frequency(144800000); +#endif /* Transmit packet and wait */ telemetry_start(TELEMETRY_APRS, 0xFFFF); diff --git a/firmware/test/tc/location_aprs.h b/firmware/test/tc/location_aprs.h index 2138f9c..10a10e3 100644 --- a/firmware/test/tc/location_aprs.h +++ b/firmware/test/tc/location_aprs.h @@ -21,7 +21,7 @@ struct location_aprs_tc_results { /* Function */ __verification__ void location_aprs_tc(void) { - aprs_location_update(location_aprs_tc_params.lon, location_aprs_tc_params.lat, 1000); + aprs_location_update(location_aprs_tc_params.lon, location_aprs_tc_params.lat); location_aprs_tc_results.tx_allow = aprs_location_tx_allow(); location_aprs_tc_results.frequency = aprs_location_frequency(); diff --git a/firmware/test/tc/location_aprs_file.h b/firmware/test/tc/location_aprs_file.h index 62ddb6d..76a5987 100644 --- a/firmware/test/tc/location_aprs_file.h +++ b/firmware/test/tc/location_aprs_file.h @@ -26,7 +26,7 @@ struct location_aprs_file_tc_results { /* Function */ __verification__ void location_aprs_file_tc(void) { - aprs_location_update(location_aprs_file_tc_params.lon, location_aprs_file_tc_params.lat, 1000); + aprs_location_update(location_aprs_file_tc_params.lon, location_aprs_file_tc_params.lat); location_aprs_file_tc_results.tx_allow = aprs_location_tx_allow(); location_aprs_file_tc_results.frequency = aprs_location_frequency();