diff --git a/Bandscope.ino b/Bandscope.ino index 3054841..2f952dc 100644 --- a/Bandscope.ino +++ b/Bandscope.ino @@ -237,14 +237,8 @@ static uint16_t chunkIndex; if ( numberOfWebsocketClients > 0 ) // Start off the json document for the scan { - jsonDocument.clear (); chunkIndex = 0; - - jsonDocument["PreAmp"] = setting.PreampGain; - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = 0; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); + initChunkSweepDoc (autoSweepStep); Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } @@ -395,12 +389,8 @@ static uint16_t chunkIndex; if ( ( chunkIndex >= wiFiPoints ) || !jsonDocInitialised ) // Start new jSon document { chunkIndex = 0; - jsonDocument.clear(); - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = autoSweepStep; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); - Points = jsonDocument.createNestedArray ("Points" ); // Add Points array + initChunkSweepDoc (autoSweepStep); + Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } } diff --git a/IFsweep.ino b/IFsweep.ino index f91d843..c8e003e 100644 --- a/IFsweep.ino +++ b/IFsweep.ino @@ -120,6 +120,7 @@ static uint16_t chunkIndex; } // initSweep || changedSetting autoSweepStep = 0; // Set the step counter to zero + sweepStep = 0; autoSweepFreq = startFreq_IF; // Set the start frequency. nextPointFreq = autoSweepFreq + autoSweepFreqStep; @@ -142,24 +143,16 @@ static uint16_t chunkIndex; if ( numberOfWebsocketClients > 0 ) // Start off the json document for the scan { - jsonDocument.clear (); chunkIndex = 0; - - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = 0; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); + initChunkSweepDoc (sweepStep); Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } - else jsonDocInitialised = false; #endif // #ifdef USE_WIFI - sweepStep = 0; startFreq = startFreq_IF + sigFreq_IF; // Start freq for the LO stopFreq = stopFreq_IF + sigFreq_IF; // Stop freq for the LO @@ -315,12 +308,8 @@ static uint16_t chunkIndex; if ( ( chunkIndex >= wiFiPoints ) || !jsonDocInitialised ) // Start new jSon document { chunkIndex = 0; - jsonDocument.clear(); - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = sweepStep; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); - Points = jsonDocument.createNestedArray ("Points" ); // Add Points array + initChunkSweepDoc (sweepStep); + Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } } diff --git a/RXsweep.ino b/RXsweep.ino index 0116113..608639e 100644 --- a/RXsweep.ino +++ b/RXsweep.ino @@ -126,6 +126,7 @@ static uint16_t chunkIndex; } // initSweep || changedSetting autoSweepStep = 0; // Set the step counter to zero + sweepStep = 0; autoSweepFreq = startFreq_RX; // Set the start frequency. nextPointFreq = autoSweepFreq + autoSweepFreqStep; @@ -148,24 +149,16 @@ static uint16_t chunkIndex; if ( numberOfWebsocketClients > 0 ) // Start off the json document for the scan { - jsonDocument.clear (); chunkIndex = 0; - - jsonDocument["PreAmp"] = setting.PreampGain; - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = 0; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); + initChunkSweepDoc (sweepStep); Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } - else jsonDocInitialised = false; #endif // #ifdef USE_WIFI - sweepStep = 0; startFreq = startFreq_RX; // Start freq for the RX stopFreq = stopFreq_RX; // Stop freq for the RX @@ -322,12 +315,8 @@ static uint16_t chunkIndex; if ( ( chunkIndex >= wiFiPoints ) || !jsonDocInitialised ) // Start new jSon document { chunkIndex = 0; - jsonDocument.clear(); - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = sweepStep; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); - Points = jsonDocument.createNestedArray ("Points" ); // Add Points array + initChunkSweepDoc (sweepStep); + Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } } diff --git a/SweepLo.ino b/SweepLo.ino index feee8b2..6fc658a 100644 --- a/SweepLo.ino +++ b/SweepLo.ino @@ -185,6 +185,7 @@ static uint32_t offsetIF; // IF frequency offset by half the bandwidth to pos } // initSweep || changedSetting autoSweepStep = 0; // Set the step counter to zero + sweepStep = 0; autoSweepFreq = setting.ScanStart; // Set the start frequency. nextPointFreq = autoSweepFreq + autoSweepFreqStep; @@ -253,22 +254,15 @@ static uint32_t offsetIF; // IF frequency offset by half the bandwidth to pos { jsonDocument.clear (); chunkIndex = 0; - - jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = 0; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); + initChunkSweepDoc (sweepStep); Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } - else jsonDocInitialised = false; #endif // #ifdef USE_WIFI - sweepStep = 0; startFreq = setting.ScanStart + tempIF; // Start freq for the LO stopFreq = setting.ScanStop + tempIF; // Stop freq for the LO @@ -454,12 +448,8 @@ static uint32_t offsetIF; // IF frequency offset by half the bandwidth to pos if ( ( chunkIndex >= wiFiPoints ) || !jsonDocInitialised ) // Start new jSon document { chunkIndex = 0; - jsonDocument.clear(); - jsonDocument["mType"] = "chunkSweep"; - jsonDocument["StartIndex"] = sweepStep; - jsonDocument["sweepPoints"] = sweepPoints; - jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); - Points = jsonDocument.createNestedArray ("Points" ); // Add Points array + initChunkSweepDoc (sweepStep); + Points = jsonDocument.createNestedArray ( "Points" ); // Add Points array jsonDocInitialised = true; } } diff --git a/simpleSA.ino b/simpleSA.ino index 8ab6329..2294603 100644 --- a/simpleSA.ino +++ b/simpleSA.ino @@ -352,10 +352,10 @@ uint16_t websocketFailCount; #ifdef USE_WIFI // Json document buffers -size_t capacity = JSON_ARRAY_SIZE ( MAX_WIFI_POINTS + 1 ) - + ( MAX_WIFI_POINTS + 1 ) * JSON_OBJECT_SIZE ( 2 ) + JSON_OBJECT_SIZE( 5 ); +//size_t capacity = JSON_ARRAY_SIZE ( MAX_WIFI_POINTS + 1 ) +// + ( MAX_WIFI_POINTS + 1 ) * JSON_OBJECT_SIZE ( 2 ) + JSON_OBJECT_SIZE( 5 ); -static DynamicJsonDocument jsonDocument ( capacity ); // Buffer for json data to be pushed to the web clients +static DynamicJsonDocument jsonDocument ( 4000 ); // Buffer for json data to be pushed to the web clients static JsonArray Points = jsonDocument.createNestedArray ( "Points" ); // add Points array #endif @@ -1114,6 +1114,21 @@ void init_sweep() } +/* + * Initialise the JSON document that is used to push the sweep data to the web clients + * Used in all the sweep modes + */ +void initChunkSweepDoc (uint32_t startIndex) +{ + jsonDocument.clear (); + jsonDocument["PreAmp"] = setting.PreampGain; // Fixed gain + jsonDocument["mType"] = "chunkSweep"; + jsonDocument["StartIndex"] = startIndex; + jsonDocument["sweepPoints"] = sweepPoints; + jsonDocument["sweepTime"] = (uint32_t)(sweepMicros/1000); +} + + /* * Initialise high frequency mode sweep. diff --git a/simpleSA_wifi.cpp b/simpleSA_wifi.cpp index 5fd0ac8..7507240 100644 --- a/simpleSA_wifi.cpp +++ b/simpleSA_wifi.cpp @@ -33,6 +33,8 @@ extern uint16_t displayPoints; extern uint16_t xDelta; extern uint16_t waterfallHeight; +extern unsigned long sweepMicros; // To report the scan time + extern int bpfCount; // Number of elements in the bandpassFilters array extern int updateSidebar; // Flag to indicate no of clients has changed diff --git a/simpleSA_wifi.h b/simpleSA_wifi.h index c31a672..a0acc22 100644 --- a/simpleSA_wifi.h +++ b/simpleSA_wifi.h @@ -51,6 +51,7 @@ void pushIFSweepSettings (); void pushRXSweepSettings (); void pushBandscopeSettings (); + void initChunkSweepDoc (uint32_t startIndex); /* * Functions outside of "TinySA_wifi: