1
// ----------------------------------------------------------------------------
5
// This file is part of flrig.
7
// flrig is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 3 of the License, or
10
// (at your option) any later version.
12
// flrig is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
// ----------------------------------------------------------------------------
39
const char *nuline = "\n";
41
static int iBaudRates[] = { 300, 600, 1200, 2400, 4800, 9600,
42
19200, 38400, 57600, 115200, 230400, 460800 };
43
const char *szBaudRates[] = { "300", "600", "1200", "2400", "4800", "9600",
44
"19200", "38400", "57600", "115200", "230400", "460800", NULL };
48
if (n > (int)sizeof(iBaudRates)) return 1200;
49
return (iBaudRates[n]);
53
bool startXcvrSerial()
55
bypass_serial_thread_loop = true;
56
// setup commands for serial port
57
if (progStatus.xcvr_serial_port == "NONE") return false;
59
RigSerial.Device(progStatus.xcvr_serial_port);
60
RigSerial.Baud(BaudRate(progStatus.comm_baudrate));
61
RigSerial.Stopbits(progStatus.stopbits);
62
RigSerial.Retries(progStatus.comm_retries);
63
RigSerial.Timeout(progStatus.comm_timeout);
64
RigSerial.RTSptt(progStatus.comm_rtsptt);
65
RigSerial.DTRptt(progStatus.comm_dtrptt);
66
RigSerial.RTSCTS(progStatus.comm_rtscts);
67
RigSerial.RTS(progStatus.comm_rtsplus);
68
RigSerial.DTR(progStatus.comm_dtrplus);
70
if (!RigSerial.OpenPort()) {
71
LOG_ERROR("Cannot access %s", progStatus.xcvr_serial_port.c_str());
73
} else if (debug::level == debug::DEBUG_LEVEL) {
88
progStatus.xcvr_serial_port.c_str(),
89
progStatus.comm_baudrate,
91
progStatus.comm_retries,
92
progStatus.comm_timeout,
93
progStatus.serloop_timing,
94
progStatus.comm_rtscts,
95
progStatus.comm_catptt,
96
progStatus.comm_rtsptt,
97
progStatus.comm_dtrptt,
98
progStatus.comm_rtsplus,
99
progStatus.comm_dtrplus );
102
RigSerial.FlushBuffer();
103
// bypass_serial_thread_loop = false;
107
bool startAuxSerial()
109
if (progStatus.aux_serial_port == "NONE") return false;
111
AuxSerial.Device(progStatus.aux_serial_port);
112
AuxSerial.Baud(1200);
113
AuxSerial.RTS(progStatus.aux_rts);
114
AuxSerial.DTR(progStatus.aux_dtr);
116
if (!AuxSerial.OpenPort()) {
117
LOG_ERROR("Cannot access %s", progStatus.aux_serial_port.c_str());
123
bool startSepSerial()
125
if (progStatus.sep_serial_port == "NONE") return false;
127
SepSerial.Device(progStatus.sep_serial_port);
128
SepSerial.Baud(1200);
130
SepSerial.RTSCTS(false);
131
SepSerial.RTS(progStatus.sep_rtsplus);
132
SepSerial.RTSptt(progStatus.sep_rtsptt);
134
SepSerial.DTR(progStatus.sep_dtrplus);
135
SepSerial.DTRptt(progStatus.sep_dtrptt);
137
if (!SepSerial.OpenPort()) {
138
LOG_ERROR("Cannot access %s", progStatus.sep_serial_port.c_str());
144
char replybuff[RXBUFFSIZE+1];
151
memset(replybuff, 0, RXBUFFSIZE + 1);
152
numread = RigSerial.ReadBuffer(replybuff, RXBUFFSIZE);
153
LOG_DEBUG("rsp:%3d, %s", numread, str2hex(replybuff, numread));
154
for (int i = 0; i < numread; replystr += replybuff[i++]);
158
int sendCommand (string s, int nread)
160
int numwrite = (int)s.size();
162
LOG_DEBUG("cmd:%3d, %s", (int)s.length(), str2hex(s.data(), s.length()));
163
if (RigSerial.IsOpen() == false) {
168
if (progStatus.byte_interval == 0)
169
RigSerial.WriteBuffer(s.c_str(), numwrite);
171
for (size_t i = 0; i < s.length(); i++) {
172
RigSerial.WriteByte(s[i]);
173
MilliSleep(progStatus.byte_interval);
176
MilliSleep( progStatus.comm_wait );
183
MilliSleep( (int)((nread + progStatus.comm_echo ? numwrite : 0)*11000.0/RigSerial.Baud()));
185
return readResponse();
189
int waitResponse(int timeout)
192
if (RigSerial.IsOpen() == false)
195
if (!(n = readResponse()))
196
for (int t = 0; t <= timeout; t += 50) {
197
if ((n = readResponse())) break;
204
void clearSerialPort()
206
if (RigSerial.IsOpen() == false) return;
207
RigSerial.FlushBuffer();