Răsfoiți Sursa

临时提交:新增忽略文件。

Jeff 4 ani în urmă
părinte
comite
e7bd9443ac

+ 1 - 0
.gitignore

@@ -108,6 +108,7 @@ ipch/
 *.ncb
 *.opensdf
 *.sdf
+*.plg
 
 # Visual Studio profiler
 *.psess

+ 25 - 0
Serail-Demo/Demo-19.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.31129.286
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo\Demo.vcxproj", "{69DDDE72-42F8-4F78-BF71-D70E22CE0675}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{69DDDE72-42F8-4F78-BF71-D70E22CE0675}.Debug|x86.ActiveCfg = Debug|Win32
+		{69DDDE72-42F8-4F78-BF71-D70E22CE0675}.Debug|x86.Build.0 = Debug|Win32
+		{69DDDE72-42F8-4F78-BF71-D70E22CE0675}.Release|x86.ActiveCfg = Release|Win32
+		{69DDDE72-42F8-4F78-BF71-D70E22CE0675}.Release|x86.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {0A3DB13F-882C-421F-B852-9010D3D9F801}
+	EndGlobalSection
+EndGlobal

BIN
Serail-Demo/Demo.opt


+ 5 - 4
Serail-Demo/Demo/Demo.dsp

@@ -37,8 +37,8 @@ RSC=rc.exe
 # PROP BASE Target_Dir ""
 # PROP Use_MFC 2
 # PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
+# PROP Output_Dir "..\..\..\..\bin\Demo"
+# PROP Intermediate_Dir "..\..\..\..\bin\Demo\Release"
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c
 # ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c
@@ -60,8 +60,9 @@ LINK32=link.exe
 # PROP BASE Target_Dir ""
 # PROP Use_MFC 2
 # PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
+# PROP Output_Dir "..\..\..\..\bin\Demo"
+# PROP Intermediate_Dir "..\..\..\..\bin\Demo\Debug"
+# PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c
 # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /FR /Yu"stdafx.h" /FD /GZ /c

+ 5 - 5
Serail-Demo/Demo/Demo.vcproj

@@ -18,8 +18,8 @@
 	<Configurations>
 		<Configuration
 			Name="Debug|Win32"
-			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
+			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
+			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)"
 			ConfigurationType="1"
 			UseOfMFC="2"
 			CharacterSet="2"
@@ -90,11 +90,11 @@
 		</Configuration>
 		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
+			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
+			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)"
 			ConfigurationType="1"
 			UseOfMFC="2"
-			CharacterSet="1"
+			CharacterSet="2"
 			WholeProgramOptimization="1"
 			>
 			<Tool

+ 117 - 0
Serail-Demo/Demo/Demo.vcxproj

@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{69DDDE72-42F8-4F78-BF71-D70E22CE0675}</ProjectGuid>
+    <RootNamespace>Demo</RootNamespace>
+    <Keyword>Win32Proj</Keyword>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <PlatformToolset>v142</PlatformToolset>
+    <UseOfMfc>Dynamic</UseOfMfc>
+    <CharacterSet>Unicode</CharacterSet>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <PlatformToolset>v142</PlatformToolset>
+    <UseOfMfc>Dynamic</UseOfMfc>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup>
+    <_ProjectFileVersion>16.0.31025.104</_ProjectFileVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+    <LinkIncremental>true</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)$(Configuration)\</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+    <LinkIncremental>false</LinkIncremental>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <MinimalRebuild>true</MinimalRebuild>
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <SubSystem>Console</SubSystem>
+      <TargetMachine>MachineX86</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <Optimization>MaxSpeed</Optimization>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <SubSystem>Console</SubSystem>
+      <OptimizeReferences>true</OptimizeReferences>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <TargetMachine>MachineX86</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="Demo.cpp" />
+    <ClCompile Include="Serial.cpp" />
+    <ClCompile Include="stdafx.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="TCLCommand.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="Demo.h" />
+    <ClInclude Include="Resource.h" />
+    <ClInclude Include="Serial.h" />
+    <ClInclude Include="stdafx.h" />
+    <ClInclude Include="targetver.h" />
+    <ClInclude Include="TCLCommand.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="Demo.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 59 - 0
Serail-Demo/Demo/Demo.vcxproj.filters

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="源文件">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="头文件">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+    <Filter Include="资源文件">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="Demo.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="Serial.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="stdafx.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="TCLCommand.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="Demo.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="Resource.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="Serial.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="stdafx.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="targetver.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="TCLCommand.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="Demo.rc">
+      <Filter>资源文件</Filter>
+    </ResourceCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+</Project>

+ 155 - 0
Serail-Demo/Demo/stdafx.cpp

@@ -41,6 +41,26 @@ bool parse_key(std::string &RetValue, std::string strLine, TCHAR *lpszText)
 int pares_time_value(std::string strTime)
 {
 	int nTimes = 0;
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
+	if ( strstr(strTime.c_str(), _T("ms")) || strstr(strTime.c_str(), _T("MS")))
+	{
+		nTimes = atol(strTime.c_str());
+	}
+	else if (strstr(strTime.c_str(), _T("s")) || strstr(strTime.c_str(), _T("S")))
+	{
+		nTimes = atol(strTime.c_str()) * 1000;
+	}
+	else if (strstr(strTime.c_str(), _T("m")) || strstr(strTime.c_str(), _T("M")))
+	{
+		nTimes = atol(strTime.c_str()) * 6000;
+	}
+	else
+	{
+		// 不带单位或其他的,默认ms;
+		nTimes = atol(strTime.c_str());
+	}
+#endif
+#if _MSC_VER >= 1500
 	if ( _tcsstr(strTime.c_str(), _T("ms")) || _tcsstr(strTime.c_str(), _T("MS")))
 	{
 		nTimes = _tstol(strTime.c_str());
@@ -58,6 +78,7 @@ int pares_time_value(std::string strTime)
 		// 不带单位或其他的,默认ms;
 		nTimes = _tstol(strTime.c_str());
 	}
+#endif
 
 	return nTimes;
 }
