websocketServer: added sentence_cmd option

pull/6/head
Michal Fratczak 2018-11-08 00:38:22 +01:00
rodzic 6be2d4d589
commit 9c7a7b29a2
3 zmienionych plików z 28 dodań i 12 usunięć

Wyświetl plik

@ -82,6 +82,7 @@ public:
float rtty_ascii_stops_ = 2;
bool live_print_ = true;
bool afc_ = false;
std::string sentence_cmd_ = "";
static bool DumpToFile(std::string fName)
{
@ -102,6 +103,7 @@ public:
oFile<<"rtty = "<<GLOBALS::get().rtty_ascii_bits_<<endl;
oFile<<"rtty = "<<GLOBALS::get().rtty_ascii_stops_<<endl;
oFile<<"afc = "<<GLOBALS::get().afc_<<endl;
oFile<<"sentence_cmd = "<<GLOBALS::get().sentence_cmd_<<endl;
}
catch (exception& e) {
cout<<"Can't save config "<<fName<<endl;

Wyświetl plik

@ -232,17 +232,11 @@ void DECODER_FEED_THREAD()
}
}
void HAB_UPLOAD_THREAD()
void LOG_THREAD()
{
using namespace std;
using namespace habdec;
if(GLOBALS::get().station_callsign_ == "")
{
cout<<C_RED<<"No --station parameter set. HAB Upload disabled."<<C_OFF<<endl;
return;
}
while(!G_DO_EXIT)
{
this_thread::sleep_for( chrono::duration<double, milli>(500) );
@ -255,9 +249,19 @@ void HAB_UPLOAD_THREAD()
for(auto& sentence : sentences)
{
string res = HabitatUploadSentence( sentence, GLOBALS::get().station_callsign_ );
if( res != "OK" )
cout<<C_CLEAR<<"HAB Upload result: "<<res<<endl;
if(GLOBALS::get().station_callsign_ != "")
{
string res = HabitatUploadSentence( sentence, GLOBALS::get().station_callsign_ );
if( res != "OK" )
cout<<C_CLEAR<<C_RED<<"HAB Upload result: "<<res<<endl;
}
if( GLOBALS::get().sentence_cmd_ != "" )
{
int res = system( (GLOBALS::get().sentence_cmd_ + " " + sentence).c_str() );
if(res)
cout<<C_CLEAR<<C_RED<<"sentence_cmd result: "<<res<<endl;
}
}
}
}
@ -304,6 +308,9 @@ int main(int argc, char** argv)
DECODER.lowpass_trans(.0025);
DECODER.livePrint( GLOBALS::get().live_print_ );
if(GLOBALS::get().station_callsign_ == "")
cout<<C_RED<<"No --station parameter set. HAB Upload disabled."<<C_OFF<<endl;
// for every decoded message
// put it on two ques: websocket upload, HAB upload
DECODER.success_callback_ =
@ -324,14 +331,14 @@ int main(int argc, char** argv)
std::thread* decoder_feed_thread = new std::thread(DECODER_FEED_THREAD);
// HAB upload
std::thread* hab_upload_thread = new std::thread(HAB_UPLOAD_THREAD);
std::thread* log_thread = new std::thread(LOG_THREAD);
// websocket server thread. this call is blocking
RunCommandServer( GLOBALS::get().command_host_ , GLOBALS::get().command_port_ );
G_DO_EXIT = true;
decoder_feed_thread->join();
hab_upload_thread->join();
log_thread->join();
return 0;
}

Wyświetl plik

@ -52,6 +52,8 @@ void prog_opts(int ac, char* av[])
("biast", po::value<bool>(), "biasT, values: 0, 1")
("bias_t", po::value<bool>(), "biasT, values: 0, 1")
("afc", po::value<bool>(), "Auto Frequency Correction, values: 0, 1")
("sentence_cmd", po::value<string>(), "call external command with sentence as parameter")
;
po::options_description cli_options("Command Line Interface options");
@ -120,6 +122,10 @@ void prog_opts(int ac, char* av[])
{
GLOBALS::get().station_callsign_ = vm["station"].as<string>();
}
if (vm.count("sentence_cmd"))
{
GLOBALS::get().sentence_cmd_ = vm["sentence_cmd"].as<string>();
}
if (vm.count("freq"))
{
GLOBALS::get().frequency_ = vm["freq"].as<float>() * 1e6;
@ -180,6 +186,7 @@ void prog_opts(int ac, char* av[])
cout<<"\tsampling_rate: "<<GLOBALS::get().sampling_rate_<<endl;
cout<<"\tcommand_host: "<<GLOBALS::get().command_host_<<endl;
cout<<"\tcommand_port: "<<GLOBALS::get().command_port_<<endl;
cout<<"\tsentence_cmd: "<<GLOBALS::get().sentence_cmd_<<endl;
cout<<"\tstation: "<<GLOBALS::get().station_callsign_<<endl;
cout<<"\tfreq: "<<GLOBALS::get().frequency_<<endl;
cout<<"\tgain: "<<GLOBALS::get().gain_<<endl;