Browse Source

Change in TNC Network clients handling

pull/16/head
Łukasz Nidecki 10 months ago
parent
commit
1e0fe1071e
  1. 4
      src/TTGO_T-Beam_LoRa_APRS.ino
  2. 2
      src/TTGO_T-Beam_LoRa_APRS_config.h
  3. 63
      src/taskTNC.cpp

4
src/TTGO_T-Beam_LoRa_APRS.ino

@ -498,7 +498,7 @@ void setup(){
}
writedisplaytext("LoRa-APRS","","Init:","RF95 OK!","","",250);
writedisplaytext(" "+Tcall,"","Init:","Waiting for GPS","","",250);
xTaskCreate(taskGPS, "taskGPS", 10000, nullptr, 1, nullptr);
xTaskCreate(taskGPS, "taskGPS", 5000, nullptr, 1, nullptr);
writedisplaytext(" "+Tcall,"","Init:","GPS Task Created!","","",250);
#ifndef T_BEAM_V1_0
adc1_config_width(ADC_WIDTH_BIT_12);
@ -523,7 +523,7 @@ void setup(){
#endif
#ifdef ENABLE_WIFI
webServerCfg = {.callsign = Tcall};
xTaskCreate(taskWebServer, "taskWebServer", 50000, (void*)(&webServerCfg), 1, nullptr);
xTaskCreate(taskWebServer, "taskWebServer", 40000, (void*)(&webServerCfg), 1, nullptr);
writedisplaytext("LoRa-APRS","","Init:","WiFi task started"," =:-) ","",250);
#endif

2
src/TTGO_T-Beam_LoRa_APRS_config.h

@ -29,6 +29,8 @@
//#define KISS_DEBUG
#define ENABLE_WIFI
#define NETWORK_TNC_PORT 8001
//#define ENABLE_WIFI_CLIENT_DEBUG
#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

63
src/taskTNC.cpp

@ -1,6 +1,6 @@
#include <list>
#include "taskTNC.h"
#ifdef ENABLE_BLUETOOTH
BluetoothSerial SerialBT;
#endif
@ -8,18 +8,24 @@ String inTNCData = "";
QueueHandle_t tncToSendQueue = nullptr;
QueueHandle_t tncReceivedQueue = nullptr;
#ifdef ENABLE_WIFI
std::list<WiFiClient *> clientsList;
#define MAX_WIFI_CLIENTS 6
WiFiClient * clients[MAX_WIFI_CLIENTS];
typedef void (*f_connectedClientCallback_t) (WiFiClient *, const String *);
void iterateWifiClients(std::list<WiFiClient *> clients, f_connectedClientCallback_t callback, const String *data){
auto clientsIterator = clients.begin();
while (clientsIterator != clients.end()){
if ((*clientsIterator)->connected()){
callback(*clientsIterator, data);
clientsIterator++;
} else {
clientsIterator = clients.erase(clientsIterator);
void iterateWifiClients(f_connectedClientCallback_t callback, const String *data){
for (int i=0; i<MAX_WIFI_CLIENTS; i++) {
auto client = clients[i];
if (client != nullptr) {
if (client->connected()) {
callback(client, data);
} else {
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("Disconnected client ") + client->remoteIP().toString() + ":" + client->remotePort());
#endif
delete client;
clients[i] = nullptr;
}
}
}
}
@ -43,7 +49,7 @@ void handleKISSData(char character) {
}
#endif
#ifdef ENABLE_WIFI
iterateWifiClients(clientsList, [](WiFiClient *client, const String *data){
iterateWifiClients([](WiFiClient *client, const String *data){
if (client->connected()){
client->print(*data);
client->flush();
@ -82,9 +88,38 @@ void handleKISSData(char character) {
#ifdef ENABLE_WIFI
WiFiClient new_client = tncServer.available();
if (new_client.connected()){
clientsList.push_back(new WiFiClient(new_client));
bool new_client_handled = false;
for (int i=0; i < MAX_WIFI_CLIENTS; i++) {
auto client = clients[i];
if (client == nullptr) {
client = new WiFiClient(new_client);
clients[i] = client;
new_client_handled = true;
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("New client #") +String(i) + ": " + client->remoteIP().toString() + ":" + client->remotePort());
#endif
break;
}
}
#ifdef ENABLE_WIFI_CLIENT_DEBUG
for (int i = 0; i < MAX_WIFI_CLIENTS; ++i) {
auto client = clients[i];
if (client != nullptr){
Serial.println(String("Client #") +String(i) + ": " + client->remoteIP().toString() + ":" + client->remotePort());
}
}
#endif
if (!new_client_handled){
#ifdef ENABLE_WIFI_CLIENT_DEBUG
Serial.println(String("Refusing client "));
#endif
new_client.stop();
}
}
iterateWifiClients(clientsList, [](WiFiClient * client, const String * unused){
iterateWifiClients([](WiFiClient * client, const String * unused){
while (client->available() > 0) {
char character = client->read();
handleKISSData(character);
@ -101,7 +136,7 @@ void handleKISSData(char character) {
}
#endif
#ifdef ENABLE_WIFI
iterateWifiClients(clientsList, [](WiFiClient *client, const String *data){
iterateWifiClients([](WiFiClient *client, const String *data){
if (client->connected()){
client->print(*data);
client->flush();

Loading…
Cancel
Save