com0com-cvs Mailing List for Null-modem emulator (Page 24)
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
You can subscribe to this list here.
2005 |
Jan
|
Feb
(7) |
Mar
|
Apr
|
May
(13) |
Jun
(18) |
Jul
(9) |
Aug
(10) |
Sep
(15) |
Oct
(6) |
Nov
(9) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(6) |
Feb
(4) |
Mar
(4) |
Apr
(2) |
May
(7) |
Jun
(11) |
Jul
(6) |
Aug
(9) |
Sep
(1) |
Oct
(27) |
Nov
(22) |
Dec
(3) |
2007 |
Jan
(13) |
Feb
(16) |
Mar
(2) |
Apr
(3) |
May
(7) |
Jun
(17) |
Jul
(9) |
Aug
(1) |
Sep
(13) |
Oct
(20) |
Nov
(18) |
Dec
(1) |
2008 |
Jan
|
Feb
(3) |
Mar
(46) |
Apr
(40) |
May
(4) |
Jun
(9) |
Jul
(7) |
Aug
(62) |
Sep
(25) |
Oct
(51) |
Nov
(67) |
Dec
(81) |
2009 |
Jan
(13) |
Feb
(31) |
Mar
(12) |
Apr
|
May
(10) |
Jun
|
Jul
(5) |
Aug
(2) |
Sep
(10) |
Oct
|
Nov
(3) |
Dec
(1) |
2010 |
Jan
|
Feb
(1) |
Mar
(4) |
Apr
|
May
(12) |
Jun
(9) |
Jul
(12) |
Aug
(7) |
Sep
(6) |
Oct
|
Nov
|
Dec
(1) |
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(11) |
Jun
|
Jul
(26) |
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
(23) |
2012 |
Jan
(7) |
Feb
(3) |
Mar
|
Apr
|
May
(2) |
Jun
(9) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Vyacheslav F. <vf...@us...> - 2008-03-28 16:02:25
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv18783 Added Files: .cvsignore Log Message: Initial revision --- NEW FILE: .cvsignore --- *.user Release Debug |
From: Vyacheslav F. <vf...@us...> - 2008-03-28 16:01:18
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv18356 Modified Files: port.cpp Log Message: Fixed Help Index: port.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/tcp/port.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** port.cpp 27 Mar 2008 17:19:18 -0000 1.1 --- port.cpp 28 Mar 2008 16:01:13 -0000 1.2 *************** *** 20,27 **** * * $Log$ * Revision 1.1 2008/03/27 17:19:18 vfrolov * Initial revision * - * */ --- 20,29 ---- * * $Log$ + * Revision 1.2 2008/03/28 16:01:13 vfrolov + * Fixed Help + * * Revision 1.1 2008/03/27 17:19:18 vfrolov * Initial revision * */ *************** *** 43,47 **** "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", ! "TCP port", }; --- 45,49 ---- "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", ! "TCP port driver", }; *************** *** 59,66 **** << " " << pProgPath << " ... [--use-port-module=" << GetPluginAbout()->pName << "] [*]<listen port> ..." << endl << endl ! << " The sign * above means that connection shold be permanent as it possible." << endl << endl << "Options:" << endl << " --interface=<if> - use interface <if>." << endl << "Examples:" << endl << " " << pProgPath << " --use-port-module=" << GetPluginAbout()->pName << " 1111 222.22.22.22:2222" << endl --- 61,86 ---- << " " << pProgPath << " ... [--use-port-module=" << GetPluginAbout()->pName << "] [*]<listen port> ..." << endl << endl ! << " The sign * above means that connection shold be permanent as it's possible." << endl ! << " In client mode it will force connection to remote host on start or on" << endl ! << " disconnect." << endl << endl << "Options:" << endl << " --interface=<if> - use interface <if>." << endl + << endl + << "Output data stream description:" << endl + << " LINE_DATA(<data>) - send <data> to remote host." << endl + << " CONNECT(TRUE) - increment connection counter." << endl + << " CONNECT(FALSE) - decrement connection counter." << endl + << endl + << "In client mode if there is not connection to remote host the incrementing of" << endl + << "the connection counter will force connection to remote host." << endl + << "If sign * is not used and there is connection to remote host the decrementing" << endl + << "of the connection counter to 0 will force disconnection from remote host." << endl + << endl + << "Input data stream description:" << endl + << " LINE_DATA(<data>) - received <data> from remote host." << endl + << " CONNECT(TRUE) - connected to remote host." << endl + << " CONNECT(FALSE) - disconnected." << endl + << endl << "Examples:" << endl << " " << pProgPath << " --use-port-module=" << GetPluginAbout()->pName << " 1111 222.22.22.22:2222" << endl |
From: Vyacheslav F. <vf...@us...> - 2008-03-28 16:00:24
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv17931 Modified Files: comport.h comport.cpp Log Message: Added connectionCounter Index: comport.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/tcp/comport.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comport.cpp 27 Mar 2008 17:18:27 -0000 1.1 --- comport.cpp 28 Mar 2008 16:00:19 -0000 1.2 *************** *** 20,27 **** * * $Log$ * Revision 1.1 2008/03/27 17:18:27 vfrolov * Initial revision * - * */ --- 20,29 ---- * * $Log$ + * Revision 1.2 2008/03/28 16:00:19 vfrolov + * Added connectionCounter + * * Revision 1.1 2008/03/27 17:18:27 vfrolov * Initial revision * */ *************** *** 96,99 **** --- 98,102 ---- hSock(INVALID_SOCKET), isConnected(FALSE), + connectionCounter(0), name("TCP"), hMasterPort(NULL), *************** *** 302,309 **** if (pMsg->type == HUB_MSG_TYPE_CONNECT) { if (pMsg->u.val) { if (!pListener) StartConnect(); } else { ! if (hSock != INVALID_SOCKET && !permanent) { Disconnect(hSock); --- 305,320 ---- if (pMsg->type == HUB_MSG_TYPE_CONNECT) { if (pMsg->u.val) { + connectionCounter++; + + _ASSERTE(connectionCounter > 0); + if (!pListener) StartConnect(); } else { ! _ASSERTE(connectionCounter > 0); ! ! connectionCounter--; ! ! if (hSock != INVALID_SOCKET && !permanent && connectionCounter <= 0) { Disconnect(hSock); Index: comport.h =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/tcp/comport.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comport.h 27 Mar 2008 17:18:27 -0000 1.1 --- comport.h 28 Mar 2008 16:00:19 -0000 1.2 *************** *** 20,27 **** * * $Log$ * Revision 1.1 2008/03/27 17:18:27 vfrolov * Initial revision * - * */ --- 20,29 ---- * * $Log$ + * Revision 1.2 2008/03/28 16:00:19 vfrolov + * Added connectionCounter + * * Revision 1.1 2008/03/27 17:18:27 vfrolov * Initial revision * */ *************** *** 102,105 **** --- 104,108 ---- SOCKET hSock; BOOL isConnected; + int connectionCounter; BOOL permanent; |
From: Vyacheslav F. <vf...@us...> - 2008-03-28 15:55:13
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv15827 Modified Files: port.cpp Log Message: Fixed help Index: port.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/port.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** port.cpp 26 Mar 2008 08:41:18 -0000 1.1 --- port.cpp 28 Mar 2008 15:55:09 -0000 1.2 *************** *** 20,27 **** * * $Log$ * Revision 1.1 2008/03/26 08:41:18 vfrolov * Initial revision * - * */ --- 20,29 ---- * * $Log$ + * Revision 1.2 2008/03/28 15:55:09 vfrolov + * Fixed help + * * Revision 1.1 2008/03/26 08:41:18 vfrolov * Initial revision * */ *************** *** 43,47 **** "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", ! "Serial port", }; --- 45,49 ---- "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", ! "Serial port driver", }; *************** *** 54,58 **** { cerr ! << "COM port options:" << endl << " --baud=<b> - set baud rate to <b> (" << ComParams().BaudRateStr() << " by default)," << endl << " where <b> is " << ComParams::BaudRateLst() << "." << endl --- 56,63 ---- { cerr ! << "Usage:" << endl ! << " " << pProgPath << " ... [--use-port-module=" << GetPluginAbout()->pName << "] <com port> ..." << endl ! << endl ! << "Options:" << endl << " --baud=<b> - set baud rate to <b> (" << ComParams().BaudRateStr() << " by default)," << endl << " where <b> is " << ComParams::BaudRateLst() << "." << endl *************** *** 91,97 **** << " " << ComParams::EventsLst() << "." << endl << endl << "Examples:" << endl << " " << pProgPath << " COM1 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl ! << " " << pProgPath << " --baud=9600 COM1 --baud=19200 \\\\.\\CNCB1" << endl ; } --- 96,116 ---- << " " << ComParams::EventsLst() << "." << endl << endl + << "Output data stream description:" << endl + << " LINE_DATA(<data>) - write <data> to serial port." << endl + << " COM_FUNCTION(<function>) - direct serial port to perform <function>." << endl + << endl + << "Input data stream description:" << endl + << " LINE_DATA(<data>) - readed <data> from serial port." << endl + << " CONNECT(TRUE) - serial port started." << endl + << " MODEM_STATUS(<value>) - modem control register changed to <value>." << endl + << " COM_ERRORS(<mask>) - occured communications errors indicated in <mask>." << endl + << endl << "Examples:" << endl << " " << pProgPath << " COM1 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl ! << " - receive data from COM1 and send it to CNCB1 and CNCB2," << endl ! << " receive data from CNCB1 and send it to COM1." << endl ! << " " << pProgPath << " --baud=9600 COM1 --baud=19200 COM2" << endl ! << " - receive data at speed 9600 from COM1 and send it to COM2 at speed 19200," << endl ! << " receive data at speed 19200 from COM2 and send it to COM1 at speed 9600." << endl ; } |
From: Vyacheslav F. <vf...@us...> - 2008-03-28 15:53:54
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv15076 Modified Files: hub4com.cpp Log Message: Fixed help Index: hub4com.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** hub4com.cpp 26 Mar 2008 08:48:18 -0000 1.8 --- hub4com.cpp 28 Mar 2008 15:53:48 -0000 1.9 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.9 2008/03/28 15:53:48 vfrolov + * Fixed help + * * Revision 1.8 2008/03/26 08:48:18 vfrolov * Initial revision *************** *** 59,63 **** cerr << "Usage:" << endl ! << " " << pProgPath << " [options] \\\\.\\<port0> [options] [\\\\.\\<port1> ...]" << endl << endl << "Common options:" << endl --- 62,66 ---- cerr << "Usage:" << endl ! << " " << pProgPath << " [options] <port0> [options] [<port1> ...]" << endl << endl << "Common options:" << endl *************** *** 118,122 **** << "Examples:" << endl << " " << pProgPath << " --route=All:All \\\\.\\CNCB0 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl ! << " " << pProgPath << " --echo-route=0 \\\\.\\COM2" << endl ; } --- 121,129 ---- << "Examples:" << endl << " " << pProgPath << " --route=All:All \\\\.\\CNCB0 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl ! << " - receive data from CNCB0 and send it to CNCB1 and CNCB2," << endl ! << " receive data from CNCB1 and send it to CNCB0 and CNCB2," << endl ! << " receive data from CNCB2 and send it to CNCB0 and CNCB1." << endl ! << " " << pProgPath << " --echo-route=0 COM2" << endl ! << " - receive data from COM2 and send it back to COM2." << endl ; } |
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:21:10
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv2947 Modified Files: hub4com.sln Log Message: Added project port-tcp Index: hub4com.sln =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.sln,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** hub4com.sln 26 Mar 2008 08:45:53 -0000 1.1 --- hub4com.sln 27 Mar 2008 17:21:03 -0000 1.2 *************** *** 6,9 **** --- 6,11 ---- Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "port-serial", "plugins\serial\serial.vcproj", "{031557BD-5B2D-4B87-B40D-2DD9C43E68BC}" EndProject + Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "port-tcp", "plugins\tcp\tcp.vcproj", "{A1F397C9-2779-49D9-886F-A25D5E41EB0B}" + EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution *************** *** 20,23 **** --- 22,29 ---- {031557BD-5B2D-4B87-B40D-2DD9C43E68BC}.Release|Win32.ActiveCfg = Release|Win32 {031557BD-5B2D-4B87-B40D-2DD9C43E68BC}.Release|Win32.Build.0 = Release|Win32 + {A1F397C9-2779-49D9-886F-A25D5E41EB0B}.Debug|Win32.ActiveCfg = Debug|Win32 + {A1F397C9-2779-49D9-886F-A25D5E41EB0B}.Debug|Win32.Build.0 = Debug|Win32 + {A1F397C9-2779-49D9-886F-A25D5E41EB0B}.Release|Win32.ActiveCfg = Release|Win32 + {A1F397C9-2779-49D9-886F-A25D5E41EB0B}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution |
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:19:21
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv2316 Added Files: import.h port.cpp tcp.vcproj Log Message: Initial revision --- NEW FILE: import.h --- /* * $Id: import.h,v 1.1 2008/03/27 17:19:18 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: import.h,v $ * Revision 1.1 2008/03/27 17:19:18 vfrolov * Initial revision * * */ #ifndef _IMPORT_H #define _IMPORT_H #include "../plugins_api.h" /////////////////////////////////////////////////////////////// extern ROUTINE_BUF_ALLOC *pBufAlloc; extern ROUTINE_BUF_FREE *pBufFree; extern ROUTINE_ON_XOFF *pOnXoff; extern ROUTINE_ON_XON *pOnXon; extern ROUTINE_ON_READ *pOnRead; /////////////////////////////////////////////////////////////// #endif // _IMPORT_H --- NEW FILE: port.cpp --- /* * $Id: port.cpp,v 1.1 2008/03/27 17:19:18 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: port.cpp,v $ * Revision 1.1 2008/03/27 17:19:18 vfrolov * Initial revision * * */ #include "precomp.h" #include "comparams.h" #include "comport.h" #include "import.h" #include "../../utils.h" /////////////////////////////////////////////////////////////// static PLUGIN_TYPE CALLBACK GetPluginType() { return PLUGIN_TYPE_PORT; } /////////////////////////////////////////////////////////////// static const PLUGIN_ABOUT_A about = { sizeof(PLUGIN_ABOUT_A), "tcp", "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", "TCP port", }; static const PLUGIN_ABOUT_A * CALLBACK GetPluginAbout() { return &about; } /////////////////////////////////////////////////////////////// static void CALLBACK Help(const char *pProgPath) { cerr << "Usage (client mode):" << endl << " " << pProgPath << " ... [--use-port-module=" << GetPluginAbout()->pName << "] [*]<host addr>:<host port> ..." << endl << "Usage (server mode):" << endl << " " << pProgPath << " ... [--use-port-module=" << GetPluginAbout()->pName << "] [*]<listen port> ..." << endl << endl << " The sign * above means that connection shold be permanent as it possible." << endl << endl << "Options:" << endl << " --interface=<if> - use interface <if>." << endl << "Examples:" << endl << " " << pProgPath << " --use-port-module=" << GetPluginAbout()->pName << " 1111 222.22.22.22:2222" << endl << " - listen TCP port 1111 and on incoming connection connect to" << endl << " 222.22.22.22:2222, receive data from 1111 and send it to" << endl << " 222.22.22.22:2222, receive data from 222.22.22.22:2222 and send it to" << endl << " 1111, on disconnecting any connection disconnect paired connection." << endl << " " << pProgPath << " --use-port-module=" << GetPluginAbout()->pName << " *111.11.11.11:1111 *222.22.22.22:2222" << endl << " - connect to 111.11.11.11:1111 and connect to 222.22.22.22:2222," << endl << " receive data from 111.11.11.11:1111 and send it to 222.22.22.22:2222," << endl << " receive data from 222.22.22.22:2222 and send it to 111.11.11.11:1111," << endl << " on disconnecting any connection reconnect it." << endl << " " << pProgPath << " --route=All:All --use-port-module=" << GetPluginAbout()->pName << " *1111 *1111 *1111" << endl << " - up to 3 clients can connect to port 2222 and talk each others." << endl ; } /////////////////////////////////////////////////////////////// static HCONFIG CALLBACK ConfigStart() { ComParams *pComParams = new ComParams; if (!pComParams) { cerr << "No enough memory." << endl; exit(2); } return (HCONFIG)pComParams; } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Config( HCONFIG hConfig, const char *pArg) { _ASSERTE(hConfig != NULL); ComParams &comParams = *(ComParams *)hConfig; const char *pParam; if ((pParam = GetParam(pArg, "--interface=")) != NULL) { comParams.SetIF(pParam); } else { return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// static void CALLBACK ConfigStop( HCONFIG hConfig) { _ASSERTE(hConfig != NULL); delete (ComParams *)hConfig; } /////////////////////////////////////////////////////////////// static vector<Listener *> *pListeners = NULL; static HPORT CALLBACK Create( HCONFIG hConfig, const char *pPath) { _ASSERTE(hConfig != NULL); if (!pListeners) pListeners = new vector<Listener *>; if (!pListeners) return NULL; ComPort *pPort = new ComPort(*pListeners, *(const ComParams *)hConfig, pPath); if (!pPort) return NULL; return (HPORT)pPort; } /////////////////////////////////////////////////////////////// static const char *CALLBACK GetPortName( HPORT hPort) { _ASSERTE(hPort != NULL); return ((ComPort *)hPort)->Name().c_str(); } /////////////////////////////////////////////////////////////// static void CALLBACK SetPortName( HPORT hPort, const char *pName) { _ASSERTE(hPort != NULL); _ASSERTE(pName != NULL); ((ComPort *)hPort)->Name(pName); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Init( HPORT hPort, HMASTERPORT hMasterPort, HHUB hHub) { _ASSERTE(hPort != NULL); _ASSERTE(hMasterPort != NULL); _ASSERTE(hHub != NULL); return ((ComPort *)hPort)->Init(hMasterPort, hHub); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Start(HPORT hPort) { _ASSERTE(hPort != NULL); return ((ComPort *)hPort)->Start(); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Write( HPORT hPort, HUB_MSG *pMsg) { _ASSERTE(hPort != NULL); _ASSERTE(pMsg != NULL); return ((ComPort *)hPort)->Write(pMsg); } /////////////////////////////////////////////////////////////// static void CALLBACK AddXoff( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->AddXoff(1); } /////////////////////////////////////////////////////////////// static void CALLBACK AddXon( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->AddXoff(-1); } /////////////////////////////////////////////////////////////// static void CALLBACK LostReport( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->LostReport(); } /////////////////////////////////////////////////////////////// static const PORT_ROUTINES_A routines = { sizeof(PORT_ROUTINES_A), GetPluginType, GetPluginAbout, Help, ConfigStart, Config, ConfigStop, Create, GetPortName, SetPortName, Init, Start, Write, AddXoff, AddXon, LostReport, }; static const PLUGIN_ROUTINES_A *const plugins[] = { (const PLUGIN_ROUTINES_A *)&routines, NULL }; /////////////////////////////////////////////////////////////// ROUTINE_BUF_ALLOC *pBufAlloc; ROUTINE_BUF_FREE *pBufFree; ROUTINE_ON_XOFF *pOnXoff; ROUTINE_ON_XON *pOnXon; ROUTINE_ON_READ *pOnRead; /////////////////////////////////////////////////////////////// PLUGIN_INIT_A InitA; const PLUGIN_ROUTINES_A *const * CALLBACK InitA( const HUB_ROUTINES_A * pHubRoutines) { if (!ROUTINE_IS_VALID(pHubRoutines, pBufAlloc) || !ROUTINE_IS_VALID(pHubRoutines, pBufFree) || !ROUTINE_IS_VALID(pHubRoutines, pOnXoff) || !ROUTINE_IS_VALID(pHubRoutines, pOnXon) || !ROUTINE_IS_VALID(pHubRoutines, pOnRead)) { return NULL; } pBufAlloc = pHubRoutines->pBufAlloc; pBufFree = pHubRoutines->pBufFree; pOnXoff = pHubRoutines->pOnXoff; pOnXon = pHubRoutines->pOnXon; pOnRead = pHubRoutines->pOnRead; WSADATA wsaData; WSAStartup(MAKEWORD(1, 1), &wsaData); return plugins; } /////////////////////////////////////////////////////////////// --- NEW FILE: tcp.vcproj --- <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" Version="8,00" Name="port-tcp" ProjectGUID="{A1F397C9-2779-49D9-886F-A25D5E41EB0B}" 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" AdditionalDependencies="ws2_32.lib" 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" AdditionalDependencies="ws2_32.lib" 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=".\comio.h" > </File> <File RelativePath=".\comparams.h" > </File> <File RelativePath=".\comport.h" > </File> <File RelativePath=".\import.h" > </File> <File RelativePath="..\plugins_api.h" > </File> <File RelativePath=".\precomp.h" > </File> <File RelativePath="..\..\utils.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=".\comio.cpp" > </File> <File RelativePath=".\comparams.cpp" > </File> <File RelativePath=".\comport.cpp" > </File> <File RelativePath="..\plugins.def" > </File> <File RelativePath=".\port.cpp" > </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> <File RelativePath="..\..\utils.cpp" > </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> |
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:18:55
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1939 Added Files: precomp.cpp precomp.h Log Message: Initial revision --- NEW FILE: precomp.cpp --- /* * $Id: precomp.cpp,v 1.1 2008/03/27 17:18:51 vfrolov Exp $ * * Copyright (c) 2007 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.cpp,v $ * Revision 1.1 2008/03/27 17:18:51 vfrolov * Initial revision * * Revision 1.1 2007/03/26 08:00:50 vfrolov * Initial revision * * */ /////////////////////////////////////////////////////////////// #include "precomp.h" /////////////////////////////////////////////////////////////// --- NEW FILE: precomp.h --- /* * $Id: precomp.h,v 1.1 2008/03/27 17:18:52 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/03/27 17:18:52 vfrolov * Initial revision * * */ #ifndef _PRECOMP_H_ #define _PRECOMP_H_ #define _WIN32_WINNT 0x0500 #include <winsock2.h> #include <windows.h> #include <crtdbg.h> #include <string> #include <vector> #include <queue> #include <iostream> #include <fstream> #include <sstream> using namespace std; #pragma warning(disable:4512) // assignment operator could not be generated #endif /* _PRECOMP_H_ */ |
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:18:30
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1905 Added Files: comport.cpp comport.h Log Message: Initial revision --- NEW FILE: comport.cpp --- /* * $Id: comport.cpp,v 1.1 2008/03/27 17:18:27 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: comport.cpp,v $ * Revision 1.1 2008/03/27 17:18:27 vfrolov * Initial revision * * */ #include "precomp.h" #include "comport.h" #include "comio.h" #include "comparams.h" #include "import.h" /////////////////////////////////////////////////////////////// Listener::Listener(const struct sockaddr_in &_snLocal) : snLocal(_snLocal), hSockListen(INVALID_SOCKET) { } BOOL Listener::Start() { if (hSockListen != INVALID_SOCKET) return TRUE; hSockListen = Socket(snLocal); if (hSockListen == INVALID_SOCKET) return FALSE; ListenOverlapped *pOverlapped; pOverlapped = new ListenOverlapped(*this, hSockListen); if (!pOverlapped) return FALSE; if (!pOverlapped->StartWaitEvent()) { delete pOverlapped; return FALSE; } if (!Listen(hSockListen)) return FALSE; return TRUE; } BOOL Listener::OnEvent(ListenOverlapped * /*pOverlapped*/, long e, int /*err*/) { //cout << "OnEvent " << hex << e << dec << " " << err << endl; if (e == FD_ACCEPT) { if (!empty()) { ComPort *pPort = front(); _ASSERTE(pPort != NULL); pop(); pPort->Accept(); } } return TRUE; } SOCKET Listener::Accept() { return ::Accept(hSockListen); } /////////////////////////////////////////////////////////////// ComPort::ComPort( vector<Listener *> &listeners, const ComParams &comParams, const char *pPath) : pListener(NULL), hSock(INVALID_SOCKET), isConnected(FALSE), name("TCP"), hMasterPort(NULL), hHub(NULL), countReadOverlapped(0), countXoff(0), writeQueueLimit(256), writeQueued(0), writeLost(0), writeLostTotal(0) { string path; if (*pPath == '*') { path = pPath + 1; permanent = TRUE; } else { path = pPath; permanent = FALSE; } string::size_type iDelim = path.find(':'); if (iDelim != path.npos) { string addrName = path.substr(0, iDelim); string portName = path.substr(iDelim + 1); isValid = SetAddr(snLocal, comParams.GetIF(), NULL) && SetAddr(snRemote, addrName.c_str(), portName.c_str()); } else { isValid = SetAddr(snLocal, comParams.GetIF(), path.c_str()); if (isValid) { for (vector<Listener *>::iterator i = listeners.begin() ; i != listeners.end() ; i++) { if ((*i)->IsEqual(snLocal)) { pListener = *i; break; } } if (!pListener) { pListener = new Listener(snLocal); if (pListener) listeners.push_back(pListener); } if (pListener) pListener->push(this); else isValid = FALSE; } } } BOOL ComPort::Init(HMASTERPORT _hMasterPort, HHUB _hHub) { hMasterPort = _hMasterPort; hHub = _hHub; return isValid; } BOOL ComPort::Start() { _ASSERTE(hMasterPort != NULL); _ASSERTE(hHub != NULL); if (pListener) { return pListener->Start(); } else { if (permanent) StartConnect(); } return TRUE; } BOOL ComPort::StartRead() { if (countReadOverlapped) return TRUE; if (hSock == INVALID_SOCKET) return FALSE; ReadOverlapped *pOverlapped; pOverlapped = new ReadOverlapped(*this); if (!pOverlapped) return FALSE; if (!pOverlapped->StartRead()) { delete pOverlapped; return FALSE; } countReadOverlapped++; //cout << "Started Read " << name << " " << countReadOverlapped << endl; return TRUE; } void ComPort::StartConnect() { _ASSERTE(!pListener); if (hSock != INVALID_SOCKET) return; hSock = Socket(snLocal); if (hSock == INVALID_SOCKET) return; if (!StartWaitEvent(hSock) || !Connect(hSock, snRemote)) hSock = INVALID_SOCKET; } void ComPort::Accept() { _ASSERTE(pListener); if (hSock != INVALID_SOCKET) return; hSock = pListener->Accept(); if (hSock != INVALID_SOCKET) { if (StartWaitEvent(hSock)) OnConnect(); else hSock = INVALID_SOCKET; } if (hSock == INVALID_SOCKET) pListener->push(this); } BOOL ComPort::Write(HUB_MSG *pMsg) { _ASSERTE(pMsg != NULL); if (pMsg->type == HUB_MSG_TYPE_LINE_DATA) { BYTE *pBuf = pMsg->u.buf.pBuf; DWORD len = pMsg->u.buf.size; if (!len) return TRUE; if (!pBuf) { writeLost += len; return FALSE; } if (hSock == INVALID_SOCKET) { writeLost += len; return FALSE; } if (isConnected) { WriteOverlapped *pOverlapped; pOverlapped = new WriteOverlapped(*this, pBuf, len); if (!pOverlapped) { writeLost += len; return FALSE; } pMsg->type = HUB_MSG_TYPE_EMPTY; //if (writeQueued > writeQueueLimit) { //} if (!pOverlapped->StartWrite()) { writeLost += len; delete pOverlapped; return FALSE; } } else { if (writeQueued > writeQueueLimit) { for (Bufs::const_iterator i = bufs.begin() ; i != bufs.end() ; i++) { pBufFree(i->pBuf); writeLost += i->len; } bufs.clear(); } bufs.push_back(Buf(pBuf, len)); pMsg->type = HUB_MSG_TYPE_EMPTY; } if (writeQueued <= writeQueueLimit/2 && (writeQueued + len) > writeQueueLimit/2) pOnXoff(hHub, hMasterPort); writeQueued += len; //cout << "Started Write " << name << " " << len << " " << writeQueued << endl; } else if (pMsg->type == HUB_MSG_TYPE_CONNECT) { if (pMsg->u.val) { if (!pListener) StartConnect(); } else { if (hSock != INVALID_SOCKET && !permanent) { Disconnect(hSock); isConnected = FALSE; hSock = INVALID_SOCKET; HUB_MSG msg; msg.type = HUB_MSG_TYPE_CONNECT; msg.u.val = FALSE; pOnRead(hHub, hMasterPort, &msg); } } } return TRUE; } BOOL ComPort::StartWaitEvent(SOCKET hSockWait) { if (hSockWait == INVALID_SOCKET) return FALSE; WaitEventOverlapped *pOverlapped; pOverlapped = new WaitEventOverlapped(*this, hSockWait); if (!pOverlapped) return FALSE; if (!pOverlapped->StartWaitEvent()) { delete pOverlapped; return FALSE; } //cout << "Started WaitEvent " << name << endl; return TRUE; } void ComPort::OnWrite(WriteOverlapped *pOverlapped, DWORD len, DWORD done) { delete pOverlapped; if (len > done) writeLost += len - done; if (writeQueued > writeQueueLimit/2 && (writeQueued - len) <= writeQueueLimit/2) pOnXon(hHub, hMasterPort); writeQueued -= len; } void ComPort::OnRead(ReadOverlapped *pOverlapped, BYTE *pBuf, DWORD done) { HUB_MSG msg; msg.type = HUB_MSG_TYPE_LINE_DATA; msg.u.buf.pBuf = pBuf; msg.u.buf.size = done; pOnRead(hHub, hMasterPort, &msg); if (countXoff > 0 || !isConnected || !pOverlapped->StartRead()) { delete pOverlapped; countReadOverlapped--; //cout << "Stopped Read " << name << " " << countReadOverlapped << endl; } } BOOL ComPort::OnEvent(WaitEventOverlapped *pOverlapped, long e, int err) { //cout << "OnEvent " << name << " " << hex << e << dec << " " << err << endl; if (e == FD_CLOSE || (e == FD_CONNECT && err != ERROR_SUCCESS)) { if (hSock == pOverlapped->Sock()) { isConnected = FALSE; hSock = INVALID_SOCKET; HUB_MSG msg; msg.type = HUB_MSG_TYPE_CONNECT; msg.u.val = FALSE; pOnRead(hHub, hMasterPort, &msg); if (pListener) Accept(); else if (permanent) StartConnect(); } delete pOverlapped; return FALSE; } else if (e == FD_CONNECT) { if (hSock == pOverlapped->Sock()) { OnConnect(); } else { delete pOverlapped; return FALSE; } } return TRUE; } void ComPort::OnConnect() { isConnected = TRUE; if (countXoff <= 0) StartRead(); for (Bufs::const_iterator i = bufs.begin() ; i != bufs.end() ; i++) { WriteOverlapped *pWriteOverlapped; pWriteOverlapped = new WriteOverlapped(*this, i->pBuf, i->len); if (!pWriteOverlapped) { pBufFree(i->pBuf); writeLost += i->len; continue; } if (!pWriteOverlapped->StartWrite()) { writeLost += i->len; delete pWriteOverlapped; continue; } } bufs.clear(); HUB_MSG msg; msg.type = HUB_MSG_TYPE_CONNECT; msg.u.val = TRUE; pOnRead(hHub, hMasterPort, &msg); } void ComPort::AddXoff(int count) { countXoff += count; if (countXoff <= 0 && isConnected) StartRead(); } void ComPort::LostReport() { if (writeLost) { writeLostTotal += writeLost; cout << "Write lost " << name << ": " << writeLost << ", total " << writeLostTotal << endl; writeLost = 0; } } /////////////////////////////////////////////////////////////// --- NEW FILE: comport.h --- /* * $Id: comport.h,v 1.1 2008/03/27 17:18:27 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: comport.h,v $ * Revision 1.1 2008/03/27 17:18:27 vfrolov * Initial revision * * */ #ifndef _COMPORT_H #define _COMPORT_H #include "../plugins_api.h" /////////////////////////////////////////////////////////////// class ComParams; class WriteOverlapped; class ReadOverlapped; class WaitEventOverlapped; class ListenOverlapped; class ComPort; /////////////////////////////////////////////////////////////// class Listener : public queue<ComPort *> { public: Listener(const struct sockaddr_in &_snLocal); BOOL IsEqual(const struct sockaddr_in &_snLocal) { return memcmp(&snLocal, &_snLocal, sizeof(snLocal)) == 0; } BOOL Start(); BOOL OnEvent(ListenOverlapped *pOverlapped, long e, int err); SOCKET Accept(); private: struct sockaddr_in snLocal; SOCKET hSockListen; }; /////////////////////////////////////////////////////////////// struct Buf { Buf(BYTE *_pBuf, DWORD _len) : pBuf(_pBuf), len(_len) {} BYTE *pBuf; DWORD len; }; typedef vector<Buf> Bufs; /////////////////////////////////////////////////////////////// class ComPort { public: ComPort( vector<Listener *> &listeners, const ComParams &comParams, const char *pPath); BOOL Init(HMASTERPORT _hMasterPort, HHUB _hHub); BOOL Start(); BOOL Write(HUB_MSG *pMsg); void OnWrite(WriteOverlapped *pOverlapped, DWORD len, DWORD done); void OnRead(ReadOverlapped *pOverlapped, BYTE *pBuf, DWORD done); BOOL OnEvent(WaitEventOverlapped *pOverlapped, long e, int err); void AddXoff(int count); void LostReport(); void Accept(); const string &Name() const { return name; } void Name(const char *pName) { name = pName; } HANDLE Handle() const { return (HANDLE)hSock; } private: void StartConnect(); BOOL StartRead(); BOOL StartWaitEvent(SOCKET hSockWait); void OnConnect(); struct sockaddr_in snLocal; struct sockaddr_in snRemote; Listener *pListener; BOOL isValid; SOCKET hSock; BOOL isConnected; BOOL permanent; string name; HMASTERPORT hMasterPort; HHUB hHub; int countReadOverlapped; int countXoff; DWORD writeQueueLimit; DWORD writeQueued; DWORD writeLost; DWORD writeLostTotal; Bufs bufs; }; /////////////////////////////////////////////////////////////// #endif // _COMPORT_H |
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:18:02
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1512 Added Files: comparams.cpp comparams.h Log Message: Initial revision --- NEW FILE: comparams.cpp --- /* * $Id: comparams.cpp,v 1.1 2008/03/27 17:17:56 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: comparams.cpp,v $ * Revision 1.1 2008/03/27 17:17:56 vfrolov * Initial revision * * */ #include "precomp.h" #include "comparams.h" /////////////////////////////////////////////////////////////// ComParams::ComParams() : pIF(NULL) { } /////////////////////////////////////////////////////////////// ComParams::~ComParams() { SetIF(NULL); } /////////////////////////////////////////////////////////////// void ComParams::SetIF(const char *_pIF) { if (pIF) free(pIF); if (_pIF) pIF = _strdup(_pIF); else pIF = NULL; } /////////////////////////////////////////////////////////////// --- NEW FILE: comparams.h --- /* * $Id: comparams.h,v 1.1 2008/03/27 17:17:56 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: comparams.h,v $ * Revision 1.1 2008/03/27 17:17:56 vfrolov * Initial revision * * */ #ifndef _COMPARAMS_H #define _COMPARAMS_H /////////////////////////////////////////////////////////////// class ComParams { public: ComParams(); ~ComParams(); void SetIF(const char *_pIF); const char *GetIF() const { return pIF; } private: char *pIF; }; /////////////////////////////////////////////////////////////// #endif // _COMPARAMS_H |
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:17:34
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1476 Added Files: comio.cpp comio.h Log Message: Initial revision --- NEW FILE: comio.h --- /* * $Id: comio.h,v 1.1 2008/03/27 17:17:27 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: comio.h,v $ * Revision 1.1 2008/03/27 17:17:27 vfrolov * Initial revision * * */ #ifndef _COMIO_H #define _COMIO_H /////////////////////////////////////////////////////////////// class ComPort; class Listener; /////////////////////////////////////////////////////////////// extern BOOL SetAddr(struct sockaddr_in &sn, const char *pAddr, const char *pPort); extern SOCKET Socket(const struct sockaddr_in &sn); extern BOOL Connect(SOCKET hSock, const struct sockaddr_in &snRemote); extern BOOL Listen(SOCKET hSock); extern SOCKET Accept(SOCKET hSockListen); extern void Disconnect(SOCKET hSock); /////////////////////////////////////////////////////////////// class ReadOverlapped : private OVERLAPPED { public: ReadOverlapped(ComPort &_port); ~ReadOverlapped(); BOOL StartRead(); private: static VOID CALLBACK OnRead( DWORD err, DWORD done, LPOVERLAPPED pOverlapped); ComPort &port; BYTE *pBuf; }; /////////////////////////////////////////////////////////////// class WriteOverlapped : private OVERLAPPED { public: WriteOverlapped(ComPort &_port, BYTE *_pBuf, DWORD _len); ~WriteOverlapped(); BOOL StartWrite(); private: static VOID CALLBACK OnWrite( DWORD err, DWORD done, LPOVERLAPPED pOverlapped); ComPort &port; BYTE *pBuf; DWORD len; }; /////////////////////////////////////////////////////////////// class WaitEventOverlapped { public: WaitEventOverlapped(ComPort &_port, SOCKET hSockWait); ~WaitEventOverlapped(); BOOL StartWaitEvent(); SOCKET Sock() { return hSock; } private: static VOID CALLBACK OnEvent( PVOID pParameter, BOOLEAN timerOrWaitFired); ComPort &port; SOCKET hSock; HANDLE hWait; HANDLE hEvent; }; /////////////////////////////////////////////////////////////// class ListenOverlapped { public: ListenOverlapped(Listener &_listener, SOCKET hSockWait); ~ListenOverlapped(); BOOL StartWaitEvent(); SOCKET Sock() { return hSock; } private: static VOID CALLBACK OnEvent( PVOID pParameter, BOOLEAN timerOrWaitFired); Listener &listener; SOCKET hSock; HANDLE hWait; HANDLE hEvent; }; /////////////////////////////////////////////////////////////// #endif // _COMIO_H --- NEW FILE: comio.cpp --- /* * $Id: comio.cpp,v 1.1 2008/03/27 17:17:27 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: comio.cpp,v $ * Revision 1.1 2008/03/27 17:17:27 vfrolov * Initial revision * * */ #include "precomp.h" #include "comio.h" #include "comport.h" #include "import.h" /////////////////////////////////////////////////////////////// static void TraceError(DWORD err, const char *pFmt, ...) { va_list va; va_start(va, pFmt); vfprintf(stderr, pFmt, va); va_end(va); fprintf(stderr, " ERROR %s (%lu)\n", strerror(err), (unsigned long)err); } /////////////////////////////////////////////////////////////// BOOL SetAddr(struct sockaddr_in &sn, const char *pAddr, const char *pPort) { memset(&sn, 0, sizeof(sn)); sn.sin_family = AF_INET; if (pPort) { struct servent *pServEnt; pServEnt = getservbyname(pPort, "tcp"); sn.sin_port = pServEnt ? pServEnt->s_port : htons((u_short)atoi(pPort)); } sn.sin_addr.s_addr = pAddr ? inet_addr(pAddr) : INADDR_ANY; if (sn.sin_addr.s_addr == INADDR_NONE) { const struct hostent *pHostEnt = gethostbyname(pAddr); if (!pHostEnt) { TraceError(GetLastError(), "SetAddr(): gethostbyname(\"%s\")", pAddr); return FALSE; } memcpy(&sn.sin_addr, pHostEnt->h_addr, pHostEnt->h_length); } return TRUE; } /////////////////////////////////////////////////////////////// SOCKET Socket(const struct sockaddr_in &sn) { SOCKET hSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (hSock == INVALID_SOCKET) { TraceError(GetLastError(), "Socket(): socket()"); return INVALID_SOCKET; } if (bind(hSock, (struct sockaddr *)&sn, sizeof(sn)) == SOCKET_ERROR) { TraceError(GetLastError(), "Socket(): bind()"); closesocket(hSock); return INVALID_SOCKET; } u_long addr = ntohl(sn.sin_addr.s_addr); u_short port = ntohs(sn.sin_port); cout << "Socket(" << ((addr >> 24) & 0xFF) << '.' << ((addr >> 16) & 0xFF) << '.' << ((addr >> 8) & 0xFF) << '.' << ( addr & 0xFF) << ':' << port << ") = " << hex << hSock << dec << endl; return hSock; } /////////////////////////////////////////////////////////////// BOOL Connect(SOCKET hSock, const struct sockaddr_in &snRemote) { if (connect(hSock, (struct sockaddr *)&snRemote, sizeof(snRemote)) == SOCKET_ERROR) { DWORD err = GetLastError(); if (err != WSAEWOULDBLOCK) { TraceError(err, "Connect(%x): connect()", hSock); closesocket(hSock); return FALSE; } } u_long addr = ntohl(snRemote.sin_addr.s_addr); u_short port = ntohs(snRemote.sin_port); cout << "Connect(" << hex << hSock << dec << ", " << ((addr >> 24) & 0xFF) << '.' << ((addr >> 16) & 0xFF) << '.' << ((addr >> 8) & 0xFF) << '.' << ( addr & 0xFF) << ':' << port << ") ..." << endl; return TRUE; } /////////////////////////////////////////////////////////////// BOOL Listen(SOCKET hSock) { if (listen(hSock, SOMAXCONN) == SOCKET_ERROR) { TraceError(GetLastError(), "Listen(%x): listen()", hSock); closesocket(hSock); return FALSE; } cout << "Listen(" << hex << hSock << dec << ") - OK" << endl; return TRUE; } /////////////////////////////////////////////////////////////// SOCKET Accept(SOCKET hSockListen) { struct sockaddr_in sn; int snlen = sizeof(sn); SOCKET hSock = accept(hSockListen, (struct sockaddr *)&sn, &snlen); if (hSock == INVALID_SOCKET) { DWORD err = GetLastError(); if (err != WSAEWOULDBLOCK) TraceError(err, "Accept(%x): accept()", hSockListen); return INVALID_SOCKET; } u_long addr = ntohl(sn.sin_addr.s_addr); u_short port = ntohs(sn.sin_port); cout << "Accept(" << hex << hSockListen << dec << ") = " << hex << hSock << dec << " from " << ((addr >> 24) & 0xFF) << '.' << ((addr >> 16) & 0xFF) << '.' << ((addr >> 8) & 0xFF) << '.' << ( addr & 0xFF) << ':' << port << endl; return hSock; } /////////////////////////////////////////////////////////////// void Disconnect(SOCKET hSock) { if (shutdown(hSock, SD_BOTH) != 0) TraceError(GetLastError(), "Disconnect(%x): shutdown()", hSock); else cout << "Disconnect(" << hex << hSock << dec << ") - OK" << endl; } /////////////////////////////////////////////////////////////// WriteOverlapped::WriteOverlapped(ComPort &_port, BYTE *_pBuf, DWORD _len) : port(_port), pBuf(_pBuf), len(_len) { } WriteOverlapped::~WriteOverlapped() { pBufFree(pBuf); } VOID CALLBACK WriteOverlapped::OnWrite( DWORD err, DWORD done, LPOVERLAPPED pOverlapped) { WriteOverlapped *pOver = (WriteOverlapped *)pOverlapped; if (err != ERROR_SUCCESS && err != ERROR_OPERATION_ABORTED) TraceError(err, "WriteOverlapped::OnWrite: %s", pOver->port.Name().c_str()); pOver->port.OnWrite(pOver, pOver->len, done); } BOOL WriteOverlapped::StartWrite() { ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); if (!pBuf) return FALSE; if (!::WriteFileEx(port.Handle(), pBuf, len, this, OnWrite)) { TraceError(GetLastError(), "WriteOverlapped::StartWrite(): WriteFileEx(%x) %s", port.Handle(), port.Name().c_str()); return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// ReadOverlapped::ReadOverlapped(ComPort &_port) : port(_port), pBuf(NULL) { } ReadOverlapped::~ReadOverlapped() { pBufFree(pBuf); } VOID CALLBACK ReadOverlapped::OnRead( DWORD err, DWORD done, LPOVERLAPPED pOverlapped) { ReadOverlapped *pOver = (ReadOverlapped *)pOverlapped; if (err != ERROR_SUCCESS) { TraceError(err, "ReadOverlapped::OnRead(): %s", pOver->port.Name().c_str()); done = 0; } BYTE *pInBuf = pOver->pBuf; pOver->pBuf = NULL; pOver->port.OnRead(pOver, pInBuf, done); } BOOL ReadOverlapped::StartRead() { ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); #define readBufSize 64 pBuf = pBufAlloc(readBufSize); if (!pBuf) return FALSE; if (!::ReadFileEx(port.Handle(), pBuf, readBufSize, this, OnRead)) { TraceError(GetLastError(), "ReadOverlapped::StartRead(): ReadFileEx(%x) %s", port.Handle(), port.Name().c_str()); return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// WaitEventOverlapped::WaitEventOverlapped(ComPort &_port, SOCKET hSockWait) : port(_port), hSock(hSockWait), hWait(INVALID_HANDLE_VALUE) { hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL); if (!hEvent) { TraceError( GetLastError(), "WaitEventOverlapped::WaitEventOverlapped(): CreateEvent() %s", port.Name().c_str()); return; } if (!::RegisterWaitForSingleObject(&hWait, hEvent, OnEvent, this, INFINITE, WT_EXECUTEINIOTHREAD)) { TraceError( GetLastError(), "WaitEventOverlapped::StartWaitEvent(): RegisterWaitForSingleObject() %s", port.Name().c_str()); hWait = INVALID_HANDLE_VALUE; return; } } WaitEventOverlapped::~WaitEventOverlapped() { if (hSock != INVALID_SOCKET) { if (closesocket(hSock) != 0) { TraceError( GetLastError(), "WaitEventOverlapped::~WaitEventOverlapped(): closesocket(%x) %s", hSock, port.Name().c_str()); } else cout << "Close(" << hex << hSock << dec << ") - OK" << endl; } if (hWait != INVALID_HANDLE_VALUE) { if (!::UnregisterWait(hWait)) { DWORD err = GetLastError(); if (err != ERROR_IO_PENDING) { TraceError( err, "WaitEventOverlapped::~WaitEventOverlapped(): UnregisterWait() %s", port.Name().c_str()); } } } if (hEvent) { if (!::WSACloseEvent(hEvent)) { TraceError( GetLastError(), "WaitEventOverlapped::~WaitEventOverlapped(): CloseHandle(hEvent) %s", port.Name().c_str()); } } } VOID CALLBACK WaitEventOverlapped::OnEvent( PVOID pOverlapped, BOOLEAN /*timerOrWaitFired*/) { WaitEventOverlapped *pOver = (WaitEventOverlapped *)pOverlapped; WSANETWORKEVENTS events; if (::WSAEnumNetworkEvents(pOver->hSock, NULL, &events) != 0) { TraceError( GetLastError(), "WaitEventOverlapped::OnEvent: WSAEnumNetworkEvents() %s", pOver->port.Name().c_str()); } if ((events.lNetworkEvents & FD_CONNECT) != 0) { if (events.iErrorCode[FD_CONNECT_BIT] != ERROR_SUCCESS) { TraceError( events.iErrorCode[FD_CONNECT_BIT], "Connect(%lx) %s", (long)pOver->hSock, pOver->port.Name().c_str()); } if (!pOver->port.OnEvent(pOver, FD_CONNECT, events.iErrorCode[FD_CONNECT_BIT])) return; } if ((events.lNetworkEvents & FD_CLOSE) != 0) { if (!pOver->port.OnEvent(pOver, FD_CLOSE, events.iErrorCode[FD_CLOSE_BIT])) return; } } BOOL WaitEventOverlapped::StartWaitEvent() { if (!hEvent || hSock == INVALID_SOCKET || hWait == INVALID_HANDLE_VALUE) return FALSE; if (::WSAEventSelect(hSock, hEvent, FD_ACCEPT|FD_CONNECT|FD_CLOSE) != 0) { TraceError( ::GetLastError(), "WaitEventOverlapped::StartWaitEvent(): WSAEventSelect() %s", port.Name().c_str()); return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// ListenOverlapped::ListenOverlapped(Listener &_listener, SOCKET hSockWait) : listener(_listener), hSock(hSockWait), hWait(INVALID_HANDLE_VALUE) { hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL); if (!hEvent) { TraceError( GetLastError(), "ListenOverlapped::ListenOverlapped(): CreateEvent() %s"); return; } if (!::RegisterWaitForSingleObject(&hWait, hEvent, OnEvent, this, INFINITE, WT_EXECUTEINIOTHREAD)) { TraceError( GetLastError(), "ListenOverlapped::StartWaitEvent(): RegisterWaitForSingleObject() %s"); hWait = INVALID_HANDLE_VALUE; return; } } ListenOverlapped::~ListenOverlapped() { if (hSock != INVALID_SOCKET) { if (closesocket(hSock) != 0) { TraceError( GetLastError(), "ListenOverlapped::~ListenOverlapped(): closesocket(%x) %s", hSock); } else cout << "Close(" << hex << hSock << dec << ") - OK" << endl; } if (hWait != INVALID_HANDLE_VALUE) { if (!::UnregisterWait(hWait)) { DWORD err = GetLastError(); if (err != ERROR_IO_PENDING) { TraceError( err, "ListenOverlapped::~ListenOverlapped(): UnregisterWait() %s"); } } } if (hEvent) { if (!::WSACloseEvent(hEvent)) { TraceError( GetLastError(), "ListenOverlapped::~ListenOverlapped(): CloseHandle(hEvent) %s"); } } } VOID CALLBACK ListenOverlapped::OnEvent( PVOID pOverlapped, BOOLEAN /*timerOrWaitFired*/) { ListenOverlapped *pOver = (ListenOverlapped *)pOverlapped; WSANETWORKEVENTS events; if (::WSAEnumNetworkEvents(pOver->hSock, NULL, &events) != 0) { TraceError( GetLastError(), "ListenOverlapped::OnEvent: WSAEnumNetworkEvents() %s"); } if ((events.lNetworkEvents & FD_ACCEPT) != 0) { if (!pOver->listener.OnEvent(pOver, FD_ACCEPT, events.iErrorCode[FD_ACCEPT_BIT])) return; } } BOOL ListenOverlapped::StartWaitEvent() { if (!hEvent || hSock == INVALID_SOCKET || hWait == INVALID_HANDLE_VALUE) return FALSE; if (::WSAEventSelect(hSock, hEvent, FD_ACCEPT) != 0) { TraceError( ::GetLastError(), "ListenOverlapped::StartWaitEvent(): WSAEventSelect() %s"); return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// |
From: Vyacheslav F. <vf...@us...> - 2008-03-27 17:16:25
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1065/tcp Log Message: Directory /cvsroot/com0com/hub4com/plugins/tcp added to the repository |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:50:38
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13437 Removed Files: comio.cpp comio.h comparams.cpp comport.cpp comparams.h comport.h Log Message: Redesigned for using plugins --- comport.cpp DELETED --- --- comparams.cpp DELETED --- --- comio.h DELETED --- --- comparams.h DELETED --- --- comport.h DELETED --- --- comio.cpp DELETED --- |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:48:24
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv12655 Modified Files: comhub.cpp comhub.h hub4com.cpp hub4com.vcproj Log Message: Initial revision Index: hub4com.vcproj =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.vcproj,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** hub4com.vcproj 26 Mar 2007 08:03:49 -0000 1.2 --- hub4com.vcproj 26 Mar 2008 08:48:18 -0000 1.3 *************** *** 179,195 **** > <File RelativePath=".\comhub.h" > </File> <File ! RelativePath=".\comio.h" > </File> <File ! RelativePath=".\comparams.h" > </File> <File ! RelativePath=".\comport.h" > </File> --- 179,211 ---- > <File + RelativePath=".\bufutils.h" + > + </File> + <File RelativePath=".\comhub.h" > </File> <File ! RelativePath=".\export.h" > </File> <File ! RelativePath=".\filters.h" > </File> <File ! RelativePath=".\hubmsg.h" ! > ! </File> ! <File ! RelativePath=".\plugins.h" ! > ! </File> ! <File ! RelativePath=".\plugins\plugins_api.h" ! > ! </File> ! <File ! RelativePath=".\port.h" > </File> *************** *** 199,202 **** --- 215,222 ---- </File> <File + RelativePath=".\route.h" + > + </File> + <File RelativePath=".\utils.h" > *************** *** 227,243 **** </File> <File ! RelativePath=".\comio.cpp" > </File> <File ! RelativePath=".\comparams.cpp" > </File> <File ! RelativePath=".\comport.cpp" > </File> <File ! RelativePath=".\hub4com.cpp" > </File> --- 247,271 ---- </File> <File ! RelativePath=".\export.cpp" > </File> <File ! RelativePath=".\filters.cpp" > </File> <File ! RelativePath=".\hub4com.cpp" > </File> <File ! RelativePath=".\hubmsg.cpp" ! > ! </File> ! <File ! RelativePath=".\plugins.cpp" ! > ! </File> ! <File ! RelativePath=".\port.cpp" > </File> *************** *** 263,266 **** --- 291,298 ---- </File> <File + RelativePath=".\route.cpp" + > + </File> + <File RelativePath=".\utils.cpp" > Index: hub4com.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** hub4com.cpp 4 Feb 2008 10:08:49 -0000 1.7 --- hub4com.cpp 26 Mar 2008 08:48:18 -0000 1.8 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.8 2008/03/26 08:48:18 vfrolov + * Initial revision + * * Revision 1.7 2008/02/04 10:08:49 vfrolov * Fixed <LstR>:<LstL> parsing bug *************** *** 45,122 **** #include "precomp.h" - #include "comparams.h" #include "comhub.h" #include "utils.h" /////////////////////////////////////////////////////////////// ! static void Usage(const char *pProgName) { cerr << "Usage:" << endl ! << " " << pProgName << " [options] \\\\.\\<port0> [options] [\\\\.\\<port1> ...]" << endl << endl << "Common options:" << endl << " --help - show this help." << endl << endl ! << "COM port options:" << endl ! << " --baud=<b> - set baud rate to <b> (" << ComParams().BaudRateStr() << " by default)," << endl ! << " where <b> is " << ComParams::BaudRateLst() << "." << endl ! << " --data=<d> - set data bits to <d> (" << ComParams().ByteSizeStr() << " by default)," << endl ! << " where <d> is " << ComParams::ByteSizeLst() << "." << endl ! << " --parity=<p> - set parity to <p> (" << ComParams().ParityStr() << " by default)," << endl ! << " where <p> is" << endl ! << " " << ComParams::ParityLst() << "." << endl ! << " --stop=<s> - set stop bits to <s> (" << ComParams().StopBitsStr() << " by default)," << endl ! << " where <s> is " << ComParams::StopBitsLst() << "." << endl ! << " --octs=<c> - set CTS handshaking on output to <c>" << endl ! << " (" << ComParams().OutCtsStr() << " by default), where <c> is" << endl ! << " " << ComParams::OutCtsLst() << "." << endl ! << " --odsr=<c> - set DSR handshaking on output to <c>" << endl ! << " (" << ComParams().OutDsrStr() << " by default), where <c> is" << endl ! << " " << ComParams::OutDsrLst() << "." << endl ! << " --ox=<c> - set XON/XOFF handshaking on output to <c>" << endl ! << " (" << ComParams().OutXStr() << " by default), where <c> is" << endl ! << " " << ComParams::OutXLst() << "." << endl ! << " --ix=<c> - set XON/XOFF handshaking on input to <c>" << endl ! << " (" << ComParams().InXStr() << " by default), where <c> is" << endl ! << " " << ComParams::InXLst() << "." << endl ! << " If XON/XOFF handshaking on input is enabled for" << endl ! << " the port then XON/XOFF characters will be" << endl ! << " discarded from output to this port." << endl ! << " --idsr=<c> - set DSR sensitivity on input to <c>" << endl ! << " (" << ComParams().InDsrStr() << " by default), where <c> is" << endl ! << " " << ComParams::InDsrLst() << "." << endl ! << " --ito=<t> - set read interval timeout to <t> (" << ComParams().IntervalTimeoutStr() << " by default)," << endl ! << " where <t> is " << ComParams::IntervalTimeoutLst() << "." << endl ! << endl ! << " The value c[urrent] above means to use current COM port settings." << endl << endl << "Route options:" << endl ! << " --route=<LstR>:<LstL> - send data received from any port from <LstR> to" << endl ! << " all ports (except this port) from <LstL>." << endl ! << " --bi-route=<LstR>:<LstL> - send data received from any port from <LstR> to" << endl ! << " all ports (except this port) from <LstL> and vice" << endl ! << " versa." << endl ! << " --echo-route=<Lst> - send data received from any port from <Lst> back" << endl ! << " to this port." << endl ! << " --no-route=<LstR>:<LstL> - do not send data received from any port from" << endl ! << " <LstR> to ports from <LstL>." << endl << endl - << " The syntax of <LstR>, <LstL> and <Lst> above: <P1>[,<P2>...]" << endl - << " The <Pn> above is a zero based position number of port or All." << endl << " If no any route option specified, then the options --route=0:All --route=1:0" << endl << " used by default (route data from first port to all ports and from second" << endl << " port to first port)." << endl << endl << "Examples:" << endl ! << " " << pProgName << " \\\\.\\COM1 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl ! << " " << pProgName << " --route=All:All \\\\.\\CNCB0 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl ! << " " << pProgName << " --baud=9600 \\\\.\\COM1 --baud=19200 \\\\.\\CNCB1" << endl ! << " " << pProgName << " --echo-route=0 \\\\.\\COM2" << endl ; - exit(1); } /////////////////////////////////////////////////////////////// ! static BOOL EchoRoute(ComHub &hub, const char *pList) { char *pTmpList = _strdup(pList); --- 48,132 ---- #include "precomp.h" #include "comhub.h" + #include "filters.h" #include "utils.h" + #include "plugins.h" + #include "route.h" /////////////////////////////////////////////////////////////// ! static void Usage(const char *pProgPath, Plugins &plugins) { cerr << "Usage:" << endl ! << " " << pProgPath << " [options] \\\\.\\<port0> [options] [\\\\.\\<port1> ...]" << endl << endl << "Common options:" << endl + << " --load=<file>[:<prms>] - load arguments from a file (one argument per line)" << endl + << " and insert them to the command line. The syntax of" << endl + << " <prms> is <PRM1>[,<PRM2>...], where <PRMn> will" << endl + << " replace %%n%%." << endl << " --help - show this help." << endl + << " --help=* - show help for all modules." << endl + << " --help=<LstM> - show help for modules listed in <LstM>." << endl << endl ! << " The syntax of <LstM> above is <MID0>[,<MID1>...], where <MIDn> is a module" << endl ! << " name." << endl << endl << "Route options:" << endl ! << " --route=<LstR>:<LstL> - send data received from any port listed in <LstR>" << endl ! << " to all ports (except itself) listed in <LstL>." << endl ! << " --bi-route=<LstR>:<LstL> - send data received from any port listed in <LstR>" << endl ! << " to all ports (except itself) listed in <LstL> and" << endl ! << " vice versa." << endl ! << " --echo-route=<Lst> - send data received from any port listed in <Lst>" << endl ! << " back to itself via all attached filters." << endl ! << " --no-route=<LstR>:<LstL> - do not send data received from any port listed in" << endl ! << " <LstR> to the ports listed in <LstL>." << endl << endl << " If no any route option specified, then the options --route=0:All --route=1:0" << endl << " used by default (route data from first port to all ports and from second" << endl << " port to first port)." << endl << endl + << "Filter options:" << endl + << " --create-filter=<MID>[,<FID>][:<Args>]" << endl + << " - by using module with type 'filter' and with name" << endl + << " <MID> create a filter with name <FID> (<FID> is" << endl + << " <MID> by default) and put arguments <Args> (if" << endl + << " any) to the filter." << endl + << " --add-filters=<Lst>:<LstF>" << endl + << " - attach the filters listed in <LstF> to the ports" << endl + << " listed in <Lst>. These filters will handle the" << endl + << " data by IN method just after receiving from ports" << endl + << " listed in <Lst> or by OUT method just before" << endl + << " sending to ports listed in <Lst>." << endl + << endl + << " The syntax of <LstF> above is <FID0>[.<Method>][,<FID1>[.<Method>]...], where" << endl + << " <FIDn> is a filter name and <Method> is IN or OUT. The <FID> w/o <Method> is" << endl + << " equivalent to <FID>.IN,<FID>.OUT" << endl + << endl + << "Port options:" << endl + << " --use-port-module=<MID> - use module with type 'port' and with name <MID> to" << endl + << " create the following ports (<MID> is serial by" << endl + << " default)." << endl + << endl + << "The syntax of <LstR>, <LstL> and <Lst> above is <P1>[,<P2>...], where <Pn> is a" << endl + << "zero based position number of port or All." << endl + ; + plugins.List(cerr); + cerr + << endl << "Examples:" << endl ! << " " << pProgPath << " --route=All:All \\\\.\\CNCB0 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl ! << " " << pProgPath << " --echo-route=0 \\\\.\\COM2" << endl ; } /////////////////////////////////////////////////////////////// ! static BOOL EnumPortList( ! ComHub &hub, ! const char *pList, ! BOOL (*pFunc)(ComHub &hub, int iPort, PVOID p0, PVOID p1, PVOID p2), ! PVOID p0 = NULL, ! PVOID p1 = NULL, ! PVOID p2 = NULL) { char *pTmpList = _strdup(pList); *************** *** 134,144 **** if (_stricmp(p, "All") == 0) { ! i = -1; ! } else if (!StrToInt(p, &i) || i < 0 || i >= hub.NumPorts()) { res = FALSE; - break; } - - hub.RouteData(i, i, FALSE, FALSE); } --- 144,157 ---- if (_stricmp(p, "All") == 0) { ! for (i = 0 ; i < hub.NumPorts() ; i++) { ! if (!pFunc(hub, i, p0, p1, p2)) ! res = FALSE; ! } ! } else if (StrToInt(p, &i) && i >= 0 && i < hub.NumPorts()) { ! if (!pFunc(hub, i, p0, p1, p2)) ! res = FALSE; ! } else { res = FALSE; } } *************** *** 148,204 **** } /////////////////////////////////////////////////////////////// ! static BOOL Route(ComHub &hub, const char *pListFrom, const char *pListTo, BOOL noRoute) { ! char *pTmpListFrom = _strdup(pListFrom); ! if (!pTmpListFrom) { cerr << "No enough memory." << endl; exit(2); } ! BOOL res = TRUE; ! char *pSave1; ! for (char *pFrom = STRTOK_R(pTmpListFrom, ",", &pSave1) ; pFrom ; pFrom = STRTOK_R(NULL, ",", &pSave1)) { ! int iFrom; ! if (_stricmp(pFrom, "All") == 0) { ! iFrom = -1; ! } else if (!StrToInt(pFrom, &iFrom) || iFrom < 0 || iFrom >= hub.NumPorts()) { ! res = FALSE; ! break; ! } ! char *pTmpListTo = _strdup(pListTo); ! if (!pTmpListTo) { ! cerr << "No enough memory." << endl; ! exit(2); ! } ! char *pSave2; ! for (char *pTo = STRTOK_R(pTmpListTo, ",", &pSave2) ; pTo ; pTo = STRTOK_R(NULL, ",", &pSave2)) { ! int iTo; ! if (_stricmp(pTo, "All") == 0) { ! iTo = -1; ! } else if (!StrToInt(pTo, &iTo) || iTo < 0 || iTo >= hub.NumPorts()) { ! res = FALSE; ! break; ! } ! hub.RouteData(iFrom, iTo, noRoute, TRUE); ! } ! free(pTmpListTo); } ! free(pTmpListFrom); ! return res; } /////////////////////////////////////////////////////////////// ! static void Route(ComHub &hub, const char *pParam, BOOL biDirection, BOOL noRoute) { char *pTmp = _strdup(pParam); --- 161,322 ---- } /////////////////////////////////////////////////////////////// ! static BOOL EchoRoute(ComHub &/*hub*/, int iPort, PVOID pMap, PVOID /*p1*/, PVOID /*p2*/) { ! AddRoute(*(PortNumMap *)pMap, iPort, iPort, FALSE, FALSE); ! return TRUE; ! } ! static void EchoRoute(ComHub &hub, const char *pList, PortNumMap &map) ! { ! if (!EnumPortList(hub, pList, EchoRoute, &map)) { ! cerr << "Invalid echo route " << pList << endl; ! exit(1); ! } ! } ! /////////////////////////////////////////////////////////////// ! static BOOL Route(ComHub &/*hub*/, int iTo, PVOID pIFrom, PVOID pNoRoute, PVOID pMap) ! { ! AddRoute(*(PortNumMap *)pMap, *(int *)pIFrom, iTo, *(BOOL *)pNoRoute, TRUE); ! return TRUE; ! } ! ! static BOOL RouteList(ComHub &hub, int iFrom, PVOID pListTo, PVOID pNoRoute, PVOID pMap) ! { ! return EnumPortList(hub, (const char *)pListTo, Route, &iFrom, pNoRoute, pMap); ! } ! ! static BOOL Route( ! ComHub &hub, ! const char *pListFrom, ! const char *pListTo, ! BOOL noRoute, ! PortNumMap &map) ! { ! return EnumPortList(hub, pListFrom, RouteList, (PVOID)pListTo, &noRoute, &map); ! } ! /////////////////////////////////////////////////////////////// ! static void Route( ! ComHub &hub, ! const char *pParam, ! BOOL biDirection, ! BOOL noRoute, ! PortNumMap &map) ! { ! char *pTmp = _strdup(pParam); ! ! if (!pTmp) { cerr << "No enough memory." << endl; exit(2); } ! char *pSave; ! const char *pListR = STRTOK_R(pTmp, ":", &pSave); ! const char *pListL = STRTOK_R(NULL, ":", &pSave); ! if (!pListR || !pListL || ! !Route(hub, pListR, pListL, noRoute, map) || ! (biDirection && !Route(hub, pListL, pListR, noRoute, map))) ! { ! cerr << "Invalid route " << pParam << endl; ! exit(1); ! } ! free(pTmp); ! } ! /////////////////////////////////////////////////////////////// ! static void CreateFilter( ! const Plugins &plugins, ! Filters &filter, ! const char *pParam) ! { ! char *pTmp = _strdup(pParam); ! if (!pTmp) { ! cerr << "No enough memory." << endl; ! exit(2); ! } ! char *pSave; ! char *pPlugin = STRTOK_R(pTmp, ":", &pSave); ! char *pArgs = STRTOK_R(NULL, "", &pSave); ! if (!pPlugin || !*pPlugin) { ! cerr << "No module name." << endl; ! exit(1); ! } ! const char *pPluginName = STRTOK_R(pPlugin, ",", &pSave); ! if (!pPluginName || !*pPluginName) { ! cerr << "No module name." << endl; ! exit(1); ! } ! HCONFIG hConfig; ! ! const FILTER_ROUTINES_A *pFltRoutines = ! (const FILTER_ROUTINES_A *)plugins.GetRoutines(PLUGIN_TYPE_FILTER, pPluginName, &hConfig); ! ! if (!pFltRoutines) { ! cerr << "No filter module " << pPluginName << endl; ! exit(1); } ! const char *pFilterName = STRTOK_R(NULL, "", &pSave); ! if (!pFilterName || !*pFilterName) ! pFilterName = pPluginName; ! ! if (!filter.CreateFilter(pFltRoutines, pFilterName, hConfig, pArgs)) { ! cerr << "Invalid filter " << pParam << endl; ! exit(1); ! } ! ! free(pTmp); } /////////////////////////////////////////////////////////////// ! static BOOL AddFilters(ComHub &/*hub*/, int iPort, PVOID pFilters, PVOID pListFlt, PVOID /*p2*/) ! { ! char *pTmpList = _strdup((const char *)pListFlt); ! ! if (!pTmpList) { ! cerr << "No enough memory." << endl; ! exit(2); ! } ! ! char *pSave; ! ! for (char *pFilter = STRTOK_R(pTmpList, ",", &pSave) ; ! pFilter ; ! pFilter = STRTOK_R(NULL, ",", &pSave)) ! { ! string filter(pFilter); ! string::size_type dot = filter.rfind('.'); ! string method(dot != filter.npos ? filter.substr(dot) : ""); ! ! if (method == ".IN") { ! if (!((Filters *)pFilters)->AddFilter(iPort, filter.substr(0, dot).c_str(), TRUE)) ! exit(1); ! } ! else ! if (method == ".OUT") { ! if (!((Filters *)pFilters)->AddFilter(iPort, filter.substr(0, dot).c_str(), FALSE)) ! exit(1); ! } ! else { ! if (!((Filters *)pFilters)->AddFilter(iPort, filter.c_str(), TRUE)) ! exit(1); ! if (!((Filters *)pFilters)->AddFilter(iPort, filter.c_str(), FALSE)) ! exit(1); ! } ! } ! ! free(pTmpList); ! ! return TRUE; ! } ! ! static void AddFilters(ComHub &hub, Filters &filters, const char *pParam) { char *pTmp = _strdup(pParam); *************** *** 210,221 **** char *pSave; ! const char *pListR = STRTOK_R(pTmp, ":", &pSave); ! const char *pListL = STRTOK_R(NULL, ":", &pSave); ! if (!pListR || !pListL || ! !Route(hub, pListR, pListL, noRoute) || ! (biDirection && !Route(hub, pListL, pListR, noRoute))) ! { ! cerr << "Invalid route " << pParam << endl; exit(1); } --- 328,341 ---- char *pSave; ! const char *pList = STRTOK_R(pTmp, ":", &pSave); ! const char *pListFlt = STRTOK_R(NULL, "", &pSave); ! if (!pList || !*pList || !pListFlt || !*pListFlt) { ! cerr << "Invalid filter parameters " << pParam << endl; ! exit(1); ! } ! ! if (!EnumPortList(hub, pList, AddFilters, &filters, (PVOID)pListFlt)) { ! cerr << "Can't add filters " << pListFlt << " to ports " << pList << endl; exit(1); } *************** *** 224,238 **** } /////////////////////////////////////////////////////////////// ! int main(int argc, char* argv[]) { ! int i; ! ! ComHub hub; ! for (i = 1 ; i < argc ; i++) { ! if (!GetParam(argv[i], "--")) { ! if (!hub.Add(argv[i])) ! return 1; ! } } --- 344,354 ---- } /////////////////////////////////////////////////////////////// ! static void Init(ComHub &hub, int argc, const char *const argv[]) { ! Args args(argc - 1, argv + 1); ! for (vector<string>::const_iterator i = args.begin() ; i != args.end() ; i++) { ! if (!GetParam(i->c_str(), "--")) ! hub.Add(); } *************** *** 240,252 **** BOOL defaultRouteFlowControl = TRUE; int plugged = 0; ! char **pArgs; ! ComParams comParams; ! for (pArgs = &argv[1] ; argc > 1 ; pArgs++, argc--) { ! const char *pArg = GetParam(*pArgs, "--"); if (!pArg) { ! if (!hub.PlugIn(plugged++, *pArgs, comParams)) exit(1); --- 356,389 ---- BOOL defaultRouteFlowControl = TRUE; int plugged = 0; + Plugins *pPlugins = new Plugins(); ! if (!pPlugins) { ! cerr << "No enough memory." << endl; ! exit(2); ! } ! Filters *pFilters = NULL; ! ! PortNumMap routeDataMap; ! PortNumMap routeFlowControlMap; ! ! const char *pUsePortModule = "serial"; ! ! for (vector<string>::const_iterator i = args.begin() ; i != args.end() ; i++) { ! BOOL ok = pPlugins->Config(i->c_str()); ! const char *pArg = GetParam(i->c_str(), "--"); if (!pArg) { ! HCONFIG hConfig; ! ! const PORT_ROUTINES_A *pPortRoutines = ! (const PORT_ROUTINES_A *)pPlugins->GetRoutines(PLUGIN_TYPE_PORT, pUsePortModule, &hConfig); ! ! if (!pPortRoutines) { ! cerr << "No port module " << pUsePortModule << endl; ! exit(1); ! } ! ! if (!hub.CreatePort(pPortRoutines, plugged++, hConfig, i->c_str())) exit(1); *************** *** 257,360 **** if ((pParam = GetParam(pArg, "help")) != NULL && *pParam == 0) { ! Usage(argv[0]); ! } else ! if ((pParam = GetParam(pArg, "baud=")) != NULL) { ! if (!comParams.SetBaudRate(pParam)) { ! cerr << "Unknown baud rate value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "data=")) != NULL) { ! if (!comParams.SetByteSize(pParam)) { ! cerr << "Unknown data bits value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "parity=")) != NULL) { ! if (!comParams.SetParity(pParam)) { ! cerr << "Unknown parity value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "stop=")) != NULL) { ! if (!comParams.SetStopBits(pParam)) { ! cerr << "Unknown stop bits value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "octs=")) != NULL) { ! if (!comParams.SetOutCts(pParam)) { ! cerr << "Unknown CTS handshaking on output value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "odsr=")) != NULL) { ! if (!comParams.SetOutDsr(pParam)) { ! cerr << "Unknown DSR handshaking on output value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "ox=")) != NULL) { ! if (!comParams.SetOutX(pParam)) { ! cerr << "Unknown XON/XOFF handshaking on output value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "ix=")) != NULL) { ! if (!comParams.SetInX(pParam)) { ! cerr << "Unknown XON/XOFF handshaking on input value " << pParam << endl; ! exit(1); ! } ! } else ! if ((pParam = GetParam(pArg, "idsr=")) != NULL) { ! if (!comParams.SetInDsr(pParam)) { ! cerr << "Unknown DSR sensitivity value " << pParam << endl; ! exit(1); ! } } else ! if ((pParam = GetParam(pArg, "ito=")) != NULL) { ! if (!comParams.SetIntervalTimeout(pParam)) { ! cerr << "Unknown read interval timeout value " << pParam << endl; ! exit(1); } } else if ((pParam = GetParam(pArg, "route=")) != NULL) { defaultRouteData = FALSE; ! Route(hub, pParam, FALSE, FALSE); } else if ((pParam = GetParam(pArg, "bi-route=")) != NULL) { defaultRouteData = FALSE; ! Route(hub, pParam, TRUE, FALSE); } else if ((pParam = GetParam(pArg, "no-route=")) != NULL) { defaultRouteData = FALSE; ! Route(hub, pParam, FALSE, TRUE); } else if ((pParam = GetParam(pArg, "echo-route=")) != NULL) { defaultRouteData = FALSE; ! EchoRoute(hub, pParam); } else { ! cerr << "Unknown option " << pArg << endl; ! exit(1); } } if (plugged < 2) { ! if (plugged < 1) ! Usage(argv[0]); } else if (defaultRouteData) { ! hub.RouteData(0, -1, FALSE, TRUE); ! hub.RouteData(1, 0, FALSE, TRUE); } if (defaultRouteFlowControl) { ! hub.RouteFlowControl(FALSE); } else { } hub.RouteReport(); if (hub.StartAll()) { DWORD nextReportTime = 0; --- 394,496 ---- if ((pParam = GetParam(pArg, "help")) != NULL && *pParam == 0) { ! Usage(argv[0], *pPlugins); ! exit(0); } else ! if ((pParam = GetParam(pArg, "help=")) != NULL) { ! char *pTmpList = _strdup(pParam); ! ! if (!pTmpList) { ! cerr << "No enough memory." << endl; ! exit(2); } + + char *pSave; + + for (char *p = STRTOK_R(pTmpList, ",", &pSave) ; p ; p = STRTOK_R(NULL, ",", &pSave)) + pPlugins->Help(argv[0], p); + + free(pTmpList); + exit(0); } else if ((pParam = GetParam(pArg, "route=")) != NULL) { defaultRouteData = FALSE; ! Route(hub, pParam, FALSE, FALSE, routeDataMap); } else if ((pParam = GetParam(pArg, "bi-route=")) != NULL) { defaultRouteData = FALSE; ! Route(hub, pParam, TRUE, FALSE, routeDataMap); } else if ((pParam = GetParam(pArg, "no-route=")) != NULL) { defaultRouteData = FALSE; ! Route(hub, pParam, FALSE, TRUE, routeDataMap); } else if ((pParam = GetParam(pArg, "echo-route=")) != NULL) { defaultRouteData = FALSE; ! EchoRoute(hub, pParam, routeDataMap); ! } else ! if ((pParam = GetParam(pArg, "create-filter=")) != NULL) { ! if (!pFilters) ! pFilters = new Filters(hub); ! ! if (!pFilters) { ! cerr << "No enough memory." << endl; ! exit(2); ! } ! ! CreateFilter(*pPlugins, *pFilters, pParam); ! } else ! if ((pParam = GetParam(pArg, "add-filters=")) != NULL) { ! if (!pFilters) { ! cerr << "No create-filter option before " << i->c_str() << endl; ! exit(1); ! } ! ! AddFilters(hub, *pFilters, pParam); ! } else ! if ((pParam = GetParam(pArg, "use-port-module=")) != NULL) { ! pUsePortModule = pParam; } else { ! if (!ok) { ! cerr << "Unknown option " << i->c_str() << endl; ! exit(1); ! } } } + delete pPlugins; + if (plugged < 2) { ! if (plugged < 1) { ! Usage(argv[0], *pPlugins); ! exit(1); ! } } else if (defaultRouteData) { ! Route(hub, "0:All", FALSE, FALSE, routeDataMap); ! Route(hub, "1:0", FALSE, FALSE, routeDataMap); } if (defaultRouteFlowControl) { ! SetFlowControlRoute(routeFlowControlMap, routeDataMap, FALSE); } else { } + hub.SetFlowControlRoute(routeFlowControlMap); + hub.SetDataRoute(routeDataMap); + + hub.SetFilters(pFilters); hub.RouteReport(); + if (pFilters) + pFilters->Report(); + } + /////////////////////////////////////////////////////////////// + int main(int argc, char* argv[]) + { + ComHub hub; + + Init(hub, argc, argv); + if (hub.StartAll()) { DWORD nextReportTime = 0; Index: comhub.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** comhub.h 19 Dec 2007 13:46:36 -0000 1.4 --- comhub.h 26 Mar 2008 08:48:18 -0000 1.5 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2006-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2006-2008 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.5 2008/03/26 08:48:18 vfrolov + * Initial revision + * * Revision 1.4 2007/12/19 13:46:36 vfrolov * Added ability to send data received from port to the same port *************** *** 37,77 **** #define _COMHUB_H /////////////////////////////////////////////////////////////// ! class ComPort; ! class ComParams; /////////////////////////////////////////////////////////////// ! typedef vector<ComPort*> ComPorts; ! typedef multimap<ComPort*, ComPort*> ComPortMap; /////////////////////////////////////////////////////////////// class ComHub { public: ! ComHub() {} ! ! BOOL Add(const char *pPath); ! BOOL PlugIn(int n, const char *pPath, const ComParams &comParams); ! BOOL StartAll(); ! void Write(ComPort *pFromPort, LPCVOID pData, DWORD len); ! void AddXoff(ComPort *pFromPort, int count); ! void LostReport() const; ! ! void RouteData(int iFrom, int iTo, BOOL noRoute, BOOL noEcho) { ! Route(routeDataMap, iFrom, iTo, noRoute, noEcho); } ! void RouteFlowControl(int iFrom, int iTo, BOOL noRoute, BOOL noEcho) { ! Route(routeFlowControlMap, iFrom, iTo, noRoute, noEcho); } ! void RouteFlowControl(BOOL fromAnyDataReceiver); void RouteReport() const; int NumPorts() const { return (int)ports.size(); } private: ! void Route(ComPortMap &map, int iFrom, int iTo, BOOL noRoute, BOOL noEcho) const; ! ComPorts ports; ! ComPortMap routeDataMap; ! ComPortMap routeFlowControlMap; }; /////////////////////////////////////////////////////////////// --- 40,114 ---- #define _COMHUB_H + #include "plugins/plugins_api.h" + /////////////////////////////////////////////////////////////// ! class Port; ! class Filters; ! class HubMsg; /////////////////////////////////////////////////////////////// ! typedef vector<Port*> Ports; ! typedef multimap<Port*, Port*> PortMap; ! typedef multimap<int, int> PortNumMap; ! /////////////////////////////////////////////////////////////// ! #define HUB_SIGNATURE 'h4cH' /////////////////////////////////////////////////////////////// class ComHub { public: ! ComHub() : pFilters(NULL) { ! #ifdef _DEBUG ! signature = HUB_SIGNATURE; ! #endif } ! #ifdef _DEBUG ! ~ComHub() { ! _ASSERTE(signature == HUB_SIGNATURE); ! signature = 0; } + #endif ! void Add() { ports.push_back(NULL); } ! BOOL CreatePort( ! const PORT_ROUTINES_A *pPortRoutines, ! int n, ! HCONFIG hConfig, ! const char *pPath); ! BOOL StartAll() const; ! void OnRead(Port *pFromPort, HubMsg *pMsg) const; ! void AddXoff(Port *pFromPort) const; ! void AddXon(Port *pFromPort) const; ! void LostReport() const; ! void SetDataRoute(const PortNumMap &map); ! void SetFlowControlRoute(const PortNumMap &map); void RouteReport() const; int NumPorts() const { return (int)ports.size(); } + Filters *SetFilters(Filters *_pFilters) { + Filters *pFiltersOld = pFilters; + pFilters = _pFilters; + return pFiltersOld; + } + + Port *ComHub::GetPort(int n) const { + if (n < 0 || n >= NumPorts()) + return NULL; + + return ports.at(n); + } + private: ! Ports ports; ! PortMap routeDataMap; ! PortMap routeFlowControlMap; ! Filters *pFilters; ! ! #ifdef _DEBUG ! DWORD signature; ! ! public: ! BOOL IsValid() { return signature == HUB_SIGNATURE; } ! #endif }; /////////////////////////////////////////////////////////////// Index: comhub.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** comhub.cpp 19 Dec 2007 13:46:36 -0000 1.4 --- comhub.cpp 26 Mar 2008 08:48:18 -0000 1.5 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2006-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2006-2008 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.5 2008/03/26 08:48:18 vfrolov + * Initial revision + * * Revision 1.4 2007/12/19 13:46:36 vfrolov * Added ability to send data received from port to the same port *************** *** 36,116 **** #include "precomp.h" #include "comhub.h" ! #include "comport.h" /////////////////////////////////////////////////////////////// ! typedef pair <ComPort*, ComPort*> ComPortPair; ! /////////////////////////////////////////////////////////////// ! static ComPortMap::iterator FindPair(ComPortMap &map, const ComPortPair &pair) { ! ComPortMap::iterator i; ! for (i = map.find(pair.first) ; i != map.end() ; i++) { ! if (i->first != pair.first) ! return map.end(); ! if (i->second == pair.second) ! break; } ! return i; ! } ! /////////////////////////////////////////////////////////////// ! BOOL ComHub::Add(const char * /*pPath*/) ! { ! ComPort *pPort = new ComPort(*this); ! if (!pPort) { ! cerr << "Can't create ComPort " << ports.size() << endl; return FALSE; } - ports.push_back(pPort); - return TRUE; } ! BOOL ComHub::PlugIn(int n, const char *pPath, const ComParams &comParams) { ! ComPort *pPort = ports.at(n); ! ! if (!pPort->Open(pPath, comParams)) return FALSE; return TRUE; } ! BOOL ComHub::StartAll() { ! BOOL res = TRUE; ! for (ComPorts::const_iterator i = ports.begin() ; i != ports.end() ; i++) { ! if (!(*i)->Start()) ! res = FALSE; } ! return res; } ! void ComHub::Write(ComPort *pFromPort, LPCVOID pData, DWORD len) { ! ComPortMap::const_iterator i; ! ! for (i = routeDataMap.find(pFromPort) ; i != routeDataMap.end() ; i++) { if (i->first != pFromPort) break; ! i->second->Write(pData, len); } } ! void ComHub::AddXoff(ComPort *pFromPort, int count) { ! ComPortMap::const_iterator i; ! ! for (i = routeFlowControlMap.find(pFromPort) ; i != routeFlowControlMap.end() ; i++) { if (i->first != pFromPort) break; ! i->second->AddXoff(count); } } --- 39,155 ---- #include "precomp.h" #include "comhub.h" ! #include "port.h" ! #include "filters.h" ! #include "hubmsg.h" /////////////////////////////////////////////////////////////// ! BOOL ComHub::CreatePort( ! const PORT_ROUTINES_A *pPortRoutines, ! int n, ! HCONFIG hConfig, ! const char *pPath) { ! if (!ROUTINE_IS_VALID(pPortRoutines, pCreate)) { ! cerr << "No create routine for port " << pPath << endl; ! return FALSE; ! } ! HPORT hPort = pPortRoutines->pCreate(hConfig, pPath); ! if (!hPort) { ! cerr << "Can't create port " << pPath << endl; ! return FALSE; } ! ports[n] = new Port(*this, n, pPortRoutines, hPort); ! if (!ports[n]) { ! cerr << "Can't create master port " << pPath << endl; return FALSE; } return TRUE; } ! BOOL ComHub::StartAll() const { ! if (pFilters && !pFilters->Init()) return FALSE; + for (Ports::const_iterator i = ports.begin() ; i != ports.end() ; i++) { + if (!(*i)->Init()) + return FALSE; + } + + for (Ports::const_iterator i = ports.begin() ; i != ports.end() ; i++) { + if (!(*i)->Start()) + return FALSE; + } + return TRUE; } ! void ComHub::OnRead(Port *pFromPort, HubMsg *pMsg) const { ! _ASSERTE(pFromPort != NULL); ! _ASSERTE(pMsg != NULL); ! if (pFilters) { ! HubMsg *pEchoMsg = NULL; ! ! if (!pFilters->InMethod(pFromPort->Num(), pMsg, &pEchoMsg)) { ! if (pEchoMsg) { ! delete pEchoMsg; ! pEchoMsg = NULL; ! } ! } ! ! for (HubMsg *pCurMsg = pEchoMsg ; pCurMsg ; pCurMsg = pCurMsg->Next()) ! pFromPort->Write(pCurMsg); ! ! if (pEchoMsg) ! delete pEchoMsg; } ! for (PortMap::const_iterator i = routeDataMap.find(pFromPort) ; i != routeDataMap.end() ; i++) { ! if (i->first != pFromPort) ! break; ! ! HubMsg *pOutMsg = pMsg->Clone(); ! ! if (pFilters && pOutMsg) { ! if (!pFilters->OutMethod(pFromPort->Num(), i->second->Num(), pOutMsg)) { ! if (pOutMsg) { ! delete pOutMsg; ! pOutMsg = NULL; ! } ! } ! } ! ! for (HubMsg *pCurMsg = pOutMsg ; pCurMsg ; pCurMsg = pCurMsg->Next()) ! i->second->Write(pCurMsg); ! ! if (pOutMsg) ! delete pOutMsg; ! } } ! void ComHub::AddXoff(Port *pFromPort) const { ! for (PortMap::const_iterator i = routeFlowControlMap.find(pFromPort) ; i != routeFlowControlMap.end() ; i++) { if (i->first != pFromPort) break; ! i->second->AddXoff(); } } ! void ComHub::AddXon(Port *pFromPort) const { ! for (PortMap::const_iterator i = routeFlowControlMap.find(pFromPort) ; i != routeFlowControlMap.end() ; i++) { if (i->first != pFromPort) break; ! i->second->AddXon(); } } *************** *** 118,175 **** void ComHub::LostReport() const { ! for (ComPorts::const_iterator i = ports.begin() ; i != ports.end() ; i++) (*i)->LostReport(); } ! void ComHub::RouteFlowControl(BOOL fromAnyDataReceiver) { ! for (ComPortMap::const_iterator i = routeDataMap.begin() ; i != routeDataMap.end() ; i++) { ! ComPortPair pair(i->second, i->first); ! if (FindPair(routeFlowControlMap, pair) == routeFlowControlMap.end()) { ! if (fromAnyDataReceiver || FindPair(routeDataMap, pair) != routeDataMap.end()) ! routeFlowControlMap.insert(pair); ! } ! } } ! void ComHub::Route(ComPortMap &map, int iFrom, int iTo, BOOL noRoute, BOOL noEcho) const { ! if (iFrom < 0) { ! for (int iF = 0 ; iF < (int)ports.size() ; iF++) { ! if(iTo < 0) { ! for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iF, iT, noRoute, noEcho); ! } else { ! Route(map, iF, iTo, noRoute, noEcho); ! } ! } ! } else { ! if(iTo < 0) { ! for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iFrom, iT, noRoute, noEcho); ! } ! else ! if (iFrom != iTo || !noEcho || noRoute) { ! ComPortPair pair(ports.at(iFrom), ports.at(iTo)); ! ! for (;;) { ! ComPortMap::iterator i = FindPair(map, pair); ! if (i == map.end()) { ! if (!noRoute) ! map.insert(pair); ! break; ! } else if (noRoute) { ! map.erase(i); ! } else { ! break; ! } ! } ! } ! } } ! static void RouteReport(const ComPortMap &map, const char *pMapName) { if (!map.size()) { --- 157,181 ---- void ComHub::LostReport() const { ! for (Ports::const_iterator i = ports.begin() ; i != ports.end() ; i++) (*i)->LostReport(); } ! void ComHub::SetDataRoute(const PortNumMap &map) { ! routeDataMap.clear(); ! for (PortNumMap::const_iterator i = map.begin() ; i != map.end() ; i++) ! routeDataMap.insert(pair<Port*, Port*>(ports.at(i->first), ports.at(i->second))); } ! void ComHub::SetFlowControlRoute(const PortNumMap &map) { ! routeFlowControlMap.clear(); ! for (PortNumMap::const_iterator i = map.begin() ; i != map.end() ; i++) ! routeFlowControlMap.insert(pair<Port*, Port*>(ports.at(i->first), ports.at(i->second))); } ! static void RouteReport(const PortMap &map, const char *pMapName) { if (!map.size()) { *************** *** 178,184 **** } ! ComPort *pLastPort = NULL; ! for (ComPortMap::const_iterator i = map.begin() ; i != map.end() ; i++) { if (pLastPort != i->first) { if (pLastPort) --- 184,190 ---- } ! Port *pLastPort = NULL; ! for (PortMap::const_iterator i = map.begin() ; i != map.end() ; i++) { if (pLastPort != i->first) { if (pLastPort) |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:45:58
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11541 Added Files: hub4com.sln Log Message: Initial revision --- NEW FILE: hub4com.sln --- (This appears to be a binary file; contents omitted.) |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:44:38
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11140 Added Files: comport.cpp comport.h Log Message: Redesigned for using plugins --- NEW FILE: comport.cpp --- /* * $Id: comport.cpp,v 1.1 2008/03/26 08:44:34 vfrolov Exp $ * * Copyright (c) 2006-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: comport.cpp,v $ * Revision 1.1 2008/03/26 08:44:34 vfrolov * Redesigned for using plugins * * Revision 1.4 2007/04/16 07:33:38 vfrolov * Fixed LostReport() * * Revision 1.3 2007/02/06 11:53:33 vfrolov * Added options --odsr, --ox, --ix and --idsr * Added communications error reporting * * Revision 1.2 2007/02/05 09:33:20 vfrolov * Implemented internal flow control * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * */ #include "precomp.h" #include "comport.h" #include "comio.h" #include "comparams.h" #include "import.h" /////////////////////////////////////////////////////////////// ComPort::ComPort( const ComParams &comParams, const char *pPath) : hMasterPort(NULL), hHub(NULL), countReadOverlapped(0), countWaitCommEventOverlapped(0), countXoff(0), filterX(FALSE), writeQueueLimit(256), writeQueued(0), writeLost(0), writeLostTotal(0), errors(0) { filterX = comParams.InX(); string path(pPath); name = path.substr(path.rfind('\\') + 1); handle = ::OpenComPort(pPath, comParams); } BOOL ComPort::Init(HMASTERPORT _hMasterPort, HHUB _hHub) { if (handle == INVALID_HANDLE_VALUE) { cerr << "ComPort::Init(): Invalid handle" << endl; return FALSE; } hMasterPort = _hMasterPort; hHub = _hHub; return TRUE; } BOOL ComPort::Start() { _ASSERTE(hMasterPort != NULL); _ASSERTE(hHub != NULL); _ASSERTE(handle != INVALID_HANDLE_VALUE); CheckComEvents(DWORD(-1)); DWORD events; if (!::GetCommMask(handle, &events)) { DWORD err = ::GetLastError(); cerr << "ComPort::Start(): GetCommMask() ERROR " << err << endl; return FALSE; } if (events && !StartWaitCommEvent()) return FALSE; if (!StartRead()) return FALSE; HUB_MSG msg; msg.type = HUB_MSG_TYPE_CONNECT; msg.u.val = TRUE; pOnRead(hHub, hMasterPort, &msg); return TRUE; } BOOL ComPort::StartRead() { if (countReadOverlapped) return TRUE; if (handle == INVALID_HANDLE_VALUE) return FALSE; ReadOverlapped *pOverlapped; pOverlapped = new ReadOverlapped(*this); if (!pOverlapped) return FALSE; if (!pOverlapped->StartRead()) { delete pOverlapped; return FALSE; } countReadOverlapped++; //cout << "Started Read " << name << " " << countReadOverlapped << endl; return TRUE; } BOOL ComPort::Write(HUB_MSG *pMsg) { _ASSERTE(pMsg != NULL); if (pMsg->type == HUB_MSG_TYPE_LINE_DATA) { BYTE *pBuf = pMsg->u.buf.pBuf; DWORD len = pMsg->u.buf.size; if (!len) return TRUE; if (!pBuf) { writeLost += len; return FALSE; } if (filterX) { BYTE *pSrc = pBuf; BYTE *pDst = pBuf; for (DWORD i = 0 ; i < len ; i++) { if (*pSrc == 0x11 || *pSrc == 0x13) pSrc++; else *pDst++ = *pSrc++; } len = DWORD(pDst - pBuf); } if (!len) return TRUE; if (handle == INVALID_HANDLE_VALUE) { writeLost += len; return FALSE; } WriteOverlapped *pOverlapped; pOverlapped = new WriteOverlapped(*this, pBuf, len); if (!pOverlapped) { writeLost += len; return FALSE; } pMsg->type = HUB_MSG_TYPE_EMPTY; if (writeQueued > writeQueueLimit) ::PurgeComm(handle, PURGE_TXABORT|PURGE_TXCLEAR); if (!pOverlapped->StartWrite()) { writeLost += len; delete pOverlapped; return FALSE; } if (writeQueued <= writeQueueLimit/2 && (writeQueued + len) > writeQueueLimit/2) pOnXoff(hHub, hMasterPort); writeQueued += len; //cout << "Started Write " << name << " " << len << " " << writeQueued << endl; } else if (pMsg->type == HUB_MSG_TYPE_COM_FUNCTION) { if (handle == INVALID_HANDLE_VALUE) return FALSE; if (!::EscapeCommFunction(handle, pMsg->u.val)) return FALSE; } return TRUE; } BOOL ComPort::StartWaitCommEvent() { if (countWaitCommEventOverlapped) return TRUE; if (handle == INVALID_HANDLE_VALUE) return FALSE; WaitCommEventOverlapped *pOverlapped; pOverlapped = new WaitCommEventOverlapped(*this); if (!pOverlapped) return FALSE; if (!pOverlapped->StartWaitCommEvent()) { delete pOverlapped; return FALSE; } countWaitCommEventOverlapped++; //cout << "Started WaitCommEvent " << name << " " << countReadOverlapped << endl; return TRUE; } void ComPort::OnWrite(WriteOverlapped *pOverlapped, DWORD len, DWORD done) { delete pOverlapped; if (len > done) writeLost += len - done; if (writeQueued > writeQueueLimit/2 && (writeQueued - len) <= writeQueueLimit/2) pOnXon(hHub, hMasterPort); writeQueued -= len; } void ComPort::OnRead(ReadOverlapped *pOverlapped, BYTE *pBuf, DWORD done) { HUB_MSG msg; msg.type = HUB_MSG_TYPE_LINE_DATA; msg.u.buf.pBuf = pBuf; msg.u.buf.size = done; pOnRead(hHub, hMasterPort, &msg); if (countXoff > 0 || !pOverlapped->StartRead()) { delete pOverlapped; countReadOverlapped--; //cout << "Stopped Read " << name << " " << countReadOverlapped << endl; } } void ComPort::OnCommEvent(WaitCommEventOverlapped *pOverlapped, DWORD eMask) { CheckComEvents(eMask); if (!pOverlapped->StartWaitCommEvent()) { delete pOverlapped; countWaitCommEventOverlapped--; cout << "Stopped WaitCommEvent " << name << " " << countWaitCommEventOverlapped << endl; } } void ComPort::CheckComEvents(DWORD eMask) { if ((eMask & (EV_CTS|EV_DSR|EV_RLSD|EV_RING)) != 0) { DWORD stat; if (::GetCommModemStatus(handle, &stat)) { HUB_MSG msg; msg.type = HUB_MSG_TYPE_MODEM_STATUS; msg.u.val = stat; pOnRead(hHub, hMasterPort, &msg); } } if ((eMask & (EV_BREAK|EV_ERR)) != 0) { DWORD errs; if (!::ClearCommError(handle, &errs, NULL)) errs = 0; if (errs) { errors |= errs; HUB_MSG msg; msg.type = HUB_MSG_TYPE_COM_ERRORS; msg.u.val = errs; pOnRead(hHub, hMasterPort, &msg); } } } void ComPort::AddXoff(int count) { _ASSERTE(handle != INVALID_HANDLE_VALUE); countXoff += count; if (countXoff <= 0) StartRead(); } void ComPort::LostReport() { _ASSERTE(handle != INVALID_HANDLE_VALUE); if (writeLost) { writeLostTotal += writeLost; cout << "Write lost " << name << ": " << writeLost << ", total " << writeLostTotal << endl; writeLost = 0; } CheckComEvents(EV_BREAK|EV_ERR); if (errors) { cout << "Error " << name << ":"; if (errors & CE_RXOVER) { cout << " RXOVER"; errors &= ~CE_RXOVER; } if (errors & CE_OVERRUN) { cout << " OVERRUN"; errors &= ~CE_OVERRUN; } if (errors & CE_RXPARITY) { cout << " RXPARITY"; errors &= ~CE_RXPARITY; } if (errors & CE_FRAME) { cout << " FRAME"; errors &= ~CE_FRAME; } if (errors & CE_BREAK) { cout << " BREAK"; errors &= ~CE_BREAK; } if (errors & CE_TXFULL) { cout << " TXFULL"; errors &= ~CE_TXFULL; } if (errors) { cout << " 0x" << hex << errors << dec; errors = 0; } #define IOCTL_SERIAL_GET_STATS CTL_CODE(FILE_DEVICE_SERIAL_PORT,35,METHOD_BUFFERED,FILE_ANY_ACCESS) typedef struct _SERIALPERF_STATS { ULONG ReceivedCount; ULONG TransmittedCount; ULONG FrameErrorCount; ULONG SerialOverrunErrorCount; ULONG BufferOverrunErrorCount; ULONG ParityErrorCount; } SERIALPERF_STATS, *PSERIALPERF_STATS; SERIALPERF_STATS stats; DWORD size; if (DeviceIoControl(handle, IOCTL_SERIAL_GET_STATS, NULL, 0, &stats, sizeof(stats), &size, NULL)) { cout << ", total" << " RXOVER=" << stats.BufferOverrunErrorCount << " OVERRUN=" << stats.SerialOverrunErrorCount << " RXPARITY=" << stats.ParityErrorCount << " FRAME=" << stats.FrameErrorCount; } cout << endl; } } /////////////////////////////////////////////////////////////// --- NEW FILE: comport.h --- /* * $Id: comport.h,v 1.1 2008/03/26 08:44:34 vfrolov Exp $ * * Copyright (c) 2006-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: comport.h,v $ * Revision 1.1 2008/03/26 08:44:34 vfrolov * Redesigned for using plugins * * Revision 1.3 2007/02/06 11:53:33 vfrolov * Added options --odsr, --ox, --ix and --idsr * Added communications error reporting * * Revision 1.2 2007/02/05 09:33:20 vfrolov * Implemented internal flow control * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * */ #ifndef _COMPORT_H #define _COMPORT_H #include "../plugins_api.h" /////////////////////////////////////////////////////////////// class ComParams; class WriteOverlapped; class ReadOverlapped; class WaitCommEventOverlapped; /////////////////////////////////////////////////////////////// class ComPort { public: ComPort( const ComParams &comParams, const char *pPath); BOOL Init(HMASTERPORT _hMasterPort, HHUB _hHub); BOOL Start(); BOOL Write(HUB_MSG *pMsg); void OnWrite(WriteOverlapped *pOverlapped, DWORD len, DWORD done); void OnRead(ReadOverlapped *pOverlapped, BYTE *pBuf, DWORD done); void OnCommEvent(WaitCommEventOverlapped *pOverlapped, DWORD eMask); void AddXoff(int count); void LostReport(); const string &Name() const { return name; } void Name(const char *pName) { name = pName; } HANDLE Handle() const { return handle; } private: BOOL StartRead(); BOOL StartWaitCommEvent(); void CheckComEvents(DWORD eMask); string name; HANDLE handle; HMASTERPORT hMasterPort; HHUB hHub; int countReadOverlapped; int countWaitCommEventOverlapped; int countXoff; BOOL filterX; DWORD writeQueueLimit; DWORD writeQueued; DWORD writeLost; DWORD writeLostTotal; DWORD errors; }; /////////////////////////////////////////////////////////////// #endif // _COMPORT_H |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:44:17
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11112 Added Files: comparams.cpp comparams.h Log Message: Redesigned for using plugins --- NEW FILE: comparams.cpp --- /* * $Id: comparams.cpp,v 1.1 2008/03/26 08:44:13 vfrolov Exp $ * * Copyright (c) 2006-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: comparams.cpp,v $ * Revision 1.1 2008/03/26 08:44:13 vfrolov * Redesigned for using plugins * * Revision 1.4 2007/05/14 12:06:37 vfrolov * Added read interval timeout option * * Revision 1.3 2007/02/06 11:53:33 vfrolov * Added options --odsr, --ox, --ix and --idsr * Added communications error reporting * * Revision 1.2 2007/02/01 12:14:59 vfrolov * Redesigned COM port params * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include "precomp.h" #include "comparams.h" #include "../../utils.h" /////////////////////////////////////////////////////////////// static struct { DWORD val; const char *pName; } event_names[] = { {EV_CTS, "cts"}, {EV_DSR, "dsr"}, {EV_RLSD, "dcd"}, {EV_RING, "ring"}, {EV_BREAK, "break"}, {EV_ERR, "err"}, }; /////////////////////////////////////////////////////////////// ComParams::ComParams() : baudRate(CBR_19200), byteSize(8), parity(NOPARITY), stopBits(ONESTOPBIT), outCts(1), outDsr(0), outX(0), inX(0), inDsr(0), intervalTimeout(0), events(0) { } BOOL ComParams::SetBaudRate(const char *pBaudRate) { if (*pBaudRate == 'c') { baudRate = -1; return TRUE; } if (isdigit(*pBaudRate)) { baudRate = atol(pBaudRate); return TRUE; } return FALSE; } BOOL ComParams::SetByteSize(const char *pByteSize) { if (*pByteSize == 'c') { byteSize = -1; return TRUE; } if (isdigit(*pByteSize)) { byteSize = atoi(pByteSize); return TRUE; } return FALSE; } BOOL ComParams::SetParity(const char *pParity) { switch (*pParity) { case 'n': parity = NOPARITY; break; case 'o': parity = ODDPARITY; break; case 'e': parity = EVENPARITY; break; case 'm': parity = MARKPARITY; break; case 's': parity = SPACEPARITY; break; case 'c': parity = -1; break; default : return FALSE; } return TRUE; } BOOL ComParams::SetStopBits(const char *pStopBits) { switch (*pStopBits) { case '1': if ((pStopBits[1] == '.' || pStopBits[1] == ',') && pStopBits[2] == '5') stopBits = ONE5STOPBITS; else stopBits = ONESTOPBIT; break; case '2': stopBits = TWOSTOPBITS; break; case 'c': stopBits = -1; break; default : return FALSE; } return TRUE; } BOOL ComParams::SetIntervalTimeout(const char *pIntervalTimeout) { if (isdigit(*pIntervalTimeout)) { intervalTimeout = atol(pIntervalTimeout); return TRUE; } return FALSE; } BOOL ComParams::SetEvents(const char *pEvents) { char *pTmp = _strdup(pEvents); if (!pTmp) { cerr << "No enough memory." << endl; exit(2); } events = 0; char *pSave; for (char *pName = STRTOK_R(pTmp, ",", &pSave) ; pName ; pName = STRTOK_R(NULL, ",", &pSave)) { BOOL found = FALSE; for (int i = 0 ; i < sizeof(event_names)/sizeof(event_names[0]) ; i++) { if (_stricmp(pName, event_names[i].pName) == 0) { events |= event_names[i].val; found = TRUE; break; } } if (!found && _stricmp(pName, "none") != 0) { free(pTmp); return FALSE; } } free(pTmp); return TRUE; } BOOL ComParams::SetFlag(const char *pFlagStr, int *pFlag) { if (_stricmp(pFlagStr, "on") == 0) { *pFlag = 1; } else if (_stricmp(pFlagStr, "off") == 0) { *pFlag = 0; } else if (*pFlagStr == 'c') { *pFlag = -1; } else return FALSE; return TRUE; } /////////////////////////////////////////////////////////////// string ComParams::BaudRateStr(long baudRate) { if (baudRate >= 0) { stringstream buf; buf << baudRate; return buf.str(); } return baudRate == -1 ? "current" : "?"; } string ComParams::ByteSizeStr(int byteSize) { if (byteSize >= 0) { stringstream buf; buf << byteSize; return buf.str(); } return byteSize == -1 ? "current" : "?"; } string ComParams::ParityStr(int parity) { switch (parity) { case NOPARITY: return "no"; case ODDPARITY: return "odd"; case EVENPARITY: return "even"; case MARKPARITY: return "mark"; case SPACEPARITY: return "space"; case -1: return "current"; } return "?"; } string ComParams::StopBitsStr(int stopBits) { switch (stopBits) { case ONESTOPBIT: return "1"; case ONE5STOPBITS: return "1.5"; case TWOSTOPBITS: return "2"; case -1: return "current"; } return "?"; } string ComParams::IntervalTimeoutStr(long intervalTimeout) { if (intervalTimeout > 0) { stringstream buf; buf << intervalTimeout; return buf.str(); } return "0"; } string ComParams::EventsStr(DWORD events) { if (events > 0) { stringstream buf; BOOL first = TRUE; for (int i = 0 ; i < sizeof(event_names)/sizeof(event_names[0]) ; i++) { if ((events & event_names[i].val) != 0) { if (first) first = FALSE; else buf << ","; buf << event_names[i].pName; } } return buf.str(); } return "none"; } string ComParams::FlagStr(int flag) { switch (flag) { case 1: return "on"; case 0: return "off"; case -1: return "current"; } return "?"; } /////////////////////////////////////////////////////////////// const char *ComParams::BaudRateLst() { return "a positive number or c[urrent]"; } const char *ComParams::ByteSizeLst() { return "a positive number or c[urrent]"; } const char *ComParams::ParityLst() { return "n[o], o[dd], e[ven], m[ark], s[pace] or c[urrent]"; } const char *ComParams::StopBitsLst() { return "1, 1.5, 2 or c[urrent]"; } const char *ComParams::IntervalTimeoutLst() { return "a positive number or 0 milliseconds"; } const char *ComParams::EventsLst() { return "<E1>[,<E2>...], where <En> is cts, dsr, dcd, ring, break, err or none"; } const char *ComParams::FlagLst() { return "on, off or c[urrent]"; } /////////////////////////////////////////////////////////////// --- NEW FILE: comparams.h --- /* * $Id: comparams.h,v 1.1 2008/03/26 08:44:13 vfrolov Exp $ * * Copyright (c) 2006-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: comparams.h,v $ * Revision 1.1 2008/03/26 08:44:13 vfrolov * Redesigned for using plugins * * Revision 1.4 2007/05/14 12:06:37 vfrolov * Added read interval timeout option * * Revision 1.3 2007/02/06 11:53:33 vfrolov * Added options --odsr, --ox, --ix and --idsr * Added communications error reporting * * Revision 1.2 2007/02/01 12:14:59 vfrolov * Redesigned COM port params * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * */ #ifndef _COMPARAMS_H #define _COMPARAMS_H /////////////////////////////////////////////////////////////// class ComParams { public: ComParams(); BOOL SetBaudRate(const char *pBaudRate); BOOL SetByteSize(const char *pByteSize); BOOL SetParity(const char *pParity); BOOL SetStopBits(const char *pStopBits); BOOL SetOutCts(const char *pOutCts) { return SetFlag(pOutCts, &outCts); } BOOL SetOutDsr(const char *pOutDsr) { return SetFlag(pOutDsr, &outDsr); } BOOL SetOutX(const char *pOutX) { return SetFlag(pOutX, &outX); } BOOL SetInX(const char *pInX) { return SetFlag(pInX, &inX); } BOOL SetInDsr(const char *pInDsr) { return SetFlag(pInDsr, &inDsr); } BOOL SetIntervalTimeout(const char *pIntervalTimeout); BOOL SetEvents(const char *pEvents); static string BaudRateStr(long baudRate); static string ByteSizeStr(int byteSize); static string ParityStr(int parity); static string StopBitsStr(int stopBits); static string OutCtsStr(int outCts) { return FlagStr(outCts); } static string OutDsrStr(int outDsr) { return FlagStr(outDsr); } static string OutXStr(int outX) { return FlagStr(outX); } static string InXStr(int inX) { return FlagStr(inX); } static string InDsrStr(int inDsr) { return FlagStr(inDsr); } static string IntervalTimeoutStr(long intervalTimeout); static string EventsStr(DWORD events); string BaudRateStr() const { return BaudRateStr(baudRate); } string ByteSizeStr() const { return ByteSizeStr(byteSize); } string ParityStr() const { return ParityStr(parity); } string StopBitsStr() const { return StopBitsStr(stopBits); } string OutCtsStr() const { return OutCtsStr(outCts); } string OutDsrStr() const { return OutDsrStr(outDsr); } string OutXStr() const { return OutXStr(outX); } string InXStr() const { return InXStr(inX); } string InDsrStr() const { return InDsrStr(inDsr); } string IntervalTimeoutStr() const { return IntervalTimeoutStr(intervalTimeout); } string EventsStr() const { return EventsStr(events); } static const char *BaudRateLst(); static const char *ByteSizeLst(); static const char *ParityLst(); static const char *StopBitsLst(); static const char *OutCtsLst() { return FlagLst(); } static const char *OutDsrLst() { return FlagLst(); } static const char *OutXLst() { return FlagLst(); } static const char *InXLst() { return FlagLst(); } static const char *InDsrLst() { return FlagLst(); } static const char *IntervalTimeoutLst(); static const char *EventsLst(); long BaudRate() const { return baudRate; } int ByteSize() const { return byteSize; } int Parity() const { return parity; } int StopBits() const { return stopBits; } int OutCts() const { return outCts; } int OutDsr() const { return outDsr; } int OutX() const { return outX; } int InX() const { return inX; } int InDsr() const { return inDsr; } long IntervalTimeout() const { return intervalTimeout; } DWORD Events() const { return events; } private: BOOL SetFlag(const char *pFlagStr, int *pFlag); static string FlagStr(int flag); static const char *FlagLst(); long baudRate; int byteSize; int parity; int stopBits; int outCts; int outDsr; int outX; int inX; int inDsr; long intervalTimeout; DWORD events; }; /////////////////////////////////////////////////////////////// #endif // _COMPARAMS_H |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:43:53
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv10754 Added Files: comio.cpp comio.h Log Message: Redesigned for using plugins --- NEW FILE: comio.h --- /* * $Id: comio.h,v 1.1 2008/03/26 08:43:50 vfrolov Exp $ * * Copyright (c) 2006-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: comio.h,v $ * Revision 1.1 2008/03/26 08:43:50 vfrolov * Redesigned for using plugins * * Revision 1.3 2007/02/06 11:53:33 vfrolov * Added options --odsr, --ox, --ix and --idsr * Added communications error reporting * * Revision 1.2 2007/02/05 09:33:20 vfrolov * Implemented internal flow control * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * */ #ifndef _COMIO_H #define _COMIO_H /////////////////////////////////////////////////////////////// class ComPort; class ComParams; /////////////////////////////////////////////////////////////// extern HANDLE OpenComPort(const char *pPath, const ComParams &comParams); /////////////////////////////////////////////////////////////// class ReadOverlapped : private OVERLAPPED { public: ReadOverlapped(ComPort &_port); ~ReadOverlapped(); BOOL StartRead(); private: static VOID CALLBACK OnRead( DWORD err, DWORD done, LPOVERLAPPED pOverlapped); ComPort &port; BYTE *pBuf; }; /////////////////////////////////////////////////////////////// class WriteOverlapped : private OVERLAPPED { public: WriteOverlapped(ComPort &_port, BYTE *_pBuf, DWORD _len); ~WriteOverlapped(); BOOL StartWrite(); private: static VOID CALLBACK OnWrite( DWORD err, DWORD done, LPOVERLAPPED pOverlapped); ComPort &port; BYTE *pBuf; DWORD len; }; /////////////////////////////////////////////////////////////// class WaitCommEventOverlapped : private OVERLAPPED { public: WaitCommEventOverlapped(ComPort &_port); ~WaitCommEventOverlapped(); BOOL StartWaitCommEvent(); private: static VOID CALLBACK OnCommEvent( PVOID pParameter, BOOLEAN timerOrWaitFired); ComPort &port; HANDLE hWait; DWORD eMask; }; /////////////////////////////////////////////////////////////// #endif // _COMIO_H --- NEW FILE: comio.cpp --- /* * $Id: comio.cpp,v 1.1 2008/03/26 08:43:50 vfrolov Exp $ * * Copyright (c) 2006-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: comio.cpp,v $ * Revision 1.1 2008/03/26 08:43:50 vfrolov * Redesigned for using plugins * * Revision 1.5 2007/05/14 12:06:37 vfrolov * Added read interval timeout option * * Revision 1.4 2007/02/06 11:53:33 vfrolov * Added options --odsr, --ox, --ix and --idsr * Added communications error reporting * * Revision 1.3 2007/02/05 09:33:20 vfrolov * Implemented internal flow control * * Revision 1.2 2007/02/01 12:14:59 vfrolov * Redesigned COM port params * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * */ #include "precomp.h" #include "comio.h" #include "comport.h" #include "comparams.h" #include "import.h" /////////////////////////////////////////////////////////////// static void TraceError(DWORD err, const char *pFmt, ...) { va_list va; va_start(va, pFmt); vfprintf(stderr, pFmt, va); va_end(va); fprintf(stderr, " ERROR %s (%lu)\n", strerror(err), (unsigned long)err); } /////////////////////////////////////////////////////////////// static BOOL myGetCommState(HANDLE handle, DCB *dcb) { dcb->DCBlength = sizeof(*dcb); if (!GetCommState(handle, dcb)) { TraceError(GetLastError(), "GetCommState()"); return FALSE; } return TRUE; } static BOOL mySetCommState(HANDLE handle, DCB *dcb) { if (!SetCommState(handle, dcb)) { TraceError(GetLastError(), "SetCommState()"); return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// HANDLE OpenComPort(const char *pPath, const ComParams &comParams) { HANDLE handle = CreateFile(pPath, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (handle == INVALID_HANDLE_VALUE) { TraceError(GetLastError(), "OpenComPort(): CreateFile(\"%s\")", pPath); return INVALID_HANDLE_VALUE; } DCB dcb; if (!myGetCommState(handle, &dcb)) { CloseHandle(handle); return INVALID_HANDLE_VALUE; } if (comParams.BaudRate() >= 0) dcb.BaudRate = (DWORD)comParams.BaudRate(); if (comParams.ByteSize() >= 0) dcb.ByteSize = (BYTE)comParams.ByteSize(); if (comParams.Parity() >= 0) dcb.Parity = (BYTE)comParams.Parity(); if (comParams.StopBits() >= 0) dcb.StopBits = (BYTE)comParams.StopBits(); if (comParams.OutCts() >= 0) dcb.fOutxCtsFlow = comParams.OutCts(); if (comParams.OutDsr() >= 0) dcb.fOutxDsrFlow = comParams.OutDsr(); if (comParams.OutX() >= 0) dcb.fOutX = comParams.OutX(); if (comParams.InX() >= 0) dcb.fInX = comParams.InX(); if (comParams.InDsr() >= 0) dcb.fDsrSensitivity = comParams.InDsr(); dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; dcb.fDtrControl = DTR_CONTROL_ENABLE; dcb.fParity = FALSE; dcb.fNull = FALSE; dcb.fAbortOnError = FALSE; dcb.fErrorChar = FALSE; if (!mySetCommState(handle, &dcb)) { CloseHandle(handle); return INVALID_HANDLE_VALUE; } COMMTIMEOUTS timeouts; if (!GetCommTimeouts(handle, &timeouts)) { TraceError(GetLastError(), "OpenComPort(): GetCommTimeouts()"); CloseHandle(handle); return INVALID_HANDLE_VALUE; } if (comParams.IntervalTimeout() > 0) { timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; timeouts.ReadIntervalTimeout = (DWORD)comParams.IntervalTimeout(); } else { timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; timeouts.ReadTotalTimeoutConstant = MAXDWORD - 1; timeouts.ReadIntervalTimeout = MAXDWORD; } timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; if (!SetCommTimeouts(handle, &timeouts)) { TraceError(GetLastError(), "OpenComPort(): SetCommTimeouts()"); CloseHandle(handle); return INVALID_HANDLE_VALUE; } if (!::SetCommMask(handle, comParams.Events())) { TraceError(GetLastError(), "OpenComPort(): SetCommMask()"); CloseHandle(handle); return INVALID_HANDLE_VALUE; } cout << "Open(" << "\"" << pPath << "\", baud=" << ComParams::BaudRateStr(dcb.BaudRate) << ", data=" << ComParams::ByteSizeStr(dcb.ByteSize) << ", parity=" << ComParams::ParityStr(dcb.Parity) << ", stop=" << ComParams::StopBitsStr(dcb.StopBits) << ", octs=" << ComParams::OutCtsStr(dcb.fOutxCtsFlow) << ", odsr=" << ComParams::OutDsrStr(dcb.fOutxDsrFlow) << ", ox=" << ComParams::OutXStr(dcb.fOutX) << ", ix=" << ComParams::InXStr(dcb.fInX) << ", idsr=" << ComParams::InDsrStr(dcb.fDsrSensitivity) << ", ito=" << comParams.IntervalTimeoutStr() << ", rt-events=" << comParams.EventsStr() << ") - OK" << endl; return handle; } /////////////////////////////////////////////////////////////// WriteOverlapped::WriteOverlapped(ComPort &_port, BYTE *_pBuf, DWORD _len) : port(_port), pBuf(_pBuf), len(_len) { } WriteOverlapped::~WriteOverlapped() { pBufFree(pBuf); } VOID CALLBACK WriteOverlapped::OnWrite( DWORD err, DWORD done, LPOVERLAPPED pOverlapped) { WriteOverlapped *pOver = (WriteOverlapped *)pOverlapped; if (err != ERROR_SUCCESS && err != ERROR_OPERATION_ABORTED) TraceError(err, "WriteOverlapped::OnWrite: %s", pOver->port.Name().c_str()); pOver->port.OnWrite(pOver, pOver->len, done); } BOOL WriteOverlapped::StartWrite() { ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); if (!pBuf) return FALSE; if (!::WriteFileEx(port.Handle(), pBuf, len, this, OnWrite)) return FALSE; return TRUE; } /////////////////////////////////////////////////////////////// ReadOverlapped::ReadOverlapped(ComPort &_port) : port(_port), pBuf(NULL) { } ReadOverlapped::~ReadOverlapped() { pBufFree(pBuf); } VOID CALLBACK ReadOverlapped::OnRead( DWORD err, DWORD done, LPOVERLAPPED pOverlapped) { ReadOverlapped *pOver = (ReadOverlapped *)pOverlapped; if (err != ERROR_SUCCESS) { TraceError(err, "ReadOverlapped::OnRead(): %s", pOver->port.Name().c_str()); done = 0; } BYTE *pInBuf = pOver->pBuf; pOver->pBuf = NULL; pOver->port.OnRead(pOver, pInBuf, done); } BOOL ReadOverlapped::StartRead() { ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); #define readBufSize 64 pBuf = pBufAlloc(readBufSize); if (!pBuf) return FALSE; if (::ReadFileEx(port.Handle(), pBuf, readBufSize, this, OnRead)) return TRUE; TraceError(GetLastError(), "ReadOverlapped::StartRead(): ReadFileEx() %s", port.Name().c_str()); return FALSE; } /////////////////////////////////////////////////////////////// WaitCommEventOverlapped::WaitCommEventOverlapped(ComPort &_port) : port(_port), hWait(INVALID_HANDLE_VALUE) { ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL); if (!hEvent) { TraceError( GetLastError(), "WaitCommEventOverlapped::WaitCommEventOverlapped(): CreateEvent() %s", port.Name().c_str()); return; } if (!::RegisterWaitForSingleObject(&hWait, hEvent, OnCommEvent, this, INFINITE, WT_EXECUTEINIOTHREAD)) { TraceError( GetLastError(), "WaitCommEventOverlapped::StartWaitCommEvent(): RegisterWaitForSingleObject() %s", port.Name().c_str()); hWait = INVALID_HANDLE_VALUE; return; } } WaitCommEventOverlapped::~WaitCommEventOverlapped() { if (hWait != INVALID_HANDLE_VALUE) { if (!::UnregisterWait(hWait)) { TraceError( GetLastError(), "WaitCommEventOverlapped::~WaitCommEventOverlapped(): UnregisterWait() %s", port.Name().c_str()); } } if (hEvent) { if (!::CloseHandle(hEvent)) { TraceError( GetLastError(), "WaitCommEventOverlapped::~WaitCommEventOverlapped(): CloseHandle(hEvent) %s", port.Name().c_str()); } } } VOID CALLBACK WaitCommEventOverlapped::OnCommEvent( PVOID pOverlapped, BOOLEAN /*timerOrWaitFired*/) { WaitCommEventOverlapped *pOver = (WaitCommEventOverlapped *)pOverlapped; DWORD done; if (!::GetOverlappedResult(pOver->port.Handle(), pOver, &done, FALSE)) { TraceError( GetLastError(), "WaitCommEventOverlapped::OnCommEvent(): GetOverlappedResult() %s", pOver->port.Name().c_str()); pOver->eMask = 0; } pOver->port.OnCommEvent(pOver, pOver->eMask); } BOOL WaitCommEventOverlapped::StartWaitCommEvent() { if (!hEvent) return FALSE; if (!::WaitCommEvent(port.Handle(), &eMask, this)) { DWORD err = ::GetLastError(); if (err != ERROR_IO_PENDING) { TraceError( err, "WaitCommEventOverlapped::StartWaitCommEvent(): WaitCommEvent() %s", port.Name().c_str()); return FALSE; } } return TRUE; } /////////////////////////////////////////////////////////////// |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:41:22
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv10020 Added Files: serial.vcproj import.h port.cpp Log Message: Initial revision --- NEW FILE: import.h --- /* * $Id: import.h,v 1.1 2008/03/26 08:41:18 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: import.h,v $ * Revision 1.1 2008/03/26 08:41:18 vfrolov * Initial revision * * */ #ifndef _IMPORT_H #define _IMPORT_H #include "../plugins_api.h" /////////////////////////////////////////////////////////////// extern ROUTINE_BUF_ALLOC *pBufAlloc; extern ROUTINE_BUF_FREE *pBufFree; extern ROUTINE_ON_XOFF *pOnXoff; extern ROUTINE_ON_XON *pOnXon; extern ROUTINE_ON_READ *pOnRead; /////////////////////////////////////////////////////////////// #endif // _IMPORT_H --- NEW FILE: serial.vcproj --- <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" Version="8,00" Name="port-serial" ProjectGUID="{031557BD-5B2D-4B87-B40D-2DD9C43E68BC}" 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=".\comio.h" > </File> <File RelativePath=".\comparams.h" > </File> <File RelativePath=".\comport.h" > </File> <File RelativePath=".\import.h" > </File> <File RelativePath="..\plugins_api.h" > </File> <File RelativePath=".\precomp.h" > </File> <File RelativePath="..\..\utils.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=".\comio.cpp" > </File> <File RelativePath=".\comparams.cpp" > </File> <File RelativePath=".\comport.cpp" > </File> <File RelativePath="..\plugins.def" > </File> <File RelativePath=".\port.cpp" > </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> <File RelativePath="..\..\utils.cpp" > </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: port.cpp --- /* * $Id: port.cpp,v 1.1 2008/03/26 08:41:18 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: port.cpp,v $ * Revision 1.1 2008/03/26 08:41:18 vfrolov * Initial revision * * */ #include "precomp.h" #include "comparams.h" #include "comport.h" #include "import.h" #include "../../utils.h" /////////////////////////////////////////////////////////////// static PLUGIN_TYPE CALLBACK GetPluginType() { return PLUGIN_TYPE_PORT; } /////////////////////////////////////////////////////////////// static const PLUGIN_ABOUT_A about = { sizeof(PLUGIN_ABOUT_A), "serial", "Copyright (c) 2008 Vyacheslav Frolov", "GNU General Public License", "Serial port", }; static const PLUGIN_ABOUT_A * CALLBACK GetPluginAbout() { return &about; } /////////////////////////////////////////////////////////////// static void CALLBACK Help(const char *pProgPath) { cerr << "COM port options:" << endl << " --baud=<b> - set baud rate to <b> (" << ComParams().BaudRateStr() << " by default)," << endl << " where <b> is " << ComParams::BaudRateLst() << "." << endl << " --data=<d> - set data bits to <d> (" << ComParams().ByteSizeStr() << " by default)," << endl << " where <d> is " << ComParams::ByteSizeLst() << "." << endl << " --parity=<p> - set parity to <p> (" << ComParams().ParityStr() << " by default)," << endl << " where <p> is" << endl << " " << ComParams::ParityLst() << "." << endl << " --stop=<s> - set stop bits to <s> (" << ComParams().StopBitsStr() << " by default)," << endl << " where <s> is " << ComParams::StopBitsLst() << "." << endl << " --octs=<c> - set CTS handshaking on output to <c>" << endl << " (" << ComParams().OutCtsStr() << " by default), where <c> is" << endl << " " << ComParams::OutCtsLst() << "." << endl << " --odsr=<c> - set DSR handshaking on output to <c>" << endl << " (" << ComParams().OutDsrStr() << " by default), where <c> is" << endl << " " << ComParams::OutDsrLst() << "." << endl << " --ox=<c> - set XON/XOFF handshaking on output to <c>" << endl << " (" << ComParams().OutXStr() << " by default), where <c> is" << endl << " " << ComParams::OutXLst() << "." << endl << " --ix=<c> - set XON/XOFF handshaking on input to <c>" << endl << " (" << ComParams().InXStr() << " by default), where <c> is" << endl << " " << ComParams::InXLst() << "." << endl << " If XON/XOFF handshaking on input is enabled for" << endl << " the port then XON/XOFF characters will be" << endl << " discarded from output to this port." << endl << " --idsr=<c> - set DSR sensitivity on input to <c>" << endl << " (" << ComParams().InDsrStr() << " by default), where <c> is" << endl << " " << ComParams::InDsrLst() << "." << endl << " --ito=<t> - set read interval timeout to <t> (" << ComParams().IntervalTimeoutStr() << " by default)," << endl << " where <t> is " << ComParams::IntervalTimeoutLst() << "." << endl << " --rt-events=<LstEv> - set events that should be handled in real-time to" << endl << " <LstEv> (" << ComParams().EventsStr() << " by default)." << endl << endl << " The value c[urrent] above means to use current COM port settings." << endl << " The syntax of <LstEv> above is" << endl << " " << ComParams::EventsLst() << "." << endl << endl << "Examples:" << endl << " " << pProgPath << " COM1 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl << " " << pProgPath << " --baud=9600 COM1 --baud=19200 \\\\.\\CNCB1" << endl ; } /////////////////////////////////////////////////////////////// static HCONFIG CALLBACK ConfigStart() { ComParams *pComParams = new ComParams; if (!pComParams) { cerr << "No enough memory." << endl; exit(2); } return (HCONFIG)pComParams; } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Config( HCONFIG hConfig, const char *pArg) { _ASSERTE(hConfig != NULL); ComParams &comParams = *(ComParams *)hConfig; const char *pParam; if ((pParam = GetParam(pArg, "--baud=")) != NULL) { if (!comParams.SetBaudRate(pParam)) { cerr << "Unknown baud rate value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--data=")) != NULL) { if (!comParams.SetByteSize(pParam)) { cerr << "Unknown data bits value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--parity=")) != NULL) { if (!comParams.SetParity(pParam)) { cerr << "Unknown parity value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--stop=")) != NULL) { if (!comParams.SetStopBits(pParam)) { cerr << "Unknown stop bits value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--octs=")) != NULL) { if (!comParams.SetOutCts(pParam)) { cerr << "Unknown CTS handshaking on output value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--odsr=")) != NULL) { if (!comParams.SetOutDsr(pParam)) { cerr << "Unknown DSR handshaking on output value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--ox=")) != NULL) { if (!comParams.SetOutX(pParam)) { cerr << "Unknown XON/XOFF handshaking on output value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--ix=")) != NULL) { if (!comParams.SetInX(pParam)) { cerr << "Unknown XON/XOFF handshaking on input value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--idsr=")) != NULL) { if (!comParams.SetInDsr(pParam)) { cerr << "Unknown DSR sensitivity value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--ito=")) != NULL) { if (!comParams.SetIntervalTimeout(pParam)) { cerr << "Unknown read interval timeout value in " << pArg << endl; exit(1); } } else if ((pParam = GetParam(pArg, "--rt-events=")) != NULL) { if (!comParams.SetEvents(pParam)) { cerr << "Unknown events in " << pArg << endl; exit(1); } } else { return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// static void CALLBACK ConfigStop( HCONFIG hConfig) { _ASSERTE(hConfig != NULL); delete (ComParams *)hConfig; } /////////////////////////////////////////////////////////////// static HPORT CALLBACK Create( HCONFIG hConfig, const char *pPath) { _ASSERTE(hConfig != NULL); ComPort *pPort = new ComPort(*(const ComParams *)hConfig, pPath); if (!pPort) return NULL; return (HPORT)pPort; } /////////////////////////////////////////////////////////////// static const char *CALLBACK GetPortName( HPORT hPort) { _ASSERTE(hPort != NULL); return ((ComPort *)hPort)->Name().c_str(); } /////////////////////////////////////////////////////////////// static void CALLBACK SetPortName( HPORT hPort, const char *pName) { _ASSERTE(hPort != NULL); _ASSERTE(pName != NULL); ((ComPort *)hPort)->Name(pName); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Init( HPORT hPort, HMASTERPORT hMasterPort, HHUB hHub) { _ASSERTE(hPort != NULL); _ASSERTE(hMasterPort != NULL); _ASSERTE(hHub != NULL); return ((ComPort *)hPort)->Init(hMasterPort, hHub); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Start(HPORT hPort) { _ASSERTE(hPort != NULL); return ((ComPort *)hPort)->Start(); } /////////////////////////////////////////////////////////////// static BOOL CALLBACK Write( HPORT hPort, HUB_MSG *pMsg) { _ASSERTE(hPort != NULL); _ASSERTE(pMsg != NULL); return ((ComPort *)hPort)->Write(pMsg); } /////////////////////////////////////////////////////////////// static void CALLBACK AddXoff( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->AddXoff(1); } /////////////////////////////////////////////////////////////// static void CALLBACK AddXon( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->AddXoff(-1); } /////////////////////////////////////////////////////////////// static void CALLBACK LostReport( HPORT hPort) { _ASSERTE(hPort != NULL); ((ComPort *)hPort)->LostReport(); } /////////////////////////////////////////////////////////////// static const PORT_ROUTINES_A routines = { sizeof(PORT_ROUTINES_A), GetPluginType, GetPluginAbout, Help, ConfigStart, Config, ConfigStop, Create, GetPortName, SetPortName, Init, Start, Write, AddXoff, AddXon, LostReport, }; static const PLUGIN_ROUTINES_A *const plugins[] = { (const PLUGIN_ROUTINES_A *)&routines, NULL }; /////////////////////////////////////////////////////////////// ROUTINE_BUF_ALLOC *pBufAlloc; ROUTINE_BUF_FREE *pBufFree; ROUTINE_ON_XOFF *pOnXoff; ROUTINE_ON_XON *pOnXon; ROUTINE_ON_READ *pOnRead; /////////////////////////////////////////////////////////////// PLUGIN_INIT_A InitA; const PLUGIN_ROUTINES_A *const * CALLBACK InitA( const HUB_ROUTINES_A * pHubRoutines) { if (!ROUTINE_IS_VALID(pHubRoutines, pBufAlloc) || !ROUTINE_IS_VALID(pHubRoutines, pBufFree) || !ROUTINE_IS_VALID(pHubRoutines, pOnXoff) || !ROUTINE_IS_VALID(pHubRoutines, pOnXon) || !ROUTINE_IS_VALID(pHubRoutines, pOnRead)) { return NULL; } pBufAlloc = pHubRoutines->pBufAlloc; pBufFree = pHubRoutines->pBufFree; pOnXoff = pHubRoutines->pOnXoff; pOnXon = pHubRoutines->pOnXon; pOnRead = pHubRoutines->pOnRead; return plugins; } /////////////////////////////////////////////////////////////// |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:40:49
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9648 Added Files: precomp.cpp precomp.h Log Message: Initial revision --- NEW FILE: precomp.cpp --- /* * $Id: precomp.cpp,v 1.1 2008/03/26 08:40:45 vfrolov Exp $ * * Copyright (c) 2007 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.cpp,v $ * Revision 1.1 2008/03/26 08:40:45 vfrolov * Initial revision * * Revision 1.1 2007/03/26 08:00:50 vfrolov * Initial revision * * */ /////////////////////////////////////////////////////////////// #include "precomp.h" /////////////////////////////////////////////////////////////// --- NEW FILE: precomp.h --- /* * $Id: precomp.h,v 1.1 2008/03/26 08:40:45 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/03/26 08:40:45 vfrolov * Initial revision * * */ #ifndef _PRECOMP_H_ #define _PRECOMP_H_ #define _WIN32_WINNT 0x0500 #include <windows.h> #include <crtdbg.h> #include <string> #include <vector> #include <map> #include <iostream> #include <fstream> #include <sstream> using namespace std; #pragma warning(disable:4512) // assignment operator could not be generated #endif /* _PRECOMP_H_ */ |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:38:40
|
Update of /cvsroot/com0com/hub4com/plugins In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8824 Added Files: plugins.def plugins_api.h Log Message: Initial revision --- NEW FILE: plugins.def --- EXPORTS InitA --- NEW FILE: plugins_api.h --- /* * $Id: plugins_api.h,v 1.1 2008/03/26 08:38:37 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: plugins_api.h,v $ * Revision 1.1 2008/03/26 08:38:37 vfrolov * Initial revision * * */ #ifndef _PLUGINS_API_H #define _PLUGINS_API_H #ifdef __cplusplus extern "C" { #endif /*******************************************************************/ #define HUB_MSG_UNION_TYPE_MASK 0xF000 #define HUB_MSG_UNION_TYPE_NONE 0x0000 #define HUB_MSG_UNION_TYPE_BUF 0x1000 #define HUB_MSG_UNION_TYPE_VAL 0x2000 /*******************************************************************/ #define HUB_MSG_TYPE_EMPTY (HUB_MSG_UNION_TYPE_NONE | 0) #define HUB_MSG_TYPE_LINE_DATA (HUB_MSG_UNION_TYPE_BUF | 1) #define HUB_MSG_TYPE_CONNECT (HUB_MSG_UNION_TYPE_VAL | 2) #define HUB_MSG_TYPE_MODEM_STATUS (HUB_MSG_UNION_TYPE_VAL | 3) #define HUB_MSG_TYPE_COM_ERRORS (HUB_MSG_UNION_TYPE_VAL | 4) #define HUB_MSG_TYPE_COM_FUNCTION (HUB_MSG_UNION_TYPE_VAL | 5) /*******************************************************************/ typedef struct _HUB_MSG { WORD type; union { struct { BYTE *pBuf; DWORD size; } buf; DWORD val; } u; } HUB_MSG; /*******************************************************************/ DECLARE_HANDLE(HHUB); DECLARE_HANDLE(HMASTERPORT); /*******************************************************************/ typedef BYTE *(CALLBACK ROUTINE_BUF_ALLOC)( DWORD size); typedef VOID (CALLBACK ROUTINE_BUF_FREE)( BYTE *pBuf); typedef HUB_MSG *(CALLBACK ROUTINE_MSG_REPLACE_BUF)( HUB_MSG *pMsg, WORD type, const BYTE *pSrc, DWORD sizeSrc); typedef HUB_MSG *(CALLBACK ROUTINE_MSG_INSERT_BUF)( HUB_MSG *pPrevMsg, WORD type, const BYTE *pSrc, DWORD sizeSrc); typedef HUB_MSG *(CALLBACK ROUTINE_MSG_REPLACE_VAL)( HUB_MSG *pMsg, WORD type, DWORD val); typedef HUB_MSG *(CALLBACK ROUTINE_MSG_INSERT_VAL)( HUB_MSG *pMsg, WORD type, DWORD val); typedef HUB_MSG *(CALLBACK ROUTINE_MSG_REPLACE_NONE)( HUB_MSG *pMsg, WORD type); typedef HUB_MSG *(CALLBACK ROUTINE_MSG_INSERT_NONE)( HUB_MSG *pMsg, WORD type); typedef int (CALLBACK ROUTINE_NUM_PORTS)( HHUB hHub); typedef const char *(CALLBACK ROUTINE_PORT_NAME_A)( HHUB hHub, int n); typedef void (CALLBACK ROUTINE_ON_XOFF)( HHUB hHub, HMASTERPORT hMasterPort); typedef void (CALLBACK ROUTINE_ON_XON)( HHUB hHub, HMASTERPORT hMasterPort); typedef void (CALLBACK ROUTINE_ON_READ)( HHUB hHub, HMASTERPORT hMasterPort, HUB_MSG *pMsg); /*******************************************************************/ typedef struct _HUB_ROUTINES_A { size_t size; ROUTINE_BUF_ALLOC *pBufAlloc; ROUTINE_BUF_FREE *pBufFree; ROUTINE_MSG_REPLACE_BUF *pMsgReplaceBuf; ROUTINE_MSG_INSERT_BUF *pMsgInsertBuf; ROUTINE_MSG_REPLACE_VAL *pMsgReplaceVal; ROUTINE_MSG_INSERT_VAL *pMsgInsertVal; ROUTINE_MSG_REPLACE_NONE *pMsgReplaceNone; ROUTINE_MSG_INSERT_NONE *pMsgInsertNone; ROUTINE_NUM_PORTS *pNumPorts; ROUTINE_PORT_NAME_A *pPortName; ROUTINE_ON_XOFF *pOnXoff; ROUTINE_ON_XON *pOnXon; ROUTINE_ON_READ *pOnRead; } HUB_ROUTINES_A; /*******************************************************************/ typedef enum _PLUGIN_TYPE { PLUGIN_TYPE_INVALID, PLUGIN_TYPE_FILTER, PLUGIN_TYPE_PORT, } PLUGIN_TYPE; /*******************************************************************/ DECLARE_HANDLE(HCONFIG); /*******************************************************************/ typedef struct _PLUGIN_ABOUT_A { size_t size; const char *pName; const char *pCopyright; const char *pLicense; const char *pDescription; } PLUGIN_ABOUT_A; /*******************************************************************/ typedef PLUGIN_TYPE (CALLBACK PLUGIN_GET_TYPE)(); typedef const PLUGIN_ABOUT_A *(CALLBACK PLUGIN_GET_ABOUT_A)(); typedef void (CALLBACK PLUGIN_HELP_A)( const char *pProgPath); typedef HCONFIG (CALLBACK PLUGIN_CONFIG_START)(); typedef BOOL (CALLBACK PLUGIN_CONFIG_A)( HCONFIG hConfig, const char *pArg); typedef void (CALLBACK PLUGIN_CONFIG_STOP)( HCONFIG hConfig); /*******************************************************************/ #define COMMON_PLUGIN_ROUTINES_A \ size_t size; \ PLUGIN_GET_TYPE *pGetPluginType; \ PLUGIN_GET_ABOUT_A *pGetPluginAbout; \ PLUGIN_HELP_A *pHelp; \ PLUGIN_CONFIG_START *pConfigStart; \ PLUGIN_CONFIG_A *pConfig; \ PLUGIN_CONFIG_STOP *pConfigStop; \ /*******************************************************************/ typedef struct _PLUGIN_ROUTINES_A { COMMON_PLUGIN_ROUTINES_A } PLUGIN_ROUTINES_A; /*******************************************************************/ #define PLUGIN_INIT_PROC_NAME "Init" #define PLUGIN_INIT_PROC_NAME_A PLUGIN_INIT_PROC_NAME "A" /*******************************************************************/ typedef const PLUGIN_ROUTINES_A *const *(CALLBACK PLUGIN_INIT_A)( const HUB_ROUTINES_A *pHubRoutines); /*******************************************************************/ DECLARE_HANDLE(HFILTER); /*******************************************************************/ typedef HFILTER (CALLBACK FILTER_CREATE_A)( HCONFIG hConfig, int argc, const char *const argv[]); typedef BOOL (CALLBACK FILTER_INIT)( HFILTER hFilter, HHUB hHub); typedef BOOL (CALLBACK FILTER_IN_METHOD)( HFILTER hFilter, int nFromPort, HUB_MSG *pInMsg, HUB_MSG **ppEchoMsg); typedef BOOL (CALLBACK FILTER_OUT_METHOD)( HFILTER hFilter, int nFromPort, int nToPort, HUB_MSG *pOutMsg); /*******************************************************************/ typedef struct _FILTER_ROUTINES_A { COMMON_PLUGIN_ROUTINES_A FILTER_CREATE_A *pCreate; FILTER_INIT *pInit; FILTER_IN_METHOD *pInMethod; FILTER_OUT_METHOD *pOutMethod; } FILTER_ROUTINES_A; /*******************************************************************/ DECLARE_HANDLE(HPORT); /*******************************************************************/ typedef HPORT (CALLBACK PORT_CREATE_A)( HCONFIG hConfig, const char *pPath); typedef const char *(CALLBACK PORT_GET_NAME_A)( HPORT hPort); typedef void (CALLBACK PORT_SET_NAME_A)( HPORT hPort, const char *pName); typedef BOOL (CALLBACK PORT_INIT)( HPORT hPort, HMASTERPORT hMasterPort, HHUB hHub); typedef BOOL (CALLBACK PORT_START)( HPORT hPort); typedef BOOL (CALLBACK PORT_WRITE)( HPORT hPort, HUB_MSG *pMsg); typedef void (CALLBACK PORT_ADD_XOFF)( HPORT hPort); typedef void (CALLBACK PORT_ADD_XON)( HPORT hPort); typedef void (CALLBACK PORT_LOST_REPORT)( HPORT hPort); /*******************************************************************/ typedef struct _PORT_ROUTINES_A { COMMON_PLUGIN_ROUTINES_A PORT_CREATE_A *pCreate; PORT_GET_NAME_A *pGetPortName; PORT_SET_NAME_A *pSetPortName; PORT_INIT *pInit; PORT_START *pStart; PORT_WRITE *pWrite; PORT_ADD_XOFF *pAddXoff; PORT_ADD_XON *pAddXon; PORT_LOST_REPORT *pLostReport; } PORT_ROUTINES_A; /*******************************************************************/ #define ROUTINE_GET(pStruct, pRoutine) \ ((((BYTE *)(&(pStruct)->pRoutine + 1)) <= ((BYTE *)(pStruct) + (pStruct)->size)) \ ? (pStruct)->pRoutine \ : NULL) #define ROUTINE_IS_VALID(pStruct, pRoutine) \ (ROUTINE_GET(pStruct, pRoutine) != NULL) /*******************************************************************/ #ifdef __cplusplus } #endif #endif /* _PLUGINS_API_H */ |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:38:10
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8785/serial Log Message: Directory /cvsroot/com0com/hub4com/plugins/serial added to the repository |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:37:41
|
Update of /cvsroot/com0com/hub4com/plugins In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8425/plugins Log Message: Directory /cvsroot/com0com/hub4com/plugins added to the repository |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:37:12
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8349 Added Files: route.cpp route.h Log Message: Initial revision --- NEW FILE: route.cpp --- /* * $Id: route.cpp,v 1.1 2008/03/26 08:37:06 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: route.cpp,v $ * Revision 1.1 2008/03/26 08:37:06 vfrolov * Initial revision * * */ #include "precomp.h" #include "route.h" /////////////////////////////////////////////////////////////// typedef pair<int, int> PortPair; /////////////////////////////////////////////////////////////// static PortNumMap::iterator FindPair(PortNumMap &map, const PortPair &pair) { PortNumMap::iterator i; for (i = map.find(pair.first) ; i != map.end() ; i++) { if (i->first != pair.first) return map.end(); if (i->second == pair.second) break; } return i; } void AddRoute( PortNumMap &map, int iFrom, int iTo, BOOL noRoute, BOOL noEcho) { if (iFrom != iTo || !noEcho || noRoute) { PortPair pair(iFrom, iTo); for (;;) { PortNumMap::iterator i = FindPair(map, pair); if (i == map.end()) { if (!noRoute) map.insert(pair); break; } else if (noRoute) { map.erase(i); } else { break; } } } } void SetFlowControlRoute( PortNumMap &routeFlowControlMap, PortNumMap &routeDataMap, BOOL fromAnyDataReceiver) { routeFlowControlMap.clear(); for (PortNumMap::const_iterator i = routeDataMap.begin() ; i != routeDataMap.end() ; i++) { PortPair pair(i->second, i->first); if (FindPair(routeFlowControlMap, pair) == routeFlowControlMap.end()) { if (fromAnyDataReceiver || FindPair(routeDataMap, pair) != routeDataMap.end()) routeFlowControlMap.insert(pair); } } } /////////////////////////////////////////////////////////////// --- NEW FILE: route.h --- /* * $Id: route.h,v 1.1 2008/03/26 08:37:06 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: route.h,v $ * Revision 1.1 2008/03/26 08:37:06 vfrolov * Initial revision * * */ #ifndef _ROUTE_H #define _ROUTE_H /////////////////////////////////////////////////////////////// typedef multimap<int, int> PortNumMap; /////////////////////////////////////////////////////////////// void AddRoute( PortNumMap &map, int iFrom, int iTo, BOOL noRoute, BOOL noEcho); void SetFlowControlRoute( PortNumMap &routeFlowControlMap, PortNumMap &routeDataMap, BOOL fromAnyDataReceiver); /////////////////////////////////////////////////////////////// #endif // _ROUTE_H |
From: Vyacheslav F. <vf...@us...> - 2008-03-26 08:36:50
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8007 Added Files: port.cpp port.h Log Message: Initial revision --- NEW FILE: port.h --- /* * $Id: port.h,v 1.1 2008/03/26 08:36:47 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: port.h,v $ * Revision 1.1 2008/03/26 08:36:47 vfrolov * Initial revision * * */ #ifndef _PORT_H #define _PORT_H #include "plugins/plugins_api.h" /////////////////////////////////////////////////////////////// class ComHub; class HubMsg; /////////////////////////////////////////////////////////////// #define PORT_SIGNATURE 'h4cP' /////////////////////////////////////////////////////////////// class Port { public: Port(ComHub &_hub, int _num, const PORT_ROUTINES_A *pPortRoutines, HPORT _hPort); #ifdef _DEBUG ~Port() { _ASSERTE(signature == PORT_SIGNATURE); signature = 0; } #endif BOOL Init(); BOOL Start(); BOOL Write(HubMsg *pMsg); void AddXoff(); void AddXon(); const string &Name() const { return name; } int Num() const { return num; } void LostReport(); private: ComHub &hub; int num; string name; HPORT hPort; PORT_INIT *pInit; PORT_START *pStart; PORT_WRITE *pWrite; PORT_ADD_XOFF *pAddXoff; PORT_ADD_XON *pAddXon; PORT_LOST_REPORT *pLostReport; #ifdef _DEBUG DWORD signature; public: BOOL IsValid() { return signature == PORT_SIGNATURE; } #endif }; /////////////////////////////////////////////////////////////// #endif // _PORT_H --- NEW FILE: port.cpp --- /* * $Id: port.cpp,v 1.1 2008/03/26 08:36:47 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: port.cpp,v $ * Revision 1.1 2008/03/26 08:36:47 vfrolov * Initial revision * * */ #include "precomp.h" #include "port.h" #include "comhub.h" /////////////////////////////////////////////////////////////// Port::Port(ComHub &_hub, int _num, const PORT_ROUTINES_A *pPortRoutines, HPORT _hPort) : hub(_hub), num(_num), hPort(_hPort) { #ifdef _DEBUG signature = PORT_SIGNATURE; #endif const char *pName = ROUTINE_IS_VALID(pPortRoutines, pGetPortName) ? pPortRoutines->pGetPortName(hPort) : NULL; stringstream buf; if (pName && *pName) { buf << pName; } else { buf << "P"; } buf << "(" << num << ")"; name = buf.str(); if (ROUTINE_IS_VALID(pPortRoutines, pSetPortName)) pPortRoutines->pSetPortName(hPort, name.c_str()); pInit = ROUTINE_GET(pPortRoutines, pInit); pStart = ROUTINE_GET(pPortRoutines, pStart); pWrite = ROUTINE_GET(pPortRoutines, pWrite); pAddXoff = ROUTINE_GET(pPortRoutines, pAddXoff); pAddXon = ROUTINE_GET(pPortRoutines, pAddXon); pLostReport = ROUTINE_GET(pPortRoutines, pLostReport); } BOOL Port::Init() { if (!pInit) return TRUE; return pInit(hPort, HMASTERPORT(this), HHUB(&hub)); } BOOL Port::Start() { if (!pStart) return TRUE; if (!pStart(hPort)) { cerr << "Can't start " << name << endl; return FALSE; } cout << "Started " << name << endl; return TRUE; } BOOL Port::Write(HubMsg *pMsg) { _ASSERTE(pMsg != NULL); if (!pWrite) return TRUE; return pWrite(hPort, (HUB_MSG *)pMsg); } void Port::AddXoff() { if (pAddXoff) pAddXoff(hPort); } void Port::AddXon() { if (pAddXon) pAddXon(hPort); } void Port::LostReport() { if (pLostReport) pLostReport(hPort); } /////////////////////////////////////////////////////////////// |