Skip to content

Commit 4dff8ad

Browse files
committed
Added handling of serial port DCB for Windows
1 parent fe6cba2 commit 4dff8ad

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

Diff for: src/ptt.c

+46-32
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,51 @@ typedef int HANDLE;
180180

181181
#if __WIN32__
182182

183-
#define RTS_ON(fd) EscapeCommFunction(fd,SETRTS);
184-
#define RTS_OFF(fd) EscapeCommFunction(fd,CLRRTS);
185-
#define DTR_ON(fd) EscapeCommFunction(fd,SETDTR);
186-
#define DTR_OFF(fd) EscapeCommFunction(fd,CLRDTR);
183+
void setRTS(HANDLE fd, unsigned char state)
184+
{
185+
if (!EscapeCommFunction(fd, state ? SETRTS : CLRRTS)) {
186+
return;
187+
}
188+
189+
DCB dcb;
190+
if (!GetCommState(fd, &dcb)) {
191+
return;
192+
}
193+
194+
dcb.fRtsControl = state ? RTS_CONTROL_ENABLE : RTS_CONTROL_DISABLE;
195+
196+
SetCommState(fd, &dcb);
197+
}
198+
199+
void setDTR(HANDLE fd, unsigned char state)
200+
{
201+
if (!EscapeCommFunction(fd, state ? SETDTR : CLRDTR)) {
202+
return;
203+
}
204+
205+
DCB dcb;
206+
if (!GetCommState(fd, &dcb)) {
207+
return;
208+
}
209+
210+
dcb.fDtrControl = state ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE;
211+
212+
SetCommState(fd, &dcb);
213+
}
187214

188215
#else
189216

190-
#define RTS_ON(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff |= TIOCM_RTS; ioctl (fd, TIOCMSET, &stuff); }
191-
#define RTS_OFF(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff &= ~TIOCM_RTS; ioctl (fd, TIOCMSET, &stuff); }
192-
#define DTR_ON(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff |= TIOCM_DTR; ioctl (fd, TIOCMSET, &stuff); }
193-
#define DTR_OFF(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff &= ~TIOCM_DTR; ioctl (fd, TIOCMSET, &stuff); }
217+
void setRTS(HANDLE fd, unsigned char state)
218+
{
219+
int bit = TIOCM_RTS;
220+
ioctl(fd, state ? TIOCMBIS : TIOCMBIC, &bit);
221+
}
222+
223+
void setDTR(HANDLE fd, unsigned char state)
224+
{
225+
int bit = TIOCM_DTR;
226+
ioctl(fd, state ? TIOCMBIS : TIOCMBIC, &bit);
227+
}
194228

195229
#define LPT_IO_ADDR 0x378
196230

@@ -1182,21 +1216,11 @@ void ptt_set (int ot, int chan, int ptt_signal)
11821216

11831217
if (save_audio_config_p->achan[chan].octrl[ot].ptt_line == PTT_LINE_RTS) {
11841218

1185-
if (ptt) {
1186-
RTS_ON(ptt_fd[chan][ot]);
1187-
}
1188-
else {
1189-
RTS_OFF(ptt_fd[chan][ot]);
1190-
}
1219+
setRTS(ptt_fd[chan][ot], ptt);
11911220
}
11921221
else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line == PTT_LINE_DTR) {
11931222

1194-
if (ptt) {
1195-
DTR_ON(ptt_fd[chan][ot]);
1196-
}
1197-
else {
1198-
DTR_OFF(ptt_fd[chan][ot]);
1199-
}
1223+
setDTR(ptt_fd[chan][ot], ptt);
12001224
}
12011225

12021226
/*
@@ -1205,21 +1229,11 @@ void ptt_set (int ot, int chan, int ptt_signal)
12051229

12061230
if (save_audio_config_p->achan[chan].octrl[ot].ptt_line2 == PTT_LINE_RTS) {
12071231

1208-
if (ptt2) {
1209-
RTS_ON(ptt_fd[chan][ot]);
1210-
}
1211-
else {
1212-
RTS_OFF(ptt_fd[chan][ot]);
1213-
}
1232+
setRTS(ptt_fd[chan][ot], ptt2);
12141233
}
12151234
else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line2 == PTT_LINE_DTR) {
12161235

1217-
if (ptt2) {
1218-
DTR_ON(ptt_fd[chan][ot]);
1219-
}
1220-
else {
1221-
DTR_OFF(ptt_fd[chan][ot]);
1222-
}
1236+
setDTR(ptt_fd[chan][ot], ptt2);
12231237
}
12241238
/* else neither one */
12251239

0 commit comments

Comments
 (0)