From: drowe67 Date: Fri, 25 Dec 2015 20:45:45 +0000 (+0000) Subject: initial attempt at Win32 support X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=30c9ef1b0e8e55107535a01ecec84913ee93cce9;p=freetel-svn-tracking.git initial attempt at Win32 support git-svn-id: https://svn.code.sf.net/p/freetel/code@2570 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/freebeacon/freebeacon.c b/freebeacon/freebeacon.c index 6663e5bc..eb189133 100644 --- a/freebeacon/freebeacon.c +++ b/freebeacon/freebeacon.c @@ -11,12 +11,17 @@ #include #include #include -#include #include -#include #include #include +#ifdef _WIN32 +#include +#else +#include +#include +#endif + #include #include @@ -781,8 +786,8 @@ int main(int argc, char *argv[]) { fstatus = fopen(statusPageFileName, "wt"); if (fstatus != NULL) { fprintf(fstatus, "\n\n\n\n\n"); - fprintf(fstatus, "%s: state: %s peak: %d sync: %d SNR: %3.1f triggered: %d\n", - timeStr, state_str[state], peak, sync, snr_est, triggered); + fprintf(fstatus, "%s: state: %s peak: %d sync: %d SNR: %3.1f triggered: %d txtMsg: %s\n", + timeStr, state_str[state], peak, sync, snr_est, triggered, txtMsg); fprintf(fstatus, "\n\n"); fclose(fstatus); } @@ -858,6 +863,61 @@ int openComPort(const char *name) if(com_handle != COM_HANDLE_INVALID) closeComPort(); +#ifdef _WIN32 + { + COMMCONFIG CC; + DWORD CCsize=sizeof(CC); + COMMTIMEOUTS timeouts; + DCB dcb; + + if(GetDefaultCommConfigA(name, &CC, &CCsize)) { + CC.dcb.fOutxCtsFlow = FALSE; + CC.dcb.fOutxDsrFlow = FALSE; + CC.dcb.fDtrControl = DTR_CONTROL_DISABLE; + CC.dcb.fDsrSensitivity = FALSE; + CC.dcb.fRtsControl = RTS_CONTROL_DISABLE; + SetDefaultCommConfigA(name, &CC, CCsize); + } + + if((com_handle=CreateFileA(name + ,GENERIC_READ|GENERIC_WRITE /* Access */ + ,0 /* Share mode */ + ,NULL /* Security attributes */ + ,OPEN_EXISTING /* Create access */ + ,FILE_ATTRIBUTE_NORMAL /* File attributes */ + ,NULL /* Template */ + ))==INVALID_HANDLE_VALUE) + return false; + + if(GetCommTimeouts(com_handle, &timeouts)) { + timeouts.ReadIntervalTimeout=MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier=0; + timeouts.ReadTotalTimeoutConstant=0; // No-wait read timeout + timeouts.WriteTotalTimeoutMultiplier=0; + timeouts.WriteTotalTimeoutConstant=5000; // 5 seconds + SetCommTimeouts(com_handle,&timeouts); + } + + /* Force N-8-1 mode: */ + if(GetCommState(com_handle, &dcb)==TRUE) { + dcb.ByteSize = 8; + dcb.Parity = NOPARITY; + dcb.StopBits = ONESTOPBIT; + dcb.DCBlength = sizeof(DCB); + dcb.fBinary = TRUE; + dcb.fOutxCtsFlow = FALSE; + dcb.fOutxDsrFlow = FALSE; + dcb.fDtrControl = DTR_CONTROL_DISABLE; + dcb.fDsrSensitivity = FALSE; + dcb.fTXContinueOnXoff= TRUE; + dcb.fOutX = FALSE; + dcb.fInX = FALSE; + dcb.fRtsControl = RTS_CONTROL_DISABLE; + dcb.fAbortOnError = FALSE; + SetCommState(com_handle, &dcb); + } + } +#else { struct termios t; @@ -896,13 +956,18 @@ int openComPort(const char *name) } } +#endif return 0; } void closeComPort(void) { +#ifdef _WIN32 + CloseHandle(com_handle); +#else close(com_handle); +#endif com_handle = COM_HANDLE_INVALID; } @@ -916,10 +981,14 @@ void raiseDTR(void) { if(com_handle == COM_HANDLE_INVALID) return; +#ifdef _WIN32 + EscapeCommFunction(com_handle, SETDTR); +#else { // For C89 happiness int flags = TIOCM_DTR; ioctl(com_handle, TIOCMBIS, &flags); } +#endif } @@ -927,29 +996,42 @@ void raiseRTS(void) { if(com_handle == COM_HANDLE_INVALID) return; +#ifdef _WIN32 + EscapeCommFunction(com_handle, SETRTS); +#else { // For C89 happiness int flags = TIOCM_RTS; ioctl(com_handle, TIOCMBIS, &flags); } +#endif } void lowerDTR(void) { if(com_handle == COM_HANDLE_INVALID) return; + +#ifdef _WIN32 + EscapeCommFunction(com_handle, CLRDTR); +#else { // For C89 happiness int flags = TIOCM_DTR; ioctl(com_handle, TIOCMBIC, &flags); } +#endif } void lowerRTS(void) { if(com_handle == COM_HANDLE_INVALID) return; +#ifdef _WIN32 + EscapeCommFunction(com_handle, CLRRTS); +#else { // For C89 happiness int flags = TIOCM_RTS; ioctl(com_handle, TIOCMBIC, &flags); } +#endif }