diff --git a/src/dialogs/confdialog.cxx b/src/dialogs/confdialog.cxx index e50c2c4c..aab35f63 100644 --- a/src/dialogs/confdialog.cxx +++ b/src/dialogs/confdialog.cxx @@ -1445,6 +1445,13 @@ btnInitRIGCAT->redraw_label(); progdefaults.changed = true; } +Fl_Value_Slider *valRigCatStopbits=(Fl_Value_Slider *)0; + +static void cb_valRigCatStopbits(Fl_Value_Slider* o, void*) { + progdefaults.RigCatStopbits = (int)o->value(); +progdefaults.changed = true; +} + Fl_Group *tabHamlib=(Fl_Group *)0; Fl_Check_Button *chkUSEHAMLIB=(Fl_Check_Button *)0; @@ -1609,6 +1616,13 @@ btnInitHAMLIB->labelcolor(FL_RED); btnInitHAMLIB->redraw_label(); } +Fl_Value_Slider *valHamRigStopbits=(Fl_Value_Slider *)0; + +static void cb_valHamRigStopbits(Fl_Value_Slider* o, void*) { + progdefaults.HamRigStopbits = (int)o->value(); +progdefaults.changed = true; +} + Fl_Group *grpMemmap=(Fl_Group *)0; Fl_Check_Button *chkUSEMEMMAP=(Fl_Check_Button *)0; @@ -2227,6 +2241,7 @@ static const char szBaudRates[] = "300|600|1200|2400|4800|9600|19200|38400|57600 { tabOperator = new Fl_Group(0, 25, 500, 345, _("Operator")); tabOperator->callback((Fl_Callback*)cb_tabOperator); tabOperator->when(FL_WHEN_CHANGED); + tabOperator->hide(); { Fl_Group* o = new Fl_Group(5, 35, 490, 165, _("Station")); o->box(FL_ENGRAVED_FRAME); o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE); @@ -3665,7 +3680,6 @@ an merging")); tabModems->end(); } // Fl_Group* tabModems { tabRig = new Fl_Group(0, 25, 500, 345, _("Rig")); - tabRig->hide(); { tabsRig = new Fl_Tabs(0, 25, 500, 345); tabsRig->selection_color(FL_LIGHT1); { Fl_Group* o = new Fl_Group(0, 50, 500, 320, _("Hardware PTT")); @@ -3731,6 +3745,7 @@ an merging")); } // Fl_Group* o { Fl_Group* o = new Fl_Group(0, 50, 500, 320, _("RigCAT")); o->tooltip(_("Rig Control using xml spec file")); + o->hide(); { chkUSERIGCAT = new Fl_Check_Button(195, 60, 110, 20, _("Use RigCAT")); chkUSERIGCAT->tooltip(_("RigCAT used for rig control")); chkUSERIGCAT->down_box(FL_DOWN_BOX); @@ -3770,7 +3785,7 @@ an merging")); cntRigCatWait->align(FL_ALIGN_TOP_LEFT); o->value(progdefaults.RigCatWait); } // Fl_Value_Input* cntRigCatWait - { Fl_Choice* o = mnuXmlRigBaudrate = new Fl_Choice(386, 154, 99, 22, _("Baud rate:")); + { Fl_Choice* o = mnuXmlRigBaudrate = new Fl_Choice(386, 150, 99, 22, _("Baud rate:")); mnuXmlRigBaudrate->tooltip(_("Pick baud rate from list")); mnuXmlRigBaudrate->down_box(FL_BORDER_BOX); mnuXmlRigBaudrate->callback((Fl_Callback*)cb_mnuXmlRigBaudrate); @@ -3824,12 +3839,24 @@ an merging")); chkRigCatRTSCTSflow->callback((Fl_Callback*)cb_chkRigCatRTSCTSflow); o->value(progdefaults.RigCatRTSCTSflow); } // Fl_Check_Button* chkRigCatRTSCTSflow + { Fl_Value_Slider* o = valRigCatStopbits = new Fl_Value_Slider(425, 190, 60, 22, _("Stopbits")); + valRigCatStopbits->type(1); + valRigCatStopbits->color(FL_BACKGROUND2_COLOR); + valRigCatStopbits->selection_color((Fl_Color)40); + valRigCatStopbits->minimum(1); + valRigCatStopbits->maximum(2); + valRigCatStopbits->step(1); + valRigCatStopbits->value(2); + valRigCatStopbits->textsize(14); + valRigCatStopbits->callback((Fl_Callback*)cb_valRigCatStopbits); + valRigCatStopbits->align(FL_ALIGN_LEFT); + o->value(progdefaults.RigCatStopbits); + } // Fl_Value_Slider* valRigCatStopbits grpRigCAT->end(); } // Fl_Group* grpRigCAT o->end(); } // Fl_Group* o { tabHamlib = new Fl_Group(0, 50, 500, 320, _("Hamlib")); - tabHamlib->hide(); { chkUSEHAMLIB = new Fl_Check_Button(195, 60, 100, 20, _("Use Hamlib")); chkUSEHAMLIB->tooltip(_("Hamlib used for rig control")); chkUSEHAMLIB->down_box(FL_DOWN_BOX); @@ -3857,35 +3884,34 @@ an merging")); inpRIGdev->callback((Fl_Callback*)cb_inpRIGdev); o->value(progdefaults.HamRigDevice.c_str()); } // Fl_Input_Choice* inpRIGdev - { Fl_Value_Input* o = cntHamlibRetries = new Fl_Value_Input(30, 137, 70, 24, _("Retries")); + { Fl_Value_Input* o = cntHamlibRetries = new Fl_Value_Input(30, 133, 70, 24, _("Retries")); cntHamlibRetries->tooltip(_("# times to resend command before giving up")); cntHamlibRetries->callback((Fl_Callback*)cb_cntHamlibRetries); cntHamlibRetries->align(FL_ALIGN_TOP_LEFT); o->value(progdefaults.HamlibRetries); } // Fl_Value_Input* cntHamlibRetries - { Fl_Value_Input* o = cntHamlibTimeout = new Fl_Value_Input(155, 137, 70, 24, _("Retry Interval (ms)")); + { Fl_Value_Input* o = cntHamlibTimeout = new Fl_Value_Input(155, 133, 70, 24, _("Retry Interval (ms)")); cntHamlibTimeout->tooltip(_("Msec\'s between retries")); cntHamlibTimeout->callback((Fl_Callback*)cb_cntHamlibTimeout); cntHamlibTimeout->align(FL_ALIGN_TOP_LEFT); o->value(progdefaults.HamlibTimeout); } // Fl_Value_Input* cntHamlibTimeout - { Fl_Value_Input* o = cntHamlibWriteDelay = new Fl_Value_Input(30, 183, 70, 24, _("Write delay (ms)")); + { Fl_Value_Input* o = cntHamlibWriteDelay = new Fl_Value_Input(30, 176, 70, 24, _("Write delay (ms)")); cntHamlibWriteDelay->tooltip(_("Msec\'s between sequential commands")); cntHamlibWriteDelay->callback((Fl_Callback*)cb_cntHamlibWriteDelay); cntHamlibWriteDelay->align(FL_ALIGN_TOP_LEFT); o->value(progdefaults.HamlibWriteDelay); } // Fl_Value_Input* cntHamlibWriteDelay - { Fl_Value_Input* o = cntHamlibWait = new Fl_Value_Input(156, 182, 70, 24, _("Post write delay (ms)")); + { Fl_Value_Input* o = cntHamlibWait = new Fl_Value_Input(156, 176, 70, 24, _("Post write delay (ms)")); cntHamlibWait->tooltip(_("Wait interval (msecs) before reading response")); cntHamlibWait->callback((Fl_Callback*)cb_cntHamlibWait); cntHamlibWait->align(FL_ALIGN_TOP_LEFT); o->value(progdefaults.HamlibWait); } // Fl_Value_Input* cntHamlibWait - { Fl_Choice* o = mnuBaudRate = new Fl_Choice(385, 138, 99, 22, _("Baud rate:")); + { Fl_Choice* o = mnuBaudRate = new Fl_Choice(385, 127, 99, 22, _("Baud rate:")); mnuBaudRate->tooltip(_("Serial port baud rate")); mnuBaudRate->down_box(FL_BORDER_BOX); mnuBaudRate->callback((Fl_Callback*)cb_mnuBaudRate); - mnuBaudRate->align(FL_ALIGN_TOP_LEFT); o->add(szBaudRates); o->value(progdefaults.HamRigBaudrate); } // Fl_Choice* mnuBaudRate @@ -3957,6 +3983,19 @@ an merging")); chkHamlibXONXOFFflow->callback((Fl_Callback*)cb_chkHamlibXONXOFFflow); o->value(progdefaults.HamlibXONXOFFflow); } // Fl_Check_Button* chkHamlibXONXOFFflow + { Fl_Value_Slider* o = valHamRigStopbits = new Fl_Value_Slider(424, 162, 60, 22, _("Stopbits")); + valHamRigStopbits->type(1); + valHamRigStopbits->color(FL_BACKGROUND2_COLOR); + valHamRigStopbits->selection_color((Fl_Color)40); + valHamRigStopbits->minimum(1); + valHamRigStopbits->maximum(2); + valHamRigStopbits->step(1); + valHamRigStopbits->value(2); + valHamRigStopbits->textsize(14); + valHamRigStopbits->callback((Fl_Callback*)cb_valHamRigStopbits); + valHamRigStopbits->align(FL_ALIGN_LEFT); + o->value(progdefaults.HamRigStopbits); + } // Fl_Value_Slider* valHamRigStopbits grpHamlib->end(); } // Fl_Group* grpHamlib tabHamlib->end(); diff --git a/src/dialogs/confdialog.fl b/src/dialogs/confdialog.fl index f7a5ad9c..a6b2ede0 100644 --- a/src/dialogs/confdialog.fl +++ b/src/dialogs/confdialog.fl @@ -89,8 +89,8 @@ static const char szBaudRates[] = "300|600|1200|2400|4800|9600|19200|38400|57600 } { Fl_Group tabOperator { label Operator - callback {progdefaults.changed = true;} open selected - xywh {0 25 500 345} when 1 + callback {progdefaults.changed = true;} open + xywh {0 25 500 345} when 1 hide } { Fl_Group {} { label Station open @@ -1508,7 +1508,7 @@ progdefaults.changed = true;} } Fl_Group tabRig { label Rig open - xywh {0 25 500 345} hide + xywh {0 25 500 345} } { Fl_Tabs tabsRig {open xywh {0 25 500 345} selection_color 50 @@ -1620,7 +1620,7 @@ progdefaults.changed = true;} } Fl_Group {} { label RigCAT open - tooltip {Rig Control using xml spec file} xywh {0 50 500 320} + tooltip {Rig Control using xml spec file} xywh {0 50 500 320} hide } { Fl_Check_Button chkUSERIGCAT { label {Use RigCAT} @@ -1697,7 +1697,7 @@ progdefaults.changed = true;} btnInitRIGCAT->labelcolor(FL_RED); btnInitRIGCAT->redraw_label(); progdefaults.changed = true;} open - tooltip {Pick baud rate from list} xywh {386 154 99 22} down_box BORDER_BOX + tooltip {Pick baud rate from list} xywh {386 150 99 22} down_box BORDER_BOX code0 {o->add(szBaudRates);} code1 {o->value(progdefaults.XmlRigBaudrate);} } {} @@ -1792,11 +1792,18 @@ progdefaults.changed = true;} tooltip {Rig uses RTS/CTS handshake} xywh {50 320 170 20} down_box DOWN_BOX code0 {o->value(progdefaults.RigCatRTSCTSflow);} } + Fl_Value_Slider valRigCatStopbits { + label Stopbits + callback {progdefaults.RigCatStopbits = (int)o->value(); +progdefaults.changed = true;} + xywh {425 190 60 22} type Horizontal color 7 selection_color 40 align 4 minimum 1 maximum 2 step 1 value 2 textsize 14 + code0 {o->value(progdefaults.RigCatStopbits);} + } } } Fl_Group tabHamlib { label Hamlib open - xywh {0 50 500 320} hide + xywh {0 50 500 320} } { Fl_Check_Button chkUSEHAMLIB { label {Use Hamlib} @@ -1843,7 +1850,7 @@ btnInitHAMLIB->redraw_label();} open callback {progdefaults.HamlibRetries = (int)o->value(); btnInitHAMLIB->labelcolor(FL_RED); btnInitHAMLIB->redraw_label();} - tooltip {\# times to resend command before giving up} xywh {30 137 70 24} align 5 + tooltip {\# times to resend command before giving up} xywh {30 133 70 24} align 5 code0 {o->value(progdefaults.HamlibRetries);} } Fl_Value_Input cntHamlibTimeout { @@ -1851,7 +1858,7 @@ btnInitHAMLIB->redraw_label();} callback {progdefaults.HamlibTimeout = (int)o->value(); btnInitHAMLIB->labelcolor(FL_RED); btnInitHAMLIB->redraw_label();} - tooltip {Msec's between retries} xywh {155 137 70 24} align 5 + tooltip {Msec's between retries} xywh {155 133 70 24} align 5 code0 {o->value(progdefaults.HamlibTimeout);} } Fl_Value_Input cntHamlibWriteDelay { @@ -1859,7 +1866,7 @@ btnInitHAMLIB->redraw_label();} callback {progdefaults.HamlibWriteDelay = (int)o->value(); btnInitHAMLIB->labelcolor(FL_RED); btnInitHAMLIB->redraw_label();} - tooltip {Msec's between sequential commands} xywh {30 183 70 24} align 5 + tooltip {Msec's between sequential commands} xywh {30 176 70 24} align 5 code0 {o->value(progdefaults.HamlibWriteDelay);} } Fl_Value_Input cntHamlibWait { @@ -1867,7 +1874,7 @@ btnInitHAMLIB->redraw_label();} callback {progdefaults.HamlibWait = (int)o->value(); btnInitHAMLIB->labelcolor(FL_RED); btnInitHAMLIB->redraw_label();} - tooltip {Wait interval (msecs) before reading response} xywh {156 182 70 24} align 5 + tooltip {Wait interval (msecs) before reading response} xywh {156 176 70 24} align 5 code0 {o->value(progdefaults.HamlibWait);} } Fl_Choice mnuBaudRate { @@ -1875,7 +1882,7 @@ btnInitHAMLIB->redraw_label();} callback {progdefaults.HamRigBaudrate = o->value(); btnInitHAMLIB->labelcolor(FL_RED); btnInitHAMLIB->redraw_label();} open - tooltip {Serial port baud rate} xywh {385 138 99 22} down_box BORDER_BOX align 5 + tooltip {Serial port baud rate} xywh {385 127 99 22} down_box BORDER_BOX code0 {o->add(szBaudRates);} code1 {o->value(progdefaults.HamRigBaudrate);} } {} @@ -1965,6 +1972,13 @@ btnInitHAMLIB->redraw_label();} tooltip {Rig requires Xon/Xoff flow control} xywh {269 281 185 20} down_box DOWN_BOX code0 {o->value(progdefaults.HamlibXONXOFFflow);} } + Fl_Value_Slider valHamRigStopbits { + label Stopbits + callback {progdefaults.HamRigStopbits = (int)o->value(); +progdefaults.changed = true;} selected + xywh {424 162 60 22} type Horizontal color 7 selection_color 40 align 4 minimum 1 maximum 2 step 1 value 2 textsize 14 + code0 {o->value(progdefaults.HamRigStopbits);} + } } } Fl_Group {} { diff --git a/src/include/confdialog.h b/src/include/confdialog.h index 4150e29d..64d992f9 100644 --- a/src/include/confdialog.h +++ b/src/include/confdialog.h @@ -220,6 +220,7 @@ extern Fl_Round_Button *btnRigCatDTRptt; extern Fl_Check_Button *btnRigCatRTSplus; extern Fl_Check_Button *btnRigCatDTRplus; extern Fl_Check_Button *chkRigCatRTSCTSflow; +extern Fl_Value_Slider *valRigCatStopbits; extern Fl_Group *tabHamlib; extern Fl_Check_Button *chkUSEHAMLIB; extern Fl_Group *grpHamlib; @@ -239,6 +240,7 @@ extern Fl_Check_Button *btnHamlibDTRplus; extern Fl_Check_Button *chkHamlibRTSplus; extern Fl_Check_Button *chkHamlibRTSCTSflow; extern Fl_Check_Button *chkHamlibXONXOFFflow; +extern Fl_Value_Slider *valHamRigStopbits; extern Fl_Group *grpMemmap; extern Fl_Check_Button *chkUSEMEMMAP; extern Fl_Round_Button *btnMEMMAPptt; diff --git a/src/include/configuration.h b/src/include/configuration.h index 33fcb6cb..76bed277 100644 --- a/src/include/configuration.h +++ b/src/include/configuration.h @@ -539,6 +539,9 @@ " 0: 300; 1: 600; 2: 1200; 3: 2400; 4: 4800; 5: 9600; 6: 19200;\n" \ " 7: 38400; 8: 57600; 9: 115200; 10: 230400; 11: 460800.", \ 1) /* 600 baud */ \ + ELEM_(int, HamRigStopbits, "HAMRIGSTOPBITS", \ + "Hamlib stopbits <1/2>.", \ + 2) /* 600 baud */ \ ELEM_(std::string, XmlRigFilename, "XMLRIGFILENAME", \ "RigCAT XML file name", \ "") \ @@ -548,6 +551,9 @@ ELEM_(int, XmlRigBaudrate, "XMLRIGBAUDRATE", \ "RigCAT rig baud rate. See HAMRIGBAUDRATE.", \ 1) /* 600 baud */ \ + ELEM_(int, RigCatStopbits, "RIGCATSTOPBITS", \ + "RigCAT stopbits. <1/2>", \ + 2) /* 600 baud */ \ ELEM_(bool, TTYptt, "TTYPTT", \ "Use separate device for PTT", \ false) \ diff --git a/src/include/serial.h b/src/include/serial.h index b2fb20bb..2497ff29 100644 --- a/src/include/serial.h +++ b/src/include/serial.h @@ -20,43 +20,46 @@ public: //Methods bool OpenPort(); - + bool IsOpen() { return fd < 0 ? 0 : 1; }; void ClosePort(); void Device (std::string dev) { device = dev;}; std::string Device() { return device;}; - + void Baud(int b) { baud = b;}; int Baud() { return baud;}; - + void Timeout(int tm) { timeout = tm;} int Timeout() { return timeout; } - + void Retries(int r) { retries = r;} int Retries() { return retries;} - + void RTS(bool r){rts = r;} bool RTS(){return rts;} - + void RTSptt(bool b){rtsptt = b;} bool RTSptt(){return rtsptt;} - + void DTR(bool d){dtr = d;} bool DTR(){return dtr;} - + void DTRptt(bool b){dtrptt = b;} bool DTRptt(){return dtrptt;} - + void RTSCTS(bool b){rtscts = b;} bool RTSCTS(){return rtscts;} void SetPTT(bool b); - + + void Stopbits(int n) {stopbits = (n == 1 ? 1 : 2);} + int Stopbits() { return stopbits;} + int ReadBuffer (unsigned char *b, int nbr); int WriteBuffer(unsigned char *str, int nbr); void FlushBuffer(); - - + + private: //Members std::string device; @@ -72,6 +75,7 @@ private: bool rts; bool rtsptt; bool rtscts; + int stopbits; char bfr[2048]; //Methods bool IOselect(); @@ -88,6 +92,7 @@ public: rtsptt = dtrptt = false; rtscts = false; baud = CBR_9600; + stopbits = 2; }; Cserial( std::string portname) { device = portname; @@ -125,29 +130,32 @@ public: void Device (std::string dev) { device = dev;}; std::string Device() { return device;}; - + void Baud(int b) { baud = b;}; int Baud() { return baud;}; - + void Retries(int r) { retries = r;} int Retries() { return retries;} - + void RTS(bool r){rts = r;} bool RTS(){return rts;} - + void RTSptt(bool b){rtsptt = b;} bool RTSptt(){return rtsptt;} - + void DTR(bool d){dtr = d;} bool DTR(){return dtr;} - + void DTRptt(bool b){dtrptt = b;} bool DTRptt(){return dtrptt;} - + void RTSCTS(bool b){rtscts = b;} bool RTSCTS(){return rtscts;} void SetPTT(bool b); + void Stopbits(int n) {stopbits = (n == 1 ? 1 : 2);} + int Stopbits() { return stopbits;} + //Members private: std::string device; @@ -161,7 +169,7 @@ private: //Is the Port Ready? BOOL bPortReady; - + //Number of Bytes Written to port DWORD nBytesWritten; @@ -176,13 +184,13 @@ private: int baud; int retries; - + bool dtr; bool dtrptt; bool rts; bool rtsptt; bool rtscts; - + int stopbits; }; #endif // __MINGW32__ diff --git a/src/rigcontrol/hamlib.cxx b/src/rigcontrol/hamlib.cxx index fd9e01f6..b566f19b 100644 --- a/src/rigcontrol/hamlib.cxx +++ b/src/rigcontrol/hamlib.cxx @@ -69,60 +69,65 @@ void show_error(const char* msg1, const char* msg2 = 0) void hamlib_get_defaults() { - char szParam[40]; + char szParam[40]; - progdefaults.HamRigModel = hamlib_get_rig_model(cboHamlibRig->index()); - - xcvr->init(progdefaults.HamRigModel); - - if (xcvr->getCaps()->port_type != RIG_PORT_SERIAL) { - xcvr->close(); - return; - } - - xcvr->getConf("serial_speed", szParam); - progdefaults.HamRigBaudrate = progdefaults.nBaudRate(szParam); - mnuBaudRate->value(progdefaults.HamRigBaudrate); + progdefaults.HamRigModel = hamlib_get_rig_model(cboHamlibRig->index()); - xcvr->getConf("post_write_delay", szParam); - sscanf(szParam, "%d", &progdefaults.HamlibWait); - cntHamlibWait->value(progdefaults.HamlibWait); - - xcvr->getConf("write_delay", szParam); - sscanf(szParam, "%d", &progdefaults.HamlibWriteDelay); - cntHamlibWriteDelay->value(progdefaults.HamlibWriteDelay); - - xcvr->getConf("timeout", szParam); - sscanf(szParam, "%d", &progdefaults.HamlibTimeout); - cntHamlibTimeout->value(progdefaults.HamlibTimeout); - - xcvr->getConf("retry", szParam); - sscanf(szParam, "%d", &progdefaults.HamlibRetries); - cntHamlibRetries->value(progdefaults.HamlibRetries); + xcvr->init(progdefaults.HamRigModel); - xcvr->getConf("rts_state", szParam); - if (strcmp(szParam, "ON") == 0) - progdefaults.HamlibRTSplus = true; - else - progdefaults.HamlibRTSplus = false; - chkHamlibRTSplus->value(progdefaults.HamlibRTSplus); + if (xcvr->getCaps()->port_type != RIG_PORT_SERIAL) { + xcvr->close(); + return; + } - xcvr->getConf("dtr_state", szParam); - if (strcmp(szParam, "ON") == 0) - progdefaults.HamlibDTRplus = true; - else - progdefaults.HamlibDTRplus = false; - btnHamlibDTRplus->value(progdefaults.HamlibDTRplus); - - progdefaults.HamlibRTSCTSflow = false; - progdefaults.HamlibXONXOFFflow = false; - xcvr->getConf("serial_handshake", szParam); - if (strcmp(szParam, "Hardware") == 0) progdefaults.HamlibRTSCTSflow = true; - if (strcmp(szParam, "XONXOFF") == 0) progdefaults.HamlibXONXOFFflow = true; - chkHamlibRTSCTSflow->value(progdefaults.HamlibRTSCTSflow); - chkHamlibXONXOFFflow->value(progdefaults.HamlibXONXOFFflow); + xcvr->getConf("serial_speed", szParam); + progdefaults.HamRigBaudrate = progdefaults.nBaudRate(szParam); + mnuBaudRate->value(progdefaults.HamRigBaudrate); - xcvr->close(); + xcvr->getConf("post_write_delay", szParam); + sscanf(szParam, "%d", &progdefaults.HamlibWait); + cntHamlibWait->value(progdefaults.HamlibWait); + + xcvr->getConf("write_delay", szParam); + sscanf(szParam, "%d", &progdefaults.HamlibWriteDelay); + cntHamlibWriteDelay->value(progdefaults.HamlibWriteDelay); + + xcvr->getConf("timeout", szParam); + sscanf(szParam, "%d", &progdefaults.HamlibTimeout); + cntHamlibTimeout->value(progdefaults.HamlibTimeout); + + xcvr->getConf("retry", szParam); + sscanf(szParam, "%d", &progdefaults.HamlibRetries); + cntHamlibRetries->value(progdefaults.HamlibRetries); + + xcvr->getConf("rts_state", szParam); + if (strcmp(szParam, "ON") == 0) + progdefaults.HamlibRTSplus = true; + else + progdefaults.HamlibRTSplus = false; + chkHamlibRTSplus->value(progdefaults.HamlibRTSplus); + + xcvr->getConf("dtr_state", szParam); + if (strcmp(szParam, "ON") == 0) + progdefaults.HamlibDTRplus = true; + else + progdefaults.HamlibDTRplus = false; + btnHamlibDTRplus->value(progdefaults.HamlibDTRplus); + + progdefaults.HamlibRTSCTSflow = false; + progdefaults.HamlibXONXOFFflow = false; + xcvr->getConf("serial_handshake", szParam); + if (strcmp(szParam, "Hardware") == 0) progdefaults.HamlibRTSCTSflow = true; + if (strcmp(szParam, "XONXOFF") == 0) progdefaults.HamlibXONXOFFflow = true; + chkHamlibRTSCTSflow->value(progdefaults.HamlibRTSCTSflow); + chkHamlibXONXOFFflow->value(progdefaults.HamlibXONXOFFflow); + + xcvr->getConf("stop_bits", szParam); + progdefaults.HamRigStopbits = 2; + if (strcmp(szParam, "1") == 0) progdefaults.HamRigStopbits = 1; + valHamRigStopbits->value(progdefaults.HamRigStopbits); + + xcvr->close(); } bool hamlib_init(bool bPtt) @@ -171,13 +176,13 @@ bool hamlib_init(bool bPtt) if (progdefaults.HamlibRTSplus) xcvr->setConf("rts_state", "ON"); - else - xcvr->setConf("rts_state", "OFF"); + else + xcvr->setConf("rts_state", "OFF"); if (progdefaults.HamlibDTRplus) xcvr->setConf("dtr_state", "ON"); - else - xcvr->setConf("dtr_state", "OFF"); + else + xcvr->setConf("dtr_state", "OFF"); if (progdefaults.HamlibRTSCTSflow) xcvr->setConf("serial_handshake", "Hardware"); @@ -186,6 +191,7 @@ bool hamlib_init(bool bPtt) else xcvr->setConf("serial_handshake", "None"); } + xcvr->setConf("stop_bits", progdefaults.HamRigStopbits == 1 ? "1" : "2"); string::size_type c = progdefaults.HamConfig.find('#'); if (c != string::npos) @@ -200,7 +206,6 @@ bool hamlib_init(bool bPtt) conf += end; } } - xcvr->open(); } catch (const RigException& Ex) { @@ -211,7 +216,7 @@ bool hamlib_init(bool bPtt) MilliSleep(500); - LOG_INFO("trying frequency request"); + LOG_INFO("trying frequency request"); try { need_freq = true; freq = xcvr->getFreq(); @@ -234,12 +239,12 @@ bool hamlib_init(bool bPtt) show_error("Get Mode", Ex.what()); need_mode = false; } - + try { if (hamlib_ptt == true) { - LOG_INFO("trying PTT"); - xcvr->setPTT(RIG_PTT_OFF); - } + LOG_INFO("trying PTT"); + xcvr->setPTT(RIG_PTT_OFF); + } } catch (const RigException& Ex) { show_error("Set Ptt", Ex.what()); @@ -257,15 +262,15 @@ bool hamlib_init(bool bPtt) hamlib_exit = false; hamlib_bypass = false; - + if (pthread_create(&hamlib_thread, NULL, hamlib_loop, NULL) < 0) { show_error(__func__, "pthread_create failed"); xcvr->close(); return false; - } + } init_Hamlib_RigDialog(); - + hamlib_closed = false; return true; } @@ -302,7 +307,7 @@ bool hamlib_active(void) void hamlib_set_ptt(int ptt) { - if (xcvr->isOnLine() == false) + if (xcvr->isOnLine() == false) return; if (!hamlib_ptt) return; @@ -320,7 +325,7 @@ void hamlib_set_ptt(int ptt) void hamlib_set_qsy(long long f, long long fmid) { - if (xcvr->isOnLine() == false) + if (xcvr->isOnLine() == false) return; pthread_mutex_lock(&hamlib_mutex); double fdbl = f; @@ -416,7 +421,7 @@ static void *hamlib_loop(void *args) long int freq = 0L; rmode_t numode = RIG_MODE_NONE; bool freqok = false, modeok = false; - + for (;;) { MilliSleep(100); if (hamlib_exit) @@ -425,7 +430,7 @@ static void *hamlib_loop(void *args) continue; // hamlib locked while accessing hamlib serial i/o pthread_mutex_lock(&hamlib_mutex); - + if (need_freq) { freq_t f; try { @@ -444,7 +449,7 @@ static void *hamlib_loop(void *args) } if (hamlib_exit) break; - + if (need_mode && hamlib_rmode == numode) { try { numode = xcvr->getMode(hamlib_pbwidth); @@ -467,7 +472,7 @@ static void *hamlib_loop(void *args) show_frequency(hamlib_freq); wf->rfcarrier(hamlib_freq); } - + if (modeok && (hamlib_rmode != numode)) { hamlib_rmode = numode; show_mode(modeString(hamlib_rmode)); @@ -480,7 +485,7 @@ static void *hamlib_loop(void *args) hamlib_rmode == RIG_MODE_ECSSLSB || hamlib_rmode == RIG_MODE_RTTY)); } - + if (hamlib_exit) break; } diff --git a/src/rigcontrol/rigclass.cxx b/src/rigcontrol/rigclass.cxx index ed3abd3e..28bd0003 100644 --- a/src/rigcontrol/rigclass.cxx +++ b/src/rigcontrol/rigclass.cxx @@ -50,8 +50,8 @@ const struct rig_caps* Rig::getCaps(void) void Rig::open(void) { - int err; - if ((err = rig_open(rig)) != RIG_OK) + int err = rig_open(rig); + if (err != RIG_OK) throw RigException(err); } diff --git a/src/rigcontrol/rigio.cxx b/src/rigcontrol/rigio.cxx index d84c26bc..08d2a0c3 100644 --- a/src/rigcontrol/rigio.cxx +++ b/src/rigcontrol/rigio.cxx @@ -1,7 +1,7 @@ // ==================================================================== // // rigio.cxx -- thread for reading/writing to serial port -// to which the transceiver is connected +// to which the transceiver is connected // // ==================================================================== @@ -15,11 +15,11 @@ #include #ifdef RIGCATTEST - #include "rigCAT.h" + #include "rigCAT.h" #else - #include "fl_digi.h" - #include "misc.h" - #include "configuration.h" + #include "fl_digi.h" + #include "misc.h" + #include "configuration.h" #endif #include "rigsupport.h" @@ -39,17 +39,17 @@ using namespace std; Cserial rigio; static pthread_mutex_t rigCAT_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_t *rigCAT_thread = 0; +static pthread_t *rigCAT_thread = 0; -static bool rigCAT_exit = false; -static bool rigCAT_open = false; -static bool rigCAT_bypass = false; -static unsigned char replybuff[200]; -static unsigned char sendbuff[200]; +static bool rigCAT_exit = false; +static bool rigCAT_open = false; +static bool rigCAT_bypass = false; +static unsigned char replybuff[200]; +static unsigned char sendbuff[200]; -static string sRigWidth = ""; -static string sRigMode = ""; -static long long llFreq = 0; +static string sRigWidth = ""; +static string sRigMode = ""; +static long long llFreq = 0; static bool nonCATrig = false; static bool noXMLfile = false; @@ -63,932 +63,934 @@ int readtimeout, readwait; bool hexout(const string& s, int retnbr) { - unsigned char retbuf[2]; - int numread = 0; - int numwrite = (int)s.size(); + unsigned char retbuf[2]; + int numread = 0; + int numwrite = (int)s.size(); - for (int n = 0; n < progdefaults.RigCatRetries; n++) { - memset(sendbuff,0, 200); - for (unsigned int i = 0; i < s.length(); i++) - sendbuff[i] = s[i]; + for (int n = 0; n < progdefaults.RigCatRetries; n++) { + memset(sendbuff,0, 200); + for (unsigned int i = 0; i < s.length(); i++) + sendbuff[i] = s[i]; // write the command string - rigio.WriteBuffer(sendbuff, s.size()); + rigio.WriteBuffer(sendbuff, s.size()); // read the echo if required - numread = 0; - if (progdefaults.RigCatECHO == true) { - memset(replybuff,0,200); - while (numread < numwrite) { - readwait = progdefaults.RigCatWait + 1; - memset(retbuf, 0, 2); - while (readwait && rigio.ReadBuffer(retbuf, 1) == 0) { - MilliSleep(1); - readwait--; - } - if (!readwait) break; - replybuff[numread] = retbuf[0]; - numread++; - } + numread = 0; + if (progdefaults.RigCatECHO == true) { + memset(replybuff,0,200); + while (numread < numwrite) { + readwait = progdefaults.RigCatWait + 1; + memset(retbuf, 0, 2); + while (readwait && rigio.ReadBuffer(retbuf, 1) == 0) { + MilliSleep(1); + readwait--; + } + if (!readwait) break; + replybuff[numread] = retbuf[0]; + numread++; + } - if (readwait == 0) { - return false; // could not read the echo - } - } + if (readwait == 0) { + return false; // could not read the echo + } + } // read the response if required - if (retnbr > 0) { - memset(replybuff,0,200); - numread = 0; - while (numread < retnbr) { - readwait = progdefaults.RigCatWait + 1; - memset(retbuf, 0, 2); - while (readwait && rigio.ReadBuffer(retbuf, 1) == 0) { - MilliSleep(1); - readwait--; - } - if (!readwait) break; - replybuff[numread] = retbuf[0]; - numread++; - } - if (numread == retnbr) { - return true; - } else - LOG_ERROR("read fail, %d bytes, retry # %d", numread, n); - } - else // no response need - return true; // just return true + if (retnbr > 0) { + memset(replybuff,0,200); + numread = 0; + while (numread < retnbr) { + readwait = progdefaults.RigCatWait + 1; + memset(retbuf, 0, 2); + while (readwait && rigio.ReadBuffer(retbuf, 1) == 0) { + MilliSleep(1); + readwait--; + } + if (!readwait) break; + replybuff[numread] = retbuf[0]; + numread++; + } + if (numread == retnbr) { + return true; + } else + LOG_ERROR("read fail, %d bytes, retry # %d", numread, n); + } + else // no response need + return true; // just return true - if ((readtimeout = progdefaults.RigCatTimeout) > 0) - while (readtimeout--) - MilliSleep(1); - } + if ((readtimeout = progdefaults.RigCatTimeout) > 0) + while (readtimeout--) + MilliSleep(1); + } // failed to read in RigCatRetries - return false; // timed out + return false; // timed out } string to_bcd_be(long long freq, int len) { - string bcd = ""; - unsigned char a; - int numchars = len / 2; - if (len & 1) numchars ++; - for (int i = 0; i < numchars; i++) { - a = 0; - a |= freq%10; - freq /= 10; - a |= (freq%10)<<4; - freq /= 10; - bcd += a; - } - return bcd; + string bcd = ""; + unsigned char a; + int numchars = len / 2; + if (len & 1) numchars ++; + for (int i = 0; i < numchars; i++) { + a = 0; + a |= freq%10; + freq /= 10; + a |= (freq%10)<<4; + freq /= 10; + bcd += a; + } + return bcd; } string to_bcd(long long freq, int len) { - string bcd = ""; - string bcd_be = to_bcd_be(freq, len); - int bcdlen = bcd_be.size(); - for (int i = bcdlen - 1; i >= 0; i--) - bcd += bcd_be[i]; - return bcd; + string bcd = ""; + string bcd_be = to_bcd_be(freq, len); + int bcdlen = bcd_be.size(); + for (int i = bcdlen - 1; i >= 0; i--) + bcd += bcd_be[i]; + return bcd; } long long fm_bcd (size_t p, int len) { - int i; - long long f = 0; - int numchars = len/2; - if (len & 1) numchars ++; - for (i = 0; i < numchars; i++) { - f *=10; - f += replybuff[p + i] >> 4; - f *= 10; - f += replybuff[p + i] & 0x0F; - } - return f; + int i; + long long f = 0; + int numchars = len/2; + if (len & 1) numchars ++; + for (i = 0; i < numchars; i++) { + f *=10; + f += replybuff[p + i] >> 4; + f *= 10; + f += replybuff[p + i] & 0x0F; + } + return f; } long long fm_bcd_be(size_t p, int len) { - unsigned char temp; - int numchars = len/2; - if (len & 1) numchars++; - for (int i = 0; i < numchars / 2; i++) { - temp = replybuff[p + i]; - replybuff[p + i] = replybuff[p + numchars -1 - i]; - replybuff[p + numchars -1 - i] = temp; - } - return fm_bcd(p, len); + unsigned char temp; + int numchars = len/2; + if (len & 1) numchars++; + for (int i = 0; i < numchars / 2; i++) { + temp = replybuff[p + i]; + replybuff[p + i] = replybuff[p + numchars -1 - i]; + replybuff[p + numchars -1 - i] = temp; + } + return fm_bcd(p, len); } string to_binary_be(long long freq, int len) { - string bin = ""; - for (int i = 0; i < len; i++) { - bin += freq & 0xFF; - freq >>= 8; - } - return bin; + string bin = ""; + for (int i = 0; i < len; i++) { + bin += freq & 0xFF; + freq >>= 8; + } + return bin; } string to_binary(long long freq, int len) { - string bin = ""; - string bin_be = to_binary_be(freq, len); - int binlen = bin_be.size(); - for (int i = binlen - 1; i >= 0; i--) - bin += bin_be[i]; - return bin; + string bin = ""; + string bin_be = to_binary_be(freq, len); + int binlen = bin_be.size(); + for (int i = binlen - 1; i >= 0; i--) + bin += bin_be[i]; + return bin; } long long fm_binary(size_t p, int len) { - int i; - long long f = 0; - for (i = 0; i < len; i++) { - f *= 256; - f += replybuff[p + i]; - } - return f; + int i; + long long f = 0; + for (i = 0; i < len; i++) { + f *= 256; + f += replybuff[p + i]; + } + return f; } long long fm_binary_be(size_t p, int len) { - unsigned char temp; - int numchars = len/2; - if (len & 1) numchars++; - for (int i = 0; i < numchars / 2; i++) { - temp = replybuff[p + i]; - replybuff[p + i] = replybuff[p + numchars -1 - i]; - replybuff[p + numchars -1 - i] = temp; - } - return fm_binary(p, len); + unsigned char temp; + int numchars = len/2; + if (len & 1) numchars++; + for (int i = 0; i < numchars / 2; i++) { + temp = replybuff[p + i]; + replybuff[p + i] = replybuff[p + numchars -1 - i]; + replybuff[p + numchars -1 - i] = temp; + } + return fm_binary(p, len); } string to_decimal_be(long long d, int len) { - string sdec_be = ""; - for (int i = 0; i < len; i++) { - sdec_be += (char)((d % 10) + '0'); - d /= 10; - } - return sdec_be; + string sdec_be = ""; + for (int i = 0; i < len; i++) { + sdec_be += (char)((d % 10) + '0'); + d /= 10; + } + return sdec_be; } string to_decimal(long long d, int len) { - string sdec = ""; - string sdec_be = to_decimal_be(d, len); - int bcdlen = sdec_be.size(); - for (int i = bcdlen - 1; i >= 0; i--) - sdec += sdec_be[i]; - return sdec; + string sdec = ""; + string sdec_be = to_decimal_be(d, len); + int bcdlen = sdec_be.size(); + for (int i = bcdlen - 1; i >= 0; i--) + sdec += sdec_be[i]; + return sdec; } long long fm_decimal(size_t p, int len) { - long long d = 0; - for (int i = 0; i < len; i++) { - d *= 10; - d += replybuff[p + i] - '0'; - } - return d; + long long d = 0; + for (int i = 0; i < len; i++) { + d *= 10; + d += replybuff[p + i] - '0'; + } + return d; } long long fm_decimal_be(size_t p, int len) { - unsigned char temp; - int numchars = len/2; - if (len & 1) numchars++; - for (int i = 0; i < numchars / 2; i++) { - temp = replybuff[p + i]; - replybuff[p + i] = replybuff[p + numchars -1 - i]; - replybuff[p + numchars -1 - i] = temp; - } - return fm_decimal(p, len); + unsigned char temp; + int numchars = len/2; + if (len & 1) numchars++; + for (int i = 0; i < numchars / 2; i++) { + temp = replybuff[p + i]; + replybuff[p + i] = replybuff[p + numchars -1 - i]; + replybuff[p + numchars -1 - i] = temp; + } + return fm_decimal(p, len); } string to_freqdata(DATA d, long long f) { - int num, den; - num = 100; - den = (int)(d.resolution * 100); - if (d.size == 0) return ""; - if (d.dtype == "BCD") { - if (d.reverse == true) - return to_bcd_be((long long int)(f * num / den), d.size); - else - return to_bcd((long long int)(f * num / den), d.size); - } else if (d.dtype == "BINARY") { - if (d.reverse == true) - return to_binary_be((long long int)(f * num / den), d.size); - else - return to_binary((long long int)(f * num / den), d.size); - } else if (d.dtype == "DECIMAL") { - if (d.reverse == true) - return to_decimal_be((long long int)(f * num / den), d.size); - else - return to_decimal((long long int)(f * num / den), d.size); - } - return ""; + int num, den; + num = 100; + den = (int)(d.resolution * 100); + if (d.size == 0) return ""; + if (d.dtype == "BCD") { + if (d.reverse == true) + return to_bcd_be((long long int)(f * num / den), d.size); + else + return to_bcd((long long int)(f * num / den), d.size); + } else if (d.dtype == "BINARY") { + if (d.reverse == true) + return to_binary_be((long long int)(f * num / den), d.size); + else + return to_binary((long long int)(f * num / den), d.size); + } else if (d.dtype == "DECIMAL") { + if (d.reverse == true) + return to_decimal_be((long long int)(f * num / den), d.size); + else + return to_decimal((long long int)(f * num / den), d.size); + } + return ""; } long long fm_freqdata(DATA d, size_t p) { - int num, den; - num = (int)(d.resolution * 100); - den = 100; - if (d.dtype == "BCD") { - if (d.reverse == true) { - // LOG_INFO("BCD reverse"); - return (long long int)(fm_bcd_be(p, d.size) * num / den); - } else { - // LOG_INFO("BCD normal"); - return (long long int)(fm_bcd(p, d.size) * num / den); - } - } else if (d.dtype == "BINARY") { - if (d.reverse == true) - return (long long int)(fm_binary_be(p, d.size) * num / den); - else - return (long long int)(fm_binary(p, d.size) * num / den); - } else if (d.dtype == "DECIMAL") { - if (d.reverse == true) - return (long long int)(fm_decimal_be(p, d.size) * num / den); - else - return (long long int)(fm_decimal(p, d.size) * num / den); - } - return 0; + int num, den; + num = (int)(d.resolution * 100); + den = 100; + if (d.dtype == "BCD") { + if (d.reverse == true) { + // LOG_INFO("BCD reverse"); + return (long long int)(fm_bcd_be(p, d.size) * num / den); + } else { + // LOG_INFO("BCD normal"); + return (long long int)(fm_bcd(p, d.size) * num / den); + } + } else if (d.dtype == "BINARY") { + if (d.reverse == true) + return (long long int)(fm_binary_be(p, d.size) * num / den); + else + return (long long int)(fm_binary(p, d.size) * num / den); + } else if (d.dtype == "DECIMAL") { + if (d.reverse == true) + return (long long int)(fm_decimal_be(p, d.size) * num / den); + else + return (long long int)(fm_decimal(p, d.size) * num / den); + } + return 0; } long long rigCAT_getfreq() { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - if (nonCATrig == true || noXMLfile) { - return noCATfreq; - } + if (nonCATrig == true || noXMLfile) { + return noCATfreq; + } -// LOG_DEBUG("get frequency"); +// LOG_DEBUG("get frequency"); - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "GETFREQ") - break; - ++itrCmd; - } + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "GETFREQ") + break; + ++itrCmd; + } - if (itrCmd == commands.end()) { - LOG_WARN("GET_FREQ not defined"); - return -2; // get_freq command is not defined! - } + if (itrCmd == commands.end()) { + LOG_WARN("GET_FREQ not defined"); + return -2; // get_freq command is not defined! + } - modeCmd = *itrCmd; + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.info.size() == 0) - return 0; + if (modeCmd.info.size() == 0) + return 0; - for (list::iterator preply = reply.begin(); preply != reply.end(); ++preply) { - if (preply->SYMBOL != modeCmd.info) - continue; + for (list::iterator preply = reply.begin(); preply != reply.end(); ++preply) { + if (preply->SYMBOL != modeCmd.info) + continue; - XMLIOS rTemp = *preply; - size_t p = 0, pData = 0; - size_t len = rTemp.str1.size(); + XMLIOS rTemp = *preply; + size_t p = 0, pData = 0; + size_t len = rTemp.str1.size(); - // send the command - if (hexout(strCmd, rTemp.size ) == false) { - LOG_ERROR("Hexout failed"); - return -1; - } + // send the command + if (hexout(strCmd, rTemp.size ) == false) { + LOG_ERROR("Hexout failed"); + return -1; + } - // check the pre data string - if (len) { - for (size_t i = 0; i < len; i++) { - if ((char)rTemp.str1[i] != (char)replybuff[i]) { - LOG_WARN("failed pre data string test @ %" PRIuSZ, i); - return 0; - } - } - p = len; - } - if (rTemp.fill1) p += rTemp.fill1; - pData = p; - if (rTemp.data.dtype == "BCD") { - p += rTemp.data.size / 2; - if (rTemp.data.size & 1) p++; - } else - p += rTemp.data.size; - // check the post data string - len = rTemp.str2.size(); - if (rTemp.fill2) p += rTemp.fill2; - if (len) { - for (size_t i = 0; i < len; i++) - if ((char)rTemp.str2[i] != (char)replybuff[p + i]) { - LOG_WARN("failed post data string test @ %" PRIuSZ, i); - return 0; - } - } - // convert the data field - long long f = fm_freqdata(rTemp.data, pData); - if ( f >= rTemp.data.min && f <= rTemp.data.max) { - return f; - } - else { - LOG_WARN("freq value failed %lld", f); - return 0; - } - } + // check the pre data string + if (len) { + for (size_t i = 0; i < len; i++) { + if ((char)rTemp.str1[i] != (char)replybuff[i]) { + LOG_WARN("failed pre data string test @ %" PRIuSZ, i); + return 0; + } + } + p = len; + } + if (rTemp.fill1) p += rTemp.fill1; + pData = p; + if (rTemp.data.dtype == "BCD") { + p += rTemp.data.size / 2; + if (rTemp.data.size & 1) p++; + } else + p += rTemp.data.size; + // check the post data string + len = rTemp.str2.size(); + if (rTemp.fill2) p += rTemp.fill2; + if (len) { + for (size_t i = 0; i < len; i++) + if ((char)rTemp.str2[i] != (char)replybuff[p + i]) { + LOG_WARN("failed post data string test @ %" PRIuSZ, i); + return 0; + } + } + // convert the data field + long long f = fm_freqdata(rTemp.data, pData); + if ( f >= rTemp.data.min && f <= rTemp.data.max) { + return f; + } + else { + LOG_WARN("freq value failed %lld", f); + return 0; + } + } - return 0; + return 0; } void rigCAT_setfreq(long long f) { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - if (noXMLfile || nonCATrig) { - noCATfreq = f; - return; - } + if (noXMLfile || nonCATrig) { + noCATfreq = f; + return; + } -// LOG_DEBUG("set frequency %lld", f); +// LOG_DEBUG("set frequency %lld", f); - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "SETFREQ") - break; - ++itrCmd; - } - if (itrCmd == commands.end()) { - LOG_WARN("SET_FREQ not defined"); - noCATfreq = f; - return; - } + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "SETFREQ") + break; + ++itrCmd; + } + if (itrCmd == commands.end()) { + LOG_WARN("SET_FREQ not defined"); + noCATfreq = f; + return; + } - modeCmd = *itrCmd; + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); - strCmd.append( to_freqdata(modeCmd.data, f) ); + strCmd.append( to_freqdata(modeCmd.data, f) ); - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.ok.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.ok) { - XMLIOS rTemp = *preply; + if (modeCmd.ok.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.ok) { + XMLIOS rTemp = *preply; // send the command - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, rTemp.size); - pthread_mutex_unlock(&rigCAT_mutex); - return; - } - preply++; - } - } else { - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, 0); - pthread_mutex_unlock(&rigCAT_mutex); - } + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, rTemp.size); + pthread_mutex_unlock(&rigCAT_mutex); + return; + } + preply++; + } + } else { + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, 0); + pthread_mutex_unlock(&rigCAT_mutex); + } } string rigCAT_getmode() { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - if (nonCATrig == true || noXMLfile) - return noCATmode; + if (nonCATrig == true || noXMLfile) + return noCATmode; -// LOG_DEBUG("get mode"); +// LOG_DEBUG("get mode"); - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "GETMODE") - break; - ++itrCmd; - } - if (itrCmd == commands.end()) - return ""; - modeCmd = *itrCmd; + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "GETMODE") + break; + ++itrCmd; + } + if (itrCmd == commands.end()) + return ""; + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.info.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.info) { - XMLIOS rTemp = *preply; - size_t p = 0, pData = 0; + if (modeCmd.info.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.info) { + XMLIOS rTemp = *preply; + size_t p = 0, pData = 0; // send the command - if (hexout(strCmd, rTemp.size) == false) { - return ""; - } + if (hexout(strCmd, rTemp.size) == false) { + return ""; + } // check the pre data string - size_t len = rTemp.str1.size(); - if (len) { - for (size_t i = 0; i < len; i++) - if ((char)rTemp.str1[i] != (char)replybuff[i]) - return ""; - p = len; - } - if (rTemp.fill1) p += rTemp.fill1; - pData = p; + size_t len = rTemp.str1.size(); + if (len) { + for (size_t i = 0; i < len; i++) + if ((char)rTemp.str1[i] != (char)replybuff[i]) + return ""; + p = len; + } + if (rTemp.fill1) p += rTemp.fill1; + pData = p; // check the post data string - p += rTemp.data.size; - len = rTemp.str2.size(); - if (rTemp.fill2) p += rTemp.fill2; - if (len) { - for (size_t i = 0; i < len; i++) - if ((char)rTemp.str2[i] != (char)replybuff[p + i]) - return ""; - } + p += rTemp.data.size; + len = rTemp.str2.size(); + if (rTemp.fill2) p += rTemp.fill2; + if (len) { + for (size_t i = 0; i < len; i++) + if ((char)rTemp.str2[i] != (char)replybuff[p + i]) + return ""; + } // convert the data field - string mData = ""; - for (int i = 0; i < rTemp.data.size; i++) - mData += (char)replybuff[pData + i]; + string mData = ""; + for (int i = 0; i < rTemp.data.size; i++) + mData += (char)replybuff[pData + i]; // new for FT100 and the ilk that use bit fields - if (rTemp.data.size == 1) { - unsigned char d = mData[0]; - if (rTemp.data.shiftbits) - d >>= rTemp.data.shiftbits; - d &= rTemp.data.andmask; - mData[0] = d; - } - list::iterator mode; - list *pmode; - if (lmodes.empty() == false) - pmode = &lmodes; - else if (lmodeREPLY.empty() == false) - pmode = &lmodeREPLY; - else - return ""; - mode = pmode->begin(); - while (mode != pmode->end()) { - if ((*mode).BYTES == mData) - break; - mode++; - } - if (mode != pmode->end()) - return ((*mode).SYMBOL); - else - return ""; - } - preply++; - } - } + if (rTemp.data.size == 1) { + unsigned char d = mData[0]; + if (rTemp.data.shiftbits) + d >>= rTemp.data.shiftbits; + d &= rTemp.data.andmask; + mData[0] = d; + } + list::iterator mode; + list *pmode; + if (lmodes.empty() == false) + pmode = &lmodes; + else if (lmodeREPLY.empty() == false) + pmode = &lmodeREPLY; + else + return ""; + mode = pmode->begin(); + while (mode != pmode->end()) { + if ((*mode).BYTES == mData) + break; + mode++; + } + if (mode != pmode->end()) + return ((*mode).SYMBOL); + else + return ""; + } + preply++; + } + } - return ""; + return ""; } void rigCAT_setmode(const string& md) { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - if (nonCATrig == true || noXMLfile) { - noCATmode = md; - return; - } + if (nonCATrig == true || noXMLfile) { + noCATmode = md; + return; + } -// LOG_DEBUG("set mode %s", md.c_str()); +// LOG_DEBUG("set mode %s", md.c_str()); - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "SETMODE") - break; - ++itrCmd; - } - modeCmd = *itrCmd; + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "SETMODE") + break; + ++itrCmd; + } + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); - if ( modeCmd.data.size > 0 ) { - list::iterator mode; - list *pmode; - if (lmodes.empty() == false) - pmode = &lmodes; - else if (lmodeCMD.empty() == false) - pmode = &lmodeCMD; - else - return; - mode = pmode->begin(); - while (mode != pmode->end()) { - if ((*mode).SYMBOL == md) - break; - mode++; - } - if (mode != pmode->end()) - strCmd.append( (*mode).BYTES ); - } - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if ( modeCmd.data.size > 0 ) { + list::iterator mode; + list *pmode; + if (lmodes.empty() == false) + pmode = &lmodes; + else if (lmodeCMD.empty() == false) + pmode = &lmodeCMD; + else + return; + mode = pmode->begin(); + while (mode != pmode->end()) { + if ((*mode).SYMBOL == md) + break; + mode++; + } + if (mode != pmode->end()) + strCmd.append( (*mode).BYTES ); + } + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.ok.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.ok) { - XMLIOS rTemp = *preply; + if (modeCmd.ok.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.ok) { + XMLIOS rTemp = *preply; // send the command - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, rTemp.size); - pthread_mutex_unlock(&rigCAT_mutex); - return; - } - preply++; - } - } else { - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, 0); - pthread_mutex_unlock(&rigCAT_mutex); - } + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, rTemp.size); + pthread_mutex_unlock(&rigCAT_mutex); + return; + } + preply++; + } + } else { + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, 0); + pthread_mutex_unlock(&rigCAT_mutex); + } } string rigCAT_getwidth() { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - if (nonCATrig == true || noXMLfile) - return noCATwidth; + if (nonCATrig == true || noXMLfile) + return noCATwidth; -// LOG_DEBUG("get width"); +// LOG_DEBUG("get width"); - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "GETBW") - break; - ++itrCmd; - } - if (itrCmd == commands.end()) - return ""; - modeCmd = *itrCmd; + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "GETBW") + break; + ++itrCmd; + } + if (itrCmd == commands.end()) + return ""; + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.info.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.info) { - XMLIOS rTemp = *preply; - size_t p = 0, pData = 0; + if (modeCmd.info.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.info) { + XMLIOS rTemp = *preply; + size_t p = 0, pData = 0; // send the command - if (hexout(strCmd, rTemp.size) == false) { - return ""; - } + if (hexout(strCmd, rTemp.size) == false) { + return ""; + } // check the pre data string - size_t len = rTemp.str1.size(); - if (len) { - for (size_t i = 0; i < len; i++) - if ((char)rTemp.str1[i] != (char)replybuff[i]) - return ""; - p = pData = len; - } - if (rTemp.fill1) p += rTemp.fill1; - pData = p; - p += rTemp.data.size; + size_t len = rTemp.str1.size(); + if (len) { + for (size_t i = 0; i < len; i++) + if ((char)rTemp.str1[i] != (char)replybuff[i]) + return ""; + p = pData = len; + } + if (rTemp.fill1) p += rTemp.fill1; + pData = p; + p += rTemp.data.size; // check the post data string - if (rTemp.fill2) p += rTemp.fill2; - len = rTemp.str2.size(); - if (len) { - for (size_t i = 0; i < len; i++) - if ((char)rTemp.str2[i] != (char)replybuff[p + i]) - return ""; - } + if (rTemp.fill2) p += rTemp.fill2; + len = rTemp.str2.size(); + if (len) { + for (size_t i = 0; i < len; i++) + if ((char)rTemp.str2[i] != (char)replybuff[p + i]) + return ""; + } // convert the data field - string mData = ""; - for (int i = 0; i < rTemp.data.size; i++) - mData += (char)replybuff[pData + i]; + string mData = ""; + for (int i = 0; i < rTemp.data.size; i++) + mData += (char)replybuff[pData + i]; // new for FT100 and the ilk that use bit fields - if (rTemp.data.size == 1) { - unsigned char d = mData[0]; - if (rTemp.data.shiftbits) - d >>= rTemp.data.shiftbits; - d &= rTemp.data.andmask; - mData[0] = d; - } - list::iterator bw; - list *pbw; - if (lbws.empty() == false) - pbw = &lbws; - else if (lbwREPLY.empty() == false) - pbw = &lbwREPLY; - else - return ""; - bw = pbw->begin(); - while (bw != pbw->end()) { - if ((*bw).BYTES == mData) - break; - bw++; - } - if (bw != pbw->end()) - return ((*bw).SYMBOL); - else - return ""; - } - preply++; - } - } - return ""; + if (rTemp.data.size == 1) { + unsigned char d = mData[0]; + if (rTemp.data.shiftbits) + d >>= rTemp.data.shiftbits; + d &= rTemp.data.andmask; + mData[0] = d; + } + list::iterator bw; + list *pbw; + if (lbws.empty() == false) + pbw = &lbws; + else if (lbwREPLY.empty() == false) + pbw = &lbwREPLY; + else + return ""; + bw = pbw->begin(); + while (bw != pbw->end()) { + if ((*bw).BYTES == mData) + break; + bw++; + } + if (bw != pbw->end()) + return ((*bw).SYMBOL); + else + return ""; + } + preply++; + } + } + return ""; } void rigCAT_setwidth(const string& w) { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; -// LOG_DEBUG("set width"); +// LOG_DEBUG("set width"); - if (noXMLfile) { - noCATwidth = w; - return; - } + if (noXMLfile) { + noCATwidth = w; + return; + } - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "SETBW") - break; - ++itrCmd; - } - if (itrCmd == commands.end()) { - noCATwidth = w; - return; - } - modeCmd = *itrCmd; + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "SETBW") + break; + ++itrCmd; + } + if (itrCmd == commands.end()) { + noCATwidth = w; + return; + } + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); - if ( modeCmd.data.size > 0 ) { + if ( modeCmd.data.size > 0 ) { - list::iterator bw; - list *pbw; - if (lbws.empty() == false) - pbw = &lbws; - else if (lbwCMD.empty() == false) - pbw = &lbwCMD; - else - return; - bw = pbw->begin(); - while (bw != pbw->end()) { - if ((*bw).SYMBOL == w) - break; - bw++; - } - if (bw != pbw->end()) - strCmd.append( (*bw).BYTES ); - } - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + list::iterator bw; + list *pbw; + if (lbws.empty() == false) + pbw = &lbws; + else if (lbwCMD.empty() == false) + pbw = &lbwCMD; + else + return; + bw = pbw->begin(); + while (bw != pbw->end()) { + if ((*bw).SYMBOL == w) + break; + bw++; + } + if (bw != pbw->end()) + strCmd.append( (*bw).BYTES ); + } + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.ok.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.ok) { - XMLIOS rTemp = *preply; + if (modeCmd.ok.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.ok) { + XMLIOS rTemp = *preply; // send the command - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, rTemp.size); - pthread_mutex_unlock(&rigCAT_mutex); - return; - } - preply++; - } - } else { - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, 0); - pthread_mutex_unlock(&rigCAT_mutex); - } + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, rTemp.size); + pthread_mutex_unlock(&rigCAT_mutex); + return; + } + preply++; + } + } else { + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, 0); + pthread_mutex_unlock(&rigCAT_mutex); + } } void rigCAT_pttON() { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - LOG_INFO("ptt ON"); + LOG_INFO("ptt ON"); - rigio.SetPTT(1); // always execute the h/w ptt if enabled + rigio.SetPTT(1); // always execute the h/w ptt if enabled - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "PTTON") - break; - ++itrCmd; - } - if (itrCmd == commands.end()) - return; - modeCmd = *itrCmd; + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "PTTON") + break; + ++itrCmd; + } + if (itrCmd == commands.end()) + return; + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.ok.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.ok) { - XMLIOS rTemp = *preply; + if (modeCmd.ok.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.ok) { + XMLIOS rTemp = *preply; // send the command - hexout(strCmd, rTemp.size); - return; - } - preply++; - } - } else { - hexout(strCmd, 0); - } + hexout(strCmd, rTemp.size); + return; + } + preply++; + } + } else { + hexout(strCmd, 0); + } } void rigCAT_pttOFF() { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - LOG_INFO("ptt OFF"); + LOG_INFO("ptt OFF"); - rigio.SetPTT(0); // always execute the h/w ptt if enabled + rigio.SetPTT(0); // always execute the h/w ptt if enabled - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "PTTOFF") - break; - ++itrCmd; - } - if (itrCmd == commands.end()) - return; - modeCmd = *itrCmd; + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "PTTOFF") + break; + ++itrCmd; + } + if (itrCmd == commands.end()) + return; + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.ok.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.ok) { - XMLIOS rTemp = *preply; + if (modeCmd.ok.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.ok) { + XMLIOS rTemp = *preply; // send the command - hexout(strCmd, rTemp.size); - return; - } - preply++; - } - } else { - hexout(strCmd, 0); - } + hexout(strCmd, rTemp.size); + return; + } + preply++; + } + } else { + hexout(strCmd, 0); + } } void rigCAT_sendINIT() { - XMLIOS modeCmd; - list::iterator itrCmd; - string strCmd; + XMLIOS modeCmd; + list::iterator itrCmd; + string strCmd; - if (noXMLfile) - return; + if (noXMLfile) + return; -// LOG_DEBUG("INIT rig"); +// LOG_DEBUG("INIT rig"); - itrCmd = commands.begin(); - while (itrCmd != commands.end()) { - if ((*itrCmd).SYMBOL == "INIT") - break; - ++itrCmd; - } - if (itrCmd == commands.end()) - return; - modeCmd = *itrCmd; + itrCmd = commands.begin(); + while (itrCmd != commands.end()) { + if ((*itrCmd).SYMBOL == "INIT") + break; + ++itrCmd; + } + if (itrCmd == commands.end()) + return; + modeCmd = *itrCmd; - if ( modeCmd.str1.empty() == false) - strCmd.append(modeCmd.str1); - if (modeCmd.str2.empty() == false) - strCmd.append(modeCmd.str2); + if ( modeCmd.str1.empty() == false) + strCmd.append(modeCmd.str1); + if (modeCmd.str2.empty() == false) + strCmd.append(modeCmd.str2); - if (modeCmd.ok.size()) { - list::iterator preply = reply.begin(); - while (preply != reply.end()) { - if (preply->SYMBOL == modeCmd.ok) { - XMLIOS rTemp = *preply; + if (modeCmd.ok.size()) { + list::iterator preply = reply.begin(); + while (preply != reply.end()) { + if (preply->SYMBOL == modeCmd.ok) { + XMLIOS rTemp = *preply; // send the command - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, rTemp.size); - pthread_mutex_unlock(&rigCAT_mutex); - return; - } - preply++; - } - } else { - pthread_mutex_lock(&rigCAT_mutex); - hexout(strCmd, 0); - pthread_mutex_unlock(&rigCAT_mutex); - } + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, rTemp.size); + pthread_mutex_unlock(&rigCAT_mutex); + return; + } + preply++; + } + } else { + pthread_mutex_lock(&rigCAT_mutex); + hexout(strCmd, 0); + pthread_mutex_unlock(&rigCAT_mutex); + } } void rigCAT_defaults() { - progdefaults.XmlRigBaudrate = xmlrig.baud; - mnuXmlRigBaudrate->value(xmlrig.baud); + progdefaults.XmlRigBaudrate = xmlrig.baud; + mnuXmlRigBaudrate->value(xmlrig.baud); - progdefaults.RigCatRTSplus = xmlrig.rts; - btnRigCatRTSplus->value(xmlrig.rts); + progdefaults.RigCatRTSplus = xmlrig.rts; + btnRigCatRTSplus->value(xmlrig.rts); - progdefaults.RigCatDTRplus = xmlrig.dtr; - btnRigCatDTRplus->value(xmlrig.dtr); + progdefaults.RigCatDTRplus = xmlrig.dtr; + btnRigCatDTRplus->value(xmlrig.dtr); - progdefaults.RigCatRTSptt = xmlrig.rtsptt; - btnRigCatRTSptt->value(xmlrig.rtsptt); + progdefaults.RigCatRTSptt = xmlrig.rtsptt; + btnRigCatRTSptt->value(xmlrig.rtsptt); - progdefaults.RigCatDTRptt = xmlrig.dtrptt; - btnRigCatDTRptt->value(xmlrig.dtrptt); + progdefaults.RigCatDTRptt = xmlrig.dtrptt; + btnRigCatDTRptt->value(xmlrig.dtrptt); - progdefaults.RigCatRTSCTSflow = xmlrig.rtscts; - chkRigCatRTSCTSflow->value(xmlrig.rtscts); + progdefaults.RigCatRTSCTSflow = xmlrig.rtscts; + chkRigCatRTSCTSflow->value(xmlrig.rtscts); - progdefaults.RigCatRetries = xmlrig.retries; - cntRigCatRetries->value(xmlrig.retries); + progdefaults.RigCatRetries = xmlrig.retries; + cntRigCatRetries->value(xmlrig.retries); - progdefaults.RigCatTimeout = xmlrig.timeout; - cntRigCatTimeout->value(xmlrig.timeout); + progdefaults.RigCatTimeout = xmlrig.timeout; + cntRigCatTimeout->value(xmlrig.timeout); - progdefaults.RigCatWait = xmlrig.write_delay; - cntRigCatWait->value(xmlrig.write_delay); + progdefaults.RigCatWait = xmlrig.write_delay; + cntRigCatWait->value(xmlrig.write_delay); - progdefaults.RigCatECHO = xmlrig.echo; - btnRigCatEcho->value(xmlrig.echo); + progdefaults.RigCatECHO = xmlrig.echo; + btnRigCatEcho->value(xmlrig.echo); - progdefaults.RigCatCMDptt = xmlrig.cmdptt; - btnRigCatCMDptt->value(xmlrig.cmdptt); + progdefaults.RigCatCMDptt = xmlrig.cmdptt; + btnRigCatCMDptt->value(xmlrig.cmdptt); } bool rigCAT_init(bool useXML) { - if (rigCAT_open == true) { - LOG_ERROR("RigCAT already open"); - return false; - } + if (rigCAT_open == true) { + LOG_ERROR("RigCAT already open"); + return false; + } - noXMLfile = true; - sRigMode = ""; - sRigWidth = ""; - nonCATrig = true; + noXMLfile = true; + sRigMode = ""; + sRigWidth = ""; + nonCATrig = true; - if (useXML == true) { - if (readRigXML() == false) - LOG_ERROR("No rig.xml file present"); - else { - noXMLfile = false; - rigio.Device(progdefaults.XmlRigDevice); - rigio.Baud(progdefaults.BaudRate(progdefaults.XmlRigBaudrate)); - rigio.RTS(progdefaults.RigCatRTSplus); - rigio.DTR(progdefaults.RigCatDTRplus); - rigio.RTSptt(progdefaults.RigCatRTSptt); - rigio.DTRptt(progdefaults.RigCatDTRptt); - rigio.RTSCTS(progdefaults.RigCatRTSCTSflow); + if (useXML == true) { + if (readRigXML() == false) + LOG_ERROR("No rig.xml file present"); + else { + noXMLfile = false; + rigio.Device(progdefaults.XmlRigDevice); + rigio.Baud(progdefaults.BaudRate(progdefaults.XmlRigBaudrate)); + rigio.RTS(progdefaults.RigCatRTSplus); + rigio.DTR(progdefaults.RigCatDTRplus); + rigio.RTSptt(progdefaults.RigCatRTSptt); + rigio.DTRptt(progdefaults.RigCatDTRptt); + rigio.RTSCTS(progdefaults.RigCatRTSCTSflow); + rigio.Stopbits(progdefaults.RigCatStopbits); - LOG_INFO("\n\ + LOG_INFO("\n\ Serial port parameters:\n\ device : %s\n\ baudrate : %d\n\ +stopbits : %d\n\ retries : %d\n\ timeout : %d\n\ wait : %d\n\ @@ -998,194 +1000,195 @@ initial dtr: %+d\n\ use dtr ptt: %c\n\ flowcontrol: %c\n\ echo : %c\n", - rigio.Device().c_str(), - rigio.Baud(), - progdefaults.RigCatRetries, - progdefaults.RigCatTimeout, - progdefaults.RigCatWait, - (rigio.RTS() ? +12 : -12), (rigio.RTSptt() ? 'T' : 'F'), - (rigio.DTR() ? +12 : -12), (rigio.DTRptt() ? 'T' : 'F'), - (rigio.RTSCTS() ? 'T' : 'F'), - progdefaults.RigCatECHO ? 'T' : 'F'); + rigio.Device().c_str(), + rigio.Baud(), + rigio.Stopbits(), + progdefaults.RigCatRetries, + progdefaults.RigCatTimeout, + progdefaults.RigCatWait, + (rigio.RTS() ? +12 : -12), (rigio.RTSptt() ? 'T' : 'F'), + (rigio.DTR() ? +12 : -12), (rigio.DTRptt() ? 'T' : 'F'), + (rigio.RTSCTS() ? 'T' : 'F'), + progdefaults.RigCatECHO ? 'T' : 'F'); - if (rigio.OpenPort() == false) { - LOG_ERROR("Cannot open serial port %s", rigio.Device().c_str()); - return false; - } - sRigMode = ""; - sRigWidth = ""; + if (rigio.OpenPort() == false) { + LOG_ERROR("Cannot open serial port %s", rigio.Device().c_str()); + return false; + } + sRigMode = ""; + sRigWidth = ""; - nonCATrig = false; + nonCATrig = false; - if (rigCAT_getfreq() == -1) { // will set nonCATrig to true if getfreq not spec'd - LOG_ERROR("Xcvr Freq request not answered"); - rigio.ClosePort(); - return false; - } else { - rigCAT_sendINIT(); - init_Xml_RigDialog(); - } - } - } else - init_NoRig_RigDialog(); + if (rigCAT_getfreq() == -1) { // will set nonCATrig to true if getfreq not spec'd + LOG_ERROR("Xcvr Freq request not answered"); + rigio.ClosePort(); + return false; + } else { + rigCAT_sendINIT(); + init_Xml_RigDialog(); + } + } + } else + init_NoRig_RigDialog(); - llFreq = 0; - rigCAT_bypass = false; - rigCAT_exit = false; + llFreq = 0; + rigCAT_bypass = false; + rigCAT_exit = false; - rigCAT_thread = new pthread_t; + rigCAT_thread = new pthread_t; - if (pthread_create(rigCAT_thread, NULL, rigCAT_loop, NULL) < 0) { - LOG_ERROR("pthread_create failed"); - rigio.ClosePort(); - return false; - } + if (pthread_create(rigCAT_thread, NULL, rigCAT_loop, NULL) < 0) { + LOG_ERROR("pthread_create failed"); + rigio.ClosePort(); + return false; + } - rigCAT_open = true; - return true; + rigCAT_open = true; + return true; } void rigCAT_close(void) { - int count = 200; - if (rigCAT_open == false) - return; - rigCAT_exit = true; + int count = 200; + if (rigCAT_open == false) + return; + rigCAT_exit = true; - while (rigCAT_open == true) { - MilliSleep(50); - count--; - if (!count) { - LOG_ERROR("RigCAT stuck"); - pthread_mutex_lock(&rigCAT_mutex); - rigio.ClosePort(); - pthread_mutex_unlock(&rigCAT_mutex); - exit(0); - } - } - delete rigCAT_thread; - rigCAT_thread = 0; - LOG_DEBUG("RigCAT closed, count = %d", count); + while (rigCAT_open == true) { + MilliSleep(50); + count--; + if (!count) { + LOG_ERROR("RigCAT stuck"); + pthread_mutex_lock(&rigCAT_mutex); + rigio.ClosePort(); + pthread_mutex_unlock(&rigCAT_mutex); + exit(0); + } + } + delete rigCAT_thread; + rigCAT_thread = 0; + LOG_DEBUG("RigCAT closed, count = %d", count); } bool rigCAT_active(void) { - return (rigCAT_open); + return (rigCAT_open); } void rigCAT_set_ptt(int ptt) { - if (rigCAT_open == false) - return; - pthread_mutex_lock(&rigCAT_mutex); - if (ptt) { - rigCAT_pttON(); - rigCAT_bypass = true; - } else{ - rigCAT_pttOFF(); - rigCAT_bypass = false; - } - pthread_mutex_unlock(&rigCAT_mutex); + if (rigCAT_open == false) + return; + pthread_mutex_lock(&rigCAT_mutex); + if (ptt) { + rigCAT_pttON(); + rigCAT_bypass = true; + } else{ + rigCAT_pttOFF(); + rigCAT_bypass = false; + } + pthread_mutex_unlock(&rigCAT_mutex); } #ifndef RIGCATTEST void rigCAT_set_qsy(long long f, long long fmid) { - if (rigCAT_open == false) - return; + if (rigCAT_open == false) + return; - // send new freq to rig - rigCAT_setfreq(f); + // send new freq to rig + rigCAT_setfreq(f); - if (active_modem->freqlocked() == true) { - active_modem->set_freqlock(false); - active_modem->set_freq((int)fmid); - active_modem->set_freqlock(true); - } else - active_modem->set_freq((int)fmid); - wf->rfcarrier(f); - wf->movetocenter(); + if (active_modem->freqlocked() == true) { + active_modem->set_freqlock(false); + active_modem->set_freq((int)fmid); + active_modem->set_freqlock(true); + } else + active_modem->set_freq((int)fmid); + wf->rfcarrier(f); + wf->movetocenter(); } #endif bool ModeIsLSB(const string& s) { - if (noXMLfile) { - if (s == "LSB") - return true; - return false; - } - list::iterator pM = LSBmodes.begin(); - while (pM != LSBmodes.end() ) { - if (*pM == s) - return true; - pM++; - } - return false; + if (noXMLfile) { + if (s == "LSB") + return true; + return false; + } + list::iterator pM = LSBmodes.begin(); + while (pM != LSBmodes.end() ) { + if (*pM == s) + return true; + pM++; + } + return false; } static void *rigCAT_loop(void *args) { - SET_THREAD_ID(RIGCTL_TID); + SET_THREAD_ID(RIGCTL_TID); - long long freq = 0L; - string sWidth, sMode; + long long freq = 0L; + string sWidth, sMode; - for (;;) { - MilliSleep(200); + for (;;) { + MilliSleep(200); - if (rigCAT_bypass == true) - continue; - if (rigCAT_exit == true) - break; + if (rigCAT_bypass == true) + continue; + if (rigCAT_exit == true) + break; - pthread_mutex_lock(&rigCAT_mutex); - freq = rigCAT_getfreq(); - pthread_mutex_unlock(&rigCAT_mutex); + pthread_mutex_lock(&rigCAT_mutex); + freq = rigCAT_getfreq(); + pthread_mutex_unlock(&rigCAT_mutex); - pthread_mutex_lock(&rigCAT_mutex); - sWidth = rigCAT_getwidth(); - pthread_mutex_unlock(&rigCAT_mutex); + pthread_mutex_lock(&rigCAT_mutex); + sWidth = rigCAT_getwidth(); + pthread_mutex_unlock(&rigCAT_mutex); - pthread_mutex_lock(&rigCAT_mutex); - sMode = rigCAT_getmode(); - pthread_mutex_unlock(&rigCAT_mutex); + pthread_mutex_lock(&rigCAT_mutex); + sMode = rigCAT_getmode(); + pthread_mutex_unlock(&rigCAT_mutex); - if ((freq > 0) && (freq != llFreq)) { - llFreq = freq; - show_frequency(freq); - wf->rfcarrier(freq); - } + if ((freq > 0) && (freq != llFreq)) { + llFreq = freq; + show_frequency(freq); + wf->rfcarrier(freq); + } - if (sWidth.size() && sWidth != sRigWidth) { - sRigWidth = sWidth; - show_bw(sWidth); - } + if (sWidth.size() && sWidth != sRigWidth) { + sRigWidth = sWidth; + show_bw(sWidth); + } - if (sMode.size() && sMode != sRigMode) { - sRigMode = sMode; - if (ModeIsLSB(sMode)) - wf->USB(false); - else - wf->USB(true); - show_mode(sMode); - } - } + if (sMode.size() && sMode != sRigMode) { + sRigMode = sMode; + if (ModeIsLSB(sMode)) + wf->USB(false); + else + wf->USB(true); + show_mode(sMode); + } + } - if (rigcontrol) - rigcontrol->hide(); - wf->USB(true); + if (rigcontrol) + rigcontrol->hide(); + wf->USB(true); // wf->setQSY(0); - pthread_mutex_lock(&rigCAT_mutex); - LOG_DEBUG("Exiting rigCAT loop, closing serial port"); - rigio.ClosePort(); - pthread_mutex_unlock(&rigCAT_mutex); + pthread_mutex_lock(&rigCAT_mutex); + LOG_DEBUG("Exiting rigCAT loop, closing serial port"); + rigio.ClosePort(); + pthread_mutex_unlock(&rigCAT_mutex); - rigCAT_open = false; - rigCAT_exit = false; - rigCAT_bypass = false; + rigCAT_open = false; + rigCAT_exit = false; + rigCAT_bypass = false; - return NULL; + return NULL; } diff --git a/src/rigcontrol/serial.cxx b/src/rigcontrol/serial.cxx index c1afebce..42014f6d 100644 --- a/src/rigcontrol/serial.cxx +++ b/src/rigcontrol/serial.cxx @@ -38,6 +38,7 @@ Cserial::Cserial() { rtsptt = dtrptt = false; rtscts = false; status = 0; + stopbits = 2; fd = -1; } @@ -69,7 +70,7 @@ bool Cserial::OpenPort() { newtio.c_cflag &= ~PARENB; - if (0) + if (stopbits == 1) newtio.c_cflag &= ~CSTOPB; // 1 stop bit else newtio.c_cflag |= CSTOPB; // 2 stop bit @@ -284,7 +285,7 @@ BOOL Cserial::OpenPort() if(hComm == INVALID_HANDLE_VALUE) return FALSE; - ConfigurePort( baud, 8, FALSE, NOPARITY, ONESTOPBIT); + ConfigurePort( baud, 8, FALSE, NOPARITY, stopbits); FlushBuffer();