[Com0com-cvs] hub4com/plugins/pinmap filter.cpp,1.3,1.4
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2008-08-20 14:57:16
|
Update of /cvsroot/com0com/hub4com/plugins/pinmap In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29647/plugins/pinmap Modified Files: filter.cpp Log Message: Redesigned serial port options Index: filter.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/pinmap/filter.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** filter.cpp 14 Aug 2008 09:49:45 -0000 1.3 --- filter.cpp 20 Aug 2008 14:30:19 -0000 1.4 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.4 2008/08/20 14:30:19 vfrolov + * Redesigned serial port options + * * Revision 1.3 2008/08/14 09:49:45 vfrolov * Fixed output pins masking *************** *** 36,39 **** --- 39,44 ---- /////////////////////////////////////////////////////////////// static ROUTINE_MSG_INSERT_VAL *pMsgInsertVal = NULL; + static ROUTINE_PORT_NAME_A *pPortName = NULL; + static ROUTINE_FILTER_NAME_A *pFilterName = NULL; /////////////////////////////////////////////////////////////// const char *GetParam(const char *pArg, const char *pPattern) *************** *** 58,86 **** static struct { const char *pName; ! DWORD val; } pinOut_names[] = { ! {"rts=", SO_V2O_PIN_STATE(PIN_STATE_RTS)}, ! {"dtr=", SO_V2O_PIN_STATE(PIN_STATE_DTR)}, ! {"out1=", SO_V2O_PIN_STATE(PIN_STATE_OUT1)}, ! {"out2=", SO_V2O_PIN_STATE(PIN_STATE_OUT2)}, ! {"break=", SO_V2O_PIN_STATE(PIN_STATE_BREAK)}, }; /////////////////////////////////////////////////////////////// static struct { const char *pName; ! DWORD val; } pinIn_names[] = { ! {"cts", GO_V2O_MODEM_STATUS(MODEM_STATUS_CTS)}, ! {"dsr", GO_V2O_MODEM_STATUS(MODEM_STATUS_DSR)}, ! {"dcd", GO_V2O_MODEM_STATUS(MODEM_STATUS_DCD)}, ! {"ring", GO_V2O_MODEM_STATUS(MODEM_STATUS_RI)}, ! {"break", GO_V2O_LINE_STATUS(LINE_STATUS_BI)}, }; /////////////////////////////////////////////////////////////// class State { public: ! State() : inVal(0) {} ! WORD inVal; }; /////////////////////////////////////////////////////////////// --- 63,97 ---- static struct { const char *pName; ! WORD val; } pinOut_names[] = { ! {"rts=", PIN_STATE_RTS}, ! {"dtr=", PIN_STATE_DTR}, ! {"out1=", PIN_STATE_OUT1}, ! {"out2=", PIN_STATE_OUT2}, ! {"break=", PIN_STATE_BREAK}, }; /////////////////////////////////////////////////////////////// + #define MST2LSRMST(m) ((WORD)((BYTE)(m))) + #define LSR2LSRMST(l) ((WORD)(((WORD)(BYTE)(l)) << 8)) + #define LSRMST2MST(lm) ((BYTE)(lm)) + #define LSRMST2LSR(lm) ((BYTE)((lm) >> 8)) + #define LSRMST2GO(lm) (GO_V2O_MODEM_STATUS(LSRMST2MST(lm)) | GO_V2O_LINE_STATUS(LSRMST2LSR(lm))) + static struct { const char *pName; ! WORD lmVal; } pinIn_names[] = { ! {"cts", MST2LSRMST(MODEM_STATUS_CTS)}, ! {"dsr", MST2LSRMST(MODEM_STATUS_DSR)}, ! {"dcd", MST2LSRMST(MODEM_STATUS_DCD)}, ! {"ring", MST2LSRMST(MODEM_STATUS_RI)}, ! {"break", LSR2LSRMST(LINE_STATUS_BI)}, }; /////////////////////////////////////////////////////////////// class State { public: ! State() : lmInVal(0) {} ! WORD lmInVal; }; /////////////////////////////////////////////////////////////// *************** *** 88,92 **** --- 99,106 ---- public: Filter(int argc, const char *const argv[]); + void SetHub(HHUB _hHub) { hHub = _hHub; } State *GetState(int nPort); + const char *PortName(int nPort) const { return pPortName(hHub, nPort); } + const char *FilterName() const { return pFilterName(hHub, (HFILTER)this); } struct PinOuts { *************** *** 99,105 **** PinOuts pinMap[sizeof(pinIn_names)/sizeof(pinIn_names[0])]; WORD outMask; ! WORD inMask; private: typedef map<int, State*> PortsMap; typedef pair<int, State*> PortPair; --- 113,121 ---- PinOuts pinMap[sizeof(pinIn_names)/sizeof(pinIn_names[0])]; WORD outMask; ! WORD lmInMask; private: + HHUB hHub; + typedef map<int, State*> PortsMap; typedef pair<int, State*> PortPair; *************** *** 112,116 **** Filter::Filter(int argc, const char *const argv[]) : outMask(0), ! inMask(0) { for (const char *const *pArgs = &argv[1] ; argc > 1 ; pArgs++, argc--) { --- 128,133 ---- Filter::Filter(int argc, const char *const argv[]) : outMask(0), ! lmInMask(0), ! hHub(NULL) { for (const char *const *pArgs = &argv[1] ; argc > 1 ; pArgs++, argc--) { *************** *** 126,130 **** } ! if (!inMask) { Parse("rts=cts"); Parse("dtr=dsr"); --- 143,147 ---- } ! if (!lmInMask) { Parse("rts=cts"); Parse("dtr=dsr"); *************** *** 168,172 **** if (_stricmp(pParam, pinIn_names[iIn].pName) == 0) { foundIn = TRUE; ! inMask |= pinIn_names[iIn].val; pinMap[iIn].mask |= pinOut_names[iOut].val; --- 185,189 ---- if (_stricmp(pParam, pinIn_names[iIn].pName) == 0) { foundIn = TRUE; ! lmInMask |= pinIn_names[iIn].lmVal; pinMap[iIn].mask |= pinOut_names[iOut].val; *************** *** 251,257 **** << endl << "OUT method input data stream description:" << endl ! << " SET_OPTIONS(<opts>) - the value <opts> will be or'ed with the required mask" << endl << " to to set pin state." << endl ! << " GET_OPTIONS(<pOpts>) - the value pointed by <pOpts> will be or'ed with" << endl << " the required mask to get line status and modem" << endl << " status." << endl --- 268,274 ---- << endl << "OUT method input data stream description:" << endl ! << " SET_OUT_OPTS(<opts>) - the value <opts> will be or'ed with the required mask" << endl << " to to set pin state." << endl ! << " GET_IN_OPTS(<pOpts>) - the value pointed by <pOpts> will be or'ed with" << endl << " the required mask to get line status and modem" << endl << " status." << endl *************** *** 292,305 **** } /////////////////////////////////////////////////////////////// static void InsertPinState( Filter &filter, ! WORD inMask, ! WORD inVal, HUB_MSG **ppOutMsg) { ! if (!inMask) return; ! //cout << "InsertPinState inMask=0x" << hex << inMask << " inVal=0x" << inVal << dec << endl; WORD mask = 0; --- 309,334 ---- } /////////////////////////////////////////////////////////////// + static BOOL CALLBACK Init( + HFILTER hFilter, + HHUB hHub) + { + _ASSERTE(hFilter != NULL); + _ASSERTE(hHub != NULL); + + ((Filter *)hFilter)->SetHub(hHub); + + return TRUE; + } + /////////////////////////////////////////////////////////////// static void InsertPinState( Filter &filter, ! WORD lmInMask, ! WORD lmInVal, HUB_MSG **ppOutMsg) { ! if (!lmInMask) return; ! //cout << "InsertPinState lmInMask=0x" << hex << lmInMask << " lmInVal=0x" << lmInVal << dec << endl; WORD mask = 0; *************** *** 307,316 **** for (int iIn = 0 ; iIn < sizeof(pinIn_names)/sizeof(pinIn_names[0]) ; iIn++) { ! if ((inMask & pinIn_names[iIn].val) == 0) continue; mask |= filter.pinMap[iIn].mask; ! if ((inVal & pinIn_names[iIn].val) != 0) val |= (filter.pinMap[iIn].val & filter.pinMap[iIn].mask); else --- 336,345 ---- for (int iIn = 0 ; iIn < sizeof(pinIn_names)/sizeof(pinIn_names[0]) ; iIn++) { ! if ((lmInMask & pinIn_names[iIn].lmVal) == 0) continue; mask |= filter.pinMap[iIn].mask; ! if ((lmInVal & pinIn_names[iIn].lmVal) != 0) val |= (filter.pinMap[iIn].val & filter.pinMap[iIn].mask); else *************** *** 327,331 **** static BOOL CALLBACK OutMethod( HFILTER hFilter, ! int /*nFromPort*/, int nToPort, HUB_MSG *pOutMsg) --- 356,360 ---- static BOOL CALLBACK OutMethod( HFILTER hFilter, ! int nFromPort, int nToPort, HUB_MSG *pOutMsg) *************** *** 335,349 **** switch (pOutMsg->type) { ! case HUB_MSG_TYPE_SET_OPTIONS: { // or'e with the required mask to set pin state ! pOutMsg->u.val |= ((Filter *)hFilter)->outMask; break; } ! case HUB_MSG_TYPE_GET_OPTIONS: { _ASSERTE(pOutMsg->u.pv.pVal != NULL); // or'e with the required mask to get line status and modem status ! WORD mask = (WORD)(((Filter *)hFilter)->inMask & pOutMsg->u.pv.val); ! *pOutMsg->u.pv.pVal |= mask; break; } --- 364,388 ---- switch (pOutMsg->type) { ! case HUB_MSG_TYPE_SET_OUT_OPTS: { // or'e with the required mask to set pin state ! pOutMsg->u.val |= SO_V2O_PIN_STATE(((Filter *)hFilter)->outMask); break; } ! case HUB_MSG_TYPE_GET_IN_OPTS: { _ASSERTE(pOutMsg->u.pv.pVal != NULL); // or'e with the required mask to get line status and modem status ! *pOutMsg->u.pv.pVal |= (LSRMST2GO(((Filter *)hFilter)->lmInMask) & pOutMsg->u.pv.val); ! break; ! } ! case HUB_MSG_TYPE_FAIL_IN_OPTS: { ! DWORD fail_options = (pOutMsg->u.val & LSRMST2GO(((Filter *)hFilter)->lmInMask)); ! ! if (fail_options) { ! cerr << ((Filter *)hFilter)->PortName(nFromPort) ! << " WARNING: Requested by filter " << ((Filter *)hFilter)->FilterName() ! << " option(s) 0x" << hex << fail_options << dec ! << " not accepted" << endl; ! } break; } *************** *** 359,373 **** return FALSE; ! WORD inVal; if (pOutMsg->type == HUB_MSG_TYPE_MODEM_STATUS) ! inVal = ((WORD)pOutMsg->u.val & 0x00FF) | (pState->inVal & 0xFF00); else ! inVal = ((WORD)pOutMsg->u.val << 8) | (pState->inVal & 0x00FF); ! inVal &= ((Filter *)hFilter)->inMask; ! InsertPinState(*(Filter *)hFilter, pState->inVal ^ inVal, inVal, &pOutMsg); ! pState->inVal = inVal; break; } --- 398,412 ---- return FALSE; ! WORD lmInVal; if (pOutMsg->type == HUB_MSG_TYPE_MODEM_STATUS) ! lmInVal = (MST2LSRMST(pOutMsg->u.val) | (pState->lmInVal & LSR2LSRMST(-1))); else ! lmInVal = (LSR2LSRMST(pOutMsg->u.val) | (pState->lmInVal & MST2LSRMST(-1))); ! lmInVal &= ((Filter *)hFilter)->lmInMask; ! InsertPinState(*(Filter *)hFilter, pState->lmInVal ^ lmInVal, lmInVal, &pOutMsg); ! pState->lmInVal = lmInVal; break; } *************** *** 386,390 **** NULL, // ConfigStop Create, ! NULL, // Init NULL, // InMethod OutMethod, --- 425,429 ---- NULL, // ConfigStop Create, ! Init, NULL, // InMethod OutMethod, *************** *** 400,408 **** const HUB_ROUTINES_A * pHubRoutines) { ! if (!ROUTINE_IS_VALID(pHubRoutines, pMsgInsertVal)) { return NULL; } pMsgInsertVal = pHubRoutines->pMsgInsertVal; return plugins; --- 439,452 ---- const HUB_ROUTINES_A * pHubRoutines) { ! if (!ROUTINE_IS_VALID(pHubRoutines, pMsgInsertVal) || ! !ROUTINE_IS_VALID(pHubRoutines, pPortName) || ! !ROUTINE_IS_VALID(pHubRoutines, pFilterName)) ! { return NULL; } pMsgInsertVal = pHubRoutines->pMsgInsertVal; + pPortName = pHubRoutines->pPortName; + pFilterName = pHubRoutines->pFilterName; return plugins; |