event processing starting to come together, issuing system commands and logging events
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 9 Jun 2014 10:45:59 +0000 (10:45 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 9 Jun 2014 10:45:59 +0000 (10:45 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1642 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/Makefile.linux
fdmdv2/src/dlg_options.cpp
fdmdv2/src/dlg_options.h
fdmdv2/src/fdmdv2_defines.h
fdmdv2/src/fdmdv2_main.cpp
fdmdv2/src/fdmdv2_main.h

index f49e9e2aa976308f5c10fa4f523bf2ced70b925a..632f146d8f245cbd00653f7f24953a0e220d9604 100644 (file)
@@ -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
index 470da44c3dff6eb58ee42fd71543223b04341212..f5c16be7a3037ee05cbc74dba89534a34a315e0c 100644 (file)
@@ -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");
+}
+
index 897bb37683f42619d06af98924e626e578b848eb..49da32c7706654d457513a6ae78dcefa48ac8c57 100644 (file)
@@ -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:
 };
 
index 032cece374717b3f663dd3cc49a2895647a41c8b..c972bd89e8dd28a50a6ca2bc12aafe1d5b3337dd 100644 (file)
@@ -81,7 +81,8 @@
 
 // Text messaging Data
 #define MAX_CALLSIGN         80
-
+#define MAX_EVENT_LOG        10
+   
 enum
 {
     ID_ROTATE_LEFT = wxID_HIGHEST + 1,
index 9b55d41665f850111a4392d02c83b58ca02dca67..e072c7a29bafa07253d7e8c5b7e5664418290702 100644 (file)
@@ -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; i<MAX_EVENT_LOG; i++)
+        m_event_log[i][0] = 0;
+
     m_modal = false;
 }
 
@@ -527,7 +531,8 @@ MainFrame::~MainFrame()
         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->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<strlen(m_callsign)-2; i++)
-                checksum_rx += callsign[i];
+            if (strlen(m_callsign) > 2) {
+                for(unsigned int i=0; i<strlen(m_callsign)-2; i++)
+                    checksum_rx += m_callsign[i];
+            }
             unsigned int checksum_tx;
             int ret = sscanf(&m_callsign[strlen(m_callsign)-2], "%2x", &checksum_tx);
-            //printf("checksums: %2x %2x\n", checksum_tx, checksum_rx);
+            printf("m_callsign: %s checksums: %2x %2x\n", m_callsign, checksum_tx, checksum_rx);
 
             wxString s;
             if (ret && (checksum_tx == checksum_rx)) {
                 m_callsign[strlen(m_callsign)-2] = 0;
                 s.Printf("%s", m_callsign);
                 m_txtCtrlCallSign->SetValue(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
index 16b2ed2d53d2fa9f8971e2716ba346cdbae7c632..8a234573143264025717410fa62b9fa6cbbc9d91 100644 (file)
@@ -48,6 +48,7 @@
 #include <wx/sstream.h>
 #include <wx/listbox.h>
 #include <wx/textdlg.h>
+#include <wx/regex.h>
 
 #include <samplerate.h>
 
@@ -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;