@@ -132,4 +153,138 @@ EXIT:
 	if(fp)
 		fclose(fp);
 	return ret;
+}
+
+unsigned char TwoHexCharToInteger(char high, char low)
+{
+	if (!isalpha(high) && isdigit(high) || !isalpha(low) && isdigit(low)) {
+		// 应用输出日志;
+		return 0;
+	}
+
+	char Numb1 = high >= 'A' ? (toupper(high) - '0' - 7) * 16 : (high - '0') * 16;
+	char Numb2 = low >= 'A' ? (toupper(low) - '0' - 7) : (low - '0');
+
+	return (Numb1 + Numb2);
+}
+
+const unsigned short CRC16_TABLE[16] = {
+	0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
+	0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF
+};
+
+unsigned short CRC16Calculate(byte *pBuffer, unsigned int wordLength)
+{
+	unsigned short wordCRC;
+	byte byteTemp;
+
+	wordCRC = 0xFFFF;
+	while (wordLength--)
+	{
+		byteTemp = (byte)(wordCRC >> 0x0C);
+		wordCRC <<= 4;
+		wordCRC ^= CRC16_TABLE[byteTemp ^ ((*pBuffer) >> 0x04)];
+		byteTemp = (byte)(wordCRC >> 0x0C);
+		wordCRC <<= 4;
+		wordCRC ^= CRC16_TABLE[byteTemp ^ ((*pBuffer) & 0x0F)];
+		pBuffer++;
+	}
+
+	return wordCRC;
+}
+
+std::string HexStringToBytes(std::string strHex, const int &len /* = 3 */)
+{
+	byte value = 0;
+	std::string strBytes;
+	int nSize = strHex.size();
+	for (int i = 0; i < nSize; i += len)
+	{
+#if _MSC_VER >=1500
+		strBytes.push_back((char)TwoHexCharToInteger(strHex[i], strHex[i + 1]));
+#endif
+#if _MSC_VER >=1200 && _MSC_VER < 1500
+		strBytes.append((char)TwoHexCharToInteger(strHex[i], strHex[i + 1]),1);
+#endif
+	}
+
+	return strBytes;
+}
+
+std::string BytesToHexString(const unsigned char *pbuffer, int nLen, char chSpace)
+{
+	std::string hex;
+	char szhex[5] = {0};
+	for (int i = 0; i < nLen; i++)
+	{
+		memset(szhex, 0, 5);
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
+	sprintf(szhex, "%02X%c", pbuffer[i], chSpace);
+#endif
+#if _MSC_VER >= 1500
+		_stprintf_s(szhex, "%02X%c", pbuffer[i], chSpace);
+#endif
+		hex.append(szhex);
+	}
+
+	return hex.substr(0, hex.size() - 1);
+}
+
+std::string BytesToHexString(const unsigned char *pbuffer, int nLen)
+{
+	std::string hex;
+	char szhex[5] = {0};
+	for (int i = 0; i < nLen; i++)
+	{
+		memset(szhex, 0, 5);
+		
+#if _MSC_VER >= 1200 && _MSC_VER < 1500
+		sprintf(szhex, "%02X", pbuffer[i]);
+#endif
+#if _MSC_VER >= 1500
+		_stprintf_s(szhex, "%02X", pbuffer[i]);
+#endif
+		hex.append(szhex);
+	}
+
+	return hex;
+}
+
+BOOL IsValidString(LPCTSTR lpszString)
+{
+	if (lpszString == NULL)
+		return FALSE;
+
+	do
+	{
+		// ASCII可显示的字符;
+		if (*lpszString < 32 || *lpszString > 126)
+		{
+			return FALSE;
+		}
+	} while (*++lpszString);
+
+	return TRUE;
+}
+
+// 去除空格;
+std::string &trim(std::string &str)
+{
+#if 0
+	int nIndex = 0;
+	while ((nIndex = str.find_first_of(' ')) != std::string::npos)
+		str.erase(nIndex, 1);
+
+	return str;
+#endif
+
+#if _MSC_VER > 1900
+	str.erase(std::remove_if(str.begin(), str.end(), [](unsigned char x) {return std::isspace(x); }), str.end()); //C++17
+#endif
+#if _MSC_VER >= 1200 && _MSC_VER < 1600
+	for (std::string::iterator it = str.begin(); it != str.end();)	{
+		!isspace(*it) ? it++ : it = it = str.erase(it);
+	}
+#endif
+	return str;
 }

+ 2 - 2
Serail-Demo/Demo/stdafx.h

@@ -31,8 +31,7 @@
 #include "Serial.h"
 
 
-typedef struct __CMDPARAM__
-{
+typedef struct __CMDPARAM__ {
 	std::string name;		// 命令描述;
 	std::string head;		// 命令头;
 	std::string code;		// 命令码;
@@ -45,4 +44,5 @@ typedef struct __CMDPARAM__
 int pares_time_value(std::string strTime);
 bool parse_key(std::string &value, std::string strLine, TCHAR *lpszText);
 int parse_cmd_param_from_file(char *file_name, std::vector<CommandParam> &vtCommandParams);
+unsigned char TwoHexCharToInteger(char high, char low);
 // TODO: 在此处引用程序需要的其他头文件