From: drowe67 Date: Mon, 9 Jun 2014 10:45:59 +0000 (+0000) Subject: event processing starting to come together, issuing system commands and logging events X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=20a3d247c831ed8fe713e92a5c1b667f3acc152d;p=freetel-svn-tracking.git event processing starting to come together, issuing system commands and logging events git-svn-id: https://svn.code.sf.net/p/freetel/code@1642 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/src/Makefile.linux b/fdmdv2/src/Makefile.linux index f49e9e2a..632f146d 100644 --- a/fdmdv2/src/Makefile.linux +++ b/fdmdv2/src/Makefile.linux @@ -54,7 +54,7 @@ endif CODEC2=codec2 CODEC2_INC=-I$(CODEC2)/src -CODEC2_LIB=$(CODEC2)/src/.libs/libcodec2.a +CODEC2_LIB=$(CODEC2)/build_dir/src/libcodec2.a # Sox --------------------------------------------------- # (libmagic is rqd or later versions of Ubuntu) @@ -164,7 +164,7 @@ endif # Codec 2 ---------------------------------------------------------- $(CODEC2)/.built: $(CODEC2) - cd $(CODEC2) && ./configure && make && touch .built + cd $(CODEC2)/build_dir && cmake ../ && make && touch ../.built $(CODEC2): svn co https://freetel.svn.sourceforge.net/svnroot/freetel/codec2 diff --git a/fdmdv2/src/dlg_options.cpp b/fdmdv2/src/dlg_options.cpp index 470da44c..f5c16be7 100644 --- a/fdmdv2/src/dlg_options.cpp +++ b/fdmdv2/src/dlg_options.cpp @@ -39,7 +39,7 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c wxStaticBoxSizer* sbSizer_testFrames; sbSizer_testFrames = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Test Frames")), wxVERTICAL); - m_ckboxTestFrame = new wxCheckBox(this, wxID_ANY, _("Enable"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + m_ckboxTestFrame = new wxCheckBox(this, wxID_ANY, _("Enable System Calls"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); sbSizer_testFrames->Add(m_ckboxTestFrame, 0, wxALIGN_LEFT, 0); bSizer30->Add(sbSizer_testFrames,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3); @@ -85,10 +85,13 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c // list of regexps - wxStaticBoxSizer* sbSizer_regexp = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Regular Expressions to Process Events")), wxVERTICAL); - m_txt_events_regexp = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(400,100), wxTE_MULTILINE); - m_txt_events_regexp->SetToolTip(_("Enter regular expressions to process events")); - sbSizer_regexp->Add(m_txt_events_regexp, 1, wxEXPAND, 5); + wxStaticBoxSizer* sbSizer_regexp = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Regular Expressions to Process Events")), wxHORIZONTAL); + m_txt_events_regexp_match = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,100), wxTE_MULTILINE); + m_txt_events_regexp_match->SetToolTip(_("Enter regular expressions to match events")); + sbSizer_regexp->Add(m_txt_events_regexp_match, 1, wxEXPAND, 5); + m_txt_events_regexp_replace = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,100), wxTE_MULTILINE); + m_txt_events_regexp_replace->SetToolTip(_("Enter regular expressions to replace events")); + sbSizer_regexp->Add(m_txt_events_regexp_replace, 1, wxEXPAND, 5); sbSizer_events->Add(sbSizer_regexp, 1, wxEXPAND, 5); // log of events and responses @@ -139,6 +142,9 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c m_sdbSizer5Cancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnCancel), NULL, this); m_sdbSizer5OK->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(OptionsDlg::OnOK), NULL, this); + + event_in_serial = 0; + event_out_serial = 0; } //------------------------------------------------------------------------- @@ -168,7 +174,8 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) m_ckboxTestFrame->SetValue(wxGetApp().m_testFrames); m_ckbox_events->SetValue(wxGetApp().m_events); - m_txt_events_regexp->SetValue(wxGetApp().m_events_regexp); + m_txt_events_regexp_match->SetValue(wxGetApp().m_events_regexp_match); + m_txt_events_regexp_replace->SetValue(wxGetApp().m_events_regexp_replace); if (wxGetApp().m_textEncoding == 1) m_rb_textEncoding1->SetValue(true); @@ -182,7 +189,8 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) wxGetApp().m_testFrames = m_ckboxTestFrame->GetValue(); wxGetApp().m_events = m_ckbox_events->GetValue(); - wxGetApp().m_events_regexp = m_txt_events_regexp->GetValue(); + wxGetApp().m_events_regexp_match = m_txt_events_regexp_match->GetValue(); + wxGetApp().m_events_regexp_replace = m_txt_events_regexp_replace->GetValue(); if (m_rb_textEncoding1->GetValue()) wxGetApp().m_textEncoding = 1; @@ -193,7 +201,8 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) pConfig->Write(wxT("/Data/CallSign"), wxGetApp().m_callSign); pConfig->Write(wxT("/Data/TextEncoding"), wxGetApp().m_textEncoding); pConfig->Write(wxT("/Events/enable"), wxGetApp().m_events); - pConfig->Write(wxT("/Events/regexp"), wxGetApp().m_events_regexp); + pConfig->Write(wxT("/Events/regexp_match"), wxGetApp().m_events_regexp_match); + pConfig->Write(wxT("/Events/regexp_replace"), wxGetApp().m_events_regexp_replace); pConfig->Flush(); } } @@ -232,3 +241,14 @@ void OptionsDlg::OnInitDialog(wxInitDialogEvent& event) { ExchangeData(EXCHANGE_DATA_IN, false); } + + +void OptionsDlg::updateEventLog(wxString event_in, wxString event_out) { + wxString event_in_with_serial, event_out_with_serial; + event_in_with_serial.Printf(_T("[%d] %s"), event_in_serial++, event_in); + event_out_with_serial.Printf(_T("[%d] %s"), event_out_serial++, event_out); + + m_txt_events_in->AppendText(event_in_with_serial+"\n"); + m_txt_events_out->AppendText(event_out_with_serial+"\n"); +} + diff --git a/fdmdv2/src/dlg_options.h b/fdmdv2/src/dlg_options.h index 897bb376..49da32c7 100644 --- a/fdmdv2/src/dlg_options.h +++ b/fdmdv2/src/dlg_options.h @@ -23,6 +23,7 @@ #define __OPTIONS_DIALOG__ #include "fdmdv2_main.h" +#include "fdmdv2_defines.h" //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= // Class OptionsDlg @@ -37,6 +38,9 @@ class OptionsDlg : public wxDialog ~OptionsDlg(); void ExchangeData(int inout, bool storePersistent); + void updateEventLog(wxString event_in, wxString event_out); + + bool enableEventsChecked() {return m_ckbox_events->GetValue();} protected: // Handlers for events. @@ -52,7 +56,8 @@ class OptionsDlg : public wxDialog wxRadioButton *m_rb_textEncoding2; wxCheckBox *m_ckbox_events; - wxTextCtrl *m_txt_events_regexp; + wxTextCtrl *m_txt_events_regexp_match; + wxTextCtrl *m_txt_events_regexp_replace; wxTextCtrl *m_txt_events_in; wxTextCtrl *m_txt_events_out; wxTextCtrl *m_txt_event_test; @@ -61,6 +66,8 @@ class OptionsDlg : public wxDialog wxButton* m_sdbSizer5OK; wxButton* m_sdbSizer5Cancel; + unsigned int event_in_serial, event_out_serial; + private: }; diff --git a/fdmdv2/src/fdmdv2_defines.h b/fdmdv2/src/fdmdv2_defines.h index 032cece3..c972bd89 100644 --- a/fdmdv2/src/fdmdv2_defines.h +++ b/fdmdv2/src/fdmdv2_defines.h @@ -81,7 +81,8 @@ // Text messaging Data #define MAX_CALLSIGN 80 - +#define MAX_EVENT_LOG 10 + enum { ID_ROTATE_LEFT = wxID_HIGHEST + 1, diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index 9b55d416..e072c7a2 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -371,8 +371,9 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) wxGetApp().m_callSign = pConfig->Read("/Data/CallSign", wxT("")); wxGetApp().m_textEncoding = pConfig->Read("/Data/TextEncoding", 1); wxGetApp().m_events = pConfig->Read("/Events/enable", f); - wxGetApp().m_events_regexp = pConfig->Read("/Events/regexp", - wxT("s|onstart,mycallsign=(.*),|curl http://qso.freedv.org/cgi-bin/onstart.cgi?callsign=$1|")); + wxGetApp().m_events_regexp_match = pConfig->Read("/Events/regexp_match", wxT("s=(.*)")); + wxGetApp().m_events_regexp_replace = pConfig->Read("/Events/regexp_replace", + wxT("curl http://qso.freedv.org/cgi-bin/onspot.cgi?s=\\1")); pConfig->SetPath(wxT("/")); @@ -456,6 +457,9 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) g_total_bits = 0; wxGetApp().m_testFrames = false; + for(int i=0; iWrite(wxT("/Data/CallSign"), wxGetApp().m_callSign); pConfig->Write(wxT("/Data/TextEncoding"), wxGetApp().m_textEncoding); pConfig->Write(wxT("/Events/enable"), wxGetApp().m_events); - pConfig->Write(wxT("/Events/regexp"), wxGetApp().m_events_regexp); + pConfig->Write(wxT("/Events/regexp_match"), wxGetApp().m_events_regexp_match); + pConfig->Write(wxT("/Events/regexp_replace"), wxGetApp().m_events_regexp_replace); pConfig->Write(wxT("/Filter/MicInEQEnable"), wxGetApp().m_MicInEQEnable); pConfig->Write(wxT("/Filter/SpkOutEQEnable"), wxGetApp().m_SpkOutEQEnable); @@ -923,17 +928,20 @@ void MainFrame::OnTimer(wxTimerEvent &evt) // lets see if checksum is OK unsigned char checksum_rx = 0; - for(unsigned int i=0; i 2) { + for(unsigned int i=0; iSetValue(s); + processTxtEvent(m_callsign); m_checksumGood++; s.Printf("%d", m_checksumGood); @@ -1673,11 +1681,12 @@ void MainFrame::OnToolsFilter(wxCommandEvent& event) void MainFrame::OnToolsOptions(wxCommandEvent& event) { wxUnusedVar(event); - OptionsDlg *dlg = new OptionsDlg(NULL); + optionsDlg = new OptionsDlg(NULL); m_modal=true; - dlg->ShowModal(); + optionsDlg->ShowModal(); m_modal=false; - delete dlg; + delete optionsDlg; + optionsDlg = NULL; } //------------------------------------------------------------------------- @@ -2506,6 +2515,48 @@ fprintf(stderr, "Err: %d\n", m_txErr); } } + +void MainFrame::processTxtEvent(char event[]) { + + // process with regexp and issue system command + + wxString event_str(event); + wxRegEx re(wxGetApp().m_events_regexp_match); + wxString regexp_replace_str(wxGetApp().m_events_regexp_replace); + re.Replace(&event_str, regexp_replace_str); + const char *event_out = event_str.ToUTF8(); + + wxString event_out_with_return_code; + + bool enableSystem = false; + if (wxGetApp().m_events) + enableSystem = true; + + // If options dialog is up current value of events checkbox overrides + + if (optionsDlg != NULL) { + if (optionsDlg->enableEventsChecked()) + enableSystem = true; + else + enableSystem = false; + } + + if (enableSystem) { + int ret = wxExecute(event_str); + event_out_with_return_code.Printf(_T("%s -> process ID %d"), event_out, ret); + } + else { + event_out_with_return_code.Printf(_T("%s)"), event_out); + } + + // update event log GUI if currently displayed + + if (optionsDlg != NULL) { + optionsDlg->updateEventLog(wxString(event), event_out_with_return_code); + } +} + + #define SBQ_MAX_ARGS 4 void *MainFrame::designAnEQFilter(const char filterType[], float freqHz, float gaindB, float Q) @@ -2894,15 +2945,13 @@ int MainFrame::rxCallback( // RX side processing -------------------------------------------- // - // assemble a mono buffer (just use left channel if stereo) and write to FIFO + // assemble a mono buffer and write to FIFO assert(framesPerBuffer < MAX_FPB); if(rptr) { for(i = 0; i < framesPerBuffer; i++, rptr += cbData->inputChannels1) - { - indata[i] = *rptr; - } + indata[i] = rptr[0]; if (fifo_write(cbData->infifo1, indata, framesPerBuffer)) { //wxLogDebug("infifo1 full\n"); } @@ -3451,15 +3500,13 @@ int MainFrame::txCallback( // if (statusFlags) // printf("cb2 statusFlags: 0x%x\n", (int)statusFlags); - // assemble a mono buffer (just use left channel) and write to FIFO + // assemble a mono buffer and write to FIFO assert(framesPerBuffer < MAX_FPB); if(rptr) { for(i = 0; i < framesPerBuffer; i++, rptr += cbData->inputChannels2) - { - indata[i] = *rptr; - } + indata[i] = rptr[0]; } //#define SC2_LOOPBACK diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index 16b2ed2d..8a234573 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -48,6 +48,7 @@ #include #include #include +#include #include @@ -66,6 +67,7 @@ #include "topFrame.h" #include "dlg_ptt.h" +#include "dlg_options.h" #include "fdmdv2_plot.h" #include "fdmdv2_plot_scalar.h" #include "fdmdv2_plot_scatter.h" @@ -174,7 +176,8 @@ class MainApp : public wxApp wxString m_callSign; bool m_events; unsigned int m_textEncoding; - wxString m_events_regexp; + wxString m_events_regexp_match; + wxString m_events_regexp_replace; bool m_snrSlow; @@ -485,6 +488,11 @@ class MainFrame : public TopFrame unsigned int m_checksumGood; unsigned int m_checksumBad; + // Events + char m_event_log[MAX_EVENT_LOG][MAX_CALLSIGN]; + void processTxtEvent(char event[]); + class OptionsDlg *optionsDlg; + // level Gauge float m_maxLevel;