Recon event nothread (#984)

* deleted unreliable Thread system and use exclusively the statistics events instead
* reducing used variables, reducing number of functions, revamped main drawing and locking system
* max speed is fixed at a maximum of 10 scans/secs due to statistics not coming quicker than that
This commit is contained in:
gullradriel 2023-05-14 21:20:10 +02:00 committed by GitHub
parent 9ce2f3fdea
commit a27881ecd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1540 additions and 2015 deletions

File diff suppressed because it is too large Load Diff

View File

@ -38,87 +38,10 @@
#include "string_format.hpp"
#include "file.hpp"
#include "app_settings.hpp"
// maximum usable freq
#define MAX_UFREQ 7200000000
// 1Mhz helper
#ifdef OneMHz
#undef OneMHz
#endif
#define OneMHz 1000000
#include "ui_recon_settings.hpp"
namespace ui {
class ReconThread {
public:
ReconThread(freqman_db *database );
~ReconThread();
void set_recon(const bool v);
void set_freq_delete(const bool v);
bool is_recon();
void set_lock_duration( const uint32_t v );
uint32_t get_lock_duration();
void set_lock_nb_match( const uint32_t v );
void set_match_mode( const uint32_t v );
uint32_t get_lock_nb_match();
void set_freq_lock(const int32_t v);
int32_t is_freq_lock();
int64_t get_current_freq();
void set_stepper(const int64_t v);
void set_index_stepper(const int64_t v);
void change_recon_direction();
bool get_recon_direction();
void set_recon_direction( const bool v);
void set_continuous(const bool v);
void set_default_modulation( freqman_index_t index );
freqman_index_t get_current_modulation();
void set_default_bandwidth( freqman_index_t index );
freqman_index_t get_current_bandwidth();
void set_default_step( freqman_index_t index );
void set_freq_index( int16_t index );
int16_t get_freq_index();
void run();
void stop();
ReconThread(const ReconThread&) = delete;
ReconThread(ReconThread&&) = delete;
ReconThread& operator=(const ReconThread&) = delete;
ReconThread& operator=(ReconThread&&) = delete;
private:
freqman_db &frequency_list_ ;
Thread* thread { nullptr };
int64_t freq = 0 ;
uint32_t step = 0 ;
freqman_index_t def_modulation = 0 ;
freqman_index_t def_bandwidth = 0 ;
freqman_index_t def_step = 0 ;
tone_index tone = 0 ;
freqman_entry last_entry = { } ;
int16_t frequency_index = 0 ;
bool _recon { true };
bool _freq_delete { false };
bool _fwd { true };
bool _continuous { true };
bool entry_has_changed = false ;
int64_t _stepper { 0 };
int64_t _index_stepper { 0 };
int32_t _freq_lock { 0 };
uint32_t _lock_duration { 50 };
uint32_t _lock_nb_match { 10 };
static msg_t static_fn(void* arg);
};
class ReconView : public View {
public:
ReconView(NavigationView& nav);
@ -169,30 +92,28 @@ namespace ui {
private:
NavigationView& nav_;
void start_recon_thread();
void audio_output_start();
bool check_sd_card();
size_t change_mode( freqman_index_t mod_type);
void show_max( bool refresh_display = false );
void recon_pause();
void recon_resume();
void user_pause();
void user_resume();
void frequency_file_load( bool stop_all_before = false);
void on_statistics_update(const ChannelStatistics& statistics);
void on_headphone_volume_changed(int32_t v);
void set_display_freq( int64_t freq );
void handle_retune( int64_t freq , uint32_t index );
bool check_sd_card();
void on_index_delta(int32_t v);
void on_stepper_delta(int32_t v);
void recon_redraw();
void handle_retune();
void handle_coded_squelch(const uint32_t value);
jammer::jammer_range_t frequency_range { false, 0, MAX_UFREQ }; //perfect for manual recon task too...
int32_t squelch { 0 };
int32_t db { 0 };
int32_t timer { 0 };
int32_t wait { 1000 }; // in msec. if > 0 wait duration after a lock, if < 0 duration is set to 'wait' unless there is no more activity
uint32_t lock_wait { 1000 }; // in msec. Represent the maximum amount of time we will wait for a lock to complete before switching to next
int32_t def_step { 0 };
int32_t wait { RECON_DEF_WAIT_DURATION }; // in msec. if > 0 wait duration after a lock, if < 0 duration is set to 'wait' unless there is no more activity
freqman_db frequency_list = { };
uint32_t current_index { 0 };
int32_t current_index { 0 };
bool userpause { false };
bool continuous_lock { false };
std::string input_file = { "RECON" };
@ -206,13 +127,28 @@ namespace ui {
bool load_hamradios = { true };
bool update_ranges = { true };
bool fwd = { true };
bool recon = true ;
uint32_t recon_lock_nb_match = { 3 };
uint32_t recon_lock_duration = { 50 };
uint32_t recon_match_mode = { 0 };
uint32_t recon_lock_duration = { RECON_DEF_LOCK_DURATION };
uint32_t recon_match_mode = { RECON_MATCH_CONTINUOUS };
bool scanner_mode { false };
bool manual_mode { false };
bool sd_card_mounted = false ;
int32_t volume = 40 ;
int32_t stepper = 0 ;
int32_t index_stepper = 0 ;
int64_t freq = 0 ;
uint32_t step = 0 ;
freqman_index_t def_modulation = 0 ;
freqman_index_t def_bandwidth = 0 ;
freqman_index_t def_step = 0 ;
tone_index tone = 0 ;
freqman_entry last_entry = { } ;
bool entry_has_changed = false ;
uint32_t freq_lock { 0 };
int64_t minfreq = 0 ;
int64_t maxfreq = 0 ;
bool has_looped = false ;
Labels labels
{
@ -260,21 +196,21 @@ namespace ui {
NumberField field_wait {
{ 20 * 8, 1 * 16 },
5,
{ -9000, 9000 },
100,
{ -(10000-STATS_UPDATE_INTERVAL) , (10000-STATS_UPDATE_INTERVAL) },
STATS_UPDATE_INTERVAL,
' ',
};
NumberField field_lock_wait {
{ 26 * 8, 1 * 16 },
4,
{ 100 , 9000 },
100,
{ RECON_DEF_LOCK_DURATION , (10000-RECON_DEF_LOCK_DURATION) },
RECON_DEF_LOCK_DURATION,
' ',
};
RSSI rssi {
{ 0 * 16, 2 * 16, 240 - 8 * 8 + 4 , 16 },
{ 0 * 16, 2 * 16, SCREEN_W - 8 * 8 + 4 , 16 },
};
ButtonWithEncoder text_cycle {
@ -283,11 +219,11 @@ namespace ui {
};
Text text_max {
{ 4 * 8, 3 * 16, 240 - 7 * 8 - 4 * 8 , 16 },
{ 4 * 8, 3 * 16, SCREEN_W - 7 * 8 - 4 * 8 , 16 },
};
Text desc_cycle {
{0, 4 * 16, 240 , 16 },
{0, 4 * 16, SCREEN_W , 16 },
};
/* BigFrequency big_display { //Show frequency in glamour
@ -315,23 +251,23 @@ namespace ui {
};
Button button_recon_setup {
{ 240 - 7 * 8 , 2 * 16 , 7 * 8, 28 },
{ SCREEN_W - 7 * 8 , 2 * 16 , 7 * 8, 28 },
"CONFIG"
};
Button button_looking_glass {
{ 240 - 7 * 8 , 5 * 16 , 7 * 8, 28 },
{ SCREEN_W - 7 * 8 , 5 * 16 , 7 * 8, 28 },
"GLASS"
};
// Button can be RECON or SCANNER
Button button_scanner_mode {
{ 240 - 7 * 8 , 8 * 16 , 7 * 8, 28 },
{ SCREEN_W - 7 * 8 , 8 * 16 , 7 * 8, 28 },
"RECON"
};
Text file_name { //Show file used
{ 0 , 8 * 16 + 6 , 240 - 7 * 8, 16 },
{ 0 , 8 * 16 + 6 , SCREEN_W - 7 * 8, 16 },
};
ButtonWithEncoder button_manual_start {
@ -400,8 +336,6 @@ namespace ui {
"<REMOVE>"
};
std::unique_ptr<ReconThread> recon_thread { };
MessageHandlerRegistration message_handler_coded_squelch {
Message::ID::CodedSquelch,
[this](const Message* const p) {
@ -410,14 +344,6 @@ namespace ui {
}
};
MessageHandlerRegistration message_handler_retune {
Message::ID::Retune,
[this](const Message* const p) {
const auto message = *reinterpret_cast<const RetuneMessage*>(p);
this->handle_retune(message.freq,message.range);
}
};
MessageHandlerRegistration message_handler_stats {
Message::ID::ChannelStatistics,
[this](const Message* const p) {

View File

@ -34,7 +34,7 @@ using namespace portapack;
namespace ui {
bool ReconSetupLoadStrings( std::string source, std::string &input_file , std::string &output_file , uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , int32_t &recon_squelch_level , uint32_t &recon_match_mode , int32_t &wait , uint32_t &lock_wait , int32_t &volume )
bool ReconSetupLoadStrings( std::string source, std::string &input_file , std::string &output_file , uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , int32_t &recon_squelch_level , uint32_t &recon_match_mode , int32_t &wait , int32_t &volume )
{
File settings_file;
size_t length, file_position = 0;
@ -44,8 +44,8 @@ namespace ui {
char file_data[257];
uint32_t it = 0 ;
uint32_t nb_params = 9 ;
std::string params[ 9 ];
uint32_t nb_params = RECON_SETTINGS_NB_PARAMS ;
std::string params[ RECON_SETTINGS_NB_PARAMS ];
bool check_sd_card = (sd_card::status() == sd_card::Status::Mounted) ? true : false ;
@ -91,12 +91,11 @@ namespace ui {
/* bad number of params, signal defaults */
input_file = "RECON" ;
output_file = "RECON_RESULTS" ;
recon_lock_duration = 50 ;
recon_lock_nb_match = 3 ;
recon_lock_duration = RECON_DEF_LOCK_DURATION ;
recon_lock_nb_match = RECON_DEF_NB_MATCH ;
recon_squelch_level = -14 ;
recon_match_mode = 0 ;
wait = 1000 ;
lock_wait = 1000 ;
recon_match_mode = RECON_MATCH_CONTINUOUS ;
wait = RECON_DEF_WAIT_DURATION ;
volume = 40 ;
return false ;
}
@ -114,12 +113,12 @@ namespace ui {
if( it > 2 )
recon_lock_duration = strtoll( params[ 2 ].c_str() , nullptr , 10 );
else
recon_lock_duration = 50 ;
recon_lock_duration = RECON_DEF_LOCK_DURATION ;
if( it > 3 )
recon_lock_nb_match = strtoll( params[ 3 ].c_str() , nullptr , 10 );
else
recon_lock_nb_match = 3 ;
recon_lock_nb_match = RECON_DEF_NB_MATCH ;
if( it > 4 )
recon_squelch_level = strtoll( params[ 4 ].c_str() , nullptr , 10 );
@ -129,17 +128,12 @@ namespace ui {
if( it > 5 )
recon_match_mode = strtoll( params[ 5 ].c_str() , nullptr , 10 );
else
recon_match_mode = 0 ;
recon_match_mode = RECON_MATCH_CONTINUOUS ;
if( it > 6 )
wait = strtoll( params[ 6 ].c_str() , nullptr , 10 );
else
wait = 1000 ;
if( it > 7 )
lock_wait = strtoll( params[ 7 ].c_str() , nullptr , 10 );
else
lock_wait = 1000 ;
wait = RECON_DEF_WAIT_DURATION ;
if( it > 8 )
volume = strtoll( params[ 8 ].c_str() , nullptr , 10 );
@ -149,7 +143,7 @@ namespace ui {
return true ;
}
bool ReconSetupSaveStrings( std::string dest, std::string input_file , std::string output_file , uint32_t recon_lock_duration , uint32_t recon_lock_nb_match , int32_t recon_squelch_level , uint32_t recon_match_mode , int32_t wait , uint32_t lock_wait , int32_t volume )
bool ReconSetupSaveStrings( std::string dest, std::string input_file , std::string output_file , uint32_t recon_lock_duration , uint32_t recon_lock_nb_match , int32_t recon_squelch_level , uint32_t recon_match_mode , int32_t wait , int32_t volume )
{
File settings_file;
@ -163,7 +157,6 @@ namespace ui {
settings_file.write_line( to_string_dec_int( recon_squelch_level ) );
settings_file.write_line( to_string_dec_uint( recon_match_mode ) );
settings_file.write_line( to_string_dec_int( wait ) );
settings_file.write_line( to_string_dec_uint( lock_wait ) );
settings_file.write_line( to_string_dec_int( volume ) );
return true ;
}

View File

@ -20,6 +20,9 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef _UI_RECON_SETTINGS
#define _UI_RECON_SETTINGS
#include "serializer.hpp"
#include "ui.hpp"
#include "ui_widget.hpp"
@ -27,10 +30,38 @@
#include "ui_navigation.hpp"
#include "string_format.hpp"
// maximum usable freq
#define MAX_UFREQ 7200000000
// 1Mhz helper
#ifdef OneMHz
#undef OneMHz
#endif
#define OneMHz 1000000
// modes
#define RECON_MATCH_CONTINUOUS 0
#define RECON_MATCH_SPARSE 1
// statistics update interval (change here if it's evolving) in ms
#define STATS_UPDATE_INTERVAL 100
// default number of match to have a lock
#define RECON_DEF_NB_MATCH 3
#define RECON_DEF_LOCK_DURATION 100 // have to be >= and a multiple of STATS_UPDATE_INTERVAL
#define RECON_DEF_WAIT_DURATION 1000 // will be incremented/decremented by STATS_UPDATE_INTERVAL steps
// screen size helper
#define SCREEN_W 240
//#define SCREEN_H 320
// recon settings nb params
#define RECON_SETTINGS_NB_PARAMS 8
namespace ui {
bool ReconSetupLoadStrings( std::string source, std::string &input_file , std::string &output_file , uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , int32_t &recon_squelch_level , uint32_t &recon_match_mode , int32_t &wait , uint32_t &lock_wait , int32_t &volume );
bool ReconSetupSaveStrings( std::string dest, const std::string input_file , const std::string output_file , const uint32_t recon_lock_duration , const uint32_t recon_lock_nb_match , int32_t recon_squelch_level , uint32_t recon_match_mode , int32_t wait , uint32_t lock_wait , int32_t volume );
bool ReconSetupLoadStrings( std::string source, std::string &input_file , std::string &output_file , uint32_t &recon_lock_duration , uint32_t &recon_lock_nb_match , int32_t &recon_squelch_level , uint32_t &recon_match_mode , int32_t &wait , int32_t &volume );
bool ReconSetupSaveStrings( std::string dest, const std::string input_file , const std::string output_file , const uint32_t recon_lock_duration , const uint32_t recon_lock_nb_match , int32_t recon_squelch_level , uint32_t recon_match_mode , int32_t wait , int32_t volume );
class ReconSetupViewMain : public View {
public:
@ -94,9 +125,9 @@ namespace ui {
private:
const uint32_t _recon_lock_duration = 50 ;
const uint32_t _recon_lock_nb_match = 10 ;
const uint32_t _recon_match_mode = 0 ;
const uint32_t _recon_lock_duration = STATS_UPDATE_INTERVAL ;
const uint32_t _recon_lock_nb_match = RECON_DEF_NB_MATCH ;
const uint32_t _recon_match_mode = RECON_MATCH_CONTINUOUS ;
Checkbox checkbox_load_freqs {
{ 1 * 8, 12 },
@ -128,8 +159,8 @@ namespace ui {
NumberField field_recon_lock_duration {
{ 1 * 8, 132 }, // position X , Y
4, // number of displayed digits (even empty)
{ 50 , 990 }, // range of number
10, // rotary encoder increment
{ STATS_UPDATE_INTERVAL , 10000-STATS_UPDATE_INTERVAL }, // range of number
STATS_UPDATE_INTERVAL, // rotary encoder increment
' ', // filling character
false // can loop
};
@ -172,11 +203,11 @@ namespace ui {
std::string input_file = { "RECON" };
std::string output_file = { "RECON_RESULTS" };
uint32_t recon_lock_duration = 50 ;
uint32_t recon_lock_nb_match = 10 ;
uint32_t recon_match_mode = 0 ;
uint32_t recon_lock_duration = STATS_UPDATE_INTERVAL ;
uint32_t recon_lock_nb_match = RECON_DEF_NB_MATCH ;
uint32_t recon_match_mode = RECON_MATCH_CONTINUOUS ;
Rect view_rect = { 0, 3 * 8, 240, 230 };
Rect view_rect = { 0, 3 * 8, SCREEN_W, 230 };
ReconSetupViewMain viewMain{ nav_ , view_rect , input_file , output_file };
ReconSetupViewMore viewMore{ nav_ , view_rect , recon_lock_duration , recon_lock_nb_match , recon_match_mode };
@ -192,3 +223,5 @@ namespace ui {
};
} /* namespace ui */
#endif