From 28c044f95f9f473945ecc3d81229314142cb1e5c Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Thu, 25 Jun 2015 19:49:47 +0100 Subject: [PATCH] Added altitude to aprs geofence. APRS always enabled below 200m --- firmware/inc/location.h | 2 +- firmware/src/location.c | 12 +++++++++--- firmware/src/main.c | 2 +- firmware/test/tc/location_aprs.h | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/firmware/inc/location.h b/firmware/inc/location.h index 9522c62..487589c 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); +void aprs_location_update(float lon, float lat, uint32_t altitude); #endif /* LOCATION_H */ diff --git a/firmware/src/location.c b/firmware/src/location.c index 71a4a16..36f514d 100644 --- a/firmware/src/location.c +++ b/firmware/src/location.c @@ -30,6 +30,7 @@ #include "geofence_aprs.h" int32_t current_aprs_zone = -2, current_aprs_zone_outline = -2; +uint32_t _altitude = 0; #define polyX(i) (poly[(i*2)+0]) #define polyY(i) (poly[(i*2)+1]) @@ -97,8 +98,10 @@ bool latlon_in_aprs_zone(int32_t aprs_zone, int32_t aprs_zone_outline, float lon */ bool aprs_location_tx_allow(void) { - /* Not in any zone, or in a zone other than Alpha */ - return (current_aprs_zone == -1) || (current_aprs_zone > 0); + /* Not in any zone, or in a zone other than Alpha, or not airbourne */ + return (current_aprs_zone == -1) || + (current_aprs_zone > 0) || + (_altitude < 200); } /** * Returns the aprs frequency in the current zone. @@ -118,10 +121,13 @@ int32_t aprs_location_frequency(void) { /** * Updates the aprs location based on the current lat/lon */ -void aprs_location_update(float lon, float lat) { +void aprs_location_update(float lon, float lat, uint32_t altitude) { 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 3532a45..88ab83b 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -191,7 +191,7 @@ void aprs_telemetry(void) { uint32_t altitude = pos.payload.height / 1000; /* Update location */ - aprs_location_update(lon, lat); + aprs_location_update(lon, lat, altitude); /* aprs okay here? */ if (aprs_location_tx_allow()) { diff --git a/firmware/test/tc/location_aprs.h b/firmware/test/tc/location_aprs.h index 10a10e3..8f3c062 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); + aprs_location_update(location_aprs_tc_params.lon, location_aprs_tc_params.lat, 0); location_aprs_tc_results.tx_allow = aprs_location_tx_allow(); location_aprs_tc_results.frequency = aprs_location_frequency();