diff --git a/tracker/software/Makefile b/tracker/software/Makefile index 87210da3..a619803c 100644 --- a/tracker/software/Makefile +++ b/tracker/software/Makefile @@ -116,9 +116,9 @@ LDSCRIPT= board/STM32F413xH.ld CSRC = $(ALLCSRC) \ $(TESTSRC) \ $(CHIBIOS)/os/various/fatfs_bindings/fatfs_diskio.c \ + threads/rxtx/beacon.c \ threads/collector.c \ threads/rxtx/position.c \ - threads/rxtx/beacon.c \ threads/rxtx/image.c \ threads/rxtx/log.c \ threads/rxtx/radio.c \ diff --git a/tracker/software/config.c b/tracker/software/config.c index 1916cef6..44b2f5cd 100644 --- a/tracker/software/config.c +++ b/tracker/software/config.c @@ -126,7 +126,7 @@ const conf_t conf_flash_default = { }, .rx = { // The receive identity for APRS .radio_conf = { - .freq = 145175000, + .freq = FREQ_APRS_DYNAMIC, .mod = MOD_AFSK, .rssi = 0x3F }, @@ -144,7 +144,7 @@ const conf_t conf_flash_default = { .call = "VK2GJ-5", .path = "WIDE2-1", .symbol = SYM_DIGIPEATER, - .fixed = true, + .beacon = true, .lat = -337331175, .lon = 1511143478, .alt = 144, @@ -153,12 +153,14 @@ const conf_t conf_flash_default = { .tel_enc_cycle = TIME_S2I(60*180) }, .base = { - // The base station identity - how and where tracker originated messages are sent - .enabled = true, + // The base station identity + // Tracker originated messages can be sent to this call sign sent + .enabled = false, .call = "VK2GJ-7", .path = "WIDE2-1", }, .dig_active = true, + .freq = 145175000 // Default APRS frequency }, // Power control diff --git a/tracker/software/math/geofence.c b/tracker/software/math/geofence.c index 5077a807..c3a8f794 100644 --- a/tracker/software/math/geofence.c +++ b/tracker/software/math/geofence.c @@ -6,6 +6,7 @@ #include "hal.h" #include "geofence.h" #include "collector.h" +#include "config.h" static const coord_t america[] = { // Latitude Longitude (in deg*10000000) @@ -657,7 +658,7 @@ uint32_t getAPRSRegionFrequency(void) { // Position unknown if(point == NULL || (point->gps_lat == 0 && point->gps_lon == 0)) - return 144800000; + return conf_sram.aprs.freq; // America 144.390 MHz if(isPointInAmerica(point->gps_lat, point->gps_lon)) diff --git a/tracker/software/pkt/devices/si446x.c b/tracker/software/pkt/devices/si446x.c index 5ac39eca..75571584 100644 --- a/tracker/software/pkt/devices/si446x.c +++ b/tracker/software/pkt/devices/si446x.c @@ -13,6 +13,8 @@ #include "radio.h" #endif +#include "geofence.h" + // Si446x variables static int16_t lastTemp = 0x7FFF; @@ -259,6 +261,11 @@ bool Si446x_setBandParameters(radio_unit_t radio, radio_freq_t freq, channel_hz_t step) { + if(freq == FREQ_APRS_DYNAMIC) { + freq = getAPRSRegionFrequency(); // Get transmission frequency by geofencing + /* If using geofence ignore channel and step for now. */ + step = 0; + } /* Check band is in range. */ if(freq < 144000000UL || freq > 900000000UL) return false; @@ -696,6 +703,7 @@ bool Si4464_resumeReceive(radio_unit_t radio, rx_step, rx_chan); + TRACE_INFO( "SI > Enable reception %d.%03d MHz (ch %d)," " RSSI %d, %s", op_freq/1000000, (op_freq % 1000000)/1000, diff --git a/tracker/software/pkt/managers/pktradio.c b/tracker/software/pkt/managers/pktradio.c index aaed390d..14ed5f69 100644 --- a/tracker/software/pkt/managers/pktradio.c +++ b/tracker/software/pkt/managers/pktradio.c @@ -20,6 +20,7 @@ #endif #include "si446x.h" #include "debug.h" +#include "geofence.h" /** * @brief Process radio task requests. @@ -506,6 +507,14 @@ void pktReleaseRadio(radio_unit_t radio) { radio_freq_t pktComputeOperatingFrequency(radio_freq_t base_freq, channel_hz_t step, radio_ch_t chan) { + + if(base_freq == FREQ_APRS_DYNAMIC) { + base_freq = getAPRSRegionFrequency(); // Get transmission frequency by geofencing + // If using geofence ignore channel and step. + chan = 0; + step = 0; + } + return base_freq + (step * chan); } diff --git a/tracker/software/sven_config.c b/tracker/software/sven_config.c new file mode 100644 index 00000000..02d9090b --- /dev/null +++ b/tracker/software/sven_config.c @@ -0,0 +1,173 @@ +/** + * Put your configuration settings here. See description of all fields in types.h + */ + +#include "config.h" +#include "aprs.h" + +conf_t conf_sram; + +const conf_t conf_flash_default = { + // Primary position node + .pos_pri = { + .thread_conf = { + .active = true, + .cycle = TIME_S2I(60*1), + .init_delay = TIME_S2I(5) + }, + .radio_conf = { + .pwr = 0x7F, + .freq = FREQ_APRS_RECEIVE, + .mod = MOD_AFSK, + .rssi = 0x4F, + }, + // Node identity + .call = "DL7AD-11", + .path = "WIDE1-1", + .symbol = SYM_SMALLAIRCRAFT, + .aprs_msg = true, + + .tel_enc_cycle = TIME_S2I(10800) + }, + + // Secondary position node + .pos_sec = { + .thread_conf = { + .active = false, + .cycle = TIME_S2I(120), + .init_delay = TIME_S2I(60) + }, + .radio_conf = { + .pwr = 0x7F, + .freq = FREQ_APRS_DYNAMIC, + .mod = MOD_AFSK, + .rssi = 0x4F + }, + // Node identity + .call = "DL7AD-14", + .path = "WIDE1-1", + .symbol = SYM_BALLOON, + .aprs_msg = true, + + .tel_enc_cycle = TIME_S2I(10800) + }, + + // Primary image node + .img_pri = { + .thread_conf = { + .active = true, + .cycle = TIME_S2I(0), + .init_delay = TIME_S2I(60*3), + .send_spacing = TIME_S2I(15) + }, + .radio_conf = { + .pwr = 0x7F, + .freq = 144800000, + .mod = MOD_AFSK, + .rssi = 0x4F, + .redundantTx = false + }, + // Node identity + .call = "DL7AD-11", + .path = "", + + .res = RES_QVGA, + .quality = 4, + .buf_size = 40*1024 + }, + + // Secondary image node + .img_sec = { + .thread_conf = { + .active = false, + .cycle = TIME_S2I(60*5), + .init_delay = TIME_S2I(60*1), + .send_spacing = TIME_S2I(30) + }, + .radio_conf = { + .pwr = 0x7F, + .freq = 145175000, + .mod = MOD_AFSK, + .rssi = 0x4F + }, + // Node identity + .call = "VK2GJ-14", + .path = "", + + .res = RES_QVGA, + .quality = 4, + .buf_size = 15*1024 + }, + + // Log node + .log = { + .thread_conf = { + .active = false, + .cycle = TIME_S2I(10), + .init_delay = TIME_S2I(5) + }, + .radio_conf = { + .pwr = 0x7F, + .freq = FREQ_APRS_DYNAMIC, + .mod = MOD_AFSK, + .rssi = 0x4F + }, + // Node identity + .call = "VK2GJ-13", + .path = "WIDE1-1", + .density = 10 + }, + + // APRS node + .aprs = { + .thread_conf = { + .active = true, + .init_delay = TIME_S2I(20), + }, + .rx = { // The receive identity for APRS + .radio_conf = { + .freq = 144800000, + .mod = MOD_AFSK, + .rssi = 0x3F + }, + // Node rx identity + .call = "DL7AD-11" + }, + .tx = { // The transmit identity for digipeat transmit and messages responses + .radio_conf = { + .freq = FREQ_APRS_RECEIVE, + .pwr = 0x7F, + .mod = MOD_AFSK, + .rssi = 0x4F + }, + // Node tx identity + .call = "DL7AD-11", + .path = "WIDE2-1", + .symbol = SYM_DIGIPEATER, + .beacon = false, + .lat = -337331175, + .lon = 1511143478, + .alt = 144, + .interval = TIME_S2I(60*5), + + .tel_enc_cycle = TIME_S2I(60*180) + }, + .base = { + // The base station identity + // Tracker originated messages can be sent to this call sign sent + .enabled = false, + .call = "VK2GJ-7", + .path = "WIDE2-1", + }, + .dig_active = false, + .freq = 144800000 // Default APRS frequency + }, + + // Power control + .keep_cam_switched_on = false, + .gps_on_vbat = 1000, + .gps_off_vbat = 1000, + .gps_onper_vbat = 1000, + + .magic = CONFIG_MAGIC_DEFAULT // Do not remove. This is the activation bit. +}; diff --git a/tracker/software/threads/collector.c b/tracker/software/threads/collector.c index ddbad420..99718e02 100644 --- a/tracker/software/threads/collector.c +++ b/tracker/software/threads/collector.c @@ -312,7 +312,7 @@ THD_FUNCTION(collectorThread, arg) { data_cycle_time = conf_sram.pos_pri.thread_conf.cycle; } else if(conf_sram.pos_sec.thread_conf.active) { // Only secondary position thread is active data_cycle_time = conf_sram.pos_sec.thread_conf.cycle; - } else if(conf_sram.aprs.thread_conf.active && conf_sram.aprs.tx.fixed) { // APRS fixed location is active + } else if(conf_sram.aprs.thread_conf.active && conf_sram.aprs.tx.beacon) { // APRS beacon is active data_cycle_time = conf_sram.pos_sec.thread_conf.cycle; } else { // There must be an error TRACE_ERROR("COLL > Data collector started but no position thread is active"); diff --git a/tracker/software/threads/rxtx/beacon.h b/tracker/software/threads/rxtx/beacon.h index 6b76190e..c5a05477 100644 --- a/tracker/software/threads/rxtx/beacon.h +++ b/tracker/software/threads/rxtx/beacon.h @@ -1,8 +1,14 @@ -#ifndef __POS_H__ -#define __POS_H__ +#ifndef __BEACON_H__ +#define __BEACON_H__ #include "types.h" -void start_beacon_thread(const thd_aprs_conf_t *conf); +#ifdef __cplusplus +extern "C" { +#endif + void start_beacon_thread(const thd_aprs_conf_t *conf); +#ifdef __cplusplus +} +#endif -#endif /* __POS_H__ */ +#endif /* __BEACON_H__ */ diff --git a/tracker/software/threads/rxtx/position.c b/tracker/software/threads/rxtx/position.c index 535f53a1..746cdf84 100644 --- a/tracker/software/threads/rxtx/position.c +++ b/tracker/software/threads/rxtx/position.c @@ -65,38 +65,36 @@ THD_FUNCTION(posThread, arg) /* * Encode/Transmit APRSD packet. * This is a tracker originated message (not a reply to a request). - * The message will be sent to the base station set in path. + * The message will be sent to the base station set in path if set. + * Else send it to device identity. */ - if(conf_sram.aprs.base.enabled) { - /* - * Send message from this device. - * Use call sign and path as specified in base config. - * There is no acknowledgment requested. - */ - packet = aprs_compose_aprsd_message( - conf->call, - conf->path, - conf_sram.aprs.base.call); - if(packet == NULL) { - TRACE_WARN("POS > No free packet objects " - "or badly formed APRSD message"); - } else { - if(!transmitOnRadio(packet, - conf_sram.aprs.base.radio_conf.freq, - 0, - 0, - conf_sram.aprs.base.radio_conf.pwr, - conf_sram.aprs.base.radio_conf.mod, - conf_sram.aprs.base.radio_conf.rssi - )) { - TRACE_ERROR("POS > Failed to transmit APRSD data"); - } - chThdSleep(TIME_S2I(5)); + char *call = conf_sram.aprs.base.enabled + ? conf_sram.aprs.base.call : APRS_DEVICE_CALLSIGN; + /* + * Send message from this device. + * Use call sign and path as specified in base config. + * There is no acknowledgment requested. + */ + packet = aprs_compose_aprsd_message( + conf->call, + conf->path, + call); + if(packet == NULL) { + TRACE_WARN("POS > No free packet objects " + "or badly formed APRSD message"); + } else { + if(!transmitOnRadio(packet, + conf_sram.aprs.base.radio_conf.freq, + 0, + 0, + conf_sram.aprs.base.radio_conf.pwr, + conf_sram.aprs.base.radio_conf.mod, + conf_sram.aprs.base.radio_conf.rssi + )) { + TRACE_ERROR("POS > Failed to transmit APRSD data"); } - } else { - /* TODO: Implement a fallback destination if no base station set? */ - TRACE_INFO("POS > APRSD data not sent - no base station specified"); - } + chThdSleep(TIME_S2I(5)); + } // Telemetry encoding parameter transmission if(conf->tel_enc_cycle != 0 && last_conf_transmission diff --git a/tracker/software/threads/rxtx/radio.c b/tracker/software/threads/rxtx/radio.c index 403dfddd..44987d82 100644 --- a/tracker/software/threads/rxtx/radio.c +++ b/tracker/software/threads/rxtx/radio.c @@ -82,12 +82,12 @@ void start_aprs_threads(radio_unit_t radio, radio_freq_t base_freq, channel_hz_t step, radio_ch_t chan, radio_squelch_t rssi) { - if(base_freq == FREQ_APRS_DYNAMIC) { +/* if(base_freq == FREQ_APRS_DYNAMIC) { base_freq = getAPRSRegionFrequency(); // Get transmission frequency by geofencing - /* If using geofence ignore channel and step for now. */ + // If using geofence ignore channel and step. chan = 0; step = 0; - } + }*/ if(base_freq == FREQ_APRS_RECEIVE) { TRACE_ERROR("RX > Cannot specify FREQ_APRS_RECEIVE for receiver"); diff --git a/tracker/software/threads/threads.c b/tracker/software/threads/threads.c index 3ef3b974..bcc9e4d8 100644 --- a/tracker/software/threads/threads.c +++ b/tracker/software/threads/threads.c @@ -49,7 +49,7 @@ void start_user_threads(void) if(conf_sram.log.thread_conf.active) start_logging_thread(&conf_sram.log); - if(conf_sram.aprs.thread_conf.active && conf_sram.aprs.tx.fixed) + if(conf_sram.aprs.thread_conf.active && conf_sram.aprs.tx.beacon) start_beacon_thread(&conf_sram.aprs); if(conf_sram.aprs.thread_conf.active) { diff --git a/tracker/software/threads/threads.h b/tracker/software/threads/threads.h index 50ecf1ed..a526c3f0 100644 --- a/tracker/software/threads/threads.h +++ b/tracker/software/threads/threads.h @@ -1,5 +1,5 @@ -#ifndef __MODULES_H__ -#define __MODULES_H__ +#ifndef __THREADS_H__ +#define __THREADS_H__ #include "ch.h" @@ -8,5 +8,4 @@ void start_user_threads(void); extern sysinterval_t watchdog_tracking; // Last update time for module TRACKING -#endif - +#endif /* __THREADS_H__ */ diff --git a/tracker/software/types.h b/tracker/software/types.h index 4b9e063c..432489f7 100644 --- a/tracker/software/types.h +++ b/tracker/software/types.h @@ -128,7 +128,7 @@ typedef struct { uint16_t symbol; uint8_t rssi; // Squelch for CCA check bool enabled; - bool fixed; + bool beacon; int32_t lat; int32_t lon; int32_t alt; @@ -143,6 +143,7 @@ typedef struct { thd_tx_conf_t tx; thd_tx_conf_t base; // Base station receiving unsolicited sends bool dig_active; // Digipeater active flag + uint32_t freq; // Default APRS frequency if no GPS } thd_aprs_conf_t;