com0com-cvs Mailing List for Null-modem emulator (Page 29)
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...> - 2007-05-07 11:16:23
|
Update of /cvsroot/com0com/com2tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv2228 Modified Files: version.h Log Message: Pre-tagging version change Index: version.h =================================================================== RCS file: /cvsroot/com0com/com2tcp/version.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** version.h 25 Nov 2005 13:43:56 -0000 1.2 --- version.h 7 May 2007 11:16:18 -0000 1.3 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2005 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2005-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 23,32 **** #define _C2T_VERSION_H_ ! #define C2T_COPYRIGHT_YEARS "2005" #define C2T_V1 1 ! #define C2T_V2 2 #define C2T_V3 0 ! #define C2T_V4 1 #define MK_VERSION_STR1(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4 --- 23,32 ---- #define _C2T_VERSION_H_ ! #define C2T_COPYRIGHT_YEARS "2005-2007" #define C2T_V1 1 ! #define C2T_V2 3 #define C2T_V3 0 ! #define C2T_V4 0 #define MK_VERSION_STR1(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4 |
From: Vyacheslav F. <vf...@us...> - 2007-05-07 11:15:04
|
Update of /cvsroot/com0com/com2tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv1484 Modified Files: ReadMe.txt Log Message: Added more info. Index: ReadMe.txt =================================================================== RCS file: /cvsroot/com0com/com2tcp/ReadMe.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ReadMe.txt 3 Oct 2005 13:48:08 -0000 1.3 --- ReadMe.txt 7 May 2007 11:14:59 -0000 1.4 *************** *** 4,7 **** --- 4,8 ---- INTRODUCTION + ============ The COM port to TCP redirector is a Windows application and is a part *************** *** 10,24 **** In conjunction with the Null-modem emulator (com0com) the com2tcp enables to use a COM port based applications to communicate with the ! TCP/IP based applications. The homepage for com0com project is http://com0com.sourceforge.net/. BUILDING ! Start MSVC (v5 or v6) with com2tcp.dsw file. ! Set Active Configuration to com2tcp - Win32 Release". Build com2tcp.exe. EXAMPLE OF USAGE You have old TERM95.EXE application from the Norton Commander 5.0 for --- 11,28 ---- In conjunction with the Null-modem emulator (com0com) the com2tcp enables to use a COM port based applications to communicate with the ! TCP/IP based applications. It also allows communication with a remote ! serial port via the TCP/IP. The homepage for com0com project is http://com0com.sourceforge.net/. BUILDING + ======== ! Start Microsoft Visual C++ 2005 with hub4com.vcproj file. ! Set Active Configuration to "com2tcp - Win32 Release". Build com2tcp.exe. EXAMPLE OF USAGE + ================ You have old TERM95.EXE application from the Norton Commander 5.0 for |
From: Vyacheslav F. <vf...@us...> - 2007-05-07 11:10:59
|
Update of /cvsroot/com0com/com2tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv32403 Added Files: .cvsignore com2tcp.vcproj Log Message: Initial revision --- NEW FILE: .cvsignore --- *.ncb *.sln *.user *.suo Release Debug --- NEW FILE: com2tcp.vcproj --- <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" Version="8,00" Name="com2tcp" ProjectGUID="{4DF5E603-9690-4C6F-8C66-1D16613BCB17}" > <Platforms> <Platform Name="Win32" /> </Platforms> <ToolFiles> </ToolFiles> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory=".\Debug" IntermediateDirectory=".\Debug" ConfigurationType="1" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="false" CharacterSet="2" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" TypeLibraryName=".\Debug/com2tcp.tlb" HeaderFileName="" /> <Tool Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="1" PrecompiledHeaderFile=".\Debug/com2tcp.pch" AssemblerListingLocation=".\Debug/" ObjectFile=".\Debug/" ProgramDataBaseFileName=".\Debug/" BrowseInformation="1" WarningLevel="4" SuppressStartupBanner="true" DebugInformationFormat="4" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" PreprocessorDefinitions="_DEBUG" Culture="1049" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" AdditionalDependencies="odbc32.lib odbccp32.lib ws2_32.lib" OutputFile=".\Debug/com2tcp.exe" LinkIncremental="2" SuppressStartupBanner="true" GenerateDebugInformation="true" ProgramDatabaseFile=".\Debug/com2tcp.pdb" SubSystem="1" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" SuppressStartupBanner="true" OutputFile=".\Debug/com2tcp.bsc" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCWebDeploymentTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> <Configuration Name="Release|Win32" OutputDirectory=".\Release" IntermediateDirectory=".\Release" ConfigurationType="1" InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="false" CharacterSet="2" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" TypeLibraryName=".\Release/com2tcp.tlb" HeaderFileName="" /> <Tool Name="VCCLCompilerTool" Optimization="2" InlineFunctionExpansion="1" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" StringPooling="true" RuntimeLibrary="0" EnableFunctionLevelLinking="true" PrecompiledHeaderFile=".\Release/com2tcp.pch" AssemblerListingLocation=".\Release/" ObjectFile=".\Release/" ProgramDataBaseFileName=".\Release/" BrowseInformation="1" WarningLevel="4" SuppressStartupBanner="true" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" PreprocessorDefinitions="NDEBUG" Culture="1049" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" AdditionalDependencies="odbc32.lib odbccp32.lib ws2_32.lib" OutputFile=".\Release/com2tcp.exe" LinkIncremental="1" SuppressStartupBanner="true" ProgramDatabaseFile=".\Release/com2tcp.pdb" SubSystem="1" TargetMachine="1" /> <Tool Name="VCALinkTool" /> <Tool Name="VCManifestTool" /> <Tool Name="VCXDCMakeTool" /> <Tool Name="VCBscMakeTool" SuppressStartupBanner="true" OutputFile=".\Release/com2tcp.bsc" /> <Tool Name="VCFxCopTool" /> <Tool Name="VCAppVerifierTool" /> <Tool Name="VCWebDeploymentTool" /> <Tool Name="VCPostBuildEventTool" /> </Configuration> </Configurations> <References> </References> <Files> <Filter Name="Source Files" Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > <File RelativePath="com2tcp.cpp" > <FileConfiguration Name="Debug|Win32" > <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> <FileConfiguration Name="Release|Win32" > <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> </File> <File RelativePath="com2tcp.rc" > <FileConfiguration Name="Debug|Win32" > <Tool Name="VCResourceCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> <FileConfiguration Name="Release|Win32" > <Tool Name="VCResourceCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> </File> <File RelativePath="telnet.cpp" > <FileConfiguration Name="Debug|Win32" > <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> <FileConfiguration Name="Release|Win32" > <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> </File> <File RelativePath="utils.cxx" > <FileConfiguration Name="Debug|Win32" > <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> <FileConfiguration Name="Release|Win32" > <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="" /> </FileConfiguration> </File> </Filter> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl" > <File RelativePath="precomp.h" > </File> <File RelativePath="telnet.h" > </File> <File RelativePath="utils.h" > </File> </Filter> <Filter Name="Resource Files" Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" > </Filter> <File RelativePath="ReadMe.txt" > </File> </Files> <Globals> </Globals> </VisualStudioProject> |
From: Vyacheslav F. <vf...@us...> - 2007-04-16 07:33:41
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv22841 Modified Files: comport.cpp Log Message: Fixed LostReport() Index: comport.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comport.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** comport.cpp 6 Feb 2007 11:53:33 -0000 1.3 --- comport.cpp 16 Apr 2007 07:33:38 -0000 1.4 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 200,207 **** cout << "Error " << name << ":"; ! if (errors & CE_RXOVER) { cout << " RXOVER"; } ! if (errors & CE_OVERRUN) { cout << " OVERRUN"; } ! if (errors & CE_RXPARITY) { cout << " RXPARITY"; } ! if (errors & CE_FRAME) { cout << " FRAME"; } #define IOCTL_SERIAL_GET_STATS CTL_CODE(FILE_DEVICE_SERIAL_PORT,35,METHOD_BUFFERED,FILE_ANY_ACCESS) --- 203,213 ---- 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; } #define IOCTL_SERIAL_GET_STATS CTL_CODE(FILE_DEVICE_SERIAL_PORT,35,METHOD_BUFFERED,FILE_ANY_ACCESS) |
From: Vyacheslav F. <vf...@us...> - 2007-04-16 07:31:38
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv22010 Modified Files: ReadMe.txt Log Message: Added example about GPS Index: ReadMe.txt =================================================================== RCS file: /cvsroot/com0com/hub4com/ReadMe.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ReadMe.txt 1 Feb 2007 12:06:32 -0000 1.2 --- ReadMe.txt 16 Apr 2007 07:31:35 -0000 1.3 *************** *** 12,16 **** ports and vice versa. In conjunction with the com0com driver the hub4com makes it possible to handle data from a single serial device by a number ! of different applications. The homepage for com0com project is http://com0com.sourceforge.net/. --- 12,17 ---- ports and vice versa. In conjunction with the com0com driver the hub4com makes it possible to handle data from a single serial device by a number ! of different applications. For example, several applications can share ! data from one GPS device. The homepage for com0com project is http://com0com.sourceforge.net/. |
From: Vyacheslav F. <vf...@us...> - 2007-04-16 07:29:25
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv21247 Modified Files: version.h Log Message: Post-tagging version change Index: version.h =================================================================== RCS file: /cvsroot/com0com/hub4com/version.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** version.h 23 Jan 2007 09:13:10 -0000 1.1 --- version.h 16 Apr 2007 07:29:22 -0000 1.2 *************** *** 28,32 **** #define H4C_V2 0 #define H4C_V3 0 ! #define H4C_V4 0 #define MK_VERSION_STR1(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4 --- 28,32 ---- #define H4C_V2 0 #define H4C_V3 0 ! #define H4C_V4 1 #define MK_VERSION_STR1(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4 |
From: Vyacheslav F. <vf...@us...> - 2007-03-26 13:45:08
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29027 Modified Files: hub4com.vcproj Log Message: Link with static runtime library Precompile header Index: hub4com.vcproj =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** hub4com.vcproj 23 Jan 2007 09:13:10 -0000 1.1 --- hub4com.vcproj 26 Mar 2007 08:03:49 -0000 1.2 *************** *** 21,24 **** --- 21,25 ---- IntermediateDirectory="Debug" ConfigurationType="1" + UseOfMFC="0" > <Tool *************** *** 43,49 **** MinimalRebuild="true" BasicRuntimeChecks="3" ! RuntimeLibrary="3" ! UsePrecompiledHeader="0" ! PrecompiledHeaderFile="" WarningLevel="4" Detect64BitPortabilityProblems="true" --- 44,51 ---- MinimalRebuild="true" BasicRuntimeChecks="3" ! RuntimeLibrary="1" ! UsePrecompiledHeader="2" ! PrecompiledHeaderThrough="precomp.h" ! PrecompiledHeaderFile="$(IntDir)\precomp.pch" WarningLevel="4" Detect64BitPortabilityProblems="true" *************** *** 96,99 **** --- 98,102 ---- IntermediateDirectory="Release" ConfigurationType="1" + UseOfMFC="0" > <Tool *************** *** 115,121 **** Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" ! RuntimeLibrary="2" ! UsePrecompiledHeader="0" ! PrecompiledHeaderFile="" WarningLevel="4" Detect64BitPortabilityProblems="true" --- 118,125 ---- Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" ! RuntimeLibrary="0" ! UsePrecompiledHeader="2" ! PrecompiledHeaderThrough="precomp.h" ! PrecompiledHeaderFile="$(IntDir)\precomp.pch" WarningLevel="4" Detect64BitPortabilityProblems="true" *************** *** 239,242 **** --- 243,266 ---- </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" > |
From: Vyacheslav F. <vf...@us...> - 2007-03-26 13:45:07
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv27905 Added Files: precomp.cpp Log Message: Initial revision --- NEW FILE: precomp.cpp --- /* * $Id: precomp.cpp,v 1.1 2007/03/26 08:00:50 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 2007/03/26 08:00:50 vfrolov * Initial revision * * */ /////////////////////////////////////////////////////////////// #include "precomp.h" /////////////////////////////////////////////////////////////// |
From: Vyacheslav F. <vf...@us...> - 2007-02-28 13:58:51
|
Update of /cvsroot/com0com/homepage In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv19725 Modified Files: index.html Log Message: Added hub4com Index: index.html =================================================================== RCS file: /cvsroot/com0com/homepage/index.html,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** index.html 17 Oct 2006 11:24:18 -0000 1.5 --- index.html 28 Feb 2007 13:58:44 -0000 1.6 *************** *** 37,49 **** <p> The Null-modem emulator can be used to provide serial interface for COM port redirectors. ! For example, with com2tcp ("COM port to TCP redirector", part of the <a href="http://sourceforge.net/projects/com0com/">com0com</a> project) you can communicate via serial interface with the TCP/IP servers. </p> <p>You can find more information in <a href="http://com0com.cvs.sourceforge.net/*checkout*/com0com/com0com/ReadMe.txt?revision=RELEASED"> ReadMe.txt for com0com</a>, <a href="http://com0com.cvs.sourceforge.net/*checkout*/com0com/com2tcp/ReadMe.txt?revision=RELEASED"> ! ReadMe.txt for com2tcp</a> and on <a href="http://sourceforge.net/projects/com0com/">SourceForge Project --- 37,63 ---- <p> The Null-modem emulator can be used to provide serial interface for COM port redirectors. ! For example, with the com2tcp ( ! <a href="http://com0com.cvs.sourceforge.net/*checkout*/com0com/com2tcp/ReadMe.txt?revision=RELEASED"> ! COM port to TCP redirector</a>, ! part of the <a href="http://sourceforge.net/projects/com0com/">com0com</a> project) you can communicate via serial interface with the TCP/IP servers. </p> + <p> + With the hub4com ( + <a href="http://com0com.cvs.sourceforge.net/*checkout*/com0com/hub4com/ReadMe.txt?revision=RELEASED"> + HUB for COM ports</a>, + part of the + <a href="http://sourceforge.net/projects/com0com/">com0com</a> + project) it is possible to handle data from a single serial device by a number of different + applications. For example, several applications can share data from one GPS device. + </p> <p>You can find more information in <a href="http://com0com.cvs.sourceforge.net/*checkout*/com0com/com0com/ReadMe.txt?revision=RELEASED"> ReadMe.txt for com0com</a>, <a href="http://com0com.cvs.sourceforge.net/*checkout*/com0com/com2tcp/ReadMe.txt?revision=RELEASED"> ! ReadMe.txt for com2tcp</a>, ! <a href="http://com0com.cvs.sourceforge.net/*checkout*/com0com/hub4com/ReadMe.txt?revision=RELEASED"> ! ReadMe.txt for hub4com</a> and on <a href="http://sourceforge.net/projects/com0com/">SourceForge Project |
From: Vyacheslav F. <vf...@us...> - 2007-02-21 16:52:38
|
Update of /cvsroot/com0com/com0com/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv22117 Modified Files: trace.c trace.h tracetbl.c Log Message: Added tracing of IRP_MJ_POWER with more details Index: trace.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/trace.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** trace.c 20 Feb 2007 12:01:47 -0000 1.25 --- trace.c 21 Feb 2007 16:52:34 -0000 1.26 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.26 2007/02/21 16:52:34 vfrolov + * Added tracing of IRP_MJ_POWER with more details + * * Revision 1.25 2007/02/20 12:01:47 vfrolov * Added result dumping SERIAL_XOFF_COUNTER *************** *** 124,127 **** --- 127,131 ---- #define TRACE_BUF_SIZE 256 #define TRACE_BUFS_NUM 4 + #define TRACE_IRQL_BUF_SIZE 1024 /********************************************************************/ typedef struct _TRACE_BUFFER { *************** *** 149,153 **** static UNICODE_STRING traceFileName; static PDRIVER_OBJECT pDrvObj; ! static KSPIN_LOCK strOldLock; static KSPIN_LOCK bufsLock; static TRACE_BUFFER traceBufs[TRACE_BUFS_NUM]; --- 153,157 ---- static UNICODE_STRING traceFileName; static PDRIVER_OBJECT pDrvObj; ! static KSPIN_LOCK irqlBufLock; static KSPIN_LOCK bufsLock; static TRACE_BUFFER traceBufs[TRACE_BUFS_NUM]; *************** *** 945,951 **** IO_STATUS_BLOCK ioStatusBlock; ! static CHAR strOld[500]; ! static LONG strOldBusyInd = 0; ! static LONG strOldFreeInd = 0; if (errorCount > TRACE_ERROR_LIMIT) { --- 949,955 ---- IO_STATUS_BLOCK ioStatusBlock; ! static CHAR irqlBuf[TRACE_IRQL_BUF_SIZE]; ! static LONG irqlBufBusyInd = 0; ! static LONG irqlBufFreeInd = 0; if (errorCount > TRACE_ERROR_LIMIT) { *************** *** 968,979 **** GetTimeFields(&timeFields); ! KeAcquireSpinLock(&strOldLock, &oldIrql); ! size = sizeof(strOld) - strOldFreeInd; ! pDestStr = strOld + (sizeof(strOld) - size); pDestStr = AnsiStrCopyTimeFields(pDestStr, &size, &timeFields); pDestStr = AnsiStrFormat(pDestStr, &size, " *%u* %s\r\n", (unsigned)KeGetCurrentIrql(), pStr); ! HALT_UNLESS3(size > 0, strOldFreeInd, strOldBusyInd, sizeof(strOld)); if (size == 1) { --- 972,983 ---- GetTimeFields(&timeFields); ! KeAcquireSpinLock(&irqlBufLock, &oldIrql); ! size = sizeof(irqlBuf) - irqlBufFreeInd; ! pDestStr = irqlBuf + (sizeof(irqlBuf) - size); pDestStr = AnsiStrCopyTimeFields(pDestStr, &size, &timeFields); pDestStr = AnsiStrFormat(pDestStr, &size, " *%u* %s\r\n", (unsigned)KeGetCurrentIrql(), pStr); ! HALT_UNLESS3(size > 0, irqlBufFreeInd, irqlBufBusyInd, sizeof(irqlBuf)); if (size == 1) { *************** *** 983,989 **** } ! strOldFreeInd = (LONG)(sizeof(strOld) - size); ! KeReleaseSpinLock(&strOldLock, oldIrql); return; --- 987,993 ---- } ! irqlBufFreeInd = (LONG)(sizeof(irqlBuf) - size); ! KeReleaseSpinLock(&irqlBufLock, oldIrql); return; *************** *** 1024,1044 **** pDestStr = pBuf->buf; ! while (strOldFreeInd) { SIZE_T lenBuf; KIRQL oldIrql; ! KeAcquireSpinLock(&strOldLock, &oldIrql); ! lenBuf = strOldFreeInd - strOldBusyInd; if (lenBuf) { if (lenBuf > size - 1) lenBuf = size - 1; ! RtlCopyMemory(pDestStr, &strOld[strOldBusyInd], lenBuf); pDestStr[lenBuf] = 0; ! strOldBusyInd += (LONG)lenBuf; ! HALT_UNLESS3(strOldBusyInd <= strOldFreeInd, strOldFreeInd, strOldBusyInd, lenBuf); ! if (strOldBusyInd == strOldFreeInd) ! strOldFreeInd = strOldBusyInd = 0; } ! KeReleaseSpinLock(&strOldLock, oldIrql); if (lenBuf) --- 1028,1048 ---- pDestStr = pBuf->buf; ! while (irqlBufFreeInd) { SIZE_T lenBuf; KIRQL oldIrql; ! KeAcquireSpinLock(&irqlBufLock, &oldIrql); ! lenBuf = irqlBufFreeInd - irqlBufBusyInd; if (lenBuf) { if (lenBuf > size - 1) lenBuf = size - 1; ! RtlCopyMemory(pDestStr, &irqlBuf[irqlBufBusyInd], lenBuf); pDestStr[lenBuf] = 0; ! irqlBufBusyInd += (LONG)lenBuf; ! HALT_UNLESS3(irqlBufBusyInd <= irqlBufFreeInd, irqlBufFreeInd, irqlBufBusyInd, lenBuf); ! if (irqlBufBusyInd == irqlBufFreeInd) ! irqlBufFreeInd = irqlBufBusyInd = 0; } ! KeReleaseSpinLock(&irqlBufLock, oldIrql); if (lenBuf) *************** *** 1117,1121 **** pDrvObj = _pDrvObj; ! KeInitializeSpinLock(&strOldLock); KeInitializeSpinLock(&bufsLock); skippedTraces = 0; --- 1121,1125 ---- pDrvObj = _pDrvObj; ! KeInitializeSpinLock(&irqlBufLock); KeInitializeSpinLock(&bufsLock); skippedTraces = 0; *************** *** 1530,1534 **** break; case IRP_MN_QUERY_INTERFACE: - pDestStr = AnsiStrCopyStr(pDestStr, &size, " "); pDestStr = AnsiStrFormat(pDestStr, &size, " GUID: %8lX-%4X-%4X-%2X%2X-%2X%2X%2X%2X%2X%2X", --- 1534,1537 ---- *************** *** 1553,1556 **** --- 1556,1600 ---- pDestStr = AnsiStrCopyStr(pDestStr, &size, " "); pDestStr = AnsiStrCopyCode(pDestStr, &size, code, codeNameTablePower, "POWER_", 10); + + if ((flags & TRACE_FLAG_PARAMS) == 0) + break; + + switch (code) { + case IRP_MN_SET_POWER: + case IRP_MN_QUERY_POWER: { + POWER_STATE_TYPE powerType = pIrpStack->Parameters.Power.Type; + POWER_STATE powerState = pIrpStack->Parameters.Power.State; + + pDestStr = AnsiStrCopyStr(pDestStr, &size, " "); + pDestStr = AnsiStrCopyCode(pDestStr, &size, powerType, codeNameTablePowerType, "Type_", 10); + pDestStr = AnsiStrCopyStr(pDestStr, &size, " "); + + switch (powerType) { + case DevicePowerState: + pDestStr = AnsiStrCopyCode(pDestStr, &size, powerState.DeviceState, + codeNameTableDevicePowerState, "State_", 10); + break; + case SystemPowerState: + pDestStr = AnsiStrCopyCode(pDestStr, &size, powerState.SystemState, + codeNameTableSystemPowerState, "State_", 10); + break; + default: + pDestStr = AnsiStrCopyCode(pDestStr, &size, powerState.SystemState, NULL, "State_", 10); + break; + } + + pDestStr = AnsiStrCopyStr(pDestStr, &size, " "); + pDestStr = AnsiStrCopyCode(pDestStr, &size, pIrpStack->Parameters.Power.ShutdownType, + codeNameTablePowerAction, "Action_", 10); + break; + } + case IRP_MN_WAIT_WAKE: { + SYSTEM_POWER_STATE powerState = pIrpStack->Parameters.WaitWake.PowerState; + + pDestStr = AnsiStrCopyStr(pDestStr, &size, " Sys "); + pDestStr = AnsiStrCopyCode(pDestStr, &size, powerState, codeNameTableSystemPowerState, "State_", 10); + break; + } + } break; } Index: trace.h =================================================================== RCS file: /cvsroot/com0com/com0com/sys/trace.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** trace.h 23 Aug 2006 12:56:20 -0000 1.10 --- trace.h 21 Feb 2007 16:52:34 -0000 1.11 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.11 2007/02/21 16:52:34 vfrolov + * Added tracing of IRP_MJ_POWER with more details + * * Revision 1.10 2006/08/23 12:56:20 vfrolov * Added codeNameTableWmi *************** *** 122,125 **** --- 125,132 ---- CODE2NAME codeNameTablePnp[]; CODE2NAME codeNameTablePower[]; + CODE2NAME codeNameTablePowerType[]; + CODE2NAME codeNameTableSystemPowerState[]; + CODE2NAME codeNameTableDevicePowerState[]; + CODE2NAME codeNameTablePowerAction[]; CODE2NAME codeNameTableWmi[]; CODE2NAME codeNameTableDoType[]; Index: tracetbl.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/tracetbl.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tracetbl.c 20 Feb 2007 11:57:59 -0000 1.11 --- tracetbl.c 21 Feb 2007 16:52:34 -0000 1.12 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.12 2007/02/21 16:52:34 vfrolov + * Added tracing of IRP_MJ_POWER with more details + * * Revision 1.11 2007/02/20 11:57:59 vfrolov * Added STATUS_SERIAL_COUNTER_TIMEOUT and STATUS_SERIAL_MORE_WRITES *************** *** 180,183 **** --- 183,226 ---- }; + CODE2NAME codeNameTablePowerType[] = { + {SystemPowerState, "Sys"}, + {DevicePowerState, "Dev"}, + {0, NULL} + }; + + CODE2NAME codeNameTableSystemPowerState[] = { + TOCODE2NAME(PowerSystem, Unspecified), + TOCODE2NAME(PowerSystem, Working), + TOCODE2NAME(PowerSystem, Sleeping1), + TOCODE2NAME(PowerSystem, Sleeping2), + TOCODE2NAME(PowerSystem, Sleeping3), + TOCODE2NAME(PowerSystem, Hibernate), + TOCODE2NAME(PowerSystem, Shutdown), + TOCODE2NAME(PowerSystem, Maximum), + {0, NULL} + }; + + CODE2NAME codeNameTableDevicePowerState[] = { + TOCODE2NAME(PowerDevice, Unspecified), + TOCODE2NAME(PowerDevice, D0), + TOCODE2NAME(PowerDevice, D1), + TOCODE2NAME(PowerDevice, D2), + TOCODE2NAME(PowerDevice, D3), + TOCODE2NAME(PowerDevice, Maximum), + {0, NULL} + }; + + CODE2NAME codeNameTablePowerAction[] = { + TOCODE2NAME(PowerAction, None), + TOCODE2NAME(PowerAction, Reserved), + TOCODE2NAME(PowerAction, Sleep), + TOCODE2NAME(PowerAction, Hibernate), + TOCODE2NAME(PowerAction, Shutdown), + TOCODE2NAME(PowerAction, ShutdownReset), + TOCODE2NAME(PowerAction, ShutdownOff), + TOCODE2NAME(PowerAction, WarmEject), + {0, NULL} + }; + CODE2NAME codeNameTableWmi[] = { TOCODE2NAME(IRP_MN_, QUERY_ALL_DATA), |
From: Vyacheslav F. <vf...@us...> - 2007-02-21 16:48:50
|
Update of /cvsroot/com0com/com0com/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv20419 Modified Files: power.c Log Message: Added MajorFunction checking Index: power.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/power.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** power.c 17 Jul 2006 10:03:54 -0000 1.2 --- power.c 21 Feb 2007 16:48:44 -0000 1.3 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.3 2007/02/21 16:48:44 vfrolov + * Added MajorFunction checking + * * Revision 1.2 2006/07/17 10:03:54 vfrolov * Moved pIrpStack *************** *** 31,34 **** --- 34,42 ---- #include "precomp.h" + /* + * FILE_ID used by HALT_UNLESS to put it on BSOD + */ + #define FILE_ID 0xC + NTSTATUS PdoPortPower( IN PC0C_PDOPORT_EXTENSION pDevExt, *************** *** 37,48 **** NTSTATUS status; PIO_STACK_LOCATION pIrpStack = IoGetCurrentIrpStackLocation(pIrp); - POWER_STATE_TYPE powerType = pIrpStack->Parameters.Power.Type; - POWER_STATE powerState = pIrpStack->Parameters.Power.State; switch (pIrpStack->MinorFunction) { case IRP_MN_SET_POWER: ! switch (powerType) { case DevicePowerState: ! PoSetPowerState(pDevExt->pDevObj, powerType, powerState); status = STATUS_SUCCESS; break; --- 45,54 ---- NTSTATUS status; PIO_STACK_LOCATION pIrpStack = IoGetCurrentIrpStackLocation(pIrp); switch (pIrpStack->MinorFunction) { case IRP_MN_SET_POWER: ! switch (pIrpStack->Parameters.Power.Type) { case DevicePowerState: ! PoSetPowerState(pDevExt->pDevObj, DevicePowerState, pIrpStack->Parameters.Power.State); status = STATUS_SUCCESS; break; *************** *** 80,86 **** PC0C_COMMON_EXTENSION pDevExt = pDevObj->DeviceExtension; ! TraceIrp("c0cPowerDispatch", pIrp, NULL, TRACE_FLAG_PARAMS); ! status = STATUS_NO_SUCH_DEVICE; switch (pDevExt->doType) { --- 86,94 ---- PC0C_COMMON_EXTENSION pDevExt = pDevObj->DeviceExtension; ! HALT_UNLESS2(IoGetCurrentIrpStackLocation(pIrp)->MajorFunction == IRP_MJ_POWER, ! IoGetCurrentIrpStackLocation(pIrp)->MajorFunction, ! IoGetCurrentIrpStackLocation(pIrp)->MinorFunction); ! TraceIrp("POWER", pIrp, NULL, TRACE_FLAG_PARAMS); switch (pDevExt->doType) { *************** *** 95,98 **** --- 103,107 ---- break; default: + status = STATUS_NO_SUCH_DEVICE; pIrp->IoStatus.Status = status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); |
From: Vyacheslav F. <vf...@us...> - 2007-02-20 12:05:21
|
Update of /cvsroot/com0com/com0com/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv28914 Modified Files: com0com.h io.c ioctl.c startirp.c timeout.c timeout.h write.c Log Message: Implemented IOCTL_SERIAL_XOFF_COUNTER Fixed cancel and timeout routines Index: ioctl.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/ioctl.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** ioctl.c 15 Jan 2007 16:07:12 -0000 1.28 --- ioctl.c 20 Feb 2007 12:05:11 -0000 1.29 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.29 2007/02/20 12:05:11 vfrolov + * Implemented IOCTL_SERIAL_XOFF_COUNTER + * Fixed cancel and timeout routines + * * Revision 1.28 2007/01/15 16:07:12 vfrolov * Fixed non zero Information for IOCTL_SERIAL_PURGE and IOCTL_SERIAL_LSRMST_INSERT *************** *** 316,319 **** --- 320,326 ---- status = FdoPortImmediateChar(pIoPortLocal, pIrp, pIrpStack); break; + case IOCTL_SERIAL_XOFF_COUNTER: + status = FdoPortXoffCounter(pIoPortLocal, pIrp, pIrpStack); + break; case IOCTL_SERIAL_PURGE: { LIST_ENTRY queueToComplete; Index: com0com.h =================================================================== RCS file: /cvsroot/com0com/com0com/sys/com0com.h,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** com0com.h 11 Jan 2007 14:44:52 -0000 1.32 --- com0com.h 20 Feb 2007 12:05:11 -0000 1.33 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.33 2007/02/20 12:05:11 vfrolov + * Implemented IOCTL_SERIAL_XOFF_COUNTER + * Fixed cancel and timeout routines + * * Revision 1.32 2007/01/11 14:44:52 vfrolov * Defined *************** *** 227,230 **** --- 231,235 ---- SERIAL_CHARS specialChars; + LONG xoffCounter; ULONG errors; ULONG amountInWriteQueue; *************** *** 338,341 **** --- 343,347 ---- IN PC0C_FDOPORT_START_ROUTINE pStartRoutine); + VOID CompleteIrp(PIRP pIrp, NTSTATUS status, PLIST_ENTRY pQueueToComplete); VOID CancelQueue(PC0C_IRP_QUEUE pQueue, PLIST_ENTRY pQueueToComplete); VOID FdoPortCancelQueues(IN PC0C_IO_PORT pIoPort); *************** *** 347,350 **** --- 353,361 ---- IN PIO_STACK_LOCATION pIrpStack); + NTSTATUS FdoPortXoffCounter( + IN PC0C_IO_PORT pIoPort, + IN PIRP pIrp, + IN PIO_STACK_LOCATION pIrpStack); + NTSTATUS FdoPortWaitOnMask( IN PC0C_IO_PORT pIoPort, *************** *** 372,375 **** --- 383,387 ---- #define C0C_IRP_FLAG_WAIT_ONE 0x04 #define C0C_IRP_FLAG_INTERVAL_TIMEOUT 0x08 + #define C0C_IRP_FLAG_EXPIRED 0x10 UCHAR flags; Index: startirp.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/startirp.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** startirp.c 22 Jan 2007 17:05:16 -0000 1.15 --- startirp.c 20 Feb 2007 12:05:11 -0000 1.16 *************** *** 20,25 **** * * $Log$ * Revision 1.15 2007/01/22 17:05:16 vfrolov ! * Added missing 1IoMarkIrpPending() * * Revision 1.14 2007/01/15 16:09:16 vfrolov --- 20,29 ---- * * $Log$ + * Revision 1.16 2007/02/20 12:05:11 vfrolov + * Implemented IOCTL_SERIAL_XOFF_COUNTER + * Fixed cancel and timeout routines + * * Revision 1.15 2007/01/22 17:05:16 vfrolov ! * Added missing IoMarkIrpPending() * * Revision 1.14 2007/01/15 16:09:16 vfrolov *************** *** 91,94 **** --- 95,99 ---- case IOCTL_SERIAL_WAIT_ON_MASK: case IOCTL_SERIAL_IMMEDIATE_CHAR: + case IOCTL_SERIAL_XOFF_COUNTER: return (PC0C_IRP_STATE)&pIrpStack->Parameters.DeviceIoControl.Type3InputBuffer; } *************** *** 134,137 **** --- 139,143 ---- VOID CancelRoutine(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp) { + LIST_ENTRY queueToComplete; PC0C_IO_PORT pIoPort; PC0C_IRP_STATE pState; *************** *** 147,150 **** --- 153,158 ---- pQueue = &pIoPort->irpQueues[pState->iQueue]; + InitializeListHead(&queueToComplete); + KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql); *************** *** 159,172 **** } ! if (pState->flags & C0C_IRP_FLAG_IS_CURRENT) ShiftQueue(pQueue); KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); ! TraceIrp("cancel", pIrp, NULL, TRACE_FLAG_RESULTS); ! pIrp->IoStatus.Status = STATUS_CANCELLED; ! pIrp->IoStatus.Information = 0; ! IoCompleteRequest(pIrp, IO_SERIAL_INCREMENT); } --- 167,197 ---- } ! pIrp->IoStatus.Status = STATUS_CANCELLED; ! InsertTailList(&queueToComplete, &pIrp->Tail.Overlay.ListEntry); ! ! if (pState->flags & C0C_IRP_FLAG_IS_CURRENT) { ShiftQueue(pQueue); + if (pState->iQueue == C0C_QUEUE_WRITE) + ReadWrite(pIoPort->pIoPortRemote, FALSE, pIoPort, FALSE, &queueToComplete); + } + KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); ! FdoPortCompleteQueue(&queueToComplete); ! } ! VOID CompleteIrp(PIRP pIrp, NTSTATUS status, PLIST_ENTRY pQueueToComplete) ! { ! PDRIVER_CANCEL pCancelRoutine; ! ! #pragma warning(push, 3) ! pCancelRoutine = IoSetCancelRoutine(pIrp, NULL); ! #pragma warning(pop) ! ! if (pCancelRoutine) { ! pIrp->IoStatus.Status = status; ! InsertTailList(pQueueToComplete, &pIrp->Tail.Overlay.ListEntry); ! } } *************** *** 174,192 **** { while (pQueue->pCurrent) { - PDRIVER_CANCEL pCancelRoutine; PIRP pIrp; pIrp = pQueue->pCurrent; - - #pragma warning(push, 3) - pCancelRoutine = IoSetCancelRoutine(pIrp, NULL); - #pragma warning(pop) - ShiftQueue(pQueue); ! if (pCancelRoutine) { ! pIrp->IoStatus.Status = STATUS_CANCELLED; ! InsertTailList(pQueueToComplete, &pIrp->Tail.Overlay.ListEntry); ! } } } --- 199,208 ---- { while (pQueue->pCurrent) { PIRP pIrp; pIrp = pQueue->pCurrent; ShiftQueue(pQueue); ! CompleteIrp(pIrp, STATUS_CANCELLED, pQueueToComplete); } } *************** *** 218,221 **** --- 234,245 ---- pListEntry = RemoveHeadList(pQueueToComplete); pIrp = CONTAINING_RECORD(pListEntry, IRP, Tail.Overlay.ListEntry); + pIrpStack = IoGetCurrentIrpStackLocation(pIrp); + + if (pIrp->IoStatus.Status == STATUS_TIMEOUT && pIrp->IoStatus.Information && + pIrpStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && + pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER) + { + pIrp->IoStatus.Status = STATUS_SERIAL_COUNTER_TIMEOUT; + } TraceIrp("complete", pIrp, &pIrp->IoStatus.Status, TRACE_FLAG_RESULTS); *************** *** 236,244 **** } - pIrpStack = IoGetCurrentIrpStackLocation(pIrp); - if (pIrp->IoStatus.Status == STATUS_CANCELLED || (pIrpStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && ! pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR)) { pIrp->IoStatus.Information = 0; --- 260,267 ---- } if (pIrp->IoStatus.Status == STATUS_CANCELLED || (pIrpStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && ! (pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR || ! pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER))) { pIrp->IoStatus.Information = 0; *************** *** 266,284 **** NTSTATUS StartIrp( ! IN PC0C_IO_PORT pIoPort, ! IN PIRP pIrp, ! IN PC0C_IRP_STATE pState, ! IN PC0C_IRP_QUEUE pQueue, ! IN KIRQL oldIrql, ! IN PC0C_FDOPORT_START_ROUTINE pStartRoutine) { NTSTATUS status; - LIST_ENTRY queueToComplete; pQueue->pCurrent = pIrp; pState->flags |= C0C_IRP_FLAG_IS_CURRENT; - InitializeListHead(&queueToComplete); - if (pState->iQueue == C0C_QUEUE_WRITE) { ULONG length = GetWriteLength(pIrp); --- 289,304 ---- NTSTATUS StartIrp( ! PC0C_IO_PORT pIoPort, ! PIRP pIrp, ! PC0C_IRP_STATE pState, ! PC0C_IRP_QUEUE pQueue, ! PLIST_ENTRY pQueueToComplete, ! PC0C_FDOPORT_START_ROUTINE pStartRoutine) { NTSTATUS status; pQueue->pCurrent = pIrp; pState->flags |= C0C_IRP_FLAG_IS_CURRENT; if (pState->iQueue == C0C_QUEUE_WRITE) { ULONG length = GetWriteLength(pIrp); *************** *** 286,294 **** if (length) { pIoPort->amountInWriteQueue += length; ! UpdateTransmitToggle(pIoPort, &queueToComplete); } } ! status = pStartRoutine(pIoPort, &queueToComplete); if (status == STATUS_PENDING) { --- 306,314 ---- if (length) { pIoPort->amountInWriteQueue += length; ! UpdateTransmitToggle(pIoPort, pQueueToComplete); } } ! status = pStartRoutine(pIoPort, pQueueToComplete); if (status == STATUS_PENDING) { *************** *** 310,314 **** if (status == STATUS_CANCELLED || (pIrpStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && ! pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR)) { pIrp->IoStatus.Information = 0; --- 330,335 ---- if (status == STATUS_CANCELLED || (pIrpStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && ! (pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR || ! pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER))) { pIrp->IoStatus.Information = 0; *************** *** 320,327 **** } - KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); - - FdoPortCompleteQueue(&queueToComplete); - return status; } --- 341,344 ---- *************** *** 334,341 **** --- 351,360 ---- { NTSTATUS status; + LIST_ENTRY queueToComplete; KIRQL oldIrql; PC0C_IRP_QUEUE pQueue; PC0C_IRP_STATE pState; + InitializeListHead(&queueToComplete); pState = GetIrpState(pIrp); *************** *** 357,365 **** } else { if (!pQueue->pCurrent) { ! return StartIrp(pIoPort, pIrp, pState, pQueue, oldIrql, pStartRoutine); } else { PIO_STACK_LOCATION pIrpStack; pIrpStack = IoGetCurrentIrpStackLocation(pIrp); if (pIrpStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && --- 376,386 ---- } else { if (!pQueue->pCurrent) { ! status = StartIrp(pIoPort, pIrp, pState, pQueue, &queueToComplete, pStartRoutine); } else { PIO_STACK_LOCATION pIrpStack; + PIO_STACK_LOCATION pCurrentStack; pIrpStack = IoGetCurrentIrpStackLocation(pIrp); + pCurrentStack = IoGetCurrentIrpStackLocation(pQueue->pCurrent); if (pIrpStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && *************** *** 372,379 **** pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR) { - PIO_STACK_LOCATION pCurrentStack; - - pCurrentStack = IoGetCurrentIrpStackLocation(pQueue->pCurrent); - if (pCurrentStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && pCurrentStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR) --- 393,396 ---- *************** *** 391,407 **** pCurrentState->flags |= C0C_IRP_FLAG_IN_QUEUE; ! return StartIrp(pIoPort, pIrp, pState, pQueue, oldIrql, pStartRoutine); } } else { - pIrp->IoStatus.Status = STATUS_PENDING; - IoMarkIrpPending(pIrp); InsertTailList(&pQueue->queue, &pIrp->Tail.Overlay.ListEntry); pState->flags |= C0C_IRP_FLAG_IN_QUEUE; ! if (pState->iQueue == C0C_QUEUE_WRITE) pIoPort->amountInWriteQueue += GetWriteLength(pIrp); ! status = STATUS_PENDING; } } --- 408,441 ---- pCurrentState->flags |= C0C_IRP_FLAG_IN_QUEUE; ! status = StartIrp(pIoPort, pIrp, pState, pQueue, &queueToComplete, pStartRoutine); } } else { InsertTailList(&pQueue->queue, &pIrp->Tail.Overlay.ListEntry); pState->flags |= C0C_IRP_FLAG_IN_QUEUE; ! if (pState->iQueue == C0C_QUEUE_WRITE) { pIoPort->amountInWriteQueue += GetWriteLength(pIrp); + } ! if (pCurrentStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && ! pCurrentStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER && ! pQueue->pCurrent->IoStatus.Information) ! { ! if (pIrpStack->MajorFunction == IRP_MJ_FLUSH_BUFFERS) { ! status = NoPending(pIrp, STATUS_SUCCESS); ! } else { ! PIRP pIrpXoffCounter = pQueue->pCurrent; ! ! ShiftQueue(pQueue); ! CompleteIrp(pIrpXoffCounter, STATUS_SERIAL_MORE_WRITES, &queueToComplete); ! ! status = StartIrp(pIoPort, pIrp, pState, pQueue, &queueToComplete, pStartRoutine); ! } ! } else { ! pIrp->IoStatus.Status = STATUS_PENDING; ! IoMarkIrpPending(pIrp); ! status = STATUS_PENDING; ! } } } *************** *** 410,413 **** --- 444,449 ---- KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); + FdoPortCompleteQueue(&queueToComplete); + return status; } Index: io.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/io.c,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** io.c 27 Nov 2006 11:58:27 -0000 1.29 --- io.c 20 Feb 2007 12:05:11 -0000 1.30 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.30 2007/02/20 12:05:11 vfrolov + * Implemented IOCTL_SERIAL_XOFF_COUNTER + * Fixed cancel and timeout routines + * * Revision 1.29 2006/11/27 11:58:27 vfrolov * Fixed unexpected completing all queued read requests when *************** *** 126,130 **** #define GET_REST_BUFFER(pIrp, done) \ ! (((PUCHAR)(pIrp)->AssociatedIrp.SystemBuffer) + done) typedef struct _RW_DATA { --- 130,140 ---- #define GET_REST_BUFFER(pIrp, done) \ ! (((PUCHAR)(pIrp)->AssociatedIrp.SystemBuffer) + (done)) ! ! #define GET_REST_BUFFER_WRITE(pIrp, done) \ ! ((IoGetCurrentIrpStackLocation(pIrp)->MajorFunction == IRP_MJ_DEVICE_CONTROL && \ ! IoGetCurrentIrpStackLocation(pIrp)->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER) \ ! ? &(((PSERIAL_XOFF_COUNTER)(pIrp)->AssociatedIrp.SystemBuffer)->XoffChar) + (done) \ ! : GET_REST_BUFFER(pIrp, (done))) typedef struct _RW_DATA { *************** *** 165,174 **** PIO_STACK_LOCATION pIrpStack = IoGetCurrentIrpStackLocation(pIrp); ! switch(pIrpStack->MajorFunction) { case IRP_MJ_WRITE: return pIrpStack->Parameters.Write.Length; case IRP_MJ_DEVICE_CONTROL: ! if (pIrpStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_IMMEDIATE_CHAR) return sizeof(UCHAR); break; } --- 175,187 ---- PIO_STACK_LOCATION pIrpStack = IoGetCurrentIrpStackLocation(pIrp); ! switch (pIrpStack->MajorFunction) { case IRP_MJ_WRITE: return pIrpStack->Parameters.Write.Length; case IRP_MJ_DEVICE_CONTROL: ! switch (pIrpStack->Parameters.DeviceIoControl.IoControlCode) { ! case IOCTL_SERIAL_IMMEDIATE_CHAR: ! case IOCTL_SERIAL_XOFF_COUNTER: return sizeof(UCHAR); + } break; } *************** *** 219,222 **** --- 232,237 ---- PLIST_ENTRY pQueueToComplete) { + PIRP pCurrent; + SetXonXoffHolding(pReadIoPort, pFlowFilter->lastXonXoff); *************** *** 233,236 **** --- 248,271 ---- pReadIoPort->perfStats.ReceivedCount += (ULONG)size; + + pCurrent = pReadIoPort->irpQueues[C0C_QUEUE_WRITE].pCurrent; + + if (pCurrent) { + PIO_STACK_LOCATION pCurrentStack; + + pCurrentStack = IoGetCurrentIrpStackLocation(pCurrent); + + if (pCurrentStack->MajorFunction == IRP_MJ_DEVICE_CONTROL && + pCurrentStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER && + pCurrent->IoStatus.Information) + { + if ((LONG)size < pReadIoPort->xoffCounter) { + pReadIoPort->xoffCounter -= (LONG)size; + } else { + ShiftQueue(&pReadIoPort->irpQueues[C0C_QUEUE_WRITE]); + CompleteIrp(pCurrent, STATUS_SUCCESS, pQueueToComplete); + } + } + } } *************** *** 256,260 **** information = pIrp->IoStatus.Information; ! pWriteBuf = GET_REST_BUFFER(pIrp, information); writeLength = GetWriteLength(pIrp); } else { --- 291,295 ---- information = pIrp->IoStatus.Information; ! pWriteBuf = GET_REST_BUFFER_WRITE(pIrp, information); writeLength = GetWriteLength(pIrp); } else { *************** *** 341,345 **** information = pIrp->IoStatus.Information; ! pWriteBuf = GET_REST_BUFFER(pIrp, information); writeLength = GetWriteLength(pIrp); } else { --- 376,380 ---- information = pIrp->IoStatus.Information; ! pWriteBuf = GET_REST_BUFFER_WRITE(pIrp, information); writeLength = GetWriteLength(pIrp); } else { *************** *** 426,430 **** PIRP pIrpWrite = pDataWrite->data.irp.pIrp; ! pWriteBuf = GET_REST_BUFFER(pIrpWrite, pIrpWrite->IoStatus.Information); writeLength = GetWriteLength(pIrpWrite) - pIrpWrite->IoStatus.Information; } else { --- 461,465 ---- PIRP pIrpWrite = pDataWrite->data.irp.pIrp; ! pWriteBuf = GET_REST_BUFFER_WRITE(pIrpWrite, pIrpWrite->IoStatus.Information); writeLength = GetWriteLength(pIrpWrite) - pIrpWrite->IoStatus.Information; } else { *************** *** 540,543 **** --- 575,579 ---- { PIRP pIrp; + PC0C_IRP_STATE pState; #if DBG *************** *** 548,557 **** pIrp = pQueue->pCurrent; ! if (status == STATUS_PENDING && done) { ! PC0C_IRP_STATE pState; ! ! pState = GetIrpState(pIrp); ! HALT_UNLESS(pState); if ((pState->flags & C0C_IRP_FLAG_WAIT_ONE) != 0) { status = STATUS_SUCCESS; --- 584,591 ---- pIrp = pQueue->pCurrent; ! pState = GetIrpState(pIrp); ! HALT_UNLESS(pState); + if (status == STATUS_PENDING && done) { if ((pState->flags & C0C_IRP_FLAG_WAIT_ONE) != 0) { status = STATUS_SUCCESS; *************** *** 563,568 **** } ! if (!first && status == STATUS_PENDING) status = SetIrpTimeout(pIoPort, pIrp); HALT_UNLESS(pCancelRoutine); --- 597,607 ---- } ! if (status == STATUS_PENDING && (pState->flags & C0C_IRP_FLAG_EXPIRED) != 0) { ! status = STATUS_TIMEOUT; ! } ! else ! if (!first && status == STATUS_PENDING) { status = SetIrpTimeout(pIoPort, pIrp); + } HALT_UNLESS(pCancelRoutine); *************** *** 573,586 **** #pragma warning(pop) if (pIrp->Cancel) { ! #pragma warning(push, 3) ! pCancelRoutine = IoSetCancelRoutine(pIrp, NULL); ! #pragma warning(pop) ! ! if (pCancelRoutine) { ! ShiftQueue(pQueue); ! pIrp->IoStatus.Status = STATUS_CANCELLED; ! InsertTailList(pQueueToComplete, &pIrp->Tail.Overlay.ListEntry); ! return STATUS_CANCELLED; ! } } } else { --- 612,618 ---- #pragma warning(pop) if (pIrp->Cancel) { ! ShiftQueue(pQueue); ! CompleteIrp(pIrp, STATUS_CANCELLED, pQueueToComplete); ! return STATUS_CANCELLED; } } else { *************** *** 593,596 **** --- 625,666 ---- } + VOID StartXoffCounter(PC0C_IO_PORT pIoPortWrite, PLIST_ENTRY pQueueToComplete) + { + PIRP pIrpXoffCounter; + PC0C_IRP_STATE pState; + PC0C_IRP_QUEUE pQueue; + + pQueue = &pIoPortWrite->irpQueues[C0C_QUEUE_WRITE]; + + #if DBG + HALT_UNLESS(!pQueue->started); + #endif /* DBG */ + + pIrpXoffCounter = pQueue->pCurrent; + ShiftQueue(pQueue); + + while (pQueue->pCurrent) { + PIRP pCurrent = pQueue->pCurrent; + + if (IoGetCurrentIrpStackLocation(pCurrent)->MajorFunction != IRP_MJ_FLUSH_BUFFERS) { + CompleteIrp(pIrpXoffCounter, STATUS_SERIAL_MORE_WRITES, pQueueToComplete); + return; + } + + ShiftQueue(pQueue); + CompleteIrp(pCurrent, STATUS_SUCCESS, pQueueToComplete); + } + + pIoPortWrite->xoffCounter = ((PSERIAL_XOFF_COUNTER)pIrpXoffCounter->AssociatedIrp.SystemBuffer)->Counter; + + pState = GetIrpState(pIrpXoffCounter); + HALT_UNLESS(pState); + + pQueue->pCurrent = pIrpXoffCounter; + pState->flags |= C0C_IRP_FLAG_IS_CURRENT; + + SetXoffCounterTimeout(pIoPortWrite, pIrpXoffCounter); + } + NTSTATUS FdoPortIo( short ioType, *************** *** 881,887 **** while (dataIrpWrite.data.irp.pIrp) { ! if (IoGetCurrentIrpStackLocation(dataIrpWrite.data.irp.pIrp)->MajorFunction == ! IRP_MJ_FLUSH_BUFFERS) ! { dataIrpWrite.data.irp.status = STATUS_SUCCESS; } else { --- 951,957 ---- while (dataIrpWrite.data.irp.pIrp) { ! PIO_STACK_LOCATION pIrpStackWrite = IoGetCurrentIrpStackLocation(dataIrpWrite.data.irp.pIrp); ! ! if (pIrpStackWrite->MajorFunction == IRP_MJ_FLUSH_BUFFERS) { dataIrpWrite.data.irp.status = STATUS_SUCCESS; } else { *************** *** 921,930 **** break; ! if(startWrite && firstWrite) { ! status = dataIrpWrite.data.irp.status; ! ShiftQueue(pQueueWrite); } else { ! StopCurrentIrp(dataIrpWrite.data.irp.status, pCancelRoutineWrite, firstWrite, ! doneWrite, pIoPortWrite, pQueueWrite, pQueueToComplete); } --- 991,1023 ---- break; ! /* stop current pIrpWrite */ ! ! if (dataIrpWrite.data.irp.status == STATUS_SUCCESS && ! pIrpStackWrite->MajorFunction == IRP_MJ_DEVICE_CONTROL && ! pIrpStackWrite->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER) ! { ! if(startWrite && firstWrite) ! status = STATUS_PENDING; ! else ! StopCurrentIrp(STATUS_PENDING, pCancelRoutineWrite, firstWrite, ! doneWrite, pIoPortWrite, pQueueWrite, pQueueToComplete); ! ! if (dataIrpWrite.data.irp.pIrp == pQueueWrite->pCurrent) { ! if (doneWrite) ! StartXoffCounter(pIoPortWrite, pQueueToComplete); ! ! if (dataIrpWrite.data.irp.pIrp == pQueueWrite->pCurrent) { ! dataIrpWrite.data.irp.pIrp = NULL; ! break; ! } ! } } else { ! if(startWrite && firstWrite) { ! status = dataIrpWrite.data.irp.status; ! ShiftQueue(pQueueWrite); ! } else { ! StopCurrentIrp(dataIrpWrite.data.irp.status, pCancelRoutineWrite, firstWrite, ! doneWrite, pIoPortWrite, pQueueWrite, pQueueToComplete); ! } } *************** *** 1037,1043 **** while (dataIrpWrite.data.irp.pIrp) { ! if (IoGetCurrentIrpStackLocation(dataIrpWrite.data.irp.pIrp)->MajorFunction == ! IRP_MJ_FLUSH_BUFFERS) ! { dataIrpWrite.data.irp.status = STATUS_SUCCESS; } else { --- 1130,1136 ---- while (dataIrpWrite.data.irp.pIrp) { ! PIO_STACK_LOCATION pIrpStackWrite = IoGetCurrentIrpStackLocation(dataIrpWrite.data.irp.pIrp); ! ! if (pIrpStackWrite->MajorFunction == IRP_MJ_FLUSH_BUFFERS) { dataIrpWrite.data.irp.status = STATUS_SUCCESS; } else { *************** *** 1091,1107 **** } ! if(startWrite && firstWrite) { ! if (dataIrpWrite.data.irp.status == STATUS_PENDING) ! dataIrpWrite.data.irp.status = ! SetIrpTimeout(pIoPortWrite, dataIrpWrite.data.irp.pIrp); ! status = dataIrpWrite.data.irp.status; ! if (dataIrpWrite.data.irp.status != STATUS_PENDING) ! ShiftQueue(pQueueWrite); } else { ! dataIrpWrite.data.irp.status = ! StopCurrentIrp(dataIrpWrite.data.irp.status, pCancelRoutineWrite, firstWrite, ! doneWrite, pIoPortWrite, pQueueWrite, pQueueToComplete); } --- 1184,1221 ---- } ! /* stop current pIrpWrite */ ! if (dataIrpWrite.data.irp.status == STATUS_SUCCESS && ! pIrpStackWrite->MajorFunction == IRP_MJ_DEVICE_CONTROL && ! pIrpStackWrite->Parameters.DeviceIoControl.IoControlCode == IOCTL_SERIAL_XOFF_COUNTER) ! { ! if(startWrite && firstWrite) ! status = STATUS_PENDING; ! else ! StopCurrentIrp(STATUS_PENDING, pCancelRoutineWrite, firstWrite, ! doneWrite, pIoPortWrite, pQueueWrite, pQueueToComplete); ! if (dataIrpWrite.data.irp.pIrp == pQueueWrite->pCurrent) { ! if (doneWrite) ! StartXoffCounter(pIoPortWrite, pQueueToComplete); ! ! if (dataIrpWrite.data.irp.pIrp == pQueueWrite->pCurrent) ! break; ! } } else { ! if(startWrite && firstWrite) { ! if (dataIrpWrite.data.irp.status == STATUS_PENDING) ! dataIrpWrite.data.irp.status = ! SetIrpTimeout(pIoPortWrite, dataIrpWrite.data.irp.pIrp); ! ! status = dataIrpWrite.data.irp.status; ! ! if (dataIrpWrite.data.irp.status != STATUS_PENDING) ! ShiftQueue(pQueueWrite); ! } else { ! dataIrpWrite.data.irp.status = ! StopCurrentIrp(dataIrpWrite.data.irp.status, pCancelRoutineWrite, firstWrite, ! doneWrite, pIoPortWrite, pQueueWrite, pQueueToComplete); ! } } Index: timeout.h =================================================================== RCS file: /cvsroot/com0com/com0com/sys/timeout.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** timeout.h 21 Jun 2006 16:23:57 -0000 1.4 --- timeout.h 20 Feb 2007 12:05:11 -0000 1.5 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.5 2007/02/20 12:05:11 vfrolov + * Implemented IOCTL_SERIAL_XOFF_COUNTER + * Fixed cancel and timeout routines + * * Revision 1.4 2006/06/21 16:23:57 vfrolov * Fixed possible BSOD after one port of pair removal *************** *** 43,46 **** --- 47,54 ---- VOID SetIntervalTimeout(PC0C_IO_PORT pIoPort); + VOID SetXoffCounterTimeout( + PC0C_IO_PORT pIoPort, + PIRP pIrp); + NTSTATUS SetIrpTimeout( PC0C_IO_PORT pIoPort, Index: write.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/write.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** write.c 23 Jun 2006 11:44:52 -0000 1.8 --- write.c 20 Feb 2007 12:05:11 -0000 1.9 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.9 2007/02/20 12:05:11 vfrolov + * Implemented IOCTL_SERIAL_XOFF_COUNTER + * Fixed cancel and timeout routines + * * Revision 1.8 2006/06/23 11:44:52 vfrolov * Mass replacement pDevExt by pIoPort *************** *** 72,75 **** --- 76,97 ---- } + NTSTATUS FdoPortXoffCounter( + IN PC0C_IO_PORT pIoPort, + IN PIRP pIrp, + IN PIO_STACK_LOCATION pIrpStack) + { + PSERIAL_XOFF_COUNTER pXoffCounter; + + if (pIrpStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(SERIAL_XOFF_COUNTER)) + return STATUS_BUFFER_TOO_SMALL; + + pXoffCounter = (PSERIAL_XOFF_COUNTER)pIrp->AssociatedIrp.SystemBuffer; + + if (pXoffCounter->Counter <= 0) + return STATUS_INVALID_PARAMETER; + + return FdoPortStartIrp(pIoPort, pIrp, C0C_QUEUE_WRITE, StartIrpWrite); + } + NTSTATUS FdoPortWrite(IN PC0C_IO_PORT pIoPort, IN PIRP pIrp) { Index: timeout.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/timeout.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** timeout.c 21 Jun 2006 16:23:57 -0000 1.7 --- timeout.c 20 Feb 2007 12:05:11 -0000 1.8 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.8 2007/02/20 12:05:11 vfrolov + * Implemented IOCTL_SERIAL_XOFF_COUNTER + * Fixed cancel and timeout routines + * * Revision 1.7 2006/06/21 16:23:57 vfrolov * Fixed possible BSOD after one port of pair removal *************** *** 56,100 **** IN PC0C_IRP_QUEUE pQueue) { KIRQL oldIrql; - PIRP pIrp; ! KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql); ! ! pIrp = pQueue->pCurrent; ! ! if (pIrp) { ! PDRIVER_CANCEL pCancelRoutine; ! #pragma warning(push, 3) ! pCancelRoutine = IoSetCancelRoutine(pIrp, NULL); ! #pragma warning(pop) ! if (pCancelRoutine) { ! PC0C_IRP_STATE pState; ! pState = GetIrpState(pIrp); ! HALT_UNLESS(pState); ! if (pState->iQueue == C0C_QUEUE_WRITE) { ! pIoPort->amountInWriteQueue -= ! GetWriteLength(pIrp) - (ULONG)pIrp->IoStatus.Information; ! } ! ShiftQueue(pQueue); ! if (pQueue->pCurrent) ! SetIrpTimeout(pIoPort, pQueue->pCurrent); ! } else { ! pIrp = NULL; ! } } KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); ! if (pIrp) { ! TraceIrp("timeout", pIrp, NULL, TRACE_FLAG_RESULTS); ! ! pIrp->IoStatus.Status = STATUS_TIMEOUT; ! IoCompleteRequest(pIrp, IO_SERIAL_INCREMENT); ! } } --- 60,87 ---- IN PC0C_IRP_QUEUE pQueue) { + LIST_ENTRY queueToComplete; KIRQL oldIrql; ! InitializeListHead(&queueToComplete); ! KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql); ! if (pQueue->pCurrent) { ! PC0C_IRP_STATE pState; ! pState = GetIrpState(pQueue->pCurrent); ! HALT_UNLESS(pState); ! pState->flags |= C0C_IRP_FLAG_EXPIRED; ! if (pState->iQueue == C0C_QUEUE_WRITE) ! ReadWrite(pIoPort->pIoPortRemote, FALSE, pIoPort, FALSE, &queueToComplete); ! else ! ReadWrite(pIoPort, FALSE, pIoPort->pIoPortRemote, FALSE, &queueToComplete); } KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); ! FdoPortCompleteQueue(&queueToComplete); } *************** *** 224,227 **** --- 211,235 ---- } + VOID SetXoffCounterTimeout( + PC0C_IO_PORT pIoPort, + PIRP pIrp) + { + PSERIAL_XOFF_COUNTER pXoffCounter; + LARGE_INTEGER total; + + KeCancelTimer(&pIoPort->timerWriteTotal); + + pXoffCounter = (PSERIAL_XOFF_COUNTER)pIrp->AssociatedIrp.SystemBuffer; + + if (pXoffCounter->Timeout) { + total.QuadPart = ((LONGLONG)pXoffCounter->Timeout) * -10000; + + KeSetTimer( + &pIoPort->timerWriteTotal, + total, + &pIoPort->timerWriteTotalDpc); + } + } + VOID TimeoutReadTotal( IN PKDPC pDpc, *************** *** 300,306 **** PIRP pIrp) { ! switch (IoGetCurrentIrpStackLocation(pIrp)->MajorFunction) { case IRP_MJ_WRITE: return SetWriteTimeout(pIoPort, pIrp); case IRP_MJ_READ: return SetReadTimeout(pIoPort, pIrp); --- 308,323 ---- PIRP pIrp) { ! PIO_STACK_LOCATION pIrpStack = IoGetCurrentIrpStackLocation(pIrp); ! ! switch (pIrpStack->MajorFunction) { case IRP_MJ_WRITE: return SetWriteTimeout(pIoPort, pIrp); + case IRP_MJ_DEVICE_CONTROL: + switch (pIrpStack->Parameters.DeviceIoControl.IoControlCode) { + case IOCTL_SERIAL_XOFF_COUNTER: + case IOCTL_SERIAL_IMMEDIATE_CHAR: + return SetWriteTimeout(pIoPort, pIrp); + } + break; case IRP_MJ_READ: return SetReadTimeout(pIoPort, pIrp); |
From: Vyacheslav F. <vf...@us...> - 2007-02-20 12:01:51
|
Update of /cvsroot/com0com/com0com/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv27337 Modified Files: trace.c Log Message: Added result dumping SERIAL_XOFF_COUNTER Index: trace.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/trace.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** trace.c 15 Feb 2007 11:43:56 -0000 1.24 --- trace.c 20 Feb 2007 12:01:47 -0000 1.25 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.25 2007/02/20 12:01:47 vfrolov + * Added result dumping SERIAL_XOFF_COUNTER + * * Revision 1.24 2007/02/15 11:43:56 vfrolov * Added tracing SERIAL_XOFF_COUNTER *************** *** 1349,1353 **** pDestStr = AnsiStrCopyDump(pDestStr, &size, pSysBuf, inform); else ! pDestStr = AnsiStrFormat(pDestStr, &size, "%lu:", (long)inform); } break; --- 1352,1356 ---- pDestStr = AnsiStrCopyDump(pDestStr, &size, pSysBuf, inform); else ! pDestStr = AnsiStrFormat(pDestStr, &size, "%lu", (long)inform); } break; *************** *** 1471,1476 **** break; case IOCTL_SERIAL_XOFF_COUNTER: ! if ((flags & TRACE_FLAG_PARAMS) && inLength >= sizeof(SERIAL_XOFF_COUNTER)) ! pDestStr = AnsiStrCopyXoffCounter(pDestStr, &size, (PSERIAL_XOFF_COUNTER)pSysBuf); break; } --- 1474,1488 ---- break; case IOCTL_SERIAL_XOFF_COUNTER: ! if (inLength >= sizeof(SERIAL_XOFF_COUNTER)) { ! if ((flags & TRACE_FLAG_PARAMS)) ! pDestStr = AnsiStrCopyXoffCounter(pDestStr, &size, (PSERIAL_XOFF_COUNTER)pSysBuf); ! if (flags & TRACE_FLAG_RESULTS) { ! pDestStr = AnsiStrCopyStr(pDestStr, &size, " "); ! if (enableMask & TRACE_ENABLE_DUMP) ! pDestStr = AnsiStrCopyDump(pDestStr, &size, &((PSERIAL_XOFF_COUNTER)pSysBuf)->XoffChar, inform); ! else ! pDestStr = AnsiStrFormat(pDestStr, &size, "%lu", (long)inform); ! } ! } break; } |
From: Vyacheslav F. <vf...@us...> - 2007-02-20 11:58:10
|
Update of /cvsroot/com0com/com0com/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv25691 Modified Files: tracetbl.c Log Message: Added STATUS_SERIAL_COUNTER_TIMEOUT and STATUS_SERIAL_MORE_WRITES Index: tracetbl.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/tracetbl.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** tracetbl.c 27 Sep 2006 07:24:51 -0000 1.10 --- tracetbl.c 20 Feb 2007 11:57:59 -0000 1.11 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.11 2007/02/20 11:57:59 vfrolov + * Added STATUS_SERIAL_COUNTER_TIMEOUT and STATUS_SERIAL_MORE_WRITES + * * Revision 1.10 2006/09/27 07:24:51 vfrolov * Added IRP_MN_REGINFO_EX *************** *** 260,263 **** --- 263,268 ---- TOCODE2NAME(STATUS_, DEVICE_BUSY), TOCODE2NAME(STATUS_, WMI_GUID_NOT_FOUND), + TOCODE2NAME(STATUS_, SERIAL_COUNTER_TIMEOUT), + TOCODE2NAME(STATUS_, SERIAL_MORE_WRITES), {0, NULL} }; |
From: Vyacheslav F. <vf...@us...> - 2007-02-15 11:44:03
|
Update of /cvsroot/com0com/com0com/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11266 Modified Files: trace.c Log Message: Added tracing SERIAL_XOFF_COUNTER Index: trace.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/trace.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** trace.c 2 Feb 2007 09:52:21 -0000 1.23 --- trace.c 15 Feb 2007 11:43:56 -0000 1.24 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.24 2007/02/15 11:43:56 vfrolov + * Added tracing SERIAL_XOFF_COUNTER + * * Revision 1.23 2007/02/02 09:52:21 vfrolov * Fixed huge system error logging if bad trace file used *************** *** 463,466 **** --- 466,483 ---- break; } + case 'd': { + LONG n; + if (l) + n = va_arg(va, long); + else + n = va_arg(va, int); + if (n < 0) { + pDestStr = AnsiStrCopyStr(pDestStr, &size, "-"); + n = -n; + } + pDestStr = AnsiStrCopyNum(pDestStr, &size, n, 10, width); + format = FALSE; + break; + } case 'u': { ULONG n; *************** *** 768,771 **** --- 785,798 ---- } + PCHAR AnsiStrCopyXoffCounter( + PCHAR pDestStr, + PSIZE_T pSize, + IN PSERIAL_XOFF_COUNTER pXoffCounter) + { + return AnsiStrFormat(pDestStr, pSize, + " Timeout=%lu Counter=%ld XoffChar=0x%X", + (long)pXoffCounter->Timeout, (long)pXoffCounter->Counter, (int)pXoffCounter->XoffChar); + } + PCHAR AnsiStrCopyCommStatus( PCHAR pDestStr, *************** *** 1443,1446 **** --- 1470,1477 ---- } break; + case IOCTL_SERIAL_XOFF_COUNTER: + if ((flags & TRACE_FLAG_PARAMS) && inLength >= sizeof(SERIAL_XOFF_COUNTER)) + pDestStr = AnsiStrCopyXoffCounter(pDestStr, &size, (PSERIAL_XOFF_COUNTER)pSysBuf); + break; } break; |
From: Vyacheslav F. <vf...@us...> - 2007-02-15 08:48:50
|
Update of /cvsroot/com0com/com0com/setup In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv10362 Modified Files: devutils.cpp Log Message: Fixed 1658441 - Installation Failed Thanks to Michael A. Smith Index: devutils.cpp =================================================================== RCS file: /cvsroot/com0com/com0com/setup/devutils.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** devutils.cpp 10 Nov 2006 14:07:40 -0000 1.4 --- devutils.cpp 15 Feb 2007 08:48:45 -0000 1.5 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2006-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * Revision 1.5 2007/02/15 08:48:45 vfrolov + * Fixed 1658441 - Installation Failed + * Thanks to Michael A. Smith + * * Revision 1.4 2006/11/10 14:07:40 vfrolov * Implemented remove command *************** *** 456,460 **** } /////////////////////////////////////////////////////////////// ! BOOL InstallDevice( InfFile &infFile, const char *pDevId, --- 460,464 ---- } /////////////////////////////////////////////////////////////// ! static int TryInstallDevice( InfFile &infFile, const char *pDevId, *************** *** 464,471 **** GUID classGUID; char className[32]; if (!SetupDiGetINFClass(infFile.Path(), &classGUID, className, sizeof(className), 0)) { ShowLastError(MB_OK|MB_ICONSTOP, "SetupDiGetINFClass(%s)", infFile.Path()); ! return FALSE; } --- 468,478 ---- GUID classGUID; char className[32]; + DWORD updateErr; + + updateErr = ERROR_SUCCESS; if (!SetupDiGetINFClass(infFile.Path(), &classGUID, className, sizeof(className), 0)) { ShowLastError(MB_OK|MB_ICONSTOP, "SetupDiGetINFClass(%s)", infFile.Path()); ! return IDCANCEL; } *************** *** 478,482 **** if (hDevInfo == INVALID_HANDLE_VALUE) { ShowLastError(MB_OK|MB_ICONSTOP, "SetupDiCreateDeviceInfoList()"); ! return FALSE; } --- 485,489 ---- if (hDevInfo == INVALID_HANDLE_VALUE) { ShowLastError(MB_OK|MB_ICONSTOP, "SetupDiCreateDeviceInfoList()"); ! return IDCANCEL; } *************** *** 531,535 **** if (!res) { ! ShowLastError(MB_OK|MB_ICONSTOP, "UpdateDriverForPlugAndPlayDevices()"); err1: --- 538,542 ---- if (!res) { ! updateErr = GetLastError(); err1: *************** *** 542,546 **** SetupDiDestroyDeviceInfoList(hDevInfo); ! return res; } /////////////////////////////////////////////////////////////// --- 549,607 ---- SetupDiDestroyDeviceInfoList(hDevInfo); ! ! if (updateErr != ERROR_SUCCESS) { ! if (updateErr == ERROR_FILE_NOT_FOUND) { ! LONG err; ! HKEY hKey; ! ! err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUNONCE, 0, KEY_READ, &hKey); ! ! if (err == ERROR_SUCCESS) ! RegCloseKey(hKey); ! ! if (err == ERROR_FILE_NOT_FOUND) { ! int res2 = ShowMsg(MB_CANCELTRYCONTINUE, ! "Can't update driver. Possible it's because your Windows registry is corrupted and\n" ! "there is not the following key:\n" ! "\n" ! "HKEY_LOCAL_MACHINE\\" REGSTR_PATH_RUNONCE "\n" ! "\n" ! "Continue to add the key to the registry.\n"); ! ! if (res2 == IDCONTINUE) { ! err = RegCreateKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUNONCE, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL); ! ! if (err == ERROR_SUCCESS) { ! RegCloseKey(hKey); ! return IDTRYAGAIN; ! } else { ! ShowLastError(MB_OK|MB_ICONSTOP, "RegCreateKeyEx()"); ! return IDCANCEL; ! } ! } ! ! return res2; ! } ! } ! ! ShowError(MB_OK|MB_ICONSTOP, updateErr, "UpdateDriverForPlugAndPlayDevices()"); ! } ! ! return res ? IDCONTINUE : IDCANCEL; ! } ! ! BOOL InstallDevice( ! InfFile &infFile, ! const char *pDevId, ! PDEVCALLBACK pDevCallBack, ! void *pCallBackParam) ! { ! int res; ! ! do { ! res = TryInstallDevice(infFile, pDevId, pDevCallBack, pCallBackParam); ! } while (res == IDTRYAGAIN); ! ! return res == IDCONTINUE; } /////////////////////////////////////////////////////////////// |
From: Vyacheslav F. <vf...@us...> - 2007-02-08 11:52:16
|
Update of /cvsroot/com0com/com2tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29338 Modified Files: telnet.cpp telnet.h Log Message: Added missing IAC escaping Index: telnet.h =================================================================== RCS file: /cvsroot/com0com/com2tcp/telnet.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** telnet.h 3 Oct 2005 13:44:17 -0000 1.3 --- telnet.h 8 Feb 2007 11:52:11 -0000 1.4 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2005 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2005-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.4 2007/02/08 11:52:11 vfrolov + * Added missing IAC escaping + * * Revision 1.3 2005/10/03 13:44:17 vfrolov * Added Clean() method *************** *** 43,46 **** --- 46,50 ---- virtual int Write(const void *pBuf, int count); + virtual int Send(const void *pBuf, int count); virtual void Clean(); protected: Index: telnet.cpp =================================================================== RCS file: /cvsroot/com0com/com2tcp/telnet.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** telnet.cpp 13 Nov 2006 10:37:14 -0000 1.4 --- telnet.cpp 8 Feb 2007 11:52:11 -0000 1.5 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2005-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2005-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.5 2007/02/08 11:52:11 vfrolov + * Added missing IAC escaping + * * Revision 1.4 2006/11/13 10:37:14 vfrolov * Fixed type casting *************** *** 119,122 **** --- 122,139 ---- } + int TelnetProtocol::Send(const void *pBuf, int count) + { + for (int i = 0 ; i < count ; i++) { + BYTE ch = ((const BYTE *)pBuf)[i]; + + if (ch == cdIAC) + SendRaw(&ch, 1); + + SendRaw(&ch, 1); + } + + return count; + } + int TelnetProtocol::Write(const void *pBuf, int count) { *************** *** 135,138 **** --- 152,156 ---- case cdIAC: WriteRaw(&ch, 1); + state = stData; break; case cdSB: |
From: Vyacheslav F. <vf...@us...> - 2007-02-06 11:53:40
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13602 Modified Files: comio.cpp comport.cpp comport.h comparams.h comparams.cpp comio.h hub4com.cpp Log Message: Added options --odsr, --ox, --ix and --idsr Added communications error reporting Index: comport.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comport.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comport.cpp 5 Feb 2007 09:33:20 -0000 1.2 --- comport.cpp 6 Feb 2007 11:53:33 -0000 1.3 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * 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 *************** *** 33,36 **** --- 37,41 ---- #include "comhub.h" #include "comio.h" + #include "comparams.h" /////////////////////////////////////////////////////////////// *************** *** 40,43 **** --- 45,49 ---- countReadOverlapped(0), countXoff(0), + filterX(FALSE), writeQueueLimit(256), writeQueued(0), *************** *** 57,60 **** --- 63,67 ---- writeLost = 0; + filterX = comParams.InX(); string path(pPath); *************** *** 118,121 **** --- 125,137 ---- return FALSE; + if (filterX) { + len = pOverlapped->FilterX(); + + if (!len) { + delete pOverlapped; + return TRUE; + } + } + if (writeQueued > writeQueueLimit) PurgeComm(handle, PURGE_TXABORT|PURGE_TXCLEAR); *************** *** 175,181 **** if (writeLost) { writeLostTotal += writeLost; ! cout << "Write lost: " << name << " " << writeLost << " total " << writeLostTotal << endl; writeLost = 0; } } /////////////////////////////////////////////////////////////// --- 191,232 ---- if (writeLost) { writeLostTotal += writeLost; ! cout << "Write lost " << name << ": " << writeLost << ", total " << writeLostTotal << endl; writeLost = 0; } + + DWORD errors; + + if (ClearCommError(handle, &errors, NULL) && errors) { + cout << "Error " << name << ":"; + + if (errors & CE_RXOVER) { cout << " RXOVER"; } + if (errors & CE_OVERRUN) { cout << " OVERRUN"; } + if (errors & CE_RXPARITY) { cout << " RXPARITY"; } + if (errors & CE_FRAME) { cout << " FRAME"; } + + #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; + } } /////////////////////////////////////////////////////////////// Index: comparams.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comparams.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comparams.cpp 1 Feb 2007 12:14:59 -0000 1.2 --- comparams.cpp 6 Feb 2007 11:53:33 -0000 1.3 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * 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 *************** *** 39,43 **** stopBits(ONESTOPBIT), outCts(1), ! outDsr(0) { } --- 43,50 ---- stopBits(ONESTOPBIT), outCts(1), ! outDsr(0), ! outX(0), ! inX(0), ! inDsr(0) { } *************** *** 103,137 **** } ! BOOL ComParams::SetOutCts(const char *pOutCts) ! { ! if (_stricmp(pOutCts, "on") == 0) { ! outCts = 1; ! } ! else ! if (_stricmp(pOutCts, "off") == 0) { ! outCts = 0; ! } ! else ! if (*pOutCts == 'c') { ! outCts = -1; ! } ! else ! return FALSE; ! ! return TRUE; ! } ! ! BOOL ComParams::SetOutDsr(const char *pOutDsr) { ! if (_stricmp(pOutDsr, "on") == 0) { ! outDsr = 1; } else ! if (_stricmp(pOutDsr, "off") == 0) { ! outDsr = 0; } else ! if (*pOutDsr == 'c') { ! outDsr = -1; } else --- 110,125 ---- } ! 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 *************** *** 187,203 **** } ! string ComParams::OutCtsStr(int outCts) ! { ! switch (outCts) { ! case 1: return "on"; ! case 0: return "off"; ! case -1: return "current"; ! } ! return "?"; ! } ! ! string ComParams::OutDsrStr(int outDsr) { ! switch (outDsr) { case 1: return "on"; case 0: return "off"; --- 175,181 ---- } ! string ComParams::FlagStr(int flag) { ! switch (flag) { case 1: return "on"; case 0: return "off"; *************** *** 227,236 **** } ! const char *ComParams::OutCtsLst() ! { ! return "on, off or c[urrent]"; ! } ! ! const char *ComParams::OutDsrLst() { return "on, off or c[urrent]"; --- 205,209 ---- } ! const char *ComParams::FlagLst() { return "on, off or c[urrent]"; Index: hub4com.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** hub4com.cpp 5 Feb 2007 09:33:20 -0000 1.3 --- hub4com.cpp 6 Feb 2007 11:53:33 -0000 1.4 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * 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 *************** *** 60,66 **** << " (" << ComParams().OutCtsStr() << " by default), where <c> is" << endl << " " << ComParams::OutCtsLst() << "." << endl ! << " --odsr=<c> - set DSR handshaking on output to <d>" << endl ! << " (" << ComParams().OutDsrStr() << " by default), where <d> is" << endl << " " << ComParams::OutDsrLst() << "." << endl << endl << " The value c[urrent] above means to use current COM port settings." << endl --- 64,82 ---- << " (" << 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 << endl << " The value c[urrent] above means to use current COM port settings." << endl *************** *** 228,231 **** --- 244,265 ---- } } 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, "route=")) != NULL) { defaultRouteData = FALSE; Index: comio.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comio.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comio.h 5 Feb 2007 09:33:20 -0000 1.2 --- comio.h 6 Feb 2007 11:53:33 -0000 1.3 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * 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 *************** *** 60,63 **** --- 64,68 ---- ~WriteOverlapped(); BOOL StartWrite(); + DWORD FilterX(); private: Index: comparams.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comparams.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comparams.h 1 Feb 2007 12:14:59 -0000 1.2 --- comparams.h 6 Feb 2007 11:53:33 -0000 1.3 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * 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 *************** *** 42,47 **** BOOL SetParity(const char *pParity); BOOL SetStopBits(const char *pStopBits); ! BOOL SetOutCts(const char *pOutCts); ! BOOL SetOutDsr(const char *pOutDsr); static string BaudRateStr(long baudRate); --- 46,54 ---- 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); } static string BaudRateStr(long baudRate); *************** *** 49,54 **** static string ParityStr(int parity); static string StopBitsStr(int stopBits); ! static string OutCtsStr(int outCts); ! static string OutDsrStr(int outDsr); string BaudRateStr() const { return BaudRateStr(baudRate); } --- 56,64 ---- 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); } string BaudRateStr() const { return BaudRateStr(baudRate); } *************** *** 58,61 **** --- 68,74 ---- 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); } static const char *BaudRateLst(); *************** *** 63,68 **** static const char *ParityLst(); static const char *StopBitsLst(); ! static const char *OutCtsLst(); ! static const char *OutDsrLst(); long BaudRate() const { return baudRate; } --- 76,84 ---- 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(); } long BaudRate() const { return baudRate; } *************** *** 72,77 **** --- 88,100 ---- 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; } private: + BOOL SetFlag(const char *pFlagStr, int *pFlag); + static string FlagStr(int flag); + static const char *FlagLst(); + long baudRate; int byteSize; *************** *** 80,83 **** --- 103,109 ---- int outCts; int outDsr; + int outX; + int inX; + int inDsr; }; /////////////////////////////////////////////////////////////// Index: comport.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comport.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comport.h 5 Feb 2007 09:33:20 -0000 1.2 --- comport.h 6 Feb 2007 11:53:33 -0000 1.3 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * 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 *************** *** 61,64 **** --- 65,69 ---- int countReadOverlapped; int countXoff; + BOOL filterX; DWORD writeQueueLimit; Index: comio.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comio.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** comio.cpp 5 Feb 2007 09:33:20 -0000 1.3 --- comio.cpp 6 Feb 2007 11:53:33 -0000 1.4 *************** *** 20,23 **** --- 20,27 ---- * * $Log$ + * 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 *************** *** 108,116 **** dcb.fOutxDsrFlow = comParams.OutDsr(); ! dcb.fDsrSensitivity = FALSE; dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; dcb.fDtrControl = DTR_CONTROL_ENABLE; ! dcb.fOutX = FALSE; ! dcb.fInX = FALSE; dcb.fParity = FALSE; dcb.fNull = FALSE; --- 112,127 ---- 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; *************** *** 152,155 **** --- 163,169 ---- << ", 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) << ") - OK" << endl; return handle; *************** *** 173,176 **** --- 187,205 ---- } + DWORD WriteOverlapped::FilterX() + { + BYTE *pSrc = pBuf; + BYTE *pDst = pBuf; + + for (DWORD i = 0 ; i < len ; i++) { + if (*pSrc == 0x11 || *pSrc == 0x13) + pSrc++; + else + *pDst++ = *pSrc++; + } + + return len = DWORD(pDst - pBuf); + } + VOID CALLBACK WriteOverlapped::OnWrite( DWORD err, |
From: Vyacheslav F. <vf...@us...> - 2007-02-06 11:45:50
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv10900 Modified Files: .cvsignore Log Message: Added *.suo Index: .cvsignore =================================================================== RCS file: /cvsroot/com0com/hub4com/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 1 Feb 2007 12:16:56 -0000 1.1 --- .cvsignore 6 Feb 2007 11:45:45 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- *.sln *.user + *.suo Release Debug |
From: Vyacheslav F. <vf...@us...> - 2007-02-05 09:33:24
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv6060 Modified Files: comhub.cpp comhub.h comio.cpp comio.h comport.cpp comport.h hub4com.cpp Log Message: Implemented internal flow control Index: comport.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comport.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comport.cpp 23 Jan 2007 09:13:10 -0000 1.1 --- comport.cpp 5 Feb 2007 09:33:20 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 35,39 **** : handle(INVALID_HANDLE_VALUE), hub(_hub), ! writeQueued(0) { } --- 38,46 ---- : handle(INVALID_HANDLE_VALUE), hub(_hub), ! countReadOverlapped(0), ! countXoff(0), ! writeQueueLimit(256), ! writeQueued(0), ! writeLostTotal(0) { } *************** *** 62,65 **** --- 69,85 ---- BOOL ComPort::Start() { + if (!StartRead()) + return FALSE; + + cout << "Started " << name << endl; + + return TRUE; + } + + BOOL ComPort::StartRead() + { + if (countReadOverlapped) + return TRUE; + if (handle == INVALID_HANDLE_VALUE) return FALSE; *************** *** 77,81 **** } ! cout << "Started " << name << endl; return TRUE; --- 97,103 ---- } ! countReadOverlapped++; ! ! //cout << "Started Read " << name << " " << countReadOverlapped << endl; return TRUE; *************** *** 96,115 **** return FALSE; ! if (writeQueued > 256) PurgeComm(handle, PURGE_TXABORT|PURGE_TXCLEAR); if (!pOverlapped->StartWrite()) { delete pOverlapped; return FALSE; } ! //cout << "Started Write " << pOverlapped->i << " " << path << " " << len << " " << writeQueued << endl; return TRUE; } ! void ComPort::OnRead(LPCVOID pBuf, DWORD done) { ! hub.Write(this, pBuf, done); } --- 118,172 ---- return FALSE; ! 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) ! hub.AddXoff(this, 1); ! ! writeQueued += len; ! ! //cout << "Started Write " << name << " " << len << " " << writeQueued << 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) ! hub.AddXoff(this, -1); ! ! writeQueued -= len; ! } ! ! void ComPort::OnRead(ReadOverlapped *pOverlapped, LPCVOID pBuf, DWORD done) ! { ! if (done) ! hub.Write(this, pBuf, done); ! ! if (countXoff > 0 || !pOverlapped->StartRead()) { ! delete pOverlapped; ! countReadOverlapped--; ! ! //cout << "Stopped Read " << name << " " << countReadOverlapped << endl; ! } ! } ! ! void ComPort::AddXoff(int count) ! { ! countXoff += count; ! ! if (countXoff <= 0) ! StartRead(); } Index: hub4com.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** hub4com.cpp 1 Feb 2007 12:14:59 -0000 1.2 --- hub4com.cpp 5 Feb 2007 09:33:20 -0000 1.3 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 168,171 **** --- 171,175 ---- BOOL defaultRouteData = TRUE; + BOOL defaultRouteFlowControl = TRUE; int plugged = 0; *************** *** 249,253 **** } ! hub.RouteDataReport(); if (hub.StartAll()) { --- 253,262 ---- } ! if (defaultRouteFlowControl) { ! hub.RouteFlowControl(FALSE); ! } else { ! } ! ! hub.RouteReport(); if (hub.StartAll()) { Index: comio.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comio.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comio.h 23 Jan 2007 09:13:10 -0000 1.1 --- comio.h 5 Feb 2007 09:33:20 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 49,56 **** ComPort &port; BYTE buf[64]; - - int i; - - static int iNext; }; --- 52,55 ---- *************** *** 71,78 **** BYTE *pBuf; DWORD len; - - int i; - - static int iNext; }; /////////////////////////////////////////////////////////////// --- 70,73 ---- Index: comhub.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comhub.h 1 Feb 2007 12:14:58 -0000 1.2 --- comhub.h 5 Feb 2007 09:33:20 -0000 1.3 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.3 2007/02/05 09:33:20 vfrolov + * Implemented internal flow control + * * Revision 1.2 2007/02/01 12:14:58 vfrolov * Redesigned COM port params *************** *** 48,59 **** BOOL StartAll(); void Write(ComPort *pFromPort, LPCVOID pData, DWORD len); ! void LostReport(); ! void RouteData(int iFrom, int iTo, BOOL noRoute); ! void RouteDataReport(); ! int NumPorts() { return (int)ports.size(); } private: ComPorts ports; ComPortMap routeDataMap; }; /////////////////////////////////////////////////////////////// --- 51,75 ---- 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) { ! Route(routeDataMap, iFrom, iTo, noRoute); ! } ! ! void RouteFlowControl(int iFrom, int iTo, BOOL noRoute) { ! Route(routeFlowControlMap, iFrom, iTo, noRoute); ! } ! ! 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) const; + ComPorts ports; ComPortMap routeDataMap; + ComPortMap routeFlowControlMap; }; /////////////////////////////////////////////////////////////// Index: comport.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comport.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comport.h 23 Jan 2007 09:13:10 -0000 1.1 --- comport.h 5 Feb 2007 09:33:20 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 32,35 **** --- 35,40 ---- class ComHub; class ComParams; + class WriteOverlapped; + class ReadOverlapped; /////////////////////////////////////////////////////////////// class ComPort *************** *** 41,56 **** BOOL Start(); BOOL Write(LPCVOID pData, DWORD len); ! void OnRead(LPCVOID pBuf, DWORD done); const string &Name() const { return name; } HANDLE Handle() const { return handle; } - DWORD &WriteQueued() { return writeQueued; } - DWORD &WriteLost() { return writeLost; } void LostReport(); private: string name; HANDLE handle; ComHub &hub; DWORD writeQueued; DWORD writeLost; --- 46,66 ---- BOOL Start(); BOOL Write(LPCVOID pData, DWORD len); ! void OnWrite(WriteOverlapped *pOverlapped, DWORD len, DWORD done); ! void OnRead(ReadOverlapped *pOverlapped, LPCVOID pBuf, DWORD done); ! void AddXoff(int count); const string &Name() const { return name; } HANDLE Handle() const { return handle; } void LostReport(); private: + BOOL StartRead(); + string name; HANDLE handle; ComHub &hub; + int countReadOverlapped; + int countXoff; + DWORD writeQueueLimit; DWORD writeQueued; DWORD writeLost; Index: comhub.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comhub.cpp 1 Feb 2007 12:14:58 -0000 1.2 --- comhub.cpp 5 Feb 2007 09:33:20 -0000 1.3 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.3 2007/02/05 09:33:20 vfrolov + * Implemented internal flow control + * * Revision 1.2 2007/02/01 12:14:58 vfrolov * Redesigned COM port params *************** *** 36,40 **** typedef pair <ComPort*, ComPort*> ComPortPair; /////////////////////////////////////////////////////////////// ! static ComPortMap::iterator FindPair(ComPortMap &map, ComPortPair &pair) { ComPortMap::iterator i; --- 39,43 ---- typedef pair <ComPort*, ComPort*> ComPortPair; /////////////////////////////////////////////////////////////// ! static ComPortMap::iterator FindPair(ComPortMap &map, const ComPortPair &pair) { ComPortMap::iterator i; *************** *** 99,103 **** } ! void ComHub::LostReport() { for (ComPorts::const_iterator i = ports.begin() ; i != ports.end() ; i++) --- 102,118 ---- } ! 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); ! } ! } ! ! void ComHub::LostReport() const { for (ComPorts::const_iterator i = ports.begin() ; i != ports.end() ; i++) *************** *** 105,109 **** } ! void ComHub::RouteData(int iFrom, int iTo, BOOL noRoute) { if (iFrom < 0) { --- 120,136 ---- } ! 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) const { if (iFrom < 0) { *************** *** 111,117 **** if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! RouteData(iF, iT, noRoute); } else { ! RouteData(iF, iTo, noRoute); } } --- 138,144 ---- if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iF, iT, noRoute); } else { ! Route(map, iF, iTo, noRoute); } } *************** *** 119,123 **** if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! RouteData(iFrom, iT, noRoute); } else --- 146,150 ---- if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) ! Route(map, iFrom, iT, noRoute); } else *************** *** 126,137 **** for (;;) { ! ComPortMap::iterator i = FindPair(routeDataMap, pair); ! if (i == routeDataMap.end()) { if (!noRoute) ! routeDataMap.insert(pair); break; } else if (noRoute) { ! routeDataMap.erase(i); } else { break; --- 153,164 ---- 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; *************** *** 142,149 **** } ! void ComHub::RouteDataReport() { ! if (!routeDataMap.size()) { ! cout << "No route for data" << endl; return; } --- 169,176 ---- } ! static void RouteReport(const ComPortMap &map, const char *pMapName) { ! if (!map.size()) { ! cout << "No route for " << pMapName << endl; return; } *************** *** 151,160 **** ComPort *pLastPort = NULL; ! for (ComPortMap::const_iterator i = routeDataMap.begin() ; i != routeDataMap.end() ; i++) { if (pLastPort != i->first) { if (pLastPort) cout << endl; ! cout << "Route data " << i->first->Name() << " -->"; pLastPort = i->first; --- 178,187 ---- ComPort *pLastPort = NULL; ! for (ComPortMap::const_iterator i = map.begin() ; i != map.end() ; i++) { if (pLastPort != i->first) { if (pLastPort) cout << endl; ! cout << "Route " << pMapName << " " << i->first->Name() << " -->"; pLastPort = i->first; *************** *** 167,169 **** --- 194,202 ---- cout << endl; } + + void ComHub::RouteReport() const + { + ::RouteReport(routeDataMap, "data"); + ::RouteReport(routeFlowControlMap, "flow control"); + } /////////////////////////////////////////////////////////////// Index: comio.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comio.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comio.cpp 1 Feb 2007 12:14:59 -0000 1.2 --- comio.cpp 5 Feb 2007 09:33:20 -0000 1.3 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 153,159 **** } /////////////////////////////////////////////////////////////// - int ReadOverlapped::iNext = 0; - int WriteOverlapped::iNext = 0; - /////////////////////////////////////////////////////////////// WriteOverlapped::WriteOverlapped(ComPort &_port, const void *_pBuf, DWORD _len) : port(_port), --- 156,159 ---- *************** *** 178,192 **** LPOVERLAPPED pOverlapped) { ! WriteOverlapped &overlapped = *(WriteOverlapped *)pOverlapped; if (err != ERROR_SUCCESS && err != ERROR_OPERATION_ABORTED) ! TraceError(err, "WriteOverlapped::OnWrite: %s", overlapped.port.Name().c_str()); ! ! if (overlapped.len > done) ! overlapped.port.WriteLost() += overlapped.len - done; ! ! overlapped.port.WriteQueued() -= overlapped.len; ! delete &overlapped; } --- 178,187 ---- 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); } *************** *** 195,209 **** ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); ! i = iNext++; ! if (!pBuf) { return FALSE; - } ! if (::WriteFileEx(port.Handle(), pBuf, len, this, OnWrite)) { ! port.WriteQueued() += len; ! return TRUE; ! } ! return FALSE; } /////////////////////////////////////////////////////////////// --- 190,200 ---- ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); ! if (!pBuf) ! return FALSE; ! if (!::WriteFileEx(port.Handle(), pBuf, len, this, OnWrite)) return FALSE; ! return TRUE; } /////////////////////////////////////////////////////////////// *************** *** 213,224 **** LPOVERLAPPED pOverlapped) { ! ReadOverlapped &overlapped = *(ReadOverlapped *)pOverlapped; ! if (err == ERROR_SUCCESS) ! overlapped.port.OnRead(overlapped.buf, done); ! else ! TraceError(err, "ReadOverlapped::OnRead(): %s", overlapped.port.Name().c_str()); ! overlapped.StartRead(); } --- 204,215 ---- LPOVERLAPPED pOverlapped) { ! ReadOverlapped *pOver = (ReadOverlapped *)pOverlapped; ! if (err != ERROR_SUCCESS) { ! TraceError(err, "ReadOverlapped::OnRead(): %s", pOver->port.Name().c_str()); ! done = 0; ! } ! pOver->port.OnRead(pOver, pOver->buf, done); } *************** *** 227,232 **** ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); - i = iNext++; - if (::ReadFileEx(port.Handle(), buf, sizeof(buf), this, OnRead)) { return TRUE; --- 218,221 ---- |
From: Vyacheslav F. <vf...@us...> - 2007-02-02 09:52:30
|
Update of /cvsroot/com0com/com0com/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv31299 Modified Files: trace.c Log Message: Fixed huge system error logging if bad trace file used Index: trace.c =================================================================== RCS file: /cvsroot/com0com/com0com/sys/trace.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** trace.c 27 Oct 2006 12:36:58 -0000 1.22 --- trace.c 2 Feb 2007 09:52:21 -0000 1.23 *************** *** 2,6 **** * $Id$ * ! * Copyright (c) 2004-2006 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify --- 2,6 ---- * $Id$ * ! * Copyright (c) 2004-2007 Vyacheslav Frolov * * This program is free software; you can redistribute it and/or modify *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.23 2007/02/02 09:52:21 vfrolov + * Fixed huge system error logging if bad trace file used + * * Revision 1.22 2006/10/27 12:36:58 vfrolov * Removed unnecessary InterlockedExchange*() *************** *** 112,115 **** --- 115,119 ---- #include "strutils.h" /********************************************************************/ + #define TRACE_ERROR_LIMIT 10 #define TRACE_BUF_SIZE 256 #define TRACE_BUFS_NUM 4 *************** *** 135,138 **** --- 139,143 ---- } traceEnable; /********************************************************************/ + static int errorCount; static WCHAR traceFileNameBuf[256]; static UNICODE_STRING traceFileName; *************** *** 892,897 **** NULL); ! if (!NT_SUCCESS(status)) SysLog(pIoObject, status, L"TraceWrite ZwWriteFile FAIL"); return status; --- 897,904 ---- NULL); ! if (!NT_SUCCESS(status)) { ! errorCount++; SysLog(pIoObject, status, L"TraceWrite ZwWriteFile FAIL"); + } return status; *************** *** 912,915 **** --- 919,930 ---- static LONG strOldFreeInd = 0; + if (errorCount > TRACE_ERROR_LIMIT) { + if (errorCount < (TRACE_ERROR_LIMIT + 100)) { + errorCount += 100; + SysLog(pDrvObj, STATUS_SUCCESS, L"Trace disabled"); + } + return; + } + if (KeGetCurrentIrql() != PASSIVE_LEVEL) { SIZE_T size; *************** *** 1026,1033 **** status = ZwClose(handle); ! if (!NT_SUCCESS(status)) SysLog(pIoObject, status, L"TraceOutput ZwClose FAIL"); } else { SysLog(pIoObject, status, L"TraceOutput ZwCreateFile FAIL"); } --- 1041,1051 ---- status = ZwClose(handle); ! if (!NT_SUCCESS(status)) { ! errorCount++; SysLog(pIoObject, status, L"TraceOutput ZwClose FAIL"); + } } else { + errorCount++; SysLog(pIoObject, status, L"TraceOutput ZwCreateFile FAIL"); } *************** *** 1075,1078 **** --- 1093,1097 ---- RtlInitUnicodeString(&traceFileName, NULL); + errorCount = 0; QueryRegistryTrace(pRegistryPath); *************** *** 1096,1099 **** --- 1115,1123 ---- TraceF(NULL, "===== BEGIN ====="); TraceF(NULL, "VERSION " C0C_VERSION_STR " (" __DATE__ " " __TIME__ ")"); + + if (errorCount) { + RtlInitUnicodeString(&traceFileName, NULL); + SysLog(pDrvObj, STATUS_SUCCESS, L"Trace disabled"); + } } } |
From: Vyacheslav F. <vf...@us...> - 2007-02-01 12:17:04
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv17431 Added Files: .cvsignore Log Message: Initial revision --- NEW FILE: .cvsignore --- *.ncb *.sln *.user Release Debug |
From: Vyacheslav F. <vf...@us...> - 2007-02-01 12:15:10
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv16449 Modified Files: comhub.cpp comhub.h hub4com.cpp comio.cpp comparams.cpp comparams.h precomp.h Log Message: Redesigned COM port params Index: comparams.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comparams.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comparams.cpp 23 Jan 2007 09:13:10 -0000 1.1 --- comparams.cpp 1 Feb 2007 12:14:59 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 34,41 **** byteSize(8), parity(NOPARITY), ! stopBits(ONESTOPBIT) { } BOOL ComParams::SetParity(const char *pParity) { --- 37,76 ---- byteSize(8), parity(NOPARITY), ! stopBits(ONESTOPBIT), ! outCts(1), ! outDsr(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) { *************** *** 46,50 **** case 'm': parity = MARKPARITY; break; case 's': parity = SPACEPARITY; break; ! case 'd': parity = -1; break; default : return FALSE; } --- 81,85 ---- case 'm': parity = MARKPARITY; break; case 's': parity = SPACEPARITY; break; ! case 'c': parity = -1; break; default : return FALSE; } *************** *** 62,66 **** break; case '2': stopBits = TWOSTOPBITS; break; ! case 'd': stopBits = -1; break; default : return FALSE; } --- 97,101 ---- break; case '2': stopBits = TWOSTOPBITS; break; ! case 'c': stopBits = -1; break; default : return FALSE; } *************** *** 68,72 **** } ! const char *ComParams::ParityStr(int parity) { switch (parity) { --- 103,167 ---- } ! BOOL ComParams::SetOutCts(const char *pOutCts) ! { ! if (_stricmp(pOutCts, "on") == 0) { ! outCts = 1; ! } ! else ! if (_stricmp(pOutCts, "off") == 0) { ! outCts = 0; ! } ! else ! if (*pOutCts == 'c') { ! outCts = -1; ! } ! else ! return FALSE; ! ! return TRUE; ! } ! ! BOOL ComParams::SetOutDsr(const char *pOutDsr) ! { ! if (_stricmp(pOutDsr, "on") == 0) { ! outDsr = 1; ! } ! else ! if (_stricmp(pOutDsr, "off") == 0) { ! outDsr = 0; ! } ! else ! if (*pOutDsr == 'c') { ! outDsr = -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) { *************** *** 76,85 **** case MARKPARITY: return "mark"; case SPACEPARITY: return "space"; ! case -1: return "default"; } return "?"; } ! const char *ComParams::StopBitsStr(int stopBits) { switch (stopBits) { --- 171,180 ---- case MARKPARITY: return "mark"; case SPACEPARITY: return "space"; ! case -1: return "current"; } return "?"; } ! string ComParams::StopBitsStr(int stopBits) { switch (stopBits) { *************** *** 87,113 **** case ONE5STOPBITS: return "1.5"; case TWOSTOPBITS: return "2"; ! case -1: return "default"; } return "?"; } const char *ComParams::BaudRateLst() { ! return "a positive number or d[efault]"; } const char *ComParams::ByteSizeLst() { ! return "a positive number or d[efault]"; } const char *ComParams::ParityLst() { ! return "n[o], o[dd], e[ven], m[ark], s[pace] or d[efault]"; } const char *ComParams::StopBitsLst() { ! return "1, 1.5, 2 or d[efault]"; } /////////////////////////////////////////////////////////////// --- 182,238 ---- case ONE5STOPBITS: return "1.5"; case TWOSTOPBITS: return "2"; ! case -1: return "current"; } return "?"; } + string ComParams::OutCtsStr(int outCts) + { + switch (outCts) { + case 1: return "on"; + case 0: return "off"; + case -1: return "current"; + } + return "?"; + } + + string ComParams::OutDsrStr(int outDsr) + { + switch (outDsr) { + 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::OutCtsLst() ! { ! return "on, off or c[urrent]"; ! } ! ! const char *ComParams::OutDsrLst() ! { ! return "on, off or c[urrent]"; } /////////////////////////////////////////////////////////////// Index: hub4com.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/hub4com.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** hub4com.cpp 23 Jan 2007 09:13:10 -0000 1.1 --- hub4com.cpp 1 Feb 2007 12:14:59 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 36,40 **** cerr << "Usage:" << endl ! << " " << pProgName << " [options] \\\\.\\<port0> \\\\.\\<port1> ..." << endl << endl << "Common options:" << endl --- 39,43 ---- cerr << "Usage:" << endl ! << " " << pProgName << " [options] \\\\.\\<port0> [options] \\\\.\\<port1> ..." << endl << endl << "Common options:" << endl *************** *** 42,54 **** << endl << "COM port options:" << endl ! << " --baud=<b> - set baud rate to <b> (default is " << ComParams().BaudRate() << ")," << endl << " where <b> is " << ComParams::BaudRateLst() << "." << endl ! << " --data=<d> - set data bits to <d> (default is " << ComParams().ByteSize() << "), where <d> is" << endl ! << " " << ComParams::ByteSizeLst() << "." << endl ! << " --parity=<p> - set parity to <p> (default is " << ComParams::ParityStr(ComParams().Parity()) << "), where <p> is" << endl << " " << ComParams::ParityLst() << "." << endl ! << " --stop=<s> - set stop bits to <s> (default is " << ComParams::StopBitsStr(ComParams().StopBits()) << "), where <s> is" << endl ! << " " << ComParams::StopBitsLst() << "." << endl ! << " The value d[efault] above means to use current COM port settings." << endl << endl << "Route options:" << endl --- 45,65 ---- << 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 <d>" << endl ! << " (" << ComParams().OutDsrStr() << " by default), where <d> is" << endl ! << " " << ComParams::OutDsrLst() << "." << endl ! << endl ! << " The value c[urrent] above means to use current COM port settings." << endl << endl << "Route options:" << endl *************** *** 59,62 **** --- 70,74 ---- << " --no-route=<LstR>:<LstL> - do not send data received from any ports from" << endl << " <LstR> to ports from <LstL>." << endl + << endl << " The syntax of <LstR> and <LstL> above: <P1>[,<P2>...]" << endl << " The <Pn> above is a zero based position number of port or All." << endl *************** *** 68,71 **** --- 80,84 ---- << " " << pProgName << " \\\\.\\COM1 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl << " " << pProgName << " --route=All:All \\\\.\\CNCB0 \\\\.\\CNCB1 \\\\.\\CNCB2" << endl + << " " << pProgName << " --baud=9600 \\\\.\\COM1 --baud=19200 \\\\.\\CNCB1" << endl ; exit(1); *************** *** 145,164 **** int i; for (i = 1 ; i < argc ; i++) { ! if (GetParam(argv[i], "--") == NULL) ! break; } - ComHub hub(argc - i); BOOL defaultRouteData = TRUE; ! char **pArgs = &argv[1]; ComParams comParams; ! while (argc > 1) { const char *pArg = GetParam(*pArgs, "--"); ! if (!pArg) ! break; const char *pParam; --- 158,185 ---- int i; + ComHub hub; + for (i = 1 ; i < argc ; i++) { ! if (!GetParam(argv[i], "--")) { ! if (!hub.Add(argv[i])) ! return 1; ! } } BOOL defaultRouteData = 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); ! ! continue; ! } const char *pParam; *************** *** 168,175 **** } else if ((pParam = GetParam(pArg, "baud=")) != NULL) { ! comParams.SetBaudRate(pParam); } else if ((pParam = GetParam(pArg, "data=")) != NULL) { ! comParams.SetByteSize(pParam); } else if ((pParam = GetParam(pArg, "parity=")) != NULL) { --- 189,202 ---- } 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) { *************** *** 185,188 **** --- 212,227 ---- } } 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, "route=")) != NULL) { defaultRouteData = FALSE; *************** *** 200,209 **** exit(1); } - - pArgs++; - argc--; } ! if (argc < 2) Usage(argv[0]); --- 239,245 ---- exit(1); } } ! if (plugged < 2) Usage(argv[0]); *************** *** 213,221 **** } - for (i = 1 ; i < argc ; i++) { - if (!hub.PlugIn(i - 1, pArgs[i - 1], comParams)) - return 1; - } - hub.RouteDataReport(); --- 249,252 ---- Index: comparams.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comparams.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comparams.h 23 Jan 2007 09:13:10 -0000 1.1 --- comparams.h 1 Feb 2007 12:14:59 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 35,45 **** ComParams(); ! void SetBaudRate(const char *pBaudRate) { baudRate = atol(pBaudRate); } ! void SetByteSize(const char *pByteSize) { byteSize = atoi(pByteSize); } BOOL SetParity(const char *pParity); BOOL SetStopBits(const char *pStopBits); ! static const char *ParityStr(int parity); ! static const char *StopBitsStr(int stopBits); static const char *BaudRateLst(); --- 38,61 ---- 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); + BOOL SetOutDsr(const char *pOutDsr); ! 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); ! static string OutDsrStr(int outDsr); ! ! 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); } static const char *BaudRateLst(); *************** *** 47,50 **** --- 63,68 ---- static const char *ParityLst(); static const char *StopBitsLst(); + static const char *OutCtsLst(); + static const char *OutDsrLst(); long BaudRate() const { return baudRate; } *************** *** 52,55 **** --- 70,75 ---- int Parity() const { return parity; } int StopBits() const { return stopBits; } + int OutCts() const { return outCts; } + int OutDsr() const { return outDsr; } private: *************** *** 58,61 **** --- 78,83 ---- int parity; int stopBits; + int outCts; + int outDsr; }; /////////////////////////////////////////////////////////////// Index: comhub.h =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comhub.h 23 Jan 2007 09:13:10 -0000 1.1 --- comhub.h 1 Feb 2007 12:14:58 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2007/02/01 12:14:58 vfrolov + * Redesigned COM port params + * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision *************** *** 39,44 **** { public: ! ComHub(int num); BOOL PlugIn(int n, const char *pPath, const ComParams &comParams); BOOL StartAll(); --- 42,48 ---- { public: ! ComHub() {} + BOOL Add(const char *pPath); BOOL PlugIn(int n, const char *pPath, const ComParams &comParams); BOOL StartAll(); Index: precomp.h =================================================================== RCS file: /cvsroot/com0com/hub4com/precomp.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** precomp.h 23 Jan 2007 09:13:10 -0000 1.1 --- precomp.h 1 Feb 2007 12:14:59 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 35,38 **** --- 38,42 ---- #include <iostream> #include <map> + #include <sstream> using namespace std; Index: comhub.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comhub.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comhub.cpp 23 Jan 2007 09:13:10 -0000 1.1 --- comhub.cpp 1 Feb 2007 12:14:58 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2007/02/01 12:14:58 vfrolov + * Redesigned COM port params + * * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision *************** *** 48,63 **** } /////////////////////////////////////////////////////////////// ! ComHub::ComHub(int num) { ! for (int i = 0 ; i < num ; i++) { ! ComPort *pPort = new ComPort(*this); ! ! if (!pPort) { ! cerr << "Can't create ComPort " << i << endl; ! break; ! } ! ports.push_back(pPort); } } --- 51,66 ---- } /////////////////////////////////////////////////////////////// ! 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; } Index: comio.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/comio.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comio.cpp 23 Jan 2007 09:13:10 -0000 1.1 --- comio.cpp 1 Feb 2007 12:14:59 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * 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 *************** *** 84,91 **** } ! if (comParams.BaudRate() > 0) dcb.BaudRate = (DWORD)comParams.BaudRate(); ! if (comParams.ByteSize() > 0) dcb.ByteSize = (BYTE)comParams.ByteSize(); --- 87,94 ---- } ! if (comParams.BaudRate() >= 0) dcb.BaudRate = (DWORD)comParams.BaudRate(); ! if (comParams.ByteSize() >= 0) dcb.ByteSize = (BYTE)comParams.ByteSize(); *************** *** 96,101 **** dcb.StopBits = (BYTE)comParams.StopBits(); ! dcb.fOutxCtsFlow = FALSE; ! dcb.fOutxDsrFlow = FALSE; dcb.fDsrSensitivity = FALSE; dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; --- 99,108 ---- dcb.StopBits = (BYTE)comParams.StopBits(); ! if (comParams.OutCts() >= 0) ! dcb.fOutxCtsFlow = comParams.OutCts(); ! ! if (comParams.OutDsr() >= 0) ! dcb.fOutxDsrFlow = comParams.OutDsr(); ! dcb.fDsrSensitivity = FALSE; dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; *************** *** 136,143 **** cout << "Open(" ! << "\"" << pPath << "\", baud=" << (unsigned)dcb.BaudRate ! << ", data=" << (unsigned)dcb.ByteSize << ", parity=" << ComParams::ParityStr(dcb.Parity) << ", stop=" << ComParams::StopBitsStr(dcb.StopBits) << ") - OK" << endl; return handle; --- 143,152 ---- 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) << ") - OK" << endl; return handle; |
From: Vyacheslav F. <vf...@us...> - 2007-02-01 12:06:36
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv12896 Modified Files: ReadMe.txt Log Message: Fixed typo Index: ReadMe.txt =================================================================== RCS file: /cvsroot/com0com/hub4com/ReadMe.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ReadMe.txt 23 Jan 2007 09:13:10 -0000 1.1 --- ReadMe.txt 1 Feb 2007 12:06:32 -0000 1.2 *************** *** 52,56 **** 2. Start the hub4com.exe on COM1, CNCB0 and CNCB1 ports: ! hub4com \\.\COM1 \\.\CNCB1 \\.\CNCB2 It will send data received from COM1 port to CNCB0 and CNCB1 ports --- 52,56 ---- 2. Start the hub4com.exe on COM1, CNCB0 and CNCB1 ports: ! hub4com \\.\COM1 \\.\CNCB0 \\.\CNCB1 It will send data received from COM1 port to CNCB0 and CNCB1 ports |
From: Vyacheslav F. <vf...@us...> - 2007-01-23 09:13:16
|
Update of /cvsroot/com0com/hub4com In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv24272 Added Files: ReadMe.txt comparams.cpp comio.h comport.cpp utils.cpp comhub.h hub4com.vcproj comparams.h hub4com.rc utils.h comhub.cpp hub4com.cpp comport.h comio.cpp precomp.h version.h Log Message: Initial revision --- NEW FILE: comport.cpp --- /* * $Id: comport.cpp,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comport.cpp,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include "precomp.h" #include "comport.h" #include "comhub.h" #include "comio.h" /////////////////////////////////////////////////////////////// ComPort::ComPort(ComHub &_hub) : handle(INVALID_HANDLE_VALUE), hub(_hub), writeQueued(0) { } BOOL ComPort::Open(const char *pPath, const ComParams &comParams) { if (handle != INVALID_HANDLE_VALUE) return FALSE; while (writeQueued) { if (SleepEx(5000, TRUE) != WAIT_IO_COMPLETION) return FALSE; } writeLost = 0; string path(pPath); name = path.substr(path.rfind('\\') + 1); handle = ::OpenComPort(pPath, comParams); return handle != INVALID_HANDLE_VALUE; } BOOL ComPort::Start() { if (handle == INVALID_HANDLE_VALUE) return FALSE; ReadOverlapped *pOverlapped; pOverlapped = new ReadOverlapped(*this); if (!pOverlapped) return FALSE; if (!pOverlapped->StartRead()) { delete pOverlapped; return FALSE; } cout << "Started " << name << endl; return TRUE; } BOOL ComPort::Write(LPCVOID pData, DWORD len) { if (handle == INVALID_HANDLE_VALUE) { writeLost += len; return FALSE; } WriteOverlapped *pOverlapped; pOverlapped = new WriteOverlapped(*this, pData, len); if (!pOverlapped) return FALSE; if (writeQueued > 256) PurgeComm(handle, PURGE_TXABORT|PURGE_TXCLEAR); if (!pOverlapped->StartWrite()) { delete pOverlapped; return FALSE; } //cout << "Started Write " << pOverlapped->i << " " << path << " " << len << " " << writeQueued << endl; return TRUE; } void ComPort::OnRead(LPCVOID pBuf, DWORD done) { hub.Write(this, pBuf, done); } void ComPort::LostReport() { if (writeLost) { writeLostTotal += writeLost; cout << "Write lost: " << name << " " << writeLost << " total " << writeLostTotal << endl; writeLost = 0; } } /////////////////////////////////////////////////////////////// --- NEW FILE: comparams.cpp --- /* * $Id: comparams.cpp,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comparams.cpp,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include "precomp.h" #include "comparams.h" /////////////////////////////////////////////////////////////// ComParams::ComParams() : baudRate(CBR_19200), byteSize(8), parity(NOPARITY), stopBits(ONESTOPBIT) { } 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 'd': 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 'd': stopBits = -1; break; default : return FALSE; } return TRUE; } const char *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 "default"; } return "?"; } const char *ComParams::StopBitsStr(int stopBits) { switch (stopBits) { case ONESTOPBIT: return "1"; case ONE5STOPBITS: return "1.5"; case TWOSTOPBITS: return "2"; case -1: return "default"; } return "?"; } const char *ComParams::BaudRateLst() { return "a positive number or d[efault]"; } const char *ComParams::ByteSizeLst() { return "a positive number or d[efault]"; } const char *ComParams::ParityLst() { return "n[o], o[dd], e[ven], m[ark], s[pace] or d[efault]"; } const char *ComParams::StopBitsLst() { return "1, 1.5, 2 or d[efault]"; } /////////////////////////////////////////////////////////////// --- NEW FILE: hub4com.vcproj --- <?xml version="1.0" encoding="windows-1251"?> <VisualStudioProject ProjectType="Visual C++" Version="8,00" Name="hub4com" ProjectGUID="{AC4EC208-ED55-4F9D-ACDD-A57642C3C296}" RootNamespace="hub4com" Keyword="Win32Proj" > <Platforms> <Platform Name="Win32" /> </Platforms> <ToolFiles> </ToolFiles> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="Debug" IntermediateDirectory="Debug" ConfigurationType="1" > <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="3" UsePrecompiledHeader="0" PrecompiledHeaderFile="" WarningLevel="4" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" LinkIncremental="2" 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="1" > <Tool Name="VCPreBuildEventTool" /> <Tool Name="VCCustomBuildTool" /> <Tool Name="VCXMLDataGeneratorTool" /> <Tool Name="VCWebServiceProxyGeneratorTool" /> <Tool Name="VCMIDLTool" /> <Tool Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE" RuntimeLibrary="2" UsePrecompiledHeader="0" PrecompiledHeaderFile="" WarningLevel="4" Detect64BitPortabilityProblems="true" DebugInformationFormat="3" /> <Tool Name="VCManagedResourceCompilerTool" /> <Tool Name="VCResourceCompilerTool" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" LinkIncremental="2" 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=".\comhub.h" > </File> <File RelativePath=".\comio.h" > </File> <File RelativePath=".\comparams.h" > </File> <File RelativePath=".\comport.h" > </File> <File RelativePath=".\precomp.h" > </File> <File RelativePath=".\utils.h" > </File> <File RelativePath=".\version.h" > </File> </Filter> <Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" > <File RelativePath=".\hub4com.rc" > </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=".\comhub.cpp" > </File> <File RelativePath=".\comio.cpp" > </File> <File RelativePath=".\comparams.cpp" > </File> <File RelativePath=".\comport.cpp" > </File> <File RelativePath=".\hub4com.cpp" > </File> <File RelativePath=".\utils.cpp" > </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: hub4com.rc --- /* * $Id: hub4com.rc,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: hub4com.rc,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include <windows.h> #include "version.h" #define VER_FILEVERSION H4C_V1,H4C_V2,H4C_V3,H4C_V4 #define VER_PRODUCTVERSION_STR H4C_VERSION_STR #define VER_LEGALCOPYRIGHT_YEARS H4C_COPYRIGHT_YEARS #define VER_COMPANYNAME_STR "Vyacheslav Frolov\0" #define VER_LEGALCOPYRIGHT_STR "Copyright (c) " VER_LEGALCOPYRIGHT_YEARS " " VER_COMPANYNAME_STR #define VER_PRODUCTNAME_STR "HUB for COM ports" #ifdef _DEBUG #define VER_DEBUG_STR " (debug version)" #define VER_FILEFLAGS VS_FF_DEBUG #else #define VER_DEBUG_STR "" #define VER_FILEFLAGS 0 #endif #define VER_FILEDESCRIPTION_STR VER_PRODUCTNAME_STR VER_DEBUG_STR #define VER_INTERNALNAME_STR "hub4com\0" #define VER_ORIGINALFILENAME_STR "hub4com.exe\0" #define VER_FILEFLAGSMASK VS_FFI_FILEFLAGSMASK #define VER_FILEOS VOS_NT_WINDOWS32 #define VER_FILETYPE VFT_APP #define VER_FILESUBTYPE 0 #include <common.ver> --- NEW FILE: hub4com.cpp --- /* * $Id: hub4com.cpp,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: hub4com.cpp,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include "precomp.h" #include "comparams.h" #include "comhub.h" #include "utils.h" /////////////////////////////////////////////////////////////// static void Usage(const char *pProgName) { cerr << "Usage:" << endl << " " << pProgName << " [options] \\\\.\\<port0> \\\\.\\<port1> ..." << endl << endl << "Common options:" << endl << " --help - show this help." << endl << endl << "COM port options:" << endl << " --baud=<b> - set baud rate to <b> (default is " << ComParams().BaudRate() << ")," << endl << " where <b> is " << ComParams::BaudRateLst() << "." << endl << " --data=<d> - set data bits to <d> (default is " << ComParams().ByteSize() << "), where <d> is" << endl << " " << ComParams::ByteSizeLst() << "." << endl << " --parity=<p> - set parity to <p> (default is " << ComParams::ParityStr(ComParams().Parity()) << "), where <p> is" << endl << " " << ComParams::ParityLst() << "." << endl << " --stop=<s> - set stop bits to <s> (default is " << ComParams::StopBitsStr(ComParams().StopBits()) << "), where <s> is" << endl << " " << ComParams::StopBitsLst() << "." << endl << " The value d[efault] above means to use current COM port settings." << endl << endl << "Route options:" << endl << " --route=<LstR>:<LstL> - send data received from any ports from <LstR> to" << endl << " all ports from <LstL>." << endl << " --bi-route=<LstR>:<LstL> - send data received from any ports from <LstR> to" << endl << " all ports from <LstL> and vice versa." << endl << " --no-route=<LstR>:<LstL> - do not send data received from any ports from" << endl << " <LstR> to ports from <LstL>." << endl << " The syntax of <LstR> and <LstL> 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 ; exit(1); } /////////////////////////////////////////////////////////////// static BOOL Route(ComHub &hub, const char *pListFrom, const char *pListTo, BOOL noRoute) { char *pTmpListFrom = _strdup(pListFrom); char *pTmpListTo = _strdup(pListTo); if (!pTmpListFrom || !pTmpListTo) { 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 *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); } } free(pTmpListTo); free(pTmpListFrom); return res; } /////////////////////////////////////////////////////////////// static void Route(ComHub &hub, const char *pParam, BOOL biDirection, BOOL noRoute) { 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) || (biDirection && !Route(hub, pListL, pListR, noRoute))) { cerr << "Invalid route " << pParam << endl; exit(1); } free(pTmp); } /////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { int i; for (i = 1 ; i < argc ; i++) { if (GetParam(argv[i], "--") == NULL) break; } ComHub hub(argc - i); BOOL defaultRouteData = TRUE; char **pArgs = &argv[1]; ComParams comParams; while (argc > 1) { const char *pArg = GetParam(*pArgs, "--"); if (!pArg) break; const char *pParam; if ((pParam = GetParam(pArg, "help")) != NULL && *pParam == 0) { Usage(argv[0]); } else if ((pParam = GetParam(pArg, "baud=")) != NULL) { comParams.SetBaudRate(pParam); } else if ((pParam = GetParam(pArg, "data=")) != NULL) { comParams.SetByteSize(pParam); } 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, "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 { cerr << "Unknown option " << pArg << endl; exit(1); } pArgs++; argc--; } if (argc < 2) Usage(argv[0]); if (defaultRouteData) { hub.RouteData(0, -1, FALSE); hub.RouteData(1, 0, FALSE); } for (i = 1 ; i < argc ; i++) { if (!hub.PlugIn(i - 1, pArgs[i - 1], comParams)) return 1; } hub.RouteDataReport(); if (hub.StartAll()) { DWORD nextReportTime = 0; for (;;) { SleepEx(5000, TRUE); DWORD time = GetTickCount(); if ((nextReportTime - time - 1) > 10000) { hub.LostReport(); nextReportTime = time + 5000; } } } return 1; } /////////////////////////////////////////////////////////////// --- NEW FILE: utils.h --- /* * $Id: utils.h,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: utils.h,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #ifndef _C0C_UTILS_H_ #define _C0C_UTILS_H_ char *STRTOK_R(char *pStr, const char *pDelims, char **ppSave); BOOL StrToInt(const char *pStr, int *pNum); const char *GetParam(const char *pArg, const char *pPattern); #endif /* _C0C_UTILS_H_ */ --- NEW FILE: comport.h --- /* * $Id: comport.h,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comport.h,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #ifndef _COMPORT_H #define _COMPORT_H /////////////////////////////////////////////////////////////// class ComHub; class ComParams; /////////////////////////////////////////////////////////////// class ComPort { public: ComPort(ComHub &_hub); BOOL Open(const char *pPath, const ComParams &comParams); BOOL Start(); BOOL Write(LPCVOID pData, DWORD len); void OnRead(LPCVOID pBuf, DWORD done); const string &Name() const { return name; } HANDLE Handle() const { return handle; } DWORD &WriteQueued() { return writeQueued; } DWORD &WriteLost() { return writeLost; } void LostReport(); private: string name; HANDLE handle; ComHub &hub; DWORD writeQueued; DWORD writeLost; DWORD writeLostTotal; }; /////////////////////////////////////////////////////////////// #endif // _COMPORT_H --- NEW FILE: comio.h --- /* * $Id: comio.h,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comio.h,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #ifndef _COMIO_H #define _COMIO_H /////////////////////////////////////////////////////////////// class ComPort; class ComParams; /////////////////////////////////////////////////////////////// HANDLE OpenComPort(const char *pPath, const ComParams &comParams); /////////////////////////////////////////////////////////////// class ReadOverlapped : private OVERLAPPED { public: ReadOverlapped(ComPort &_port) : port(_port) {} BOOL StartRead(); private: static VOID CALLBACK OnRead( DWORD err, DWORD done, LPOVERLAPPED pOverlapped); ComPort &port; BYTE buf[64]; int i; static int iNext; }; class WriteOverlapped : private OVERLAPPED { public: WriteOverlapped(ComPort &_port, const void *_pBuf, DWORD _len); ~WriteOverlapped(); BOOL StartWrite(); private: static VOID CALLBACK OnWrite( DWORD err, DWORD done, LPOVERLAPPED pOverlapped); ComPort &port; BYTE *pBuf; DWORD len; int i; static int iNext; }; /////////////////////////////////////////////////////////////// #endif // _COMIO_H --- NEW FILE: comparams.h --- /* * $Id: comparams.h,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comparams.h,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #ifndef _COMPARAMS_H #define _COMPARAMS_H /////////////////////////////////////////////////////////////// class ComParams { public: ComParams(); void SetBaudRate(const char *pBaudRate) { baudRate = atol(pBaudRate); } void SetByteSize(const char *pByteSize) { byteSize = atoi(pByteSize); } BOOL SetParity(const char *pParity); BOOL SetStopBits(const char *pStopBits); static const char *ParityStr(int parity); static const char *StopBitsStr(int stopBits); static const char *BaudRateLst(); static const char *ByteSizeLst(); static const char *ParityLst(); static const char *StopBitsLst(); long BaudRate() const { return baudRate; } int ByteSize() const { return byteSize; } int Parity() const { return parity; } int StopBits() const { return stopBits; } private: long baudRate; int byteSize; int parity; int stopBits; }; /////////////////////////////////////////////////////////////// #endif // _COMPARAMS_H --- NEW FILE: comhub.h --- /* * $Id: comhub.h,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comhub.h,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #ifndef _COMHUB_H #define _COMHUB_H /////////////////////////////////////////////////////////////// class ComPort; class ComParams; /////////////////////////////////////////////////////////////// typedef vector<ComPort*> ComPorts; typedef multimap<ComPort*, ComPort*> ComPortMap; /////////////////////////////////////////////////////////////// class ComHub { public: ComHub(int num); BOOL PlugIn(int n, const char *pPath, const ComParams &comParams); BOOL StartAll(); void Write(ComPort *pFromPort, LPCVOID pData, DWORD len); void LostReport(); void RouteData(int iFrom, int iTo, BOOL noRoute); void RouteDataReport(); int NumPorts() { return (int)ports.size(); } private: ComPorts ports; ComPortMap routeDataMap; }; /////////////////////////////////////////////////////////////// #endif // _COMHUB_H --- NEW FILE: precomp.h --- /* * $Id: precomp.h,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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.h,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #ifndef _PRECOMP_H_ #define _PRECOMP_H_ #include <windows.h> #include <string> #include <vector> #include <iostream> #include <map> using namespace std; #pragma warning(disable:4512) // assignment operator could not be generated #endif /* _PRECOMP_H_ */ --- NEW FILE: utils.cpp --- /* * $Id: utils.cpp,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: utils.cpp,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include "precomp.h" #include "utils.h" /////////////////////////////////////////////////////////////// static BOOL IsDelim(char c, const char *pDelims) { while (*pDelims) { if (c == *pDelims++) return TRUE; } return FALSE; } char *STRTOK_R(char *pStr, const char *pDelims, char **ppSave) { if (!pStr) pStr = *ppSave; while (IsDelim(*pStr, pDelims)) pStr++; if (!*pStr) { *ppSave = pStr; return NULL; } char *pToken = pStr; while (*pStr && !IsDelim(*pStr, pDelims)) pStr++; if (*pStr) *pStr++ = 0; *ppSave = pStr; return pToken; } /////////////////////////////////////////////////////////////// BOOL StrToInt(const char *pStr, int *pNum) { BOOL res = FALSE; int num; int sign = 1; switch (*pStr) { case '-': sign = -1; case '+': pStr++; break; } for (num = 0 ;; pStr++) { switch (*pStr) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': num = num*10 + (*pStr - '0'); res = TRUE; continue; case 0: break; default: res = FALSE; } break; } if (pNum) *pNum = num*sign; return res; } /////////////////////////////////////////////////////////////// const char *GetParam(const char *pArg, const char *pPattern) { size_t lenPattern = strlen(pPattern); if (_strnicmp(pArg, pPattern, lenPattern) != 0) return NULL; return pArg + lenPattern; } /////////////////////////////////////////////////////////////// --- NEW FILE: version.h --- /* * $Id: version.h,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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 * */ #ifndef _H4C_VERSION_H_ #define _H4C_VERSION_H_ #define H4C_COPYRIGHT_YEARS "2006-2007" #define H4C_V1 1 #define H4C_V2 0 #define H4C_V3 0 #define H4C_V4 0 #define MK_VERSION_STR1(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4 #define MK_VERSION_STR(V1, V2, V3, V4) MK_VERSION_STR1(V1, V2, V3, V4) #define H4C_VERSION_STR MK_VERSION_STR(H4C_V1, H4C_V2, H4C_V3, H4C_V4) #endif /* _H4C_VERSION_H_ */ --- NEW FILE: comhub.cpp --- /* * $Id: comhub.cpp,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comhub.cpp,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include "precomp.h" #include "comhub.h" #include "comport.h" /////////////////////////////////////////////////////////////// typedef pair <ComPort*, ComPort*> ComPortPair; /////////////////////////////////////////////////////////////// static ComPortMap::iterator FindPair(ComPortMap &map, 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; } /////////////////////////////////////////////////////////////// ComHub::ComHub(int num) { for (int i = 0 ; i < num ; i++) { ComPort *pPort = new ComPort(*this); if (!pPort) { cerr << "Can't create ComPort " << i << endl; break; } ports.push_back(pPort); } } 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::LostReport() { for (ComPorts::const_iterator i = ports.begin() ; i != ports.end() ; i++) (*i)->LostReport(); } void ComHub::RouteData(int iFrom, int iTo, BOOL noRoute) { if (iFrom < 0) { for (int iF = 0 ; iF < (int)ports.size() ; iF++) { if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) RouteData(iF, iT, noRoute); } else { RouteData(iF, iTo, noRoute); } } } else { if(iTo < 0) { for (int iT = 0 ; iT < (int)ports.size() ; iT++) RouteData(iFrom, iT, noRoute); } else if (iFrom != iTo || noRoute) { ComPortPair pair(ports.at(iFrom), ports.at(iTo)); for (;;) { ComPortMap::iterator i = FindPair(routeDataMap, pair); if (i == routeDataMap.end()) { if (!noRoute) routeDataMap.insert(pair); break; } else if (noRoute) { routeDataMap.erase(i); } else { break; } } } } } void ComHub::RouteDataReport() { if (!routeDataMap.size()) { cout << "No route for data" << endl; return; } ComPort *pLastPort = NULL; for (ComPortMap::const_iterator i = routeDataMap.begin() ; i != routeDataMap.end() ; i++) { if (pLastPort != i->first) { if (pLastPort) cout << endl; cout << "Route data " << i->first->Name() << " -->"; pLastPort = i->first; } cout << " " << i->second->Name(); } if (pLastPort) cout << endl; } /////////////////////////////////////////////////////////////// --- NEW FILE: ReadMe.txt --- =========================== HUB for COM ports (hub4com) =========================== INTRODUCTION ============ The HUB for COM ports (hub4com) is a Windows application and is a part of the com0com project. It allows to send data received from one COM port to a number of COM ports and vice versa. In conjunction with the com0com driver the hub4com makes it possible to handle data from a single serial device by a number of different applications. The homepage for com0com project is http://com0com.sourceforge.net/. BUILDING ======== Start Microsoft Visual C++ 2005 with hub4com.vcproj file. Set Active Configuration to hub4com - Win32 Release. Build hub4com.exe. TESTING ======= 1. With the com0com driver create three virtual COM port pairs with port names CNCA0, CNCB0, CNCA1, CNCB1, CNCA2 and CNCB2 (see com0com's ReadMe.txt file for details). 2. Start the hub4com.exe on CNCB0, CNCB1 and CNCB2 ports: hub4com --route=All:All \\.\CNCB0 \\.\CNCB1 \\.\CNCB2 3. Start the HyperTerminal on CNCA0 port. 4. Start the HyperTerminal on CNCA1 port. 5. Start the HyperTerminal on CNCA2 port. 6. The data typed to any HyperTerminal window should be printed on the others HyperTerminal windows. EXAMPLE OF USAGE ================ You have serial device that connected to your computer via COM1 port and you'd like to handle its data by two applications. You can do it this way: 1. With the com0com driver create two virtual COM port pairs with port names CNCA0, CNCB0, CNCA1 and CNCB1 (see com0com's ReadMe.txt for details). 2. Start the hub4com.exe on COM1, CNCB0 and CNCB1 ports: hub4com \\.\COM1 \\.\CNCB1 \\.\CNCB2 It will send data received from COM1 port to CNCB0 and CNCB1 ports and it will send data received from CNCB0 port to COM1 port. 3. Start the applications on CNCA0 and CNCA1 ports. --- NEW FILE: comio.cpp --- /* * $Id: comio.cpp,v 1.1 2007/01/23 09:13:10 vfrolov Exp $ * * Copyright (c) 2006-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: comio.cpp,v $ * Revision 1.1 2007/01/23 09:13:10 vfrolov * Initial revision * * */ #include "precomp.h" #include "comio.h" #include "comport.h" #include "comparams.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(); dcb.fOutxCtsFlow = FALSE; dcb.fOutxDsrFlow = FALSE; dcb.fDsrSensitivity = FALSE; dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; dcb.fDtrControl = DTR_CONTROL_ENABLE; dcb.fOutX = FALSE; dcb.fInX = FALSE; 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; } 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; } cout << "Open(" << "\"" << pPath << "\", baud=" << (unsigned)dcb.BaudRate << ", data=" << (unsigned)dcb.ByteSize << ", parity=" << ComParams::ParityStr(dcb.Parity) << ", stop=" << ComParams::StopBitsStr(dcb.StopBits) << ") - OK" << endl; return handle; } /////////////////////////////////////////////////////////////// int ReadOverlapped::iNext = 0; int WriteOverlapped::iNext = 0; /////////////////////////////////////////////////////////////// WriteOverlapped::WriteOverlapped(ComPort &_port, const void *_pBuf, DWORD _len) : port(_port), len(_len) { pBuf = new BYTE[len]; for (DWORD i = 0 ; i < len ; i++) { pBuf[i] = ((const BYTE *)_pBuf)[i]; } } WriteOverlapped::~WriteOverlapped() { if (pBuf) delete [] pBuf; } VOID CALLBACK WriteOverlapped::OnWrite( DWORD err, DWORD done, LPOVERLAPPED pOverlapped) { WriteOverlapped &overlapped = *(WriteOverlapped *)pOverlapped; if (err != ERROR_SUCCESS && err != ERROR_OPERATION_ABORTED) TraceError(err, "WriteOverlapped::OnWrite: %s", overlapped.port.Name().c_str()); if (overlapped.len > done) overlapped.port.WriteLost() += overlapped.len - done; overlapped.port.WriteQueued() -= overlapped.len; delete &overlapped; } BOOL WriteOverlapped::StartWrite() { ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); i = iNext++; if (!pBuf) { return FALSE; } if (::WriteFileEx(port.Handle(), pBuf, len, this, OnWrite)) { port.WriteQueued() += len; return TRUE; } return FALSE; } /////////////////////////////////////////////////////////////// VOID CALLBACK ReadOverlapped::OnRead( DWORD err, DWORD done, LPOVERLAPPED pOverlapped) { ReadOverlapped &overlapped = *(ReadOverlapped *)pOverlapped; if (err == ERROR_SUCCESS) overlapped.port.OnRead(overlapped.buf, done); else TraceError(err, "ReadOverlapped::OnRead(): %s", overlapped.port.Name().c_str()); overlapped.StartRead(); } BOOL ReadOverlapped::StartRead() { ::memset((OVERLAPPED *)this, 0, sizeof(OVERLAPPED)); i = iNext++; if (::ReadFileEx(port.Handle(), buf, sizeof(buf), this, OnRead)) { return TRUE; } TraceError(GetLastError(), "ReadOverlapped::StartRead(): ReadFileEx() %s", port.Name().c_str()); return FALSE; } /////////////////////////////////////////////////////////////// |