From 4ae2ed6be27a07933472356d628597406c93848c Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Wed, 28 Jun 2023 22:06:05 +0200 Subject: [PATCH] Bigfixing on RDS --- TEF6686_ESP32.ino | 145 +++++++++++++++++++++++----------------------- src/TEF6686.cpp | 55 +++++++++++++++--- src/TEF6686.h | 1 + src/language.h | 4 +- 4 files changed, 123 insertions(+), 82 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index a8c462c..91c4bd9 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -39,132 +39,112 @@ TFT_eSPI tft = TFT_eSPI(320, 240); TFT_eSPI tft = TFT_eSPI(240, 320); #endif -IPAddress remoteip; -bool nobattery; -byte af_counterold; -byte battery; -byte batteryold; -byte subnetclient; -int rssi; -int rssiold = 200; -bool edgebeep; -byte ECCold; -bool RDSSPYUSB; -bool RDSSPYTCP; -byte audiomode; bool BWreset; bool change2; bool cleanup; -bool showsquelch; -byte amnb; -byte fmnb; bool direction; bool dropout; +bool edgebeep; bool EONold; bool fullsearchrds; -bool showrdserrors; bool LowLevelInit; bool memorystore; bool menu; bool menuopen; +bool nobattery; bool power = true; +bool RDSSPYTCP; +bool RDSSPYUSB; bool RDSstatusold; bool screenmute; bool seek; bool setupmode; +bool showrdserrors; +bool showsquelch; bool softmuteam; bool softmutefm; bool SQ; bool Stereostatusold; bool StereoToggle = true; bool store; -bool TPold; bool TAold; +bool TPold; bool tuned; bool USBmode = 1; -bool XDRMute; -bool XDRGTKdata; bool wifi; bool wificonnected; +bool XDRGTKdata; bool XDRGTKTCP; bool XDRGTKUSB; -byte region; -byte regionold; +bool XDRMute; +byte af_counterold; +byte amnb; +byte audiomode; +byte band; +byte battery; +byte batteryold; +byte BWset; +byte colorinvert; +byte ContrastSet; +byte displayflip; +byte ECCold; +byte EQset; +byte fmnb; +byte freqoldcount; +byte HighCutLevel; +byte HighCutOffset; +byte iMSEQ; +byte iMSset; byte language; -byte theme; -byte tunemode; +byte memoryband[30]; byte memorypos; -String salt; -String saltkey = " "; byte memoryposold; byte menupage = 1; byte menupagestotal = 4; byte MSold; -byte band; -byte BWset; -byte ContrastSet; -byte displayflip; -byte EQset; -byte freqoldcount; -byte iMSEQ; -byte iMSset; -byte memoryband[30]; byte optenc; +byte region; +byte regionold; byte rotarymode; -byte colorinvert; +byte showmodulation; +byte showSWMIBand = 1; byte SNR; byte SNRold; +byte specialstepOIRT; byte stepsize; +byte StereoLevel; +byte subnetclient; byte TEF; +byte theme; +byte tunemode; char buff[16]; -String programServicePrevious; char programTypePrevious[17]; char radioIdPrevious[6]; -String radioTextPrevious; int AGC; int BWOld; +int bwupdatetimer; int charWidth = tft.textWidth("AA"); -unsigned int ConverterSet; int DeEmphasis; int ForceMono; int freqold; -byte HighCutLevel; -byte HighCutOffset; -unsigned int HighEdgeSet; int LevelOffset; -unsigned int LowEdgeSet; int LowLevelSet; -byte specialstepOIRT; -unsigned int LowEdgeOIRTSet; -unsigned int HighEdgeOIRTSet; -unsigned int LWHighEdgeSet; -unsigned int LWLowEdgeSet; -unsigned int MWHighEdgeSet; -unsigned int MWLowEdgeSet; -unsigned int SWHighEdgeSet; -unsigned int SWLowEdgeSet; -byte showSWMIBand = 1; -uint16_t SWMIBandPos; -uint16_t SWMIBandPosold; // Fix Me: Should store this parameter into flash, for use of restart. -String SWMIBandstring = String(); -String SWMIBandstringold = String(); int lowsignaltimer; -int bwupdatetimer; -int offsetupdatetimer; -int snrupdatetimer; int menuoption = 30; int MStatusold; +int offsetupdatetimer; int OStatusold; int peakholdold; int peakholdtimer; int rotary; +int rssi; +int rssiold = 200; int scanner_filter; +int snrupdatetimer; int Sqstatusold; int Squelch; int Squelchold; int SStatusold; -byte StereoLevel; -byte showmodulation; int Stereostatus; int VolSet; int volume; @@ -176,35 +156,44 @@ int16_t OStatus; int16_t SAvg; int16_t SAvg2; int16_t SStatus; +IPAddress remoteip; +String cryptedpassword; String PIold; +String programServicePrevious; String PSold; String PTYold; +String radioTextPrevious; String rds_clock; String rds_clockold; -String cryptedpassword; String RDSSPYRDS; String RDSSPYRDSold; String RTold; +String salt; +String saltkey = " "; +String SWMIBandstring = String(); +String SWMIBandstringold = String(); String XDRGTK_key; String XDRGTKRDS; String XDRGTKRDSold; uint16_t BW; uint16_t MStatus; +uint16_t SWMIBandPos; +uint16_t SWMIBandPosold; // Fix Me: Should store this parameter into flash, for use of restart. uint16_t USN; uint16_t WAM; uint8_t buff_pos; uint8_t RDSstatus; unsigned int change; +unsigned int ConverterSet; unsigned int freq_scan; unsigned int frequency; unsigned int frequency_AM; unsigned int frequency_LW; -unsigned int frequency_MW; -unsigned int frequency_SW; -unsigned int frequencyold; unsigned int frequency_MIBand_11M; // Surive before tuner restart +unsigned int frequency_MIBand_120M; unsigned int frequency_MIBand_13M; unsigned int frequency_MIBand_15M; +unsigned int frequency_MIBand_160M; unsigned int frequency_MIBand_16M; unsigned int frequency_MIBand_19M; unsigned int frequency_MIBand_22M; @@ -215,12 +204,23 @@ unsigned int frequency_MIBand_49M; unsigned int frequency_MIBand_60M; unsigned int frequency_MIBand_75M; unsigned int frequency_MIBand_90M; -unsigned int frequency_MIBand_120M; -unsigned int frequency_MIBand_160M; +unsigned int frequency_MW; +unsigned int frequency_SW; +unsigned int frequencyold; +unsigned int HighEdgeOIRTSet; +unsigned int HighEdgeSet; +unsigned int LowEdgeOIRTSet; +unsigned int LowEdgeSet; +unsigned int LWHighEdgeSet; +unsigned int LWLowEdgeSet; unsigned int memory[30]; +unsigned int MWHighEdgeSet; +unsigned int MWLowEdgeSet; unsigned int scanner_end; unsigned int scanner_start; unsigned int scanner_step; +unsigned int SWHighEdgeSet; +unsigned int SWLowEdgeSet; unsigned long peakholdmillis; unsigned long rtticker; @@ -234,7 +234,7 @@ WiFiUDP Udp; void setup() { setupmode = true; EEPROM.begin(259); - if (EEPROM.readByte(43) != 27) DefaultSettings(); + if (EEPROM.readByte(43) != 28) DefaultSettings(); frequency = EEPROM.readUInt(0); VolSet = EEPROM.readInt(4); @@ -2067,6 +2067,7 @@ void KeyUp() { if (colorinvert) colorinvert = 0; else colorinvert = 1; tft.setTextColor(TFT_YELLOW); if (colorinvert) tft.drawCentreString(myLanguage[language][42], 155, 110, GFXFF); else tft.drawCentreString(myLanguage[language][30], 155, 110, GFXFF); + tft.invertDisplay(colorinvert); break; } break; @@ -2446,6 +2447,7 @@ void KeyDown() { if (colorinvert) colorinvert = 0; else colorinvert = 1; tft.setTextColor(TFT_YELLOW); if (colorinvert) tft.drawCentreString(myLanguage[language][42], 155, 110, GFXFF); else tft.drawCentreString(myLanguage[language][30], 155, 110, GFXFF); + tft.invertDisplay(colorinvert); break; } break; @@ -4672,7 +4674,7 @@ void passwordcrypt() { } void DefaultSettings() { - EEPROM.writeByte(43, 27); + EEPROM.writeByte(43, 28); EEPROM.writeUInt(0, 10000); EEPROM.writeInt(4, 0); EEPROM.writeUInt(8, 0); @@ -4722,7 +4724,6 @@ void DefaultSettings() { EEPROM.writeByte(249, 0); EEPROM.writeUInt(250, 0); EEPROM.writeUInt(254, 0); - EEPROM.writeByte(258,1); - + EEPROM.writeByte(258, 0); EEPROM.commit(); } diff --git a/src/TEF6686.cpp b/src/TEF6686.cpp index 8dd17dc..50e3d9b 100644 --- a/src/TEF6686.cpp +++ b/src/TEF6686.cpp @@ -315,11 +315,11 @@ void TEF6686::readRDS(bool showrdserrors) offset = rds.rdsB & 0x03; // Let's get the character offset for PS if (ps_process == true && offset == 8) { // Activates every time character offset is at 0, so whole message is received - for (byte i = 0; i < 9; i++) PStext[i] = L'\0'; // First erase buffer - RDScharConverter(ps_buffer, PStext, sizeof(PStext) / sizeof(wchar_t)); // Convert 8 bit ASCII to 16 bit ASCII - String utf8String = convertToUTF8(PStext); // Convert RDS characterset to ASCII - rds.stationName = utf8String.substring(0, 8); // Make sure PS does not exceed 8 characters - } + for (byte i = 0; i < 9; i++) PStext[i] = L'\0'; // First erase buffer + RDScharConverter(ps_buffer, PStext, sizeof(PStext) / sizeof(wchar_t)); // Convert 8 bit ASCII to 16 bit ASCII + String utf8String = convertToUTF8(PStext); // Convert RDS characterset to ASCII + rds.stationName = extractUTF8Substring(utf8String, 0, 8); // Make sure PS does not exceed 8 characters + } ps_buffer[(offset * 2) + 0] = rds.rdsD >> 8; // First character of segment ps_buffer[(offset * 2) + 1] = rds.rdsD & 0xFF; // Second character of segment @@ -329,9 +329,9 @@ void TEF6686::readRDS(bool showrdserrors) ps_counter ++; // Let's count each run RDScharConverter(ps_buffer, PStext, sizeof(PStext) / sizeof(wchar_t)); // Convert 8 bit ASCII to 16 bit ASCII String utf8String = convertToUTF8(PStext); // Convert RDS characterset to ASCII - rds.stationName = utf8String.substring(0, 8); // Make sure PS does not exceed 8 characters - if (ps_counter == 8) ps_process = true; // OK, we had 8 runs, now let's go the idle PS writing - } + rds.stationName = extractUTF8Substring(utf8String, 0, 8); + if (ps_counter == 8) ps_process = true; // OK, we had 8 runs, now let's go the idle PS writing + } } // PTY decoder @@ -403,6 +403,7 @@ void TEF6686::readRDS(bool showrdserrors) wchar_t RTtext[65] = L""; // Create 16 bit char buffer for Extended ASCII RDScharConverter(rt_buffer, RTtext, sizeof(RTtext) / sizeof(wchar_t)); // Convert 8 bit ASCII to 16 bit ASCII rds.stationText = convertToUTF8(RTtext); // Convert RDS characterset to ASCII + rds.stationText = extractUTF8Substring(rds.stationText, 0, 64); // Make sure PS does not exceed 64 characters rds.stationText += " "; // Add extra space } } break; @@ -520,6 +521,44 @@ String TEF6686::convertToUTF8(const wchar_t* input) { return output; } +String TEF6686::extractUTF8Substring(const String& utf8String, size_t start, size_t length) { + String substring; + size_t utf8Length = utf8String.length(); + size_t utf8Index = 0; + size_t charIndex = 0; + + while (utf8Index < utf8Length && charIndex < start + length) { + uint8_t currentByte = utf8String.charAt(utf8Index); + uint8_t numBytes = 0; + + if (currentByte < 0x80) { + numBytes = 1; + } else if ((currentByte >> 5) == 0x6) { + numBytes = 2; + } else if ((currentByte >> 4) == 0xE) { + numBytes = 3; + } else if ((currentByte >> 3) == 0x1E) { + numBytes = 4; + } + + if (charIndex >= start) { + substring += utf8String.substring(utf8Index, utf8Index + numBytes); + } + + utf8Index += numBytes; + charIndex++; + } + + if (rds.underscore) { + while (substring.length() < length) { + substring += '_'; + } + } + + return substring; +} + + void TEF6686::RDScharConverter(const char* input, wchar_t* output, size_t size) { for (size_t i = 0; i < size - 1; i++) { char currentChar = input[i]; diff --git a/src/TEF6686.h b/src/TEF6686.h index 5514889..c6dc7aa 100644 --- a/src/TEF6686.h +++ b/src/TEF6686.h @@ -259,6 +259,7 @@ class TEF6686 { private: void RDScharConverter(const char* input, wchar_t* output, size_t size); String convertToUTF8(const wchar_t* input); + String extractUTF8Substring(const String& utf8String, size_t start, size_t length); char ps_buffer[9]; bool ps_process; bool rt_process; diff --git a/src/language.h b/src/language.h index 0be3e26..c66ff0f 100644 --- a/src/language.h +++ b/src/language.h @@ -70,7 +70,7 @@ static const char myLanguage[9][70][85] = { "Defaults loaded", "Audio output", "FM OIRT 30 kHz steps", - "Display color invert" + "Invert display" }, { "Nederlands", // Dutch @@ -142,7 +142,7 @@ static const char myLanguage[9][70][85] = { "Opnieuw geconfigureerd", "Audio uitgang", "FM OIRT 30 kHz steps", - "Display color invert" + "Inverteer scherm" }, { "Polski", // Polish