From b48c96fa0845ae3dfb1115de04f40e39ddfc8c16 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Tue, 3 Oct 2023 13:31:07 +0300 Subject: [PATCH] Ham: a chance to change APRS 'From'-callsign setting by means of appropriate JSON file --- .../source/SoftRF/src/platform/ESP32.cpp | 41 +++++++++++++++++++ .../source/SoftRF/src/protocol/data/JSON.cpp | 10 +++-- .../source/SoftRF/src/protocol/radio/APRS.cpp | 10 ++++- .../source/SoftRF/src/protocol/radio/APRS.h | 2 + .../SoftRF/src/protocol/radio/RemoteID.cpp | 1 - .../SoftRF/src/protocol/radio/RemoteID.h | 1 - 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/software/firmware/source/SoftRF/src/platform/ESP32.cpp b/software/firmware/source/SoftRF/src/platform/ESP32.cpp index 128185d62..10950d07e 100644 --- a/software/firmware/source/SoftRF/src/platform/ESP32.cpp +++ b/software/firmware/source/SoftRF/src/platform/ESP32.cpp @@ -215,6 +215,12 @@ RTC_Date fw_build_date_time = RTC_Date(__DATE__, __TIME__); // file system object from SdFat FatVolume fatfs; +#include "../protocol/data/JSON.h" + +#define ESP32_JSON_BUFFER_SIZE 1024 + +StaticJsonBuffer ESP32_jsonBuffer; + ui_settings_t ui_settings = { .units = UNITS_METRIC, .zoom = ZOOM_MEDIUM, @@ -2501,6 +2507,41 @@ static bool ESP32_EEPROM_begin(size_t size) static void ESP32_EEPROM_extension(int cmd) { if (cmd == EEPROM_EXT_LOAD) { +#if defined(CONFIG_IDF_TARGET_ESP32S3) + if ( ESP32_has_spiflash && FATFS_is_mounted ) { + File32 file = fatfs.open("/settings.json", FILE_READ); + + if (file) { + // StaticJsonBuffer RP2040_jsonBuffer; + + JsonObject &root = ESP32_jsonBuffer.parseObject(file); + + if (root.success()) { + JsonVariant msg_class = root["class"]; + + if (msg_class.success()) { + const char *msg_class_s = msg_class.as(); + + if (!strcmp(msg_class_s,"SOFTRF")) { + parseSettings (root); + +#if defined(USE_SA8X8) + JsonVariant fromcall = root["fromcall"]; + if (fromcall.success()) { + const char * fromcall_s = fromcall.as(); + if (strlen(fromcall_s) <= 6) { + strncpy(APRS_FromCall, fromcall_s, sizeof(APRS_FromCall)); + } + } +#endif /* USE_SA8X8 */ + } + } + } + file.close(); + } + } +#endif /* CONFIG_IDF_TARGET_ESP32S3 */ + #if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32C3) || \ defined(USE_USB_HOST) if (settings->nmea_out == NMEA_USB) { diff --git a/software/firmware/source/SoftRF/src/protocol/data/JSON.cpp b/software/firmware/source/SoftRF/src/protocol/data/JSON.cpp index 85853e535..668c4de20 100644 --- a/software/firmware/source/SoftRF/src/protocol/data/JSON.cpp +++ b/software/firmware/source/SoftRF/src/protocol/data/JSON.cpp @@ -16,7 +16,8 @@ * along with this program. If not, see . */ -#if defined(RASPBERRY_PI) || defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_RP2040) +#if defined(RASPBERRY_PI) || defined(ARDUINO_ARCH_NRF52) || \ + defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_ESP32) #include "../../system/SoC.h" #include @@ -37,7 +38,7 @@ extern eeprom_t eeprom_block; extern settings_t *settings; -#endif /* RASPBERRY_PI || ARDUINO_ARCH_NRF52 || ARDUINO_ARCH_RP2040 */ +#endif /* RASPBERRY_PI || ARDUINO_ARCH_NRF52 || ..._RP2040 || ..._ESP32 */ #if defined(RASPBERRY_PI) @@ -668,7 +669,8 @@ void parseUISettings(JsonObject& root) } #endif /* RASPBERRY_PI || ARDUINO_ARCH_NRF52 */ -#if defined(RASPBERRY_PI) || defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_RP2040) +#if defined(RASPBERRY_PI) || defined(ARDUINO_ARCH_NRF52) || \ + defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_ESP32) void parseSettings(JsonObject& root) { @@ -901,4 +903,4 @@ void parseSettings(JsonObject& root) #endif } -#endif /* RASPBERRY_PI || ARDUINO_ARCH_NRF52 || ARDUINO_ARCH_RP2040 */ +#endif /* RASPBERRY_PI || ARDUINO_ARCH_NRF52 || ..._RP2040 || ..._ESP32 */ diff --git a/software/firmware/source/SoftRF/src/protocol/radio/APRS.cpp b/software/firmware/source/SoftRF/src/protocol/radio/APRS.cpp index 72eca052c..ab36b0e17 100644 --- a/software/firmware/source/SoftRF/src/protocol/radio/APRS.cpp +++ b/software/firmware/source/SoftRF/src/protocol/radio/APRS.cpp @@ -116,6 +116,8 @@ extern AX25Msg Incoming_APRS_Packet; struct pbuf_t aprs; ParseAPRS aprsParse; +char APRS_FromCall[7] = ""; + int packet2Raw(String &tnc2, AX25Msg &Packet) { if (Packet.len < 5) return 0; @@ -232,9 +234,12 @@ bool ax25_decode(void *pkt, ufo_t *this_aircraft, ufo_t *fop) { size_t aprs_encode(void *pkt, ufo_t *this_aircraft) { char buf[APRS_PAYLOAD_SIZE]; + char id_s[7]; uint32_t id = this_aircraft->addr & 0x00FFFFFF; const char *ToCall = "OGFLR"; // TODO: make use of assigned APSRFx value + snprintf(id_s, sizeof(id_s), "%06X", id); + #if !defined(SOFTRF_ADDRESS) uint8_t addr_type = ADDR_TYPE_ANONYMOUS; #else @@ -260,7 +265,7 @@ size_t aprs_encode(void *pkt, ufo_t *this_aircraft) { float lon_dec = lon - lon_int; snprintf(buf, sizeof(buf), - "%06X>%s:" + "%s>%s:" "/" "%02d%02d%02dh" "%02d%05.2f%c" @@ -268,7 +273,8 @@ size_t aprs_encode(void *pkt, ufo_t *this_aircraft) { "%03d%05.2f%c" "'" "%03d/%03d/A=%06d !W00! id%08X +000fpm +0.0rot" /* " 7.8dB -1.6kHz gps8x3" */, - id, ToCall, + strlen(APRS_FromCall) == 0 ? id_s : APRS_FromCall, + ToCall, gnss.time.hour(), gnss.time.minute(), gnss.time.second(), abs(lat_int), fabsf(lat_dec * 60), lat < 0 ? 'S' : 'N', abs(lon_int), fabsf(lon_dec * 60), lon < 0 ? 'W' : 'E', diff --git a/software/firmware/source/SoftRF/src/protocol/radio/APRS.h b/software/firmware/source/SoftRF/src/protocol/radio/APRS.h index 2d8d78897..c82a73e92 100644 --- a/software/firmware/source/SoftRF/src/protocol/radio/APRS.h +++ b/software/firmware/source/SoftRF/src/protocol/radio/APRS.h @@ -61,4 +61,6 @@ size_t aprs_encode(void *, ufo_t *); extern const rf_proto_desc_t prol_proto_desc; +extern char APRS_FromCall[7]; + #endif /* PROTOCOL_APRS_H */ diff --git a/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp index 82a4cda01..7971f08a2 100644 --- a/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp +++ b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp @@ -27,7 +27,6 @@ #include ID_OpenDrone squitter; -UTM_Utilities utm_utils; struct UTM_parameters utm_parameters; struct UTM_data utm_data; diff --git a/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h index 6d8dff35f..bca5fe741 100644 --- a/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h +++ b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h @@ -37,7 +37,6 @@ size_t rid_encode(void *, ufo_t *); #include extern ID_OpenDrone squitter; -extern UTM_Utilities utm_utils; extern struct UTM_parameters utm_parameters; extern struct UTM_data utm_data;