kopia lustrzana https://github.com/SQ9MDD/TTGO-T-Beam-LoRa-APRS
Experimental GPS output on TCP port 10110
rodzic
0a8d94641f
commit
edee67e798
|
@ -2,4 +2,5 @@
|
|||
#include <TinyGPS++.h>
|
||||
|
||||
extern TinyGPSPlus gps;
|
||||
void taskGPS(void *parameter);
|
||||
|
||||
[[noreturn]] void taskGPS(void *parameter);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#endif
|
||||
#if defined(ENABLE_WIFI)
|
||||
#include "taskWebServer.h"
|
||||
#include "wifi_clients.h"
|
||||
#endif
|
||||
extern QueueHandle_t tncToSendQueue;
|
||||
extern QueueHandle_t tncReceivedQueue;
|
||||
|
|
|
@ -12,6 +12,7 @@ extern BG_RF95 rf95;
|
|||
#ifdef KISS_PROTOCOL
|
||||
extern WiFiServer tncServer;
|
||||
#endif
|
||||
extern WiFiServer gpsServer;
|
||||
typedef struct {
|
||||
String callsign;
|
||||
} tWebServerCfg;
|
||||
|
|
|
@ -49,6 +49,7 @@ build_flags =
|
|||
-D 'ENABLE_OLED'
|
||||
-D 'ENABLE_LED_SIGNALING'
|
||||
-D 'NETWORK_TNC_PORT=8001'
|
||||
-D 'NETWORK_GPS_PORT=10110'
|
||||
-D 'MAX_TIME_TO_NEXT_TX=360000L'
|
||||
-D 'FIX_BEACON_INTERVAL=1800000L'
|
||||
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
#include <taskGPS.h>
|
||||
#include <SparkFun_Ublox_Arduino_Library.h>
|
||||
#include <taskWebServer.h>
|
||||
|
||||
|
||||
SFE_UBLOX_GPS myGPS;
|
||||
|
||||
#ifdef ENABLE_WIFI
|
||||
#include "wifi_clients.h"
|
||||
#define MAX_GPS_WIFI_CLIENTS 6
|
||||
WiFiClient * gps_clients[MAX_GPS_WIFI_CLIENTS];
|
||||
#endif
|
||||
|
||||
// Pins for GPS
|
||||
#ifdef T_BEAM_V1_0
|
||||
static const int RXPin = 12, TXPin = 34;
|
||||
|
@ -14,7 +22,7 @@ HardwareSerial gpsSerial(1); // TTGO has HW serial
|
|||
TinyGPSPlus gps; // The TinyGPS++ object
|
||||
bool gpsInitialized = false;
|
||||
|
||||
void taskGPS(void *parameter) {
|
||||
[[noreturn]] void taskGPS(void *parameter) {
|
||||
if (!gpsInitialized){
|
||||
gpsSerial.begin(GPSBaud, SERIAL_8N1, TXPin, RXPin); //Startup HW serial for GPS
|
||||
|
||||
|
@ -35,9 +43,29 @@ void taskGPS(void *parameter) {
|
|||
}
|
||||
}
|
||||
|
||||
String gpsDataBuffer = " ";
|
||||
for (;;) {
|
||||
check_for_new_clients(&gpsServer, gps_clients, MAX_GPS_WIFI_CLIENTS);
|
||||
while (gpsSerial.available() > 0) {
|
||||
gps.encode(gpsSerial.read());
|
||||
char gpsChar = (char)gpsSerial.read();
|
||||
gps.encode(gpsChar);
|
||||
#ifdef ENABLE_WIFI
|
||||
if (gpsChar == '$') {
|
||||
gpsDataBuffer = String(gpsChar);
|
||||
} else {
|
||||
gpsDataBuffer += String(gpsChar);
|
||||
|
||||
if (gpsChar == '\n') {
|
||||
iterateWifiClients([](WiFiClient *client, int clientIdx, const String *data){
|
||||
if (client->connected()){
|
||||
client->print(*data);
|
||||
client->flush();
|
||||
}
|
||||
}, &gpsDataBuffer, gps_clients, MAX_GPS_WIFI_CLIENTS);
|
||||
gpsDataBuffer = "";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
|
|
@ -9,25 +9,6 @@ QueueHandle_t tncReceivedQueue = nullptr;
|
|||
#ifdef ENABLE_WIFI
|
||||
#define MAX_WIFI_CLIENTS 6
|
||||
WiFiClient * clients[MAX_WIFI_CLIENTS];
|
||||
|
||||
typedef void (*f_connectedClientCallback_t) (WiFiClient *, int, const String *);
|
||||
|
||||
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, i, data);
|
||||
} else {
|
||||
#ifdef ENABLE_WIFI_CLIENT_DEBUG
|
||||
Serial.println(String("Disconnected client ") + client->remoteIP().toString() + ":" + client->remotePort());
|
||||
#endif
|
||||
delete client;
|
||||
clients[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
#define IN_TNC_BUFFERS (2+MAX_WIFI_CLIENTS)
|
||||
|
@ -67,7 +48,7 @@ void handleKISSData(char character, int bufferIndex) {
|
|||
client->print(*data);
|
||||
client->flush();
|
||||
}
|
||||
}, &inTNCData);
|
||||
}, &inTNCData, clients, MAX_WIFI_CLIENTS);
|
||||
#endif
|
||||
#endif
|
||||
auto *buffer = new String();
|
||||
|
@ -103,45 +84,14 @@ void handleKISSData(char character, int bufferIndex) {
|
|||
}
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
WiFiClient new_client = tncServer.available();
|
||||
if (new_client.connected()){
|
||||
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];
|
||||
check_for_new_clients(&tncServer, clients, MAX_WIFI_CLIENTS);
|
||||
|
||||
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([](WiFiClient * client, int clientIdx, const String * unused){
|
||||
while (client->available() > 0) {
|
||||
char character = client->read();
|
||||
handleKISSData(character, 2+clientIdx);
|
||||
}
|
||||
}, nullptr);
|
||||
}, nullptr, clients, MAX_WIFI_CLIENTS);
|
||||
|
||||
#endif
|
||||
if (xQueueReceive(tncReceivedQueue, &loraReceivedFrameString, (1 / portTICK_PERIOD_MS)) == pdPASS) {
|
||||
|
@ -158,7 +108,7 @@ void handleKISSData(char character, int bufferIndex) {
|
|||
client->print(*data);
|
||||
client->flush();
|
||||
}
|
||||
}, &kissEncoded);
|
||||
}, &kissEncoded, clients, MAX_WIFI_CLIENTS);
|
||||
#endif
|
||||
|
||||
delete loraReceivedFrameString;
|
||||
|
|
|
@ -25,6 +25,7 @@ WebServer server(80);
|
|||
#ifdef KISS_PROTOCOL
|
||||
WiFiServer tncServer(NETWORK_TNC_PORT);
|
||||
#endif
|
||||
WiFiServer gpsServer(NETWORK_GPS_PORT);
|
||||
|
||||
#ifdef ENABLE_SYSLOG
|
||||
// A UDP instance to let us send and receive packets over UDP
|
||||
|
@ -324,6 +325,7 @@ void handle_saveDeviceCfg(){
|
|||
#ifdef KISS_PROTOCOL
|
||||
tncServer.begin();
|
||||
#endif
|
||||
gpsServer.begin();
|
||||
if (MDNS.begin(webServerCfg->callsign.c_str())) {
|
||||
MDNS.setInstanceName(webServerCfg->callsign + " TTGO LoRa APRS TNC " + TXFREQ + "MHz");
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
|
|
Ładowanie…
Reference in New Issue