[Com0com-cvs] hub4com/plugins/pinmap .cvsignore, NONE, 1.1 filter.cpp, NONE, 1.1 pinmap.vcproj, NON
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2008-08-11 07:26:51
|
Update of /cvsroot/com0com/hub4com/plugins/pinmap In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13043 Added Files: .cvsignore filter.cpp pinmap.vcproj precomp.cpp precomp.h Log Message: Initial revision --- NEW FILE: precomp.cpp --- /* * $Id: precomp.cpp,v 1.1 2008/08/11 07:26:48 vfrolov Exp $ * * Copyright (c) 2007-2008 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /////////////////////////////////////////////////////////////// #include "precomp.h" /////////////////////////////////////////////////////////////// --- NEW FILE: precomp.h --- /* * $Id: precomp.h,v 1.1 2008/08/11 07:26:48 vfrolov Exp $ * * Copyright (c) 2008 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * $Log: precomp.h,v $ * Revision 1.1 2008/08/11 07:26:48 vfrolov * Initial revision * */ #ifndef _PRECOMP_H_ #define _PRECOMP_H_ #include <windows.h> #include <crtdbg.h> #include <map> #include <iostream> using namespace std; #pragma warning(disable:4512) // assignment operator could not be generated #endif /* _PRECOMP_H_ */ --- NEW FILE: pinmap.vcproj --- <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" Version="8,00" Name="filter-pinmap" ProjectGUID="{DC90F370-D011-4C9A-BD59-6BDC9BC161C0}" RootNamespace="hub4com" Keyword="Win32Proj" > <Platforms> <Platform Name="Win32" /> </Platforms> <ToolFiles> </ToolFiles> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="Debug" IntermediateDirectory="Debug" ConfigurationType="2" UseOfMFC="0" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" /> <Tool Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="2" PrecompiledHeaderThrough="precomp.h" PrecompiledHeaderFile="$(IntDir)\precomp.pch" WarningLevel="4" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" OutputFile="..\..\$(OutDir)\plugins\$(ProjectName).dll" LinkIncremental="2" ModuleDefinitionFile="..\plugins.def" GenerateDebugInformation="true" SubSystem="1" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCWebDeploymentTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="Release" IntermediateDirectory="Release" ConfigurationType="2" UseOfMFC="0" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" /> <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" RuntimeLibrary="0" UsePrecompiledHeader="2" PrecompiledHeaderThrough="precomp.h" PrecompiledHeaderFile="$(IntDir)\precomp.pch" WarningLevel="4" Detect64BitPortabilityProblems="true" DebugInformationFormat="3" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" OutputFile="..\..\$(OutDir)\plugins\$(ProjectName).dll" LinkIncremental="2" ModuleDefinitionFile="..\plugins.def" GenerateDebugInformation="true" SubSystem="1" OptimizeReferences="2" EnableCOMDATFolding="2" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCWebDeploymentTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> </Configurations> <References> </References> <Files> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File RelativePath="..\plugins_api.h" > </File> <File RelativePath=".\precomp.h" > </File> </Filter> <Filter Name="Source Files" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File RelativePath=".\filter.cpp" > </File> <File RelativePath="..\plugins.def" > </File> <File RelativePath=".\precomp.cpp" > <FileConfiguration Name="Debug|Win32" > <Tool Name="VCCLCompilerTool" UsePrecompiledHeader="1" /> </FileConfiguration> <FileConfiguration Name="Release|Win32" > <Tool Name="VCCLCompilerTool" UsePrecompiledHeader="1" /> </FileConfiguration> </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: filter.cpp --- /* * $Id: filter.cpp,v 1.1 2008/08/11 07:26:48 vfrolov Exp $ * * Copyright (c) 2008 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * $Log: filter.cpp,v $ * Revision 1.1 2008/08/11 07:26:48 vfrolov * Initial revision * */ #include "precomp.h" #include "../plugins_api.h" /////////////////////////////////////////////////////////////// static ROUTINE_MSG_INSERT_VAL *pMsgInsertVal = NULL; /////////////////////////////////////////////////////////////// const char *GetParam(const char *pArg, const char *pPattern) { size_t lenPattern = strlen(pPattern); if (_strnicmp(pArg, pPattern, lenPattern) != 0) return NULL; return pArg + lenPattern; } /////////////////////////////////////////////////////////////// class Valid { public: Valid() : isValid(TRUE) {} void Invalidate() { isValid = FALSE; } BOOL IsValid() const { return isValid; } private: BOOL isValid; }; /////////////////////////////////////////////////////////////// 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; }; /////////////////////////////////////////////////////////////// class Filter : public Valid { public: Filter(int argc, const char *const argv[]); State *GetState(int nPort); struct PinOuts { PinOuts() : mask(0), val(0) {} WORD mask; WORD val; }; PinOuts pinMap[sizeof(pinIn_names)/sizeof(pinIn_names[0])]; WORD outMask; WORD inMask; private: typedef map<int, State*> PortsMap; typedef pair<int, State*> PortPair; PortsMap portsMap; void Parse(const char *pArg); }; Filter::Filter(int argc, const char *const argv[]) : outMask(0), inMask(0) { for (const char *const *pArgs = &argv[1] ; argc > 1 ; pArgs++, argc--) { const char *pArg = GetParam(*pArgs, "--"); if (!pArg) { cerr << "Unknown option " << *pArgs << endl; Invalidate(); continue; } Parse(pArg); } if (!inMask) { Parse("rts=cts"); Parse("dtr=dsr"); Parse("break=break"); } } void Filter::Parse(const char *pArg) { BOOL foundOut = FALSE; for (int iOut = 0 ; iOut < sizeof(pinOut_names)/sizeof(pinOut_names[0]) ; iOut++) { const char *pParam; if ((pParam = GetParam(pArg, pinOut_names[iOut].pName)) == NULL) continue; foundOut = TRUE; if ((outMask & pinOut_names[iOut].val) != 0) { cerr << "Duplicated option --" << pinOut_names[iOut].pName << endl; Invalidate(); } outMask |= pinOut_names[iOut].val; BOOL negative; if (*pParam == '!') { negative = TRUE; pParam++; } else { negative = FALSE; } BOOL foundIn = FALSE; _ASSERTE(sizeof(pinIn_names)/sizeof(pinIn_names[0]) == sizeof(pinMap)/sizeof(pinMap[0])); for (int iIn = 0 ; iIn < sizeof(pinIn_names)/sizeof(pinIn_names[0]) ; iIn++) { if (_stricmp(pParam, pinIn_names[iIn].pName) == 0) { foundIn = TRUE; inMask |= pinIn_names[iIn].val; pinMap[iIn].mask |= pinOut_names[iOut].val; if (negative) pinMap[iIn].val &= ~pinOut_names[iOut].val; else pinMap[iIn].val |= pinOut_names[iOut].val; break; } } if (!foundIn) { cerr << "Unknown pin " << pParam << endl; Invalidate(); } break; } if (!foundOut) { cerr << "Unknown option " << pArg << endl; Invalidate(); } } State *Filter::GetState(int nPort) { PortsMap::iterator iPair = portsMap.find(nPort); if (iPair == portsMap.end()) { portsMap.insert(PortPair(nPort, NULL)); iPair = portsMap.find(nPort); if (iPair == portsMap.end()) return NULL; } if (!iPair->second) iPair->second = new State(); return iPair->second; } /////////////////////////////////////////////////////////////// static PLUGIN_TYPE CALLBACK GetPluginType() { return PLUGIN_TYPE_FILTER; } /////////////////////////////////////////////////////////////// static const PLUGIN_ABOUT_A about = { sizeof(PLUGIN_ABOUT_A), "pinmap", "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", "Pinouts mapping filter", }; static const PLUGIN_ABOUT_A * CALLBACK GetPluginAbout() { return &about; } /////////////////////////////////////////////////////////////// static void CALLBACK Help(const char *pProgPath) { cerr << "Usage:" << endl << " " << pProgPath << " ... --create-filter=" << GetPluginAbout()->pName << "[,<FID>][:<options>] ... --add-filters=<ports>:[...,]<FID>[,...] ..." << endl << endl << "Wire options:" << endl << " --rts=[!]<s> - wire input state of <s> to output pin RTS." << endl << " --dtr=[!]<s> - wire input state of <s> to output pin DTR." << endl << " --out1=[!]<s> - wire input state of <s> to output pin OUT1." << endl << " --out2=[!]<s> - wire input state of <s> to output pin OUT2." << endl << " --break=[!]<s> - wire input state of <s> to output pin BREAK." << endl << endl << " The possible values of <s> above can be cts, dsr, dcd, ring or break. The" << endl << " exclamation sign (!) can be used to invert the value. If no any wire option" << endl << " specified, then the options --rts=cts --dtr=dsr --break=break are used by" << endl << " default." << endl << endl << "OUT method input data stream description:" << endl << " HUB_MSG_TYPE_GET_OPTIONS(<pOptions>)" << endl << " - the value pointed by <pOptions> will be or'ed with" << endl << " the required mask to get line status and modem" << endl << " status." << endl << " SET_PIN_STATE(<set>) - pin settings controlled by this filter will be" << endl << " discarded from <set>." << endl << " LINE_STATUS(<val>) - current state of line" << endl << " MODEM_STATUS(<val>) - current state of modem" << endl << endl << "OUT method output data stream description:" << endl << " SET_PIN_STATE(<set>) - will be added on appropriate state changing." << endl << endl << "Examples:" << endl << " " << pProgPath << " --create-filter=" << GetPluginAbout()->pName << " --add-filters=0,1:" << GetPluginAbout()->pName << " COM1 COM2" << endl << " - transfer data and signals between COM1 and COM2." << endl << " " << pProgPath << " --echo-route=0 COM2" << endl << " - receive data and signals from COM2 and send it back to COM2." << endl ; } /////////////////////////////////////////////////////////////// static HFILTER CALLBACK Create( HCONFIG /*hConfig*/, int argc, const char *const argv[]) { Filter *pFilter = new Filter(argc, argv); if (!pFilter) return NULL; if (!pFilter->IsValid()) { delete pFilter; return NULL; } return (HFILTER)pFilter; } /////////////////////////////////////////////////////////////// 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; WORD val = 0; for (int iIn = 0 ; iIn < sizeof(pinIn_names)/sizeof(pinIn_names[0]) ; iIn++) { if ((inMask & pinIn_names[iIn].val) == 0) continue; mask |= (DWORD)filter.pinMap[iIn].mask; if ((inVal & pinIn_names[iIn].val) != 0) val |= (filter.pinMap[iIn].val & mask); else val |= (~filter.pinMap[iIn].val & mask); } if (mask) { DWORD dVal = (SPS_PIN2MASK(mask) | val); //cout << "SET_PIN_STATE 0x" << hex << dVal << dec << endl; *ppOutMsg = pMsgInsertVal(*ppOutMsg, HUB_MSG_TYPE_SET_PIN_STATE, dVal); } } static BOOL CALLBACK OutMethod( HFILTER hFilter, int /*nFromPort*/, int nToPort, HUB_MSG *pOutMsg) { _ASSERTE(hFilter != NULL); _ASSERTE(pOutMsg != NULL); 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; } case HUB_MSG_TYPE_SET_PIN_STATE: // discard any pin settings controlled by this filter pOutMsg->u.val &= ~(SPS_PIN2MASK(((Filter *)hFilter)->outMask)); break; case HUB_MSG_TYPE_LINE_STATUS: case HUB_MSG_TYPE_MODEM_STATUS: { State *pState = ((Filter *)hFilter)->GetState(nToPort); if (!pState) 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; } } return pOutMsg != NULL; } /////////////////////////////////////////////////////////////// static const FILTER_ROUTINES_A routines = { sizeof(FILTER_ROUTINES_A), GetPluginType, GetPluginAbout, Help, NULL, // ConfigStart NULL, // Config NULL, // ConfigStop Create, NULL, // Init NULL, // InMethod OutMethod, }; static const PLUGIN_ROUTINES_A *const plugins[] = { (const PLUGIN_ROUTINES_A *)&routines, NULL }; /////////////////////////////////////////////////////////////// PLUGIN_INIT_A InitA; const PLUGIN_ROUTINES_A *const * CALLBACK InitA( const HUB_ROUTINES_A * pHubRoutines) { if (!ROUTINE_IS_VALID(pHubRoutines, pMsgInsertVal)) { return NULL; } pMsgInsertVal = pHubRoutines->pMsgInsertVal; return plugins; } /////////////////////////////////////////////////////////////// --- NEW FILE: .cvsignore --- *.user Release Debug |