From 0ce1ca00f8487b9a3d5a64848e825d778325423f Mon Sep 17 00:00:00 2001 From: M0WID Date: Mon, 19 Oct 2020 23:25:56 +0100 Subject: [PATCH] Commands via terminal Enabled console commands via normal terminal emulator Added menu for calibration of filters --- RXsweep.ino | 15 +- SweepLo.ino | 4 +- cmd.cpp | 72 ++-- cmd.h | 3 + data/about.html | 2 +- data/index.html | 3 +- data/siggen.html | 976 ---------------------------------------------- simpleSA.ino | 6 +- simpleSA_wifi.cpp | 468 +++------------------- ui.cpp | 10 +- 10 files changed, 135 insertions(+), 1424 deletions(-) delete mode 100644 data/siggen.html diff --git a/RXsweep.ino b/RXsweep.ino index 2ef61c9..e6aff7d 100644 --- a/RXsweep.ino +++ b/RXsweep.ino @@ -54,6 +54,7 @@ static int16_t lastMode; // Record last operating mode (sig gen, normal) static uint16_t currentPointRSSI; static uint16_t peakRSSI; +static uint16_t centreRSSI; // RSSI at centre of sweep (ie at IF) static uint16_t prevPointRSSI; static uint32_t peakFreq; static uint16_t peakIndex; @@ -81,11 +82,16 @@ static uint16_t bpfCalFirstSweepDone; if (bpfCalibrate) { + setting.LevelOffset = 0; if (bpfCalFirstSweepDone) { - // max value for this bpFilter index (pervious sweep) is in peaks[0].Level - bpfCalibrations[bpFilterIndex] = CAL_POWER - rssiTodBm ( peaks[0].Level); - Serial.printf("bpfCalibration: filter: %i, rbw10=%i , cal=%f \n", bpFilterIndex, currentRBW10, bpfCalibrations[bpFilterIndex]); + // max value for this bpFilter index (previous sweep) is in peaks[0].Level + // value at the IF is in myActual[displayPoints/2] + // use the average of the two values + uint16_t rssi_average = ( peaks[0].Level + myActual[displayPoints/2] ) / 2; + bpfCalibrations[bpFilterIndex] = CAL_POWER - rssiTodBm( rssi_average ); + Serial.printf("bpfCalibration: filter: %i, rbw10=%i , cal=%f, rssi av = %i\n", + bpFilterIndex, currentRBW10, bpfCalibrations[bpFilterIndex], rssi_average); bpFilterIndex ++; if (bpFilterIndex >= bpfCount) // end of calibration @@ -93,6 +99,7 @@ static uint16_t bpfCalFirstSweepDone; bpfCalibrate = false; currentRBW10 = setting.Bandwidth10; SaveBpfCalibration(); + WriteSettings(); Serial.println("bpfCalibration done"); } else // not reached end of filters @@ -132,7 +139,7 @@ static uint16_t bpfCalFirstSweepDone; att.SetAtten ( 0 ); // Set the internal attenuator // pre-calculate adjustment for RSSI values - dBadjust = -120.0 - setting.ExternalGain; // No correction applied for this mode + dBadjust = -120.0 - setting.ExternalGain; // No Level Offset correction applied for this mode //Serial.printf("RXSweep dBadjust = %f; ext gain = %f\n", dBadjust, setting.ExternalGain); xmit.SetPowerReference ( setting.ReferenceOut ); // Set the GPIO reference output diff --git a/SweepLo.ino b/SweepLo.ino index 791be57..7086918 100644 --- a/SweepLo.ino +++ b/SweepLo.ino @@ -144,8 +144,8 @@ static uint32_t tgIF; // Track gen IF - SA IF plus any offset if both SI4432 // pre-calculate adjustment for RSSI values dBadjust = (double)setting.Attenuate - 120.0 + setting.LevelOffset - setting.ExternalGain + bpfCalibrations[bpfIndex]; - Serial.printf("SweepLo dBadjust = %f; leveloffset = %f; attenuate = %i, ext gain = %f\n", - dBadjust, setting.LevelOffset, setting.Attenuate, setting.ExternalGain); + Serial.printf("SweepLo dBadjust = %f; leveloffset = %f; attenuate = %i, ext gain = %f, bpfCal = %f\n", + dBadjust, setting.LevelOffset, setting.Attenuate, setting.ExternalGain, bpfCalibrations[bpfIndex]); resetAverage = changedSetting; diff --git a/cmd.cpp b/cmd.cpp index f9d2f71..569d144 100644 --- a/cmd.cpp +++ b/cmd.cpp @@ -194,6 +194,8 @@ extern uint8_t dBmToRSSI ( double dBm ); { "TRACKSIG", MSG_TGSIG }, // turn off tracking generator output { "TGFREQ", MSG_TGFREQ }, // Set Track gen freq for sig gen mode { "BPFCAL", MSG_BPFCAL }, // Start bandpass filter calibration + { "OTA", MSG_OTA }, // Select OTA Update Mode + { "", MSG_NONE } // Unrecognized command }; @@ -239,16 +241,20 @@ void ShowMenu () Serial.println ( " PAUSE.........Pause or resume the sweep" ); - Serial.println ( "\nDisplay Options:\n" ); + + Serial.println ( "\nMode selection:\n" ); Serial.println ( " SALO..........Set to analyse mode low frequency range" ); Serial.println ( " SGLO..........Set to signal generator mode low frequency range" ); Serial.println ( " IFSWEEP.......Set to IF Sweep mode to analyse the TinySA SAW filters" ); Serial.println ( " RXSWEEP.......Set to RX Sweep mode to analyse the TinySA FIR filters" ); Serial.println ( " BANDSCOPE.....Set to BANDSCOPE mode" ); + Serial.println ( " OTA...........Set to OTA update mode to download firmware or SPIFFS over wifi" ); + + Serial.println ( "\nDisplay Options:\n" ); Serial.println ( " TRACES........Turn display traces on or off ['GAIN' or 'dB']" ); - + Serial.printf ( " PREAMP/GAIN...Set or get the receiver preamp gain\n" ); Serial.println ( " See documentation for allowed values" ); @@ -386,9 +392,9 @@ void ShowMenu () bool CheckCommand () { -char inBuff[80]; // Input buffer -char c = 0; // Just one character -int16_t index = 0; // Index to the buffer +static char inBuff[80]; // Input buffer +char c = 0; // Just one character +static int16_t index = 0; // Index to the buffer if ( !Serial.available() ) // Any input? return false; // Nope! @@ -397,18 +403,28 @@ int16_t index = 0; // Index to the buffer { c = toupper ( Serial.read () ); // Get next character Serial.print(c); // Echo - Serial.printf("(%02X)", c); // debug + //Serial.printf("(%02X)", c); // debug - if (( c == '\r' ) || ( c == '\n' )) // End of the line? + if ( ( c == '\r' ) || ( c == '\n' ) ) // End of the line? { + Serial.println(); inBuff[index++] = '\0'; // Replace with a null - Serial.println("EOL"); // debug - return ParseCommand ( inBuff ); // Process the command and return result + //Serial.printf("EOL = %s \n", inBuff); // debug + boolean result = ParseCommand ( inBuff ); // Process the command and return result + index = 0; + return result; } else // Not the end of the line + { inBuff[index++] = c; // Save the character - - inBuff[index] = '\0'; // Make next character a null + inBuff[index+1] = '\0'; // Make next character a null + } + if (index >= 78) + { + Serial.println("Serial Buffer Overun"); + index = 0; + break; + } } return false; @@ -1657,6 +1673,10 @@ uint8_t reg69; // Ditto setMode(RX_SWEEP); return true; + case MSG_OTA: + setMode(OTA_UPDATE); + return true; + case MSG_TGOFFSET: if ( dataLen != 0 ) // Frequency specified? { @@ -1798,17 +1818,7 @@ uint8_t reg69; // Ditto * Valid only if already in RX Sweep mode */ case MSG_BPFCAL: - if ( setting.Mode == RX_SWEEP ) - { - bpfCalibrate = true; - Serial.println("Starting bpf calibration"); - return true; - } - else - { - Serial.println("bpfCal only works in RX_SWEEP (RBW test) mode"); - } - return false; + return StartBpfCal (); default: @@ -3173,6 +3183,24 @@ uint32_t GetRXsweepSigFreq ( void ) } +/* + * start the bandpass filter calibration sequence + * must be in RX_Sweep mode + */ + boolean StartBpfCal ( void ) + { + if ( setting.Mode == RX_SWEEP ) + { + bpfCalibrate = true; + Serial.println("Starting bpf calibration"); + return true; + } + else + { + Serial.println("bpfCal only works in RX_SWEEP (RBW test) mode"); + return false; + } + } /* * Specific start/stop frequency setting for Bandscope mode diff --git a/cmd.h b/cmd.h index 6a1005a..40d08b1 100644 --- a/cmd.h +++ b/cmd.h @@ -86,6 +86,7 @@ #define MSG_TGFREQ 57 // Set Track Gen frequency for sig gen mode #define MSG_TGSIG 58 // Set Track Gen sig gen mode #define MSG_BPFCAL 59 // Start bandpass filter calibration +#define MSG_OTA 60 // OTA Update mode #define MSG_COLOURTEST 99 // test of waterfall colours - remove this when done! @@ -219,6 +220,8 @@ uint32_t GetRXsweepSpan ( void ); void SetRXsweepSigFreq ( uint32_t freq ); uint32_t GetRXsweepSigFreq ( void ); +boolean StartBpfCal ( void ); + void SetSweepCenter ( uint32_t freq, uint8_t span ); uint32_t GetSweepCenter ( void ); diff --git a/data/about.html b/data/about.html index 9b87ab5..dc41423 100644 --- a/data/about.html +++ b/data/about.html @@ -47,7 +47,7 @@

