From 4b2005e7f7621476919d89476493adc7411e559e Mon Sep 17 00:00:00 2001 From: Robert Stiles Date: Thu, 26 May 2016 07:46:36 -0500 Subject: [PATCH] KISS IO Bug fixes/Additions and C++11 Test * Unified IO switching code * Add: MFSK31 and MFSK16 use for KISS IO operations * Add: KISS IO Auto connect on FLDIGI start up * In Listen Mode (TCP) on disconnect returns to waiting for connection. * TCP none listing mode connection tries 10 (one sec interval) times before giving up. * Save/restore KPSQL button state. * User 7bit modem switch warning is now selectable * Logic error when saving FLDIGI progStatus.data_io_enable variable. * Add: TXLOCK: command to the KISS hardware command set. * Assign/Compare KISS hardware modem names in capital letter form. * Add: Close KISS Socket on write fail. * Fixed issues effecting Win32 compile. * Add: Test compiler for C++11 support. Configuration macro added but not used until other FLDIGI source code c++11 compiler error are resolved. Recent compilers require c++11 in other to use std::bind(). * Correct typedef clockid_t conflict between timeops.h and pthead_time.h * Add new IO panel widgets to the lock/unlock mechanism. * Restore initial IO panel locked state. --- m4/c++11.m4 | 108 + src/config_script/run_scripts.cxx | 48 +- src/dialogs/confdialog.cxx | 162 +- src/dialogs/confdialog.fl | 174 +- src/dialogs/fl_digi.cxx | 61 +- src/globals/globals.cxx | 12 +- src/include/confdialog.h | 2 + src/include/configuration.h | 19 +- src/include/data_io.h | 9 +- src/include/filters.h | 3 + src/include/kiss_io.h | 7 + src/include/socket.h | 3 + src/include/status.h | 4 +- src/include/timeops.h | 24 +- src/main.cxx | 31 +- src/misc/kiss_io.cxx | 5066 +++++++++++++++-------------- src/misc/socket.cxx | 2 + src/misc/status.cxx | 22 +- src/rigcontrol/xmlrpc_rig.cxx | 22 +- src/trx/modem.cxx | 2 +- 20 files changed, 3114 insertions(+), 2667 deletions(-) create mode 100644 m4/c++11.m4 diff --git a/m4/c++11.m4 b/m4/c++11.m4 new file mode 100644 index 00000000..7d19b1d2 --- /dev/null +++ b/m4/c++11.m4 @@ -0,0 +1,108 @@ +m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[ + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + struct Base { + virtual void f() {} + }; + struct Child : public Base { + virtual void f() {} + }; + + typedef check> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check check_type; + check_type c; + check_type&& cr = static_cast(c); + + auto d = a; + auto l = [](){}; +]]) + +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl + m4_if([$1], [], [], + [$1], [ext], [], + [$1], [noext], [], + [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl + m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], + [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], + [$2], [optional], [ax_cxx_compile_cxx11_required=false], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++11 features by default, + ax_cv_cxx_compile_cxx11, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [ax_cv_cxx_compile_cxx11=yes], + [ax_cv_cxx_compile_cxx11=no])]) + if test x$ax_cv_cxx_compile_cxx11 = xyes; then + ac_success=yes + fi + + m4_if([$1], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++11 -std=gnu++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + CXX11_SWITCH="$switch" + AC_SUBST(CXX11_SWITCH) + ac_success=yes + break + fi + done + fi]) + + m4_if([$1], [ext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=c++11 -std=c++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + CXX11_SWITCH="$switch" + AC_SUBST(CXX11_SWITCH) + ac_success=yes + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx11_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) + fi + else + if test x$ac_success = xno; then + HAVE_CXX11=0 + AC_MSG_NOTICE([No compiler with C++11 support was found]) + else + HAVE_CXX11=1 + AC_DEFINE(HAVE_CXX11,1, + [define if the compiler supports basic C++11 syntax]) + fi + + AC_SUBST(HAVE_CXX11) + fi +]) diff --git a/src/config_script/run_scripts.cxx b/src/config_script/run_scripts.cxx index 1f57b613..07eebc0f 100644 --- a/src/config_script/run_scripts.cxx +++ b/src/config_script/run_scripts.cxx @@ -421,7 +421,7 @@ static int assign_index(widget_type * widget, ScriptParsing *sp, SCRIPT_COMMANDS widget->do_callback(); data = index; - + return script_no_errors; } @@ -1245,11 +1245,9 @@ int process_io_active_port(ScriptParsing *sp, SCRIPT_COMMANDS *sc) return script_no_errors; if(value.find(PARM_KISS) != std::string::npos) { - btnEnable_kiss->value(true); - btnEnable_kiss->do_callback(); + enable_kiss(); } else if(value.find(PARM_ARQ) != std::string::npos) { - btnEnable_arq->value(true); - btnEnable_arq->do_callback(); + enable_arq(); } else { return script_invalid_parameter; } @@ -2797,42 +2795,42 @@ int process_reset(ScriptParsing *sp, SCRIPT_COMMANDS *sc) ***********************************************************/ static void script_execute(const char *filename, bool queue_flag) { - + ScriptParsing *sp = 0; static std::string script_filename = ""; - + if(!filename) { LOG_INFO(_("Script file name (path) null pointer")); return; } - + script_filename.assign(filename); - + if(script_filename.empty()) { LOG_INFO(_("Script file name (path) invalid")); return; } - + sp = new ScriptParsing; - + if(!sp) { LOG_INFO(_("Script Parsing Class Allocation Fail (%s)"), script_filename.c_str()); return; } - + LOG_INFO(_("Executing script file: %s"), script_filename.c_str()); - + sp->parse_commands((char *) script_filename.c_str()); - + if(sp->script_errors()) { LOG_INFO(_("Issues reported in processing script file: %s"), script_filename.c_str()); fl_alert("%s", _("Script file contains potential issues\nSee documentation and/or Log file for details.")); } - + if(sp->restart_flag()) { fl_alert("%s", _("Some changes made by the script requires program\nrestart before they become active.")); } - + if(sp) delete sp; } @@ -2845,16 +2843,16 @@ static void script_execute(const char *filename, bool queue_flag) void cb_scripts(bool reset_path = false) { pthread_mutex_lock(&mutex_script_io); - + static bool first_time = true; static char script_filename[FL_PATH_MAX + 1]; std::string new_path = ""; - + if(reset_path || first_time) { memset(script_filename, 0, sizeof(script_filename)); strncpy(script_filename, ScriptsDir.c_str(), FL_PATH_MAX); int len = strnlen(script_filename, FL_PATH_MAX); - + if(len > 0) { len--; if(script_filename[len] == PATH_CHAR_SEPERATOR); @@ -2862,22 +2860,22 @@ void cb_scripts(bool reset_path = false) } else { return; } - + first_time = false; } - + const char *p = FSEL::select((char *)_("Script Files"), (char *)_("*.txt"), \ script_filename); - + if(p) { memset(script_filename, 0, sizeof(script_filename)); strncpy(script_filename, p, FL_PATH_MAX); - + Fl::lock(); script_execute(script_filename, false); Fl::unlock(); - + } - + pthread_mutex_unlock(&mutex_script_io); } diff --git a/src/dialogs/confdialog.cxx b/src/dialogs/confdialog.cxx index c36d0ee7..fbf2ed30 100644 --- a/src/dialogs/confdialog.cxx +++ b/src/dialogs/confdialog.cxx @@ -5658,10 +5658,7 @@ Fl_Check_Button *btnEnable_arq=(Fl_Check_Button *)0; static void cb_btnEnable_arq(Fl_Check_Button* o, void*) { if(o->value()) { - progdefaults.changed = true; - progdefaults.data_io_enabled = ARQ_IO; - data_io_enabled = ARQ_IO; - enable_disable_kpsql(); + enable_arq(); } progdefaults.changed = true; @@ -5671,9 +5668,7 @@ Fl_Check_Button *btnEnable_kiss=(Fl_Check_Button *)0; static void cb_btnEnable_kiss(Fl_Check_Button* o, void*) { if(o->value()) { - progdefaults.data_io_enabled = KISS_IO; - data_io_enabled = KISS_IO; - enable_disable_kpsql(); + enable_kiss(); } progdefaults.changed = true; } @@ -5681,10 +5676,14 @@ progdefaults.changed = true; Fl_Check_Button *btnEnable_ax25_decode=(Fl_Check_Button *)0; static void cb_btnEnable_ax25_decode(Fl_Check_Button* o, void*) { - if(o->value()) + if(o->value()) { + progStatus.ax25_decode_enabled = true; progdefaults.ax25_decode_enabled = true; -else +} +else { + progStatus.ax25_decode_enabled = false; progdefaults.ax25_decode_enabled = false; +} progdefaults.changed = true; } @@ -5693,8 +5692,10 @@ Fl_Check_Button *btnEnable_csma=(Fl_Check_Button *)0; static void cb_btnEnable_csma(Fl_Check_Button* o, void*) { if(o->value()) { + progStatus.csma_enabled = true; progdefaults.csma_enabled = true; } else { + progStatus.csma_enabled = false; progdefaults.csma_enabled = false; } progdefaults.changed = true; @@ -5710,56 +5711,69 @@ progdefaults.changed = true; Fl_Input2 *txtKiss_ip_address=(Fl_Input2 *)0; static void cb_txtKiss_ip_address(Fl_Input2* o, void*) { - progdefaults.kiss_address = o->value(); + progStatus.kiss_address = o->value(); +progdefaults.kiss_address = o->value(); progdefaults.changed = true; } Fl_Counter *cntKPSQLAttenuation=(Fl_Counter *)0; static void cb_cntKPSQLAttenuation(Fl_Counter* o, void*) { - progdefaults.kpsql_attenuation = (int) o->value(); -update_kpsql_fractional_gain(progdefaults.kpsql_attenuation); + progStatus.kpsql_attenuation = (int) o->value(); +progdefaults.kpsql_attenuation = (int) o->value(); +update_kpsql_fractional_gain(progStatus.kpsql_attenuation); progdefaults.changed = true; } Fl_Input2 *txtKiss_ip_io_port_no=(Fl_Input2 *)0; static void cb_txtKiss_ip_io_port_no(Fl_Input2* o, void*) { - progdefaults.kiss_io_port = o->value(); + progStatus.kiss_io_port = o->value(); +progdefaults.kiss_io_port = o->value(); progdefaults.changed = true; } Fl_Counter *cntBusyChannelSeconds=(Fl_Counter *)0; static void cb_cntBusyChannelSeconds(Fl_Counter* o, void*) { - progdefaults.busyChannelSeconds = (int) o->value(); + progStatus.busyChannelSeconds = (int) o->value(); +progdefaults.busyChannelSeconds = (int) o->value(); progdefaults.changed = true; } Fl_Check_Button *btnEnableBusyChannel=(Fl_Check_Button *)0; static void cb_btnEnableBusyChannel(Fl_Check_Button* o, void*) { - if(o->value()) + if(o->value()) { + progStatus.enableBusyChannel = true; progdefaults.enableBusyChannel = true; -else +} +else { + progStatus.enableBusyChannel = false; progdefaults.enableBusyChannel = false; +} progdefaults.changed = true; } Fl_Input2 *txtKiss_ip_out_port_no=(Fl_Input2 *)0; static void cb_txtKiss_ip_out_port_no(Fl_Input2* o, void*) { - progdefaults.kiss_out_port = o->value(); + progStatus.kiss_out_port = o->value(); +progdefaults.kiss_out_port = o->value(); progdefaults.changed = true; } Fl_Check_Button *btnEnable_dual_port=(Fl_Check_Button *)0; static void cb_btnEnable_dual_port(Fl_Check_Button* o, void*) { - if(o->value()) + if(o->value()) { + progStatus.kiss_dual_port_enabled = true; progdefaults.kiss_dual_port_enabled = true; -else +} +else { + progStatus.kiss_dual_port_enabled = false; progdefaults.kiss_dual_port_enabled = false; +} progdefaults.changed = true; } @@ -5773,46 +5787,78 @@ static void cb_btn_restart_kiss(Fl_Button*, void*) { Fl_Button *btn_connect_kiss_io=(Fl_Button *)0; static void cb_btn_connect_kiss_io(Fl_Button*, void*) { - connect_to_kiss_io(); + connect_to_kiss_io(true); } Fl_Check_Button *btnKissTCPIO=(Fl_Check_Button *)0; static void cb_btnKissTCPIO(Fl_Check_Button* o, void*) { if(o->value()) { - progdefaults.kiss_tcp_io = true; progStatus.kiss_tcp_io = true; + progdefaults.kiss_tcp_io = true; } else { progStatus.kiss_tcp_io = false; progdefaults.kiss_tcp_io = false; } kiss_io_set_button_state(0); +progdefaults.changed = true; } Fl_Check_Button *btnKissUDPIO=(Fl_Check_Button *)0; static void cb_btnKissUDPIO(Fl_Check_Button* o, void*) { if(o->value()) { - progdefaults.kiss_tcp_io = false; progStatus.kiss_tcp_io = false; + progdefaults.kiss_tcp_io = false; } else { progStatus.kiss_tcp_io = true; progdefaults.kiss_tcp_io = true; } kiss_io_set_button_state(0); +progdefaults.changed = true; } Fl_Check_Button *btnKissTCPListen=(Fl_Check_Button *)0; static void cb_btnKissTCPListen(Fl_Check_Button* o, void*) { if(o->value()) { - progdefaults.kiss_tcp_listen = true; progStatus.kiss_tcp_listen = true; + progdefaults.kiss_tcp_listen = true; } else { progStatus.kiss_tcp_listen = false; progdefaults.kiss_tcp_listen = false; -}; +} + +progdefaults.changed = true; +} + +Fl_Check_Button *btnEnable_7bit_modem_inhibit=(Fl_Check_Button *)0; + +static void cb_btnEnable_7bit_modem_inhibit(Fl_Check_Button* o, void*) { + if(o->value()) { + progStatus.kiss_io_modem_change_inhibit = true; + progdefaults.kiss_io_modem_change_inhibit = true; +} +else { + progStatus.kiss_io_modem_change_inhibit = false; + progdefaults.kiss_io_modem_change_inhibit = false; +} + +progdefaults.changed = true; +} + +Fl_Check_Button *btnEnable_auto_connect=(Fl_Check_Button *)0; + +static void cb_btnEnable_auto_connect(Fl_Check_Button* o, void*) { + if(o->value()) { + progdefaults.tcp_udp_auto_connect = true; +} +else { + progdefaults.tcp_udp_auto_connect = false; +} + +progdefaults.changed = true; } Fl_Input2 *txtArq_ip_address=(Fl_Input2 *)0; @@ -6851,7 +6897,7 @@ ab and newline are automatically included.")); o->box(FL_ENGRAVED_FRAME); o->align(Fl_Align(FL_ALIGN_TOP|FL_ALIGN_INSIDE)); { Fl_Check_Button* o = btn_dockable_macros = new Fl_Check_Button(152, 353, 296, 20, _("Disable dockable macro bar")); - btn_dockable_macros->tooltip(_("Allow minimized main dialog height \n411 pixels with WF height = 100")); + btn_dockable_macros->tooltip(_("Allow minimized main dialog height\n411 pixels with WF height = 100")); btn_dockable_macros->down_box(FL_DOWN_BOX); btn_dockable_macros->callback((Fl_Callback*)cb_btn_dockable_macros); o->value(!progdefaults.dockable_macros); @@ -7381,7 +7427,6 @@ i on a\ntouch screen device such as a tablet.")); tabsWaterfall->color(FL_LIGHT1); tabsWaterfall->selection_color(FL_LIGHT1); { Fl_Group* o = new Fl_Group(0, 50, 600, 335, _("Display")); - o->hide(); { Fl_Group* o = new Fl_Group(50, 63, 496, 190, _("Colors and cursors")); o->box(FL_ENGRAVED_FRAME); o->align(Fl_Align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE)); @@ -7577,6 +7622,7 @@ i on a\ntouch screen device such as a tablet.")); o->end(); } // Fl_Group* o { Fl_Group* o = new Fl_Group(0, 50, 600, 335, _("FFT Processing")); + o->hide(); { Fl_Group* o = new Fl_Group(55, 71, 490, 135); o->box(FL_ENGRAVED_FRAME); { Fl_Counter2* o = cntLowFreqCutoff = new Fl_Counter2(100, 89, 70, 22, _("Lower limit")); @@ -7775,7 +7821,6 @@ i on a\ntouch screen device such as a tablet.")); tabsModems->selection_color(FL_LIGHT1); tabsModems->align(Fl_Align(FL_ALIGN_TOP_RIGHT)); { tabCW = new Fl_Group(0, 50, 600, 335, _("CW")); - tabCW->hide(); { tabsCW = new Fl_Tabs(0, 50, 600, 335); tabsCW->selection_color(FL_LIGHT1); { Fl_Group* o = new Fl_Group(0, 75, 600, 310, _("General")); @@ -9218,7 +9263,6 @@ i on a\ntouch screen device such as a tablet.")); tabsRTTY->selection_color(FL_LIGHT1); { Fl_Group* o = new Fl_Group(0, 75, 600, 310, _("Tx")); o->align(Fl_Align(FL_ALIGN_TOP_LEFT)); - o->hide(); { Fl_ListBox* o = selShift = new Fl_ListBox(65, 104, 100, 20, _("Carrier shift")); selShift->tooltip(_("Select carrier shift")); selShift->box(FL_DOWN_BOX); @@ -9374,6 +9418,7 @@ i on a\ntouch screen device such as a tablet.")); } // Fl_Group* o { Fl_Group* o = new Fl_Group(0, 75, 600, 310, _("Rx")); o->align(Fl_Align(FL_ALIGN_TOP_LEFT)); + o->hide(); { Fl_Group* o = new Fl_Group(32, 101, 535, 69, _("Receive")); o->box(FL_ENGRAVED_FRAME); o->align(Fl_Align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE)); @@ -9609,9 +9654,9 @@ le Earth)")); tabTHOR->end(); } // Fl_Group* tabTHOR { tabOther = new Fl_Group(0, 50, 600, 335, _("Other")); + tabOther->hide(); { tabsOther = new Fl_Tabs(0, 50, 600, 335); { tabNavtex = new Fl_Group(0, 75, 600, 310, _("Nav")); - tabNavtex->hide(); { Fl_Check_Button* o = btnNvtxAdifLog = new Fl_Check_Button(181, 109, 235, 30, _("Log Navtex messages to Adif file")); btnNvtxAdifLog->down_box(FL_DOWN_BOX); btnNvtxAdifLog->callback((Fl_Callback*)cb_btnNvtxAdifLog); @@ -9695,6 +9740,7 @@ le Earth)")); tabWefax->end(); } // Fl_Group* tabWefax { tabDFTscan = new Fl_Group(0, 75, 600, 310, _("Scan")); + tabDFTscan->hide(); { Fl_Counter* o = cnt_dft_scans = new Fl_Counter(235, 154, 132, 21, _("# scans")); cnt_dft_scans->minimum(10); cnt_dft_scans->maximum(1000); @@ -9735,7 +9781,6 @@ le Earth)")); tabsRig->selection_color(FL_LIGHT1); { Fl_Group* o = new Fl_Group(0, 50, 600, 335, _("RigCAT")); o->tooltip(_("Rig Control using xml spec file")); - o->hide(); { chkUSERIGCAT = new Fl_Check_Button(245, 60, 110, 20, _("Use RigCAT")); chkUSERIGCAT->tooltip(_("RigCAT used for rig control")); chkUSERIGCAT->down_box(FL_DOWN_BOX); @@ -10372,6 +10417,7 @@ definition")); tabXMLRPC->end(); } // Fl_Group* tabXMLRPC { tabFLRIG = new Fl_Group(0, 50, 600, 335, _("flrig")); + tabFLRIG->hide(); { Fl_Output* o = new Fl_Output(75, 77, 465, 58); o->tooltip(_("\" \"")); o->type(12); @@ -10669,7 +10715,6 @@ nce.\nYou may change the state from either location.\n...")); tabID->hide(); { tabsID = new Fl_Tabs(0, 25, 600, 360); { tabRsID = new Fl_Group(0, 50, 600, 335, _("RsID")); - tabRsID->hide(); { Fl_Group* o = new Fl_Group(32, 55, 535, 210, _("Reed-Solomon ID (Rx)")); o->box(FL_ENGRAVED_FRAME); o->align(Fl_Align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE)); @@ -10870,6 +10915,7 @@ gured on the\n\"Notifications\" configure dialog.")); tabVideoID->end(); } // Fl_Group* tabVideoID { tabCwID = new Fl_Group(0, 50, 600, 335, _("CW")); + tabCwID->hide(); { sld = new Fl_Group(32, 146, 536, 127, _("CW Postamble ID")); sld->box(FL_ENGRAVED_FRAME); sld->align(Fl_Align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE)); @@ -11517,7 +11563,6 @@ and restarted if needed.")); tabQRZ->hide(); { tabsQRZ = new Fl_Tabs(0, 25, 600, 360); { Fl_Group* o = new Fl_Group(0, 50, 600, 335, _("Call Lookup")); - o->hide(); { Fl_Group* o = new Fl_Group(34, 56, 538, 122, _("Web Browser lookup")); o->box(FL_ENGRAVED_FRAME); o->align(Fl_Align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE)); @@ -11696,6 +11741,7 @@ and restarted if needed.")); o->end(); } // Fl_Group* o { Fl_Group* o = new Fl_Group(0, 50, 600, 335, _("eQSL")); + o->hide(); { Fl_Input2* o = inpEQSL_id = new Fl_Input2(225, 58, 150, 20, _("User ID")); inpEQSL_id->tooltip(_("Your login name")); inpEQSL_id->box(FL_DOWN_BOX); @@ -12027,7 +12073,7 @@ and restarted if needed.")); btnEnable_arq->type(102); btnEnable_arq->down_box(FL_DOWN_BOX); btnEnable_arq->callback((Fl_Callback*)cb_btnEnable_arq); - if(progdefaults.data_io_enabled == ARQ_IO) o->value(true); + if(progStatus.data_io_enabled == ARQ_IO) o->value(true); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Check_Button* btnEnable_arq { Fl_Check_Button* o = btnEnable_kiss = new Fl_Check_Button(221, 112, 115, 20, _("Enable KISS")); @@ -12035,7 +12081,7 @@ and restarted if needed.")); btnEnable_kiss->type(102); btnEnable_kiss->down_box(FL_DOWN_BOX); btnEnable_kiss->callback((Fl_Callback*)cb_btnEnable_kiss); - if(progdefaults.data_io_enabled == KISS_IO) o->value(true); + if(progStatus.data_io_enabled == KISS_IO) o->value(true); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Check_Button* btnEnable_kiss { Fl_Check_Button* o = btnEnable_ax25_decode = new Fl_Check_Button(346, 112, 115, 20, _("AX25 Decode")); @@ -12049,7 +12095,7 @@ and restarted if needed.")); btnEnable_csma->tooltip(_("Used for BPQ32")); btnEnable_csma->down_box(FL_DOWN_BOX); btnEnable_csma->callback((Fl_Callback*)cb_btnEnable_csma); - if(progdefaults.csma_enabled) o->value(true); + if(progStatus.csma_enabled) o->value(true); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Check_Button* btnEnable_csma { new Fl_Box(8, 37, 582, 72, _("Enable ARQ for programs that support TCP and FLDIGI ARQ protocol.\nEnable KIS\ @@ -12062,12 +12108,12 @@ s require program restart.")); { Fl_Group* o = new Fl_Group(6, 138, 588, 85, _("KISS")); o->box(FL_ENGRAVED_FRAME); o->align(Fl_Align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE)); - { Fl_Button* o = btnDefault_kiss_ip = new Fl_Button(425, 193, 73, 25, _("Default")); + { Fl_Button* o = btnDefault_kiss_ip = new Fl_Button(505, 195, 80, 25, _("Default")); btnDefault_kiss_ip->tooltip(_("Returns IP Address and port\nnumber to the default value.")); btnDefault_kiss_ip->callback((Fl_Callback*)cb_btnDefault_kiss_ip); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Button* btnDefault_kiss_ip - { Fl_Input2* o = txtKiss_ip_address = new Fl_Input2(56, 193, 230, 25, _("Addr")); + { Fl_Input2* o = txtKiss_ip_address = new Fl_Input2(55, 195, 230, 25, _("Addr")); txtKiss_ip_address->tooltip(_("IP Address for KISS interface\nIP Address format: nnn.nnn.nnn.nnn\nor name: i\ .e. localhost")); txtKiss_ip_address->box(FL_DOWN_BOX); @@ -12097,7 +12143,7 @@ s require program restart.")); update_kpsql_fractional_gain(progdefaults.kpsql_attenuation); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Counter* cntKPSQLAttenuation - { Fl_Input2* o = txtKiss_ip_io_port_no = new Fl_Input2(333, 164, 55, 25, _("I/O")); + { Fl_Input2* o = txtKiss_ip_io_port_no = new Fl_Input2(330, 195, 55, 25, _("I/O")); txtKiss_ip_io_port_no->tooltip(_("IP Address Port Number")); txtKiss_ip_io_port_no->box(FL_DOWN_BOX); txtKiss_ip_io_port_no->color(FL_BACKGROUND2_COLOR); @@ -12125,7 +12171,7 @@ s require program restart.")); o->step(1,10); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Counter* cntBusyChannelSeconds - { Fl_Check_Button* o = btnEnableBusyChannel = new Fl_Check_Button(331, 145, 65, 15, _("Busy")); + { Fl_Check_Button* o = btnEnableBusyChannel = new Fl_Check_Button(235, 145, 65, 15, _("Busy")); btnEnableBusyChannel->tooltip(_("Enable Busy Channel")); btnEnableBusyChannel->down_box(FL_DOWN_BOX); btnEnableBusyChannel->callback((Fl_Callback*)cb_btnEnableBusyChannel); @@ -12133,7 +12179,7 @@ s require program restart.")); else o->value(false); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Check_Button* btnEnableBusyChannel - { Fl_Input2* o = txtKiss_ip_out_port_no = new Fl_Input2(333, 193, 55, 25, _("O")); + { Fl_Input2* o = txtKiss_ip_out_port_no = new Fl_Input2(425, 195, 55, 25, _("O")); txtKiss_ip_out_port_no->tooltip(_("Output port number when same IP address used")); txtKiss_ip_out_port_no->box(FL_DOWN_BOX); txtKiss_ip_out_port_no->color(FL_BACKGROUND2_COLOR); @@ -12149,7 +12195,7 @@ s require program restart.")); o->value(progdefaults.kiss_out_port.c_str()); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Input2* txtKiss_ip_out_port_no - { Fl_Check_Button* o = btnEnable_dual_port = new Fl_Check_Button(485, 169, 90, 16, _("Dual Port")); + { Fl_Check_Button* o = btnEnable_dual_port = new Fl_Check_Button(360, 145, 55, 16, _("DP")); btnEnable_dual_port->tooltip(_("Enable when both programs are using the same IP address")); btnEnable_dual_port->down_box(FL_DOWN_BOX); btnEnable_dual_port->callback((Fl_Callback*)cb_btnEnable_dual_port); @@ -12161,23 +12207,23 @@ s require program restart.")); btn_restart_kiss->hide(); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Button* btn_restart_kiss - { Fl_Button* o = btn_connect_kiss_io = new Fl_Button(504, 193, 82, 25, _("Connect")); + { Fl_Button* o = btn_connect_kiss_io = new Fl_Button(504, 165, 82, 25, _("Start")); btn_connect_kiss_io->tooltip(_("Return KISS TCP IO connection to a Listening state")); btn_connect_kiss_io->callback((Fl_Callback*)cb_btn_connect_kiss_io); - (progStatus.ip_lock || !progStatus.kiss_tcp_io) ? o->deactivate() : o->activate(); + (progStatus.ip_lock || !progdefaults.kiss_tcp_io) ? o->deactivate() : o->activate(); } // Fl_Button* btn_connect_kiss_io - { Fl_Check_Button* o = btnKissTCPIO = new Fl_Check_Button(425, 145, 60, 15, _("TCP")); + { Fl_Check_Button* o = btnKissTCPIO = new Fl_Check_Button(420, 145, 60, 15, _("TCP")); btnKissTCPIO->tooltip(_("Check to enable TCP/IP IO Connection")); btnKissTCPIO->down_box(FL_DOWN_BOX); btnKissTCPIO->callback((Fl_Callback*)cb_btnKissTCPIO); - if(progStatus.kiss_tcp_io) o->value(true); else o->value(false); + if(progdefaults.kiss_tcp_io) o->value(true); else o->value(false); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Check_Button* btnKissTCPIO - { Fl_Check_Button* o = btnKissUDPIO = new Fl_Check_Button(425, 170, 60, 15, _("UDP")); + { Fl_Check_Button* o = btnKissUDPIO = new Fl_Check_Button(295, 145, 60, 15, _("UDP")); btnKissUDPIO->tooltip(_("Check to enable UDP/IP IO")); btnKissUDPIO->down_box(FL_DOWN_BOX); btnKissUDPIO->callback((Fl_Callback*)cb_btnKissUDPIO); - if(progStatus.kiss_tcp_io) o->value(true); else o->value(false); + if(progdefaults.kiss_tcp_io) o->value(true); else o->value(false); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Check_Button* btnKissUDPIO { Fl_Check_Button* o = btnKissTCPListen = new Fl_Check_Button(485, 145, 95, 15, _("Listen / Bind")); @@ -12187,6 +12233,20 @@ s require program restart.")); if(progStatus.kiss_tcp_listen) o->value(true); else o->value(false); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Check_Button* btnKissTCPListen + { Fl_Check_Button* o = btnEnable_7bit_modem_inhibit = new Fl_Check_Button(295, 169, 140, 16, _("Inhibit 7bit Modem")); + btnEnable_7bit_modem_inhibit->tooltip(_("Inhibit 7 bit modem change notice on user or RSID reception")); + btnEnable_7bit_modem_inhibit->down_box(FL_DOWN_BOX); + btnEnable_7bit_modem_inhibit->callback((Fl_Callback*)cb_btnEnable_7bit_modem_inhibit); + if(progdefaults.kiss_io_modem_change_inhibit) o->value(true); else o->value(false); + progStatus.ip_lock ? o->deactivate() : o->activate(); + } // Fl_Check_Button* btnEnable_7bit_modem_inhibit + { Fl_Check_Button* o = btnEnable_auto_connect = new Fl_Check_Button(445, 169, 45, 16, _("AC")); + btnEnable_auto_connect->tooltip(_("Connect to host program on FLDIGI start up")); + btnEnable_auto_connect->down_box(FL_DOWN_BOX); + btnEnable_auto_connect->callback((Fl_Callback*)cb_btnEnable_auto_connect); + if(progdefaults.tcp_udp_auto_connect) o->value(true); else o->value(false); + progStatus.ip_lock ? o->deactivate() : o->activate(); + } // Fl_Check_Button* btnEnable_auto_connect o->end(); } // Fl_Group* o { Fl_Group* o = new Fl_Group(6, 225, 588, 35, _("ARQ")); @@ -12209,7 +12269,7 @@ e. localhost")); o->value(progdefaults.arq_address.c_str()); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Input2* txtArq_ip_address - { Fl_Input2* o = txtArq_ip_port_no = new Fl_Input2(333, 229, 55, 25, _("Port")); + { Fl_Input2* o = txtArq_ip_port_no = new Fl_Input2(330, 229, 55, 25, _("Port")); txtArq_ip_port_no->tooltip(_("IP Address Port Number")); txtArq_ip_port_no->box(FL_DOWN_BOX); txtArq_ip_port_no->color(FL_BACKGROUND2_COLOR); @@ -12265,7 +12325,7 @@ e. localhost")); o->value(progdefaults.xmlrpc_address.c_str()); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Input2* txtXmlrpc_ip_address - { Fl_Input2* o = txtXmlrpc_ip_port_no = new Fl_Input2(333, 270, 55, 25, _("Port")); + { Fl_Input2* o = txtXmlrpc_ip_port_no = new Fl_Input2(330, 270, 55, 25, _("Port")); txtXmlrpc_ip_port_no->tooltip(_("IP Address Port Number")); txtXmlrpc_ip_port_no->box(FL_DOWN_BOX); txtXmlrpc_ip_port_no->color(FL_BACKGROUND2_COLOR); @@ -12313,7 +12373,7 @@ i.e. localhost")); o->value(progdefaults.flrig_ip_address.c_str()); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Input2* txt_flrig_ip_address - { Fl_Input2* o = txt_flrig_ip_port = new Fl_Input2(333, 309, 55, 25, _("Port")); + { Fl_Input2* o = txt_flrig_ip_port = new Fl_Input2(330, 309, 55, 25, _("Port")); txt_flrig_ip_port->tooltip(_("IP Address Port Number")); txt_flrig_ip_port->box(FL_DOWN_BOX); txt_flrig_ip_port->color(FL_BACKGROUND2_COLOR); @@ -12346,7 +12406,7 @@ i.e. localhost")); o->value(progdefaults.xmllog_address.c_str()); progStatus.ip_lock ? o->deactivate() : o->activate(); } // Fl_Input* txt_fllog_ip_address - { Fl_Input* o = txt_fllog_ip_port = new Fl_Input(333, 345, 55, 25, _("Port")); + { Fl_Input* o = txt_fllog_ip_port = new Fl_Input(330, 345, 55, 25, _("Port")); txt_fllog_ip_port->tooltip(_("IP Address Port Number")); txt_fllog_ip_port->callback((Fl_Callback*)cb_txt_fllog_ip_port); txt_fllog_ip_port->align(Fl_Align(FL_ALIGN_RIGHT)); diff --git a/src/dialogs/confdialog.fl b/src/dialogs/confdialog.fl index 398ee521..bfcfc937 100644 --- a/src/dialogs/confdialog.fl +++ b/src/dialogs/confdialog.fl @@ -359,7 +359,7 @@ static const char szBaudRates[] = "300|600|1200|2400|4800|9600|19200|38400|57600 static const char szProsigns[] = "~|%|&|+|=|{|}|<|>|[|]| ";} {} Fl_Window {} { label {Fldigi configuration} open - xywh {1076 134 600 415} type Double color 45 selection_color 51 labelsize 18 align 80 non_modal visible + xywh {893 186 600 415} type Double color 45 selection_color 51 labelsize 18 align 80 non_modal visible } { Fl_Tabs tabsConfigure {open xywh {0 0 600 390} color 50 selection_color 50 @@ -1329,7 +1329,7 @@ progdefaults.changed = true;} label {Disable dockable macro bar} callback {progdefaults.dockable_macros = !o->value(); progdefaults.changed = true;} - tooltip {Allow minimized main dialog height + tooltip {Allow minimized main dialog height 411 pixels with WF height = 100} xywh {152 353 296 20} down_box DOWN_BOX code0 {o->value(!progdefaults.dockable_macros);} } @@ -2584,7 +2584,7 @@ UI_select();} } { Fl_Group {} { label Display open - xywh {0 50 600 335} hide + xywh {0 50 600 335} } { Fl_Group {} { label {Colors and cursors} open @@ -2825,7 +2825,7 @@ progdefaults.changed = true;} } Fl_Group {} { label {FFT Processing} open - xywh {0 50 600 335} + xywh {0 50 600 335} hide } { Fl_Group {} {open xywh {55 71 490 135} box ENGRAVED_FRAME @@ -2970,7 +2970,7 @@ behaves inside the waterfall} xywh {65 207 150 22} box DOWN_BOX color 7 align 8 } { Fl_Group tabCW { label CW - xywh {0 50 600 335} hide + xywh {0 50 600 335} } { Fl_Tabs tabsCW {open xywh {0 50 600 335} selection_color 50 @@ -4285,7 +4285,7 @@ progdefaults.changed = true;} } { Fl_Group {} { label Tx open - xywh {0 75 600 310} align 5 hide + xywh {0 75 600 310} align 5 } { Fl_Group selShift { label {Carrier shift} @@ -4408,7 +4408,7 @@ if (o->value()) { } Fl_Group {} { label Rx open - xywh {0 75 600 310} align 5 + xywh {0 75 600 310} align 5 hide } { Fl_Group {} { label Receive open @@ -4634,14 +4634,14 @@ progdefaults.changed = true;} } Fl_Group tabOther { label Other open - xywh {0 50 600 335} + xywh {0 50 600 335} hide } { Fl_Tabs tabsOther {open xywh {0 50 600 335} } { Fl_Group tabNavtex { label Nav - xywh {0 75 600 310} hide + xywh {0 75 600 310} } { Fl_Check_Button btnNvtxAdifLog { label {Log Navtex messages to Adif file} @@ -4732,7 +4732,7 @@ progdefaults.changed = true;} } Fl_Group tabDFTscan { label Scan - xywh {0 75 600 310} + xywh {0 75 600 310} hide } { Fl_Counter cnt_dft_scans { label {\# scans} @@ -4772,7 +4772,7 @@ progdefaults.changed = true;} } { Fl_Group {} { label RigCAT - tooltip {Rig Control using xml spec file} xywh {0 50 600 335} hide + tooltip {Rig Control using xml spec file} xywh {0 50 600 335} } { Fl_Check_Button chkUSERIGCAT { label {Use RigCAT} @@ -5414,7 +5414,7 @@ when both in same macro definition} xywh {210 239 90 21} type Simple align 8 min } Fl_Group tabFLRIG { label flrig open - xywh {0 50 600 335} + xywh {0 50 600 335} hide } { Fl_Output {} { tooltip {" "} xywh {75 77 465 58} type Multiline box BORDER_BOX color 50 align 0 @@ -5735,7 +5735,7 @@ progdefaults.changed = true;} open } { Fl_Group tabRsID { label RsID open - xywh {0 50 600 335} hide + xywh {0 50 600 335} } { Fl_Group {} { label {Reed-Solomon ID (Rx)} open @@ -5948,7 +5948,7 @@ progdefaults.changed = true;} } Fl_Group tabCwID { label CW - xywh {0 50 600 335} + xywh {0 50 600 335} hide } { Fl_Group sld { label {CW Postamble ID} open @@ -6563,7 +6563,7 @@ if (progdefaults.kml_enabled) { } { Fl_Group {} { label {Call Lookup} open - xywh {0 50 600 335} hide + xywh {0 50 600 335} } { Fl_Group {} { label {Web Browser lookup} open @@ -6736,7 +6736,7 @@ progdefaults.changed= true;} } Fl_Group {} { label eQSL open - xywh {0 50 600 335} + xywh {0 50 600 335} hide } { Fl_Input inpEQSL_id { label {User ID} @@ -7049,35 +7049,34 @@ kiss_io_set_button_state(0);} Fl_Check_Button btnEnable_arq { label {Enable ARQ} callback {if(o->value()) { - progdefaults.changed = true; - progdefaults.data_io_enabled = ARQ_IO; - data_io_enabled = ARQ_IO; - enable_disable_kpsql(); + enable_arq(); } progdefaults.changed = true;} tooltip {Used For PSKMail and FLDIGI Suite of Programs} xywh {96 112 115 20} type Radio down_box DOWN_BOX - code0 {if(progdefaults.data_io_enabled == ARQ_IO) o->value(true);} + code0 {if(progStatus.data_io_enabled == ARQ_IO) o->value(true);} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Check_Button btnEnable_kiss { label {Enable KISS} callback {if(o->value()) { - progdefaults.data_io_enabled = KISS_IO; - data_io_enabled = KISS_IO; - enable_disable_kpsql(); + enable_kiss(); } progdefaults.changed = true;} tooltip {Used for BPQ32} xywh {221 112 115 20} type Radio down_box DOWN_BOX - code0 {if(progdefaults.data_io_enabled == KISS_IO) o->value(true);} + code0 {if(progStatus.data_io_enabled == KISS_IO) o->value(true);} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Check_Button btnEnable_ax25_decode { label {AX25 Decode} - callback {if(o->value()) + callback {if(o->value()) { + progStatus.ax25_decode_enabled = true; progdefaults.ax25_decode_enabled = true; -else +} +else { + progStatus.ax25_decode_enabled = false; progdefaults.ax25_decode_enabled = false; +} progdefaults.changed = true;} tooltip {Decode AX25 Packets into human readable form} xywh {346 112 115 20} down_box DOWN_BOX @@ -7087,13 +7086,15 @@ progdefaults.changed = true;} Fl_Check_Button btnEnable_csma { label {Enable CSMA} callback {if(o->value()) { + progStatus.csma_enabled = true; progdefaults.csma_enabled = true; } else { + progStatus.csma_enabled = false; progdefaults.csma_enabled = false; } progdefaults.changed = true;} tooltip {Used for BPQ32} xywh {471 112 115 20} down_box DOWN_BOX - code0 {if(progdefaults.csma_enabled) o->value(true);} + code0 {if(progStatus.csma_enabled) o->value(true);} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Box {} { @@ -7113,16 +7114,17 @@ KISS/ARQ/XML Addr/Port changes require program restart.} callback {set_ip_to_default(KISS_IO); progdefaults.changed = true;} tooltip {Returns IP Address and port -number to the default value.} xywh {425 193 73 25} +number to the default value.} xywh {505 195 80 25} code0 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Input txtKiss_ip_address { label Addr - callback {progdefaults.kiss_address = o->value(); + callback {progStatus.kiss_address = o->value(); +progdefaults.kiss_address = o->value(); progdefaults.changed = true;} tooltip {IP Address for KISS interface IP Address format: nnn.nnn.nnn.nnn -or name: i.e. localhost} xywh {56 193 230 25} align 8 when 1 +or name: i.e. localhost} xywh {55 195 230 25} align 8 when 1 code0 {txtKiss_ip_address->labelsize(FL_NORMAL_SIZE);} code1 {o->value(progdefaults.kiss_address.c_str());} code2 {progStatus.ip_lock ? o->deactivate() : o->activate();} @@ -7130,8 +7132,9 @@ or name: i.e. localhost} xywh {56 193 230 25} align 8 when 1 } Fl_Counter cntKPSQLAttenuation { label {KPSQL Attenuate} - callback {progdefaults.kpsql_attenuation = (int) o->value(); -update_kpsql_fractional_gain(progdefaults.kpsql_attenuation); + callback {progStatus.kpsql_attenuation = (int) o->value(); +progdefaults.kpsql_attenuation = (int) o->value(); +update_kpsql_fractional_gain(progStatus.kpsql_attenuation); progdefaults.changed = true;} tooltip Attenuation xywh {56 169 110 20} align 8 minimum 1 maximum 999 step 1 value 1 code0 {o->value(progdefaults.kpsql_attenuation);} @@ -7141,9 +7144,10 @@ progdefaults.changed = true;} } Fl_Input txtKiss_ip_io_port_no { label {I/O} - callback {progdefaults.kiss_io_port = o->value(); + callback {progStatus.kiss_io_port = o->value(); +progdefaults.kiss_io_port = o->value(); progdefaults.changed = true;} - tooltip {IP Address Port Number} xywh {333 164 55 25} align 8 when 1 + tooltip {IP Address Port Number} xywh {330 195 55 25} align 8 when 1 code0 {txtKiss_ip_io_port_no->labelsize(FL_NORMAL_SIZE);} code1 {o->value(progdefaults.kiss_io_port.c_str());} code2 {progStatus.ip_lock ? o->deactivate() : o->activate();} @@ -7151,7 +7155,8 @@ progdefaults.changed = true;} } Fl_Counter cntBusyChannelSeconds { label Continue - callback {progdefaults.busyChannelSeconds = (int) o->value(); + callback {progStatus.busyChannelSeconds = (int) o->value(); +progdefaults.busyChannelSeconds = (int) o->value(); progdefaults.changed = true;} tooltip {Continue after in seconds} xywh {56 145 110 20} align 8 minimum 1 maximum 999 step 1 value 1 code0 {o->value(progdefaults.busyChannelSeconds);} @@ -7160,35 +7165,44 @@ progdefaults.changed = true;} } Fl_Check_Button btnEnableBusyChannel { label Busy - callback {if(o->value()) + callback {if(o->value()) { + progStatus.enableBusyChannel = true; progdefaults.enableBusyChannel = true; -else +} +else { + progStatus.enableBusyChannel = false; progdefaults.enableBusyChannel = false; +} progdefaults.changed = true;} - tooltip {Enable Busy Channel} xywh {331 145 65 15} down_box DOWN_BOX + tooltip {Enable Busy Channel} xywh {235 145 65 15} down_box DOWN_BOX code0 {if(progdefaults.enableBusyChannel) o->value(true);} code1 {else o->value(false);} code2 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Input txtKiss_ip_out_port_no { label O - callback {progdefaults.kiss_out_port = o->value(); + callback {progStatus.kiss_out_port = o->value(); +progdefaults.kiss_out_port = o->value(); progdefaults.changed = true;} - tooltip {Output port number when same IP address used} xywh {333 193 55 25} align 8 when 1 + tooltip {Output port number when same IP address used} xywh {425 195 55 25} align 8 when 1 code0 {txtKiss_ip_out_port_no->labelsize(FL_NORMAL_SIZE);} code1 {o->value(progdefaults.kiss_out_port.c_str());} code2 {progStatus.ip_lock ? o->deactivate() : o->activate();} class Fl_Input2 } Fl_Check_Button btnEnable_dual_port { - label {Dual Port} - callback {if(o->value()) + label DP + callback {if(o->value()) { + progStatus.kiss_dual_port_enabled = true; progdefaults.kiss_dual_port_enabled = true; -else +} +else { + progStatus.kiss_dual_port_enabled = false; progdefaults.kiss_dual_port_enabled = false; +} progdefaults.changed = true;} - tooltip {Enable when both programs are using the same IP address} xywh {485 169 90 16} down_box DOWN_BOX + tooltip {Enable when both programs are using the same IP address} xywh {360 145 55 16} down_box DOWN_BOX code0 {if(progdefaults.kiss_dual_port_enabled) o->value(true); else o->value(false);} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } @@ -7199,53 +7213,87 @@ progdefaults.changed = true;} code0 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Button btn_connect_kiss_io { - label Connect - callback {connect_to_kiss_io();} - tooltip {Return KISS TCP IO connection to a Listening state} xywh {504 193 82 25} - code0 {(progStatus.ip_lock || !progStatus.kiss_tcp_io) ? o->deactivate() : o->activate();} + label Start + callback {connect_to_kiss_io(true);} + tooltip {Return KISS TCP IO connection to a Listening state} xywh {504 165 82 25} + code0 {(progStatus.ip_lock || !progdefaults.kiss_tcp_io) ? o->deactivate() : o->activate();} } Fl_Check_Button btnKissTCPIO { label TCP callback {if(o->value()) { - progdefaults.kiss_tcp_io = true; progStatus.kiss_tcp_io = true; + progdefaults.kiss_tcp_io = true; } else { progStatus.kiss_tcp_io = false; progdefaults.kiss_tcp_io = false; } -kiss_io_set_button_state(0);} - tooltip {Check to enable TCP/IP IO Connection} xywh {425 145 60 15} down_box DOWN_BOX - code0 {if(progStatus.kiss_tcp_io) o->value(true); else o->value(false);} +kiss_io_set_button_state(0); +progdefaults.changed = true;} + tooltip {Check to enable TCP/IP IO Connection} xywh {420 145 60 15} down_box DOWN_BOX + code0 {if(progdefaults.kiss_tcp_io) o->value(true); else o->value(false);} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Check_Button btnKissUDPIO { label UDP callback {if(o->value()) { - progdefaults.kiss_tcp_io = false; progStatus.kiss_tcp_io = false; + progdefaults.kiss_tcp_io = false; } else { progStatus.kiss_tcp_io = true; progdefaults.kiss_tcp_io = true; } -kiss_io_set_button_state(0);} - tooltip {Check to enable UDP/IP IO} xywh {425 170 60 15} down_box DOWN_BOX - code0 {if(progStatus.kiss_tcp_io) o->value(true); else o->value(false);} +kiss_io_set_button_state(0); +progdefaults.changed = true;} + tooltip {Check to enable UDP/IP IO} xywh {295 145 60 15} down_box DOWN_BOX + code0 {if(progdefaults.kiss_tcp_io) o->value(true); else o->value(false);} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } Fl_Check_Button btnKissTCPListen { label {Listen / Bind} callback {if(o->value()) { - progdefaults.kiss_tcp_listen = true; progStatus.kiss_tcp_listen = true; + progdefaults.kiss_tcp_listen = true; } else { progStatus.kiss_tcp_listen = false; progdefaults.kiss_tcp_listen = false; -}} +} + +progdefaults.changed = true;} tooltip {Monitor for TCP connection} xywh {485 145 95 15} down_box DOWN_BOX code0 {if(progStatus.kiss_tcp_listen) o->value(true); else o->value(false);} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } + Fl_Check_Button btnEnable_7bit_modem_inhibit { + label {Inhibit 7bit Modem} + callback {if(o->value()) { + progStatus.kiss_io_modem_change_inhibit = true; + progdefaults.kiss_io_modem_change_inhibit = true; +} +else { + progStatus.kiss_io_modem_change_inhibit = false; + progdefaults.kiss_io_modem_change_inhibit = false; +} + +progdefaults.changed = true;} + tooltip {Inhibit 7 bit modem change notice on user or RSID reception} xywh {295 169 140 16} down_box DOWN_BOX + code0 {if(progdefaults.kiss_io_modem_change_inhibit) o->value(true); else o->value(false);} + code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} + } + Fl_Check_Button btnEnable_auto_connect { + label AC + callback {if(o->value()) { + progdefaults.tcp_udp_auto_connect = true; +} +else { + progdefaults.tcp_udp_auto_connect = false; +} + +progdefaults.changed = true;} + tooltip {Connect to host program on FLDIGI start up} xywh {445 169 45 16} down_box DOWN_BOX + code0 {if(progdefaults.tcp_udp_auto_connect) o->value(true); else o->value(false);} + code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} + } } Fl_Group {} { label ARQ open @@ -7267,7 +7315,7 @@ or name: i.e. localhost} xywh {56 229 230 25} align 8 when 1 label Port callback {progdefaults.arq_port = o->value(); progdefaults.changed = true;} - tooltip {IP Address Port Number} xywh {333 229 55 25} align 8 when 1 + tooltip {IP Address Port Number} xywh {330 229 55 25} align 8 when 1 code0 {o->labelsize(FL_NORMAL_SIZE);} code1 {o->value(progdefaults.arq_port.c_str());} code2 {progStatus.ip_lock ? o->deactivate() : o->activate();} @@ -7319,7 +7367,7 @@ or name: i.e. localhost} xywh {56 270 230 25} align 8 when 1 label Port callback {progdefaults.xmlrpc_port = o->value(); progdefaults.changed = true;} - tooltip {IP Address Port Number} xywh {333 270 55 25} align 8 when 1 + tooltip {IP Address Port Number} xywh {330 270 55 25} align 8 when 1 code0 {o->labelsize(FL_NORMAL_SIZE);} code1 {o->value(progdefaults.xmlrpc_port.c_str());} code2 {progStatus.ip_lock ? o->deactivate() : o->activate();} @@ -7360,7 +7408,7 @@ or name: i.e. localhost} xywh {56 309 230 25} align 8 when 1 label Port callback {progdefaults.flrig_ip_port = o->value(); progdefaults.changed = true;} - tooltip {IP Address Port Number} xywh {333 309 55 25} align 8 when 1 + tooltip {IP Address Port Number} xywh {330 309 55 25} align 8 when 1 code0 {o->labelsize(FL_NORMAL_SIZE);} code1 {o->value(progdefaults.flrig_ip_port.c_str());} code2 {progStatus.ip_lock ? o->deactivate() : o->activate();} @@ -7390,7 +7438,7 @@ or name: i.e. localhost} xywh {56 345 230 25} align 8 Fl_Input txt_fllog_ip_port { label Port callback {progdefaults.xmllog_port = o->value();} - tooltip {IP Address Port Number} xywh {333 345 55 25} align 8 + tooltip {IP Address Port Number} xywh {330 345 55 25} align 8 code0 {o->value(progdefaults.xmllog_port.c_str());} code1 {progStatus.ip_lock ? o->deactivate() : o->activate();} } diff --git a/src/dialogs/fl_digi.cxx b/src/dialogs/fl_digi.cxx index c14cbfbf..ef2db184 100644 --- a/src/dialogs/fl_digi.cxx +++ b/src/dialogs/fl_digi.cxx @@ -1450,12 +1450,12 @@ void init_modem(trx_mode mode, int freq) LOG_INFO("Invaild Modem for KISS I/O (%s)", mode_info[mode].sname); - if(!fl_choice2(_("Switch to ARQ I/O"), _("Yes"), _("No"), NULL)) { - btnEnable_kiss->value(false); - btnEnable_kiss->do_callback(); + int _yes = false; + if(!progdefaults.kiss_io_modem_change_inhibit) + _yes = fl_choice2(_("Switch to ARQ I/O"), _("No"), _("Yes"), NULL); - btnEnable_arq->value(true); - btnEnable_arq->do_callback(); + if(_yes) { + enable_arq(); } else { std::string modem_name; modem_name.assign(mode_info[current_mode].sname); @@ -2737,7 +2737,7 @@ void cb_mnuPicViewer(Fl_Menu_ *, void *) { void cb_sldrSquelch(Fl_Slider* o, void*) { - if(progStatus.pwrsqlonoff) { + if(progStatus.kpsql_enabled) { progStatus.sldrPwrSquelchValue = o->value(); } else { progStatus.sldrSquelchValue = o->value(); @@ -3238,18 +3238,23 @@ void cbSQL(Fl_Widget *w, void *vi) void cbPwrSQL(Fl_Widget *w, void *vi) { - if(data_io_enabled == KISS_IO) { + if(progStatus.data_io_enabled == KISS_IO) { FL_LOCK_D(); Fl_Button *b = (Fl_Button *)w; b->activate(); int v = b->value(); - if(!v) + if(!v) { sldrSquelch->value(progStatus.sldrSquelchValue); - else + progStatus.kpsql_enabled = false; + progdefaults.kpsql_enabled = false; + b->clear(); + } else { sldrSquelch->value(progStatus.sldrPwrSquelchValue); - + progStatus.kpsql_enabled = true; + progdefaults.kpsql_enabled = true; + b->set(); + } FL_UNLOCK_D(); - progStatus.pwrsqlonoff = v ? true : false; } else { FL_LOCK_D(); Fl_Button *b = (Fl_Button *)w; @@ -7193,8 +7198,8 @@ void create_fl_digi_main_primary() { btnSQL->tooltip(_("Squelch")); btnPSQL->selection_color(progdefaults.Sql1Color); + btnPSQL->value(progdefaults.kpsql_enabled); btnPSQL->callback(cbPwrSQL, 0); - btnPSQL->value(1); btnPSQL->tooltip(_("Monitor KISS Pwr Squelch")); if(progdefaults.data_io_enabled == KISS_IO) @@ -7837,7 +7842,7 @@ void create_fl_digi_main_WF_only() { btnSQL->tooltip(_("Squelch")); btnPSQL->selection_color(progdefaults.Sql1Color); btnPSQL->callback(cbPwrSQL, 0); - btnPSQL->value(1); + btnPSQL->value(progdefaults.kpsql_enabled); btnPSQL->tooltip(_("Monitor KISS Pwr Squelch")); if(progdefaults.data_io_enabled == KISS_IO) @@ -7948,7 +7953,7 @@ static void callback_set_metric(double metric) if (active_modem->get_mode() == MODE_IFKP) ifkp_s2n_progress->value(metric); - if(progStatus.pwrsqlonoff) { + if(progStatus.kpsql_enabled) { if ((metric >= progStatus.sldrPwrSquelchValue) || inhibit_tx_seconds) btnPSQL->selection_color(progdefaults.Sql2Color); else @@ -9127,21 +9132,33 @@ void notch_off() void enable_kiss(void) { + if(btnEnable_arq->value()) { + btnEnable_arq->value(false); + } + progdefaults.changed = true; progdefaults.data_io_enabled = KISS_IO; + progStatus.data_io_enabled = KISS_IO; data_io_enabled = KISS_IO; + btnEnable_kiss->value(true); - btnEnable_arq->value(false); + enable_disable_kpsql(); } void enable_arq(void) { + if(btnEnable_kiss->value()) { + btnEnable_kiss->value(false); + } + progdefaults.changed = true; progdefaults.data_io_enabled = ARQ_IO; + progStatus.data_io_enabled = ARQ_IO; data_io_enabled = ARQ_IO; + btnEnable_arq->value(true); - btnEnable_kiss->value(false); + enable_disable_kpsql(); } @@ -9150,12 +9167,16 @@ void enable_disable_kpsql(void) if(progdefaults.data_io_enabled == KISS_IO) { check_kiss_modem(); btnPSQL->activate(); + if(progStatus.kpsql_enabled || progdefaults.kpsql_enabled) { + btnPSQL->value(true); + btnPSQL->do_callback(); + } } else { sldrSquelch->value(progStatus.sldrSquelchValue); - progStatus.pwrsqlonoff = false; - btnPSQL->value(0); + btnPSQL->value(false); btnPSQL->deactivate(); } + progStatus.data_io_enabled = progdefaults.data_io_enabled; } @@ -9175,6 +9196,8 @@ void disable_config_p2p_io_widgets(void) cntBusyChannelSeconds->deactivate(); btnDefault_kiss_ip->deactivate(); btn_restart_kiss->deactivate(); + btnEnable_7bit_modem_inhibit->deactivate(); + btnEnable_auto_connect->deactivate(); txtArq_ip_address->deactivate(); txtArq_ip_port_no->deactivate(); @@ -9213,6 +9236,8 @@ void enable_config_p2p_io_widgets(void) cntBusyChannelSeconds->activate(); btnDefault_kiss_ip->activate(); btn_restart_kiss->activate(); + btnEnable_7bit_modem_inhibit->activate(); + btnEnable_auto_connect->activate(); txtArq_ip_address->activate(); txtArq_ip_port_no->activate(); diff --git a/src/globals/globals.cxx b/src/globals/globals.cxx index b622b20d..1619701b 100644 --- a/src/globals/globals.cxx +++ b/src/globals/globals.cxx @@ -57,7 +57,7 @@ const struct mode_info_t mode_info[NUM_MODES] = { { MODE_DOMINOEX5, &dominoex5_modem, "DOMEX5", "DominoEX 5", "DOMINOEX5", "DOMINO", "DM 5", DISABLED_IO }, { MODE_DOMINOEX8, &dominoex8_modem, "DOMEX8", "DominoEX 8", "DOMINOEX8", "DOMINO", "DM 8", DISABLED_IO }, { MODE_DOMINOEX11, &dominoex11_modem, "DOMX11", "DominoEX 11", "DOMINOEX11", "DOMINO", "DM11", DISABLED_IO }, - { MODE_DOMINOEX16, &dominoex16_modem, "DOMX16", "DominoEX 16", "DOMINOEX16", "DOMINO", "DM16", DISABLED_IO }, + { MODE_DOMINOEX16, &dominoex16_modem, "DOMX16", "DominoEX 16", "DOMINOEX16", "DOMINO", "DM16", ARQ_IO | KISS_IO }, { MODE_DOMINOEX22, &dominoex22_modem, "DOMX22", "DominoEX 22", "DOMINOEX22", "DOMINO", "DM22", ARQ_IO | KISS_IO }, { MODE_DOMINOEX44, &dominoex44_modem, "DOMX44", "DominoEX 44", "DOMINOEX44", "DOMINO", "DM44", ARQ_IO | KISS_IO }, { MODE_DOMINOEX88, &dominoex88_modem, "DOMX88", "DominoEX 88", "DOMINOEX88", "DOMINO", "DM88", ARQ_IO | KISS_IO }, @@ -71,13 +71,13 @@ const struct mode_info_t mode_info[NUM_MODES] = { { MODE_HELL80, &feld_80modem, "HELL80", "Hell 80", "", "HELL80", "HL80", DISABLED_IO }, { MODE_MFSK8, &mfsk8_modem, "MFSK8", "MFSK-8", "MFSK8", "MFSK8", "MK 8", DISABLED_IO }, - { MODE_MFSK16, &mfsk16_modem, "MFSK16", "MFSK-16", "MFSK16", "MFSK16", "MK16", ARQ_IO }, + { MODE_MFSK16, &mfsk16_modem, "MFSK16", "MFSK-16", "MFSK16", "MFSK16", "MK16", ARQ_IO | KISS_IO }, { MODE_MFSK32, &mfsk32_modem, "MFSK32", "MFSK-32", "MFSK32", "MFSK32", "MK32", ARQ_IO | KISS_IO }, { MODE_MFSK4, &mfsk4_modem, "MFSK4", "MFSK-4", "MFSK4", "MFSK4", "MK 4", DISABLED_IO }, { MODE_MFSK11, &mfsk11_modem, "MFSK11", "MFSK-11", "MFSK11", "MFSK11", "MK11", DISABLED_IO }, { MODE_MFSK22, &mfsk22_modem, "MFSK22", "MFSK-22", "MFSK22", "MFSK22", "MK22", DISABLED_IO }, - { MODE_MFSK31, &mfsk31_modem, "MFSK31", "MFSK-31", "MFSK31", "MFSK31", "MK31", ARQ_IO }, + { MODE_MFSK31, &mfsk31_modem, "MFSK31", "MFSK-31", "MFSK31", "MFSK31", "MK31", ARQ_IO | KISS_IO }, { MODE_MFSK64, &mfsk64_modem, "MFSK64", "MFSK-64", "MFSK64", "MFSK64", "MK64", ARQ_IO | KISS_IO }, { MODE_MFSK128, &mfsk128_modem, "MFSK128", "MFSK-128", "MFSK128", "MFSK128", "MK128", ARQ_IO | KISS_IO }, { MODE_MFSK64L, &mfsk64l_modem, "MFSK64L", "MFSK-64L", "MFSK64L", "MFSK64L", "MK64L", ARQ_IO | KISS_IO }, @@ -204,9 +204,9 @@ const struct mode_info_t mode_info[NUM_MODES] = { std::ostream& operator<<(std::ostream& s, const qrg_mode_t& m) { - return s << m.rfcarrier << ' ' - << m.rmode << ' ' - << m.carrier << ' ' + return s << m.rfcarrier << ' ' + << m.rmode << ' ' + << m.carrier << ' ' << mode_info[m.mode].sname << ' ' << m.usage; } diff --git a/src/include/confdialog.h b/src/include/confdialog.h index 1fb8d851..8f7eb9bb 100644 --- a/src/include/confdialog.h +++ b/src/include/confdialog.h @@ -730,6 +730,8 @@ extern Fl_Button *btn_connect_kiss_io; extern Fl_Check_Button *btnKissTCPIO; extern Fl_Check_Button *btnKissUDPIO; extern Fl_Check_Button *btnKissTCPListen; +extern Fl_Check_Button *btnEnable_7bit_modem_inhibit; +extern Fl_Check_Button *btnEnable_auto_connect; extern Fl_Input2 *txtArq_ip_address; extern Fl_Input2 *txtArq_ip_port_no; extern Fl_Button *btnDefault_arq_ip; diff --git a/src/include/configuration.h b/src/include/configuration.h index ea2a57f4..63b5bba0 100644 --- a/src/include/configuration.h +++ b/src/include/configuration.h @@ -1680,17 +1680,26 @@ "Number of seconds to wait before transmit resume", \ 3) \ ELEM_(int, kpsql_attenuation, "KPSQL_ATTENUATION", \ - "KPSQL Attenuation in 1/n of 1:1 Gain", \ - 2) \ + "KPSQL Attenuation in 1/n of 1:1 Gain", \ + 2) \ ELEM_(bool, csma_enabled, "CSMA_ENABLED", \ "Use CSMA on heavy traffic channels (AX25)", \ true) \ - ELEM_(bool, kiss_tcp_io, "KISS_TCP_IO", \ - "Connect kiss io via TCP/IP vise UDP/IP", \ - false) \ + ELEM_(bool, kiss_tcp_io, "KISS_TCP_IO", \ + "Connect kiss io via TCP/IP vise UDP/IP", \ + false) \ ELEM_(bool, kiss_tcp_listen, "KISS_TCP_LISTEN", \ "Listen for TCP connection (Server mode)", \ false) \ + ELEM_(bool, kpsql_enabled, "KPSQL_ENABLED", \ + "Enable/Disable KPSQL", \ + false) \ + ELEM_(bool, tcp_udp_auto_connect, "TCP_UDP_AUTO_CONNECT", \ + "Make Connect Attemp on Fldigi Start", \ + false) \ + ELEM_(bool, kiss_io_modem_change_inhibit, "KISS_IO_MODEM_CHANGE_INHIBIT", \ + "Enable/Disable Modem Change to a non 8 bit when KISS IO is in use", \ + false) \ ELEM_(std::string, flrig_ip_address, "FLRIG_IP_ADDRESS", \ "IP Address of flrig server", \ DEFAULT_FLRIG_IP_ADDRESS) \ diff --git a/src/include/data_io.h b/src/include/data_io.h index b1146e4f..2326adcc 100644 --- a/src/include/data_io.h +++ b/src/include/data_io.h @@ -29,8 +29,6 @@ #include "gettext.h" -#define IO_CONNECT_STR _("Connect") -#define IO_DISCONNECT_STR _("Disc") #define IO_START_STR _("Start") #define IO_STOP_STR _("Stop") @@ -62,7 +60,7 @@ enum {DISABLED_IO, ARQ_IO, KISS_IO, XMLRPC_IO, FLRIG_IO, FLLOG_IO}; // This variable indepent of progdefaults.data_io_enabled // and progStatus.data_io_enabled -// Only on start de we assign this variable with progStatus.data_io_enabled. +// Only on start do we assign this variable with progStatus.data_io_enabled. // This is one way assignment as we dont want to save all of the available states // this variable will have. extern int data_io_enabled; // Located in kiss_io.cxx @@ -80,6 +78,9 @@ extern void WriteKISS(const char data); extern void WriteKISS(const char *data); extern void WriteKISS(const char *data, size_t size); extern void WriteKISS(std::string data); +extern bool kiss_thread_running(void); + +extern bool kiss_auto_connect(void); extern void check_kiss_modem(void); extern int kiss_get_char(void); @@ -91,7 +92,7 @@ extern bool bcast_rsid_kiss_frame(int new_wf_pos, int new_mode, int old_wf_pos, extern void bcast_trxc_kiss_frame(void); extern void update_kpsql_fractional_gain(int value); extern void kiss_io_set_button_state(void *); -extern void connect_to_kiss_io(void); +extern void connect_to_kiss_io(bool); // ARQ implementation extern void arq_init(void); diff --git a/src/include/filters.h b/src/include/filters.h index e279c70c..fcba25c2 100644 --- a/src/include/filters.h +++ b/src/include/filters.h @@ -29,6 +29,9 @@ #define _FILTER_H #include "complex.h" +#ifndef M_PI +#define M_PI (3.1415926535897932385) +#endif //===================================================================== // FIR filters diff --git a/src/include/kiss_io.h b/src/include/kiss_io.h index 2d47ef9d..6c6388c0 100644 --- a/src/include/kiss_io.h +++ b/src/include/kiss_io.h @@ -55,6 +55,9 @@ #define KISS_BUFFER_FACTOR 2 #define HDLC_BUFFER_FACTOR 3 +#define KISS_CONNECT_RETRY_COUNT 10 +#define KISS_RETRY_WAIT_TIME 1000 + #define MAX_TEMP_BUFFER_SIZE 32000 #define TX_BUFFER_TIMEOUT (60 * 10) // Ten minute timeout @@ -147,6 +150,8 @@ static void set_sql_on_off(char *); static void set_trxs_bc_mode(char *); static void set_txbe_bc_mode(char *); static void set_wf_cursor_pos(char *); +static void set_reply_tx_lock(char *); + static void TransmitCSMA(); static void WriteToHostBuffered(const char *data, size_t size); //static void WriteToHostBuffered(const char *data); @@ -167,6 +172,8 @@ void ReadFromHostSocket(void); //static void set_busy_state_bc_mode(char * arg); static void reply_busy_state(char * arg); +bool kiss_thread_running(void); + #ifdef KISS_RX_THREAD static void *ReadFromHostSocket(void *args); #else diff --git a/src/include/socket.h b/src/include/socket.h index 3ffc41b2..4dae0396 100644 --- a/src/include/socket.h +++ b/src/include/socket.h @@ -36,6 +36,9 @@ #else # include # include +# ifndef ENOTCONN +# define ENOTCONN WSAENOTCONN +# endif #endif #include diff --git a/src/include/status.h b/src/include/status.h index 09f38729..651ba305 100644 --- a/src/include/status.h +++ b/src/include/status.h @@ -80,7 +80,6 @@ struct status { double sldrPwrSquelchValue; bool afconoff; bool sqlonoff; - bool pwrsqlonoff; int scopeX; int scopeY; bool scopeVisible; @@ -166,9 +165,12 @@ struct status { bool csma_enabled; bool kiss_tcp_io; bool kiss_tcp_listen; + bool kpsql_enabled; bool ip_lock; + bool kiss_io_modem_change_inhibit; double squelch_value; bool psk8DCDShortFlag; + std::string browser_search; bool meters; diff --git a/src/include/timeops.h b/src/include/timeops.h index 9611cac1..d48ba0db 100644 --- a/src/include/timeops.h +++ b/src/include/timeops.h @@ -24,13 +24,27 @@ #include #include #include + #ifdef __MINGW32__ # include -#else -# if !HAVE_CLOCK_GETTIME - enum clockid_t { CLOCK_REALTIME, CLOCK_MONOTONIC }; - int clock_gettime(clockid_t clock_id, struct timespec* tp); -# endif +#endif + +#if !HAVE_CLOCK_GETTIME +// enum clockid_t { CLOCK_REALTIME, CLOCK_MONOTONIC }; +#ifndef __clockid_t_defined +typedef int clockid_t; +#define __clockid_t_defined 1 +#endif /* __clockid_t_defined */ + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif + +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC 1 +#endif + +int clock_gettime(clockid_t clock_id, struct timespec* tp); #endif struct timespec operator+(const struct timespec &t0, const double &t); diff --git a/src/main.cxx b/src/main.cxx index 0000c323..9fa2fdcb 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -251,16 +251,27 @@ void start_process(string executable) void toggle_io_port_selection(int io_mode) { + switch(io_mode) { case ARQ_IO: - btnEnable_kiss->do_callback(); - btnEnable_arq->do_callback(); - progdefaults.changed = false; - break; + enable_arq(); + progdefaults.changed = false; + break; case KISS_IO: - btnEnable_arq->do_callback(); - btnEnable_kiss->do_callback(); + + enable_kiss(); + + if(progdefaults.tcp_udp_auto_connect) { + btn_connect_kiss_io->value(1); + btn_connect_kiss_io->do_callback(); + } + + if(progdefaults.kpsql_enabled) { + btnPSQL->value(progdefaults.kpsql_enabled); + btnPSQL->do_callback(); + } + progdefaults.changed = false; break; @@ -348,12 +359,12 @@ void delayed_startup(void *) data_io_enabled = DISABLED_IO; arq_init(); - //kiss_init(); + if (progdefaults.connect_to_maclogger) maclogger_init(); data_io_enabled = progStatus.data_io_enabled; - toggle_io_port_selection(data_io_enabled); + disable_config_p2p_io_widgets(); notify_start(); @@ -843,10 +854,10 @@ void generate_option_help(void) { << " The default is: " << progdefaults.data_io_enabled << "\n\n" << " --kiss-server-address HOSTNAME\n" - << " Set the KISS UDP server address\n" + << " Set the KISS TCP/UDP server address\n" << " The default is: " << progdefaults.kiss_address << "\n\n" << " --kiss-server-port-io I/O PORT\n" - << " Set the KISS UDP server I/O port\n" + << " Set the KISS TCP/UDP server I/O port\n" << " The default is: " << progdefaults.kiss_io_port << "\n\n" << " --kiss-server-port-o Output PORT\n" << " Set the KISS UDP server output port\n" diff --git a/src/misc/kiss_io.cxx b/src/misc/kiss_io.cxx index 774b80b4..d6c52e24 100644 --- a/src/misc/kiss_io.cxx +++ b/src/misc/kiss_io.cxx @@ -91,6 +91,7 @@ static pthread_mutex_t to_host_arq_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t to_host_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t to_radio_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t external_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t restart_mutex = PTHREAD_MUTEX_INITIALIZER; bool kiss_enabled = false; bool kiss_exit = false; @@ -130,6 +131,7 @@ bool kiss_bcast_rsid_reception = false; bool kiss_bcast_trx_toggle = false; bool kiss_text_available = false; static bool kiss_reset_flag = false; +static int retry_count = KISS_CONNECT_RETRY_COUNT; #define HISTO_COUNT 256 #define HISTO_THRESH_HOLD 48 @@ -168,6 +170,7 @@ static std::vector availabe_kiss_modems; extern void ax25_decode(unsigned char *buffer, size_t count, bool pad, bool tx_flag); static void kiss_main_thread_close(void *ptr); +static void kiss_main_thread_retry_open(void *ptr); static int kiss_raw_enabled = KISS_RAW_DISABLED; @@ -177,95 +180,96 @@ static int kiss_raw_enabled = KISS_RAW_DISABLED; * between real values and translated values. **********************************************************************************/ static int not_allowed[256] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 16 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 48 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 64 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 96 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 112 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // 128 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 176 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 192 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 208 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 224 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 240 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 // 256 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 16 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 48 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 64 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 96 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 112 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // 128 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 176 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 192 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 208 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 224 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 240 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 // 256 }; /********************************************************************************** * KISS hardware frame commands strings and calling functions **********************************************************************************/ EXEC_HARDWARE_CMD_MATCH exec_match[] = { - { (char *) "BCHN", set_busy_channel_on_off }, - { (char *) "BCHNS", set_busy_channel_duration }, - { (char *) "BUSY", reply_busy_state }, - { (char *) "CSMA", set_csma_mode }, - { (char *) "FLSTAT", reply_fldigi_stat }, - { (char *) "IBCHN", set_busy_channel_inhibit }, - { (char *) "KISSCRCM", set_crc_mode }, - { (char *) "KISSRAW", set_kiss_raw_mode }, - { (char *) "KPSQL", set_kpsql_on_off }, - { (char *) "KPSATT", set_kpsql_fraction_gain }, - { (char *) "KPSQLP", reply_kpsql_pwr_level }, - { (char *) "KPSQLS", set_kpsql_squelch_level }, - { (char *) "MODEM", set_kiss_modem }, - { (char *) "MODEMBW", reply_active_modem_bw }, - { (char *) "MODEML", reply_modem_list }, - { (char *) "RSIDBCAST", set_rsid_bc_mode }, - { (char *) "RSIDM", set_rsid_mode }, - { (char *) "RSIDRX", set_rsid_rx }, - { (char *) "RSIDTX", set_rsid_tx }, - { (char *) "SQL", set_sql_on_off }, - { (char *) "SQLP", reply_sql_pwr_level }, - { (char *) "SQLS", set_sql_level }, - { (char *) "TNC", reply_tnc_name }, - { (char *) "TRXSBCAST", set_trxs_bc_mode }, - { (char *) "TRXS", reply_trx_state }, - { (char *) "TXBEBCAST", set_txbe_bc_mode }, - { (char *) "TXBUF", reply_tx_buffer_count }, - { (char *) "WFBW", reply_waterfall_bw }, - { (char *) "WFF", set_wf_cursor_pos }, - { (char *) 0, 0 } + { (char *) "BCHN", set_busy_channel_on_off }, + { (char *) "BCHNS", set_busy_channel_duration }, + { (char *) "BUSY", reply_busy_state }, + { (char *) "CSMA", set_csma_mode }, + { (char *) "FLSTAT", reply_fldigi_stat }, + { (char *) "IBCHN", set_busy_channel_inhibit }, + { (char *) "KISSCRCM", set_crc_mode }, + { (char *) "KISSRAW", set_kiss_raw_mode }, + { (char *) "KPSQL", set_kpsql_on_off }, + { (char *) "KPSATT", set_kpsql_fraction_gain }, + { (char *) "KPSQLP", reply_kpsql_pwr_level }, + { (char *) "KPSQLS", set_kpsql_squelch_level }, + { (char *) "MODEM", set_kiss_modem }, + { (char *) "MODEMBW", reply_active_modem_bw }, + { (char *) "MODEML", reply_modem_list }, + { (char *) "RSIDBCAST", set_rsid_bc_mode }, + { (char *) "RSIDM", set_rsid_mode }, + { (char *) "RSIDRX", set_rsid_rx }, + { (char *) "RSIDTX", set_rsid_tx }, + { (char *) "SQL", set_sql_on_off }, + { (char *) "SQLP", reply_sql_pwr_level }, + { (char *) "SQLS", set_sql_level }, + { (char *) "TNC", reply_tnc_name }, + { (char *) "TRXSBCAST", set_trxs_bc_mode }, + { (char *) "TRXS", reply_trx_state }, + { (char *) "TXBEBCAST", set_txbe_bc_mode }, + { (char *) "TXBUF", reply_tx_buffer_count }, + { (char *) "TXLOCK", set_reply_tx_lock }, + { (char *) "WFBW", reply_waterfall_bw }, + { (char *) "WFF", set_wf_cursor_pos }, + { (char *) 0, 0 } }; #ifdef USE_NOCTRL static const char *asc[128] = { - "", "", "", "", - "", "", "", "", - "", "", "\n", "", - "", "", "", "", - "", "", "", "", - "", "", "", "", - "", "", "", "", - "", "", "", "", - " ", "!", "\"", "#", - "$", "%", "&", "\'", - "(", ")", "*", "+", - ",", "-", ".", "/", - "0", "1", "2", "3", - "4", "5", "6", "7", - "8", "9", ":", ";", - "<", "=", ">", "?", - "@", "A", "B", "C", - "D", "E", "F", "G", - "H", "I", "J", "K", - "L", "M", "N", "O", - "P", "Q", "R", "S", - "T", "U", "V", "W", - "X", "Y", "Z", "[", - "\\", "]", "^", "_", - "`", "a", "b", "c", - "d", "e", "f", "g", - "h", "i", "j", "k", - "l", "m", "n", "o", - "p", "q", "r", "s", - "t", "u", "v", "w", - "x", "y", "z", "{", - "|", "}", "~", "" + "", "", "", "", + "", "", "", "", + "", "", "\n", "", + "", "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "", "", + "", "", "", "", + " ", "!", "\"", "#", + "$", "%", "&", "\'", + "(", ")", "*", "+", + ",", "-", ".", "/", + "0", "1", "2", "3", + "4", "5", "6", "7", + "8", "9", ":", ";", + "<", "=", ">", "?", + "@", "A", "B", "C", + "D", "E", "F", "G", + "H", "I", "J", "K", + "L", "M", "N", "O", + "P", "Q", "R", "S", + "T", "U", "V", "W", + "X", "Y", "Z", "[", + "\\", "]", "^", "_", + "`", "a", "b", "c", + "d", "e", "f", "g", + "h", "i", "j", "k", + "l", "m", "n", "o", + "p", "q", "r", "s", + "t", "u", "v", "w", + "x", "y", "z", "{", + "|", "}", "~", "" }; /********************************************************************************** @@ -273,20 +277,20 @@ static const char *asc[128] = { **********************************************************************************/ static string noctrl(string src) { - static string retstr; - retstr.clear(); - char hexstr[10]; - int c; - for (size_t i = 0; i < src.length(); i++) { - c = src[i]; - if ( c > 0 && c < 128) - retstr.append(asc[c]); - else { - snprintf(hexstr, sizeof(hexstr), "<%0X>", c & 0xFF); - retstr.append(hexstr); - } - } - return retstr; + static string retstr; + retstr.clear(); + char hexstr[10]; + int c; + for (size_t i = 0; i < src.length(); i++) { + c = src[i]; + if ( c > 0 && c < 128) + retstr.append(asc[c]); + else { + snprintf(hexstr, sizeof(hexstr), "<%0X>", c & 0xFF); + retstr.append(hexstr); + } + } + return retstr; } #endif // USE_NOCTRL @@ -295,46 +299,46 @@ static string noctrl(string src) **********************************************************************************/ static int calc_ccitt_crc(char *buf, int n) { - static int crc_table[] = { - 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, - 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, - 0xcc01, 0xcc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, - 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, - 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, - 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, - 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, - 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, - 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, - 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, - 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, - 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, - 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, - 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, - 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, - 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, - 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, - 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, - 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, - 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, - 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, - 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, - 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, - 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, - 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, - 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, - 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, - 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, - 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, - 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, - 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, - 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040 - }; + static int crc_table[] = { + 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, + 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, + 0xcc01, 0xcc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, + 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, + 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, + 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, + 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, + 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, + 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, + 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, + 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, + 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, + 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, + 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, + 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, + 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, + 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, + 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, + 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, + 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, + 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, + 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, + 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, + 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, + 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, + 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, + 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, + 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, + 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, + 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, + 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, + 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040 + }; - int crc; - crc = 0; - while (--n >= 0) - crc = ((crc >> 8) & 0xff) ^ crc_table[(crc ^ *buf++) & 0xff]; - return crc; + int crc; + crc = 0; + while (--n >= 0) + crc = ((crc >> 8) & 0xff) ^ crc_table[(crc ^ *buf++) & 0xff]; + return crc; } /********************************************************************************** @@ -342,11 +346,11 @@ static int calc_ccitt_crc(char *buf, int n) **********************************************************************************/ static int calc_xor_crc(char *buf, int n) { - int crc; - crc = 0; - while (--n >= 0) - crc ^= (*buf++ & 0xff); - return crc; + int crc; + crc = 0; + while (--n >= 0) + crc ^= (*buf++ & 0xff); + return crc; } /********************************************************************************** @@ -355,46 +359,46 @@ static int calc_xor_crc(char *buf, int n) static int calc_fcs_crc(char *buf, int n) { - static int fcstab[256] = { - 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, - 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, - 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, - 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, - 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, - 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, - 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, - 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, - 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, - 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, - 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, - 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, - 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, - 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, - 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, - 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, - 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, - 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, - 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, - 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, - 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, - 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, - 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, - 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, - 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, - 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, - 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, - 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, - 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, - 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, - 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, - 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 - }; + static int fcstab[256] = { + 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, + 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, + 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, + 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, + 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, + 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, + 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, + 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, + 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, + 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, + 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, + 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, + 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, + 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, + 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, + 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, + 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, + 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, + 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, + 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, + 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, + 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, + 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, + 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, + 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 + }; - int crc; - crc = 0xFFFF; - while (--n >= 0) - crc = ((crc >> 8) & 0xff) ^ fcstab[(crc ^ *buf++) & 0xff]; - return crc; + int crc; + crc = 0xFFFF; + while (--n >= 0) + crc = ((crc >> 8) & 0xff) ^ fcstab[(crc ^ *buf++) & 0xff]; + return crc; } /********************************************************************************** @@ -402,8 +406,8 @@ static int calc_fcs_crc(char *buf, int n) **********************************************************************************/ static void set_button(Fl_Button * button, bool value) { - button->value(value); - button->do_callback(); + button->value(value); + button->do_callback(); } @@ -412,8 +416,8 @@ static void set_button(Fl_Button * button, bool value) **********************************************************************************/ static void set_counter(Fl_Counter * counter, int value) { - counter->value(value); - counter->do_callback(); + counter->value(value); + counter->do_callback(); } /********************************************************************************** @@ -421,8 +425,8 @@ static void set_counter(Fl_Counter * counter, int value) **********************************************************************************/ static void set_slider2(Fl_Slider2 * sider, int value) { - sider->value(value); - sider->do_callback(); + sider->value(value); + sider->do_callback(); } /********************************************************************************** @@ -430,33 +434,40 @@ static void set_slider2(Fl_Slider2 * sider, int value) **********************************************************************************/ bool valid_kiss_modem(string _modem) { - if(_modem.empty()) return false; + if(_modem.empty()) return false; - int index = 0; - int count = availabe_kiss_modems.size(); + int index = 0; + int count = availabe_kiss_modems.size(); + std::string _tmp_str; if(count < 1) { - for(index = 0; index < NUM_MODES; index++) - if(mode_info[index].iface_io & KISS_IO) - availabe_kiss_modems.push_back(mode_info[index].sname); + + for(index = 0; index < NUM_MODES; index++) { + if(mode_info[index].iface_io & KISS_IO) { + _tmp_str = uppercase_string(mode_info[index].sname); + availabe_kiss_modems.push_back(_tmp_str); + } + } count = availabe_kiss_modems.size(); } - std::string cmp_str = ""; + std::string cmp_str = ""; index = 0; - while(index < count) { - cmp_str = uppercase_string(availabe_kiss_modems[index]); - if(cmp_str.empty()) return false; + _modem = uppercase_string(_modem); - if(_modem.compare(cmp_str) == 0) { - return true; - } + while(index < count) { + cmp_str = availabe_kiss_modems[index]; + if(cmp_str.empty()) return false; - index++; - } + if(_modem.compare(cmp_str) == 0) { + return true; + } - return false; + index++; + } + + return false; } /********************************************************************************** @@ -464,13 +475,13 @@ bool valid_kiss_modem(string _modem) **********************************************************************************/ void check_kiss_modem(void) { - int mode = active_modem->get_mode(); - std::string modem_name; - modem_name.assign(mode_info[mode].sname); - bool valid = valid_kiss_modem(modem_name); + int mode = active_modem->get_mode(); + std::string modem_name; + modem_name.assign(mode_info[mode].sname); + bool valid = valid_kiss_modem(modem_name); - if(!valid) - set_default_kiss_modem(); + if(!valid) + set_default_kiss_modem(); } /********************************************************************************** @@ -478,7 +489,7 @@ void check_kiss_modem(void) **********************************************************************************/ static void set_default_kiss_modem(void) { - set_kiss_modem((char *) default_kiss_modem.c_str()); + set_kiss_modem((char *) default_kiss_modem.c_str()); } @@ -487,19 +498,19 @@ static void set_default_kiss_modem(void) **********************************************************************************/ inline std::string uppercase_string(std::string str) { - int index = 0; - int count = str.size(); - std::string ret_str = ""; + int index = 0; + int count = str.size(); + std::string ret_str = ""; - if(!count) return ret_str; + if(!count) return ret_str; - ret_str.reserve(count + 1); - ret_str.clear(); + ret_str.reserve(count + 1); + ret_str.clear(); - for(index = 0; index < count; index++) - ret_str += toupper(str[index]); + for(index = 0; index < count; index++) + ret_str += toupper(str[index]); - return ret_str; + return ret_str; } /********************************************************************************** @@ -507,35 +518,37 @@ inline std::string uppercase_string(std::string str) **********************************************************************************/ static void set_kiss_modem(char * arg) { - if(!arg) return; + if(!arg) return; - std::string _modem = ""; - std::string _cmp_modem = ""; + std::string _modem = ""; + std::string _cmp_modem = ""; - _modem.assign(arg); + _modem.assign(arg); - if(_modem.empty()) { - return reply_active_modem(arg); - } + if(_modem.empty()) { + return reply_active_modem(arg); + } - bool valid = valid_kiss_modem(_modem); + bool valid = valid_kiss_modem(_modem); - if(valid) { - for (size_t i = 0; i < NUM_MODES; i++) { - _cmp_modem = uppercase_string(mode_info[i].sname); - if (_modem == _cmp_modem) { - REQ_SYNC(init_modem_sync, i, 0); - kiss_modem.assign(_modem); - break; - } - } - return; - } + _modem = uppercase_string(_modem); - if(!valid) - LOG_INFO("Modem %s invalid for KISS use. Must support 8bit.", _modem.c_str()); + if(valid) { + for (size_t i = 0; i < NUM_MODES; i++) { + _cmp_modem = uppercase_string(mode_info[i].sname); + if (_modem == _cmp_modem) { + REQ_SYNC(init_modem_sync, i, 0); + kiss_modem.assign(_modem); + break; + } + } + return; + } - return; + if(!valid) + LOG_INFO("Modem %s invalid for KISS use. Must support 8bit.", _modem.c_str()); + + return; } /********************************************************************************** @@ -543,45 +556,45 @@ static void set_kiss_modem(char * arg) **********************************************************************************/ static void reply_fldigi_stat(char *arg) { - std::string package = ""; - std::string cmd = "FLSTAT:"; + std::string package = ""; + std::string cmd = "FLSTAT:"; - unsigned int hours = 0; - unsigned int mins = 0; - unsigned int secs = 0; + unsigned int hours = 0; + unsigned int mins = 0; + unsigned int secs = 0; - time_t current_time = time(0); - time_t diff_time = 0; + time_t current_time = time(0); + time_t diff_time = 0; - char buffer[64]; + char buffer[64]; - package.assign(cmd); + package.assign(cmd); - if(program_started_flag) { - package.append("OK"); - } else { - package.append("INIT"); - program_started_flag = true; - } + if(program_started_flag) { + package.append("OK"); + } else { + package.append("INIT"); + program_started_flag = true; + } - if(program_start_time == 0) - program_start_time = time(0); + if(program_start_time == 0) + program_start_time = time(0); - diff_time = current_time - program_start_time; + diff_time = current_time - program_start_time; - hours = (unsigned int) (diff_time / 3600); - diff_time -= (time_t) (hours * 3600); + hours = (unsigned int) (diff_time / 3600); + diff_time -= (time_t) (hours * 3600); - mins = (unsigned int)(diff_time / 60); - diff_time -= (time_t) (mins * 60); + mins = (unsigned int)(diff_time / 60); + diff_time -= (time_t) (mins * 60); - secs = (unsigned int) diff_time; + secs = (unsigned int) diff_time; - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, ",%02u:%02u:%02u", hours, mins, secs); - package.append(buffer); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer)-1, ",%02u:%02u:%02u", hours, mins, secs); + package.append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } @@ -591,26 +604,26 @@ static void reply_fldigi_stat(char *arg) **********************************************************************************/ static void set_csma_mode(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string rsid_tx_state = ""; - rsid_tx_state.assign(arg); + std::string rsid_tx_state = ""; + rsid_tx_state.assign(arg); - if(rsid_tx_state.empty()) - return reply_csma_mode(arg); + if(rsid_tx_state.empty()) + return reply_csma_mode(arg); - std::string state = uppercase_string(rsid_tx_state); + std::string state = uppercase_string(rsid_tx_state); - if(state.find("ON") != std::string::npos) { - REQ(set_button, btnEnable_csma, 1); - return; - } + if(state.find("ON") != std::string::npos) { + REQ(set_button, btnEnable_csma, 1); + return; + } - if(state.find("OFF") != std::string::npos) { - REQ(set_button, btnEnable_csma, 0); - return; - } + if(state.find("OFF") != std::string::npos) { + REQ(set_button, btnEnable_csma, 0); + return; + } } /********************************************************************************** @@ -618,17 +631,17 @@ static void set_csma_mode(char * arg) **********************************************************************************/ static void reply_csma_mode(char *arg) { - std::string package = ""; - std::string cmd = "CSMA:"; + std::string package = ""; + std::string cmd = "CSMA:"; - package.assign(cmd); + package.assign(cmd); - if(progdefaults.csma_enabled) - package.append("ON"); - else - package.append("OFF"); + if(progdefaults.csma_enabled) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } @@ -640,38 +653,38 @@ static void reply_csma_mode(char *arg) **********************************************************************************/ static void set_busy_channel_inhibit(char *arg) { - std::string argstr = ""; - time_t temp = 0; + std::string argstr = ""; + time_t temp = 0; - if(arg) { - argstr.assign(arg); - if(!argstr.empty()) { - if(argstr[0] == 'I' || argstr[0] == 'i') { - if(progdefaults.enableBusyChannel && inhibit_tx_seconds) { - temp_disable_tx_inhibit = time(0) + temp_disable_tx_duration; - } - } else if(isdigit(argstr[0])) { - sscanf(arg, "%lu", &temp); - if(temp == 0) - temp_disable_tx_duration = DISABLE_TX_INHIBIT_DURATION; - else - temp_disable_tx_duration = temp; - } - return; - } - } + if(arg) { + argstr.assign(arg); + if(!argstr.empty()) { + if(argstr[0] == 'I' || argstr[0] == 'i') { + if(progdefaults.enableBusyChannel && inhibit_tx_seconds) { + temp_disable_tx_inhibit = time(0) + temp_disable_tx_duration; + } + } else if(isdigit(argstr[0])) { + sscanf(arg, "%lu", &temp); + if(temp == 0) + temp_disable_tx_duration = DISABLE_TX_INHIBIT_DURATION; + else + temp_disable_tx_duration = temp; + } + return; + } + } - std::string cmd = "IBCHN:"; - std::string package = ""; - char buff[32]; + std::string cmd = "IBCHN:"; + std::string package = ""; + char buff[32]; - package.assign(cmd); + package.assign(cmd); - memset(buff, 0, sizeof(buff)); - snprintf(buff, sizeof(buff)-1, "%lu", temp_disable_tx_duration); - package.append(buff); + memset(buff, 0, sizeof(buff)); + snprintf(buff, sizeof(buff)-1, "%lu", temp_disable_tx_duration); + package.append(buff); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -679,21 +692,21 @@ static void set_busy_channel_inhibit(char *arg) **********************************************************************************/ static void set_kpsql_fraction_gain(char *arg) { - if(!arg) return; - std::string args; + if(!arg) return; + std::string args; - args.assign(arg); + args.assign(arg); - if(args.empty()) - return reply_kpsql_fraction_gain(arg); + if(args.empty()) + return reply_kpsql_fraction_gain(arg); - unsigned int value = 0; + unsigned int value = 0; - sscanf(args.c_str(), "%u", &value); + sscanf(args.c_str(), "%u", &value); - update_kpsql_fractional_gain(value); + update_kpsql_fractional_gain(value); - REQ(set_counter, cntKPSQLAttenuation, progdefaults.kpsql_attenuation); + REQ(set_counter, cntKPSQLAttenuation, progdefaults.kpsql_attenuation); } /********************************************************************************** @@ -701,15 +714,15 @@ static void set_kpsql_fraction_gain(char *arg) **********************************************************************************/ void update_kpsql_fractional_gain(int value) { - guard_lock external_lock(&external_mutex); + guard_lock external_lock(&external_mutex); - if(value > 1) { - progdefaults.kpsql_attenuation = value; - fractional_gain = 1.0 / ((double) value); - } else { - progdefaults.kpsql_attenuation = FGD_DEFAULT; - fractional_gain = 1.0 / ( 1.0 * FGD_DEFAULT); - } + if(value > 1) { + progdefaults.kpsql_attenuation = value; + fractional_gain = 1.0 / ((double) value); + } else { + progdefaults.kpsql_attenuation = FGD_DEFAULT; + fractional_gain = 1.0 / ( 1.0 * FGD_DEFAULT); + } } /********************************************************************************** @@ -717,17 +730,17 @@ void update_kpsql_fractional_gain(int value) **********************************************************************************/ static void reply_kpsql_fraction_gain(char *arg) { - std::string package = ""; - std::string cmd = "KPSATT:"; - char buffer[128]; + std::string package = ""; + std::string cmd = "KPSATT:"; + char buffer[128]; - package.assign(cmd); - memset(buffer, 0, sizeof(buffer)); + package.assign(cmd); + memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, "%u", progdefaults.kpsql_attenuation); - package.append(buffer); + snprintf(buffer, sizeof(buffer)-1, "%u", progdefaults.kpsql_attenuation); + package.append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } @@ -736,25 +749,25 @@ static void reply_kpsql_fraction_gain(char *arg) **********************************************************************************/ static void set_wf_cursor_pos(char * arg) { - if(!arg) return; + if(!arg) return; - std::string wf_cursor_pos = ""; - wf_cursor_pos.assign(arg); + std::string wf_cursor_pos = ""; + wf_cursor_pos.assign(arg); - if(wf_cursor_pos.empty()) - return reply_wf_freq_pos(arg); + if(wf_cursor_pos.empty()) + return reply_wf_freq_pos(arg); - int cursor = 0; - int mode_bw = active_modem->get_bandwidth(); + int cursor = 0; + int mode_bw = active_modem->get_bandwidth(); - sscanf(wf_cursor_pos.c_str(), "%d", &cursor); + sscanf(wf_cursor_pos.c_str(), "%d", &cursor); - mode_bw >>= 1; + mode_bw >>= 1; - if((cursor - mode_bw) < 0) cursor = mode_bw; - if((cursor + mode_bw) >= IMAGE_WIDTH) cursor = IMAGE_WIDTH - mode_bw; + if((cursor - mode_bw) < 0) cursor = mode_bw; + if((cursor + mode_bw) >= IMAGE_WIDTH) cursor = IMAGE_WIDTH - mode_bw; - active_modem->set_freq((double) cursor); + active_modem->set_freq((double) cursor); } @@ -763,26 +776,26 @@ static void set_wf_cursor_pos(char * arg) **********************************************************************************/ static void set_rsid_tx(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string rsid_tx_state = ""; - rsid_tx_state.assign(arg); + std::string rsid_tx_state = ""; + rsid_tx_state.assign(arg); - if(rsid_tx_state.empty()) - return reply_rsid_tx_state(arg); + if(rsid_tx_state.empty()) + return reply_rsid_tx_state(arg); - std::string state = uppercase_string(rsid_tx_state); + std::string state = uppercase_string(rsid_tx_state); - if(state.find("ON") != std::string::npos) { - REQ(set_button, btnTxRSID, 1); - return; - } + if(state.find("ON") != std::string::npos) { + REQ(set_button, btnTxRSID, 1); + return; + } - if(state.find("OFF") != std::string::npos) { - REQ(set_button, btnTxRSID, 0); - return; - } + if(state.find("OFF") != std::string::npos) { + REQ(set_button, btnTxRSID, 0); + return; + } } /********************************************************************************** @@ -790,27 +803,27 @@ static void set_rsid_tx(char * arg) **********************************************************************************/ static void set_rsid_rx(char *arg) { - if(!arg) - return; + if(!arg) + return; - std::string rsid_rx_state = ""; + std::string rsid_rx_state = ""; - rsid_rx_state.assign(arg); + rsid_rx_state.assign(arg); - if(rsid_rx_state.empty()) - return reply_rsid_rx_state(arg); + if(rsid_rx_state.empty()) + return reply_rsid_rx_state(arg); - std::string state = uppercase_string(rsid_rx_state); + std::string state = uppercase_string(rsid_rx_state); - if(state.find("ON") != std::string::npos) { - REQ(set_button, btnRSID, 1); - return; - } + if(state.find("ON") != std::string::npos) { + REQ(set_button, btnRSID, 1); + return; + } - if(state.find("OFF") != std::string::npos) { - REQ(set_button, btnRSID, 0); - return; - } + if(state.find("OFF") != std::string::npos) { + REQ(set_button, btnRSID, 0); + return; + } } /********************************************************************************** @@ -818,33 +831,33 @@ static void set_rsid_rx(char *arg) **********************************************************************************/ static void set_rsid_mode(char *arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_rsid_mode_state(arg); + if(strarg.empty()) + return reply_rsid_mode_state(arg); - std::string state = uppercase_string(strarg); + std::string state = uppercase_string(strarg); - if(state.find("BANDPASS") != std::string::npos) { - REQ(set_button, chkRSidWideSearch, 1); - } + if(state.find("BANDPASS") != std::string::npos) { + REQ(set_button, chkRSidWideSearch, 1); + } - if(state.find("MODEM") != std::string::npos) { - REQ(set_button, chkRSidWideSearch, 0); - } + if(state.find("MODEM") != std::string::npos) { + REQ(set_button, chkRSidWideSearch, 0); + } - if(state.find("NOTIFY") != std::string::npos) { - REQ(set_button, chkRSidNotifyOnly, 1); - } + if(state.find("NOTIFY") != std::string::npos) { + REQ(set_button, chkRSidNotifyOnly, 1); + } - if(state.find("ACTIVE") != std::string::npos) { - REQ(set_button, chkRSidNotifyOnly, 0); - } + if(state.find("ACTIVE") != std::string::npos) { + REQ(set_button, chkRSidNotifyOnly, 0); + } } /********************************************************************************** @@ -852,27 +865,27 @@ static void set_rsid_mode(char *arg) **********************************************************************************/ static void set_rsid_bc_mode(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_rsid_bc_mode(arg); + if(strarg.empty()) + return reply_rsid_bc_mode(arg); - std::string state = uppercase_string(strarg); + std::string state = uppercase_string(strarg); - if(state.find("ON") != std::string::npos) { - kiss_bcast_rsid_reception = true; - return; - } + if(state.find("ON") != std::string::npos) { + kiss_bcast_rsid_reception = true; + return; + } - if(state.find("OFF") != std::string::npos) { - kiss_bcast_rsid_reception = false; - return; - } + if(state.find("OFF") != std::string::npos) { + kiss_bcast_rsid_reception = false; + return; + } } /********************************************************************************** @@ -880,17 +893,17 @@ static void set_rsid_bc_mode(char * arg) **********************************************************************************/ static void reply_rsid_bc_mode(char * arg) { - std::string package = ""; - std::string cmd = "RSIDBCAST:"; + std::string package = ""; + std::string cmd = "RSIDBCAST:"; - package.assign(cmd); + package.assign(cmd); - if(kiss_bcast_rsid_reception) - package.append("ON"); - else - package.append("OFF"); + if(kiss_bcast_rsid_reception) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -898,27 +911,27 @@ static void reply_rsid_bc_mode(char * arg) **********************************************************************************/ static void set_trxs_bc_mode(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_trxs_bc_mode(arg); + if(strarg.empty()) + return reply_trxs_bc_mode(arg); - std::string state = uppercase_string(strarg); + std::string state = uppercase_string(strarg); - if(state.find("ON") != std::string::npos) { - kiss_bcast_trx_toggle = true; - return; - } + if(state.find("ON") != std::string::npos) { + kiss_bcast_trx_toggle = true; + return; + } - if(state.find("OFF") != std::string::npos) { - kiss_bcast_trx_toggle = false; - return; - } + if(state.find("OFF") != std::string::npos) { + kiss_bcast_trx_toggle = false; + return; + } } /********************************************************************************** @@ -926,17 +939,17 @@ static void set_trxs_bc_mode(char * arg) **********************************************************************************/ static void reply_trxs_bc_mode(char * arg) { - std::string package = ""; - std::string cmd = "TRXSBCAST:"; + std::string package = ""; + std::string cmd = "TRXSBCAST:"; - package.assign(cmd); + package.assign(cmd); - if(kiss_bcast_trx_toggle) - package.append("ON"); - else - package.append("OFF"); + if(kiss_bcast_trx_toggle) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -944,27 +957,27 @@ static void reply_trxs_bc_mode(char * arg) **********************************************************************************/ static void set_txbe_bc_mode(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_txbe_bc_mode(arg); + if(strarg.empty()) + return reply_txbe_bc_mode(arg); - std::string state = uppercase_string(strarg); + std::string state = uppercase_string(strarg); - if(state.find("ON") != std::string::npos) { - bcast_tx_buffer_empty_flag = true; - return; - } + if(state.find("ON") != std::string::npos) { + bcast_tx_buffer_empty_flag = true; + return; + } - if(state.find("OFF") != std::string::npos) { - bcast_tx_buffer_empty_flag = false; - return; - } + if(state.find("OFF") != std::string::npos) { + bcast_tx_buffer_empty_flag = false; + return; + } } /********************************************************************************** @@ -972,17 +985,17 @@ static void set_txbe_bc_mode(char * arg) **********************************************************************************/ static void reply_txbe_bc_mode(char * arg) { - std::string package = ""; - std::string cmd = "TXBEBCAST:"; + std::string package = ""; + std::string cmd = "TXBEBCAST:"; - package.assign(cmd); + package.assign(cmd); - if(bcast_tx_buffer_empty_flag) - package.append("ON"); - else - package.append("OFF"); + if(bcast_tx_buffer_empty_flag) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -990,12 +1003,12 @@ static void reply_txbe_bc_mode(char * arg) **********************************************************************************/ static void reply_tnc_name(char * arg) { - std::string package = ""; - std::string cmd = "TNC:"; + std::string package = ""; + std::string cmd = "TNC:"; - package.assign(cmd).append("FLDIGI ").append(PACKAGE_VERSION); + package.assign(cmd).append("FLDIGI ").append(PACKAGE_VERSION); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1003,17 +1016,17 @@ static void reply_tnc_name(char * arg) **********************************************************************************/ static void reply_trx_state(char * arg) { - std::string package = ""; - std::string cmd = "TRXS:"; + std::string package = ""; + std::string cmd = "TRXS:"; - package.assign(cmd); + package.assign(cmd); - if((trx_state == STATE_TX) || (trx_state == STATE_TUNE)) - package.append("TX"); - else - package.append("RX"); + if((trx_state == STATE_TX) || (trx_state == STATE_TUNE)) + package.append("TX"); + else + package.append("RX"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1021,17 +1034,17 @@ static void reply_trx_state(char * arg) **********************************************************************************/ static void reply_rsid_rx_state(char * arg) { - std::string package = ""; - std::string cmd = "RSIDRX:"; + std::string package = ""; + std::string cmd = "RSIDRX:"; - package.assign(cmd); + package.assign(cmd); - if(progdefaults.rsid) - package.append("ON"); - else - package.append("OFF"); + if(progdefaults.rsid) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1039,17 +1052,60 @@ static void reply_rsid_rx_state(char * arg) **********************************************************************************/ static void reply_rsid_tx_state(char * arg) { - std::string package = ""; - std::string cmd = "RSIDTX:"; + std::string package = ""; + std::string cmd = "RSIDTX:"; - package.assign(cmd); + package.assign(cmd); - if(progdefaults.TransmitRSid) - package.append("ON"); - else - package.append("OFF"); + if(progdefaults.TransmitRSid) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); +} + +/********************************************************************************** + * TXLOCK: FLDIGI TXLOCK: or without arg return lock state. + **********************************************************************************/ +static void set_reply_tx_lock(char * arg) +{ + if(!arg) return; + + std::string strarg = ""; + std::string package = ""; + std::string cmd = "TXLOCK:"; + + strarg.assign(arg); + + if(strarg.empty()) { + package.assign(cmd); + + if (!active_modem) + package.append("INOP"); + else if(active_modem->freqlocked()) + package.append("ON"); + else + package.append("OFF"); + + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + + return; + } + + if (!active_modem) return; + + if(strarg.find("ON") != std::string::npos) { + active_modem->set_freqlock(true); + REQ(set_button, (Fl_Button *) wf->xmtlock, 1); + return; + } + + if(strarg.find("OFF") != std::string::npos) { + active_modem->set_freqlock(false); + REQ(set_button, (Fl_Button *) wf->xmtlock, 0); + return; + } } /********************************************************************************** @@ -1057,18 +1113,18 @@ static void reply_rsid_tx_state(char * arg) **********************************************************************************/ static void reply_wf_freq_pos(char * arg) { - std::string package = ""; - std::string cmd = "WFF:"; - char buff[32]; + std::string package = ""; + std::string cmd = "WFF:"; + char buff[32]; - package.assign(cmd); + package.assign(cmd); - memset(buff, 0, sizeof(buff)); - snprintf(buff, sizeof(buff) - 1, "%d", (int) active_modem->get_txfreq()); + memset(buff, 0, sizeof(buff)); + snprintf(buff, sizeof(buff) - 1, "%d", (int) active_modem->get_txfreq()); - package.append(buff); + package.append(buff); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1076,22 +1132,22 @@ static void reply_wf_freq_pos(char * arg) **********************************************************************************/ static void reply_rsid_mode_state(char * arg) { - std::string package = ""; - std::string cmd = "RSIDM:"; + std::string package = ""; + std::string cmd = "RSIDM:"; - package.assign(cmd); + package.assign(cmd); - if(progdefaults.rsidWideSearch) - package.append("BANDPASS,"); - else - package.append("MODEM,"); + if(progdefaults.rsidWideSearch) + package.append("BANDPASS,"); + else + package.append("MODEM,"); - if(progdefaults.rsid_notify_only) - package.append("NOTIFY"); - else - package.append("ACTIVE"); + if(progdefaults.rsid_notify_only) + package.append("NOTIFY"); + else + package.append("ACTIVE"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1099,13 +1155,13 @@ static void reply_rsid_mode_state(char * arg) **********************************************************************************/ static void reply_active_modem(char * arg) { - std::string package = ""; - std::string cmd = "MODEM:"; - int mode = active_modem->get_mode(); - package.assign(cmd); - package.append(mode_info[mode].sname); + std::string package = ""; + std::string cmd = "MODEM:"; + int mode = active_modem->get_mode(); + package.assign(cmd); + package.append(mode_info[mode].sname); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1113,16 +1169,16 @@ static void reply_active_modem(char * arg) **********************************************************************************/ static void reply_active_modem_bw(char * arg) { - std::string package = ""; - std::string cmd = "MODEMBW:"; - char buff[32]; + std::string package = ""; + std::string cmd = "MODEMBW:"; + char buff[32]; - memset(buff, 0, sizeof(buff)); - snprintf(buff, sizeof(buff) - 1, "%d", (int) active_modem->get_bandwidth()); + memset(buff, 0, sizeof(buff)); + snprintf(buff, sizeof(buff) - 1, "%d", (int) active_modem->get_bandwidth()); - package.assign(cmd).append(buff); + package.assign(cmd).append(buff); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1130,17 +1186,17 @@ static void reply_active_modem_bw(char * arg) **********************************************************************************/ static void reply_waterfall_bw(char * arg) { - std::string package = ""; - std::string cmd = "WFBW:"; - char buff[32]; + std::string package = ""; + std::string cmd = "WFBW:"; + char buff[32]; - memset(buff, 0, sizeof(buff)); - snprintf(buff, sizeof(buff) - 1, "%d,%d", (int) progdefaults.LowFreqCutoff, - progdefaults.HighFreqCutoff ); + memset(buff, 0, sizeof(buff)); + snprintf(buff, sizeof(buff) - 1, "%d,%d", (int) progdefaults.LowFreqCutoff, + progdefaults.HighFreqCutoff ); - package.assign(cmd).append(buff); + package.assign(cmd).append(buff); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1149,20 +1205,20 @@ static void reply_waterfall_bw(char * arg) **********************************************************************************/ static void reply_modem_list(char * arg) { - int index = 0; - int count = 0; - std::string package = ""; - std::string cmd = "MODEML:"; + int index = 0; + int count = 0; + std::string package = ""; + std::string cmd = "MODEML:"; - package.assign(cmd); + package.assign(cmd); - count = availabe_kiss_modems.size(); + count = availabe_kiss_modems.size(); - for(index = 0; index < count - 1; index++) - package.append(availabe_kiss_modems[index]).append(","); - package.append(availabe_kiss_modems[index]); + for(index = 0; index < count - 1; index++) + package.append(availabe_kiss_modems[index]).append(","); + package.append(availabe_kiss_modems[index]); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1170,32 +1226,32 @@ static void reply_modem_list(char * arg) **********************************************************************************/ static void reply_tx_buffer_count(char * arg) { - char *buffer = (char *)0; - unsigned int buffer_size = 64; - unsigned tx_buffer_count = 0; - std::string package = ""; - std::string cmd = "TXBUF:"; + char *buffer = (char *)0; + unsigned int buffer_size = 64; + unsigned tx_buffer_count = 0; + std::string package = ""; + std::string cmd = "TXBUF:"; - buffer = new char[buffer_size]; + buffer = new char[buffer_size]; - if(!buffer) { - LOG_DEBUG("%s", "Buffer allocation Error"); - return; - } + if(!buffer) { + LOG_DEBUG("%s", "Buffer allocation Error"); + return; + } - { - guard_lock to_radio_lock(&to_radio_mutex); - tx_buffer_count = to_radio.size(); - } + { + guard_lock to_radio_lock(&to_radio_mutex); + tx_buffer_count = to_radio.size(); + } - memset(buffer, 0, buffer_size); - snprintf(buffer, buffer_size - 1, "%u", tx_buffer_count); + memset(buffer, 0, buffer_size); + snprintf(buffer, buffer_size - 1, "%u", tx_buffer_count); - package.assign(cmd).append(buffer); + package.assign(cmd).append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); - if(buffer) delete [] buffer; + if(buffer) delete [] buffer; } @@ -1204,25 +1260,25 @@ static void reply_tx_buffer_count(char * arg) **********************************************************************************/ static void set_sql_on_off(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_sql_on_off(arg); + if(strarg.empty()) + return reply_sql_on_off(arg); - if(strarg.find("ON") != std::string::npos) { - REQ(set_button, btnSQL, 1); - return; - } + if(strarg.find("ON") != std::string::npos) { + REQ(set_button, btnSQL, 1); + return; + } - if(strarg.find("OFF") != std::string::npos) { - REQ(set_button, btnSQL, 0); - return; - } + if(strarg.find("OFF") != std::string::npos) { + REQ(set_button, btnSQL, 0); + return; + } } /********************************************************************************** @@ -1230,17 +1286,17 @@ static void set_sql_on_off(char * arg) **********************************************************************************/ static void reply_sql_on_off(char * arg) { - std::string package = ""; - std::string cmd = "SQL:"; + std::string package = ""; + std::string cmd = "SQL:"; - package.assign(cmd); + package.assign(cmd); - if(progStatus.sqlonoff) - package.append("ON"); - else - package.append("OFF"); + if(progStatus.sqlonoff) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1248,17 +1304,17 @@ static void reply_sql_on_off(char * arg) **********************************************************************************/ static void reply_sql_pwr_level(char * arg) { - std::string package = ""; - std::string cmd = "SQLP:"; - char buffer[64]; + std::string package = ""; + std::string cmd = "SQLP:"; + char buffer[64]; - package.assign(cmd); + package.assign(cmd); - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) progStatus.squelch_value); - package.append(buffer); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) progStatus.squelch_value); + package.append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } @@ -1267,25 +1323,25 @@ static void reply_sql_pwr_level(char * arg) **********************************************************************************/ static void set_sql_level(char * arg) { - if(!arg) - return; - int value = 0; + if(!arg) + return; + int value = 0; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_sql_level(arg); + if(strarg.empty()) + return reply_sql_level(arg); - sscanf(strarg.c_str(), "%d", &value); - if(value < 1) value = 1; - if(value > 100) value = 100; + sscanf(strarg.c_str(), "%d", &value); + if(value < 1) value = 1; + if(value > 100) value = 100; - progStatus.sldrSquelchValue = value; + progStatus.sldrSquelchValue = value; - if(!progStatus.pwrsqlonoff) - REQ(set_slider2, sldrSquelch, value); + if(!progStatus.kpsql_enabled) + REQ(set_slider2, sldrSquelch, value); } /********************************************************************************** @@ -1293,17 +1349,17 @@ static void set_sql_level(char * arg) **********************************************************************************/ static void reply_sql_level(char * arg) { - std::string package = ""; - std::string cmd = "SQLS:"; - char buffer[64]; + std::string package = ""; + std::string cmd = "SQLS:"; + char buffer[64]; - package.assign(cmd); + package.assign(cmd); - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) progStatus.sldrSquelchValue); - package.append(buffer); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) progStatus.sldrSquelchValue); + package.append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1311,25 +1367,25 @@ static void reply_sql_level(char * arg) **********************************************************************************/ static void set_busy_channel_on_off(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_busy_channel_on_off(arg); + if(strarg.empty()) + return reply_busy_channel_on_off(arg); - if(strarg.find("ON") != std::string::npos) { - REQ(set_button, btnEnableBusyChannel, 1); - return; - } + if(strarg.find("ON") != std::string::npos) { + REQ(set_button, btnEnableBusyChannel, 1); + return; + } - if(strarg.find("OFF") != std::string::npos) { - REQ(set_button, btnEnableBusyChannel, 0); - return; - } + if(strarg.find("OFF") != std::string::npos) { + REQ(set_button, btnEnableBusyChannel, 0); + return; + } } @@ -1338,17 +1394,17 @@ static void set_busy_channel_on_off(char * arg) **********************************************************************************/ static void reply_busy_channel_on_off(char * arg) { - std::string package = ""; - std::string cmd = "BCHN:"; + std::string package = ""; + std::string cmd = "BCHN:"; - package.assign(cmd); + package.assign(cmd); - if(progdefaults.enableBusyChannel) - package.append("ON"); - else - package.append("OFF"); + if(progdefaults.enableBusyChannel) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1356,20 +1412,20 @@ static void reply_busy_channel_on_off(char * arg) **********************************************************************************/ static void set_busy_channel_duration(char * arg) { - if(!arg) - return; - int value = 0; - std::string strarg = ""; + if(!arg) + return; + int value = 0; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_busy_channel_duration(arg); + if(strarg.empty()) + return reply_busy_channel_duration(arg); - sscanf(strarg.c_str(), "%d", &value); - if(value < 1) value = 1; + sscanf(strarg.c_str(), "%d", &value); + if(value < 1) value = 1; - REQ(set_counter, cntBusyChannelSeconds, value); + REQ(set_counter, cntBusyChannelSeconds, value); } /********************************************************************************** @@ -1377,17 +1433,17 @@ static void set_busy_channel_duration(char * arg) **********************************************************************************/ static void reply_busy_channel_duration(char * arg) { - std::string package = ""; - std::string cmd = "BCHNS:"; - char buffer[64]; + std::string package = ""; + std::string cmd = "BCHNS:"; + char buffer[64]; - package.assign(cmd); + package.assign(cmd); - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, "%d", progdefaults.busyChannelSeconds); - package.append(buffer); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer)-1, "%d", progdefaults.busyChannelSeconds); + package.append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } @@ -1396,20 +1452,20 @@ static void reply_busy_channel_duration(char * arg) **********************************************************************************/ static void reply_busy_state(char * arg) { - std::string package = ""; - std::string cmd = "BUSY:"; + std::string package = ""; + std::string cmd = "BUSY:"; - package.assign(cmd); + package.assign(cmd); - if((trx_state == STATE_TX) || \ - (kpsql_pl > kpsql_threshold) || \ - (inhibit_tx_seconds)) { - package.append("T"); - } else { - package.append("F"); - } + if((trx_state == STATE_TX) || \ + (kpsql_pl > kpsql_threshold) || \ + (inhibit_tx_seconds)) { + package.append("T"); + } else { + package.append("F"); + } - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1417,25 +1473,25 @@ static void reply_busy_state(char * arg) **********************************************************************************/ static void set_kpsql_on_off(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_kpsql_on_off(arg); + if(strarg.empty()) + return reply_kpsql_on_off(arg); - if(strarg.find("ON") != std::string::npos) { - REQ(set_button, btnPSQL, 1); - return; - } + if(strarg.find("ON") != std::string::npos) { + REQ(set_button, btnPSQL, 1); + return; + } - if(strarg.find("OFF") != std::string::npos) { - REQ(set_button, btnPSQL, 0); - return; - } + if(strarg.find("OFF") != std::string::npos) { + REQ(set_button, btnPSQL, 0); + return; + } } @@ -1444,17 +1500,17 @@ static void set_kpsql_on_off(char * arg) **********************************************************************************/ static void reply_kpsql_on_off(char * arg) { - std::string package = ""; - std::string cmd = "KPSQL:"; + std::string package = ""; + std::string cmd = "KPSQL:"; - package.assign(cmd); + package.assign(cmd); - if(progStatus.pwrsqlonoff) - package.append("ON"); - else - package.append("OFF"); + if(progStatus.kpsql_enabled) + package.append("ON"); + else + package.append("OFF"); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1462,27 +1518,27 @@ static void reply_kpsql_on_off(char * arg) **********************************************************************************/ static void reply_kpsql_pwr_level(char * arg) { - std::string package = ""; - std::string cmd = "KPSQLP:"; - char buffer[64]; - float plevel = 0; - float scale = 100.0 / ((float) HISTO_COUNT); + std::string package = ""; + std::string cmd = "KPSQLP:"; + char buffer[64]; + float plevel = 0; + float scale = 100.0 / ((float) HISTO_COUNT); - package.assign(cmd); + package.assign(cmd); - if(kpsql_pl > (double) HISTO_COUNT) { - plevel = HISTO_COUNT; - } else { - plevel = kpsql_pl; - } + if(kpsql_pl > (double) HISTO_COUNT) { + plevel = HISTO_COUNT; + } else { + plevel = kpsql_pl; + } - plevel *= scale; + plevel *= scale; - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) plevel); - package.append(buffer); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) plevel); + package.append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1490,27 +1546,27 @@ static void reply_kpsql_pwr_level(char * arg) **********************************************************************************/ static void set_kpsql_squelch_level(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_kpsql_squelch_level(arg); + if(strarg.empty()) + return reply_kpsql_squelch_level(arg); - int value = 0; + int value = 0; - sscanf(strarg.c_str(), "%d", &value); + sscanf(strarg.c_str(), "%d", &value); - if(value < 1) value = 1; - if(value > 100) value = 100; + if(value < 1) value = 1; + if(value > 100) value = 100; - progStatus.sldrPwrSquelchValue = value; + progStatus.sldrPwrSquelchValue = value; - if(progStatus.pwrsqlonoff) - REQ(set_slider2, sldrSquelch, value); + if(progStatus.kpsql_enabled) + REQ(set_slider2, sldrSquelch, value); } @@ -1519,17 +1575,17 @@ static void set_kpsql_squelch_level(char * arg) **********************************************************************************/ static void reply_kpsql_squelch_level(char * arg) { - std::string package = ""; - std::string cmd = "KPSQLS:"; - char buffer[64]; + std::string package = ""; + std::string cmd = "KPSQLS:"; + char buffer[64]; - package.assign(cmd); + package.assign(cmd); - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) progStatus.sldrPwrSquelchValue); - package.append(buffer); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer)-1, "%u", (unsigned int) progStatus.sldrPwrSquelchValue); + package.append(buffer); - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1537,31 +1593,31 @@ static void reply_kpsql_squelch_level(char * arg) **********************************************************************************/ static void set_kiss_raw_mode(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_kiss_raw_mode(arg); + if(strarg.empty()) + return reply_kiss_raw_mode(arg); - // Longer compares first - if(strarg.find("ONLY") != std::string::npos) { - kiss_raw_enabled = KISS_RAW_ONLY; - return; - } + // Longer compares first + if(strarg.find("ONLY") != std::string::npos) { + kiss_raw_enabled = KISS_RAW_ONLY; + return; + } - if(strarg.find("ON") != std::string::npos) { - kiss_raw_enabled = KISS_RAW_ON; - return; - } + if(strarg.find("ON") != std::string::npos) { + kiss_raw_enabled = KISS_RAW_ON; + return; + } - if(strarg.find("OFF") != std::string::npos) { - kiss_raw_enabled = KISS_RAW_DISABLED; - return; - } + if(strarg.find("OFF") != std::string::npos) { + kiss_raw_enabled = KISS_RAW_DISABLED; + return; + } } @@ -1570,29 +1626,29 @@ static void set_kiss_raw_mode(char * arg) **********************************************************************************/ static void reply_kiss_raw_mode(char * arg) { - std::string package = ""; - std::string cmd = "KISSRAW:"; + std::string package = ""; + std::string cmd = "KISSRAW:"; - package.assign(cmd); + package.assign(cmd); - switch(kiss_raw_enabled) { - case KISS_RAW_ONLY: - package.append("ONLY"); - break; + switch(kiss_raw_enabled) { + case KISS_RAW_ONLY: + package.append("ONLY"); + break; - case KISS_RAW_ON: - package.append("ON"); - break; + case KISS_RAW_ON: + package.append("ON"); + break; - case KISS_RAW_DISABLED: - package.append("OFF"); - break; + case KISS_RAW_DISABLED: + package.append("OFF"); + break; - default: - return; - } + default: + return; + } - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1600,44 +1656,44 @@ static void reply_kiss_raw_mode(char * arg) **********************************************************************************/ static void set_crc_mode(char * arg) { - if(!arg) - return; + if(!arg) + return; - std::string strarg = ""; + std::string strarg = ""; - strarg.assign(arg); + strarg.assign(arg); - if(strarg.empty()) - return reply_crc_mode(arg); + if(strarg.empty()) + return reply_crc_mode(arg); - if(strarg.find("SMACK") != std::string::npos) { - smack_crc_enabled = true; - crc_mode = CRC16_CCITT; - return; - } + if(strarg.find("SMACK") != std::string::npos) { + smack_crc_enabled = true; + crc_mode = CRC16_CCITT; + return; + } - if(strarg.find("CCITT") != std::string::npos) { - smack_crc_enabled = true; - crc_mode = CRC16_CCITT; - return; - } + if(strarg.find("CCITT") != std::string::npos) { + smack_crc_enabled = true; + crc_mode = CRC16_CCITT; + return; + } - if(strarg.find("FCS") != std::string::npos) { - smack_crc_enabled = true; - crc_mode = CRC16_FCS; - return; - } + if(strarg.find("FCS") != std::string::npos) { + smack_crc_enabled = true; + crc_mode = CRC16_FCS; + return; + } - if(strarg.find("XOR") != std::string::npos) { - smack_crc_enabled = true; - crc_mode = CRC8_XOR; - return; - } + if(strarg.find("XOR") != std::string::npos) { + smack_crc_enabled = true; + crc_mode = CRC8_XOR; + return; + } - if(strarg.find("NONE") != std::string::npos) { - smack_crc_enabled = false; - return; - } + if(strarg.find("NONE") != std::string::npos) { + smack_crc_enabled = false; + return; + } } @@ -1646,39 +1702,39 @@ static void set_crc_mode(char * arg) **********************************************************************************/ static void reply_crc_mode(char *arg) { - std::string package = ""; - std::string cmd = "KISSCRCM:"; + std::string package = ""; + std::string cmd = "KISSCRCM:"; - package.assign(cmd); + package.assign(cmd); - if(smack_crc_enabled) - package.append("SMACK,"); - else - package.append("NONE,"); + if(smack_crc_enabled) + package.append("SMACK,"); + else + package.append("NONE,"); - switch(crc_mode) { - case CRC16_NONE: - package.append("NONE"); - break; + switch(crc_mode) { + case CRC16_NONE: + package.append("NONE"); + break; - case CRC16_CCITT: - package.append("CCITT"); - break; + case CRC16_CCITT: + package.append("CCITT"); + break; - case CRC16_FCS: - package.append("FCS"); - break; + case CRC16_FCS: + package.append("FCS"); + break; - case CRC8_XOR: - package.append("XOR"); - break; + case CRC8_XOR: + package.append("XOR"); + break; - default: - package.append("UNDEFINED"); + default: + package.append("UNDEFINED"); - } + } - kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); + kiss_queue_frame(encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no), cmd); } /********************************************************************************** @@ -1686,70 +1742,94 @@ static void reply_crc_mode(char *arg) **********************************************************************************/ bool bcast_rsid_kiss_frame(int new_wf_pos, int new_mode, int old_wf_pos, int old_mode, int notify) { - guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); + guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); - static char buffer[256]; - char *notify_str = (char *) ""; - KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; - std::string package = ""; + char buffer[256]; + char old_modem_name[64]; + char new_modem_name[64]; + char *notify_str = (char *) ""; + KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; + std::string package = ""; - if(new_mode >= NUM_MODES || old_mode >= NUM_MODES) - return false; + if(new_mode >= NUM_MODES || old_mode >= NUM_MODES) + return false; - if(new_mode < 0 || old_mode < 0) - return false; + if(new_mode < 0 || old_mode < 0) + return false; - if(!(mode_info[new_mode].iface_io & KISS_IO)) - return false; + if(!(mode_info[new_mode].iface_io & KISS_IO)) + return false; - if(old_mode != new_mode || new_wf_pos != old_wf_pos) { - reset_histogram(); - } + if(old_mode != new_mode || new_wf_pos != old_wf_pos) { + reset_histogram(); + } - if(!kiss_bcast_rsid_reception) return true; + if(!kiss_bcast_rsid_reception) return true; - if(new_wf_pos == 0) { - new_wf_pos = old_wf_pos; - notify = RSID_KISS_USER; - } + if(new_wf_pos == 0) { + new_wf_pos = old_wf_pos; + notify = RSID_KISS_USER; + } - switch(notify) { - case RSID_KISS_NOTIFY: - notify_str = (char *) "NOTIFY"; - break; + switch(notify) { + case RSID_KISS_NOTIFY: + notify_str = (char *) "NOTIFY"; + break; - case RSID_KISS_ACTIVE: - notify_str = (char *) "ACTIVE"; - break; + case RSID_KISS_ACTIVE: + notify_str = (char *) "ACTIVE"; + break; - case RSID_KISS_USER: - notify_str = (char *) "USER"; - break; + case RSID_KISS_USER: + notify_str = (char *) "USER"; + break; - default: - LOG_DEBUG("%s", "Unknown KISS frame RSID BC Source"); - return false; - } + default: + LOG_DEBUG("%s", "Unknown KISS frame RSID BC Source"); + return false; + } - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer)-1, "RSIDN:%d,%s,%d,%s,%s", new_wf_pos, mode_info[new_mode].sname, \ - old_wf_pos, mode_info[old_mode].sname, notify_str); + // Send all modem names in capital letters - package.assign(buffer); + memset(old_modem_name, 0, sizeof(old_modem_name)); + strncpy(old_modem_name, mode_info[old_mode].sname, sizeof(old_modem_name) - 1); - frame = encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no); + for(size_t i = 0; i < sizeof(old_modem_name); i++) { + if(old_modem_name[i]) + old_modem_name[i] = toupper(old_modem_name[i]); + else + break; + } - if(!frame) { - LOG_DEBUG("%s", "Broadcast Hardware Frame Assembly Failure"); - return true; - } + memset(new_modem_name, 0, sizeof(new_modem_name)); + strncpy(new_modem_name, mode_info[new_mode].sname, sizeof(new_modem_name) - 1); - kiss_bc_frame.append((const char *) frame->data, (size_t) frame->size); + for(size_t i = 0; i < sizeof(new_modem_name); i++) { + if(new_modem_name[i]) + new_modem_name[i] = toupper(new_modem_name[i]); + else + break; + } - if(frame->data) delete [] frame->data; - if(frame) delete frame; + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer)-1, "RSIDN:%d,%s,%d,%s,%s", new_wf_pos, new_modem_name, \ + old_wf_pos, old_modem_name, notify_str); - return true; + package.assign(buffer); + + frame = encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no); + + if(!frame) { + LOG_DEBUG("%s", "Broadcast Hardware Frame Assembly Failure"); + return true; + } + + kiss_bc_frame.append((const char *) frame->data, (size_t) frame->size); + + if(frame->data) delete [] frame->data; + if(frame) delete frame; + + return true; } /********************************************************************************** @@ -1757,40 +1837,40 @@ bool bcast_rsid_kiss_frame(int new_wf_pos, int new_mode, int old_wf_pos, int old **********************************************************************************/ void bcast_trxs_kiss_frame(int state) { - guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); + guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); - KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; - std::string package; + KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; + std::string package; - package.assign("TRXS:"); + package.assign("TRXS:"); - switch(state) { - case STATE_RX: - package.append("RX") ; - break; + switch(state) { + case STATE_RX: + package.append("RX") ; + break; - case STATE_TUNE: - case STATE_TX: - package.append("TX") ; - break; + case STATE_TUNE: + case STATE_TX: + package.append("TX") ; + break; - default: - LOG_DEBUG("%s", "Unknown Transmit State"); - return; + default: + LOG_DEBUG("%s", "Unknown Transmit State"); + return; - } + } - frame = encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no); + frame = encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no); - if(!frame) { - LOG_DEBUG("%s", "Broadcast Hardware Frame Assembly Failure"); - return; - } + if(!frame) { + LOG_DEBUG("%s", "Broadcast Hardware Frame Assembly Failure"); + return; + } - kiss_bc_frame.append((const char *) frame->data, (size_t) frame->size); + kiss_bc_frame.append((const char *) frame->data, (size_t) frame->size); - if(frame->data) delete [] frame->data; - if(frame) delete frame; + if(frame->data) delete [] frame->data; + if(frame) delete frame; } /********************************************************************************** @@ -1798,26 +1878,26 @@ void bcast_trxs_kiss_frame(int state) **********************************************************************************/ void bcast_tx_buffer_empty_kiss_frame(void) { - if(!bcast_tx_buffer_empty_flag) return; + if(!bcast_tx_buffer_empty_flag) return; - guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); + guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); - KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; - std::string package; + KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; + std::string package; - package.assign("TXBE:"); + package.assign("TXBE:"); - frame = encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no); + frame = encap_kiss_frame(package, KISS_HARDWARE, kiss_port_no); - if(!frame) { - LOG_DEBUG("%s", "Broadcast Hardware Frame Assembly Failure"); - return; - } + if(!frame) { + LOG_DEBUG("%s", "Broadcast Hardware Frame Assembly Failure"); + return; + } - kiss_bc_frame.append((const char *) frame->data, (size_t) frame->size); + kiss_bc_frame.append((const char *) frame->data, (size_t) frame->size); - if(frame->data) delete [] frame->data; - if(frame) delete frame; + if(frame->data) delete [] frame->data; + if(frame) delete frame; } /********************************************************************************** @@ -1825,35 +1905,35 @@ void bcast_tx_buffer_empty_kiss_frame(void) **********************************************************************************/ static void exec_hardware_command(std::string cmd, std::string arg) { - if(cmd.empty()) return; - if(kiss_reset_flag) return; - int pos = 0; - int a = 0; - int b = 0; - int comp_size = 0; - int index = 0; - int count = sizeof(exec_match) / sizeof(EXEC_HARDWARE_CMD_MATCH); - string cmp = ""; + if(cmd.empty()) return; + if(kiss_reset_flag) return; + int pos = 0; + int a = 0; + int b = 0; + int comp_size = 0; + int index = 0; + int count = sizeof(exec_match) / sizeof(EXEC_HARDWARE_CMD_MATCH); + string cmp = ""; - for(index = 0; index < count; index++) { - if(exec_match[index].cmd == (char *)0) return; - cmp.assign(exec_match[index].cmd); - if((pos = cmp.find(cmd)) != (int)(string::npos)) { - a = cmp.size(); - b = cmd.size(); + for(index = 0; index < count; index++) { + if(exec_match[index].cmd == (char *)0) return; + cmp.assign(exec_match[index].cmd); + if((pos = cmp.find(cmd)) != (int)(string::npos)) { + a = cmp.size(); + b = cmd.size(); - if(a > b) - comp_size = a; - else - comp_size = b; + if(a > b) + comp_size = a; + else + comp_size = b; - if(cmd.compare(pos, comp_size, cmp) == 0) { - if(exec_match[index].cmd_func) - (*exec_match[index].cmd_func)((char *) arg.c_str()); - return; - } - } - } + if(cmd.compare(pos, comp_size, cmp) == 0) { + if(exec_match[index].cmd_func) + (*exec_match[index].cmd_func)((char *) arg.c_str()); + return; + } + } + } } /********************************************************************************** @@ -1861,24 +1941,24 @@ static void exec_hardware_command(std::string cmd, std::string arg) **********************************************************************************/ static bool kiss_queue_frame(KISS_QUEUE_FRAME * frame, std::string cmd) { - if(!frame) { - LOG_DEBUG("Null frame (%s)", cmd.c_str()); - return false; - } + if(!frame) { + LOG_DEBUG("Null frame (%s)", cmd.c_str()); + return false; + } - if(frame->size == 0 || frame->data == (char *)0) { - LOG_DEBUG("Frame null content (%s)", cmd.c_str()); - if(frame->data) delete[] frame->data; - delete frame; - return false; - } + if(frame->size == 0 || frame->data == (char *)0) { + LOG_DEBUG("Frame null content (%s)", cmd.c_str()); + if(frame->data) delete[] frame->data; + delete frame; + return false; + } - WriteToHostBuffered((const char *) frame->data, (size_t) frame->size); + WriteToHostBuffered((const char *) frame->data, (size_t) frame->size); - delete[] frame->data; - delete frame; + delete[] frame->data; + delete frame; - return true; + return true; } /********************************************************************************** @@ -1886,49 +1966,49 @@ static bool kiss_queue_frame(KISS_QUEUE_FRAME * frame, std::string cmd) **********************************************************************************/ size_t kiss_encode(char *src, size_t src_size, char **dst) { - if(!src || !dst || src_size < 1) return 0; + if(!src || !dst || src_size < 1) return 0; - size_t index = 0; - int count = 0; - int buffer_size = 0; - int byte = 0; - char *buffer = (char *)0; + size_t index = 0; + int count = 0; + int buffer_size = 0; + int byte = 0; + char *buffer = (char *)0; - buffer_size = (src_size * KISS_BUFFER_FACTOR) + BUFFER_PADDING; - buffer = new char[buffer_size]; + buffer_size = (src_size * KISS_BUFFER_FACTOR) + BUFFER_PADDING; + buffer = new char[buffer_size]; - if(!buffer) { - LOG_DEBUG("Memory allocation error near line %d", __LINE__); - *dst = (char *)0; - return 0; - } + if(!buffer) { + LOG_DEBUG("Memory allocation error near line %d", __LINE__); + *dst = (char *)0; + return 0; + } - memset(buffer, 0, buffer_size); - count = 0; - buffer[count++] = KISS_FEND; + memset(buffer, 0, buffer_size); + count = 0; + buffer[count++] = KISS_FEND; - for(index = 0; index < src_size; index++) { - byte = (int) src[index] & 0xFF; - switch(byte) { - case KISS_FESC: - buffer[count++] = KISS_FESC; - buffer[count++] = KISS_TFESC; - break; + for(index = 0; index < src_size; index++) { + byte = (int) src[index] & 0xFF; + switch(byte) { + case KISS_FESC: + buffer[count++] = KISS_FESC; + buffer[count++] = KISS_TFESC; + break; - case KISS_FEND: - buffer[count++] = KISS_FESC; - buffer[count++] = KISS_TFEND; - break; + case KISS_FEND: + buffer[count++] = KISS_FESC; + buffer[count++] = KISS_TFEND; + break; - default: - buffer[count++] = byte; - } - } + default: + buffer[count++] = byte; + } + } - buffer[count++] = KISS_FEND; - *dst = (char *) buffer; + buffer[count++] = KISS_FEND; + *dst = (char *) buffer; - return count; + return count; } /********************************************************************************** @@ -1936,62 +2016,62 @@ size_t kiss_encode(char *src, size_t src_size, char **dst) **********************************************************************************/ size_t kiss_decode(char *src, size_t src_size, char **dst) { - if(!src || !dst || src_size < 1) return 0; + if(!src || !dst || src_size < 1) return 0; - size_t index = 0; - int count = 0; - int buffer_size = 0; - int byte = 0; - int last_byte = 0; - char *buffer = (char *)0; + size_t index = 0; + int count = 0; + int buffer_size = 0; + int byte = 0; + int last_byte = 0; + char *buffer = (char *)0; - buffer_size = src_size + BUFFER_PADDING; - buffer = new char[buffer_size]; + buffer_size = src_size + BUFFER_PADDING; + buffer = new char[buffer_size]; - if(!buffer) { - LOG_DEBUG("Memory allocation error near line %d", __LINE__); - *dst = (char *)0; - return 0; - } + if(!buffer) { + LOG_DEBUG("Memory allocation error near line %d", __LINE__); + *dst = (char *)0; + return 0; + } - memset(buffer, 0, buffer_size); - count = 0; - last_byte = KISS_INVALID; + memset(buffer, 0, buffer_size); + count = 0; + last_byte = KISS_INVALID; - for(index = 0; index < src_size; index++) { + for(index = 0; index < src_size; index++) { - byte = src[index] & 0xFF; + byte = src[index] & 0xFF; - switch(byte) { - case KISS_FEND: - continue; + switch(byte) { + case KISS_FEND: + continue; - case KISS_FESC: - break; + case KISS_FESC: + break; - case KISS_TFEND: - if(last_byte == KISS_FESC) - buffer[count++] = KISS_FEND; - else - buffer[count++] = byte; - break; + case KISS_TFEND: + if(last_byte == KISS_FESC) + buffer[count++] = KISS_FEND; + else + buffer[count++] = byte; + break; - case KISS_TFESC: - if(last_byte == KISS_FESC) - buffer[count++] = KISS_FESC; - else - buffer[count++] = byte; - break; + case KISS_TFESC: + if(last_byte == KISS_FESC) + buffer[count++] = KISS_FESC; + else + buffer[count++] = byte; + break; - default: - buffer[count++] = byte; - } + default: + buffer[count++] = byte; + } - last_byte = byte; - } + last_byte = byte; + } - *dst = (char *) buffer; - return count; + *dst = (char *) buffer; + return count; } #if 0 @@ -2000,28 +2080,28 @@ size_t kiss_decode(char *src, size_t src_size, char **dst) **********************************************************************************/ std::string kiss_decode(std::string frame) { - int count = 0; - int frame_size = 0; - char *dst = (char *)0; + int count = 0; + int frame_size = 0; + char *dst = (char *)0; - static std::string ret_str = ""; + static std::string ret_str = ""; - if(frame.empty()) return frame; + if(frame.empty()) return frame; - frame_size = frame.size(); + frame_size = frame.size(); - ret_str.clear(); - ret_str.reserve(frame_size + BUFFER_PADDING); + ret_str.clear(); + ret_str.reserve(frame_size + BUFFER_PADDING); - count = kiss_decode((char *) frame.c_str(), frame.size(), &dst); + count = kiss_decode((char *) frame.c_str(), frame.size(), &dst); - if(count && dst) { - ret_str.assign(dst, count); - dst[0] = 0; - delete [] dst; - } + if(count && dst) { + ret_str.assign(dst, count); + dst[0] = 0; + delete [] dst; + } - return ret_str; + return ret_str; } #endif // 0 @@ -2030,28 +2110,28 @@ std::string kiss_decode(std::string frame) **********************************************************************************/ std::string kiss_encode(std::string frame) { - int count = 0; - int frame_size = 0; - char *dst = (char *)0; + int count = 0; + int frame_size = 0; + char *dst = (char *)0; - static std::string ret_str = ""; + static std::string ret_str = ""; - if(frame.empty()) return frame; + if(frame.empty()) return frame; - frame_size = frame.size(); + frame_size = frame.size(); - ret_str.clear(); - ret_str.reserve((frame_size * 2) + BUFFER_PADDING); + ret_str.clear(); + ret_str.reserve((frame_size * 2) + BUFFER_PADDING); - count = kiss_encode((char *) frame.c_str(), frame.size(), &dst); + count = kiss_encode((char *) frame.c_str(), frame.size(), &dst); - if(count && dst) { - ret_str.assign(dst, count); - dst[0] = 0; - delete [] dst; - } + if(count && dst) { + ret_str.assign(dst, count); + dst[0] = 0; + delete [] dst; + } - return ret_str; + return ret_str; } @@ -2060,67 +2140,67 @@ std::string kiss_encode(std::string frame) **********************************************************************************/ size_t hdlc_encode(char *src, size_t src_size, char **dst) { - if(!src || !dst || src_size < 1) return 0; + if(!src || !dst || src_size < 1) return 0; - size_t index = 0; - int count = 0; - int buffer_size = 0; - int byte = 0; - char *buffer = (char *)0; + size_t index = 0; + int count = 0; + int buffer_size = 0; + int byte = 0; + char *buffer = (char *)0; - buffer_size = (src_size * HDLC_BUFFER_FACTOR) + BUFFER_PADDING; - buffer = new char[buffer_size]; + buffer_size = (src_size * HDLC_BUFFER_FACTOR) + BUFFER_PADDING; + buffer = new char[buffer_size]; - if(!buffer) { - LOG_DEBUG("Memory allocation error near line %d", __LINE__); - *dst = (char *)0; - return 0; - } + if(!buffer) { + LOG_DEBUG("Memory allocation error near line %d", __LINE__); + *dst = (char *)0; + return 0; + } - memset(buffer, 0, buffer_size); - count = 0; - buffer[count++] = ' '; - buffer[count++] = KISS_FEND; + memset(buffer, 0, buffer_size); + count = 0; + buffer[count++] = ' '; + buffer[count++] = KISS_FEND; - for(index = 0; index < src_size; index++) { - byte = (int) src[index] & 0xFF; + for(index = 0; index < src_size; index++) { + byte = (int) src[index] & 0xFF; - if(not_allowed[byte]) { - buffer[count++] = HDLC_CNT; - if((byte + HDLC_CNT_OFFSET) > 255) - buffer[count++] = ((byte - HDLC_CNT_OFFSET) & 0xFF); - else - buffer[count++] = ((byte + HDLC_CNT_OFFSET) & 0xFF); - continue; - } + if(not_allowed[byte]) { + buffer[count++] = HDLC_CNT; + if((byte + HDLC_CNT_OFFSET) > 255) + buffer[count++] = ((byte - HDLC_CNT_OFFSET) & 0xFF); + else + buffer[count++] = ((byte + HDLC_CNT_OFFSET) & 0xFF); + continue; + } - switch(byte) { - case KISS_FESC: - buffer[count++] = KISS_FESC; - buffer[count++] = KISS_TFESC; - break; + switch(byte) { + case KISS_FESC: + buffer[count++] = KISS_FESC; + buffer[count++] = KISS_TFESC; + break; - case KISS_FEND: - buffer[count++] = KISS_FESC; - buffer[count++] = KISS_TFEND; - break; + case KISS_FEND: + buffer[count++] = KISS_FESC; + buffer[count++] = KISS_TFEND; + break; - case HDLC_CNT: - buffer[count++] = KISS_FESC; - buffer[count++] = HDLC_TCNT; - break; + case HDLC_CNT: + buffer[count++] = KISS_FESC; + buffer[count++] = HDLC_TCNT; + break; - default: - buffer[count++] = byte; - } - } + default: + buffer[count++] = byte; + } + } - buffer[count++] = KISS_FEND; - buffer[count++] = ' '; + buffer[count++] = KISS_FEND; + buffer[count++] = ' '; - *dst = (char *) buffer; + *dst = (char *) buffer; - return count; + return count; } /********************************************************************************** @@ -2128,80 +2208,80 @@ size_t hdlc_encode(char *src, size_t src_size, char **dst) **********************************************************************************/ size_t hdlc_decode(char *src, size_t src_size, char **dst) { - if(!src || !dst || src_size < 1) return 0; + if(!src || !dst || src_size < 1) return 0; - size_t index = 0; - int count = 0; - int buffer_size = 0; - int byte = 0; - int last_byte = 0; - int check_byte = 0; - char *buffer = (char *)0; + size_t index = 0; + int count = 0; + int buffer_size = 0; + int byte = 0; + int last_byte = 0; + int check_byte = 0; + char *buffer = (char *)0; - buffer_size = src_size + BUFFER_PADDING; - buffer = new char[buffer_size]; + buffer_size = src_size + BUFFER_PADDING; + buffer = new char[buffer_size]; - if(!buffer) { - LOG_DEBUG("Memory allocation error near line %d", __LINE__); - *dst = (char *)0; - return 0; - } + if(!buffer) { + LOG_DEBUG("Memory allocation error near line %d", __LINE__); + *dst = (char *)0; + return 0; + } - memset(buffer, 0, buffer_size); - count = 0; - last_byte = KISS_INVALID; + memset(buffer, 0, buffer_size); + count = 0; + last_byte = KISS_INVALID; - for(index = 0; index < src_size; index++) { + for(index = 0; index < src_size; index++) { - byte = src[index] & 0xFF; + byte = src[index] & 0xFF; - if(last_byte == HDLC_CNT) { - check_byte = byte - HDLC_CNT_OFFSET; - if((check_byte > -1) && (check_byte < 256) && not_allowed[check_byte]) { - buffer[count++] = check_byte; - last_byte = byte; - continue; - } + if(last_byte == HDLC_CNT) { + check_byte = byte - HDLC_CNT_OFFSET; + if((check_byte > -1) && (check_byte < 256) && not_allowed[check_byte]) { + buffer[count++] = check_byte; + last_byte = byte; + continue; + } - check_byte = byte + HDLC_CNT_OFFSET; - if((check_byte > -1) && (check_byte < 256) && not_allowed[check_byte]) { - buffer[count++] = check_byte; - } + check_byte = byte + HDLC_CNT_OFFSET; + if((check_byte > -1) && (check_byte < 256) && not_allowed[check_byte]) { + buffer[count++] = check_byte; + } - last_byte = byte; - continue; - } + last_byte = byte; + continue; + } - switch(byte) { - case KISS_FEND: - continue; + switch(byte) { + case KISS_FEND: + continue; - case KISS_FESC: - case HDLC_CNT: - last_byte = byte; - continue; + case KISS_FESC: + case HDLC_CNT: + last_byte = byte; + continue; - case KISS_TFEND: - if(last_byte == KISS_FESC) - byte = KISS_FEND; - break; + case KISS_TFEND: + if(last_byte == KISS_FESC) + byte = KISS_FEND; + break; - case KISS_TFESC: - if(last_byte == KISS_FESC) - byte = KISS_FESC; - break; + case KISS_TFESC: + if(last_byte == KISS_FESC) + byte = KISS_FESC; + break; - case HDLC_TCNT: - if(last_byte == KISS_FESC) - byte = HDLC_CNT; - break; - } + case HDLC_TCNT: + if(last_byte == KISS_FESC) + byte = HDLC_CNT; + break; + } - last_byte = buffer[count++] = byte; - } + last_byte = buffer[count++] = byte; + } - *dst = (char *) buffer; - return count; + *dst = (char *) buffer; + return count; } @@ -2212,38 +2292,38 @@ size_t hdlc_decode(char *src, size_t src_size, char **dst) **********************************************************************************/ static size_t encap_hdlc_frame(char *buffer, size_t data_count) { - if(!buffer || !data_count) { - LOG_DEBUG("%s", "Parameter Data Error [NULL]"); - return false; - } + if(!buffer || !data_count) { + LOG_DEBUG("%s", "Parameter Data Error [NULL]"); + return false; + } - size_t count = 0; - unsigned int crc_value = 0; - char *kiss_encap = (char *)0; + size_t count = 0; + unsigned int crc_value = 0; + char *kiss_encap = (char *)0; - if(progdefaults.ax25_decode_enabled) { - ax25_decode((unsigned char *) buffer, data_count, true, true); - } + if(progdefaults.ax25_decode_enabled) { + ax25_decode((unsigned char *) buffer, data_count, true, true); + } - crc_value = calc_fcs_crc(buffer, (int) data_count); + crc_value = calc_fcs_crc(buffer, (int) data_count); - buffer[data_count++] = CRC_LOW(crc_value); - buffer[data_count++] = CRC_HIGH(crc_value); + buffer[data_count++] = CRC_LOW(crc_value); + buffer[data_count++] = CRC_HIGH(crc_value); - count = hdlc_encode(buffer, data_count, &kiss_encap); + count = hdlc_encode(buffer, data_count, &kiss_encap); - if(kiss_encap && count) { - memcpy(buffer, kiss_encap, count); + if(kiss_encap && count) { + memcpy(buffer, kiss_encap, count); #ifdef EXTENED_DEBUG_INFO - LOG_HEX(buffer, count); + LOG_HEX(buffer, count); #endif - delete [] kiss_encap; - } else { - LOG_DEBUG("%s", "Kiss Encode Memory Allocation Error"); - return 0; - } + delete [] kiss_encap; + } else { + LOG_DEBUG("%s", "Kiss Encode Memory Allocation Error"); + return 0; + } - return count; + return count; } /********************************************************************************* @@ -2253,72 +2333,72 @@ static size_t encap_hdlc_frame(char *buffer, size_t data_count) *********************************************************************************/ static size_t decap_hdlc_frame(char *buffer, size_t data_count) { - if(!buffer || !data_count) { - LOG_DEBUG("%s", "Parameter Data Error/NULL"); - return false; - } + if(!buffer || !data_count) { + LOG_DEBUG("%s", "Parameter Data Error/NULL"); + return false; + } - size_t count = 0; - // size_t index = 0; - unsigned int crc_value = 0; - unsigned int calc_crc_value = 0; - char *kiss_decap = (char *)0; + size_t count = 0; + // size_t index = 0; + unsigned int crc_value = 0; + unsigned int calc_crc_value = 0; + char *kiss_decap = (char *)0; - count = hdlc_decode(buffer, data_count, &kiss_decap); + count = hdlc_decode(buffer, data_count, &kiss_decap); #ifdef EXTENED_DEBUG_INFO - if(data_count && buffer) - LOG_HEX(buffer, data_count); + if(data_count && buffer) + LOG_HEX(buffer, data_count); - if(count && kiss_decap) - LOG_HEX(kiss_decap, count); + if(count && kiss_decap) + LOG_HEX(kiss_decap, count); #endif - do { + do { - if(count > data_count || !kiss_decap) { - LOG_DEBUG("%s", "Kiss decode error"); - count = 0; - break; - } + if(count > data_count || !kiss_decap) { + LOG_DEBUG("%s", "Kiss decode error"); + count = 0; + break; + } - if(count > 2) - count -= 2; + if(count > 2) + count -= 2; - if(count) { - calc_crc_value = calc_fcs_crc(kiss_decap, (int) count); - } - else { - LOG_DEBUG("%s", "Kiss decode error"); - count = 0; - break; - } + if(count) { + calc_crc_value = calc_fcs_crc(kiss_decap, (int) count); + } + else { + LOG_DEBUG("%s", "Kiss decode error"); + count = 0; + break; + } - crc_value = CRC_LOW_HIGH(kiss_decap[count], kiss_decap[count + 1]); + crc_value = CRC_LOW_HIGH(kiss_decap[count], kiss_decap[count + 1]); - if(crc_value != calc_crc_value) { - count = 0; - break; - } + if(crc_value != calc_crc_value) { + count = 0; + break; + } - temp_disable_tx_inhibit = time(0) + DISABLE_TX_INHIBIT_DURATION; // valid packet, disable busy channel inhitbit for x duration. + temp_disable_tx_inhibit = time(0) + DISABLE_TX_INHIBIT_DURATION; // valid packet, disable busy channel inhitbit for x duration. - kiss_decap[count] = kiss_decap[count + 1] = 0; - memcpy(buffer, kiss_decap, count); + kiss_decap[count] = kiss_decap[count + 1] = 0; + memcpy(buffer, kiss_decap, count); - if(progdefaults.ax25_decode_enabled) { - ax25_decode((unsigned char *) buffer, count, true, false); - } + if(progdefaults.ax25_decode_enabled) { + ax25_decode((unsigned char *) buffer, count, true, false); + } - break; - } while(1); + break; + } while(1); - if(kiss_decap) { - kiss_decap[0] = 0; - delete [] kiss_decap; - } + if(kiss_decap) { + kiss_decap[0] = 0; + delete [] kiss_decap; + } - return count; + return count; } @@ -2327,113 +2407,113 @@ static size_t decap_hdlc_frame(char *buffer, size_t data_count) **********************************************************************************/ static KISS_QUEUE_FRAME *encap_kiss_frame(char *buffer, size_t buffer_size, int frame_type, int port) { - if(!buffer || buffer_size < 1) { - LOG_DEBUG("%s", "KISS encap argument 'data' contains no data"); - return (KISS_QUEUE_FRAME *)0; - } + if(!buffer || buffer_size < 1) { + LOG_DEBUG("%s", "KISS encap argument 'data' contains no data"); + return (KISS_QUEUE_FRAME *)0; + } - if(port > 0xF || port < 0) { - LOG_DEBUG("Invalid KISS port number (%d)", port); - return (KISS_QUEUE_FRAME *)0; - } + if(port > 0xF || port < 0) { + LOG_DEBUG("Invalid KISS port number (%d)", port); + return (KISS_QUEUE_FRAME *)0; + } - switch(frame_type) { - case KISS_DATA: - case KISS_RAW: - case KISS_TXDELAY: - case KISS_PERSIST: - case KISS_SLOTTIME: - case KISS_TXTAIL: - case KISS_DUPLEX: - case KISS_HARDWARE: - break; + switch(frame_type) { + case KISS_DATA: + case KISS_RAW: + case KISS_TXDELAY: + case KISS_PERSIST: + case KISS_SLOTTIME: + case KISS_TXTAIL: + case KISS_DUPLEX: + case KISS_HARDWARE: + break; - default: - LOG_DEBUG("Invalid KISS frame type (%d)", frame_type); - return (KISS_QUEUE_FRAME *)0; - } + default: + LOG_DEBUG("Invalid KISS frame type (%d)", frame_type); + return (KISS_QUEUE_FRAME *)0; + } - int size = 0; - int index = 0; - unsigned int crc_value = 0; - KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; + int size = 0; + int index = 0; + unsigned int crc_value = 0; + KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; - frame = new KISS_QUEUE_FRAME; + frame = new KISS_QUEUE_FRAME; - if(!frame) { - LOG_DEBUG("%s", "KISS struct frame memory allocation error"); - return (KISS_QUEUE_FRAME *)0; - } + if(!frame) { + LOG_DEBUG("%s", "KISS struct frame memory allocation error"); + return (KISS_QUEUE_FRAME *)0; + } - size = (buffer_size * KISS_BUFFER_FACTOR) + BUFFER_PADDING; // Resulting data space could be 2 fold higher. - frame->data = (char *) new char[size]; + size = (buffer_size * KISS_BUFFER_FACTOR) + BUFFER_PADDING; // Resulting data space could be 2 fold higher. + frame->data = (char *) new char[size]; - if(!frame->data) { - delete frame; - LOG_DEBUG("%s", "KISS buffer frame memory allocation error"); - return (KISS_QUEUE_FRAME *)0; - } + if(!frame->data) { + delete frame; + LOG_DEBUG("%s", "KISS buffer frame memory allocation error"); + return (KISS_QUEUE_FRAME *)0; + } - memset(frame->data, 0, size); - size = buffer_size; + memset(frame->data, 0, size); + size = buffer_size; - frame->data[0] = SET_KISS_TYPE_PORT(frame_type, port); - memcpy(&frame->data[1], buffer, size); + frame->data[0] = SET_KISS_TYPE_PORT(frame_type, port); + memcpy(&frame->data[1], buffer, size); - size++; + size++; - if((frame_type == KISS_DATA) || (frame_type == KISS_RAW)) { + if((frame_type == KISS_DATA) || (frame_type == KISS_RAW)) { - if(smack_crc_enabled) { + if(smack_crc_enabled) { - frame->data[0] = SMACK_CRC_ASSIGN(frame->data[0]); + frame->data[0] = SMACK_CRC_ASSIGN(frame->data[0]); - switch(crc_mode) { - case CRC16_CCITT: - crc_value = calc_ccitt_crc((char *) frame->data, size); - frame->data[size++] = CRC_LOW(crc_value); - frame->data[size++] = CRC_HIGH(crc_value); - break; + switch(crc_mode) { + case CRC16_CCITT: + crc_value = calc_ccitt_crc((char *) frame->data, size); + frame->data[size++] = CRC_LOW(crc_value); + frame->data[size++] = CRC_HIGH(crc_value); + break; - case CRC16_FCS: - crc_value = calc_fcs_crc((char *) frame->data, size); - frame->data[size++] = CRC_LOW(crc_value); - frame->data[size++] = CRC_HIGH(crc_value); - break; + case CRC16_FCS: + crc_value = calc_fcs_crc((char *) frame->data, size); + frame->data[size++] = CRC_LOW(crc_value); + frame->data[size++] = CRC_HIGH(crc_value); + break; - case CRC8_XOR: - crc_value = calc_xor_crc((char *) frame->data, size); - frame->data[size++] = CRC_LOW(crc_value); - break; + case CRC8_XOR: + crc_value = calc_xor_crc((char *) frame->data, size); + frame->data[size++] = CRC_LOW(crc_value); + break; - default: - break; - } - } - } + default: + break; + } + } + } - char *tmp = (char *)0; + char *tmp = (char *)0; - index = kiss_encode((char *) frame->data, size, &tmp); + index = kiss_encode((char *) frame->data, size, &tmp); - if(tmp) { + if(tmp) { #ifdef EXTENED_DEBUG_INFO - LOG_HEX(tmp, index); + LOG_HEX(tmp, index); #endif - frame->data[0] = 0; - delete [] frame->data; - frame->data = (char *) tmp; - frame->size = index; - } else { - LOG_DEBUG("KISS encode allocation error near line %d", __LINE__); - delete [] frame->data; - delete frame; - frame = (KISS_QUEUE_FRAME *)0; - } + frame->data[0] = 0; + delete [] frame->data; + frame->data = (char *) tmp; + frame->size = index; + } else { + LOG_DEBUG("KISS encode allocation error near line %d", __LINE__); + delete [] frame->data; + delete frame; + frame = (KISS_QUEUE_FRAME *)0; + } - return frame; + return frame; } /********************************************************************************** @@ -2441,8 +2521,8 @@ static KISS_QUEUE_FRAME *encap_kiss_frame(char *buffer, size_t buffer_size, int **********************************************************************************/ static KISS_QUEUE_FRAME * encap_kiss_frame(std::string data, int frame_type, int port) { - if(data.empty()) return (KISS_QUEUE_FRAME *)0; - return encap_kiss_frame((char *) data.c_str(), (size_t) data.size(), frame_type, port); + if(data.empty()) return (KISS_QUEUE_FRAME *)0; + return encap_kiss_frame((char *) data.c_str(), (size_t) data.size(), frame_type, port); } /********************************************************************************** @@ -2450,100 +2530,100 @@ static KISS_QUEUE_FRAME * encap_kiss_frame(std::string data, int frame_type, int **********************************************************************************/ std::string unencap_kiss_frame(char *buffer, size_t buffer_size, int *frame_type, int *kiss_port_no) { - if(!buffer || buffer_size < 1 || !frame_type || !kiss_port_no) - return std::string(""); + if(!buffer || buffer_size < 1 || !frame_type || !kiss_port_no) + return std::string(""); - char *decoded_buffer = (char *)0; - size_t count = 0; - unsigned int crc_extracted = 0; - unsigned int crc_calc = 0; - unsigned int port = 0; - unsigned int ftype = 0; + char *decoded_buffer = (char *)0; + size_t count = 0; + unsigned int crc_extracted = 0; + unsigned int crc_calc = 0; + unsigned int port = 0; + unsigned int ftype = 0; - static std::string ret_str = ""; + static std::string ret_str = ""; - ret_str.clear(); + ret_str.clear(); #ifdef EXTENED_DEBUG_INFO - LOG_HEX(buffer, buffer_size); + LOG_HEX(buffer, buffer_size); #endif - count = kiss_decode(buffer, buffer_size, &decoded_buffer); + count = kiss_decode(buffer, buffer_size, &decoded_buffer); - if(!count || !decoded_buffer) { - LOG_DEBUG("Kiss decoder memory allocation error near line %d", __LINE__); - return ret_str; - } + if(!count || !decoded_buffer) { + LOG_DEBUG("Kiss decoder memory allocation error near line %d", __LINE__); + return ret_str; + } - ftype = KISS_CMD(decoded_buffer[0]); - port = KISS_PORT(decoded_buffer[0]); + ftype = KISS_CMD(decoded_buffer[0]); + port = KISS_PORT(decoded_buffer[0]); - if((ftype == KISS_DATA) || (ftype == KISS_RAW)) { - smack_crc_enabled = SMACK_CRC(port); - port = SMACK_CRC_MASK(port); + if((ftype == KISS_DATA) || (ftype == KISS_RAW)) { + smack_crc_enabled = SMACK_CRC(port); + port = SMACK_CRC_MASK(port); - if(smack_crc_enabled) { - switch(crc_mode) { - case CRC16_CCITT: - count -= 2; - if(count > 2) { - crc_calc = calc_ccitt_crc(decoded_buffer, count); - crc_extracted = CRC_LOW_HIGH(decoded_buffer[count], decoded_buffer[count + 1]); - } else { - crc_calc = crc_extracted + 1; // Force a fail - } - break; + if(smack_crc_enabled) { + switch(crc_mode) { + case CRC16_CCITT: + count -= 2; + if(count > 2) { + crc_calc = calc_ccitt_crc(decoded_buffer, count); + crc_extracted = CRC_LOW_HIGH(decoded_buffer[count], decoded_buffer[count + 1]); + } else { + crc_calc = crc_extracted + 1; // Force a fail + } + break; - case CRC16_FCS: - count -= 2; - if(count > 2) { - crc_calc = calc_fcs_crc(decoded_buffer, count); - crc_extracted = CRC_LOW_HIGH(decoded_buffer[count], decoded_buffer[count + 1]); - } else { - crc_calc = crc_extracted + 1; - } - break; + case CRC16_FCS: + count -= 2; + if(count > 2) { + crc_calc = calc_fcs_crc(decoded_buffer, count); + crc_extracted = CRC_LOW_HIGH(decoded_buffer[count], decoded_buffer[count + 1]); + } else { + crc_calc = crc_extracted + 1; + } + break; - case CRC8_XOR: - count -= 1; - if(count > 1) { - crc_calc = CRC_LOW(calc_fcs_crc(decoded_buffer, count)); - crc_extracted = CRC_LOW(decoded_buffer[count]); - } else { - crc_calc = crc_extracted + 1; - } - break; + case CRC8_XOR: + count -= 1; + if(count > 1) { + crc_calc = CRC_LOW(calc_fcs_crc(decoded_buffer, count)); + crc_extracted = CRC_LOW(decoded_buffer[count]); + } else { + crc_calc = crc_extracted + 1; + } + break; - default: - LOG_DEBUG("CRC type not found %d", crc_mode); - } + default: + LOG_DEBUG("CRC type not found %d", crc_mode); + } - if(crc_calc != crc_extracted) { + if(crc_calc != crc_extracted) { - if(frame_type) *frame_type = ftype; - if(kiss_port_no) *kiss_port_no = port; - if(decoded_buffer) delete [] decoded_buffer; + if(frame_type) *frame_type = ftype; + if(kiss_port_no) *kiss_port_no = port; + if(decoded_buffer) delete [] decoded_buffer; - ret_str.clear(); - return ret_str; - } - } - } + ret_str.clear(); + return ret_str; + } + } + } - if(count > 0) - count--; + if(count > 0) + count--; #ifdef EXTENED_DEBUG_INFO - LOG_HEX(&decoded_buffer[1], count); + LOG_HEX(&decoded_buffer[1], count); #endif - ret_str.assign(&decoded_buffer[1], count); + ret_str.assign(&decoded_buffer[1], count); - if(frame_type) *frame_type = ftype; - if(kiss_port_no) *kiss_port_no = port; - if(decoded_buffer) delete [] decoded_buffer; + if(frame_type) *frame_type = ftype; + if(kiss_port_no) *kiss_port_no = port; + if(decoded_buffer) delete [] decoded_buffer; - return ret_str; + return ret_str; } /********************************************************************************** @@ -2551,10 +2631,10 @@ std::string unencap_kiss_frame(char *buffer, size_t buffer_size, int *frame_type **********************************************************************************/ std::string unencap_kiss_frame(std::string package, int *frame_type, int *kiss_port_no) { - if(package.empty() || !frame_type || !kiss_port_no) - return std::string(""); + if(package.empty() || !frame_type || !kiss_port_no) + return std::string(""); - return unencap_kiss_frame((char *) package.c_str(), (size_t) package.size(), frame_type, kiss_port_no); + return unencap_kiss_frame((char *) package.c_str(), (size_t) package.size(), frame_type, kiss_port_no); } /********************************************************************************** @@ -2562,66 +2642,66 @@ std::string unencap_kiss_frame(std::string package, int *frame_type, int *kiss_p **********************************************************************************/ static void parse_hardware_frame(std::string frame) { - if(frame.empty()) return; + if(frame.empty()) return; - string cmd = ""; - string arg = ""; - static char buffer[512]; - string parse_frame = ""; - char bofmsg[] = "Temp Buffer overflow"; - size_t count = frame.size(); - size_t index = 0; - size_t pos = 0; - size_t j = 0; + string cmd = ""; + string arg = ""; + static char buffer[512]; + string parse_frame = ""; + char bofmsg[] = "Temp Buffer overflow"; + size_t count = frame.size(); + size_t index = 0; + size_t pos = 0; + size_t j = 0; - parse_frame.assign(frame); + parse_frame.assign(frame); #ifdef EXTENED_DEBUG_INFO - LOG_HEX(frame.c_str(), frame.size()); + LOG_HEX(frame.c_str(), frame.size()); #endif - do { - if(kiss_reset_flag) return; + do { + if(kiss_reset_flag) return; - pos = parse_frame.find(":"); + pos = parse_frame.find(":"); - if(pos == string::npos) return; + if(pos == string::npos) return; - j = 0; - memset(buffer, 0, sizeof(buffer)); - for(index = 0; index < pos; index++) { - if(parse_frame[index] <= ' ') continue; - buffer[j++] = toupper(parse_frame[index]); - if(j >= sizeof(buffer)) { - LOG_DEBUG("%s", bofmsg); - return; - } - } - cmd.assign(buffer); + j = 0; + memset(buffer, 0, sizeof(buffer)); + for(index = 0; index < pos; index++) { + if(parse_frame[index] <= ' ') continue; + buffer[j++] = toupper(parse_frame[index]); + if(j >= sizeof(buffer)) { + LOG_DEBUG("%s", bofmsg); + return; + } + } + cmd.assign(buffer); - j = 0; - memset(buffer, 0, sizeof(buffer)); - for(index = pos + 1; index < count; index++) { - if(parse_frame[index] <= ' ') break; - buffer[j++] = parse_frame[index]; - if(j >= sizeof(buffer)) { - LOG_DEBUG("%s", bofmsg); - return; - } - } - arg.assign(buffer); + j = 0; + memset(buffer, 0, sizeof(buffer)); + for(index = pos + 1; index < count; index++) { + if(parse_frame[index] <= ' ') break; + buffer[j++] = parse_frame[index]; + if(j >= sizeof(buffer)) { + LOG_DEBUG("%s", bofmsg); + return; + } + } + arg.assign(buffer); - if(cmd.empty()) return; + if(cmd.empty()) return; - exec_hardware_command(cmd, arg); + exec_hardware_command(cmd, arg); - if(index > count) - index = count; + if(index > count) + index = count; - parse_frame.erase(0, index); - count = parse_frame.size(); + parse_frame.erase(0, index); + count = parse_frame.size(); - } while(count > 0); + } while(count > 0); } @@ -2630,150 +2710,150 @@ static void parse_hardware_frame(std::string frame) **********************************************************************************/ static void parse_kiss_frame(std::string frame_segment) { - guard_lock kiss_rx_lock(&kiss_frame_mutex); + guard_lock kiss_rx_lock(&kiss_frame_mutex); - unsigned int cur_byte = KISS_INVALID; - unsigned int frame_size = 0; - unsigned int index = 0; - unsigned int fend_count = 0; - unsigned int cmsa_data = 0; - int buffer_size = 0; - int port_no = KISS_INVALID; - int frame_type = KISS_INVALID; - int data_count = 0; + unsigned int cur_byte = KISS_INVALID; + unsigned int frame_size = 0; + unsigned int index = 0; + unsigned int fend_count = 0; + unsigned int cmsa_data = 0; + int buffer_size = 0; + int port_no = KISS_INVALID; + int frame_type = KISS_INVALID; + int data_count = 0; - bool process_one_frame = false; - char *buffer = (char *)0; + bool process_one_frame = false; + char *buffer = (char *)0; - kiss_frame.append(frame_segment); + kiss_frame.append(frame_segment); - while(1) { + while(1) { - if(kiss_frame.empty()) return; + if(kiss_frame.empty()) return; - frame_size = kiss_frame.size(); - process_one_frame = false; - fend_count = 0; - kiss_one_frame.clear(); + frame_size = kiss_frame.size(); + process_one_frame = false; + fend_count = 0; + kiss_one_frame.clear(); - for(index = 0; index < frame_size; index++) { - cur_byte = kiss_frame[index] & 0xFF; + for(index = 0; index < frame_size; index++) { + cur_byte = kiss_frame[index] & 0xFF; - if(cur_byte == KISS_FEND) { - fend_count++; - } + if(cur_byte == KISS_FEND) { + fend_count++; + } - if(fend_count) { - kiss_one_frame += cur_byte; - } + if(fend_count) { + kiss_one_frame += cur_byte; + } - if(fend_count == 2) { - kiss_frame.erase(0, index); - process_one_frame = true; - break; - } - } + if(fend_count == 2) { + kiss_frame.erase(0, index); + process_one_frame = true; + break; + } + } - if(!process_one_frame) - return; + if(!process_one_frame) + return; - frame_size = kiss_one_frame.size(); + frame_size = kiss_one_frame.size(); - if(frame_size < 3) { - continue; // Invalid Frame size - } + if(frame_size < 3) { + continue; // Invalid Frame size + } - kiss_one_frame = unencap_kiss_frame(kiss_one_frame, &frame_type, &port_no); + kiss_one_frame = unencap_kiss_frame(kiss_one_frame, &frame_type, &port_no); - if(kiss_one_frame.empty()) - continue; + if(kiss_one_frame.empty()) + continue; - if(port_no != (int)kiss_port_no) { - continue; - } + if(port_no != (int)kiss_port_no) { + continue; + } - switch(frame_type) { - case KISS_TXDELAY: - case KISS_PERSIST: - case KISS_SLOTTIME: - case KISS_TXTAIL: - case KISS_DUPLEX: - cmsa_data = kiss_one_frame[0] & 0xFF; - break; + switch(frame_type) { + case KISS_TXDELAY: + case KISS_PERSIST: + case KISS_SLOTTIME: + case KISS_TXTAIL: + case KISS_DUPLEX: + cmsa_data = kiss_one_frame[0] & 0xFF; + break; - case KISS_DATA: - if(kiss_raw_enabled == KISS_RAW_ONLY) - continue; - break; + case KISS_DATA: + if(kiss_raw_enabled == KISS_RAW_ONLY) + continue; + break; - case KISS_RAW: - if(kiss_raw_enabled == KISS_RAW_DISABLED) - continue; - break; + case KISS_RAW: + if(kiss_raw_enabled == KISS_RAW_DISABLED) + continue; + break; - case KISS_HARDWARE: - break; + case KISS_HARDWARE: + break; - default: - continue; // Unreconized frame_type. + default: + continue; // Unreconized frame_type. - } - // int c = 0; + } + // int c = 0; - switch(frame_type) { - case KISS_DATA: - buffer_size = (frame_size * HDLC_BUFFER_FACTOR) + BUFFER_PADDING; - buffer = new char[buffer_size]; + switch(frame_type) { + case KISS_DATA: + buffer_size = (frame_size * HDLC_BUFFER_FACTOR) + BUFFER_PADDING; + buffer = new char[buffer_size]; - if(!buffer) { - LOG_DEBUG("%s", "Buffer Allocation Error"); - return; - } - data_count = kiss_one_frame.size(); - memset(buffer, 0, buffer_size); - memcpy(buffer, kiss_one_frame.c_str(), data_count); + if(!buffer) { + LOG_DEBUG("%s", "Buffer Allocation Error"); + return; + } + data_count = kiss_one_frame.size(); + memset(buffer, 0, buffer_size); + memcpy(buffer, kiss_one_frame.c_str(), data_count); - data_count = encap_hdlc_frame(buffer, data_count); + data_count = encap_hdlc_frame(buffer, data_count); - WriteToRadioBuffered((const char *) buffer, (size_t) data_count); + WriteToRadioBuffered((const char *) buffer, (size_t) data_count); - buffer[0] = 0; - delete [] buffer; - buffer = 0; + buffer[0] = 0; + delete [] buffer; + buffer = 0; - break; + break; - case KISS_RAW: - WriteToRadioBuffered((const char *) kiss_one_frame.c_str(), (size_t) kiss_one_frame.size()); - break; + case KISS_RAW: + WriteToRadioBuffered((const char *) kiss_one_frame.c_str(), (size_t) kiss_one_frame.size()); + break; - case KISS_TXDELAY: - tx_delay = cmsa_data; - break; + case KISS_TXDELAY: + tx_delay = cmsa_data; + break; - case KISS_PERSIST: - persistance = cmsa_data; - break; + case KISS_PERSIST: + persistance = cmsa_data; + break; - case KISS_SLOTTIME: - slot_time = cmsa_data; - break; + case KISS_SLOTTIME: + slot_time = cmsa_data; + break; - case KISS_TXTAIL: - break; + case KISS_TXTAIL: + break; - case KISS_DUPLEX: - if(cmsa_data) - duplex = KISS_FULL_DUPLEX; - else - duplex = KISS_HALF_DUPLEX; - break; + case KISS_DUPLEX: + if(cmsa_data) + duplex = KISS_FULL_DUPLEX; + else + duplex = KISS_HALF_DUPLEX; + break; - case KISS_HARDWARE: - parse_hardware_frame(kiss_one_frame); - break; - } - } // while(1) + case KISS_HARDWARE: + parse_hardware_frame(kiss_one_frame); + break; + } + } // while(1) } #if 0 @@ -2782,8 +2862,8 @@ static void parse_kiss_frame(std::string frame_segment) **********************************************************************************/ static void WriteToHostBuffered(const char data) { - guard_lock to_host_lock(&to_host_mutex); - to_host += data; + guard_lock to_host_lock(&to_host_mutex); + to_host += data; } /********************************************************************************** @@ -2791,8 +2871,8 @@ static void WriteToHostBuffered(const char data) **********************************************************************************/ static void WriteToHostBuffered(const char *data) { - guard_lock to_host_lock(&to_host_mutex); - to_host.append(data); + guard_lock to_host_lock(&to_host_mutex); + to_host.append(data); } #endif // #if 0 @@ -2801,8 +2881,8 @@ static void WriteToHostBuffered(const char *data) **********************************************************************************/ static void WriteToHostBuffered(const char *data, size_t size) { - guard_lock to_host_lock(&to_host_mutex); - to_host.append(data, size); + guard_lock to_host_lock(&to_host_mutex); + to_host.append(data, size); } #if 0 @@ -2811,9 +2891,9 @@ static void WriteToHostBuffered(const char *data, size_t size) **********************************************************************************/ static void WriteToRadioBuffered(unsigned char data) { - guard_lock to_radio_lock(&to_radio_mutex); - set_tx_timeout(); - to_radio += data; + guard_lock to_radio_lock(&to_radio_mutex); + set_tx_timeout(); + to_radio += data; } /********************************************************************************** @@ -2821,10 +2901,10 @@ static void WriteToRadioBuffered(unsigned char data) **********************************************************************************/ static void WriteToRadioBuffered(const char *data) { - guard_lock to_radio_lock(&to_radio_mutex); - if(!data) return; - set_tx_timeout(); - to_radio.append(data); + guard_lock to_radio_lock(&to_radio_mutex); + if(!data) return; + set_tx_timeout(); + to_radio.append(data); } #endif // #if 0 @@ -2833,10 +2913,10 @@ static void WriteToRadioBuffered(const char *data) **********************************************************************************/ static void WriteToRadioBuffered(const char *data, size_t size) { - guard_lock to_radio_lock(&to_radio_mutex); - if(!data || size < 1) return; - set_tx_timeout(); - to_radio.append(data, size); + guard_lock to_radio_lock(&to_radio_mutex); + if(!data || size < 1) return; + set_tx_timeout(); + to_radio.append(data, size); } /********************************************************************************** @@ -2844,9 +2924,9 @@ static void WriteToRadioBuffered(const char *data, size_t size) **********************************************************************************/ inline void set_tx_timeout(void) { - if(to_radio.empty()) { - transmit_buffer_flush_timeout = time(0) + TX_BUFFER_TIMEOUT; - } + if(to_radio.empty()) { + transmit_buffer_flush_timeout = time(0) + TX_BUFFER_TIMEOUT; + } } /********************************************************************************** @@ -2856,46 +2936,46 @@ inline void set_tx_timeout(void) #if 0 static double detect_bandpass_signal(void) { - int freq = 0; - int bw = 500; - int freq_step = 64; - int freq_pos = 0; - int start_freq = freq - (bw >> 1); - int end_freq = freq + (bw >> 1); - int freq_half_step = freq_step >> 1; - double low_value = FLT_MAX; - double high_value = FLT_MIN; - double ratio = 0; - double high_ratio = FLT_MIN; - double low_ratio = FLT_MAX; - double pd = 0; + int freq = 0; + int bw = 500; + int freq_step = 64; + int freq_pos = 0; + int start_freq = freq - (bw >> 1); + int end_freq = freq + (bw >> 1); + int freq_half_step = freq_step >> 1; + double low_value = FLT_MAX; + double high_value = FLT_MIN; + double ratio = 0; + double high_ratio = FLT_MIN; + double low_ratio = FLT_MAX; + double pd = 0; - for(freq = 500; freq < 3000; freq += 500) { + for(freq = 500; freq < 3000; freq += 500) { - start_freq = freq - (bw >> 1); - end_freq = freq + (bw >> 1); - freq_half_step = freq_step >> 1; - low_value = FLT_MAX; - high_value = FLT_MIN; - ratio = 0; - pd = 0; + start_freq = freq - (bw >> 1); + end_freq = freq + (bw >> 1); + freq_half_step = freq_step >> 1; + low_value = FLT_MAX; + high_value = FLT_MIN; + ratio = 0; + pd = 0; - for(; start_freq <= end_freq; start_freq += freq_step) { - freq_pos = start_freq + freq_half_step; - pd = wf->powerDensity((double) freq_pos, (double) freq_step); - if(pd < low_value) low_value = pd; - if(pd > high_value) high_value = pd; - } + for(; start_freq <= end_freq; start_freq += freq_step) { + freq_pos = start_freq + freq_half_step; + pd = wf->powerDensity((double) freq_pos, (double) freq_step); + if(pd < low_value) low_value = pd; + if(pd > high_value) high_value = pd; + } - ratio = (ratio + (high_value/low_value)) * 0.5; - //ratio = high_value/low_value; + ratio = (ratio + (high_value/low_value)) * 0.5; + //ratio = high_value/low_value; - if(high_ratio < ratio) high_ratio = ratio; - if(low_ratio > ratio) low_ratio = ratio; + if(high_ratio < ratio) high_ratio = ratio; + if(low_ratio > ratio) low_ratio = ratio; - } + } - return high_ratio; + return high_ratio; } #endif // #if 0 @@ -2907,11 +2987,11 @@ static double detect_bandpass_signal(void) #define IGNORE_PL_PERIOD 300 typedef struct { - time_t first_detected_time; - int pl_index; - int data_count; - double pl_indexed[PL_AVG_COUNT]; - double pl_avg; + time_t first_detected_time; + int pl_index; + int data_count; + double pl_indexed[PL_AVG_COUNT]; + double pl_avg; } POWER_MASK; POWER_MASK power_mask[4000]; @@ -2922,99 +3002,99 @@ POWER_MASK power_mask[4000]; **********************************************************************************/ static double detect_signal(int freq, int bw, double *low, double *high, double threshold) { - int freq_step = 15; - int freq_pos = 0; - int start_freq = freq - (bw >> 1); - int end_freq = freq + (bw >> 1); - int freq_half_step = freq_step >> 1; - int i = 0; - double low_value = FLT_MAX; - double high_value = FLT_MIN; - double ratio = 0.0; - double pd = 0; - double ratio_avg = 0.0; - static double pratio0 = 0.0; - static double pratio1 = 0.0; - static double pratio2 = 0.0; - static old_low = 20; + int freq_step = 15; + int freq_pos = 0; + int start_freq = freq - (bw >> 1); + int end_freq = freq + (bw >> 1); + int freq_half_step = freq_step >> 1; + int i = 0; + double low_value = FLT_MAX; + double high_value = FLT_MIN; + double ratio = 0.0; + double pd = 0; + double ratio_avg = 0.0; + static double pratio0 = 0.0; + static double pratio1 = 0.0; + static double pratio2 = 0.0; + static old_low = 20; - time_t current_time = time(0); + time_t current_time = time(0); - if(trx_state != STATE_RX) return ratio_avg; + if(trx_state != STATE_RX) return ratio_avg; - for(i = 0; start_freq <= end_freq; start_freq += freq_step, i++) { - freq_pos = start_freq + freq_half_step; - pd = wf->powerDensity((double) freq_pos, (double) freq_step); + for(i = 0; start_freq <= end_freq; start_freq += freq_step, i++) { + freq_pos = start_freq + freq_half_step; + pd = wf->powerDensity((double) freq_pos, (double) freq_step); - if(pd > threshold) { - if(!power_mask[i].first_detected_time) - power_mask[i].first_detected_time = current_time; + if(pd > threshold) { + if(!power_mask[i].first_detected_time) + power_mask[i].first_detected_time = current_time; - if(power_mask[i].data_count < PL_INDEX_COUNT) - power_mask[i].data_count++; + if(power_mask[i].data_count < PL_INDEX_COUNT) + power_mask[i].data_count++; - power_mask[i].pl_index = power_mask[i].pl_index & PL_INDEX_COUNT_MASK; - power_mask[i].pl_indexed[power_mask[i].pl_index] = pd; - power_mask[i].pl_index++; + power_mask[i].pl_index = power_mask[i].pl_index & PL_INDEX_COUNT_MASK; + power_mask[i].pl_indexed[power_mask[i].pl_index] = pd; + power_mask[i].pl_index++; - if(((power_mask[i].first_detected_time + IGNORE_PL_PERIOD) < current_time) && power_mask[i].pl_avg >= threshold) - pd = old_low; - } + if(((power_mask[i].first_detected_time + IGNORE_PL_PERIOD) < current_time) && power_mask[i].pl_avg >= threshold) + pd = old_low; + } - if(pd < low_value) old_low = low_value = pd; - if(pd > high_value) high_value = pd; - } + if(pd < low_value) old_low = low_value = pd; + if(pd > high_value) high_value = pd; + } - if(low) *low = low_value; - if(high) *high = high_value; + if(low) *low = low_value; + if(high) *high = high_value; - old_low = low_value; + old_low = low_value; - ratio = high_value/low_value; - ratio *= fractional_gain; - kpsql_pl = ratio_avg = (ratio + pratio0 + pratio1 + pratio2) * 0.25; + ratio = high_value/low_value; + ratio *= fractional_gain; + kpsql_pl = ratio_avg = (ratio + pratio0 + pratio1 + pratio2) * 0.25; - int j = 0; - int k = 0; - int count = 0; - doube temp_avg = 0.0; - for(j = 0; j < i; j++) { - count = power_mask[j].data_count; + int j = 0; + int k = 0; + int count = 0; + doube temp_avg = 0.0; + for(j = 0; j < i; j++) { + count = power_mask[j].data_count; - if(count < PL_INDEX_COUNT) continue; + if(count < PL_INDEX_COUNT) continue; - for(k = 0; i < count; k++) { - temp_avg += power_mask[j].pl_indexed[k]; - } + for(k = 0; i < count; k++) { + temp_avg += power_mask[j].pl_indexed[k]; + } - temp_avg /= (1.0 * count); + temp_avg /= (1.0 * count); - if(temp_avg < threshold) { - memset(&power_mask[j], 0, sizeof(POWER_MASK)); - continue; - } + if(temp_avg < threshold) { + memset(&power_mask[j], 0, sizeof(POWER_MASK)); + continue; + } - power_mask[j].pl_avg = temp_avg; - } + power_mask[j].pl_avg = temp_avg; + } - if(ratio_avg > 0.0 && ratio_avg <= (double) HISTO_COUNT) { - i = (int) ratio_avg; - i &= 0xFF; - histogram[i]++; + if(ratio_avg > 0.0 && ratio_avg <= (double) HISTO_COUNT) { + i = (int) ratio_avg; + i &= 0xFF; + histogram[i]++; - if(histogram[i] > HISTO_THRESH_HOLD) { - for(i = 0; i < HISTO_COUNT; i++) { - histogram[i] >>= 1; - } - return 0.0; - } - } + if(histogram[i] > HISTO_THRESH_HOLD) { + for(i = 0; i < HISTO_COUNT; i++) { + histogram[i] >>= 1; + } + return 0.0; + } + } - pratio2 = pratio1; - pratio1 = pratio0; - pratio0 = ratio; + pratio2 = pratio1; + pratio1 = pratio0; + pratio0 = ratio; - return ratio; + return ratio; } #else /********************************************************************************** @@ -3023,67 +3103,67 @@ static double detect_signal(int freq, int bw, double *low, double *high, double **********************************************************************************/ static double detect_signal(int freq, int bw, double *low, double *high) { - int freq_step = 10; - int freq_pos = 0; - int start_freq = freq - (bw >> 1); - int end_freq = freq + (bw >> 1); - int freq_half_step = freq_step >> 1; - int i = 0; - double low_value = FLT_MAX; - double high_value = FLT_MIN; - double ratio = 0.0; - double pd = 0; - double ratio_avg = 0.0; - static double pratio0 = 0.0; - static double pratio1 = 0.0; - static double pratio2 = 0.0; - static double pratio3 = 0.0; + int freq_step = 10; + int freq_pos = 0; + int start_freq = freq - (bw >> 1); + int end_freq = freq + (bw >> 1); + int freq_half_step = freq_step >> 1; + int i = 0; + double low_value = FLT_MAX; + double high_value = FLT_MIN; + double ratio = 0.0; + double pd = 0; + double ratio_avg = 0.0; + static double pratio0 = 0.0; + static double pratio1 = 0.0; + static double pratio2 = 0.0; + static double pratio3 = 0.0; - if(trx_state != STATE_RX) return ratio_avg; + if(trx_state != STATE_RX) return ratio_avg; - for(i = 0; start_freq <= end_freq; start_freq += freq_step, i++) { - freq_pos = start_freq + freq_half_step; - pd = wf->powerDensity((double) freq_pos, (double) freq_step); - if(pd < low_value) low_value = pd; - if(pd > high_value) high_value = pd; - } + for(i = 0; start_freq <= end_freq; start_freq += freq_step, i++) { + freq_pos = start_freq + freq_half_step; + pd = wf->powerDensity((double) freq_pos, (double) freq_step); + if(pd < low_value) low_value = pd; + if(pd > high_value) high_value = pd; + } - if(low) *low = low_value; - if(high) *high = high_value; + if(low) *low = low_value; + if(high) *high = high_value; - ratio = high_value/low_value; - ratio *= fractional_gain; + ratio = high_value/low_value; + ratio *= fractional_gain; - kpsql_pl = ratio_avg = (ratio + pratio0 + pratio1 + pratio2 + pratio3) * 0.20; + kpsql_pl = ratio_avg = (ratio + pratio0 + pratio1 + pratio2 + pratio3) * 0.20; - if((ratio_avg > 0.0) && (ratio_avg <= (double) HISTO_COUNT)) { - i = (int) ratio_avg; - i &= 0xFF; - histogram[i]++; + if((ratio_avg > 0.0) && (ratio_avg <= (double) HISTO_COUNT)) { + i = (int) ratio_avg; + i &= 0xFF; + histogram[i]++; - if(histogram[i] > HISTO_THRESH_HOLD) { - for(i = 0; i < HISTO_COUNT; i++) { - histogram[i] >>= 1; - } - return 0.0; - } - } + if(histogram[i] > HISTO_THRESH_HOLD) { + for(i = 0; i < HISTO_COUNT; i++) { + histogram[i] >>= 1; + } + return 0.0; + } + } - pratio3 = pratio2; - pratio2 = pratio1; - pratio1 = pratio0; - pratio0 = ratio; + pratio3 = pratio2; + pratio2 = pratio1; + pratio1 = pratio0; + pratio0 = ratio; - return ratio; + return ratio; } #endif // 0 static void reset_histogram(void) { - memset(histogram, 0, sizeof(histogram)); - histogram[3] = 1; - inhibit_tx_seconds = time(0) + HISTO_RESET_TX_TIME; + memset(histogram, 0, sizeof(histogram)); + histogram[3] = 1; + inhibit_tx_seconds = time(0) + HISTO_RESET_TX_TIME; } /********************************************************************************** @@ -3091,28 +3171,28 @@ static void reset_histogram(void) **********************************************************************************/ static void update_sql_display(void) { - static int prev_power_level = 0; - static double convert_scale = (1.0 / ((double)HISTO_COUNT)); + static int prev_power_level = 0; + static double convert_scale = (1.0 / ((double)HISTO_COUNT)); - if(progStatus.pwrsqlonoff) { - double high_limit = 0; - double low_limit = 0; + if(progStatus.kpsql_enabled) { + double high_limit = 0; + double low_limit = 0; - if(kpsql_pl != prev_power_level) { - prev_power_level = kpsql_pl; - high_limit = sldrSquelch->maximum(); - low_limit = sldrSquelch->minimum(); - if(kpsql_pl > HISTO_COUNT) { - global_display_metric(low_limit); - } else { - double diff = high_limit - low_limit; - double scaled_value = kpsql_pl * convert_scale; - double convert_value = scaled_value * diff; - double results = high_limit - convert_value; - global_display_metric(results); - } - } - } + if(kpsql_pl != prev_power_level) { + prev_power_level = kpsql_pl; + high_limit = sldrSquelch->maximum(); + low_limit = sldrSquelch->minimum(); + if(kpsql_pl > HISTO_COUNT) { + global_display_metric(low_limit); + } else { + double diff = high_limit - low_limit; + double scaled_value = kpsql_pl * convert_scale; + double convert_value = scaled_value * diff; + double results = high_limit - convert_value; + global_display_metric(results); + } + } + } } /********************************************************************************** @@ -3120,20 +3200,20 @@ static void update_sql_display(void) **********************************************************************************/ static void flush_tx_buffer(void) { - int data_count = 0; + int data_count = 0; - { - guard_lock to_host_lock(&to_radio_mutex); - kiss_text_available = false; - pText = 0; - data_count = to_radio.size(); + { + guard_lock to_host_lock(&to_radio_mutex); + kiss_text_available = false; + pText = 0; + data_count = to_radio.size(); - if(data_count) - to_radio.clear(); - } + if(data_count) + to_radio.clear(); + } - if(data_count) - bcast_tx_buffer_empty_kiss_frame(); + if(data_count) + bcast_tx_buffer_empty_kiss_frame(); } /********************************************************************************** @@ -3141,30 +3221,30 @@ static void flush_tx_buffer(void) **********************************************************************************/ static void WriteToHostARQBuffered(void) { - std::string arq_data = ""; + std::string arq_data = ""; - { - guard_lock to_host_arq_lock(&to_host_arq_mutex); - int data_available = to_arq_host.size(); + { + guard_lock to_host_arq_lock(&to_host_arq_mutex); + int data_available = to_arq_host.size(); - if(kiss_raw_enabled == KISS_RAW_DISABLED) { - if(data_available) { - to_arq_host.clear(); - } - return; - } + if(kiss_raw_enabled == KISS_RAW_DISABLED) { + if(data_available) { + to_arq_host.clear(); + } + return; + } - if(data_available < 1) return; + if(data_available < 1) return; #ifdef EXTENED_DEBUG_INFO - LOG_HEX(to_arq_host.c_str(), to_arq_host.size()); + LOG_HEX(to_arq_host.c_str(), to_arq_host.size()); #endif - arq_data.assign(to_arq_host); - to_arq_host.clear(); - } + arq_data.assign(to_arq_host); + to_arq_host.clear(); + } - kiss_queue_frame(encap_kiss_frame(arq_data, KISS_RAW, kiss_port_no), string("ARQ")); + kiss_queue_frame(encap_kiss_frame(arq_data, KISS_RAW, kiss_port_no), string("ARQ")); } @@ -3173,180 +3253,180 @@ static void WriteToHostARQBuffered(void) **********************************************************************************/ static void TransmitCSMA(void) { - if(trx_state != STATE_RX) return; + if(trx_state != STATE_RX) return; - int data_flag = 0; - int loop_count = KISSLOOP_TIMING / KISSLOOP_FRACTION; - int half_count = loop_count >> 1; - unsigned int random_number = 0; - int index = 0; - // int skip = 0; - // int i = 0; - int bw = active_modem->get_bandwidth(); - int bw_margin = 100; - int freq = active_modem->get_txfreq(); - int delay_time = 0; - int delay_remainder = KISSLOOP_TIMING; - bool detected_signal = true; - time_t busyChannelSeconds = progdefaults.busyChannelSeconds; - int current_time = time(0); - double low = 0.0; - double high = 0.0; - double level = 0.0; + int data_flag = 0; + int loop_count = KISSLOOP_TIMING / KISSLOOP_FRACTION; + int half_count = loop_count >> 1; + unsigned int random_number = 0; + int index = 0; + // int skip = 0; + // int i = 0; + int bw = active_modem->get_bandwidth(); + int bw_margin = 100; + int freq = active_modem->get_txfreq(); + int delay_time = 0; + int delay_remainder = KISSLOOP_TIMING; + bool detected_signal = true; + time_t busyChannelSeconds = progdefaults.busyChannelSeconds; + int current_time = time(0); + double low = 0.0; + double high = 0.0; + double level = 0.0; - { - guard_lock to_radio_lock(&to_radio_mutex); - data_flag = to_radio.size(); - } + { + guard_lock to_radio_lock(&to_radio_mutex); + data_flag = to_radio.size(); + } - if(!progdefaults.enableBusyChannel) { - inhibit_tx_seconds = temp_disable_tx_inhibit = 0; - } + if(!progdefaults.enableBusyChannel) { + inhibit_tx_seconds = temp_disable_tx_inhibit = 0; + } - // Enabled on signal above threshold and option selected - if(inhibit_tx_seconds) { - if(current_time > inhibit_tx_seconds) - inhibit_tx_seconds = 0; - } + // Enabled on signal above threshold and option selected + if(inhibit_tx_seconds) { + if(current_time > inhibit_tx_seconds) + inhibit_tx_seconds = 0; + } - // Enabled on valid packet reception. - if(temp_disable_tx_inhibit) { - if(current_time > temp_disable_tx_inhibit) { - temp_disable_tx_inhibit = 0; - } - busyChannelSeconds = 1; - } + // Enabled on valid packet reception. + if(temp_disable_tx_inhibit) { + if(current_time > temp_disable_tx_inhibit) { + temp_disable_tx_inhibit = 0; + } + busyChannelSeconds = 1; + } - // If busy for an extended time flush transmit buffer - if((current_time > (int)transmit_buffer_flush_timeout) && data_flag) { - transmit_buffer_flush_timeout = current_time + TX_BUFFER_TIMEOUT; - flush_tx_buffer(); - data_flag = 0; - } + // If busy for an extended time flush transmit buffer + if((current_time > (int)transmit_buffer_flush_timeout) && data_flag) { + transmit_buffer_flush_timeout = current_time + TX_BUFFER_TIMEOUT; + flush_tx_buffer(); + data_flag = 0; + } - if(progStatus.pwrsqlonoff) { - threshold = (int) (progStatus.sldrPwrSquelchValue * 2.56); // Histogram scaled. - } else { - int idx = 0; - int first_value = 0; - int offset = 2; - for(index = 0; index < HISTO_COUNT; index++) { - if(histogram[index]) { - if(idx == 0) { - first_value = index; - } + if(progStatus.kpsql_enabled) { + threshold = (int) (progStatus.sldrPwrSquelchValue * 2.56); // Histogram scaled. + } else { + int idx = 0; + int first_value = 0; + int offset = 2; + for(index = 0; index < HISTO_COUNT; index++) { + if(histogram[index]) { + if(idx == 0) { + first_value = index; + } - if(idx >= offset) { - threshold = (double) index; - break; - } - idx++; - } - } + if(idx >= offset) { + threshold = (double) index; + break; + } + idx++; + } + } - if(index > HISTO_COUNT) { - threshold = (double) (first_value + offset); - } - } + if(index > HISTO_COUNT) { + threshold = (double) (first_value + offset); + } + } - kpsql_threshold = threshold; + kpsql_threshold = threshold; - // Minimum measured bandwidth set to KPSQL_MIN_BANDWIDTH Hz - if(bw < KPSQL_MIN_BANDWIDTH) { - bw = KPSQL_MIN_BANDWIDTH; - } + // Minimum measured bandwidth set to KPSQL_MIN_BANDWIDTH Hz + if(bw < KPSQL_MIN_BANDWIDTH) { + bw = KPSQL_MIN_BANDWIDTH; + } - if((data_flag < 1) || (inhibit_tx_seconds)) { - int no_of_hits = 0; - for(index = 0; index < loop_count; index++) { - level = detect_signal(freq, bw + bw_margin, &low, &high); + if((data_flag < 1) || (inhibit_tx_seconds)) { + int no_of_hits = 0; + for(index = 0; index < loop_count; index++) { + level = detect_signal(freq, bw + bw_margin, &low, &high); - if(progdefaults.enableBusyChannel) { - if(level > threshold) { - no_of_hits++; - if(no_of_hits > half_count) { - inhibit_tx_seconds = time(0) + busyChannelSeconds; - } - } - } - MilliSleep(loop_count); - } + if(progdefaults.enableBusyChannel) { + if(level > threshold) { + no_of_hits++; + if(no_of_hits > half_count) { + inhibit_tx_seconds = time(0) + busyChannelSeconds; + } + } + } + MilliSleep(loop_count); + } - return; - } + return; + } - for(index = 0; index < loop_count; index++) { - if(kiss_reset_flag) return; - int no_of_hits = 0; - level = detect_signal(freq, bw + bw_margin, &low, &high); - if(progdefaults.enableBusyChannel) { - if(level > threshold) { - no_of_hits++; - if(no_of_hits > half_count) { - inhibit_tx_seconds = time(0) + busyChannelSeconds; - return; - } - } - } + for(index = 0; index < loop_count; index++) { + if(kiss_reset_flag) return; + int no_of_hits = 0; + level = detect_signal(freq, bw + bw_margin, &low, &high); + if(progdefaults.enableBusyChannel) { + if(level > threshold) { + no_of_hits++; + if(no_of_hits > half_count) { + inhibit_tx_seconds = time(0) + busyChannelSeconds; + return; + } + } + } - if(level == 0) return; + if(level == 0) return; - if(level < threshold) { - detected_signal = false; - break; - } + if(level < threshold) { + detected_signal = false; + break; + } - MilliSleep(KISSLOOP_FRACTION); - delay_remainder -= KISSLOOP_FRACTION; - } + MilliSleep(KISSLOOP_FRACTION); + delay_remainder -= KISSLOOP_FRACTION; + } #undef DEBUG_HISTO #if defined DEBUG_HISTO - for(index = 0; index < 60; index++) - if(histogram[index]) - printf("%d = %d ", index, histogram[index]); - printf("\nL=%f T=%f\n", level, threshold); + for(index = 0; index < 60; index++) + if(histogram[index]) + printf("%d = %d ", index, histogram[index]); + printf("\nL=%f T=%f\n", level, threshold); #endif - if(detected_signal || inhibit_tx_seconds) { - return; - } + if(detected_signal || inhibit_tx_seconds) { + return; + } - if(progdefaults.csma_enabled) { - if(persistance > 1) { - random_number = rand() & 0xFF; - if(random_number > persistance) { - delay_time = (slot_time * 10); - MilliSleep(delay_time); - delay_remainder -= delay_time; + if(progdefaults.csma_enabled) { + if(persistance > 1) { + random_number = rand() & 0xFF; + if(random_number > persistance) { + delay_time = (slot_time * 10); + MilliSleep(delay_time); + delay_remainder -= delay_time; - if(delay_remainder > 0) - MilliSleep(delay_remainder); - return; - } - } + if(delay_remainder > 0) + MilliSleep(delay_remainder); + return; + } + } - delay_time = (tx_delay * 10); - idling = true; + delay_time = (tx_delay * 10); + idling = true; - if(trx_state == STATE_RX) - trx_transmit(); + if(trx_state == STATE_RX) + trx_transmit(); - if(delay_time > 0) - MilliSleep(delay_time); + if(delay_time > 0) + MilliSleep(delay_time); - } else { - if(trx_state == STATE_RX) - trx_transmit(); - } - - { - kiss_text_available = true; - idling = false; - active_modem->set_stopflag(false); - } - - transmit_buffer_flush_timeout = time(0) + TX_BUFFER_TIMEOUT; + } else { + if(trx_state == STATE_RX) + trx_transmit(); + } + + { + kiss_text_available = true; + idling = false; + active_modem->set_stopflag(false); + } + + transmit_buffer_flush_timeout = time(0) + TX_BUFFER_TIMEOUT; } #ifdef KISS_RX_THREAD @@ -3355,71 +3435,72 @@ static void TransmitCSMA(void) **********************************************************************************/ static void *ReadFromHostSocket(void *args) { - if(!kiss_socket) return (void *)0; - - static char buffer[2048]; - string str_buffer; - size_t count = 0; - Socket *tmp_socket = (Socket *)0; - memset(buffer, 0, sizeof(buffer)); - str_buffer.reserve(sizeof(buffer)); - - LOG_INFO("%s", "Kiss RX loop started. "); - - kiss_rx_exit = false; - allow_kiss_socket_io = false; - - if(progStatus.kiss_tcp_io && progStatus.kiss_tcp_listen) { - tmp_socket = kiss_socket->accept2(); - if(!tmp_socket) { - kiss_rx_exit = true; - } else { - kiss_socket->shut_down(); - kiss_socket->close(); - kiss_socket = tmp_socket; - } - } - - allow_kiss_socket_io = true; - - while(!kiss_rx_exit) { - - memset(buffer, 0, sizeof(buffer)); - - try { - if(allow_kiss_socket_io) { - if(progStatus.kiss_tcp_io) - count = kiss_socket->recv((void *) buffer, sizeof(buffer) - 1); - else - count = kiss_socket->recvFrom((void *) buffer, sizeof(buffer) - 1); - } - } catch (...) { - if (errno) LOG_INFO("recv/recvFrom Socket Error %d", errno); - count = 0; - } - - if((count == 0) && (errno != 0)) { - kiss_rx_exit = true; - } - - if(count && (data_io_enabled == KISS_IO)) { + if(!kiss_socket) return (void *)0; + + static char buffer[2048]; + string str_buffer; + size_t count = 0; + Socket *tmp_socket = (Socket *)0; + memset(buffer, 0, sizeof(buffer)); + str_buffer.reserve(sizeof(buffer)); + + LOG_INFO("%s", "Kiss RX loop started. "); + + kiss_rx_exit = false; + allow_kiss_socket_io = false; + + if(progStatus.kiss_tcp_io && progStatus.kiss_tcp_listen) { + tmp_socket = kiss_socket->accept2(); + if(!tmp_socket) { + kiss_rx_exit = true; + } else { + kiss_socket->shut_down(); + kiss_socket->close(); + kiss_socket = tmp_socket; + } + } + + allow_kiss_socket_io = true; + + while(!kiss_rx_exit) { + + memset(buffer, 0, sizeof(buffer)); + + try { + if(allow_kiss_socket_io) { + if(progStatus.kiss_tcp_io) + count = kiss_socket->recv((void *) buffer, sizeof(buffer) - 1); + else + count = kiss_socket->recvFrom((void *) buffer, sizeof(buffer) - 1); + } + } catch (...) { + if (errno) + LOG_INFO("recv/recvFrom Socket Error %d", errno); + count = 0; + } + + if((count == 0) && (errno != 0)) { + kiss_rx_exit = true; + } + + if(count && (data_io_enabled == KISS_IO)) { #ifdef EXTENED_DEBUG_INFO - LOG_HEX(buffer, count); + LOG_HEX(buffer, count); #endif - guard_lock from_host_lock(&from_host_mutex); - from_host.append(buffer, count); - } - } - - kiss_exit = true; - allow_kiss_socket_io = false; - if(kiss_socket) - kiss_socket->shut_down(); - - Fl::awake(kiss_main_thread_close, (void *) 0); - LOG_INFO("%s", "Kiss RX loop exit. "); - - return (void *)0; + guard_lock from_host_lock(&from_host_mutex); + from_host.append(buffer, count); + } + } + + kiss_exit = true; + allow_kiss_socket_io = false; + if(kiss_socket) + kiss_socket->shut_down(); + + Fl::awake(kiss_main_thread_close, (void *) 0); + LOG_INFO("%s", "Kiss RX loop exit. "); + + return (void *)0; } #else /********************************************************************************** @@ -3427,41 +3508,41 @@ static void *ReadFromHostSocket(void *args) **********************************************************************************/ static void ReadFromHostSocket() { - if(!kiss_socket) return; - - static char buffer[2048]; - string str_buffer; - size_t count = 0; - - memset(buffer, 0, sizeof(buffer)); - str_buffer.reserve(sizeof(buffer)); - - if(data_io_enabled != KISS_IO) { - if(str_buffer.size()) - str_buffer.clear(); - return; - } - - try { - if(allow_kiss_socket_io) { - if(progStatus.kiss_tcp_io) - count = kiss_socket->recv((void *) buffer, sizeof(buffer) - 1); - else - count = kiss_socket->recvFrom((void *) buffer, sizeof(buffer) - 1); - } - } catch (...) { - LOG_INFO("Kiss RX Loop Shutdown"); - count = 0; - kiss_rx_exit = true; - } - - if(count) { + if(!kiss_socket) return; + + static char buffer[2048]; + string str_buffer; + size_t count = 0; + + memset(buffer, 0, sizeof(buffer)); + str_buffer.reserve(sizeof(buffer)); + + if(data_io_enabled != KISS_IO) { + if(str_buffer.size()) + str_buffer.clear(); + return; + } + + try { + if(allow_kiss_socket_io) { + if(progStatus.kiss_tcp_io) + count = kiss_socket->recv((void *) buffer, sizeof(buffer) - 1); + else + count = kiss_socket->recvFrom((void *) buffer, sizeof(buffer) - 1); + } + } catch (...) { + LOG_INFO("Kiss RX Loop Shutdown"); + count = 0; + kiss_rx_exit = true; + } + + if(count) { #ifdef EXTENED_DEBUG_INFO - LOG_HEX(buffer, count); + LOG_HEX(buffer, count); #endif - guard_lock from_host_lock(&from_host_mutex); - from_host.append(buffer, count); - } + guard_lock from_host_lock(&from_host_mutex); + from_host.append(buffer, count); + } } #endif @@ -3473,51 +3554,51 @@ extern Progress *pgrsSquelch; **********************************************************************************/ static void *kiss_loop(void *args) { - SET_THREAD_ID(KISS_TID); - - int old_trx_state = STATE_TX; - - LOG_INFO("%s", "Kiss loop started. "); - - while(!kiss_exit){ - if(data_io_enabled != KISS_IO) { - MilliSleep(100); - kiss_text_available = false; - kiss_reset_buffers(); - continue; - } - - if(old_trx_state != trx_state) { - if(kiss_bcast_trx_toggle) { - switch(trx_state) { - case STATE_TX: - case STATE_RX: - case STATE_TUNE: - bcast_trxs_kiss_frame(trx_state); - default : - break; - } - } - - old_trx_state = trx_state; - } - - update_sql_display(); - ReadFromHostBuffered(); - ReadFromRadioBuffered(); - WriteToHostBCastFramesBuffered(); - WriteToHostARQBuffered(); - WriteToHostSocket(); - - TransmitCSMA(); // Loop delay located in this routine. - + SET_THREAD_ID(KISS_TID); + + int old_trx_state = STATE_TX; + + LOG_INFO("%s", "Kiss loop started. "); + + while(!kiss_exit){ + if(data_io_enabled != KISS_IO) { + MilliSleep(100); + kiss_text_available = false; + kiss_reset_buffers(); + continue; + } + + if(old_trx_state != trx_state) { + if(kiss_bcast_trx_toggle) { + switch(trx_state) { + case STATE_TX: + case STATE_RX: + case STATE_TUNE: + bcast_trxs_kiss_frame(trx_state); + default : + break; + } + } + + old_trx_state = trx_state; + } + + update_sql_display(); + ReadFromHostBuffered(); + ReadFromRadioBuffered(); + WriteToHostBCastFramesBuffered(); + WriteToHostARQBuffered(); + WriteToHostSocket(); + + TransmitCSMA(); // Loop delay located in this routine. + #ifndef KISS_RX_THREAD - ReadFromHostSocket(); + ReadFromHostSocket(); #endif - - } - // exit the kiss thread - return NULL; + MilliSleep(5); + } + // exit the kiss thread + return NULL; } @@ -3526,19 +3607,19 @@ static void *kiss_loop(void *args) **********************************************************************************/ void WriteKISS(const char data) { - if (active_modem->get_mode() == MODE_FSQ) return; - - if(kiss_reset_flag) return; - - { - guard_lock from_radio_lock(&from_radio_mutex); - from_radio += data; - } - - if(kiss_raw_enabled != KISS_RAW_DISABLED) { - guard_lock to_host_arq_lock(&to_host_arq_mutex); - to_arq_host += data; - } + if (active_modem->get_mode() == MODE_FSQ) return; + + if(kiss_reset_flag) return; + + { + guard_lock from_radio_lock(&from_radio_mutex); + from_radio += data; + } + + if(kiss_raw_enabled != KISS_RAW_DISABLED) { + guard_lock to_host_arq_lock(&to_host_arq_mutex); + to_arq_host += data; + } } /********************************************************************************** @@ -3546,21 +3627,21 @@ void WriteKISS(const char data) **********************************************************************************/ void WriteKISS(const char *data) { - if (active_modem->get_mode() == MODE_FSQ) return; - - if(kiss_reset_flag) return; - - { - guard_lock from_radio_lock(&from_radio_mutex); - if(data) - from_radio.append(data); - } - - { - guard_lock to_host_arq_lock(&to_host_arq_mutex); - if(data && (kiss_raw_enabled != KISS_RAW_DISABLED)) - to_arq_host.append(data); - } + if (active_modem->get_mode() == MODE_FSQ) return; + + if(kiss_reset_flag) return; + + { + guard_lock from_radio_lock(&from_radio_mutex); + if(data) + from_radio.append(data); + } + + { + guard_lock to_host_arq_lock(&to_host_arq_mutex); + if(data && (kiss_raw_enabled != KISS_RAW_DISABLED)) + to_arq_host.append(data); + } } /********************************************************************************** @@ -3568,23 +3649,23 @@ void WriteKISS(const char *data) **********************************************************************************/ void WriteKISS(const char *data, size_t size) { - if (active_modem->get_mode() == MODE_FSQ) return; - - if(kiss_reset_flag) return; - - { - guard_lock from_radio_lock(&from_radio_mutex); - if(data && size) { - from_radio.append(data, size); - } - } - - { - guard_lock to_host_arq_lock(&to_host_arq_mutex); - if(data && size && (kiss_raw_enabled != KISS_RAW_DISABLED)) { - to_arq_host.append(data, size); - } - } + if (active_modem->get_mode() == MODE_FSQ) return; + + if(kiss_reset_flag) return; + + { + guard_lock from_radio_lock(&from_radio_mutex); + if(data && size) { + from_radio.append(data, size); + } + } + + { + guard_lock to_host_arq_lock(&to_host_arq_mutex); + if(data && size && (kiss_raw_enabled != KISS_RAW_DISABLED)) { + to_arq_host.append(data, size); + } + } } /********************************************************************************** @@ -3592,23 +3673,23 @@ void WriteKISS(const char *data, size_t size) **********************************************************************************/ void WriteKISS(std::string data) { - if (active_modem->get_mode() == MODE_FSQ) return; - - if(kiss_reset_flag) return; - - { - guard_lock from_radio_lock(&from_radio_mutex); - if(!data.empty()) { - from_radio.append(data); - } - } - - { - guard_lock to_host_arq_lock(&to_host_arq_mutex); - if(!data.empty() && (kiss_raw_enabled != KISS_RAW_DISABLED)) { - to_arq_host.append(data); - } - } + if (active_modem->get_mode() == MODE_FSQ) return; + + if(kiss_reset_flag) return; + + { + guard_lock from_radio_lock(&from_radio_mutex); + if(!data.empty()) { + from_radio.append(data); + } + } + + { + guard_lock to_host_arq_lock(&to_host_arq_mutex); + if(!data.empty() && (kiss_raw_enabled != KISS_RAW_DISABLED)) { + to_arq_host.append(data); + } + } } /********************************************************************************** @@ -3616,24 +3697,30 @@ void WriteKISS(std::string data) **********************************************************************************/ void WriteToHostSocket(void) { - if(kiss_reset_flag) return; + if(kiss_reset_flag) return; - guard_lock to_host_lock(&to_host_mutex); - if(to_host.empty()) return; + guard_lock to_host_lock(&to_host_mutex); + size_t count = 0; - if(kiss_socket && data_io_enabled == KISS_IO) { - if(allow_kiss_socket_io) { - if(progStatus.kiss_tcp_io) - kiss_socket->send(to_host.c_str(), to_host.size()); - else - kiss_socket->sendTo(to_host.c_str(), to_host.size()); - } + if(to_host.empty()) return; + + if(kiss_socket && data_io_enabled == KISS_IO) { + if(allow_kiss_socket_io) { + if(progStatus.kiss_tcp_io) + count = kiss_socket->send(to_host.c_str(), to_host.size()); + else + count = kiss_socket->sendTo(to_host.c_str(), to_host.size()); + } #ifdef EXTENED_DEBUG_INFO - LOG_HEX(to_host.c_str(), to_host.size()); + LOG_HEX(to_host.c_str(), to_host.size()); #endif + if(count == 0) { + Fl::awake(kiss_main_thread_close, (void *) 0); + LOG_INFO("%s", "Write error to KISS socket. "); + } + } - } - to_host.clear(); + to_host.clear(); } /********************************************************************************** @@ -3641,15 +3728,15 @@ void WriteToHostSocket(void) **********************************************************************************/ static void ReadFromHostBuffered(void) { - if(!kiss_socket) return; - - guard_lock from_host_lock(&from_host_mutex); - if(from_host.empty()) return; + if(!kiss_socket) return; + + guard_lock from_host_lock(&from_host_mutex); + if(from_host.empty()) return; #ifdef EXTENED_DEBUG_INFO - LOG_HEX(from_host.c_str(), from_host.size()); + LOG_HEX(from_host.c_str(), from_host.size()); #endif - parse_kiss_frame(from_host); - from_host.clear(); + parse_kiss_frame(from_host); + from_host.clear(); } /********************************************************************************** @@ -3657,91 +3744,91 @@ static void ReadFromHostBuffered(void) **********************************************************************************/ void ReadFromRadioBuffered(void) { - if(kiss_reset_flag) return; - - guard_lock from_radio_lock(&from_radio_mutex); - if(from_radio.empty()) return; - - int pos = 0; - int pos2 = 0; - // unsigned int crc = 0; - KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; - static char frame_marker[2] = { (char)(KISS_FEND), 0 }; - std::string one_frame = ""; - - pos = from_radio.find(frame_marker); - - if(pos == (int)(std::string::npos)) { - from_radio.clear(); - return; - } - - if(pos != 0) { - from_radio.erase(0, pos); - pos = 0; - } - - pos2 = from_radio.find(frame_marker, pos + 1); - if(pos2 != (int)(std::string::npos)) { - one_frame.assign(from_radio, pos, pos2 - pos + 1); - } else { - if(from_radio.size() > MAX_TEMP_BUFFER_SIZE) - from_radio.clear(); - return; - } - - char *buffer = (char *)0; - size_t buffer_size = one_frame.size() + BUFFER_PADDING; - - buffer = new char [buffer_size]; - - if(!buffer) { - LOG_DEBUG("Memory Allocation Error Near Line No. %d", __LINE__); - goto EXIT; - } - - memset(buffer, 0, buffer_size); - - buffer_size = one_frame.size(); - memcpy(buffer, one_frame.c_str(), buffer_size); - + if(kiss_reset_flag) return; + + guard_lock from_radio_lock(&from_radio_mutex); + if(from_radio.empty()) return; + + int pos = 0; + int pos2 = 0; + // unsigned int crc = 0; + KISS_QUEUE_FRAME *frame = (KISS_QUEUE_FRAME *)0; + static char frame_marker[2] = { (char)(KISS_FEND), 0 }; + std::string one_frame = ""; + + pos = from_radio.find(frame_marker); + + if(pos == (int)(std::string::npos)) { + from_radio.clear(); + return; + } + + if(pos != 0) { + from_radio.erase(0, pos); + pos = 0; + } + + pos2 = from_radio.find(frame_marker, pos + 1); + if(pos2 != (int)(std::string::npos)) { + one_frame.assign(from_radio, pos, pos2 - pos + 1); + } else { + if(from_radio.size() > MAX_TEMP_BUFFER_SIZE) + from_radio.clear(); + return; + } + + char *buffer = (char *)0; + size_t buffer_size = one_frame.size() + BUFFER_PADDING; + + buffer = new char [buffer_size]; + + if(!buffer) { + LOG_DEBUG("Memory Allocation Error Near Line No. %d", __LINE__); + goto EXIT; + } + + memset(buffer, 0, buffer_size); + + buffer_size = one_frame.size(); + memcpy(buffer, one_frame.c_str(), buffer_size); + #ifdef EXTENED_DEBUG_INFO - LOG_HEX(buffer, buffer_size); + LOG_HEX(buffer, buffer_size); #endif - - buffer_size = decap_hdlc_frame(buffer, buffer_size); - - if(buffer_size) { - from_radio.erase(pos, pos2 - pos + 1); - - if(kiss_raw_enabled != KISS_RAW_ONLY) { - frame = encap_kiss_frame(buffer, buffer_size, KISS_DATA, kiss_port_no); - - if(!frame || !frame->data) { - LOG_DEBUG("Frame Allocation Error Near Line %d", __LINE__); - goto EXIT; - } - - WriteToHostBuffered((const char *) frame->data, (size_t) frame->size); - } - } else { - from_radio.erase(pos, pos + 1); - } - + + buffer_size = decap_hdlc_frame(buffer, buffer_size); + + if(buffer_size) { + from_radio.erase(pos, pos2 - pos + 1); + + if(kiss_raw_enabled != KISS_RAW_ONLY) { + frame = encap_kiss_frame(buffer, buffer_size, KISS_DATA, kiss_port_no); + + if(!frame || !frame->data) { + LOG_DEBUG("Frame Allocation Error Near Line %d", __LINE__); + goto EXIT; + } + + WriteToHostBuffered((const char *) frame->data, (size_t) frame->size); + } + } else { + from_radio.erase(pos, pos + 1); + } + EXIT:; - - if(frame) { - if(frame->data) { - frame->data[0] = 0; - delete [] frame->data; - } - delete frame; - } - - if(buffer) { - buffer[0] = 0; - delete [] buffer; - } + + if(frame) { + if(frame->data) { + frame->data[0] = 0; + delete [] frame->data; + } + delete frame; + } + + if(buffer) { + buffer[0] = 0; + delete [] buffer; + } } /********************************************************************************** @@ -3749,15 +3836,15 @@ EXIT:; **********************************************************************************/ void WriteToHostBCastFramesBuffered(void) { - guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); - if(kiss_bc_frame.empty()) return; - WriteToHostBuffered((const char *) kiss_bc_frame.c_str(), (size_t) kiss_bc_frame.size()); - + guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); + if(kiss_bc_frame.empty()) return; + WriteToHostBuffered((const char *) kiss_bc_frame.c_str(), (size_t) kiss_bc_frame.size()); + #ifdef EXTENED_DEBUG_INFO - LOG_HEX(kiss_bc_frame.c_str(), (size_t) kiss_bc_frame.size()); + LOG_HEX(kiss_bc_frame.c_str(), (size_t) kiss_bc_frame.size()); #endif - - kiss_bc_frame.clear(); + + kiss_bc_frame.clear(); } /********************************************************************************** @@ -3765,48 +3852,48 @@ void WriteToHostBCastFramesBuffered(void) **********************************************************************************/ bool tcp_init(bool connect_flag) { - if(progdefaults.kiss_address.empty() || progdefaults.kiss_io_port.empty()) { - LOG_DEBUG("%s", "KISS IP Address or Port null"); - return false; - } - - kiss_ip_address.assign(progdefaults.kiss_address); - kiss_ip_io_port.assign(progdefaults.kiss_io_port); - kiss_ip_out_port.assign(progdefaults.kiss_out_port); - - try { - kiss_socket = new Socket(Address(kiss_ip_address.c_str(), kiss_ip_io_port.c_str(), "tcp")); - kiss_socket->set_autoclose(true); - kiss_socket->set_nonblocking(false); - - if(progdefaults.kiss_tcp_listen) - kiss_socket->bind(); - } - catch (const SocketException& e) { - LOG_ERROR("Could not resolve %s: %s", kiss_ip_address.c_str(), e.what()); - if(kiss_socket) { - kiss_socket->shut_down(); - kiss_socket->close(); - delete kiss_socket; - kiss_socket = 0; - kiss_enabled = 0; - } - return false; - } - - if(connect_flag) { - if(kiss_socket->connect1() == false) { - LOG_INFO("Connection Failed: Host program present?"); - kiss_socket->shut_down(); - kiss_socket->close(); - delete kiss_socket; - kiss_socket = 0; - kiss_enabled = 0; - return false; - } - } - - return true; + if(progdefaults.kiss_address.empty() || progdefaults.kiss_io_port.empty()) { + LOG_DEBUG("%s", "KISS IP Address or Port null"); + return false; + } + + kiss_ip_address.assign(progdefaults.kiss_address); + kiss_ip_io_port.assign(progdefaults.kiss_io_port); + kiss_ip_out_port.assign(progdefaults.kiss_out_port); + + try { + kiss_socket = new Socket(Address(kiss_ip_address.c_str(), kiss_ip_io_port.c_str(), "tcp")); + kiss_socket->set_autoclose(true); + kiss_socket->set_nonblocking(false); + + if(progdefaults.kiss_tcp_listen) + kiss_socket->bind(); + } + catch (const SocketException& e) { + LOG_ERROR("Could not resolve %s: %s", kiss_ip_address.c_str(), e.what()); + if(kiss_socket) { + kiss_socket->shut_down(); + kiss_socket->close(); + delete kiss_socket; + kiss_socket = 0; + kiss_enabled = 0; + } + return false; + } + + if(connect_flag) { + if(kiss_socket->connect1() == false) { + LOG_INFO("Connection Failed: Host program present?"); + kiss_socket->shut_down(); + kiss_socket->close(); + delete kiss_socket; + kiss_socket = 0; + kiss_enabled = 0; + return false; + } + } + + return true; } /********************************************************************************** @@ -3814,38 +3901,38 @@ bool tcp_init(bool connect_flag) **********************************************************************************/ bool udp_init(void) { - if(progdefaults.kiss_address.empty() || progdefaults.kiss_io_port.empty()) { - LOG_DEBUG("%s", "KISS IP Address or Port null"); - return false; - } - - kiss_ip_address.assign(progdefaults.kiss_address); - kiss_ip_io_port.assign(progdefaults.kiss_io_port); - kiss_ip_out_port.assign(progdefaults.kiss_out_port); - - try { - kiss_socket = new Socket(Address(kiss_ip_address.c_str(), kiss_ip_io_port.c_str(), "udp")); - kiss_socket->dual_port(&progdefaults.kiss_dual_port_enabled); - kiss_socket->set_dual_port_number(kiss_ip_out_port); - kiss_socket->set_autoclose(true); - kiss_socket->set_nonblocking(false); - - if(progdefaults.kiss_tcp_listen) // Listen flag indcates server mode. - kiss_socket->bindUDP(); - - } catch (const SocketException& e) { - LOG_ERROR("Could not resolve %s: %s", kiss_ip_address.c_str(), e.what()); - if(kiss_socket) { - kiss_socket->shut_down(); - kiss_socket->close(); - delete kiss_socket; - kiss_socket = 0; - kiss_enabled = 0; - } - return false; - } - - return true; + if(progdefaults.kiss_address.empty() || progdefaults.kiss_io_port.empty()) { + LOG_DEBUG("%s", "KISS IP Address or Port null"); + return false; + } + + kiss_ip_address.assign(progdefaults.kiss_address); + kiss_ip_io_port.assign(progdefaults.kiss_io_port); + kiss_ip_out_port.assign(progdefaults.kiss_out_port); + + try { + kiss_socket = new Socket(Address(kiss_ip_address.c_str(), kiss_ip_io_port.c_str(), "udp")); + kiss_socket->dual_port(&progdefaults.kiss_dual_port_enabled); + kiss_socket->set_dual_port_number(kiss_ip_out_port); + kiss_socket->set_autoclose(true); + kiss_socket->set_nonblocking(false); + + if(progdefaults.kiss_tcp_listen) // Listen flag indcates server mode. + kiss_socket->bindUDP(); + + } catch (const SocketException& e) { + LOG_ERROR("Could not resolve %s: %s", kiss_ip_address.c_str(), e.what()); + if(kiss_socket) { + kiss_socket->shut_down(); + kiss_socket->close(); + delete kiss_socket; + kiss_socket = 0; + kiss_enabled = 0; + } + return false; + } + + return true; } /********************************************************************************** @@ -3853,31 +3940,31 @@ bool udp_init(void) **********************************************************************************/ void kiss_reset_buffers(void) { - { - guard_lock to_host_lock(&to_host_mutex); - if(!to_host.empty()) - to_host.clear(); - } - - { - guard_lock to_host_lock(&from_radio_mutex); - if(!from_radio.empty()) - from_radio.clear(); - } - - { - guard_lock to_host_lock(&to_radio_mutex); - pText = 0; - kiss_text_available = false; - if(!to_radio.empty()) - to_radio.clear(); - } - - { - guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); - if(!kiss_bc_frame.empty()) - kiss_bc_frame.clear(); - } + { + guard_lock to_host_lock(&to_host_mutex); + if(!to_host.empty()) + to_host.clear(); + } + + { + guard_lock to_host_lock(&from_radio_mutex); + if(!from_radio.empty()) + from_radio.clear(); + } + + { + guard_lock to_host_lock(&to_radio_mutex); + pText = 0; + kiss_text_available = false; + if(!to_radio.empty()) + to_radio.clear(); + } + + { + guard_lock kiss_bc_frame_lock(&kiss_bc_frame_mutex); + if(!kiss_bc_frame.empty()) + kiss_bc_frame.clear(); + } } /********************************************************************************** @@ -3885,30 +3972,30 @@ void kiss_reset_buffers(void) **********************************************************************************/ void kiss_reset(void) { - kiss_reset_flag = true; - kiss_text_available = false; - persistance = 63; - tx_delay = 50; - duplex = KISS_HALF_DUPLEX; - crc_mode = CRC16_NONE; - smack_crc_enabled = false; - pText = 0; - - if(data_io_enabled == KISS_IO) - data_io_enabled = DISABLED_IO; - - MilliSleep(1000); - - void kiss_reset_buffers(void); - - if (trx_state == STATE_TX || trx_state == STATE_TUNE) { - REQ(abort_tx); - } - - kiss_reset_flag = false; - - if(data_io_enabled == DISABLED_IO) - data_io_enabled = KISS_IO; + kiss_reset_flag = true; + kiss_text_available = false; + persistance = 63; + tx_delay = 50; + duplex = KISS_HALF_DUPLEX; + crc_mode = CRC16_NONE; + smack_crc_enabled = false; + pText = 0; + + if(data_io_enabled == KISS_IO) + data_io_enabled = DISABLED_IO; + + MilliSleep(1000); + + void kiss_reset_buffers(void); + + if (trx_state == STATE_TX || trx_state == STATE_TUNE) { + REQ(abort_tx); + } + + kiss_reset_flag = false; + + if(data_io_enabled == DISABLED_IO) + data_io_enabled = KISS_IO; } /********************************************************************************** @@ -3916,65 +4003,82 @@ void kiss_reset(void) **********************************************************************************/ void kiss_init(bool connect_flag) { - kiss_enabled = false; - kiss_exit = false; - -// progStatus.data_io_enabled (widget state), data_io_enabled (program state) - - if(progStatus.data_io_enabled == KISS_IO) { - if(!(active_modem->iface_io() & KISS_IO)) { - set_default_kiss_modem(); - } - } - - if(init_hist_flag) { - memset(histogram, 0, sizeof(histogram)); - init_hist_flag = false; - } - - srand(time(0)); // For CSMA persistance - update_kpsql_fractional_gain(progdefaults.kpsql_attenuation); - - data_io_type = DATA_IO_NA; - - if(progStatus.kiss_tcp_io) { - if(progStatus.kiss_tcp_listen) connect_flag = false; - Fl::awake(kiss_io_set_button_state, (void *) IO_CONNECT_STR); - if(!tcp_init(connect_flag)) return; - LOG_INFO("%s", "TCP Init - OK"); - } else { - Fl::awake(kiss_io_set_button_state, (void *) IO_START_STR); - if(!udp_init()) return; - LOG_INFO("%s", "UDP Init - OK"); - } - - if (pthread_create(&kiss_thread, NULL, kiss_loop, NULL) < 0) { - LOG_ERROR("KISS kiss_thread: pthread_create failed"); - return; - } - + kiss_enabled = false; + kiss_exit = false; + + // progStatus.data_io_enabled (widget state), data_io_enabled (program state) + + if(progStatus.data_io_enabled == KISS_IO) { + if(!(active_modem->iface_io() & KISS_IO)) { + set_default_kiss_modem(); + } + } + + if(init_hist_flag) { + memset(histogram, 0, sizeof(histogram)); + init_hist_flag = false; + } + + srand(time(0)); // For CSMA persistance + update_kpsql_fractional_gain(progdefaults.kpsql_attenuation); + + data_io_type = DATA_IO_NA; + + if(progStatus.kiss_tcp_io) { + + if(retry_count > KISS_CONNECT_RETRY_COUNT) + retry_count = KISS_CONNECT_RETRY_COUNT; + + if(progStatus.kiss_tcp_listen) + connect_flag = false; + + do { + if(tcp_init(connect_flag)) break; + + if(progStatus.kiss_tcp_listen) return; + + MilliSleep(KISS_RETRY_WAIT_TIME); + + if(retry_count-- > 0) continue; + else return; + + } while(1); + + LOG_INFO("%s", "TCP Init - OK"); + } else { + if(!udp_init()) return; + LOG_INFO("%s", "UDP Init - OK"); + } + + Fl::awake(kiss_io_set_button_state, (void *) IO_START_STR); + + if (pthread_create(&kiss_thread, NULL, kiss_loop, NULL) < 0) { + LOG_ERROR("KISS kiss_thread: pthread_create failed"); + return; + } + #ifdef KISS_RX_THREAD - if (pthread_create(&kiss_rx_socket_thread, NULL, ReadFromHostSocket, NULL) < 0) { - LOG_ERROR("KISS kiss_rx_socket_thread: pthread_create failed"); - kiss_exit = true; - pthread_join(kiss_thread, NULL); - return; - } + if (pthread_create(&kiss_rx_socket_thread, NULL, ReadFromHostSocket, NULL) < 0) { + LOG_ERROR("KISS kiss_rx_socket_thread: pthread_create failed"); + kiss_exit = true; + pthread_join(kiss_thread, NULL); + return; + } #endif - - if(progStatus.kiss_tcp_io) { - Fl::awake(kiss_io_set_button_state, (void *) IO_DISCONNECT_STR); - data_io_type = DATA_IO_TCP; - } else { - Fl::awake(kiss_io_set_button_state, (void *) IO_STOP_STR); - data_io_type = DATA_IO_UDP; - } - - if(progdefaults.data_io_enabled == KISS_IO) - data_io_enabled = KISS_IO; - - kiss_enabled = true; - allow_kiss_socket_io = true; + + if(progStatus.kiss_tcp_io) { + data_io_type = DATA_IO_TCP; + } else { + data_io_type = DATA_IO_UDP; + } + + Fl::awake(kiss_io_set_button_state, (void *) IO_STOP_STR); + + if(progdefaults.data_io_enabled == KISS_IO) + data_io_enabled = KISS_IO; + + kiss_enabled = true; + allow_kiss_socket_io = true; } /********************************************************************************** @@ -3982,7 +4086,7 @@ void kiss_init(bool connect_flag) **********************************************************************************/ void kiss_main_thread_close(void *ptr) { - kiss_close(true); + kiss_close(true); } /********************************************************************************** @@ -3990,65 +4094,97 @@ void kiss_main_thread_close(void *ptr) **********************************************************************************/ void kiss_close(bool override_flag) { -// if (!kiss_enabled && !override_flag) return; - - kiss_text_available = false; - allow_kiss_socket_io = false; - - if(data_io_enabled == KISS_IO) { - data_io_enabled = DISABLED_IO; - data_io_type = DATA_IO_NA; - } - - if(kiss_socket) { - kiss_socket->shut_down(); - kiss_socket->close(); - } else { - return; - } - + // if (!kiss_enabled && !override_flag) return; + + kiss_text_available = false; + allow_kiss_socket_io = false; + + if(data_io_enabled == KISS_IO) { + data_io_enabled = DISABLED_IO; + data_io_type = DATA_IO_NA; + } + + if(kiss_socket) { + kiss_socket->shut_down(); + kiss_socket->close(); + } else { + return; + } + #ifdef KISS_RX_THREAD - kiss_rx_exit = true; - - MilliSleep(250); - - if(kiss_rx_exit) - pthread_join(kiss_rx_socket_thread, NULL); - else - CANCEL_THREAD(kiss_rx_socket_thread); + kiss_rx_exit = true; + + MilliSleep(250); + + if(kiss_rx_exit) + pthread_join(kiss_rx_socket_thread, NULL); + else + CANCEL_THREAD(kiss_rx_socket_thread); #else - kiss_exit = true; + kiss_exit = true; #endif - - MilliSleep(250); - - if(kiss_exit) - pthread_join(kiss_thread, NULL); - else - CANCEL_THREAD(kiss_thread); - - LOG_INFO("%s", "Kiss loop terminated. "); - - kiss_socket = 0; - kiss_enabled = false; - - if(progdefaults.kiss_tcp_io) - Fl::awake(kiss_io_set_button_state, (void *) IO_CONNECT_STR); - else - Fl::awake(kiss_io_set_button_state, (void *) IO_START_STR); - + + MilliSleep(250); + + if(kiss_exit) + pthread_join(kiss_thread, NULL); + else + CANCEL_THREAD(kiss_thread); + + LOG_INFO("%s", "Kiss loop terminated. "); + + kiss_socket = 0; + kiss_enabled = false; + + Fl::awake(kiss_io_set_button_state, (void *) IO_START_STR); + + if((retry_count > 0) && progStatus.kiss_tcp_io) + Fl::awake(kiss_main_thread_retry_open, (void *) 0); + } /********************************************************************************** * **********************************************************************************/ -void connect_to_kiss_io(void) +void kiss_main_thread_retry_open(void *ptr) { - if(kiss_socket) { - kiss_close(true); - } else { - kiss_init(progdefaults.kiss_tcp_listen ? false : true); - } + if(!progStatus.kiss_tcp_listen) + MilliSleep(KISS_RETRY_WAIT_TIME); + connect_to_kiss_io(false); +} + +/********************************************************************************** + * + **********************************************************************************/ +void connect_to_kiss_io(bool user_requested) +{ + guard_lock external_lock(&restart_mutex); + + if(kiss_socket) { + if(user_requested) + retry_count = 0; + + kiss_close(true); + + if(user_requested) + return; + } + + if(user_requested || progStatus.kiss_tcp_listen) + retry_count = KISS_CONNECT_RETRY_COUNT; + + if(retry_count > 0) { + retry_count--; + kiss_init(progdefaults.kiss_tcp_listen ? false : true); + } +} + +/********************************************************************************** + * + **********************************************************************************/ +bool kiss_thread_running(void) +{ + return (bool) kiss_enabled; } /********************************************************************************** @@ -4056,27 +4192,27 @@ void connect_to_kiss_io(void) **********************************************************************************/ int kiss_get_char(void) { - /// Mutex is unlocked when returning from function - guard_lock to_radio_lock(&to_radio_mutex); - int c = 0; - static bool toggle_flag = 0; - - if (kiss_text_available) { - if (pText != (int)to_radio.length()) { - c = to_radio[pText++] & 0xFF; - toggle_flag = true; - } else { - kiss_text_available = false; - to_radio.clear(); - pText = 0; - c = GET_TX_CHAR_ETX; - - if(toggle_flag) { - bcast_tx_buffer_empty_kiss_frame(); - toggle_flag = 0; - } - } - } - - return c; + /// Mutex is unlocked when returning from function + guard_lock to_radio_lock(&to_radio_mutex); + int c = 0; + static bool toggle_flag = 0; + + if (kiss_text_available) { + if (pText != (int)to_radio.length()) { + c = to_radio[pText++] & 0xFF; + toggle_flag = true; + } else { + kiss_text_available = false; + to_radio.clear(); + pText = 0; + c = GET_TX_CHAR_ETX; + + if(toggle_flag) { + bcast_tx_buffer_empty_kiss_frame(); + toggle_flag = 0; + } + } + } + + return c; } diff --git a/src/misc/socket.cxx b/src/misc/socket.cxx index dbc024ef..03ab025d 100644 --- a/src/misc/socket.cxx +++ b/src/misc/socket.cxx @@ -59,12 +59,14 @@ #include #include #include +#include //#undef NDEBUG #include "debug.h" #include "socket.h" + #if HAVE_GETADDRINFO && !defined(AI_NUMERICSERV) # define AI_NUMERICSERV 0 #endif diff --git a/src/misc/status.cxx b/src/misc/status.cxx index c89ff3cc..1db2e4f5 100644 --- a/src/misc/status.cxx +++ b/src/misc/status.cxx @@ -119,7 +119,6 @@ status progStatus = { 5.0, // double sldrPwrSquelchValue true, // bool afconoff true, // bool sqlonoff - false, // bool pwrsqlonoff 50, // int scopeX; 50, // int scopeY; false, // bool scopeVisible; @@ -201,6 +200,8 @@ status progStatus = { progdefaults.csma_enabled, progdefaults.kiss_tcp_io, progdefaults.kiss_tcp_listen, + progdefaults.kpsql_enabled, + progdefaults.kiss_io_modem_change_inhibit, true, 0.0, progdefaults.psk8DCDShortFlag, @@ -326,7 +327,8 @@ void status::saveLastState() csma_enabled = progdefaults.csma_enabled; kiss_tcp_io = progdefaults.kiss_tcp_io; kiss_tcp_listen = progdefaults.kiss_tcp_listen; - + kpsql_enabled = progdefaults.kpsql_enabled; + kiss_io_modem_change_inhibit = progdefaults.kiss_io_modem_change_inhibit; squelch_value = 0; Fl_Preferences spref(HomeDir.c_str(), "w1hkj.com", PACKAGE_TARNAME); @@ -336,7 +338,6 @@ void status::saveLastState() spref.set("mode_name", mode_info[lastmode].sname); spref.set("squelch_enabled", sqlonoff); - spref.set("pwr_squelch_enabled", pwrsqlonoff); spref.set("squelch_level", sldrSquelchValue); spref.set("pwr_squelch_level", sldrPwrSquelchValue); spref.set("afc_enabled", afconoff); @@ -479,7 +480,7 @@ if (!bWF_only) { spref.set("kiss_dual_port_enabled", kiss_dual_port_enabled); } - if(override_data_io_enabled != DISABLED_IO) + if(!override_data_io_enabled) spref.set("data_io_enabled", data_io_enabled); spref.set("ax25_decode_enabled", ax25_decode_enabled); @@ -489,6 +490,8 @@ if (!bWF_only) { spref.set("csma_enabled", csma_enabled); spref.set("kiss_tcp_io", kiss_tcp_io); spref.set("kiss_tcp_listen", kiss_tcp_listen); + spref.set("kpsql_enabled", kpsql_enabled); + spref.set("kiss_io_modem_change_inhibit", kiss_io_modem_change_inhibit); spref.set("browser_search", browser_search.c_str()); @@ -527,7 +530,6 @@ void status::loadLastState() } spref.get("squelch_enabled", i, sqlonoff); sqlonoff = i; - spref.get("pwr_squelch_enabled", i, pwrsqlonoff); pwrsqlonoff = i; spref.get("squelch_level", i, sldrSquelchValue); sldrSquelchValue = i; spref.get("pwr_squelch_level", i, sldrPwrSquelchValue); sldrPwrSquelchValue = i; spref.get("afc_enabled", i, afconoff); afconoff = i; @@ -710,7 +712,7 @@ void status::loadLastState() spref.get("kiss_dual_port_enabled", i, kiss_dual_port_enabled); kiss_dual_port_enabled = i; } - if(override_data_io_enabled != DISABLED_IO) + if(!override_data_io_enabled) spref.get("data_io_enabled", i, data_io_enabled); data_io_enabled = i; spref.get("ax25_decode_enabled", i, ax25_decode_enabled); ax25_decode_enabled = i; @@ -720,6 +722,8 @@ void status::loadLastState() spref.get("csma_enabled", i, csma_enabled); csma_enabled = i; spref.get("kiss_tcp_io", i, kiss_tcp_io); kiss_tcp_io = i; spref.get("kiss_tcp_listen", i, kiss_tcp_listen); kiss_tcp_listen = i; + spref.get("kpsql_enabled", i, kpsql_enabled); kpsql_enabled = i; + spref.get("kiss_io_modem_change_inhibit", i, kiss_io_modem_change_inhibit); kiss_io_modem_change_inhibit = i; spref.get("psk8DCDShortFlag", i, psk8DCDShortFlag); psk8DCDShortFlag = i; @@ -826,13 +830,13 @@ void status::initLastState() data_io_enabled = ARQ_IO; progdefaults.data_io_enabled = ARQ_IO; progStatus.data_io_enabled = ARQ_IO; - pwrsqlonoff = false; + kpsql_enabled = false; } btnSQL->value(sqlonoff); - btnPSQL->value(pwrsqlonoff); + btnPSQL->value(kpsql_enabled); - if(pwrsqlonoff) + if(kpsql_enabled) sldrSquelch->value(sldrPwrSquelchValue); else sldrSquelch->value(sldrSquelchValue); diff --git a/src/rigcontrol/xmlrpc_rig.cxx b/src/rigcontrol/xmlrpc_rig.cxx index a6cefb8c..780f5bf5 100644 --- a/src/rigcontrol/xmlrpc_rig.cxx +++ b/src/rigcontrol/xmlrpc_rig.cxx @@ -118,6 +118,15 @@ void xmlrpc_rig_set_qsy(long long rfc) // set / get pairs //====================================================================== +//---------------------------------------------------------------------- +// To prevent a FLTK library thread deadlock on MacOSX +//---------------------------------------------------------------------- +static void ptt_on_off_failure(void * ptt_flag) +{ + int flag = *((int *) ptt_flag); + fl_alert2("fldigi/flrig PTT %s failure", flag ? "ON" : "OFF"); +} + //---------------------------------------------------------------------- // push to talk //---------------------------------------------------------------------- @@ -126,6 +135,7 @@ static int wait_ptt_timeout = 5; // 5 polls and then disable wait static int ptt_state = 0; static int new_ptt = -1; +static int last_new_ptt = -1; void exec_flrig_ptt() { if (!connected_to_flrig) { @@ -149,7 +159,7 @@ void exec_flrig_ptt() { wait_ptt = true; wait_ptt_timeout = 10; ptt_state = new_ptt; - LOG_INFO("ptt %s in %d msec", + LOG_INFO("ptt %s in %d msec", ptt_state ? "ON" : "OFF", i*50 + (j + 1)*20); new_ptt = -1; @@ -159,10 +169,14 @@ void exec_flrig_ptt() { } } } + wait_ptt = false; wait_ptt_timeout = 0; LOG_ERROR("%s", "rig.set_ptt failed (3)"); - fl_alert2("fldigi/flrig PTT %s failure", new_ptt ? "ON" : "OFF"); + // FLTK thread dead lock on MacOSX. Call in main thread. + // fl_alert2("fldigi/flrig PTT %s failure", new_ptt ? "ON" : "OFF"); + last_new_ptt = new_ptt; + REQ(ptt_on_off_failure, (void *) &last_new_ptt); new_ptt = -1; return; } @@ -535,7 +549,7 @@ void xmlrpc_rig_post_bws(void *) string labels1 = bws_result[1][0]; static char btn1_label[2]; - btn1_label[0] = labels1[0]; btn1_label[1] = 0; + btn1_label[0] = labels1[0]; btn1_label[1] = 0; qso_btnBW1->label(btn1_label); qso_btnBW1->redraw_label(); qso_btnBW1->redraw(); @@ -567,7 +581,7 @@ void xmlrpc_rig_post_bws(void *) string labels2 = bws_result[0][0]; static char btn2_label[2]; - btn2_label[0] = labels2[0]; btn2_label[1] = 0; + btn2_label[0] = labels2[0]; btn2_label[1] = 0; qso_btnBW2->label(btn2_label); qso_btnBW2->redraw_label(); qso_btnBW2->redraw(); diff --git a/src/trx/modem.cxx b/src/trx/modem.cxx index f9bda135..626d54af 100644 --- a/src/trx/modem.cxx +++ b/src/trx/modem.cxx @@ -313,7 +313,7 @@ void modem::set_metric(double m) void modem::display_metric(double m) { set_metric(m); - if(!progStatus.pwrsqlonoff) + if(!progStatus.kpsql_enabled) ::global_display_metric(m); }