Browse Source

NETWORK_TNC test

pull/16/head
Łukasz Nidecki 10 months ago
parent
commit
316d8cb711
  1. 5
      include/taskTNC.h
  2. 10
      include/taskWebServer.h
  3. 1
      src/TTGO_T-Beam_LoRa_APRS_config.h
  4. 44
      src/taskTNC.cpp
  5. 9
      src/taskWebServer.cpp

5
include/taskTNC.h

@ -6,8 +6,11 @@
#include "BluetoothSerial.h"
extern BluetoothSerial SerialBT;
#endif
#if defined(ENABLE_WIFI)
#include "taskWebServer.h"
#endif
extern QueueHandle_t tncToSendQueue;
extern QueueHandle_t tncReceivedQueue;
void taskTNC(void *parameter);
[[noreturn]] void taskTNC(void *parameter);

10
include/taskWebServer.h

@ -5,9 +5,16 @@
#include <ESPmDNS.h>
#include <Preferences.h>
#ifndef TASK_WEBSERVER
#define TASK_WEBSERVER
#define ENABLE_PREFERENCES
extern Preferences preferences;
#ifdef KISS_PROTOCOL
extern WiFiServer tncServer;
#endif
// MAX 15 chars for preferenece key!!!
static const char *const PREF_APRS_CALLSIGN = "aprs_callsign";
static const char *const PREF_APRS_RELAY_PATH = "aprs_relay_path";
@ -33,4 +40,5 @@ typedef struct {
String callsign;
} tWebServerCfg;
[[noreturn]] void taskWebServer(void *parameter);
[[noreturn]] void taskWebServer(void *parameter);
#endif

1
src/TTGO_T-Beam_LoRa_APRS_config.h

@ -29,6 +29,7 @@
#define T_BEAM_V1_0 // if enabled t-beam v1.0 disabled t-beam V.0.7
//#define KISS_DEBUG
#define ENABLE_WIFI
#define NETWORK_TNC_PORT 8001
#define MAX_TIME_TO_NEXT_TX 360000L // TRANSMIT INTERVAL set here MAXIMUM time in ms(!) for smart beaconing - minimum time is always 1 min = 60 secs = 60000L !!!
#define FIX_BEACON_INTERVAL 1800000L // Fixed beacon interwal (when GPS is disabled and FIXED_BEACON_EN is enabled) 30min default

44
src/taskTNC.cpp

@ -6,6 +6,7 @@
String inTNCData = "";
QueueHandle_t tncToSendQueue = nullptr;
QueueHandle_t tncReceivedQueue = nullptr;
WiFiClient client;
/**
* Handle incoming TNC KISS data character
@ -23,6 +24,12 @@ void handleKISSData(char character) {
SerialBT.print(inTNCData);
}
#endif
#ifdef ENABLE_WIFI
if (client.connected()){
client.print(inTNCData);
client.flush();
}
#endif
#endif
auto *buffer = new String();
buffer->concat(TNC2DataFrame);
@ -34,31 +41,50 @@ void handleKISSData(char character) {
}
void taskTNC(void *parameter) {
[[noreturn]] void taskTNC(void *parameter) {
tncToSendQueue = xQueueCreate(4,sizeof(String *));
tncReceivedQueue = xQueueCreate(4,sizeof(String *));
String *loraReceivedFrameString = nullptr;
client = tncServer.available();
while (true) {
while (Serial.available() > 0) {
char character = Serial.read();
handleKISSData(character);
}
#ifdef ENABLE_BLUETOOTH
if (SerialBT.hasClient()) {
while (SerialBT.available() > 0) {
char character = SerialBT.read();
handleKISSData(character);
if (SerialBT.hasClient()) {
while (SerialBT.available() > 0) {
char character = SerialBT.read();
handleKISSData(character);
}
}
#endif
#ifdef ENABLE_WIFI
if (!client.connected()){
client = tncServer.available();
}
if (client.connected()){
while (client.available() > 0) {
char character = client.read();
handleKISSData(character);
}
}
}
#endif
if (xQueueReceive(tncReceivedQueue, &loraReceivedFrameString, (1 / portTICK_PERIOD_MS)) == pdPASS) {
Serial.print(encode_kiss(*loraReceivedFrameString));
const String &kissEncoded = encode_kiss(*loraReceivedFrameString);
Serial.print(kissEncoded);
#ifdef ENABLE_BLUETOOTH
if (SerialBT.hasClient()){
SerialBT.print(encode_kiss(*loraReceivedFrameString));
SerialBT.print(kissEncoded);
}
#endif
#ifdef ENABLE_WIFI
if (client.connected()){
client.print(kissEncoded);
client.flush();
}
#endif
delete loraReceivedFrameString;
}
vTaskDelay(50 / portTICK_PERIOD_MS);

9
src/taskWebServer.cpp

@ -14,6 +14,9 @@ String apSSID = "";
String apPassword = "xxxxxxxxxx";
WebServer server(80);
Preferences preferences;
#ifdef KISS_PROTOCOL
WiFiServer tncServer(NETWORK_TNC_PORT);
#endif
void sendCacheHeader() { server.sendHeader("Cache-Control", "max-age=3600"); }
void sendGzipHeader() { server.sendHeader("Content-Encoding", "gzip"); }
@ -181,8 +184,14 @@ void handle_SaveAPRSCfg() {
}
server.begin();
#ifdef KISS_PROTOCOL
tncServer.begin();
#endif
if (MDNS.begin(webServerCfg->callsign.c_str())) {
MDNS.addService("http", "tcp", 80);
#ifdef KISS_PROTOCOL
MDNS.addService("kiss-tnc", "tcp", NETWORK_TNC_PORT);
#endif
}
while (true){

Loading…
Cancel
Save