From cf1c925f40ba16fe311206a123919a77b0a96f79 Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Mon, 10 Feb 2025 19:13:15 +0100 Subject: [PATCH] Extended UDP protocol --- TEF6686_ESP32.ino | 5 ++++ src/comms.cpp | 63 ++++++++++++++++++++++++++++++++++------------- src/comms.h | 4 +++ src/logbook.cpp | 20 ++++++++++++--- src/logbook.h | 2 ++ 5 files changed, 73 insertions(+), 21 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index 045991d..3910826 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -171,6 +171,7 @@ byte BWsetFM; byte BWsetRecall; byte BWtemp; byte charwidth = 8; +byte chipmodel; byte hardwaremodel; byte ContrastSet; byte CurrentSkin; @@ -862,19 +863,23 @@ void setup() { if (lowByte(device) == 14) { fullsearchrds = false; fmsi = false; + chipmodel = 0; tft.fillRect(152, 230, 16, 6, PrimaryColor); tftPrint(0, "TEF6686 Lithio", 160, 172, ActiveColor, ActiveColorSmooth, 28); } else if (lowByte(device) == 1) { fullsearchrds = true; + chipmodel = 1; tft.fillRect(152, 230, 16, 6, PrimaryColor); tftPrint(0, "TEF6687 Lithio FMSI", 160, 172, ActiveColor, ActiveColorSmooth, 28); } else if (lowByte(device) == 9) { fullsearchrds = false; + chipmodel = 2; fmsi = false; tft.fillRect(152, 230, 16, 6, PrimaryColor); tftPrint(0, "TEF6688 Lithio DR", 160, 172, ActiveColor, ActiveColorSmooth, 28); } else if (lowByte(device) == 3) { fullsearchrds = true; + chipmodel = 3; tft.fillRect(152, 230, 16, 6, PrimaryColor); tftPrint(0, "TEF6689 Lithio FMSI DR", 160, 172, ActiveColor, ActiveColorSmooth, 28); } else { diff --git a/src/comms.cpp b/src/comms.cpp index 2cc2714..5112cff 100644 --- a/src/comms.cpp +++ b/src/comms.cpp @@ -9,52 +9,80 @@ void Communication() { if (!menu) { if (wifi) { int packetSize = Udp.parsePacket(); - if (packetSize) { - char packetBuffer[packetSize]; + if (packetSize > 0) { + char packetBuffer[packetSize + 1]; // +1 for null terminator Udp.read(packetBuffer, packetSize); + packetBuffer[packetSize] = '\0'; // Ensure valid string Udp.endPacket(); + String packet = String(packetBuffer); - if (strcmp(packetBuffer, "from=StationList;freq=?;bandwidth=?") == 0) { + + if (packet.equals("from=StationList;freq=?;bandwidth=?")) { ShowFreq(0); - } else { - externaltune = true; - int symPos = packet.indexOf("freq="); - String stlfreq = packet.substring(symPos + 5, packetSize); + return; + } + + externaltune = true; + + if (packet.charAt(0) == '*') { + if (afscreen) BuildAdvancedRDS(); + char command = packet.charAt(1); + switch (command) { + case 'U': + case 'D': + tunemode = TUNE_MAN; + ShowTuneMode(); + if (command == 'U') TuneUp(); else TuneDown(); + ShowFreq(0); + break; + + case 'S': if (!scandxmode) startFMDXScan(); break; + case 'E': if (scandxmode) cancelDXScan(); break; + + case 'R': radio.clearRDS(fullsearchrds); break; + } + return; + } + + int symPos = packet.indexOf("freq="); + + if (symPos != -1) { + String stlfreq = packet.substring(symPos + 5); + int freqValue = stlfreq.toInt(); + if (afscreen) BuildAdvancedRDS(); - if ((stlfreq.toInt()) / 10000 > (TEF == 205 ? 6400 : 6500) && (stlfreq.toInt()) / 10000 < 10800) { - unsigned int tempfreq = (stlfreq.toInt()) / 10000; + unsigned int tempfreq; + if ((freqValue / 10000) > (TEF == 205 ? 6400 : 6500) && (freqValue / 10000) < 10800) { + tempfreq = freqValue / 10000; if (scandxmode) cancelDXScan(); + if (tempfreq >= FREQ_FM_OIRT_START && tempfreq <= FREQ_FM_OIRT_END) { if (band != BAND_OIRT) { band = BAND_OIRT; frequency_OIRT = tempfreq; SelectBand(); } + radio.SetFreq(frequency_OIRT); } else { if (band != BAND_FM) { band = BAND_FM; frequency = tempfreq; SelectBand(); } - } - if (band == BAND_OIRT) { - frequency_OIRT = tempfreq; - radio.SetFreq(frequency_OIRT); - } else { - frequency = tempfreq; radio.SetFreq(frequency); } } - if ((stlfreq.toInt()) / 1000 > 144 && (stlfreq.toInt()) / 1000 < 27000) { + if ((freqValue / 1000) > 144 && (freqValue / 1000) < 27000) { + tempfreq = freqValue / 1000; if (scandxmode) cancelDXScan(); if (afscreen || advancedRDS) { BuildDisplay(); SelectBand(); ScreensaverTimerReopen(); } - unsigned int tempfreq = (stlfreq.toInt()) / 1000; + if (tempfreq >= FREQ_LW_LOW_EDGE_MIN && tempfreq <= FREQ_LW_HIGH_EDGE_MAX) { frequency_LW = tempfreq; if (band != BAND_LW) { @@ -84,6 +112,7 @@ void Communication() { } } } + radio.clearRDS(fullsearchrds); ShowFreq(0); store = true; diff --git a/src/comms.h b/src/comms.h index 82e766b..542b935 100644 --- a/src/comms.h +++ b/src/comms.h @@ -54,6 +54,7 @@ extern byte scanhold; extern byte stepsize; extern byte subnetclient; extern byte TEF; +extern byte tunemode; extern char buff[16]; extern int ActiveColor; extern int ActiveColorSmooth; @@ -154,4 +155,7 @@ extern void handleRoot(); extern void handleDownloadCSV(); extern void handleLogo(); extern void Infoboxprint(const char* input); +extern void TuneUp(); +extern void TuneDown(); +extern void ShowTuneMode(); #endif \ No newline at end of file diff --git a/src/logbook.cpp b/src/logbook.cpp index 3302a20..e036f94 100644 --- a/src/logbook.cpp +++ b/src/logbook.cpp @@ -535,6 +535,15 @@ void sendUDPlog() { } } + // set Chipmodel + String CHIP = ""; + switch (chipmodel) { + case 0: CHIP = "TEF6686"; break; + case 1: CHIP = "TEF6687"; break; + case 2: CHIP = "TEF6688"; break; + case 3: CHIP = "TEF6689"; break; + } + // Extract RT+ (RadioText Plus) content if available String RTPLUS = ""; if (radio.rds.hasRDSplus) { @@ -542,7 +551,10 @@ void sendUDPlog() { } // Construct the data row to send via UDP - String row = currentDateTime + "," + + String row = CHIP + "," + + VERSION + "," + + String(scandxmode) + "," + + currentDateTime + "," + frequencyFormatted + "," + String(radio.rds.picode).substring(0, 4) + "," + signal + "," + @@ -561,7 +573,7 @@ void sendUDPlog() { // Send the data via UDP if it's new if (UDPlogold != row) { - IPAddress broadcastIP = makeBroadcastAddress(remoteip); + IPAddress broadcastIP = makeBroadcastAddress(remoteip); Udp.beginPacket(broadcastIP, 9100); Udp.print(row); Udp.endPacket(); @@ -570,6 +582,6 @@ void sendUDPlog() { } IPAddress makeBroadcastAddress(IPAddress ip) { - // Assuming a typical subnet mask of 255.255.255.0 - return IPAddress(ip[0], ip[1], ip[2], 255); + // Assuming a typical subnet mask of 255.255.255.0 + return IPAddress(ip[0], ip[1], ip[2], 255); } \ No newline at end of file diff --git a/src/logbook.h b/src/logbook.h index c25f3f5..a7b87f0 100644 --- a/src/logbook.h +++ b/src/logbook.h @@ -12,7 +12,9 @@ extern bool autoDST; extern bool clockampm; extern bool NTPupdated; extern bool rtcset; +extern bool scandxmode; extern byte band; +extern byte chipmodel; extern byte language; extern byte unit; extern int16_t SStatus;