Skip to content

Commit

Permalink
Ham: a chance to change APRS 'From'-callsign setting by means of appr…
Browse files Browse the repository at this point in the history
…opriate JSON file
  • Loading branch information
lyusupov committed Oct 3, 2023
1 parent 1c74a1b commit b48c96f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
41 changes: 41 additions & 0 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_JSON_BUFFER_SIZE> ESP32_jsonBuffer;

ui_settings_t ui_settings = {
.units = UNITS_METRIC,
.zoom = ZOOM_MEDIUM,
Expand Down Expand Up @@ -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<ESP32_JSON_BUFFER_SIZE> 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<char*>();

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<char*>();
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) {
Expand Down
10 changes: 6 additions & 4 deletions software/firmware/source/SoftRF/src/protocol/data/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#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 <TinyGPS++.h>
Expand All @@ -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)

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
10 changes: 8 additions & 2 deletions software/firmware/source/SoftRF/src/protocol/radio/APRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -260,15 +265,16 @@ 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"
"/"
"%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',
Expand Down
2 changes: 2 additions & 0 deletions software/firmware/source/SoftRF/src/protocol/radio/APRS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <id_open.h>

ID_OpenDrone squitter;
UTM_Utilities utm_utils;

struct UTM_parameters utm_parameters;
struct UTM_data utm_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ size_t rid_encode(void *, ufo_t *);
#include <id_open.h>

extern ID_OpenDrone squitter;
extern UTM_Utilities utm_utils;
extern struct UTM_parameters utm_parameters;
extern struct UTM_data utm_data;

Expand Down

0 comments on commit b48c96f

Please sign in to comment.