You've already forked TEF6686_ESP32
Added experimental UDP log broadcast. Re-added RT to logbook
This commit is contained in:
@@ -1013,7 +1013,8 @@ void loop() {
|
||||
DoMemoryPosTune();
|
||||
ShowMemoryPos();
|
||||
} else {
|
||||
if (!autologged && autolog && RDSstatus && radio.rds.correctPI != 0) {
|
||||
if (!autologged && RDSstatus && radio.rds.correctPI != 0) {
|
||||
if (autolog) {
|
||||
switch (addRowToCSV()) {
|
||||
case 0: ShowFreq(2); break;
|
||||
case 1: ShowFreq(3); break;
|
||||
@@ -1023,6 +1024,8 @@ void loop() {
|
||||
delay(200);
|
||||
while (digitalRead(ROTARY_BUTTON) == LOW) delay(50);
|
||||
ShowFreq(0);
|
||||
}
|
||||
if (wifi) sendUDPlog();
|
||||
autologged = true;
|
||||
}
|
||||
TuneUp();
|
||||
|
||||
@@ -205,7 +205,7 @@ bool handleCreateNewLogbook() {
|
||||
}
|
||||
|
||||
// Write the header to the new CSV file
|
||||
String header = "Date,Time,Frequency,PI,Signal,Stereo,TA,TP,PTY,ECC,PS\n";
|
||||
String header = "Date,Time,Frequency,PI,Signal,Stereo,TA,TP,PTY,ECC,PS,Radiotext\n";
|
||||
file.print(header); // Ensure that the header is written properly
|
||||
|
||||
// Make sure the data is written before closing the file
|
||||
@@ -261,9 +261,17 @@ byte addRowToCSV() {
|
||||
else if (unit == 1) signal += " dBf";
|
||||
else if (unit == 2) signal += " dBm";
|
||||
|
||||
// Prepare the radio text with station information, including enhanced options if available
|
||||
String radioText = String(radio.rds.stationText + " " + radio.rds.stationText32);
|
||||
if (radio.rds.hasEnhancedRT) {
|
||||
radioText += " eRT: " + String(radio.rds.enhancedRTtext);
|
||||
}
|
||||
|
||||
// Replace commas in the station name and radio text to avoid CSV conflicts
|
||||
String stationName = radio.rds.stationName;
|
||||
String radioTextModified = radioText;
|
||||
stationName.replace(",", " "); // Replace commas in station name
|
||||
radioTextModified.replace(",", " "); // Replace commas in radio text
|
||||
|
||||
// Handle ECC, PTY, TA, TP, and Stereo flag
|
||||
String TA = radio.rds.hasTA ? "•" : " ";
|
||||
@@ -280,14 +288,15 @@ byte addRowToCSV() {
|
||||
// Construct the CSV row data
|
||||
String row = currentDateTime + "," +
|
||||
frequencyFormatted + "," +
|
||||
String(radio.rds.picode) + "," +
|
||||
String(radio.rds.picode).substring(0, 4) + "," +
|
||||
signal + "," +
|
||||
Stereo + "," +
|
||||
TA + "," +
|
||||
TP + "," +
|
||||
pty + "," +
|
||||
ECC + "," +
|
||||
stationName + "\n";
|
||||
stationName + "," +
|
||||
radioTextModified + "\n";
|
||||
|
||||
// Write the row to the file and close it
|
||||
if (file.print(row)) {
|
||||
@@ -425,3 +434,73 @@ void printLogbookCSV() {
|
||||
// Print a message indicating the end of the file content
|
||||
Serial.println("===== End of logbook.csv =====");
|
||||
}
|
||||
|
||||
void sendUDPlog() {
|
||||
// Fetch the current date and time as a string
|
||||
String currentDateTime = getCurrentDateTime();
|
||||
|
||||
// Use a placeholder ("-,-") if the date and time could not be retrieved
|
||||
if (currentDateTime == "") {
|
||||
currentDateTime = "-,-";
|
||||
}
|
||||
|
||||
// Prepare the frequency in a formatted string (e.g., "XX.XX MHz")
|
||||
int freqInt = (band == BAND_OIRT) ? (int)frequency_OIRT : (int)frequency;
|
||||
int adjustedFreq = freqInt + (band != BAND_OIRT ? ConverterSet * 100 : 0);
|
||||
String frequencyFormatted = String(adjustedFreq / 100) + "." +
|
||||
((adjustedFreq % 100 < 10) ? "0" : "") +
|
||||
String(adjustedFreq % 100) + " MHz";
|
||||
|
||||
// Calculate signal strength based on the selected unit
|
||||
int SStatusPrint = 0;
|
||||
if (unit == 0) SStatusPrint = SStatus; // dBμV
|
||||
else if (unit == 1) SStatusPrint = ((SStatus * 100) + 10875) / 100; // dBf
|
||||
else if (unit == 2) SStatusPrint = round((float(SStatus) / 10.0 - 10.0 * log10(75) - 90.0) * 10.0); // dBm
|
||||
|
||||
// Format the signal strength with appropriate decimal places and unit
|
||||
String signal = String(SStatusPrint / 10) + "." + String(abs(SStatusPrint % 10));
|
||||
if (unit == 0) signal += " dBμV";
|
||||
else if (unit == 1) signal += " dBf";
|
||||
else if (unit == 2) signal += " dBm";
|
||||
|
||||
// Prepare the radio text with station information, including enhanced options if available
|
||||
String radioText = String(radio.rds.stationText + " " + radio.rds.stationText32);
|
||||
if (radio.rds.hasEnhancedRT) {
|
||||
radioText += " eRT: " + String(radio.rds.enhancedRTtext);
|
||||
}
|
||||
|
||||
// Replace commas in the station name and radio text to avoid CSV conflicts
|
||||
String stationName = radio.rds.stationName;
|
||||
String radioTextModified = radioText;
|
||||
stationName.replace(",", " "); // Replace commas in station name
|
||||
radioTextModified.replace(",", " "); // Replace commas in radio text
|
||||
|
||||
// Handle ECC, PTY, TA, TP, and Stereo flag
|
||||
String TA = radio.rds.hasTA ? "•" : " ";
|
||||
String TP = radio.rds.hasTP ? "•" : " ";
|
||||
String Stereo = radio.getStereoStatus() ? "•" : " ";
|
||||
String pty = String(radio.rds.stationTypeCode);
|
||||
String ECC = "--";
|
||||
if (radio.rds.hasECC) {
|
||||
char eccBuffer[3]; // Buffer to hold 2-digit hex value + null terminator
|
||||
snprintf(eccBuffer, sizeof(eccBuffer), "%02X", radio.rds.ECC); // Format ECC as uppercase 2-digit hex
|
||||
ECC = String(eccBuffer);
|
||||
}
|
||||
|
||||
// Construct the CSV row data
|
||||
String row = currentDateTime + "," +
|
||||
frequencyFormatted + "," +
|
||||
String(radio.rds.picode).substring(0, 4) + "," +
|
||||
signal + "," +
|
||||
Stereo + "," +
|
||||
TA + "," +
|
||||
TP + "," +
|
||||
pty + "," +
|
||||
ECC + "," +
|
||||
stationName + "," +
|
||||
radioTextModified + "\n";
|
||||
|
||||
Udp.beginPacket(remoteip, 9100);
|
||||
Udp.print(row);
|
||||
Udp.endPacket();
|
||||
}
|
||||
@@ -21,9 +21,11 @@ extern unsigned int ConverterSet;
|
||||
extern unsigned int frequency;
|
||||
extern unsigned int frequency_OIRT;
|
||||
extern unsigned int logcounter;
|
||||
extern IPAddress remoteip;
|
||||
|
||||
extern TEF6686 radio;
|
||||
extern WebServer webserver;
|
||||
extern WiFiUDP Udp;
|
||||
|
||||
void handleRoot();
|
||||
void handleDownloadCSV();
|
||||
@@ -33,5 +35,5 @@ String getCurrentDateTime();
|
||||
bool isDST(time_t t);
|
||||
void handleLogo();
|
||||
void printLogbookCSV();
|
||||
|
||||
void sendUDPlog();
|
||||
#endif
|
||||
Reference in New Issue
Block a user