Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handling of serial port DCB for Windows #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 46 additions & 32 deletions src/ptt.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,51 @@ typedef int HANDLE;

#if __WIN32__

#define RTS_ON(fd) EscapeCommFunction(fd,SETRTS);
#define RTS_OFF(fd) EscapeCommFunction(fd,CLRRTS);
#define DTR_ON(fd) EscapeCommFunction(fd,SETDTR);
#define DTR_OFF(fd) EscapeCommFunction(fd,CLRDTR);
void setRTS(HANDLE fd, unsigned char state)
{
if (!EscapeCommFunction(fd, state ? SETRTS : CLRRTS)) {
return;
}

DCB dcb;
if (!GetCommState(fd, &dcb)) {
return;
}

dcb.fRtsControl = state ? RTS_CONTROL_ENABLE : RTS_CONTROL_DISABLE;

SetCommState(fd, &dcb);
}

void setDTR(HANDLE fd, unsigned char state)
{
if (!EscapeCommFunction(fd, state ? SETDTR : CLRDTR)) {
return;
}

DCB dcb;
if (!GetCommState(fd, &dcb)) {
return;
}

dcb.fDtrControl = state ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE;

SetCommState(fd, &dcb);
}

#else

#define RTS_ON(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff |= TIOCM_RTS; ioctl (fd, TIOCMSET, &stuff); }
#define RTS_OFF(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff &= ~TIOCM_RTS; ioctl (fd, TIOCMSET, &stuff); }
#define DTR_ON(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff |= TIOCM_DTR; ioctl (fd, TIOCMSET, &stuff); }
#define DTR_OFF(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff &= ~TIOCM_DTR; ioctl (fd, TIOCMSET, &stuff); }
void setRTS(HANDLE fd, unsigned char state)
{
int bit = TIOCM_RTS;
ioctl(fd, state ? TIOCMBIS : TIOCMBIC, &bit);
}

void setDTR(HANDLE fd, unsigned char state)
{
int bit = TIOCM_DTR;
ioctl(fd, state ? TIOCMBIS : TIOCMBIC, &bit);
}

#define LPT_IO_ADDR 0x378

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

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

if (ptt) {
RTS_ON(ptt_fd[chan][ot]);
}
else {
RTS_OFF(ptt_fd[chan][ot]);
}
setRTS(ptt_fd[chan][ot], ptt);
}
else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line == PTT_LINE_DTR) {

if (ptt) {
DTR_ON(ptt_fd[chan][ot]);
}
else {
DTR_OFF(ptt_fd[chan][ot]);
}
setDTR(ptt_fd[chan][ot], ptt);
}

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

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

if (ptt2) {
RTS_ON(ptt_fd[chan][ot]);
}
else {
RTS_OFF(ptt_fd[chan][ot]);
}
setRTS(ptt_fd[chan][ot], ptt2);
}
else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line2 == PTT_LINE_DTR) {

if (ptt2) {
DTR_ON(ptt_fd[chan][ot]);
}
else {
DTR_OFF(ptt_fd[chan][ot]);
}
setDTR(ptt_fd[chan][ot], ptt2);
}
/* else neither one */

Expand Down