Update of /cvsroot/com0com/hub4com/plugins/serial
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29647/plugins/serial
Modified Files:
comio.cpp comio.h comport.cpp comport.h port.cpp
Log Message:
Redesigned serial port options
Index: comport.cpp
===================================================================
RCS file: /cvsroot/com0com/hub4com/plugins/serial/comport.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** comport.cpp 15 Aug 2008 12:44:59 -0000 1.6
--- comport.cpp 20 Aug 2008 14:30:19 -0000 1.7
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.7 2008/08/20 14:30:19 vfrolov
+ * Redesigned serial port options
+ *
* Revision 1.6 2008/08/15 12:44:59 vfrolov
* Added fake read filter method to ports
***************
*** 77,81 ****
countXoff(0),
filterX(FALSE),
- events(0),
maskOutPins(0),
options(0),
--- 80,83 ----
***************
*** 182,236 ****
_ASSERTE(handle != INVALID_HANDLE_VALUE);
! BYTE optsLsr = GO_O2V_LINE_STATUS(options);
! BYTE optsMst = GO_O2V_MODEM_STATUS(options);
! if (optsLsr || optsMst) {
! if ((optsMst & MODEM_STATUS_CTS) != 0)
events |= EV_CTS;
! if ((optsMst & MODEM_STATUS_DSR) != 0)
events |= EV_DSR;
! if ((optsMst & MODEM_STATUS_DCD) != 0)
events |= EV_RLSD;
! if ((optsMst & MODEM_STATUS_RI) != 0)
events |= EV_RING;
! optsMst &= ~(MODEM_STATUS_CTS|MODEM_STATUS_DSR|MODEM_STATUS_DCD|MODEM_STATUS_RI);
! if (optsMst) {
! cout << name << " WARNING: Changing of MODEM STATUS bit(s) 0x"
! << hex << (unsigned)optsMst << dec << " ["
! << FieldToName(codeNameTableModemStatus, optsMst)
! << "] will be ignored" << endl;
! }
! if (optsLsr) {
! cout << name << " WARNING: Changing of LINE STATUS bit(s) 0x"
! << hex << (unsigned)optsLsr << dec << " ["
! << FieldToName(codeNameTableLineStatus, optsLsr)
! << "] will be ignored" << endl;
! }
}
! if (events) {
! if (!SetComEvents(handle, &events))
! return FALSE;
! if (!StartWaitCommEvent())
return FALSE;
cout << name << " Event(s) 0x" << hex << events << dec << " ["
! << FieldToName(codeNameTableComEvents, events)
! << "] will be monitired" << endl;
}
CheckComEvents(DWORD(-1));
! if (!StartRead())
return FALSE;
!
! HUB_MSG msg;
msg.type = HUB_MSG_TYPE_CONNECT;
--- 184,256 ----
_ASSERTE(handle != INVALID_HANDLE_VALUE);
! DWORD events = 0;
! BYTE *pBuf = NULL;
! DWORD done = 0;
! if (options & GO_ESCAPE_MODE) {
! options = SetEscMode(handle, options, 'a'/*0xFF*/, &pBuf, &done);
! } else {
! if ((options & GO_V2O_MODEM_STATUS(MODEM_STATUS_CTS)) != 0)
events |= EV_CTS;
! if ((options & GO_V2O_MODEM_STATUS(MODEM_STATUS_DSR)) != 0)
events |= EV_DSR;
! if ((options & GO_V2O_MODEM_STATUS(MODEM_STATUS_DCD)) != 0)
events |= EV_RLSD;
! if ((options & GO_V2O_MODEM_STATUS(MODEM_STATUS_RI)) != 0)
events |= EV_RING;
! options &= ~GO_V2O_MODEM_STATUS(
! MODEM_STATUS_CTS|MODEM_STATUS_DSR|MODEM_STATUS_DCD|MODEM_STATUS_RI);
! }
! BYTE optsMst = GO_O2V_MODEM_STATUS(options);
! if (optsMst) {
! cerr << name << " WARNING: Changing of MODEM STATUS bit(s) 0x"
! << hex << (unsigned)optsMst << dec << " ["
! << FieldToName(codeNameTableModemStatus, optsMst)
! << "] will be ignored" << endl;
}
! BYTE optsLsr = GO_O2V_LINE_STATUS(options);
! if (optsLsr) {
! cerr << name << " WARNING: Changing of LINE STATUS bit(s) 0x"
! << hex << (unsigned)optsLsr << dec << " ["
! << FieldToName(codeNameTableLineStatus, optsLsr)
! << "] will be ignored" << endl;
! }
!
! HUB_MSG msg;
!
! if (options) {
! cerr << name << " WARNING: Requested option(s) 0x"
! << hex << options << dec << " will be ignored" << endl;
!
! msg.type = HUB_MSG_TYPE_FAIL_IN_OPTS;
! msg.u.val = options;
! pOnRead(hHub, hMasterPort, &msg);
! }
!
! if (events) {
! if (!SetComEvents(handle, &events) || !StartWaitCommEvent()) {
! pBufFree(pBuf);
return FALSE;
+ }
cout << name << " Event(s) 0x" << hex << events << dec << " ["
! << FieldToName(codeNameTableComEvents, events)
! << "] will be monitired" << endl;
}
CheckComEvents(DWORD(-1));
! if (!StartRead()) {
! pBufFree(pBuf);
return FALSE;
! }
msg.type = HUB_MSG_TYPE_CONNECT;
***************
*** 238,241 ****
--- 258,269 ----
pOnRead(hHub, hMasterPort, &msg);
+ if (pBuf) {
+ msg.type = HUB_MSG_TYPE_LINE_DATA;
+ msg.u.buf.pBuf = pBuf;
+ msg.u.buf.size = done;
+
+ pOnRead(hHub, hMasterPort, &msg);
+ }
+
return TRUE;
}
***************
*** 272,284 ****
_ASSERTE(pInMsg != NULL);
! if (pInMsg->type == HUB_MSG_TYPE_GET_OPTIONS) {
! pInMsg->u.pv.val &= ~(GO_V2O_MODEM_STATUS(-1) | GO_V2O_LINE_STATUS(-1));
pInMsg = pMsgInsertNone(pInMsg, HUB_MSG_TYPE_EMPTY);
if (pInMsg) {
! pInMsg->type = HUB_MSG_TYPE_GET_OPTIONS;
pInMsg->u.pv.pVal = &options;
! pInMsg->u.pv.val = GO_V2O_MODEM_STATUS(-1) | GO_V2O_LINE_STATUS(-1);
}
}
--- 300,321 ----
_ASSERTE(pInMsg != NULL);
! if (pInMsg->type == HUB_MSG_TYPE_GET_IN_OPTS) {
! // get supported options from subsequent filters separately
!
! DWORD supported_options = pInMsg->u.pv.val & (
! GO_ESCAPE_MODE |
! GO_RBR_STATUS |
! GO_RLC_STATUS |
! GO_V2O_MODEM_STATUS(-1) |
! GO_V2O_LINE_STATUS(-1));
!
! pInMsg->u.pv.val &= ~supported_options;
pInMsg = pMsgInsertNone(pInMsg, HUB_MSG_TYPE_EMPTY);
if (pInMsg) {
! pInMsg->type = HUB_MSG_TYPE_GET_IN_OPTS;
pInMsg->u.pv.pVal = &options;
! pInMsg->u.pv.val = supported_options;
}
}
***************
*** 396,400 ****
}
else
! if (pMsg->type == HUB_MSG_TYPE_SET_OPTIONS) {
if (handle == INVALID_HANDLE_VALUE)
return FALSE;
--- 433,437 ----
}
else
! if (pMsg->type == HUB_MSG_TYPE_SET_OUT_OPTS) {
if (handle == INVALID_HANDLE_VALUE)
return FALSE;
***************
*** 508,512 ****
CheckComEvents(eMask);
! if (!events || !pOverlapped->StartWaitCommEvent()) {
delete pOverlapped;
countWaitCommEventOverlapped--;
--- 545,549 ----
CheckComEvents(eMask);
! if (!pOverlapped->StartWaitCommEvent()) {
delete pOverlapped;
countWaitCommEventOverlapped--;
Index: comport.h
===================================================================
RCS file: /cvsroot/com0com/hub4com/plugins/serial/comport.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** comport.h 15 Aug 2008 12:44:59 -0000 1.6
--- comport.h 20 Aug 2008 14:30:19 -0000 1.7
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.7 2008/08/20 14:30:19 vfrolov
+ * Redesigned serial port options
+ *
* Revision 1.6 2008/08/15 12:44:59 vfrolov
* Added fake read filter method to ports
***************
*** 103,107 ****
int countXoff;
BOOL filterX;
- DWORD events;
BYTE maskOutPins;
DWORD options;
--- 106,109 ----
Index: comio.h
===================================================================
RCS file: /cvsroot/com0com/hub4com/plugins/serial/comio.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** comio.h 14 Aug 2008 15:19:07 -0000 1.4
--- comio.h 20 Aug 2008 14:30:19 -0000 1.5
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.5 2008/08/20 14:30:19 vfrolov
+ * Redesigned serial port options
+ *
* Revision 1.4 2008/08/14 15:19:07 vfrolov
* Execute OnCommEvent() in main thread context
***************
*** 63,66 ****
--- 66,70 ----
extern BOOL SetComEvents(HANDLE handle, DWORD *events);
extern BOOL CommFunction(HANDLE handle, DWORD func);
+ extern DWORD SetEscMode(HANDLE handle, DWORD options, BYTE escapeChar, BYTE **ppBuf, DWORD *pDone);
///////////////////////////////////////////////////////////////
class ReadOverlapped : private OVERLAPPED
Index: port.cpp
===================================================================
RCS file: /cvsroot/com0com/hub4com/plugins/serial/port.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** port.cpp 15 Aug 2008 12:44:59 -0000 1.6
--- port.cpp 20 Aug 2008 14:30:19 -0000 1.7
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.7 2008/08/20 14:30:19 vfrolov
+ * Redesigned serial port options
+ *
* Revision 1.6 2008/08/15 12:44:59 vfrolov
* Added fake read filter method to ports
***************
*** 105,109 ****
<< endl
<< "Output data stream description:" << endl
! << " SET_OPTIONS(<opts>) - or'e <opts> with the output data stream options." << endl
<< " LINE_DATA(<data>) - write <data> to serial port." << endl
<< " SET_PIN_STATE(<state>) - set serial port pins to required state." << endl
--- 108,112 ----
<< endl
<< "Output data stream description:" << endl
! << " SET_OUT_OPTS(<opts>) - or'e <opts> with the output data stream options." << endl
<< " LINE_DATA(<data>) - write <data> to serial port." << endl
<< " SET_PIN_STATE(<state>) - set serial port pins to required state." << endl
***************
*** 116,127 ****
<< endl
<< "Fake read filter input data stream description:" << endl
! << " GET_OPTIONS(<pOpts>,<mask>)" << endl
<< " - the port removes bits from <mask> in this message" << endl
<< " for locally supported input data stream options." << endl
<< endl
<< "Fake read filter output data stream description:" << endl
! << " GET_OPTIONS(<pOpts>,<mask>)" << endl
<< " - the port adds this message at detecting the" << endl
! << " GET_OPTIONS message in the stream to get the" << endl
<< " required input data stream options." << endl
<< endl
--- 119,130 ----
<< endl
<< "Fake read filter input data stream description:" << endl
! << " GET_IN_OPTS(<pOpts>,<mask>)" << endl
<< " - the port removes bits from <mask> in this message" << endl
<< " for locally supported input data stream options." << endl
<< endl
<< "Fake read filter output data stream description:" << endl
! << " GET_IN_OPTS(<pOpts>,<mask>)" << endl
<< " - the port adds this message at detecting the" << endl
! << " GET_IN_OPTS message in the stream to get the" << endl
<< " required input data stream options." << endl
<< endl
Index: comio.cpp
===================================================================
RCS file: /cvsroot/com0com/hub4com/plugins/serial/comio.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** comio.cpp 14 Aug 2008 15:19:07 -0000 1.4
--- comio.cpp 20 Aug 2008 14:30:19 -0000 1.5
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.5 2008/08/20 14:30:19 vfrolov
+ * Redesigned serial port options
+ *
* Revision 1.4 2008/08/14 15:19:07 vfrolov
* Execute OnCommEvent() in main thread context
***************
*** 62,65 ****
--- 65,69 ----
#include "comparams.h"
#include "import.h"
+ #include "..\cncext.h"
///////////////////////////////////////////////////////////////
***************
*** 269,272 ****
--- 273,392 ----
}
///////////////////////////////////////////////////////////////
+ static ULONG GetEscCaps(HANDLE handle)
+ {
+ BYTE inBufIoctl[sizeof(UCHAR) + C0CE_SIGNATURE_SIZE + sizeof(ULONG)];
+ inBufIoctl[0] = 0; // disable inserting
+ memcpy(inBufIoctl + sizeof(UCHAR), C0CE_SIGNATURE, C0CE_SIGNATURE_SIZE);
+ *(ULONG *)(inBufIoctl + sizeof(UCHAR) + C0CE_SIGNATURE_SIZE) = C0CE_INSERT_IOCTL_CAPS;
+
+ BYTE outBuf[C0CE_SIGNATURE_SIZE + sizeof(ULONG)];
+
+ DWORD returned;
+
+ if (!DeviceIoControl(handle,
+ IOCTL_SERIAL_LSRMST_INSERT,
+ inBufIoctl, sizeof(inBufIoctl),
+ outBuf, sizeof(outBuf), &returned,
+ NULL))
+ {
+ TraceError(GetLastError(), "IOCTL_SERIAL_LSRMST_INSERT");
+ return 0;
+ }
+
+ if (returned < (C0CE_SIGNATURE_SIZE + sizeof(ULONG)) ||
+ memcmp(outBuf, C0CE_SIGNATURE, C0CE_SIGNATURE_SIZE) != 0)
+ {
+ return C0CE_INSERT_ENABLE_LSR|C0CE_INSERT_ENABLE_MST; // standard functionality
+ }
+
+ return *(ULONG *)(outBuf + C0CE_SIGNATURE_SIZE);
+ }
+
+ DWORD SetEscMode(HANDLE handle, DWORD options, BYTE escapeChar, BYTE **ppBuf, DWORD *pDone)
+ {
+ _ASSERTE(ppBuf != NULL);
+ _ASSERTE(*ppBuf == NULL);
+ _ASSERTE(pDone != NULL);
+ _ASSERTE(*pDone == 0);
+
+ if (!escapeChar)
+ return options;
+
+ ULONG opts = (C0CE_INSERT_IOCTL_GET|C0CE_INSERT_IOCTL_RXCLEAR);
+
+ if (options & GO_V2O_MODEM_STATUS(-1))
+ opts |= C0CE_INSERT_ENABLE_MST;
+
+ if (options & GO_V2O_LINE_STATUS(LINE_STATUS_BI))
+ opts |= C0CE_INSERT_ENABLE_LSR_BI;
+
+ if (options & GO_RBR_STATUS)
+ opts |= C0CE_INSERT_ENABLE_RBR;
+
+ if (options & GO_RLC_STATUS)
+ opts |= C0CE_INSERT_ENABLE_RLC;
+
+ opts &= GetEscCaps(handle);
+
+ if (!opts)
+ return options;
+
+ BYTE inBufIoctl[sizeof(UCHAR) + C0CE_SIGNATURE_SIZE + sizeof(ULONG)];
+ inBufIoctl[0] = escapeChar;
+ memcpy(inBufIoctl + sizeof(UCHAR), C0CE_SIGNATURE, C0CE_SIGNATURE_SIZE);
+ *(ULONG *)(inBufIoctl + sizeof(UCHAR) + C0CE_SIGNATURE_SIZE) = opts;
+
+ DWORD lenOutBufIoctl = 0;
+
+ if (opts & C0CE_INSERT_IOCTL_GET) {
+ if (opts & (C0CE_INSERT_ENABLE_LSR|C0CE_INSERT_ENABLE_LSR_BI))
+ lenOutBufIoctl += sizeof(UCHAR)*2 + sizeof(UCHAR);
+
+ if (opts & C0CE_INSERT_ENABLE_MST)
+ lenOutBufIoctl += sizeof(UCHAR)*2 + sizeof(UCHAR);
+
+ if (opts & C0CE_INSERT_ENABLE_RBR)
+ lenOutBufIoctl += sizeof(UCHAR)*2 + sizeof(ULONG);
+
+ if (opts & C0CE_INSERT_ENABLE_RLC)
+ lenOutBufIoctl += sizeof(UCHAR)*2 + sizeof(UCHAR)*3;
+
+ if (lenOutBufIoctl) {
+ *ppBuf = pBufAlloc(lenOutBufIoctl);
+
+ if (!*ppBuf)
+ lenOutBufIoctl = 0;
+ }
+ }
+
+ if (!DeviceIoControl(handle,
+ IOCTL_SERIAL_LSRMST_INSERT,
+ inBufIoctl, sizeof(inBufIoctl),
+ *ppBuf, lenOutBufIoctl, pDone,
+ NULL))
+ {
+ TraceError(GetLastError(), "IOCTL_SERIAL_LSRMST_INSERT");
+
+ *pDone = 0;
+ return options;
+ }
+
+ options &= ~GO_ESCAPE_MODE;
+
+ if (opts & C0CE_INSERT_ENABLE_MST)
+ options &= ~GO_V2O_MODEM_STATUS(-1);
+
+ if (opts & C0CE_INSERT_ENABLE_LSR_BI)
+ options &= ~GO_V2O_LINE_STATUS(LINE_STATUS_BI);
+
+ if (opts & C0CE_INSERT_ENABLE_RBR)
+ options &= ~GO_RBR_STATUS;
+
+ if (opts & C0CE_INSERT_ENABLE_RLC)
+ options &= ~GO_RLC_STATUS;
+
+ return options;
+ }
+ ///////////////////////////////////////////////////////////////
WriteOverlapped::WriteOverlapped(ComPort &_port, BYTE *_pBuf, DWORD _len)
: port(_port),
***************
*** 360,363 ****
--- 480,493 ----
hWait(INVALID_HANDLE_VALUE)
{
+ #ifdef _DEBUG
+ static DWORD idThread;
+
+ if (hThread == INVALID_HANDLE_VALUE) {
+ idThread = ::GetCurrentThreadId();
+ } else {
+ _ASSERTE(idThread == ::GetCurrentThreadId());
+ }
+ #endif /* _DEBUG */
+
if (hThread == INVALID_HANDLE_VALUE) {
if (!::DuplicateHandle(::GetCurrentProcess(),
|