@@ -180,17 +180,51 @@ typedef int HANDLE;
180
180
181
181
#if __WIN32__
182
182
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
+ }
187
214
188
215
#else
189
216
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
+ }
194
228
195
229
#define LPT_IO_ADDR 0x378
196
230
@@ -1182,21 +1216,11 @@ void ptt_set (int ot, int chan, int ptt_signal)
1182
1216
1183
1217
if (save_audio_config_p -> achan [chan ].octrl [ot ].ptt_line == PTT_LINE_RTS ) {
1184
1218
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 );
1191
1220
}
1192
1221
else if (save_audio_config_p -> achan [chan ].octrl [ot ].ptt_line == PTT_LINE_DTR ) {
1193
1222
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 );
1200
1224
}
1201
1225
1202
1226
/*
@@ -1205,21 +1229,11 @@ void ptt_set (int ot, int chan, int ptt_signal)
1205
1229
1206
1230
if (save_audio_config_p -> achan [chan ].octrl [ot ].ptt_line2 == PTT_LINE_RTS ) {
1207
1231
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 );
1214
1233
}
1215
1234
else if (save_audio_config_p -> achan [chan ].octrl [ot ].ptt_line2 == PTT_LINE_DTR ) {
1216
1235
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 );
1223
1237
}
1224
1238
/* else neither one */
1225
1239
0 commit comments