From 04f76c73010c17ad775cc03acd05378d1fe56b80 Mon Sep 17 00:00:00 2001 From: sh123 Date: Wed, 17 Jun 2020 13:32:00 +0300 Subject: [PATCH] Minor refactoring --- README.md | 2 +- ax25_callsign.cpp | 23 +++++++++++------------ ax25_callsign.h | 4 +++- ax25_payload.cpp | 2 +- ax25_payload.h | 2 +- loraprs_service.cpp | 11 +++++++---- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ec8bf44..b474334 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Can be used in two modes: - **LoRa APRS iGate RX/TX server over WiFi + Digipeater** - **RF to APRS-IS gating**, it will connect to your WiFI and will forward received APRS positions from RF LoRa into the APRS-IS network, it also reports client signal level, by appending it into the APRS comment, so you can see your signal reports in different locations (could be enabled or disabled from config). This way, it is also possible to setup portable iGate by connecting to your mobile phone's hotspot and provide power from the phone USB port by using OTA cable - **APRS-IS to RF gating**, it is possible to enable it together with the filter in the config, so APRS-IS data will be forwarded to RF - - **RF digirepating** for `WIDEn-n`, `TRACEn-n` new style paths, for `TRACE` will insert own callsign before digipeating + - **RF digirepating** for `WIDEn-n` new style paths - **Beaconing**, own station periodic beacon announcement to APRS-IS and RF # Compatible Boards diff --git a/ax25_callsign.cpp b/ax25_callsign.cpp index 9b7bf17..a12afb3 100644 --- a/ax25_callsign.cpp +++ b/ax25_callsign.cpp @@ -56,11 +56,8 @@ String Callsign::ToString() const bool Callsign::Digirepeat() { - // only WIDE and TRACE supported - if (call_.startsWith("WIDE*") || call_.startsWith("TRACE*")) return false; - if ((call_.startsWith("WIDE") || call_.startsWith("TRACE")) && call_.length() >= 5) { - char wideLevel = call_.charAt(4); - if ((wideLevel == '1' || wideLevel == '2' || wideLevel == '3') && ssid_ > 0) { + if (IsPath()) { + if (ssid_ > 0) { if (--ssid_ == 0) { call_ += "*"; } @@ -92,8 +89,10 @@ bool Callsign::encode(byte *txPtr, int bufferLength) const return true; } -bool Callsign::fromString(String callsign) -{ +bool Callsign::fromString(const String &inputCallsign) +{ + String callsign = inputCallsign; + // "ABCDEF-XX" if (callsign.length() > CallsignSize + 2 || callsign.length() == 0) return false; @@ -120,22 +119,22 @@ bool Callsign::fromString(String callsign) bool Callsign::fromBinary(const byte *rxPtr, int length) { if (length < CallsignSize) return false; - + byte callsign[CallsignSize]; - + const byte *ptr = rxPtr; memset(callsign, 0, sizeof(callsign)); - + for (int i = 0; i < CallsignSize - 1; i++) { char c = *(ptr++) >> 1; callsign[i] = (c == ' ') ? '\0' : c; } callsign[CallsignSize-1] = '\0'; - + ssid_ = (*ptr >> 1) & 0x0f; call_ = String((char*)callsign); - + if (call_.length() == 0) return false; return true; diff --git a/ax25_callsign.h b/ax25_callsign.h index 09cdab3..1f87dfd 100644 --- a/ax25_callsign.h +++ b/ax25_callsign.h @@ -17,6 +17,8 @@ public: inline bool IsValid() const { return isValid_; }; inline bool IsTrace() const { return call_.startsWith("TRACE"); } + inline bool IsWide() const { return call_.startsWith("WIDE"); } + inline bool IsPath() const { return IsWide(); } String ToString() const; bool ToBinary(byte *txPayload, int bufferLength) const; @@ -26,7 +28,7 @@ public: private: bool encode(byte *txPtr, int bufferLength) const; - bool fromString(String callsign); + bool fromString(const String &callsign); bool fromBinary(const byte *rxPtr, int payloadLength); private: diff --git a/ax25_payload.cpp b/ax25_payload.cpp index aaf6dfd..6504d9e 100644 --- a/ax25_payload.cpp +++ b/ax25_payload.cpp @@ -83,7 +83,7 @@ String Payload::ToString(String customComment) txt += customComment; } - return txt + String("\n"); + return txt; } bool Payload::Digirepeat(const Callsign &ownCallsign) diff --git a/ax25_payload.h b/ax25_payload.h index 6b548b6..4824229 100644 --- a/ax25_payload.h +++ b/ax25_payload.h @@ -15,7 +15,7 @@ public: inline bool IsValid() const { return isValid_; } - String ToString(String customComment); + String ToString(String customComment=String()); int ToBinary(byte *txPayload, int bufferLength) const; bool Digirepeat(const Callsign &ownCallsign); diff --git a/loraprs_service.cpp b/loraprs_service.cpp index 2395b60..881e2c1 100644 --- a/loraprs_service.cpp +++ b/loraprs_service.cpp @@ -167,9 +167,9 @@ void Service::sendBeacon() if (payload.IsValid()) { sendToLora(payload); if (enableRfToIs_) { - sendToAprsis(payload.ToString(String())); + sendToAprsis(payload.ToString()); } - Serial.println("Sent beacon"); + Serial.println("Periodic beacon is sent"); } else { Serial.println("Beacon payload is invalid"); @@ -177,6 +177,7 @@ void Service::sendBeacon() previousBeaconMs_ = currentMs; } } + void Service::sendToAprsis(String aprsMessage) { if (needsWifi() && WiFi.status() != WL_CONNECTED) { @@ -185,7 +186,7 @@ void Service::sendToAprsis(String aprsMessage) if (needsAprsis() && !aprsisConn_.connected()) { reconnectAprsis(); } - aprsisConn_.print(aprsMessage); + aprsisConn_.println(aprsMessage); if (!persistentConn_) { aprsisConn_.stop(); @@ -281,13 +282,15 @@ void Service::onLoraDataAvailable(int packetSize) if (payload.IsValid()) { String textPayload = payload.ToString(addSignalReport_ ? signalReport : String()); - Serial.print(textPayload); + Serial.println(textPayload); if (enableRfToIs_ && !isClient_) { sendToAprsis(textPayload); + Serial.println("Packet sent to APRS-IS"); } if (enableRepeater_ && payload.Digirepeat(ownCallsign_)) { sendToLora(payload); + Serial.println("Packet digirepeated"); } } else {