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/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 ( "