This simpleSA running on an ESP32 has been adapted by Dave M0WID and John WA2FZW.
- It was based on an early prototype design of the TinySA by Erik PD0EK.
+ It was based on an early arduino prototype of the TinySA by Erik PD0EK.
Information can be found at https://groups.io/g/HBTE

diff --git a/data/index.html b/data/index.html index 9295fd8..2be6077 100644 --- a/data/index.html +++ b/data/index.html @@ -1039,12 +1039,13 @@ var dateObject; */ function renderChart() { - setTimeout(function(){renderChart()}, refreshInterval.value); chartSA.render(); //setTimeout(renderChart, refreshInterval.value); + setTimeout(function(){renderChart()}, refreshInterval.value); } + //messageCount.value = messageCounter; //missedReplies.value = missedMessageCounter; hostName.value = "ws://" + location.host + ":81"; diff --git a/data/siggen.html b/data/siggen.html deleted file mode 100644 index f81a443..0000000 --- a/data/siggen.html +++ /dev/null @@ -1,976 +0,0 @@ - - - - - - -simpleSA-ESP - - - - - - - - -
- - - - -
-
-
-
- -
- -
- - -
-
- - - MHz -
-
-
- - - dBm -
-
-

Settings

-
- - - dB -
-
- - - dBm -
-
-
- - - dBm -
-
- - - MHz -
- -
- -
- - - - - -
-
-
-
-
-
Host: - - - -
-
Status: - -
-
Pings: - -
-
Refresh Interval: - -
-
-
- - -
-
- - - - diff --git a/simpleSA.ino b/simpleSA.ino index b1735f1..413992d 100644 --- a/simpleSA.ino +++ b/simpleSA.ino @@ -847,7 +847,7 @@ bool fsStatus = false; // True if SPIFFS loads ok tft.setTextColor(WHITE); tft.setFreeFont ( &FreeSansBold9pt7b ); // Select Free Serif 9 point font tft.print( "Progress:"); - tft.fillRect(120, 180, 100, 20, SIG_BACKGROUND_COLOR); // x, y, w, h, color + tft.fillRect(120, 182, 100, 20, SIG_BACKGROUND_COLOR); // x, y, w, h, color tft.setCursor (120, 200); tft.printf("%u%%", (progress / (total / 100))); @@ -1208,7 +1208,7 @@ void init_sweep() void initChunkSweepDoc (uint32_t startIndex) { jsonDocument.clear (); - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain + jsonDocument["PreAmp"] = setting.PreampGain; jsonDocument["mType"] = "chunkSweep"; jsonDocument["StartIndex"] = startIndex; jsonDocument["sweepPoints"] = sweepPoints; @@ -1911,7 +1911,7 @@ double rssiTodBm ( uint8_t rSSI ) /* - * Function to convert rSSi to dBm + * Function to convert dBm to RSSI */ uint8_t dBmToRSSI ( double dBm ) diff --git a/simpleSA_wifi.cpp b/simpleSA_wifi.cpp index 91ae0a6..ab9a7d0 100644 --- a/simpleSA_wifi.cpp +++ b/simpleSA_wifi.cpp @@ -163,12 +163,9 @@ boolean connectWiFi() // Connect to Wifi using SSID (ie via Router) /* - * Apply any hostname that we may have + * Apply hostname */ -// if ( strlen ( (char *) &configuration.Hostname[0]) > 0 ) -// WiFi.setHostname ( (char *) &configuration.Hostname[0] ); -// else WiFi.setHostname ( PROGRAM_NAME ); int maxTry = 10; // Wait for the connection to be made. @@ -505,167 +502,49 @@ void addTagNameValue ( char *b, char *_name, char *value ) /* - * On request from web page convert the data from a scan into XML and send - * - * Ideally we would push the data to the web page at the end of a scan, - * or perhaps just create the xml at the end of each scan - investigate later + * Handle settings that are common to all modes */ -//void onGetScan ( AsyncWebServerRequest *request ) -//{ -// response = request->beginResponseStream ( "text/xml" ); -//// Serial.println ( "onGetScan" ); -// -// response->print ( "" ); -// response->println ( "" ); -// -// for( int i = 0; i < displayPoints-1; i++ ) // For each data point -// { -//// Serial.printf ( " %i\n",myFreq[i], myData[i], i ); -// response->printf ( "

\n", myFreq[i], myData[i] ); -// } -// -// response->print ( "" ); -// request->send ( response ); -//} - - -/* - * On request from web page convert the gain data from a sweep into JSON and send - * Ideally we would push the data to the web page at the end of a scan, - */ - -//void onGetGainSweep ( AsyncWebServerRequest *request ) -//{ -// size_t bufferSize = JSON_ARRAY_SIZE ( SCREEN_WIDTH ) -// + JSON_OBJECT_SIZE ( 1 ) + SCREEN_WIDTH * JSON_OBJECT_SIZE ( 2 ); -// -// AsyncJsonResponse * response = new AsyncJsonResponse ( false, bufferSize ); -//// response->addHeader ( "Server","ESP Async Web Server" ); -// -// JsonObject root = response->getRoot(); -// JsonArray gainPoints = root.createNestedArray ( "gainPoints" ); // Add gainPoints array -// -///* -// * Add the objects to the array -// */ -// -// for ( int i = 0; i < displayPoints; i++ ) // For each data point -// { -// JsonObject dataPoint = gainPoints.createNestedObject(); // Add an object to the array -// dataPoint["x"] = myFreq[i]/1000000.0; // set the x(frequency) value -// dataPoint["y"] = myGain[i]; // set the y (gain) value -// } -// -// response->setLength(); -// request->send ( response ); -//} - - -/* - * On request from web page convert the data from a sweep into JSON and send. - * Ideally we would push the data to the web page at the end of a scan. - */ - -//void onGetSweep ( AsyncWebServerRequest *request ) -//{ -// size_t bufferSize = JSON_ARRAY_SIZE ( SCREEN_WIDTH ) -// + JSON_OBJECT_SIZE ( 14 ) + SCREEN_WIDTH * JSON_OBJECT_SIZE ( 2 ); -// -// AsyncJsonResponse * response = new AsyncJsonResponse ( false, bufferSize ); -// -// JsonObject root = response->getRoot(); -// -// root["dispPoints"] = displayPoints; -// root["start"] = setting.ScanStart / 1000.0; -// root["stop"] = setting.ScanStop / 1000.0; -// root["IF"] = setting.IF_Freq / 1000000.0; -// root["attenuation"] = setting.Attenuate; -// root["extGain"] = setting.ExternalGain; -// root["levelOffset"] = setting.LevelOffset; -// root["filterCal"] = bpfCalibrations[bpfIndex]; -// root["setRBW"] = setting.Bandwidth10; -// root["bandwidth"] = bandwidth; -// root["RefOut"] = setting.ReferenceOut; -// root["Drive"] = setting.Drive; -// root["sweepPoints"] = sweepPoints; -// -// if ( AGC_On ) -// root["PreAmp"] = 0x60; // Auto -// -// else -// root["PreAmp"] = setting.PreampGain; // Fixed gain -// -// JsonArray Points = root.createNestedArray ( "Points" ); // Add Points array -// -// -// for ( int i = 0; i < displayPoints; i++ ) //For each data point -// { -// JsonObject dataPoint = Points.createNestedObject(); // add an object to the array -// dataPoint["x"] = myFreq[i]/1000000.0; // set the x(frequency) value -// dataPoint["y"] = myData[i]; // set the y (RSSI) value -// } -// -// -// response->setLength(); -// request->send ( response ); -//} - - -/* - * On request from web page send the settings as JSON - */ -//void onGetSettings (AsyncWebServerRequest *request) -//{ -// AsyncJsonResponse * response = new AsyncJsonResponse(false) ; -// -// JsonObject root = response->getRoot(); -// -// root["mType"] = "Settings"; -// root["mode"] = setting.Mode; -// root["dispPoints"] = displayPoints; -// root["start"] = setting.ScanStart / 1000.0; -// root["stop"] = setting.ScanStop / 1000.0; -// root["IF"] = setting.IF_Freq / 1000000.0; -// root["attenuation"] = setting.Attenuate; -// root["extGain"] = setting.ExternalGain; -// root["levelOffset"] = setting.LevelOffset; -// root["filterCal"] = bpfCalibrations[bpfIndex]; -// root["setRBW"] = setting.Bandwidth10; -// root["bandwidth"] = bandwidth; -// root["RefOut"] = setting.ReferenceOut; -// root["Drive"] = setting.Drive; -// root["sweepPoints"] = sweepPoints; -// root["spur"] = setting.Spur; -// root["tg"] = trackGenSetting.Mode; -// root["tgPower"] = trackGenSetting.Power; -// root["tgFreq"] = trackGenSetting.Frequency; -// root["tgMod"] = trackGenSetting.ModulationType; -// root["tgModFreq"] = trackGenSetting.ModFrequency; -// root["sg"] = sigGenOutputOn; // -// root["sgPower"] = sigGenSetting.Power; -// root["sgMod"] = sigGenSetting.ModulationType; -// root["sgModFreq"] = sigGenSetting.ModFrequency; -// root["sgFreq"] = sigGenSetting.Frequency; -// root["sgCal"] = sigGenSetting.Calibration; -// root["sgRange"] = ATTENUATOR_RANGE + 11; // SI4432 output can be adjusted over 21dBm but max to SAW filter is 10dBm -// root["tgCal"] = trackGenSetting.Calibration; -// root["tgRange"] = ATTENUATOR_RANGE + 21; // no SAW filter so 20dBm output is possible. -// -// if ( AGC_On ) -// root["PreAmp"] = 0x60; // Auto -// -// else -// root["PreAmp"] = setting.PreampGain; // Fixed gain -// -// response->setLength(); -// request->send ( response ); -//// Serial.printf ( "Get Settings sweepPoints %u\n", sweepPoints ); -//} - +void addCommonSettings ( JsonDocument& jDoc ) +{ + jDoc["mType"] = "Settings"; + jDoc["mode"] = setting.Mode; + jDoc["IF"] = setting.IF_Freq / 1000000.0; + jDoc["attenuation"] = setting.Attenuate; + jDoc["extGain"] = setting.ExternalGain; + jDoc["filterCal"] = bpfCalibrations[bpfIndex]; + jDoc["setRBW"] = setting.Bandwidth10; + jDoc["bandwidth"] = bandwidth; + jDoc["RefOut"] = setting.ReferenceOut; + jDoc["Drive"] = setting.Drive; + jDoc["sweepPoints"] = sweepPoints; + jDoc["spur"] = setting.Spur; + jDoc["tg"] = trackGenSetting.Mode; + jDoc["tgPower"] = trackGenSetting.Power; + jDoc["tgFreq"] = trackGenSetting.Frequency; + jDoc["tgMod"] = trackGenSetting.ModulationType; + jDoc["tgModFreq"] = trackGenSetting.ModFrequency; + jDoc["sg"] = sigGenOutputOn; // + jDoc["sgPower"] = sigGenSetting.Power; + jDoc["sgMod"] = sigGenSetting.ModulationType; + jDoc["sgModFreq"] = sigGenSetting.ModFrequency; + jDoc["sgFreq"] = sigGenSetting.Frequency; + jDoc["sgCal"] = sigGenSetting.Calibration; + jDoc["sgRange"] = ATTENUATOR_RANGE + 11; // SI4432 output can be adjusted over 21dBm but max to SAW filter is 10dBm + jDoc["tgCal"] = trackGenSetting.Calibration; + jDoc["tgRange"] = ATTENUATOR_RANGE + 21; // no SAW filter so 20dBm output is possible. + + if ( AGC_On ) + jDoc["PreAmp"] = 0x60; // Auto + else + jDoc["PreAmp"] = setting.PreampGain; // Fixed gain +} /* * Push the settings data to the websocket clients + * Slightly different for each mode + * + * Could economise by splitting so common fields are in one function */ void pushSettings () { @@ -677,41 +556,12 @@ size_t capacity = JSON_ARRAY_SIZE ( SCREEN_WIDTH ) + SCREEN_WIDTH*JSON_OBJECT_SIZE ( 2 ) + JSON_OBJECT_SIZE ( 17 ); static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to be pushed to the web clients - jsonDocument["mType"] = "Settings"; - jsonDocument["mode"] = setting.Mode; + addCommonSettings(jsonDocument); + jsonDocument["dispPoints"] = displayPoints; jsonDocument["start"] = setting.ScanStart / 1000.0; jsonDocument["stop"] = setting.ScanStop / 1000.0; - jsonDocument["IF"] = setting.IF_Freq / 1000000.0; - jsonDocument["attenuation"] = setting.Attenuate; - jsonDocument["extGain"] = setting.ExternalGain; jsonDocument["levelOffset"] = setting.LevelOffset; - jsonDocument["filterCal"] = bpfCalibrations[bpfIndex]; - jsonDocument["setRBW"] = setting.Bandwidth10; - jsonDocument["bandwidth"] = bandwidth; - jsonDocument["RefOut"] = setting.ReferenceOut; - jsonDocument["Drive"] = setting.Drive; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["spur"] = setting.Spur; - jsonDocument["tg"] = trackGenSetting.Mode; - jsonDocument["tgPower"] = trackGenSetting.Power; - jsonDocument["tgFreq"] = trackGenSetting.Frequency; - jsonDocument["tgMod"] = trackGenSetting.ModulationType; - jsonDocument["tgModFreq"] = trackGenSetting.ModFrequency; - jsonDocument["sg"] = sigGenOutputOn; // - jsonDocument["sgPower"] = sigGenSetting.Power; - jsonDocument["sgMod"] = sigGenSetting.ModulationType; - jsonDocument["sgModFreq"] = sigGenSetting.ModFrequency; - jsonDocument["sgFreq"] = sigGenSetting.Frequency; - jsonDocument["sgCal"] = sigGenSetting.Calibration; - jsonDocument["sgRange"] = ATTENUATOR_RANGE + 11; // SI4432 output can be adjusted over 21dBm but max to SAW filter is 10dBm - jsonDocument["tgCal"] = trackGenSetting.Calibration; - jsonDocument["tgRange"] = ATTENUATOR_RANGE + 21; // no SAW filter so 20dBm output is possible. - - if ( AGC_On ) - jsonDocument["PreAmp"] = 0x60; // Auto - else - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain String wsBuffer; @@ -727,6 +577,7 @@ static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to } + /* * Push the settings data to the websocket clients */ @@ -736,39 +587,12 @@ size_t capacity = JSON_ARRAY_SIZE ( SCREEN_WIDTH ) + SCREEN_WIDTH*JSON_OBJECT_SIZE ( 2 ) + JSON_OBJECT_SIZE ( 17 ); static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to be pushed to the web clients - jsonDocument["mType"] = "Settings"; - jsonDocument["mode"] = setting.Mode; + addCommonSettings(jsonDocument); + jsonDocument["dispPoints"] = displayPoints; jsonDocument["start"] = startFreq_IF / 1000.0; jsonDocument["stop"] = stopFreq_IF / 1000.0; - jsonDocument["IF"] = setting.IF_Freq / 1000000.0; - jsonDocument["attenuation"] = setting.Attenuate; - jsonDocument["extGain"] = setting.ExternalGain; jsonDocument["levelOffset"] = setting.LevelOffset; - jsonDocument["filterCal"] = bpfCalibrations[bpfIndex]; - jsonDocument["setRBW"] = setting.Bandwidth10; - jsonDocument["bandwidth"] = bandwidth; - jsonDocument["RefOut"] = setting.ReferenceOut; - jsonDocument["Drive"] = setting.Drive; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["spur"] = setting.Spur; - jsonDocument["tg"] = trackGenSetting.Mode; - jsonDocument["tgPower"] = trackGenSetting.Power; - jsonDocument["tgFreq"] = trackGenSetting.Frequency; - jsonDocument["sg"] = sigGenOutputOn; // - jsonDocument["sgPower"] = sigGenSetting.Power; - jsonDocument["sgMod"] = sigGenSetting.ModulationType; - jsonDocument["sgModFreq"] = sigGenSetting.ModFrequency; - jsonDocument["sgFreq"] = sigGenSetting.Frequency; - jsonDocument["sgCal"] = sigGenSetting.Calibration; - jsonDocument["sgRange"] = ATTENUATOR_RANGE + 11; // SI4432 output can be adjusted over 21dBm but max to SAW filter is 10dBm - jsonDocument["tgCal"] = trackGenSetting.Calibration; - jsonDocument["tgRange"] = ATTENUATOR_RANGE + 21; // no SAW filter so 20dBm output is possible. - - if ( AGC_On ) - jsonDocument["PreAmp"] = 0x60; // Auto - else - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain String wsBuffer; @@ -779,8 +603,6 @@ static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to } else Serial.println ( "No buffer :("); - -// Serial.printf ( "Push Settings sweepPoints %u\n", sweepPoints ); } @@ -793,39 +615,12 @@ size_t capacity = JSON_ARRAY_SIZE ( SCREEN_WIDTH ) + SCREEN_WIDTH*JSON_OBJECT_SIZE ( 2 ) + JSON_OBJECT_SIZE ( 17 ); static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to be pushed to the web clients - jsonDocument["mType"] = "Settings"; - jsonDocument["mode"] = setting.Mode; + addCommonSettings(jsonDocument); + jsonDocument["dispPoints"] = displayPoints; jsonDocument["start"] = startFreq_RX / 1000.0; jsonDocument["stop"] = stopFreq_RX / 1000.0; - jsonDocument["IF"] = setting.IF_Freq / 1000000.0; - jsonDocument["attenuation"] = setting.Attenuate; - jsonDocument["extGain"] = setting.ExternalGain; jsonDocument["levelOffset"] = 0; - jsonDocument["filterCal"] = bpfCalibrations[bpfIndex]; - jsonDocument["setRBW"] = setting.Bandwidth10; - jsonDocument["bandwidth"] = bandwidth; - jsonDocument["RefOut"] = setting.ReferenceOut; - jsonDocument["Drive"] = setting.Drive; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["spur"] = setting.Spur; - jsonDocument["tg"] = trackGenSetting.Mode; - jsonDocument["tgPower"] = trackGenSetting.Power; - jsonDocument["tgFreq"] = trackGenSetting.Frequency; - jsonDocument["sg"] = sigGenOutputOn; // - jsonDocument["sgPower"] = sigGenSetting.Power; - jsonDocument["sgMod"] = sigGenSetting.ModulationType; - jsonDocument["sgModFreq"] = sigGenSetting.ModFrequency; - jsonDocument["sgFreq"] = sigGenSetting.Frequency; - jsonDocument["sgCal"] = sigGenSetting.Calibration; - jsonDocument["sgRange"] = ATTENUATOR_RANGE + 11; // SI4432 output can be adjusted over 21dBm but max to SAW filter is 10dBm - jsonDocument["tgCal"] = trackGenSetting.Calibration; - jsonDocument["tgRange"] = ATTENUATOR_RANGE + 21; // no SAW filter so 20dBm output is possible. - - if ( AGC_On ) - jsonDocument["PreAmp"] = 0x60; // Auto - else - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain String wsBuffer; @@ -836,8 +631,6 @@ static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to } else Serial.println ( "No buffer :("); - -// Serial.printf ( "Push Settings sweepPoints %u\n", sweepPoints ); } @@ -850,39 +643,12 @@ size_t capacity = JSON_ARRAY_SIZE ( SCREEN_WIDTH ) + SCREEN_WIDTH*JSON_OBJECT_SIZE ( 2 ) + JSON_OBJECT_SIZE ( 17 ); static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to be pushed to the web clients - jsonDocument["mType"] = "Settings"; - jsonDocument["mode"] = setting.Mode; + addCommonSettings(jsonDocument); + jsonDocument["dispPoints"] = setting.BandscopePoints; jsonDocument["start"] = setting.BandscopeStart / 1000.0; jsonDocument["stop"] = ( setting.BandscopeStart + setting.BandscopeSpan ) / 1000.0; - jsonDocument["IF"] = setting.IF_Freq / 1000000.0; - jsonDocument["attenuation"] = setting.Attenuate; - jsonDocument["extGain"] = setting.ExternalGain; jsonDocument["levelOffset"] = setting.LevelOffset; - jsonDocument["filterCal"] = bpfCalibrations[bpfIndex]; - jsonDocument["setRBW"] = setting.Bandwidth10; - jsonDocument["bandwidth"] = bandwidth; - jsonDocument["RefOut"] = setting.ReferenceOut; - jsonDocument["Drive"] = setting.Drive; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["spur"] = setting.Spur; - jsonDocument["tg"] = trackGenSetting.Mode; - jsonDocument["tgPower"] = trackGenSetting.Power; - jsonDocument["tgFreq"] = trackGenSetting.Frequency; - jsonDocument["sg"] = sigGenOutputOn; // - jsonDocument["sgPower"] = sigGenSetting.Power; - jsonDocument["sgMod"] = sigGenSetting.ModulationType; - jsonDocument["sgModFreq"] = sigGenSetting.ModFrequency; - jsonDocument["sgFreq"] = sigGenSetting.Frequency; - jsonDocument["sgCal"] = sigGenSetting.Calibration; - jsonDocument["sgRange"] = ATTENUATOR_RANGE + 11; // SI4432 output can be adjusted over 21dBm but max to SAW filter is 10dBm - jsonDocument["tgCal"] = trackGenSetting.Calibration; - jsonDocument["tgRange"] = ATTENUATOR_RANGE + 21; // no SAW filter so 20dBm output is possible. - - if ( AGC_On ) - jsonDocument["PreAmp"] = 0x60; // Auto - else - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain String wsBuffer; @@ -893,8 +659,6 @@ static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to } else Serial.println ( "No buffer :("); - -// Serial.printf ( "Push Settings sweepPoints %u\n", sweepPoints ); } @@ -908,41 +672,12 @@ size_t capacity = JSON_ARRAY_SIZE ( SCREEN_WIDTH ) + SCREEN_WIDTH*JSON_OBJECT_SIZE ( 2 ) + JSON_OBJECT_SIZE ( 17 ); static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to be pushed to the web clients - jsonDocument["mType"] = "Settings"; - jsonDocument["mode"] = setting.Mode; + addCommonSettings(jsonDocument); + jsonDocument["dispPoints"] = displayPoints; jsonDocument["start"] = startFreq_IF / 1000.0; jsonDocument["stop"] = stopFreq_IF / 1000.0; - jsonDocument["IF"] = setting.IF_Freq / 1000000.0; - jsonDocument["attenuation"] = setting.Attenuate; - jsonDocument["extGain"] = setting.ExternalGain; jsonDocument["levelOffset"] = setting.LevelOffset; - jsonDocument["filterCal"] = bpfCalibrations[bpfIndex]; - jsonDocument["setRBW"] = setting.Bandwidth10; - jsonDocument["bandwidth"] = bandwidth; - jsonDocument["RefOut"] = setting.ReferenceOut; - jsonDocument["Drive"] = setting.Drive; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["spur"] = setting.Spur; - jsonDocument["tg"] = trackGenSetting.Mode; - jsonDocument["tgPower"] = trackGenSetting.Power; - jsonDocument["tgMod"] = trackGenSetting.ModulationType; - jsonDocument["tgModFreq"] = trackGenSetting.ModFrequency; - jsonDocument["tgFreq"] = trackGenSetting.Frequency; - jsonDocument["sg"] = sigGenOutputOn; // - jsonDocument["sgPower"] = sigGenSetting.Power; - jsonDocument["sgMod"] = sigGenSetting.ModulationType; - jsonDocument["sgModFreq"] = sigGenSetting.ModFrequency; - jsonDocument["sgFreq"] = sigGenSetting.Frequency; - jsonDocument["sgCal"] = sigGenSetting.Calibration; - jsonDocument["sgRange"] = (ATTENUATOR_RANGE + RX_SI4432_MAX_DRIVE * 3); // SI4432 output can be adjusted over 21dBm but max to SAW filter is 10dBm - jsonDocument["tgCal"] = trackGenSetting.Calibration; - jsonDocument["tgRange"] = ATTENUATOR_RANGE + 21; // no SAW filter so full 20dBm output is possible. - - if ( AGC_On ) - jsonDocument["PreAmp"] = 0x60; // Auto - else - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain String wsBuffer; @@ -953,8 +688,6 @@ static DynamicJsonDocument jsonDocument ( capacity ); // buffer for json data to } else Serial.println ( "No buffer :("); - -// Serial.printf ( "Push Settings sweepPoints %u\n", sweepPoints ); } @@ -1027,93 +760,6 @@ void onDoReboot ( AsyncWebServerRequest *request ) } -/* - * Function sets the sweep parameters based on the data in the form posted by the web page - * No longer used - */ - -// doSetSweep ? setStart = 10 & setStop = 20 & setExtGain = 0 & setRBW = 26 - -//void onSetSweep ( AsyncWebServerRequest *request ) -//{ -// -// Serial.print ( request->url ()); // Get the paramaters passed from the -// Serial.print ( ":-" ); // web page, checking they exist -// -// if ( request->hasParam ( "setStart" )) -// { -// Serial.print ( "setStart;" ); -// AsyncWebParameter* startInput = request->getParam ( "setStart" ); -// SetSweepStart ( atof ( startInput->value().c_str()) * 1000000.0 ); -// } -// -// if ( request->hasParam ( "setStop" )) -// { -// Serial.print ( "setStop;" ); -// AsyncWebParameter* stopInput = request->getParam ( "setStop" ); -// SetSweepStop( atof ( stopInput->value().c_str()) * 1000000.0 ); -// } -// -// if ( request->hasParam ( "setExtGain" )) -// { -// Serial.print ( "setExtGain;" ); -// AsyncWebParameter* extGainInput = request->getParam ( "setExtGain" ); -//// Need to add function later -// } -// -// if ( request->hasParam ( "refOut" )) -// { -// Serial.print ( "refOut;" ); -// AsyncWebParameter* setRefOut = request->getParam ( "setRefOut" ); -// setting.ReferenceOut = atoi ( setRefOut->value().c_str() ); -// xmit.SetPowerReference ( setting.ReferenceOut ); -// } -// -// if ( request->hasParam ( "setAtten" )) -// { -// Serial.print ( "setAtten:" ); -// AsyncWebParameter* setAtten = request->getParam ( "setAtten"); -// SetAttenuation ( atoi ( setAtten->value().c_str() )); -// Serial.print ( atoi ( setAtten->value().c_str() )); -// Serial.print ( "; " ); -// } -// -// if ( request->hasParam ( "setRBW" )) -// { -// Serial.print ( "setRBW "); -// AsyncWebParameter* rbwInput = request->getParam ( "setRBW" ); -// SetRBW ( atoi ( rbwInput->value().c_str() )); -// Serial.printf ( "setting.bandwidth = %i, input = %i;", setting.Bandwidth10, atoi ( rbwInput->value().c_str() )); -// } -// -// Serial.println (); -// request->redirect ( "index.html" ); // redirect to the index page -//} -// -// -///* -// * Function sets the sweep parameters based on the data in the form posted by the web page -// * No longer used -// */ -// -//// doSetSweep ? setStart = 10 &setStop = 20 & setExtGain = 0 & setRBW = 26 -// -//void onSettings ( AsyncWebServerRequest *request ) -//{ -// Serial.print ( request->url() ); // Get the paramaters passed from the web -// Serial.print ( ":-" ); // page, checking they exist -// -// if ( request->hasParam ( "setActPower" )) -// { -// Serial.print ( "setActPower;" ); -// AsyncWebParameter* setLevelInput = request->getParam ( "setActPower" ); -// SetPowerLevel ( atof ( setLevelInput->value().c_str()) ); -// } -// -// Serial.println(); -// request->redirect ( "index.html"); // Redirect to the index page -//} - void onGetNameVersion ( AsyncWebServerRequest *request ) { @@ -1123,8 +769,8 @@ void onGetNameVersion ( AsyncWebServerRequest *request ) response->printf ( "printf ( "Name=\"%s\" ",PROGRAM_NAME ); - response->printf ( "Version=\"V%s\" ",PROGRAM_VERSION ); - response->printf ( "Copyright=\"PD0EK\"" ); + response->printf ( "Version=\"%s\" ",PROGRAM_VERSION ); + response->printf ( "Copyright=\"M0WID\"" ); response->printf ( "/>" ); @@ -1176,17 +822,11 @@ void buildServer () // We can now configure and start the server { Serial.println ( "Building Server.." ); server.reset (); // Clear any existing settings and events -// server.on ( "/getSweep", HTTP_GET, onGetSweep ); // Set event to return sweep data as JSON array -// server.on ( "/getGainSweep", HTTP_GET, onGetGainSweep ); // Set event to return sweep gain data as JSON array -// server.on ( "/getSettings", HTTP_GET, onGetSettings ); // Set event to return settings data as JSON array -// server.on ( "/doSetSweep", HTTP_POST, onSetSweep ); // Set event to set sweep values received from client - server.on ( "/doReboot", HTTP_GET, onDoReboot ); // Set event to reboot the ESP32 - server.on ( "/getNameVersion", HTTP_GET, onGetNameVersion );// Set event to return name and version -// server.on ( "/getScan", HTTP_GET, onGetScan ); // Set event to return sweep data as XML server.on ( "/getRbwList", HTTP_GET, onGetRbwList ); // Set event to return RBW options as JSON array server.on ( "/getAttenList", HTTP_GET, onGetAttenList ); // Set event to return attenuator options as JSON array server.on ( "/getSSIDs", HTTP_GET, onGetSIDDs ); // Set event to return list of SSID as XML -// server.on ( "/doSettings", HTTP_POST, onSettings ); // Set event to set setting values received from client + server.on ( "/getNameVersion", HTTP_GET, onGetNameVersion );// Set event to return name and version + server.on ( "/doReboot", HTTP_GET, onDoReboot ); // Set event to reboot the ESP32 server.serveStatic ( "/", SPIFFS, "/" ).setDefaultFile ( "index.html" ); diff --git a/ui.cpp b/ui.cpp index dfdab2d..693849f 100644 --- a/ui.cpp +++ b/ui.cpp @@ -277,6 +277,7 @@ static void menu_scale_cb ( int item ); static void menu_sweep_cb ( int item ); static void menu_IF_sweep_cb ( int item ); // M0WID added 3.0c static void menu_RX_sweep_cb ( int item ); +static void menu_bpfCal_cb ( int item ); static void menu_recall_cb ( int item ); static void menu_version_cb (int item ); static void menu_generate_cb(int item); // WA2FZW - Added in M0WID's Version 05 @@ -757,6 +758,7 @@ static Menuitem menu_RXsweep_top[] = // This is the main "IF_SWEEP" menu Menuitem ( MT_FUNC, "\2SWEEP\0SIG", menu_RX_sweep_cb ), Menuitem ( MT_FUNC, "RBW", menu_RX_sweep_cb ), Menuitem ( MT_MENU, "REFERENCE", menu_refer ), // Select GPIO2 reference frequency + Menuitem ( MT_FUNC, "\2BPF\0CAL", menu_bpfCal_cb ), Menuitem ( MT_END ) // End marker }; @@ -1493,7 +1495,6 @@ static void menu_autosettings_cb ( int item ) SetRefLevel ( AUTO_REF_LEVEL ); SetRefOutput ( AUTO_REF_OUTPUT ); SetAttenuation ( AUTO_ATTEN ); -// SetPowerLevel ( 100 ); // Removed - Screws up calibration SetRBW ( AUTO_RBW ); // Auto mode SetRX ( 0 ); setting.ShowGain = 1; // Gain trace on @@ -1827,6 +1828,13 @@ static void menu_RX_sweep_cb ( int item ) ui_process_keypad (); } + +static void menu_bpfCal_cb ( int item ) +{ + StartBpfCal (); + ui_mode_normal(); +} + static void menu_extern_cb ( int item ) { int km = KM_EXTERN;