From: drowe67 Date: Fri, 13 Jun 2014 02:27:08 +0000 (+0000) Subject: added anti system call spam tmer, and finally have checkboxes tooltips working X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=6b5ab35a2ee49e75325362ed0ee2c692e2998728;p=freetel-svn-tracking.git added anti system call spam tmer, and finally have checkboxes tooltips working git-svn-id: https://svn.code.sf.net/p/freetel/code@1648 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/src/dlg_options.cpp b/fdmdv2/src/dlg_options.cpp index 192e2687..6acca118 100644 --- a/fdmdv2/src/dlg_options.cpp +++ b/fdmdv2/src/dlg_options.cpp @@ -37,9 +37,11 @@ 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); + wxStaticBox *sb_testFrames = new wxStaticBox(this, wxID_ANY, _("Test Frames")); + sbSizer_testFrames = new wxStaticBoxSizer(sb_testFrames, wxVERTICAL); m_ckboxTestFrame = new wxCheckBox(this, wxID_ANY, _("Enable"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + sb_testFrames->SetToolTip(_("Send frames of known bits instead of compressed voice")); sbSizer_testFrames->Add(m_ckboxTestFrame, 0, wxALIGN_LEFT, 0); bSizer30->Add(sbSizer_testFrames,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3); @@ -76,12 +78,25 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c //------------------------------ wxStaticBoxSizer* sbSizer_events; - sbSizer_events = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Event Processing")), wxVERTICAL); - - // event processing enable - - m_ckbox_events = new wxCheckBox(this, wxID_ANY, _("Enable System Calls"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); - sbSizer_events->Add(m_ckbox_events, 0, 0, 5); + wxStaticBox *sb_events = new wxStaticBox(this, wxID_ANY, _("Event Processing")); + sbSizer_events = new wxStaticBoxSizer(sb_events, wxVERTICAL); + + // event processing enable and spam timer + + wxStaticBoxSizer* sbSizer_events_top; + wxStaticBox* sb_events1 = new wxStaticBox(this, wxID_ANY, _("")); + sbSizer_events_top = new wxStaticBoxSizer(sb_events1, wxHORIZONTAL); + + m_ckbox_events = new wxCheckBox(this, wxID_ANY, _("Enable System Calls Syscall Spam Timer"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + sb_events->SetToolTip(_("Enable processing of events and generation of system calls")); + sbSizer_events_top->Add(m_ckbox_events, 0, 0, 5); + m_txt_spam_timer = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(40,-1), 0, wxTextValidator(wxFILTER_DIGITS)); + m_txt_spam_timer->SetToolTip(_("Many matching events can cause a flood of syscalls. Set minimum time (seconds) between syscalls for each event here")); + sbSizer_events_top->Add(m_txt_spam_timer, 0, 0, 5); + m_rb_spam_timer = new wxRadioButton( this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); + m_rb_spam_timer->SetForegroundColour( wxColour(0, 255, 0 ) ); + sbSizer_events_top->Add(m_rb_spam_timer, 0, 0, 10); + sbSizer_events->Add(sbSizer_events_top, 0, 0, 5); // list of regexps @@ -96,7 +111,7 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c // log of events and responses - wxStaticBoxSizer* sbSizer_event_log = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Events and Responses")), wxVERTICAL); + wxStaticBoxSizer* sbSizer_event_log = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Log of Events and Responses")), wxVERTICAL); wxBoxSizer* bSizer33 = new wxBoxSizer(wxHORIZONTAL); m_txt_events_in = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200,50), wxTE_MULTILINE | wxTE_READONLY); bSizer33->Add(m_txt_events_in, 1, wxEXPAND, 5); @@ -112,10 +127,12 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c //------------------------------ wxStaticBoxSizer* sbSizer_udp; - sbSizer_udp = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("UDP Control Port")), wxHORIZONTAL); - m_ckbox_udp_enable = new wxCheckBox(this, wxID_ANY, _("Enable UDP Control Port UDP Port Nnumber:"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + wxStaticBox* sb_udp = new wxStaticBox(this, wxID_ANY, _("UDP Control Port")); + sbSizer_udp = new wxStaticBoxSizer(sb_udp, wxHORIZONTAL); + m_ckbox_udp_enable = new wxCheckBox(this, wxID_ANY, _("Enable UDP Control Port UDP Port Number:"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + sb_udp->SetToolTip(_("Enable control of FreeDV via UDP port")); sbSizer_udp->Add(m_ckbox_udp_enable, 0, wxALIGN_CENTER_HORIZONTAL, 5); - m_txt_udp_port = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100,-1), 0, wxTextValidator(wxFILTER_DIGITS)); + m_txt_udp_port = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(50,-1), 0, wxTextValidator(wxFILTER_DIGITS)); sbSizer_udp->Add(m_txt_udp_port, 0, wxALIGN_CENTER_HORIZONTAL, 5); bSizer30->Add(sbSizer_udp,0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND, 3); @@ -182,6 +199,8 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) m_ckboxTestFrame->SetValue(wxGetApp().m_testFrames); m_ckbox_events->SetValue(wxGetApp().m_events); + m_txt_spam_timer->SetValue(wxString::Format(wxT("%i"),wxGetApp().m_events_spam_timer)); + m_txt_events_regexp_match->SetValue(wxGetApp().m_events_regexp_match); m_txt_events_regexp_replace->SetValue(wxGetApp().m_events_regexp_replace); @@ -200,6 +219,9 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) wxGetApp().m_testFrames = m_ckboxTestFrame->GetValue(); wxGetApp().m_events = m_ckbox_events->GetValue(); + long spam_timer; + m_txt_spam_timer->GetValue().ToLong(&spam_timer); + wxGetApp().m_events_spam_timer = (int)spam_timer; // make sure regexp lists are terminated by a \n @@ -225,7 +247,9 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) if (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/spam_timer"), wxGetApp().m_events_spam_timer); pConfig->Write(wxT("/Events/regexp_match"), wxGetApp().m_events_regexp_match); pConfig->Write(wxT("/Events/regexp_replace"), wxGetApp().m_events_regexp_replace); diff --git a/fdmdv2/src/dlg_options.h b/fdmdv2/src/dlg_options.h index ff5d708d..bfe30d47 100644 --- a/fdmdv2/src/dlg_options.h +++ b/fdmdv2/src/dlg_options.h @@ -42,6 +42,21 @@ class OptionsDlg : public wxDialog bool enableEventsChecked() {return m_ckbox_events->GetValue();} + void SetSpamTimerLight(bool state) { + + // Colours don't work on Windows + + if (state) { + m_rb_spam_timer->SetForegroundColour( wxColour( 255,0 , 0 ) ); // red + m_rb_spam_timer->SetValue(true); + } + else { + m_rb_spam_timer->SetForegroundColour( wxColour( 0, 255, 0 ) ); // green + m_rb_spam_timer->SetValue(false); + } + } + + protected: // Handlers for events. void OnOK(wxCommandEvent& event); @@ -61,6 +76,8 @@ class OptionsDlg : public wxDialog wxTextCtrl *m_txt_events_regexp_replace; wxTextCtrl *m_txt_events_in; wxTextCtrl *m_txt_events_out; + wxTextCtrl *m_txt_spam_timer; + wxRadioButton *m_rb_spam_timer; wxCheckBox *m_ckbox_udp_enable; wxTextCtrl *m_txt_udp_port; diff --git a/fdmdv2/src/fdmdv2_defines.h b/fdmdv2/src/fdmdv2_defines.h index c972bd89..ba11f029 100644 --- a/fdmdv2/src/fdmdv2_defines.h +++ b/fdmdv2/src/fdmdv2_defines.h @@ -82,6 +82,7 @@ // Text messaging Data #define MAX_CALLSIGN 80 #define MAX_EVENT_LOG 10 +#define MAX_EVENT_RULES 100 enum { diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index f5114bf3..83d8b206 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -370,8 +370,10 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) wxGetApp().m_SpkOutEQEnable = (float)pConfig->Read(wxT("/Filter/SpkOutEQEnable"), f); wxGetApp().m_callSign = pConfig->Read("/Data/CallSign", wxT("")); - wxGetApp().m_textEncoding = pConfig->Read("/Data/TextEncoding", 1); + wxGetApp().m_textEncoding = pConfig->Read("/Data/TextEncoding", 2); + wxGetApp().m_events = pConfig->Read("/Events/enable", f); + wxGetApp().m_events_spam_timer = (int)pConfig->Read(wxT("/Events/spam_timer"), 10); 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")); @@ -385,7 +387,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) } wxGetApp().m_udp_enable = (float)pConfig->Read(wxT("/UDP/enable"), f); - wxGetApp().m_udp_port = (float)pConfig->Read(wxT("/UDP/port"), 3000); + wxGetApp().m_udp_port = (int)pConfig->Read(wxT("/UDP/port"), 3000); pConfig->SetPath(wxT("/")); @@ -561,6 +563,7 @@ 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/spam_timer"), wxGetApp().m_events_spam_timer); pConfig->Write(wxT("/Events/regexp_match"), wxGetApp().m_events_regexp_match); pConfig->Write(wxT("/Events/regexp_replace"), wxGetApp().m_events_regexp_replace); @@ -1061,6 +1064,14 @@ void MainFrame::OnTimer(wxTimerEvent &evt) Restore(); m_schedule_restore = false; } + + // Light Spam Timer LED if at least one time is running + + int i; + optionsDlg->SetSpamTimerLight(false); + for(i=0; iSetSpamTimerLight(true); } #endif @@ -1252,7 +1263,7 @@ void MainFrame::togglePTT(void) { exclusive NOR */ - if(wxGetApp().m_boolUseSerialPTT && com_handle != COM_HANDLE_INVALID) { + if(wxGetApp().m_boolUseSerialPTT && (com_handle != COM_HANDLE_INVALID)) { if (wxGetApp().m_boolUseRTS) { printf("g_tx: %d m_boolRTSPos: %d serialLine: %d\n", g_tx, wxGetApp().m_boolRTSPos, g_tx == wxGetApp().m_boolRTSPos); if (g_tx == wxGetApp().m_boolRTSPos) @@ -2020,6 +2031,8 @@ void MainFrame::OnTogBtnOnOff(wxCommandEvent& event) // Stop Running ------------------------------------------------- // + optionsDlg->SetSpamTimerLight(false); + #ifdef _USE_TIMER m_plotTimer.Stop(); #endif // _USE_TIMER @@ -2437,7 +2450,7 @@ void MainFrame::startRxStream() m_txErr = m_txInPa->streamOpen(); if(m_txErr != paNoError) { -fprintf(stderr, "Err: %d\n", m_txErr); + fprintf(stderr, "Err: %d\n", m_txErr); wxMessageBox(wxT("Sound Card 2 Open/Setup error."), wxT("Error"), wxOK); m_rxInPa->stop(); m_rxInPa->streamClose(); @@ -2557,6 +2570,7 @@ fprintf(stderr, "Err: %d\n", m_txErr); void MainFrame::processTxtEvent(char event[]) { + int rule = 0; printf("processTxtEvent:\n"); printf(" event: %s\n", event); @@ -2573,10 +2587,11 @@ void MainFrame::processTxtEvent(char event[]) { bool found_match = false; - while ((match_end = regexp_match_list.Find('\n')) != wxNOT_FOUND) { + while (((match_end = regexp_match_list.Find('\n')) != wxNOT_FOUND) && (rule < MAX_EVENT_RULES)) { //printf("match_end: %d\n", match_end); if ((replace_end = regexp_replace_list.Find('\n')) != wxNOT_FOUND) { //printf("replace_end = %d\n", replace_end); + // candidate match and replace regexps strings exist, so lets try them wxString regexp_match = regexp_match_list.SubString(0, match_end-1); @@ -2596,16 +2611,24 @@ void MainFrame::processTxtEvent(char event[]) { bool enableSystem = false; if (wxGetApp().m_events) enableSystem = true; - + + // no syscall if spam timer still running + + if (spamTimer[rule].IsRunning()) { + enableSystem = false; + printf(" spam timer running\n"); + } + const char *event_out = event_str_rep.ToUTF8(); wxString event_out_with_return_code; if (enableSystem) { int ret = wxExecute(event_str_rep); event_out_with_return_code.Printf(_T("%s -> returned %d"), event_out, ret); + spamTimer[rule].Start((wxGetApp().m_events_spam_timer)*1000, wxTIMER_ONE_SHOT); } else - event_out_with_return_code.Printf(_T("%s)"), event_out); + event_out_with_return_code.Printf(_T("%s T: %d"), event_out, spamTimer[rule].IsRunning()); // update event log GUI if currently displayed @@ -2616,6 +2639,8 @@ void MainFrame::processTxtEvent(char event[]) { } regexp_match_list = regexp_match_list.SubString(match_end+1, regexp_match_list.length()); regexp_replace_list = regexp_replace_list.SubString(replace_end+1, regexp_replace_list.length()); + + rule++; } if ((optionsDlg != NULL) && !found_match) { diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index 6fe1acce..8c11fb85 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -176,6 +176,7 @@ class MainApp : public wxApp wxString m_callSign; bool m_events; + int m_events_spam_timer; unsigned int m_textEncoding; wxString m_events_regexp_match; wxString m_events_regexp_replace; @@ -502,10 +503,11 @@ class MainFrame : public TopFrame char *m_pcallsign; unsigned int m_checksumGood; unsigned int m_checksumBad; - + // Events void processTxtEvent(char event[]); class OptionsDlg *optionsDlg; + wxTimer spamTimer[MAX_EVENT_RULES]; // level Gauge float m_maxLevel; diff --git a/fdmdv2/src/topFrame.cpp b/fdmdv2/src/topFrame.cpp index 807f9515..c383a8f7 100644 --- a/fdmdv2/src/topFrame.cpp +++ b/fdmdv2/src/topFrame.cpp @@ -68,9 +68,6 @@ TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const m_menuItemFilter = new wxMenuItem(tools, wxID_ANY, wxString(_("&Filter")) , wxEmptyString, wxITEM_NORMAL); tools->Append(m_menuItemFilter); - wxMenuItem* m_menuItemCaptTxInStream; - m_menuItemCaptTxInStream = new wxMenuItem(tools, wxID_ANY, wxString(_("&Capture Tx Input Stream")), wxEmptyString, wxITEM_NORMAL); - wxMenuItem* m_menuItemPlayFileToMicIn; m_menuItemPlayFileToMicIn = new wxMenuItem(tools, wxID_ANY, wxString(_("Start/Stop Play File - Mic In")) , wxEmptyString, wxITEM_NORMAL); g_playFileToMicInEventId = m_menuItemPlayFileToMicIn->GetId(); @@ -219,11 +216,18 @@ TopFrame::TopFrame(wxWindow* parent, wxWindowID id, const wxString& title, const bSizer15->Add(m_txtCtrlCallSign, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5); lowerSizer->Add(bSizer15, 1, wxEXPAND, 5); - wxStaticBoxSizer* sbSizer_Checksum = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Good/Bad Checksums")), wxHORIZONTAL); - m_txtChecksumGood = new wxStaticText(this, wxID_ANY, wxT("0"), wxDefaultPosition, wxSize(100,-1), wxALIGN_CENTRE); - sbSizer_Checksum->Add(m_txtChecksumGood, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 1); - m_txtChecksumBad = new wxStaticText(this, wxID_ANY, wxT("0"), wxDefaultPosition, wxSize(100,-1), wxALIGN_CENTRE); - sbSizer_Checksum->Add(m_txtChecksumBad, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 1); + wxStaticBoxSizer* sbSizer_Checksum = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, _("Checksums")), wxHORIZONTAL); + + wxStaticText *goodLabel = new wxStaticText(this, wxID_ANY, wxT("Good: "), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); + sbSizer_Checksum->Add(goodLabel, 0, 0, 2); + m_txtChecksumGood = new wxStaticText(this, wxID_ANY, wxT("0"), wxDefaultPosition, wxSize(30,-1), wxALIGN_CENTRE); + sbSizer_Checksum->Add(m_txtChecksumGood, 0, 0, 2); + + wxStaticText *badLabel = new wxStaticText(this, wxID_ANY, wxT("Bad: "), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); + sbSizer_Checksum->Add(badLabel, 0, 0, 1); + m_txtChecksumBad = new wxStaticText(this, wxID_ANY, wxT("0"), wxDefaultPosition, wxSize(30,-1), wxALIGN_CENTRE); + sbSizer_Checksum->Add(m_txtChecksumBad, 0, 0, 1); + lowerSizer->Add(sbSizer_Checksum, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 1); //=====================================================