From a1c8f2761c1bfae4aa087ba279934ffea56793f0 Mon Sep 17 00:00:00 2001 From: sh123 Date: Tue, 26 Oct 2021 12:01:14 +0300 Subject: [PATCH] Add configuration flag to allow text aprs messaging --- ax25_payload.cpp | 27 ++++++++++++++++++++++++++- ax25_payload.h | 4 +++- config.h | 1 + esp32_loraprs.ino | 4 ++++ loraprs_config.h | 1 + loraprs_service.cpp | 25 +++++++++++++++++++++---- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/ax25_payload.cpp b/ax25_payload.cpp index b18d42d..f38ced4 100644 --- a/ax25_payload.cpp +++ b/ax25_payload.cpp @@ -14,6 +14,31 @@ Payload::Payload(const String &textPayload) isValid_ = fromString(textPayload); } +Payload::Payload(const Payload &payload) + : isValid_(payload.isValid_) + , srcCall_(payload.srcCall_) + , dstCall_(payload.dstCall_) + , rptCallsCount_(payload.rptCallsCount_) + , info_(payload.info_) +{ + for (int i = 0; i < rptCallsCount_; i++) { + rptCalls_[i] = payload.rptCalls_[i]; + } +} + +Payload& Payload::operator=(const Payload &payload) +{ + isValid_ = payload.isValid_; + srcCall_ = payload.srcCall_; + dstCall_ = payload.dstCall_; + rptCallsCount_ = payload.rptCallsCount_; + info_ = payload.info_; + for (int i = 0; i < rptCallsCount_; i++) { + rptCalls_[i] = payload.rptCalls_[i]; + } + return *this; +} + void Payload::Dump() { LOG_INFO("valid: ", isValid_); @@ -65,7 +90,7 @@ int Payload::ToBinary(byte *txPayload, int bufferLength) const return (int)(txPtr-txPayload); } -String Payload::ToString(const String &customComment) +String Payload::ToString(const String &customComment) const { String txt = srcCall_.ToString() + String(">") + dstCall_.ToString(); diff --git a/ax25_payload.h b/ax25_payload.h index 80659bf..d4369df 100644 --- a/ax25_payload.h +++ b/ax25_payload.h @@ -13,10 +13,12 @@ class Payload public: Payload(const String &textPayload); Payload(const byte *rxPayload, int payloadLength); + Payload(const Payload &payload); + Payload& operator=(const Payload &payload); inline bool IsValid() const { return isValid_; } - String ToString(const String &customComment=String()); + String ToString(const String &customComment=String()) const; int ToBinary(byte *txPayload, int bufferLength) const; bool Digirepeat(const Callsign &ownCallsign); diff --git a/config.h b/config.h index 0b8724f..9fd5c48 100644 --- a/config.h +++ b/config.h @@ -65,6 +65,7 @@ #define CFG_RF_TO_IS true // forward packets from radio to internet #define CFG_IS_TO_RF false // forward packets from internet to radio basedon CFG_APRS_FILTER #define CFG_BEACON false // enable perdiodc beacon from CFG_APRS_RAW_BKN +#define CFG_TEXT_PACKETS false // enable aprs text packets instead of binary for interoperability with other projects (disables ax.25) // frequency correction for narrow band bandwidths #define CFG_FREQ_CORR false // true - correct own frequency based on received packet diff --git a/esp32_loraprs.ino b/esp32_loraprs.ino index 77275cf..b1a027e 100644 --- a/esp32_loraprs.ino +++ b/esp32_loraprs.ino @@ -70,8 +70,12 @@ void initializeConfig(LoraPrs::Config &cfg) { cfg.EnableIsToRf = CFG_IS_TO_RF; // send data from aprsis to rf cfg.EnableRepeater = CFG_DIGIREPEAT; // digirepeat incoming packets cfg.EnableBeacon = CFG_BEACON; // enable periodic AprsRawBeacon beacon to rf and aprsis if rf to aprsis is enabled + cfg.EnableTextPackets = CFG_TEXT_PACKETS; // enables text packets and disables AX25 binary frames for interoperability + + // kiss cfg.KissEnableExtensions = CFG_KISS_EXTENSIONS; // radio control and signal reports cfg.KissEnableTcpIp = CFG_KISS_TCP_IP; // enable KISS ovr TCP/IP as a server + // external ptt control cfg.PttEnable = CFG_PTT_ENABLE; diff --git a/loraprs_config.h b/loraprs_config.h index ffe79d5..2c15d72 100644 --- a/loraprs_config.h +++ b/loraprs_config.h @@ -62,6 +62,7 @@ struct Config bool EnableIsToRf; // true - enable APRS-IS to RF submission bool EnableRepeater; // true - digirepeat incoming packets based on WIDEn-n paths bool EnableBeacon; // true - send AprsRawBeacon to RF and APRS-IS if EnableRfToIs is true + bool EnableTextPackets; // true - use text plain messages insead of AX25 binary frames for interoperability with other projects // external ptt tx control bool PttEnable; // true - enable external ptt control diff --git a/loraprs_service.cpp b/loraprs_service.cpp index b81ca98..e3c5217 100644 --- a/loraprs_service.cpp +++ b/loraprs_service.cpp @@ -411,11 +411,22 @@ void Service::sendSignalReportEvent(int rssi, float snr) bool Service::sendAX25ToLora(const AX25::Payload &payload) { + int bytesWritten; byte buf[CfgMaxAX25PayloadSize]; - int bytesWritten = payload.ToBinary(buf, sizeof(buf)); - if (bytesWritten <= 0) { - LOG_WARN("Failed to serialize payload"); - return false; + if (config_.EnableTextPackets) { + String textPayload = payload.ToString(); + bytesWritten = textPayload.length(); + if (bytesWritten > CfgMaxAX25PayloadSize) { + bytesWritten = CfgMaxAX25PayloadSize; + } + textPayload.getBytes(buf, bytesWritten); + buf[bytesWritten-1] = '\0'; + } else { + bytesWritten = payload.ToBinary(buf, sizeof(buf)); + if (bytesWritten <= 0) { + LOG_WARN("Failed to serialize payload"); + return false; + } } queueSerialToRig(Cmd::Data, buf, bytesWritten); return true; @@ -475,8 +486,14 @@ void Service::loraReceive(int packetSize) void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLength) { + // create from binary AX25 AX25::Payload payload(packet, packetLength); + // try to parse as text for clients, who submit plain text + if (!payload.IsValid() && config_.EnableTextPackets && packet[packetLength - 1] == '\0') { + payload = AX25::Payload(String((char*)packet)); + } + if (payload.IsValid()) { #ifdef USE_RADIOLIB