From 079cb4980d528eaf257a8d1b977b7bd083bd1dae Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Wed, 11 Sep 2019 20:53:58 +0200 Subject: [PATCH] first test: tnc tcp/ip server for APRSdroid --- RX_FSK/RX_FSK.ino | 54 ++++++++++++++++++++++++++++++------- RX_FSK/data/config.txt | 3 +++ RX_FSK/version.h | 2 +- libraries/SondeLib/Sonde.h | 1 + libraries/SondeLib/aprs.cpp | 23 ++++++++++++++++ libraries/SondeLib/aprs.h | 8 ++++++ 6 files changed, 80 insertions(+), 11 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 62c327f..93f4535 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -45,6 +45,10 @@ boolean connected = false; WiFiUDP udp; WiFiClient client; +// KISS over TCP für communicating with APRSdroid +WiFiServer tncserver(14580); +WiFiClient tncclient; + enum KeyPress { KP_NONE = 0, KP_SHORT, KP_DOUBLE, KP_MID, KP_LONG }; @@ -397,6 +401,9 @@ struct st_configitems config_list[] = { {"call", "Call", 8, sonde.config.call}, {"passcode", "Passcode", 8, sonde.config.passcode}, {"---", "---", -1, NULL}, + /* KISS tnc settings */ + {"kisstnc", "KISS TNC (port 14590) (needs reboot)", 0, &sonde.config.kisstnc.active}, + {"kisstnc.idformat", "DFM ID Format", -2, &sonde.config.kisstnc.idformat}, /* AXUDP settings */ {"axudp.active", "AXUDP active", -3, &sonde.config.udpfeed.active}, {"axudp.host", "AXUDP Host", 63, sonde.config.udpfeed.host}, @@ -631,7 +638,7 @@ const char *handleEditPost(AsyncWebServerRequest *request) { } file.print(content); file.close(); - if (strcmp(filename.c_str(), "screens.txt")==0) { + if (strcmp(filename.c_str(), "screens.txt") == 0) { // screens update => reload disp.initFromFile(); } @@ -1201,6 +1208,9 @@ void setup() sonde.setup(); initGPS(); + if (sonde.config.kisstnc.active) { + tncserver.begin(); + } WiFi.onEvent(WiFiEvent); getKeyPress(); // clear key buffer } @@ -1275,21 +1285,44 @@ void loopDecoder() { Serial.printf("current main is %d, current rxtask is %d\n", sonde.currentSonde, rxtask.currentSonde); } - - if ((res & 0xff) == 0 && connected) { + if (!tncclient.connected()) { + Serial.println("TNC client not connected"); + tncclient = tncserver.available(); + if(tncclient.connected()) { + Serial.println("new TCP KISS connection"); + } + } + if (tncclient.available()) { + Serial.print("TCP KISS socket: recevied "); + while (tncclient.available()) { + Serial.print(tncclient.read()); // Check if we receive anything from Bluetooth + } + Serial.println(""); + } + // wifi (axudp) or bluetooth (bttnc) active => send packet + if ((res & 0xff) == 0 && (connected || tncclient.connected() )) { //Send a packet with position information // first check if ID and position lat+lonis ok SondeInfo *s = &sonde.sondeList[rxtask.receiveSonde]; if (s->validID && ((s->validPos & 0x03) == 0x03)) { - Serial.println("Sending position via UDP"); - char raw[201]; const char *str = aprs_senddata(s->lat, s->lon, s->alt, s->hs, s->dir, s->vs, sondeTypeStr[s->type], s->id, "TE0ST", sonde.config.udpfeed.symbol); - int rawlen = aprsstr_mon2raw(str, raw, APRS_MAXLEN); - Serial.print("Sending: "); Serial.println(raw); - udp.beginPacket(sonde.config.udpfeed.host, sonde.config.udpfeed.port); - udp.write((const uint8_t *)raw, rawlen); - udp.endPacket(); + if (connected) { + char raw[201]; + int rawlen = aprsstr_mon2raw(str, raw, APRS_MAXLEN); + Serial.println("Sending position via UDP"); + Serial.print("Sending: "); Serial.println(raw); + udp.beginPacket(sonde.config.udpfeed.host, sonde.config.udpfeed.port); + udp.write((const uint8_t *)raw, rawlen); + udp.endPacket(); + } + if(tncclient.connected()) { + Serial.println("Sending position via TCP"); + char raw[201]; + int rawlen = aprsstr_mon2kiss(str, raw, APRS_MAXLEN); + Serial.print("sending: "); Serial.println(raw); + tncclient.write(raw, rawlen); + } } } sonde.updateDisplay(); @@ -1375,6 +1408,7 @@ void enableNetwork(bool enable) { SetupAsyncServer(); udp.begin(WiFi.localIP(), LOCALUDPPORT); MDNS.addService("http", "tcp", 80); + tncserver.begin(); connected = true; } else { MDNS.end(); diff --git a/RX_FSK/data/config.txt b/RX_FSK/data/config.txt index bbd1e4a..2ac9a4f 100644 --- a/RX_FSK/data/config.txt +++ b/RX_FSK/data/config.txt @@ -25,6 +25,9 @@ maxsonde=20 debug=0 # wifi mode: 1=client in background; 2=AP in background; 3=client on startup, ap if failure wifi=3 +# TCP/IP KISS TNC in port 14590 for APRSdroid (0=disabled, 1=enabled) +kisstnc.active = 1 + # display mode: 1=standard 2=fieldmode 3=field w/sondetype display=1 #-------------------------------# diff --git a/RX_FSK/version.h b/RX_FSK/version.h index aa1de6b..a9dd625 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,2 +1,2 @@ const char *version_name = "RDZ_TTGO_SONDE"; -const char *version_id = "devel20190609"; +const char *version_id = "devel20190911"; diff --git a/libraries/SondeLib/Sonde.h b/libraries/SondeLib/Sonde.h index aa5f056..36c11cd 100644 --- a/libraries/SondeLib/Sonde.h +++ b/libraries/SondeLib/Sonde.h @@ -112,6 +112,7 @@ typedef struct st_rdzconfig { // for now, one feed for each type is enough, but might get extended to more? struct st_feedinfo udpfeed; // target for AXUDP messages struct st_feedinfo tcpfeed; // target for APRS-IS TCP connections + struct st_kisstnc kisstnc; // target for KISS TNC (via TCP, mainly for APRSdroid) } RDZConfig; typedef struct st_sondeinfo { diff --git a/libraries/SondeLib/aprs.cpp b/libraries/SondeLib/aprs.cpp index 447a437..bfa73fc 100644 --- a/libraries/SondeLib/aprs.cpp +++ b/libraries/SondeLib/aprs.cpp @@ -137,6 +137,7 @@ static int mkaprscall(int32_t * p, char raw[], } /* end call() */ + // returns raw len, 0 in case of error extern int aprsstr_mon2raw(const char *mon, char raw[], int raw_len) { @@ -207,6 +208,28 @@ extern int aprsstr_mon2raw(const char *mon, char raw[], int raw_len) return p+2; } /* end mon2raw() */ +extern int aprsstr_mon2kiss(const char *mon, char raw[], int raw_len) +{ + char tmp[201]; + int len = aprsstr_mon2raw(mon, tmp, 201); + if(len==0) return 0; + int idx=0; + raw[idx++] = '\xC0'; + for(int i=0; i=raw_len) + return 0; + } + return idx; +} #define FEET (1.0/0.3048) #define KNOTS (1.851984) diff --git a/libraries/SondeLib/aprs.h b/libraries/SondeLib/aprs.h index 2c14db7..5f993fd 100644 --- a/libraries/SondeLib/aprs.h +++ b/libraries/SondeLib/aprs.h @@ -16,10 +16,18 @@ struct st_feedinfo { int idformat; // 0: dxl 1: real 2: auto }; +// maybe extend for external Bluetooth interface? +// internal bluetooth consumes too much memory +struct st_kisstnc { + bool active; + int idformat; +}; + #define APRS_MAXLEN 201 void aprs_gencrctab(void); int aprsstr_mon2raw(const char *mon, char raw[], int raw_len); +int aprsstr_mon2kiss(const char *mon, char raw[], int raw_len); char * aprs_senddata(float lat, float lon, float alt, float speed, float dir, float climb, const char *type, const char *objname, const char *usercall, const char *sym);