第一次上传
This commit is contained in:
commit
78baf7a471
192
.cproject
Normal file
192
.cproject
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||||
|
<cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.debug.534720554">
|
||||||
|
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.debug.534720554" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
||||||
|
<externalSettings/>
|
||||||
|
<extensions>
|
||||||
|
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
</extensions>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.config.gnu.cross.exe.debug.534720554" name="Debug" parent="cdt.managedbuild.config.gnu.cross.exe.debug" postannouncebuildStep="" postbuildStep="" preannouncebuildStep="" prebuildStep="">
|
||||||
|
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.534720554." name="/" resourcePath="">
|
||||||
|
<toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.cross.exe.debug.414193457" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.debug">
|
||||||
|
<option id="cdt.managedbuild.option.gnu.cross.prefix.1212588849" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" useByScannerDiscovery="false" value="arm-linux-gnueabihf-" valueType="string"/>
|
||||||
|
<option id="cdt.managedbuild.option.gnu.cross.path.455008995" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" useByScannerDiscovery="false" value="/opt/GatewayToolsChain/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin" valueType="string"/>
|
||||||
|
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.914860650" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
|
||||||
|
<builder buildPath="${workspace_loc:/WirelessGateway}/Debug" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="cdt.managedbuild.builder.gnu.cross.1676369687" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
|
||||||
|
<tool command="gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cross.c.compiler.1300223808" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
|
||||||
|
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.946780619" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||||
|
<option id="gnu.c.compiler.option.debugging.level.1333255511" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.154101477" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||||
|
</tool>
|
||||||
|
<tool command="g++" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1302623447" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
|
||||||
|
<option id="gnu.cpp.compiler.option.optimization.level.1647078335" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
|
||||||
|
<option id="gnu.cpp.compiler.option.debugging.level.287276407" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
|
||||||
|
<option id="gnu.cpp.compiler.option.include.paths.801625659" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/boost/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/fftw/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/jsoncpp/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/sqlite/include"/>
|
||||||
|
</option>
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1387553514" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.310128155" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
|
||||||
|
<tool command="g++" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1049583485" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
|
||||||
|
<option id="gnu.cpp.link.option.paths.1174701783" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" useByScannerDiscovery="false" valueType="libPaths">
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/boost/lib"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/ssl/lib"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/fftw/lib"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/jsoncpp"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/mqtt1410/lib_1.1"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/sqlite/lib"/>
|
||||||
|
</option>
|
||||||
|
<option id="gnu.cpp.link.option.libs.1027000140" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
|
||||||
|
<listOptionValue builtIn="false" value="sqlite3"/>
|
||||||
|
<listOptionValue builtIn="false" value="boost_system"/>
|
||||||
|
<listOptionValue builtIn="false" value="pthread"/>
|
||||||
|
<listOptionValue builtIn="false" value="boost_thread"/>
|
||||||
|
<listOptionValue builtIn="false" value="boost_date_time"/>
|
||||||
|
<listOptionValue builtIn="false" value="fftw3"/>
|
||||||
|
<listOptionValue builtIn="false" value="ssl"/>
|
||||||
|
<listOptionValue builtIn="false" value="crypto"/>
|
||||||
|
<listOptionValue builtIn="false" value="json"/>
|
||||||
|
<listOptionValue builtIn="false" value="mosquitto"/>
|
||||||
|
</option>
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1250814802" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||||
|
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||||
|
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||||
|
</inputType>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.255920019" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
|
||||||
|
<tool command="as" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GASErrorParser" id="cdt.managedbuild.tool.gnu.cross.assembler.849564989" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.17608583" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||||
|
</tool>
|
||||||
|
</toolChain>
|
||||||
|
</folderInfo>
|
||||||
|
</configuration>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||||
|
</cconfiguration>
|
||||||
|
<cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.release.770635657">
|
||||||
|
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.release.770635657" moduleId="org.eclipse.cdt.core.settings" name="Release">
|
||||||
|
<externalSettings/>
|
||||||
|
<extensions>
|
||||||
|
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
|
</extensions>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.release.770635657" name="Release" parent="cdt.managedbuild.config.gnu.cross.exe.release" postbuildStep="cp WirelessGateway Cidn-SH;arm-linux-gnueabihf-strip Cidn-SH">
|
||||||
|
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.770635657." name="/" resourcePath="">
|
||||||
|
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.release.1737804687" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.release">
|
||||||
|
<option id="cdt.managedbuild.option.gnu.cross.prefix.1625525504" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" useByScannerDiscovery="false" value="arm-linux-gnueabihf-" valueType="string"/>
|
||||||
|
<option id="cdt.managedbuild.option.gnu.cross.path.198654844" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" useByScannerDiscovery="false" value="/opt/GatewayToolsChain/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin" valueType="string"/>
|
||||||
|
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1898042134" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
|
||||||
|
<builder buildPath="${workspace_loc:/WirelessGateway}/Release" id="cdt.managedbuild.builder.gnu.cross.2122902688" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.171749014" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
|
||||||
|
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.148132182" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||||
|
<option id="gnu.c.compiler.option.debugging.level.374757586" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.842673130" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1614235061" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
|
||||||
|
<option id="gnu.cpp.compiler.option.optimization.level.1503389911" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
|
||||||
|
<option id="gnu.cpp.compiler.option.debugging.level.2146025035" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
|
||||||
|
<option id="gnu.cpp.compiler.option.include.paths.1740362159" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/boost/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/fftw/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/jsoncpp/include"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/sqlite/include"/>
|
||||||
|
</option>
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.542083696" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.1480789657" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.762964696" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
|
||||||
|
<option id="gnu.cpp.link.option.paths.1792108116" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" useByScannerDiscovery="false" valueType="libPaths">
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/boost/lib"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/ssl/lib"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/fftw/lib"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/jsoncpp"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/mqtt1410/lib_1.1"/>
|
||||||
|
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/sqlite/lib"/>
|
||||||
|
</option>
|
||||||
|
<option id="gnu.cpp.link.option.libs.2006599708" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
|
||||||
|
<listOptionValue builtIn="false" value="sqlite3"/>
|
||||||
|
<listOptionValue builtIn="false" value="boost_system"/>
|
||||||
|
<listOptionValue builtIn="false" value="pthread"/>
|
||||||
|
<listOptionValue builtIn="false" value="boost_thread"/>
|
||||||
|
<listOptionValue builtIn="false" value="boost_date_time"/>
|
||||||
|
<listOptionValue builtIn="false" value="fftw3"/>
|
||||||
|
<listOptionValue builtIn="false" value="ssl"/>
|
||||||
|
<listOptionValue builtIn="false" value="crypto"/>
|
||||||
|
<listOptionValue builtIn="false" value="json"/>
|
||||||
|
<listOptionValue builtIn="false" value="mosquitto"/>
|
||||||
|
</option>
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1442843267" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||||
|
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||||
|
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||||
|
</inputType>
|
||||||
|
</tool>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.28417350" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
|
||||||
|
<tool id="cdt.managedbuild.tool.gnu.cross.assembler.1691218119" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
|
||||||
|
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.219849714" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||||
|
</tool>
|
||||||
|
</toolChain>
|
||||||
|
</folderInfo>
|
||||||
|
</configuration>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||||
|
</cconfiguration>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
|
<project id="WirelessGateway.cdt.managedbuild.target.gnu.cross.exe.2063102886" name="Executable" projectType="cdt.managedbuild.target.gnu.cross.exe"/>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="scannerConfiguration">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.534720554;cdt.managedbuild.config.gnu.cross.exe.debug.534720554.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1302623447;cdt.managedbuild.tool.gnu.cpp.compiler.input.1387553514">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
</scannerConfigBuildInfo>
|
||||||
|
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.release.770635657;cdt.managedbuild.config.gnu.cross.exe.release.770635657.;cdt.managedbuild.tool.gnu.cross.c.compiler.171749014;cdt.managedbuild.tool.gnu.c.compiler.input.842673130">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
</scannerConfigBuildInfo>
|
||||||
|
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.534720554;cdt.managedbuild.config.gnu.cross.exe.debug.534720554.;cdt.managedbuild.tool.gnu.cross.c.compiler.1300223808;cdt.managedbuild.tool.gnu.c.compiler.input.154101477">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
</scannerConfigBuildInfo>
|
||||||
|
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.release.770635657;cdt.managedbuild.config.gnu.cross.exe.release.770635657.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1614235061;cdt.managedbuild.tool.gnu.cpp.compiler.input.542083696">
|
||||||
|
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||||
|
</scannerConfigBuildInfo>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||||
|
<storageModule moduleId="refreshScope"/>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
|
||||||
|
<buildTargets>
|
||||||
|
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments/>
|
||||||
|
<buildTarget>all</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
<target name="clear" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
|
||||||
|
<buildCommand>make</buildCommand>
|
||||||
|
<buildArguments/>
|
||||||
|
<buildTarget>clear</buildTarget>
|
||||||
|
<stopOnError>true</stopOnError>
|
||||||
|
<useDefaultCommand>true</useDefaultCommand>
|
||||||
|
<runAllBuilders>true</runAllBuilders>
|
||||||
|
</target>
|
||||||
|
</buildTargets>
|
||||||
|
</storageModule>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
||||||
|
</cproject>
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Debug/
|
||||||
|
Release/
|
||||||
27
.project
Normal file
27
.project
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>WirelessGateway</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||||
|
<triggers>clean,full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||||
|
<triggers>full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||||
|
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
25
.settings/language.settings.xml
Normal file
25
.settings/language.settings.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<project>
|
||||||
|
<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.534720554" name="Debug">
|
||||||
|
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||||
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
|
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1734643904566128475" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
|
</provider>
|
||||||
|
</extension>
|
||||||
|
</configuration>
|
||||||
|
<configuration id="cdt.managedbuild.config.gnu.cross.exe.release.770635657" name="Release">
|
||||||
|
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||||
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
|
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1734643904566128475" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
|
</provider>
|
||||||
|
</extension>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
||||||
74
.settings/org.eclipse.cdt.codan.core.prefs
Normal file
74
.settings/org.eclipse.cdt.codan.core.prefs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.cdt.codan.checkers.errnoreturn=Warning
|
||||||
|
org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return\\")",implicit\=>false}
|
||||||
|
org.eclipse.cdt.codan.checkers.errreturnvalue=Error
|
||||||
|
org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused return value\\")"}
|
||||||
|
org.eclipse.cdt.codan.checkers.nocommentinside=-Error
|
||||||
|
org.eclipse.cdt.codan.checkers.nocommentinside.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Nesting comments\\")"}
|
||||||
|
org.eclipse.cdt.codan.checkers.nolinecomment=-Error
|
||||||
|
org.eclipse.cdt.codan.checkers.nolinecomment.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Line comments\\")"}
|
||||||
|
org.eclipse.cdt.codan.checkers.noreturn=Error
|
||||||
|
org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return value\\")",implicit\=>false}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Abstract class cannot be instantiated\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Ambiguous problem\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment in condition\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment to itself\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No break at end of case\\")",no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false,enable_fallthrough_quickfix_param\=>false}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Catching by reference is recommended\\")",unknown\=>false,exceptions\=>()}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Circular inheritance\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class members should be properly initialized\\")",skip\=>true}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem=Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.DecltypeAutoProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid 'decltype(auto)' specifier\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Field cannot be resolved\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Function cannot be resolved\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.InvalidArguments=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid arguments\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid template argument\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Label statement not found\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Member declaration not found\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Method cannot be resolved\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Name convention for function\\")",pattern\=>"^[a-z]",macro\=>true,exceptions\=>()}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class has a virtual method and non-virtual destructor\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.OverloadProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid overload\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redeclaration\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redefinition\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Return with parenthesis\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Format String Vulnerability\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Statement has no effect\\")",macro\=>true,exceptions\=>()}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suggested parenthesis around expression\\")",paramNot\=>false}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suspicious semicolon\\")",else\=>false,afterelse\=>false}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Type cannot be resolved\\")"}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused function declaration\\")",macro\=>true}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused static function\\")",macro\=>true}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused variable declaration in file scope\\")",macro\=>true,exceptions\=>("@(\#)","$Id")}
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=-Error
|
||||||
|
org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Symbol is not resolved\\")"}
|
||||||
|
useParentScope=false
|
||||||
88
API_log/SH_log.cpp
Normal file
88
API_log/SH_log.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include "SH_log.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct _LogParam {
|
||||||
|
pthread_mutex_t *m_mutex;
|
||||||
|
int m_limit_size;
|
||||||
|
int m_log_buf_size;
|
||||||
|
int m_today;
|
||||||
|
FILE *m_fp;
|
||||||
|
char m_log_full_name[256];
|
||||||
|
char *m_buf;
|
||||||
|
} gLogParam;
|
||||||
|
|
||||||
|
|
||||||
|
int log_init(const char* file_name, int log_buf_size, int limit_size)
|
||||||
|
{
|
||||||
|
memset(gLogParam.m_log_full_name, 0, 256);
|
||||||
|
gLogParam.m_mutex = new pthread_mutex_t;
|
||||||
|
pthread_mutex_init(gLogParam.m_mutex, NULL);
|
||||||
|
|
||||||
|
gLogParam.m_log_buf_size = log_buf_size;
|
||||||
|
gLogParam.m_buf = new char[gLogParam.m_log_buf_size];
|
||||||
|
memset(gLogParam.m_buf, '\0', sizeof(char) * gLogParam.m_log_buf_size);
|
||||||
|
gLogParam.m_limit_size = limit_size;
|
||||||
|
|
||||||
|
strcpy(gLogParam.m_log_full_name, file_name);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_write(const char *level, const char* format, ...)
|
||||||
|
{
|
||||||
|
FILE *fp = fopen(gLogParam.m_log_full_name, "a");
|
||||||
|
if(fp == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(gLogParam.m_buf, 0, sizeof(char)*gLogParam.m_log_buf_size);
|
||||||
|
|
||||||
|
struct timeval now = {0,0};
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
time_t t = now.tv_sec;
|
||||||
|
struct tm* sys_tm = localtime(&t);
|
||||||
|
|
||||||
|
|
||||||
|
pthread_mutex_lock(gLogParam.m_mutex);
|
||||||
|
|
||||||
|
int n = snprintf(gLogParam.m_buf, 64, "%d-%02d-%02d %02d:%02d:%02d %s: ", sys_tm->tm_year+1900, sys_tm->tm_mon+1, sys_tm->tm_mday,
|
||||||
|
sys_tm->tm_hour, sys_tm->tm_min, sys_tm->tm_sec, level);
|
||||||
|
|
||||||
|
|
||||||
|
int old_seek = ftell(fp);
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
int file_size = ftell(fp);
|
||||||
|
fseek(fp, old_seek, SEEK_SET);
|
||||||
|
if (file_size > gLogParam.m_limit_size) {
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
char cmd[256] = { 0 };
|
||||||
|
sprintf(cmd, "cp %s %s_bak", gLogParam.m_log_full_name, gLogParam.m_log_full_name);
|
||||||
|
system(cmd);
|
||||||
|
remove(gLogParam.m_log_full_name);
|
||||||
|
fp = fopen(gLogParam.m_log_full_name, "a");
|
||||||
|
if(fp == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
va_list valst;
|
||||||
|
va_start(valst, format);
|
||||||
|
|
||||||
|
int m = vsnprintf(gLogParam.m_buf + n, gLogParam.m_log_buf_size -n -1, format, valst);
|
||||||
|
gLogParam.m_buf[n + m - 1] = '\n';
|
||||||
|
fwrite(gLogParam.m_buf, n + m, 1, fp);
|
||||||
|
|
||||||
|
va_end(valst);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
pthread_mutex_unlock(gLogParam.m_mutex);
|
||||||
|
}
|
||||||
21
API_log/SH_log.h
Normal file
21
API_log/SH_log.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
#ifndef LOG_H
|
||||||
|
#define LOG_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#define LEVEL_DEBUG (char *)"[debug]"
|
||||||
|
#define LEVEL_INFO (char *)"[info]"
|
||||||
|
#define LEVEL_WARN (char *)"[warn]"
|
||||||
|
#define LEVEL_ERR (char *)"[err]"
|
||||||
|
|
||||||
|
int log_init(const char* file_name, int log_buf_size, int limit_size);
|
||||||
|
void log_write(const char *level, const char *format, ...);
|
||||||
|
|
||||||
|
#define LOG_DEBUG(format, ...) log_write(LEVEL_DEBUG, format, ##__VA_ARGS__)
|
||||||
|
#define LOG_INFO(format, ...) log_write(LEVEL_INFO, format, ##__VA_ARGS__)
|
||||||
|
#define LOG_WARN(format, ...) log_write(LEVEL_WARN, format, ##__VA_ARGS__)
|
||||||
|
#define LOG_ERROR(format, ...) log_write(LEVEL_ERR, format, ##__VA_ARGS__)
|
||||||
|
#endif
|
||||||
71
Makefile
Normal file
71
Makefile
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
TARGET = Cidn-SH
|
||||||
|
OBJ_PATH = $(shell pwd)/debug
|
||||||
|
PREFIX_BIN =
|
||||||
|
|
||||||
|
CC = arm-linux-gnueabihf-g++
|
||||||
|
STRIP = arm-linux-gnueabihf-strip
|
||||||
|
INCLUDES = -I../third_party/boost/include \
|
||||||
|
-I../third_party/fftw/include \
|
||||||
|
-I../third_party/jsoncpp/include \
|
||||||
|
-I../third_party/sqlite/include/
|
||||||
|
|
||||||
|
LIBS = -L../third_party/boost/lib \
|
||||||
|
-L../third_party/fftw/lib \
|
||||||
|
-L../third_party/ssl/lib \
|
||||||
|
-L../third_party/jsoncpp \
|
||||||
|
-L../third_party/mqtt1410/lib \
|
||||||
|
-L../third_party/sqlite/lib \
|
||||||
|
-lsqlite3 -lboost_system -lpthread -lboost_thread -lboost_date_time -lfftw3 -lssl -lcrypto -ljson -lmosquitto
|
||||||
|
|
||||||
|
CFLAGS = -O2 #-Wall -Werror
|
||||||
|
LINKFLAGS =
|
||||||
|
|
||||||
|
AllDirs :=$(shell ls -R | grep '^\./.*:' | awk '{if( \
|
||||||
|
substr($$1,3,5) != "debug") {gsub(":",""); print}}') .
|
||||||
|
|
||||||
|
Sources := $(foreach n,$(AllDirs) , $(wildcard $(n)/*.cpp))
|
||||||
|
|
||||||
|
#C_SOURCES = $(wildcard *.c)
|
||||||
|
C_SRCDIR = $(AllDirs)
|
||||||
|
C_SOURCES = $(foreach d,$(C_SRCDIR),$(wildcard $(d)/*.c) )
|
||||||
|
C_OBJS = $(patsubst %.c, $(OBJ_PATH)/%.o, $(C_SOURCES))
|
||||||
|
|
||||||
|
#CPP_SOURCES = $(wildcard *.cpp)
|
||||||
|
CPP_SRCDIR = $(AllDirs)
|
||||||
|
CPP_SOURCES = $(foreach d,$(CPP_SRCDIR),$(wildcard $(d)/*.cpp) )
|
||||||
|
CPP_OBJS = $(patsubst %.cpp, $(OBJ_PATH)/%.o, $(CPP_SOURCES))
|
||||||
|
|
||||||
|
default:init compile strip
|
||||||
|
|
||||||
|
$(C_OBJS):$(OBJ_PATH)/%.o:%.c
|
||||||
|
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
|
||||||
|
|
||||||
|
$(CPP_OBJS):$(OBJ_PATH)/%.o:%.cpp
|
||||||
|
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
|
||||||
|
|
||||||
|
init:
|
||||||
|
$(foreach d,$(AllDirs), mkdir -p $(OBJ_PATH)/$(d);)
|
||||||
|
|
||||||
|
test:
|
||||||
|
@echo "C_SOURCES: $(C_SOURCES)"
|
||||||
|
@echo "C_OBJS: $(C_OBJS)"
|
||||||
|
@echo "CPP_SOURCES: $(CPP_SOURCES)"
|
||||||
|
@echo "CPP_OBJS: $(CPP_OBJS)"
|
||||||
|
|
||||||
|
compile:$(C_OBJS) $(CPP_OBJS)
|
||||||
|
$(CC) -O2 -o $(TARGET) $^ $(LINKFLAGS) $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJ_PATH)
|
||||||
|
rm -f $(TARGET)
|
||||||
|
|
||||||
|
install: $(TARGET)
|
||||||
|
cp $(TARGET) $(PREFIX_BIN)
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
rm -f $(PREFIX_BIN)/$(TARGET)
|
||||||
|
strip:
|
||||||
|
$(STRIP) $(TARGET)
|
||||||
|
cp $(TARGET) ~/tftpboot
|
||||||
|
|
||||||
|
rebuild: clean compile
|
||||||
76
Makefile_mips
Normal file
76
Makefile_mips
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
TARGET = Cidw-mips
|
||||||
|
OBJ_PATH = $(shell pwd)/debug
|
||||||
|
PREFIX_BIN =
|
||||||
|
|
||||||
|
CC = g++
|
||||||
|
STRIP = strip
|
||||||
|
INCLUDES = -I../cidw_lib \
|
||||||
|
-I../cidw_lib/ibtdms-gpl-0.3/include \
|
||||||
|
-I../cidw_lib/include \
|
||||||
|
-I../third_party/boost/include \
|
||||||
|
-I../third_party/fftw/include \
|
||||||
|
-I../third_party/curl/include \
|
||||||
|
-I../third_party/Jsoncpp/include \
|
||||||
|
-I/usr/include/python2.7
|
||||||
|
|
||||||
|
LIBS = -L../cidw_lib/mips \
|
||||||
|
-L/usr/lib/python2.7 \
|
||||||
|
-L../third_party/boost/lib \
|
||||||
|
-L../third_party/fftw/lib \
|
||||||
|
-L../third_party/curl/lib \
|
||||||
|
-L../third_party/ssl/lib \
|
||||||
|
-L../third_party/Jsoncpp/libs \
|
||||||
|
-L../third_party/mqtt/lib \
|
||||||
|
-lpython2.7 -lsqlite3 -lboost_system -lpthread -lboost_thread -lboost_date_time -lboost_atomic -lfftw3 -lssl -lcrypto -lcurl -ljson -lmosquitto
|
||||||
|
|
||||||
|
CFLAGS = -O2 #-Wall -Werror
|
||||||
|
LINKFLAGS =
|
||||||
|
|
||||||
|
AllDirs :=$(shell ls -R | grep '^\./.*:' | awk '{if( \
|
||||||
|
substr($$1,3,5) != "debug") {gsub(":",""); print}}') .
|
||||||
|
|
||||||
|
Sources := $(foreach n,$(AllDirs) , $(wildcard $(n)/*.cpp))
|
||||||
|
|
||||||
|
#C_SOURCES = $(wildcard *.c)
|
||||||
|
C_SRCDIR = $(AllDirs)
|
||||||
|
C_SOURCES = $(foreach d,$(C_SRCDIR),$(wildcard $(d)/*.c) )
|
||||||
|
C_OBJS = $(patsubst %.c, $(OBJ_PATH)/%.o, $(C_SOURCES))
|
||||||
|
|
||||||
|
#CPP_SOURCES = $(wildcard *.cpp)
|
||||||
|
CPP_SRCDIR = $(AllDirs)
|
||||||
|
CPP_SOURCES = $(foreach d,$(CPP_SRCDIR),$(wildcard $(d)/*.cpp) )
|
||||||
|
CPP_OBJS = $(patsubst %.cpp, $(OBJ_PATH)/%.o, $(CPP_SOURCES))
|
||||||
|
|
||||||
|
default:init compile strip
|
||||||
|
|
||||||
|
$(C_OBJS):$(OBJ_PATH)/%.o:%.c
|
||||||
|
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
|
||||||
|
|
||||||
|
$(CPP_OBJS):$(OBJ_PATH)/%.o:%.cpp
|
||||||
|
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
|
||||||
|
|
||||||
|
init:
|
||||||
|
$(foreach d,$(AllDirs), mkdir -p $(OBJ_PATH)/$(d);)
|
||||||
|
|
||||||
|
test:
|
||||||
|
@echo "C_SOURCES: $(C_SOURCES)"
|
||||||
|
@echo "C_OBJS: $(C_OBJS)"
|
||||||
|
@echo "CPP_SOURCES: $(CPP_SOURCES)"
|
||||||
|
@echo "CPP_OBJS: $(CPP_OBJS)"
|
||||||
|
|
||||||
|
compile:$(C_OBJS) $(CPP_OBJS)
|
||||||
|
$(CC) -O2 -o $(TARGET) $^ $(LINKFLAGS) $(LIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJ_PATH)
|
||||||
|
rm -f $(TARGET)
|
||||||
|
|
||||||
|
install: $(TARGET)
|
||||||
|
cp $(TARGET) $(PREFIX_BIN)
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
rm -f $(PREFIX_BIN)/$(TARGET)
|
||||||
|
strip:
|
||||||
|
$(STRIP) $(TARGET)
|
||||||
|
|
||||||
|
rebuild: clean compile
|
||||||
571
aes/aes.c
Normal file
571
aes/aes.c
Normal file
@ -0,0 +1,571 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
This is an implementation of the AES algorithm, specifically ECB, CTR and CBC mode.
|
||||||
|
Block size can be chosen in aes.h - available choices are AES128, AES192, AES256.
|
||||||
|
|
||||||
|
The implementation is verified against the test vectors in:
|
||||||
|
National Institute of Standards and Technology Special Publication 800-38A 2001 ED
|
||||||
|
|
||||||
|
ECB-AES128
|
||||||
|
----------
|
||||||
|
|
||||||
|
plain-text:
|
||||||
|
6bc1bee22e409f96e93d7e117393172a
|
||||||
|
ae2d8a571e03ac9c9eb76fac45af8e51
|
||||||
|
30c81c46a35ce411e5fbc1191a0a52ef
|
||||||
|
f69f2445df4f9b17ad2b417be66c3710
|
||||||
|
|
||||||
|
key:
|
||||||
|
2b7e151628aed2a6abf7158809cf4f3c
|
||||||
|
|
||||||
|
resulting cipher
|
||||||
|
3ad77bb40d7a3660a89ecaf32466ef97
|
||||||
|
f5d3d58503b9699de785895a96fdbaaf
|
||||||
|
43b1cd7f598ece23881b00e3ed030688
|
||||||
|
7b0c785e27e8ad3f8223207104725dd4
|
||||||
|
|
||||||
|
|
||||||
|
NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0)
|
||||||
|
You should pad the end of the string with zeros if this is not the case.
|
||||||
|
For AES192/256 the key size is proportionally larger.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Includes: */
|
||||||
|
/*****************************************************************************/
|
||||||
|
#include <string.h> // CBC mode, for memset
|
||||||
|
#include "aes.h"
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Defines: */
|
||||||
|
/*****************************************************************************/
|
||||||
|
// The number of columns comprising a state in AES. This is a constant in AES. Value=4
|
||||||
|
#define Nb 4
|
||||||
|
|
||||||
|
#if defined(AES256) && (AES256 == 1)
|
||||||
|
#define Nk 8
|
||||||
|
#define Nr 14
|
||||||
|
#elif defined(AES192) && (AES192 == 1)
|
||||||
|
#define Nk 6
|
||||||
|
#define Nr 12
|
||||||
|
#else
|
||||||
|
#define Nk 4 // The number of 32 bit words in a key.
|
||||||
|
#define Nr 10 // The number of rounds in AES Cipher.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// jcallan@github points out that declaring Multiply as a function
|
||||||
|
// reduces code size considerably with the Keil ARM compiler.
|
||||||
|
// See this link for more information: https://github.com/kokke/tiny-AES-C/pull/3
|
||||||
|
#ifndef MULTIPLY_AS_A_FUNCTION
|
||||||
|
#define MULTIPLY_AS_A_FUNCTION 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Private variables: */
|
||||||
|
/*****************************************************************************/
|
||||||
|
// state - array holding the intermediate results during decryption.
|
||||||
|
typedef uint8_t state_t[4][4];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// The lookup-tables are marked const so they can be placed in read-only storage instead of RAM
|
||||||
|
// The numbers below can be computed dynamically trading ROM for RAM -
|
||||||
|
// This can be useful in (embedded) bootloader applications, where ROM is often limited.
|
||||||
|
static const uint8_t sbox[256] = {
|
||||||
|
//0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||||
|
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
|
||||||
|
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
|
||||||
|
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
||||||
|
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
|
||||||
|
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
|
||||||
|
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
||||||
|
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
|
||||||
|
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
|
||||||
|
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
||||||
|
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
|
||||||
|
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
|
||||||
|
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
||||||
|
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
|
||||||
|
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
|
||||||
|
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
||||||
|
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 };
|
||||||
|
|
||||||
|
static const uint8_t rsbox[256] = {
|
||||||
|
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
|
||||||
|
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
|
||||||
|
0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
||||||
|
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
|
||||||
|
0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
|
||||||
|
0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
||||||
|
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
|
||||||
|
0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
|
||||||
|
0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
||||||
|
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
|
||||||
|
0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
|
||||||
|
0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
||||||
|
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
|
||||||
|
0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
|
||||||
|
0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
||||||
|
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
|
||||||
|
|
||||||
|
// The round constant word array, Rcon[i], contains the values given by
|
||||||
|
// x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
|
||||||
|
static const uint8_t Rcon[11] = {
|
||||||
|
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Jordan Goulder points out in PR #12 (https://github.com/kokke/tiny-AES-C/pull/12),
|
||||||
|
* that you can remove most of the elements in the Rcon array, because they are unused.
|
||||||
|
*
|
||||||
|
* From Wikipedia's article on the Rijndael key schedule @ https://en.wikipedia.org/wiki/Rijndael_key_schedule#Rcon
|
||||||
|
*
|
||||||
|
* "Only the first some of these constants are actually used – up to rcon[10] for AES-128 (as 11 round keys are needed),
|
||||||
|
* up to rcon[8] for AES-192, up to rcon[7] for AES-256. rcon[0] is not used in AES algorithm."
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Private functions: */
|
||||||
|
/*****************************************************************************/
|
||||||
|
/*
|
||||||
|
static uint8_t getSBoxValue(uint8_t num)
|
||||||
|
{
|
||||||
|
return sbox[num];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#define getSBoxValue(num) (sbox[(num)])
|
||||||
|
/*
|
||||||
|
static uint8_t getSBoxInvert(uint8_t num)
|
||||||
|
{
|
||||||
|
return rsbox[num];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#define getSBoxInvert(num) (rsbox[(num)])
|
||||||
|
|
||||||
|
// This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states.
|
||||||
|
static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key)
|
||||||
|
{
|
||||||
|
unsigned i, j, k;
|
||||||
|
uint8_t tempa[4]; // Used for the column/row operations
|
||||||
|
|
||||||
|
// The first round key is the key itself.
|
||||||
|
for (i = 0; i < Nk; ++i)
|
||||||
|
{
|
||||||
|
RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
|
||||||
|
RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
|
||||||
|
RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
|
||||||
|
RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
// All other round keys are found from the previous round keys.
|
||||||
|
for (i = Nk; i < Nb * (Nr + 1); ++i)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
k = (i - 1) * 4;
|
||||||
|
tempa[0]=RoundKey[k + 0];
|
||||||
|
tempa[1]=RoundKey[k + 1];
|
||||||
|
tempa[2]=RoundKey[k + 2];
|
||||||
|
tempa[3]=RoundKey[k + 3];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i % Nk == 0)
|
||||||
|
{
|
||||||
|
// This function shifts the 4 bytes in a word to the left once.
|
||||||
|
// [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
|
||||||
|
|
||||||
|
// Function RotWord()
|
||||||
|
{
|
||||||
|
const uint8_t u8tmp = tempa[0];
|
||||||
|
tempa[0] = tempa[1];
|
||||||
|
tempa[1] = tempa[2];
|
||||||
|
tempa[2] = tempa[3];
|
||||||
|
tempa[3] = u8tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubWord() is a function that takes a four-byte input word and
|
||||||
|
// applies the S-box to each of the four bytes to produce an output word.
|
||||||
|
|
||||||
|
// Function Subword()
|
||||||
|
{
|
||||||
|
tempa[0] = getSBoxValue(tempa[0]);
|
||||||
|
tempa[1] = getSBoxValue(tempa[1]);
|
||||||
|
tempa[2] = getSBoxValue(tempa[2]);
|
||||||
|
tempa[3] = getSBoxValue(tempa[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tempa[0] = tempa[0] ^ Rcon[i/Nk];
|
||||||
|
}
|
||||||
|
#if defined(AES256) && (AES256 == 1)
|
||||||
|
if (i % Nk == 4)
|
||||||
|
{
|
||||||
|
// Function Subword()
|
||||||
|
{
|
||||||
|
tempa[0] = getSBoxValue(tempa[0]);
|
||||||
|
tempa[1] = getSBoxValue(tempa[1]);
|
||||||
|
tempa[2] = getSBoxValue(tempa[2]);
|
||||||
|
tempa[3] = getSBoxValue(tempa[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
j = i * 4; k=(i - Nk) * 4;
|
||||||
|
RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0];
|
||||||
|
RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1];
|
||||||
|
RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2];
|
||||||
|
RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key)
|
||||||
|
{
|
||||||
|
KeyExpansion(ctx->RoundKey, key);
|
||||||
|
}
|
||||||
|
#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
|
||||||
|
void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv)
|
||||||
|
{
|
||||||
|
KeyExpansion(ctx->RoundKey, key);
|
||||||
|
memcpy (ctx->Iv, iv, AES_BLOCKLEN);
|
||||||
|
}
|
||||||
|
void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv)
|
||||||
|
{
|
||||||
|
memcpy (ctx->Iv, iv, AES_BLOCKLEN);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This function adds the round key to state.
|
||||||
|
// The round key is added to the state by an XOR function.
|
||||||
|
static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey)
|
||||||
|
{
|
||||||
|
uint8_t i,j;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 4; ++j)
|
||||||
|
{
|
||||||
|
(*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The SubBytes Function Substitutes the values in the
|
||||||
|
// state matrix with values in an S-box.
|
||||||
|
static void SubBytes(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t i, j;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 4; ++j)
|
||||||
|
{
|
||||||
|
(*state)[j][i] = getSBoxValue((*state)[j][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ShiftRows() function shifts the rows in the state to the left.
|
||||||
|
// Each row is shifted with different offset.
|
||||||
|
// Offset = Row number. So the first row is not shifted.
|
||||||
|
static void ShiftRows(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t temp;
|
||||||
|
|
||||||
|
// Rotate first row 1 columns to left
|
||||||
|
temp = (*state)[0][1];
|
||||||
|
(*state)[0][1] = (*state)[1][1];
|
||||||
|
(*state)[1][1] = (*state)[2][1];
|
||||||
|
(*state)[2][1] = (*state)[3][1];
|
||||||
|
(*state)[3][1] = temp;
|
||||||
|
|
||||||
|
// Rotate second row 2 columns to left
|
||||||
|
temp = (*state)[0][2];
|
||||||
|
(*state)[0][2] = (*state)[2][2];
|
||||||
|
(*state)[2][2] = temp;
|
||||||
|
|
||||||
|
temp = (*state)[1][2];
|
||||||
|
(*state)[1][2] = (*state)[3][2];
|
||||||
|
(*state)[3][2] = temp;
|
||||||
|
|
||||||
|
// Rotate third row 3 columns to left
|
||||||
|
temp = (*state)[0][3];
|
||||||
|
(*state)[0][3] = (*state)[3][3];
|
||||||
|
(*state)[3][3] = (*state)[2][3];
|
||||||
|
(*state)[2][3] = (*state)[1][3];
|
||||||
|
(*state)[1][3] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t xtime(uint8_t x)
|
||||||
|
{
|
||||||
|
return ((x<<1) ^ (((x>>7) & 1) * 0x1b));
|
||||||
|
}
|
||||||
|
|
||||||
|
// MixColumns function mixes the columns of the state matrix
|
||||||
|
static void MixColumns(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint8_t Tmp, Tm, t;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
t = (*state)[i][0];
|
||||||
|
Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ;
|
||||||
|
Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ;
|
||||||
|
Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ;
|
||||||
|
Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ;
|
||||||
|
Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiply is used to multiply numbers in the field GF(2^8)
|
||||||
|
// Note: The last call to xtime() is unneeded, but often ends up generating a smaller binary
|
||||||
|
// The compiler seems to be able to vectorize the operation better this way.
|
||||||
|
// See https://github.com/kokke/tiny-AES-c/pull/34
|
||||||
|
#if MULTIPLY_AS_A_FUNCTION
|
||||||
|
static uint8_t Multiply(uint8_t x, uint8_t y)
|
||||||
|
{
|
||||||
|
return (((y & 1) * x) ^
|
||||||
|
((y>>1 & 1) * xtime(x)) ^
|
||||||
|
((y>>2 & 1) * xtime(xtime(x))) ^
|
||||||
|
((y>>3 & 1) * xtime(xtime(xtime(x)))) ^
|
||||||
|
((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define Multiply(x, y) \
|
||||||
|
( ((y & 1) * x) ^ \
|
||||||
|
((y>>1 & 1) * xtime(x)) ^ \
|
||||||
|
((y>>2 & 1) * xtime(xtime(x))) ^ \
|
||||||
|
((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \
|
||||||
|
((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
|
||||||
|
// MixColumns function mixes the columns of the state matrix.
|
||||||
|
// The method used to multiply may be difficult to understand for the inexperienced.
|
||||||
|
// Please use the references to gain more information.
|
||||||
|
static void InvMixColumns(state_t* state)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint8_t a, b, c, d;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
a = (*state)[i][0];
|
||||||
|
b = (*state)[i][1];
|
||||||
|
c = (*state)[i][2];
|
||||||
|
d = (*state)[i][3];
|
||||||
|
|
||||||
|
(*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09);
|
||||||
|
(*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d);
|
||||||
|
(*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b);
|
||||||
|
(*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// The SubBytes Function Substitutes the values in the
|
||||||
|
// state matrix with values in an S-box.
|
||||||
|
static void InvSubBytes(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t i, j;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 4; ++j)
|
||||||
|
{
|
||||||
|
(*state)[j][i] = getSBoxInvert((*state)[j][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InvShiftRows(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t temp;
|
||||||
|
|
||||||
|
// Rotate first row 1 columns to right
|
||||||
|
temp = (*state)[3][1];
|
||||||
|
(*state)[3][1] = (*state)[2][1];
|
||||||
|
(*state)[2][1] = (*state)[1][1];
|
||||||
|
(*state)[1][1] = (*state)[0][1];
|
||||||
|
(*state)[0][1] = temp;
|
||||||
|
|
||||||
|
// Rotate second row 2 columns to right
|
||||||
|
temp = (*state)[0][2];
|
||||||
|
(*state)[0][2] = (*state)[2][2];
|
||||||
|
(*state)[2][2] = temp;
|
||||||
|
|
||||||
|
temp = (*state)[1][2];
|
||||||
|
(*state)[1][2] = (*state)[3][2];
|
||||||
|
(*state)[3][2] = temp;
|
||||||
|
|
||||||
|
// Rotate third row 3 columns to right
|
||||||
|
temp = (*state)[0][3];
|
||||||
|
(*state)[0][3] = (*state)[1][3];
|
||||||
|
(*state)[1][3] = (*state)[2][3];
|
||||||
|
(*state)[2][3] = (*state)[3][3];
|
||||||
|
(*state)[3][3] = temp;
|
||||||
|
}
|
||||||
|
#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
|
||||||
|
|
||||||
|
// Cipher is the main function that encrypts the PlainText.
|
||||||
|
static void Cipher(state_t* state, const uint8_t* RoundKey)
|
||||||
|
{
|
||||||
|
uint8_t round = 0;
|
||||||
|
|
||||||
|
// Add the First round key to the state before starting the rounds.
|
||||||
|
AddRoundKey(0, state, RoundKey);
|
||||||
|
|
||||||
|
// There will be Nr rounds.
|
||||||
|
// The first Nr-1 rounds are identical.
|
||||||
|
// These Nr-1 rounds are executed in the loop below.
|
||||||
|
for (round = 1; round < Nr; ++round)
|
||||||
|
{
|
||||||
|
SubBytes(state);
|
||||||
|
ShiftRows(state);
|
||||||
|
MixColumns(state);
|
||||||
|
AddRoundKey(round, state, RoundKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The last round is given below.
|
||||||
|
// The MixColumns function is not here in the last round.
|
||||||
|
SubBytes(state);
|
||||||
|
ShiftRows(state);
|
||||||
|
AddRoundKey(Nr, state, RoundKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
|
||||||
|
static void InvCipher(state_t* state, const uint8_t* RoundKey)
|
||||||
|
{
|
||||||
|
uint8_t round = 0;
|
||||||
|
|
||||||
|
// Add the First round key to the state before starting the rounds.
|
||||||
|
AddRoundKey(Nr, state, RoundKey);
|
||||||
|
|
||||||
|
// There will be Nr rounds.
|
||||||
|
// The first Nr-1 rounds are identical.
|
||||||
|
// These Nr-1 rounds are executed in the loop below.
|
||||||
|
for (round = (Nr - 1); round > 0; --round)
|
||||||
|
{
|
||||||
|
InvShiftRows(state);
|
||||||
|
InvSubBytes(state);
|
||||||
|
AddRoundKey(round, state, RoundKey);
|
||||||
|
InvMixColumns(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The last round is given below.
|
||||||
|
// The MixColumns function is not here in the last round.
|
||||||
|
InvShiftRows(state);
|
||||||
|
InvSubBytes(state);
|
||||||
|
AddRoundKey(0, state, RoundKey);
|
||||||
|
}
|
||||||
|
#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Public functions: */
|
||||||
|
/*****************************************************************************/
|
||||||
|
#if defined(ECB) && (ECB == 1)
|
||||||
|
|
||||||
|
|
||||||
|
void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf)
|
||||||
|
{
|
||||||
|
// The next function call encrypts the PlainText with the Key using AES algorithm.
|
||||||
|
Cipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf)
|
||||||
|
{
|
||||||
|
// The next function call decrypts the PlainText with the Key using AES algorithm.
|
||||||
|
InvCipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // #if defined(ECB) && (ECB == 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(CBC) && (CBC == 1)
|
||||||
|
|
||||||
|
|
||||||
|
static void XorWithIv(uint8_t* buf, const uint8_t* Iv)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size
|
||||||
|
{
|
||||||
|
buf[i] ^= Iv[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, uint32_t length)
|
||||||
|
{
|
||||||
|
uintptr_t i;
|
||||||
|
uint8_t *Iv = ctx->Iv;
|
||||||
|
for (i = 0; i < length; i += AES_BLOCKLEN)
|
||||||
|
{
|
||||||
|
XorWithIv(buf, Iv);
|
||||||
|
Cipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
Iv = buf;
|
||||||
|
buf += AES_BLOCKLEN;
|
||||||
|
//printf("Step %d - %d", i/16, i);
|
||||||
|
}
|
||||||
|
/* store Iv in ctx for next call */
|
||||||
|
memcpy(ctx->Iv, Iv, AES_BLOCKLEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
|
||||||
|
{
|
||||||
|
uintptr_t i;
|
||||||
|
uint8_t storeNextIv[AES_BLOCKLEN];
|
||||||
|
for (i = 0; i < length; i += AES_BLOCKLEN)
|
||||||
|
{
|
||||||
|
memcpy(storeNextIv, buf, AES_BLOCKLEN);
|
||||||
|
InvCipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
XorWithIv(buf, ctx->Iv);
|
||||||
|
memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN);
|
||||||
|
buf += AES_BLOCKLEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #if defined(CBC) && (CBC == 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(CTR) && (CTR == 1)
|
||||||
|
|
||||||
|
/* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */
|
||||||
|
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length)
|
||||||
|
{
|
||||||
|
uint8_t buffer[AES_BLOCKLEN];
|
||||||
|
|
||||||
|
unsigned i;
|
||||||
|
int bi;
|
||||||
|
for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
|
||||||
|
{
|
||||||
|
if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */
|
||||||
|
{
|
||||||
|
|
||||||
|
memcpy(buffer, ctx->Iv, AES_BLOCKLEN);
|
||||||
|
Cipher((state_t*)buffer,ctx->RoundKey);
|
||||||
|
|
||||||
|
/* Increment Iv and handle overflow */
|
||||||
|
for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi)
|
||||||
|
{
|
||||||
|
/* inc will overflow */
|
||||||
|
if (ctx->Iv[bi] == 255)
|
||||||
|
{
|
||||||
|
ctx->Iv[bi] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ctx->Iv[bi] += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bi = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[i] = (buf[i] ^ buffer[bi]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #if defined(CTR) && (CTR == 1)
|
||||||
|
|
||||||
90
aes/aes.h
Normal file
90
aes/aes.h
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#ifndef _AES_H_
|
||||||
|
#define _AES_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// #define the macros below to 1/0 to enable/disable the mode of operation.
|
||||||
|
//
|
||||||
|
// CBC enables AES encryption in CBC-mode of operation.
|
||||||
|
// CTR enables encryption in counter-mode.
|
||||||
|
// ECB enables the basic ECB 16-byte block algorithm. All can be enabled simultaneously.
|
||||||
|
|
||||||
|
// The #ifndef-guard allows it to be configured before #include'ing or at compile time.
|
||||||
|
#ifndef CBC
|
||||||
|
#define CBC 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ECB
|
||||||
|
#define ECB 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CTR
|
||||||
|
#define CTR 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define AES128 1
|
||||||
|
//#define AES192 1
|
||||||
|
//#define AES256 1
|
||||||
|
|
||||||
|
#define AES_BLOCKLEN 16 //Block length in bytes AES is 128b block only
|
||||||
|
|
||||||
|
#if defined(AES256) && (AES256 == 1)
|
||||||
|
#define AES_KEYLEN 32
|
||||||
|
#define AES_keyExpSize 240
|
||||||
|
#elif defined(AES192) && (AES192 == 1)
|
||||||
|
#define AES_KEYLEN 24
|
||||||
|
#define AES_keyExpSize 208
|
||||||
|
#else
|
||||||
|
#define AES_KEYLEN 16 // Key length in bytes
|
||||||
|
#define AES_keyExpSize 176
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct AES_ctx
|
||||||
|
{
|
||||||
|
uint8_t RoundKey[AES_keyExpSize];
|
||||||
|
#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
|
||||||
|
uint8_t Iv[AES_BLOCKLEN];
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key);
|
||||||
|
#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1))
|
||||||
|
void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);
|
||||||
|
void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ECB) && (ECB == 1)
|
||||||
|
// buffer size is exactly AES_BLOCKLEN bytes;
|
||||||
|
// you need only AES_init_ctx as IV is not used in ECB
|
||||||
|
// NB: ECB is considered insecure for most uses
|
||||||
|
void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf);
|
||||||
|
void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
|
||||||
|
|
||||||
|
#endif // #if defined(ECB) && (ECB == !)
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(CBC) && (CBC == 1)
|
||||||
|
// buffer size MUST be mutile of AES_BLOCKLEN;
|
||||||
|
// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
|
||||||
|
// NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv()
|
||||||
|
// no IV should ever be reused with the same key
|
||||||
|
void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
|
||||||
|
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
|
||||||
|
|
||||||
|
#endif // #if defined(CBC) && (CBC == 1)
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(CTR) && (CTR == 1)
|
||||||
|
|
||||||
|
// Same function for encrypting as for decrypting.
|
||||||
|
// IV is incremented for every block, and used after encryption as XOR-compliment for output
|
||||||
|
// Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme
|
||||||
|
// NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv()
|
||||||
|
// no IV should ever be reused with the same key
|
||||||
|
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length);
|
||||||
|
|
||||||
|
#endif // #if defined(CTR) && (CTR == 1)
|
||||||
|
|
||||||
|
|
||||||
|
#endif //_AES_H_
|
||||||
12
aes/aes.hpp
Normal file
12
aes/aes.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef _AES_HPP_
|
||||||
|
#define _AES_HPP_
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#error Do not include the hpp header in a c project!
|
||||||
|
#endif //__cplusplus
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "aes.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //_AES_HPP_
|
||||||
317
calculation/Calculation.cpp
Normal file
317
calculation/Calculation.cpp
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
#include "Calculation.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Calculation::Calculation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Calculation::~Calculation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* 一维数据的复数快速傅里叶变换 */
|
||||||
|
/************************************************************************/
|
||||||
|
void Calculation::FFT(int n, fftw_complex* in, fftw_complex* out)
|
||||||
|
{
|
||||||
|
if (in == NULL || out == NULL) return;
|
||||||
|
fftw_plan p;
|
||||||
|
p = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||||
|
fftw_execute(p);
|
||||||
|
fftw_destroy_plan(p);
|
||||||
|
fftw_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* 一维数据的实数快速傅里叶变换 */
|
||||||
|
/************************************************************************/
|
||||||
|
void Calculation::FFT_R(int n, std::vector<float> & vecData, fftw_complex* out)
|
||||||
|
{
|
||||||
|
double in[n];
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
in[i] = vecData[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
out[i][0] = (double)vecData[i];
|
||||||
|
out[i][1] = 0;
|
||||||
|
}
|
||||||
|
//create a DFT plan and execute it
|
||||||
|
fftw_plan plan = fftw_plan_dft_r2c_1d(n, in, out, FFTW_ESTIMATE);
|
||||||
|
fftw_execute(plan);
|
||||||
|
//destroy the plan to prevent a memory leak
|
||||||
|
fftw_destroy_plan(plan);
|
||||||
|
fftw_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* 一维数据的快速傅里叶逆变换 */
|
||||||
|
/************************************************************************/
|
||||||
|
void Calculation::iFFT(int n, fftw_complex* in, fftw_complex* out)
|
||||||
|
{
|
||||||
|
if (in == NULL || out == NULL) return;
|
||||||
|
fftw_plan p;
|
||||||
|
p = fftw_plan_dft_1d(n, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||||
|
fftw_execute(p);
|
||||||
|
fftw_destroy_plan(p);
|
||||||
|
fftw_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
//************************************
|
||||||
|
// Method: caculateAmp_Pha
|
||||||
|
// FullName: Calculation::caculateAmp_Pha
|
||||||
|
// Access: public static
|
||||||
|
// Returns: void
|
||||||
|
// Qualifier:
|
||||||
|
// Parameter: int n
|
||||||
|
// Parameter: fftw_complex * in
|
||||||
|
// Parameter: int frequency
|
||||||
|
// Parameter: double & amplitude
|
||||||
|
// Parameter: double & phase
|
||||||
|
// 函数功能是计算特定频率的幅值和相位,原来的讨论中是传入一个特定的频率,然后在给定的频率左右范围内找幅值和相位
|
||||||
|
// 目前的函数实现是计算FFT变换后特定点的幅值和相位
|
||||||
|
// 然后还有一个地方需要修改,即给定频率和FFT变换结果序列
|
||||||
|
//************************************
|
||||||
|
void Calculation::caculateAmp_Pha(int n, fftw_complex* in, int frequency, double &litude, double &phase)
|
||||||
|
{
|
||||||
|
int index = frequency;
|
||||||
|
amplitude = 2 * sqrt((in[index][0] / n) * (in[index][0] / n) + (in[index][1] / n) * (in[index][1] / n));
|
||||||
|
phase = 180 * atan(in[index][1] / in[index][0]) / M_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Calculation::max(std::vector<float> & vecData)
|
||||||
|
{
|
||||||
|
std::vector<float>::iterator it;
|
||||||
|
it = std::max_element(vecData.begin(), vecData.end());
|
||||||
|
if (it != vecData.end()) {
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Calculation::min(std::vector<float> & vecData)
|
||||||
|
{
|
||||||
|
std::vector<float>::iterator it;
|
||||||
|
it = std::min_element(vecData.begin(), vecData.end());
|
||||||
|
if (it != vecData.end()) {
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Calculation::absVec(std::vector<float> & vecAbsData, std::vector<float> & vecData)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < vecData.size(); i++) {
|
||||||
|
vecAbsData.push_back(fabs(vecData[i]));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Calculation::mean(std::vector<float> & vecData)
|
||||||
|
{
|
||||||
|
double meanTemp = 0;
|
||||||
|
for (int i = 0; i < vecData.size(); i++) {
|
||||||
|
meanTemp = meanTemp += vecData[i];
|
||||||
|
}
|
||||||
|
return meanTemp / vecData.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Calculation::drop_mean(std::vector<float> & vecDropMeanData, std::vector<float> & vecData)
|
||||||
|
{
|
||||||
|
float fMean = mean(vecData);
|
||||||
|
for (int i = 0; i < vecData.size(); i++) {
|
||||||
|
vecDropMeanData.push_back(vecData[i] - fMean);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Calculation::srm(std::vector<float> & vecData)
|
||||||
|
{
|
||||||
|
double dSrmTemp = 0;
|
||||||
|
for (int i = 0; i < vecData.size(); i++){
|
||||||
|
dSrmTemp = dSrmTemp + sqrt(vecData[i]);
|
||||||
|
}
|
||||||
|
dSrmTemp = dSrmTemp / vecData.size();
|
||||||
|
return dSrmTemp * dSrmTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Calculation::rms(std::vector<float> & vecData)
|
||||||
|
{
|
||||||
|
double rmsTemp = 0;
|
||||||
|
for (int i = 0; i < vecData.size(); i++) {
|
||||||
|
rmsTemp = rmsTemp += (vecData[i] * vecData[i]);
|
||||||
|
}
|
||||||
|
rmsTemp = rmsTemp / vecData.size();
|
||||||
|
return sqrt(rmsTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Calculation::variance(std::vector<float> & vecDropMeanData)
|
||||||
|
{
|
||||||
|
double varianceTemp = 0;
|
||||||
|
for (int i = 0; i < vecDropMeanData.size(); i++) {
|
||||||
|
varianceTemp = varianceTemp += (vecDropMeanData[i] * vecDropMeanData[i]);
|
||||||
|
}
|
||||||
|
return varianceTemp/vecDropMeanData.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Calculation::skew_state(std::vector<float> & vecDropMeanData, float fVariance)
|
||||||
|
{
|
||||||
|
double tempSkew = 0;
|
||||||
|
for (int i = 0; i < vecDropMeanData.size(); i++) {
|
||||||
|
tempSkew = tempSkew + pow(vecDropMeanData[i], 3);
|
||||||
|
}
|
||||||
|
tempSkew = tempSkew / vecDropMeanData.size();
|
||||||
|
tempSkew = tempSkew / pow(fVariance, 1.5);
|
||||||
|
return tempSkew;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Calculation::kurtosis(std::vector<float> & vecDropMeanData, float fVariance)
|
||||||
|
{
|
||||||
|
double tempkurtosis = 0;
|
||||||
|
for (int i = 0; i < vecDropMeanData.size(); i++) {
|
||||||
|
tempkurtosis = tempkurtosis + pow(vecDropMeanData[i], 4);
|
||||||
|
}
|
||||||
|
tempkurtosis = tempkurtosis / vecDropMeanData.size();
|
||||||
|
tempkurtosis = tempkurtosis / pow(fVariance, 2);
|
||||||
|
return tempkurtosis;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Calculation::hilbert(std::vector<float> & vecData, std::vector<float> & vecHilbertData, int N)
|
||||||
|
{
|
||||||
|
|
||||||
|
double in[N];
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
in[i] = vecData[i];
|
||||||
|
}
|
||||||
|
fftw_complex *out;
|
||||||
|
out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);
|
||||||
|
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
out[i][0] = (double)vecData[i];
|
||||||
|
out[i][1] = 0;
|
||||||
|
}
|
||||||
|
//create a DFT plan and execute it
|
||||||
|
fftw_plan plan = fftw_plan_dft_r2c_1d(N, in, out, FFTW_ESTIMATE);
|
||||||
|
fftw_execute(plan);
|
||||||
|
//destroy the plan to prevent a memory leak
|
||||||
|
fftw_destroy_plan(plan);
|
||||||
|
int hN = N >> 1; // half of the length (N /2)
|
||||||
|
int numRem = hN; // the number of remaining elements
|
||||||
|
// multiply the appropriate values by 2
|
||||||
|
// (those that should be multiplied by 1 are left intact because they wouldn't change)
|
||||||
|
for (int i = 1; i < hN; ++i) // 1,2,...,N/2 - 1 的项乘以2
|
||||||
|
{
|
||||||
|
out[i][0] *= 2;
|
||||||
|
out[i][1] *= 2;
|
||||||
|
}
|
||||||
|
// if the length is even, the number of remaining elements decreases by 1
|
||||||
|
if (N % 2 == 0)
|
||||||
|
numRem--;
|
||||||
|
// if it's odd and greater than 1, the middle value must be multiplied by 2
|
||||||
|
else if (N > 1) // 奇数非空
|
||||||
|
{
|
||||||
|
out[hN][0] *= 2;
|
||||||
|
out[hN][1] *= 2;
|
||||||
|
}
|
||||||
|
// set the remaining values to 0
|
||||||
|
// (multiplying by 0 gives 0, so we don't care about the multiplicands)
|
||||||
|
memset(&out[hN + 1][0], 0, numRem * sizeof(fftw_complex));
|
||||||
|
// create an IDFT plan and execute it
|
||||||
|
plan = fftw_plan_dft_1d(N, out, out, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||||
|
fftw_execute(plan);
|
||||||
|
// do some cleaning
|
||||||
|
fftw_destroy_plan(plan);
|
||||||
|
fftw_cleanup();
|
||||||
|
// scale the IDFT output
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
out[i][0] /= N;
|
||||||
|
out[i][1] /= N;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int n=0; n<N; n++ )//输出
|
||||||
|
{
|
||||||
|
// xr[n]=cos(n*pi/6);//原始信号
|
||||||
|
// y_r[n] = s_i[n];
|
||||||
|
complex complex_after;
|
||||||
|
complex_after.real = out[n][1];
|
||||||
|
complex_after.imag = out[n][0];
|
||||||
|
float amp = sqrt(complex_after.real * complex_after.real +complex_after.imag * complex_after.imag);
|
||||||
|
vecHilbertData.push_back(amp);
|
||||||
|
// printf("%d %f\n",n,vecHilbertData[n]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Calculation::fftShift(fftw_complex* in, int l)
|
||||||
|
{
|
||||||
|
double temp;
|
||||||
|
double temp2;
|
||||||
|
|
||||||
|
for (int j = 0;j<l/2;j++) {
|
||||||
|
temp = in[j+l/2][0];
|
||||||
|
temp2 = in[j+l/2][1];
|
||||||
|
in[j+l/2][0] = in[j][0];
|
||||||
|
in[j+l/2][1] = in[j][1];
|
||||||
|
in[j][0] = temp;
|
||||||
|
in[j][1] = temp2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Calculation::FFTSpec(std::vector<float> & vecData, std::vector<float> & vecFFTSpecData)
|
||||||
|
{
|
||||||
|
fftw_complex *inFFt, *outFFt;
|
||||||
|
inFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecData.size());
|
||||||
|
outFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecData.size());
|
||||||
|
printf("1---------------------------------------------->%d\n",vecData.size());
|
||||||
|
|
||||||
|
for (int j = 0; j < vecData.size(); j++) {
|
||||||
|
inFFt[j][0] = (double)vecData[j];
|
||||||
|
inFFt[j][1] = 0;
|
||||||
|
}
|
||||||
|
FFT(vecData.size(),inFFt, outFFt);
|
||||||
|
for(int j = 0; j < vecData.size()/2; j++) {
|
||||||
|
vecFFTSpecData.push_back(sqrt(outFFt[j][0]*outFFt[j][0] + outFFt[j][1]*outFFt[j][1])*2/vecData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Calculation::envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData)
|
||||||
|
{
|
||||||
|
std::vector<float> vecDropMeanData;
|
||||||
|
drop_mean(vecDropMeanData, vecData);
|
||||||
|
|
||||||
|
std::vector<float> vecHilbertData;
|
||||||
|
hilbert(vecDropMeanData, vecHilbertData, vecDropMeanData.size());
|
||||||
|
|
||||||
|
fftw_complex *inHilFFt, *outHilFFt;
|
||||||
|
inHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecHilbertData.size());
|
||||||
|
outHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecHilbertData.size());
|
||||||
|
|
||||||
|
for (int j = 0; j < vecHilbertData.size(); j++) {
|
||||||
|
inHilFFt[j][0] = (double)vecHilbertData[j];
|
||||||
|
inHilFFt[j][1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FFT(vecHilbertData.size(), inHilFFt, outHilFFt);
|
||||||
|
fftShift(outHilFFt, vecHilbertData.size());
|
||||||
|
|
||||||
|
vecEnvSpecData.push_back(0);
|
||||||
|
for (int i = vecHilbertData.size() / 2 + 1; i < vecHilbertData.size(); i++) {
|
||||||
|
float ftemp = 2 * sqrt(outHilFFt[i][0] * outHilFFt[i][0] + outHilFFt[i][1] * outHilFFt[i][1]) / vecHilbertData.size();
|
||||||
|
vecEnvSpecData.push_back(ftemp);
|
||||||
|
}
|
||||||
|
}
|
||||||
155
calculation/Calculation.hpp
Normal file
155
calculation/Calculation.hpp
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
#ifndef CALCULATION_H_
|
||||||
|
|
||||||
|
#define CALCULATION_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <fftw3.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define pi 3.1415
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
float real,imag;
|
||||||
|
|
||||||
|
}complex;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Calculation : public MySingleton<Calculation>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Calculation();
|
||||||
|
|
||||||
|
~Calculation();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//最大值
|
||||||
|
|
||||||
|
float max(std::vector<float> & vecData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//最小值
|
||||||
|
|
||||||
|
float min(std::vector<float> & vecData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//将数据取绝对值
|
||||||
|
|
||||||
|
void absVec(std::vector<float> & vecAbsData, std::vector<float> & vecData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//将数据取平均值
|
||||||
|
|
||||||
|
float mean(std::vector<float> & vecData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//将数据平方处理 数据有效值
|
||||||
|
|
||||||
|
float rms(std::vector<float> & vecData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//去数据的直流分量
|
||||||
|
|
||||||
|
void drop_mean(std::vector<float> & vecDropMeanData, std::vector<float> & vecData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//方根幅值
|
||||||
|
|
||||||
|
float srm(std::vector<float> & vecData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//方差
|
||||||
|
|
||||||
|
float variance(std::vector<float> & vecDropMeanData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//偏态指标
|
||||||
|
|
||||||
|
float skew_state(std::vector<float> & vecDropMeanData, float fVariance);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//峭度指标
|
||||||
|
|
||||||
|
float kurtosis(std::vector<float> & vecDropMeanData, float fVariance);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//快速傅里叶变换函数
|
||||||
|
|
||||||
|
void FFT(int n, fftw_complex* in, fftw_complex* out);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//快速傅里叶实数变换函数
|
||||||
|
|
||||||
|
void FFT_R(int n, std::vector<float> & vecData, fftw_complex* out);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//快速傅里叶逆变换
|
||||||
|
|
||||||
|
void iFFT(int n, fftw_complex* in, fftw_complex* out);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//通道幅值和相位提取
|
||||||
|
|
||||||
|
//输入为FFT变换后的数据长度及数据,指定的频率,输出为计算后得到的幅值 和 相位
|
||||||
|
|
||||||
|
void caculateAmp_Pha(int n, fftw_complex* in, int frequency, double &litude, double &phase);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//希尔伯特变换
|
||||||
|
|
||||||
|
void hilbert(std::vector<float> & vecData, std::vector<float> & vecHilbertData, int N);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//FFT shift
|
||||||
|
|
||||||
|
void fftShift(fftw_complex* in, int l);
|
||||||
|
//频谱图数据
|
||||||
|
void FFTSpec(std::vector<float> & vecData, std::vector<float> & vecFFTSpecData);
|
||||||
|
//包络图谱数据
|
||||||
|
void envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
633
common/SH_CommonFunc.cpp
Normal file
633
common/SH_CommonFunc.cpp
Normal file
@ -0,0 +1,633 @@
|
|||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include "SH_global.h"
|
||||||
|
#include "SH_CommonFunc.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static boost::mutex s_config_mu;
|
||||||
|
|
||||||
|
int CheckFileVersion(int argc, char** argv)
|
||||||
|
{
|
||||||
|
std::string strVersion = GlobalConfig::Version;
|
||||||
|
int optionchar; /*选项字<E9A1B9>??*/
|
||||||
|
if (argc >= 2) {
|
||||||
|
if (strcmp(argv[1], "--debugmode") == 0){
|
||||||
|
GlobalConfig::RUN_MODE = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
optionchar = getopt(argc, argv, "vVhH?");
|
||||||
|
switch (optionchar) {
|
||||||
|
case 'v':
|
||||||
|
case 'V':
|
||||||
|
GlobalConfig::RUN_MODE = 1;
|
||||||
|
print_debug("Compile time:%s %s\n", __DATE__, __TIME__);
|
||||||
|
print_debug("The internal version is:%s.\n", strVersion.c_str());
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
case 'H':
|
||||||
|
case '?':
|
||||||
|
printf("Please input -v or -V to get the file version.\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string GetCurrentTime()
|
||||||
|
{
|
||||||
|
struct tm nowtime;
|
||||||
|
struct timeval tv;
|
||||||
|
char time_now[128];
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
localtime_r(&tv.tv_sec,&nowtime);
|
||||||
|
|
||||||
|
sprintf(time_now,"%d-%d-%d %d:%d:%d.%03d ",
|
||||||
|
nowtime.tm_year+1900,
|
||||||
|
nowtime.tm_mon+1,
|
||||||
|
nowtime.tm_mday,
|
||||||
|
nowtime.tm_hour,
|
||||||
|
nowtime.tm_min,
|
||||||
|
nowtime.tm_sec,
|
||||||
|
(int)(tv.tv_usec/1000)
|
||||||
|
);
|
||||||
|
|
||||||
|
std::string strtime_now = std::string((char*)time_now);
|
||||||
|
return strtime_now;
|
||||||
|
}
|
||||||
|
|
||||||
|
int system_custom(const char *cmd, char *buf)
|
||||||
|
{
|
||||||
|
FILE * fp;
|
||||||
|
int res;
|
||||||
|
char temp[1024] = {0};
|
||||||
|
if (cmd == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fp = popen(cmd, "r") ) == NULL) {
|
||||||
|
print_error("popen error\n");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
buf[0] = '\0';
|
||||||
|
while (fgets(temp, sizeof(temp), fp)) {
|
||||||
|
strcat(buf, temp);
|
||||||
|
}
|
||||||
|
res = pclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *p;
|
||||||
|
int pos = 0;
|
||||||
|
p = strstr(buf, "\n");
|
||||||
|
if(p != NULL){
|
||||||
|
pos = p - buf;
|
||||||
|
buf[pos] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string GetDayDate()
|
||||||
|
{
|
||||||
|
time_t t = time(0);
|
||||||
|
char tmp[64];
|
||||||
|
strftime(tmp, sizeof(tmp), "%Y-%m-%d",localtime(&t));
|
||||||
|
std::string data = std::string((char*)tmp);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GetTimeNet(char* timebuf,int type)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
int millisecond = tv.tv_usec / 1000;
|
||||||
|
if(type == 0){
|
||||||
|
sprintf(timebuf, "%ld%03d", tv.tv_sec, millisecond);
|
||||||
|
} else {
|
||||||
|
sprintf(timebuf, "%ld", tv.tv_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetTime_(char time_buff[],TIME_SIZE len)
|
||||||
|
{
|
||||||
|
int i = sizeof(time_buff);
|
||||||
|
memset(time_buff, 0, i);
|
||||||
|
time_t timep;
|
||||||
|
time(&timep);
|
||||||
|
strcpy(time_buff, ctime(&timep));
|
||||||
|
std::string strtemp = time_buff;
|
||||||
|
strtemp = strtemp.substr(11, len);
|
||||||
|
memset(time_buff, 0, strlen(time_buff));
|
||||||
|
strcpy(time_buff, strtemp.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ReadStrByOpt(std::string filename, std::string config, std::string option)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(s_config_mu);
|
||||||
|
Json::Value root;
|
||||||
|
Json::Reader reader;
|
||||||
|
std::string value;
|
||||||
|
std::fstream is;
|
||||||
|
is.open(filename.c_str(), std::ios::in);
|
||||||
|
if (reader.parse(is, root)) {
|
||||||
|
value = root[config]["option"][option].asString();
|
||||||
|
}
|
||||||
|
is.close();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WriteStr2Config(std::string filename, std::string config, std::string option, std::string value, bool listable)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(s_config_mu);
|
||||||
|
Json::Value root;
|
||||||
|
Json::Value subroot;
|
||||||
|
Json::Value list;
|
||||||
|
Json::Value op;
|
||||||
|
Json::Reader reader;
|
||||||
|
std::fstream is;
|
||||||
|
is.open(filename.c_str(), std::ios::in);
|
||||||
|
if (reader.parse(is, root)) {
|
||||||
|
subroot = root[config];
|
||||||
|
if (listable)
|
||||||
|
list = root[config]["list"];
|
||||||
|
else
|
||||||
|
op = root[config]["option"];
|
||||||
|
}
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
if (listable) {
|
||||||
|
list[option].append(Json::Value(value));
|
||||||
|
subroot["list"] = list;
|
||||||
|
} else {
|
||||||
|
op[option] = Json::Value(value);
|
||||||
|
subroot["option"] = op;
|
||||||
|
}
|
||||||
|
root[config] = subroot;
|
||||||
|
Json::StyledWriter sw;
|
||||||
|
std::ofstream os;
|
||||||
|
os.open(filename.c_str());
|
||||||
|
os << sw.write(root);
|
||||||
|
os.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string GetLocalMac()
|
||||||
|
{
|
||||||
|
int sock_mac;
|
||||||
|
struct ifreq ifr_mac;
|
||||||
|
char mac_addr[30];
|
||||||
|
sock_mac = socket( AF_INET, SOCK_STREAM, 0 );
|
||||||
|
if( sock_mac == -1) {
|
||||||
|
perror("create socket falise...mac/n");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
memset(&ifr_mac,0,sizeof(ifr_mac));
|
||||||
|
strncpy(ifr_mac.ifr_name, "eth0", sizeof(ifr_mac.ifr_name)-1);
|
||||||
|
if( (ioctl( sock_mac, SIOCGIFHWADDR, &ifr_mac)) < 0) {
|
||||||
|
printf("mac ioctl error/n");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
sprintf(mac_addr,"%02x%02x%02x%02x%02x%02x",
|
||||||
|
(unsigned char)ifr_mac.ifr_hwaddr.sa_data[0],
|
||||||
|
(unsigned char)ifr_mac.ifr_hwaddr.sa_data[1],
|
||||||
|
(unsigned char)ifr_mac.ifr_hwaddr.sa_data[2],
|
||||||
|
(unsigned char)ifr_mac.ifr_hwaddr.sa_data[3],
|
||||||
|
(unsigned char)ifr_mac.ifr_hwaddr.sa_data[4],
|
||||||
|
(unsigned char)ifr_mac.ifr_hwaddr.sa_data[5]);
|
||||||
|
printf("local mac:%s /n",mac_addr);
|
||||||
|
close( sock_mac );
|
||||||
|
return std::string( mac_addr );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetGwIp_(const char *eth_name)
|
||||||
|
{
|
||||||
|
int sockfd;
|
||||||
|
char gwip_[16] = {0};
|
||||||
|
if (-1 == (sockfd = socket(PF_INET, SOCK_STREAM, 0))) {
|
||||||
|
perror_info("socket");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
struct ifreq req;
|
||||||
|
struct sockaddr_in *host;
|
||||||
|
|
||||||
|
bzero(&req, sizeof(struct ifreq));
|
||||||
|
strcpy(req.ifr_name, eth_name);
|
||||||
|
print_info("eth_name = %s\n",eth_name);
|
||||||
|
ioctl(sockfd, SIOCGIFADDR, &req);
|
||||||
|
host = (struct sockaddr_in*) &req.ifr_addr;
|
||||||
|
close(sockfd);
|
||||||
|
if (host) {
|
||||||
|
strcpy(gwip_, inet_ntoa(host->sin_addr));
|
||||||
|
}
|
||||||
|
return std::string(gwip_);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string IpAddrInit()
|
||||||
|
{
|
||||||
|
const char *WLAN0 = "wlan0";
|
||||||
|
const char *ETH0 = "eth0";
|
||||||
|
std::string strip;
|
||||||
|
strip = GetGwIp_(ETH0);
|
||||||
|
if (strip.compare("0.0.0.0") == 0) {
|
||||||
|
strip = GetGwIp_(WLAN0);
|
||||||
|
}
|
||||||
|
return strip;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetWorkNic()
|
||||||
|
{
|
||||||
|
const char *WLAN0 = "wlan0";
|
||||||
|
const char *ETH0 = "eth0";
|
||||||
|
std::string strip;
|
||||||
|
strip = GetGwIp_(WLAN0);
|
||||||
|
if (strip.compare("0.0.0.0") != 0) {
|
||||||
|
return std::string(WLAN0);
|
||||||
|
}
|
||||||
|
strip = GetGwIp_(ETH0);
|
||||||
|
if (strip.compare("0.0.0.0") != 0) {
|
||||||
|
return std::string(ETH0);
|
||||||
|
}
|
||||||
|
return std::string(ETH0);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string& ClearAllSpace(std::string &str)
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
if( !str.empty()) {
|
||||||
|
while( (index = str.find(' ',index)) != string::npos) {
|
||||||
|
str.erase(index,1);
|
||||||
|
}
|
||||||
|
}return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetSysInfo()
|
||||||
|
{
|
||||||
|
const char * getCpuUse = "top -b -n 1 |grep Cpu | cut -d \",\" -f 1 | cut -d \":\" -f 2 |tr -d ' us'";
|
||||||
|
char chRes[100] = {0};
|
||||||
|
system_custom(getCpuUse, chRes);
|
||||||
|
std::string CpuUse = std::string(chRes);
|
||||||
|
|
||||||
|
const char * getCpuSys = "top -b -n 1 |grep Cpu | cut -d \",\" -f 2 |tr -d ' sy'";
|
||||||
|
memset(chRes, 0, 100);
|
||||||
|
system_custom(getCpuSys, chRes);
|
||||||
|
std::string CpuSys = std::string(chRes);
|
||||||
|
|
||||||
|
const char * getMemtotal = "cat /proc/meminfo | grep MemTotal | awk -F"":"" '{print $2}' |tr -d ' kB'";
|
||||||
|
memset(chRes, 0, 100);
|
||||||
|
system_custom(getMemtotal, chRes);
|
||||||
|
std::string MemTotal = std::string(chRes);
|
||||||
|
|
||||||
|
const char * getMemFree = "cat /proc/meminfo | grep MemFree | awk -F"":"" '{print $2}' |tr -d ' kB'";
|
||||||
|
memset(chRes, 0, 100);
|
||||||
|
system_custom(getMemFree, chRes);
|
||||||
|
std::string MemFree = std::string(chRes);
|
||||||
|
|
||||||
|
float a = boost::lexical_cast<float>(MemFree);
|
||||||
|
float b = boost::lexical_cast<float>(MemTotal);
|
||||||
|
float c = (1 - a/b)*100;
|
||||||
|
|
||||||
|
const char * getEmmcInfo = "df -h | grep /dev/root";
|
||||||
|
memset(chRes, 0, 100);
|
||||||
|
system_custom(getEmmcInfo, chRes);
|
||||||
|
std::string Emmcinfo = std::string(chRes);
|
||||||
|
std::size_t found = Emmcinfo.find("%");
|
||||||
|
if (found != std::string::npos) {
|
||||||
|
Emmcinfo = Emmcinfo.substr(found-3, 3);
|
||||||
|
}
|
||||||
|
Emmcinfo = ClearAllSpace(Emmcinfo);
|
||||||
|
|
||||||
|
char sysinfo[128] = {0};
|
||||||
|
sprintf(sysinfo, "%-13s%-13s%-13s%-13s ", boost::lexical_cast<std::string>(c).substr(0,4).c_str(), CpuSys.c_str(), CpuUse.c_str(), Emmcinfo.c_str());
|
||||||
|
return std::string(sysinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartWriteToDat()
|
||||||
|
{
|
||||||
|
print_info("start writetoDat\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float * ReSample(int WaveDataLength, int N, int *NewWaveDataLength, std::vector<float> & WaveData)
|
||||||
|
{
|
||||||
|
if (N <= 0)
|
||||||
|
return NULL;
|
||||||
|
int NewLength = (int)WaveDataLength / N;
|
||||||
|
float * _OutputData = new float[NewLength];
|
||||||
|
for(int i = 0; i < NewLength; i++) {
|
||||||
|
_OutputData[i] = WaveData[i * N];
|
||||||
|
}
|
||||||
|
*NewWaveDataLength = NewLength;
|
||||||
|
return _OutputData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SetTime(unsigned long seconds, int milliseconds)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
time_t timep = (time_t)seconds;
|
||||||
|
tv.tv_sec = timep;
|
||||||
|
tv.tv_usec = milliseconds*1000;
|
||||||
|
return settimeofday(&tv, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveConfig()
|
||||||
|
{
|
||||||
|
char cmd[32] = { 0 };
|
||||||
|
sprintf(cmd, "rm /CIDW/config/*");
|
||||||
|
system(cmd);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void ZoneConfig(std::string zoneid)
|
||||||
|
{
|
||||||
|
int a = 0;
|
||||||
|
std::string zonelists[] = {"UTC+12","UTC+11","UTC+10","UTC+9","UTC+8","UTC+7","UTC+6","UTC+5","UTC+4","UTC+3","UTC+2","UTC+1","UTC+0","UTC-1","UTC-2","UTC-3","UTC-4","UTC-5","UTC-6","UTC-7","UTC-8","UTC-9","UTC-10","UTC-11"};
|
||||||
|
for (int i = 0;i < sizeof(zonelists);i++)
|
||||||
|
{
|
||||||
|
if (zoneid.compare(zonelists[i]) == 0) {
|
||||||
|
a = i;
|
||||||
|
cout << "a = " << a << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch(a){
|
||||||
|
case 0:zoneid = "GMT-12";break;
|
||||||
|
case 1:zoneid = "GMT-11";break;
|
||||||
|
case 2:zoneid = "GMT-10";break;
|
||||||
|
case 3:zoneid = "GMT-9";break;
|
||||||
|
case 4:zoneid = "GMT-8";break;
|
||||||
|
case 5:zoneid = "GMT-7";break;
|
||||||
|
case 6:zoneid = "GMT-6";break;
|
||||||
|
case 7:zoneid = "GMT-5";break;
|
||||||
|
case 8:zoneid = "GMT-4";break;
|
||||||
|
case 9:zoneid = "GMT-3";break;
|
||||||
|
case 10:zoneid = "GMT-2";break;
|
||||||
|
case 11:zoneid = "GMT-1";break;
|
||||||
|
case 12:zoneid = "GMT-0";break;
|
||||||
|
case 13:zoneid = "GMT+1";break;
|
||||||
|
case 14:zoneid = "GMT+2";break;
|
||||||
|
case 15:zoneid = "GMT+3";break;
|
||||||
|
case 16:zoneid = "GMT+4";break;
|
||||||
|
case 17:zoneid = "GMT+5";break;
|
||||||
|
case 18:zoneid = "GMT+6";break;
|
||||||
|
case 19:zoneid = "GMT+7";break;
|
||||||
|
case 20:zoneid = "GMT+8";break;
|
||||||
|
case 21:zoneid = "GMT+9";break;
|
||||||
|
case 22:zoneid = "GMT+10";break;
|
||||||
|
case 23:zoneid = "GMT+11";break;
|
||||||
|
}
|
||||||
|
char cmd[256] = { 0 };
|
||||||
|
// sprintf(cmd, "rm /etc/localtime");
|
||||||
|
// system(cmd);
|
||||||
|
memset(cmd, 0, 256);
|
||||||
|
sprintf(cmd, "sudo ln -sf /usr/share/zoneinfo/Etc/%s /etc/localtime", zoneid.c_str());
|
||||||
|
system(cmd);
|
||||||
|
print_info("change timezone success!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetFileContent(std::string filename, int line)
|
||||||
|
{
|
||||||
|
std::string strFileContent("");
|
||||||
|
std::ifstream ifileOut(filename.c_str());
|
||||||
|
if(ifileOut.is_open()) { //文件打开
|
||||||
|
int i = 1;
|
||||||
|
while (!ifileOut.eof()) {
|
||||||
|
if (line == 0) {
|
||||||
|
std::string strTemp("");
|
||||||
|
getline(ifileOut, strTemp);
|
||||||
|
strFileContent += strTemp;
|
||||||
|
strFileContent += "\r\n";
|
||||||
|
}
|
||||||
|
if (line != 0) {
|
||||||
|
std::string strTemp("");
|
||||||
|
getline(ifileOut, strTemp);
|
||||||
|
if (line == i) {
|
||||||
|
strFileContent = strTemp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
ifileOut.close();
|
||||||
|
}
|
||||||
|
return strFileContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// int StatusPub()
|
||||||
|
// {
|
||||||
|
// long mem_used = -1;
|
||||||
|
// long mem_free = -1;
|
||||||
|
// long mem_total = -1;
|
||||||
|
// long mem_cached = -1;
|
||||||
|
// char name1[20];
|
||||||
|
// std::string strMemTotal = GetFileContent("/proc/meminfo", 1);
|
||||||
|
// std::string strMemFree = GetFileContent("/proc/meminfo", 2);
|
||||||
|
// std::string strMemCache = GetFileContent("/proc/meminfo", 5);
|
||||||
|
|
||||||
|
// sscanf(strMemTotal.c_str(),"%s%ld",name1,&mem_total);
|
||||||
|
// sscanf(strMemFree.c_str(),"%s%ld",name1,&mem_free);
|
||||||
|
// sscanf(strMemCache.c_str(),"%s%ld",name1,&mem_cached);
|
||||||
|
// mem_used = mem_total - mem_free;
|
||||||
|
// float fMemRate = 1.0 * mem_used / mem_total;
|
||||||
|
|
||||||
|
// float fCpuRate;
|
||||||
|
// char name[8];
|
||||||
|
// double cpu_idle = -1;
|
||||||
|
// double cpu_sys = -1;
|
||||||
|
// double cpu_user = -1;
|
||||||
|
// double cpu_total = -1;
|
||||||
|
// double cpu_wait = -1;
|
||||||
|
// long int user,nice,sys,idle,iowait,irq,softirq;
|
||||||
|
// std::string strCpu1 = GetFileContent("/proc/stat", 1);
|
||||||
|
// sscanf(strCpu1.c_str(),"%s%ld%ld%ld%ld%ld%ld%d",name,&user,&nice,&sys,&idle,&iowait,&irq,&softirq);
|
||||||
|
// boost::this_thread::sleep(boost::posix_time::seconds(2));
|
||||||
|
// long int userNext,niceNext,sysNext,idleNext,iowaitNext,irqNext,softirqNext;
|
||||||
|
// std::string strCpu2 = GetFileContent("/proc/stat", 1);
|
||||||
|
// sscanf(strCpu2.c_str(),"%s%ld%ld%ld%ld%ld%ld%d",name,&userNext,&niceNext,&sysNext,&idleNext,&iowaitNext,&irqNext,&softirqNext);
|
||||||
|
// cpu_total = (userNext+niceNext+sysNext+idleNext+iowaitNext+irqNext+softirqNext) - (user+nice+sys+idle+iowait+irq+softirq);
|
||||||
|
// cpu_user = userNext - user;
|
||||||
|
// cpu_sys = sysNext - sys;
|
||||||
|
// cpu_wait = iowaitNext - iowait;
|
||||||
|
// cpu_idle = idleNext - idle;
|
||||||
|
// fCpuRate = 1.0*(cpu_total - cpu_idle) / cpu_total;
|
||||||
|
// float rateUser = cpu_user *100.0/cpu_total;
|
||||||
|
// float rateSys = cpu_sys * 100.0/cpu_total;
|
||||||
|
|
||||||
|
// if (rateUser > 95) {
|
||||||
|
// rateUser = 92;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /*获取温度 */
|
||||||
|
// std::string tempRaw = GetFileContent(TEMPER_RAW, 1);
|
||||||
|
// std::string temperOffset = GetFileContent(TEMPER_OFFSET, 1);
|
||||||
|
// std::string temperScale = GetFileContent(TEMPER_SCALE, 1);
|
||||||
|
// float temperature = ((boost::lexical_cast<float>(tempRaw) + boost::lexical_cast<float>(temperOffset)) * boost::lexical_cast<float>(temperScale))/1000;
|
||||||
|
|
||||||
|
// char hardName[32];
|
||||||
|
// char hardTotal[32];
|
||||||
|
// char hardUse[32];
|
||||||
|
// char hardFree[32];
|
||||||
|
// char rateHardUse[32];
|
||||||
|
// const char * getEmmcInfo = "df -h | grep /dev/root";
|
||||||
|
// char chRes[100];
|
||||||
|
// memset(chRes, 0, 100);
|
||||||
|
// system_custom(getEmmcInfo, chRes);
|
||||||
|
// sscanf(chRes,"%s%s%s%s%s",hardName, hardTotal, hardUse, hardFree, rateHardUse);
|
||||||
|
// std::string strhardTotal(hardTotal);
|
||||||
|
// std::string strhardFree(hardFree);
|
||||||
|
// std::string strrateHardUse(rateHardUse);
|
||||||
|
|
||||||
|
// Json::Value jsData;
|
||||||
|
// Json::FastWriter fw;
|
||||||
|
// jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
|
// jsData["cpuUserUse"] = rateUser;
|
||||||
|
// jsData["memoryTotal"] = (int)mem_total;
|
||||||
|
// jsData["memoryFree"] = (int)mem_free;
|
||||||
|
// jsData["memoryUse"] = fMemRate * 100;
|
||||||
|
// jsData["hardDiskTotal"] = boost::lexical_cast<double>(strhardTotal.substr(0,strhardTotal.length() - 1));
|
||||||
|
// jsData["hardDiskFree"] = boost::lexical_cast<double>(strhardFree.substr(0,strhardFree.length() - 1));
|
||||||
|
|
||||||
|
// double total = boost::lexical_cast<double>(strhardTotal.substr(0,strhardTotal.length() - 1));
|
||||||
|
// double free = boost::lexical_cast<double>(strhardFree.substr(0,strhardFree.length() - 1));
|
||||||
|
// double use = ((total - free) / free) * 100;
|
||||||
|
// // jsData["hardDiskUse"] = boost::lexical_cast<double>(strrateHardUse.substr(0,strrateHardUse.length() - 1));
|
||||||
|
// jsData["hardDiskUse"] = use;
|
||||||
|
// jsData["cpuSystemUse"] = rateSys;
|
||||||
|
// jsData["temperature"] = temperature;
|
||||||
|
|
||||||
|
// char localtimestamp[32] = { 0 };
|
||||||
|
// GetTimeNet(localtimestamp, 1);
|
||||||
|
// std::string nowTimetamp = std::string(localtimestamp);
|
||||||
|
// jsData["updateTime"] = nowTimetamp;
|
||||||
|
// std::string strJson = fw.write(jsData);
|
||||||
|
// data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
|
||||||
|
|
||||||
|
// std::string strInfo = "mem:"+boost::lexical_cast<std::string>(fMemRate * 100) + "tem:"+boost::lexical_cast<std::string>(temperature);
|
||||||
|
|
||||||
|
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
std::string GetSysStatus()
|
||||||
|
{
|
||||||
|
long mem_used = -1;
|
||||||
|
long mem_free = -1;
|
||||||
|
long mem_total = -1;
|
||||||
|
long mem_cached = -1;
|
||||||
|
char name1[20];
|
||||||
|
std::string strMemTotal = GetFileContent("/proc/meminfo", 1);
|
||||||
|
std::string strMemFree = GetFileContent("/proc/meminfo", 2);
|
||||||
|
std::string strMemCache = GetFileContent("/proc/meminfo", 5);
|
||||||
|
|
||||||
|
sscanf(strMemTotal.c_str(),"%s%ld",name1,&mem_total);
|
||||||
|
sscanf(strMemFree.c_str(),"%s%ld",name1,&mem_free);
|
||||||
|
sscanf(strMemCache.c_str(),"%s%ld",name1,&mem_cached);
|
||||||
|
mem_used = mem_total - mem_free;
|
||||||
|
float fMemRate = 1.0 * mem_used / mem_total;
|
||||||
|
|
||||||
|
float fCpuRate;
|
||||||
|
char name[8];
|
||||||
|
double cpu_idle = -1;
|
||||||
|
double cpu_sys = -1;
|
||||||
|
double cpu_user = -1;
|
||||||
|
double cpu_total = -1;
|
||||||
|
double cpu_wait = -1;
|
||||||
|
long int user,nice,sys,idle,iowait,irq,softirq;
|
||||||
|
std::string strCpu1 = GetFileContent("/proc/stat", 1);
|
||||||
|
sscanf(strCpu1.c_str(),"%s%ld%ld%ld%ld%ld%ld%d",name,&user,&nice,&sys,&idle,&iowait,&irq,&softirq);
|
||||||
|
sleep(1);
|
||||||
|
long int userNext,niceNext,sysNext,idleNext,iowaitNext,irqNext,softirqNext;
|
||||||
|
std::string strCpu2 = GetFileContent("/proc/stat", 1);
|
||||||
|
sscanf(strCpu2.c_str(),"%s%ld%ld%ld%ld%ld%ld%d",name,&userNext,&niceNext,&sysNext,&idleNext,&iowaitNext,&irqNext,&softirqNext);
|
||||||
|
cpu_total = (userNext+niceNext+sysNext+idleNext+iowaitNext+irqNext+softirqNext) - (user+nice+sys+idle+iowait+irq+softirq);
|
||||||
|
cpu_user = userNext - user;
|
||||||
|
cpu_sys = sysNext - sys;
|
||||||
|
cpu_wait = iowaitNext - iowait;
|
||||||
|
cpu_idle = idleNext - idle;
|
||||||
|
fCpuRate = 1.0*(cpu_total - cpu_idle) / cpu_total;
|
||||||
|
float rateUser = cpu_user *100.0/cpu_total;
|
||||||
|
float rateSys = cpu_sys * 100.0/cpu_total;
|
||||||
|
if (rateUser > 95) {
|
||||||
|
rateUser = 92;
|
||||||
|
}
|
||||||
|
|
||||||
|
char hardName[32];
|
||||||
|
char hardTotal[32];
|
||||||
|
char hardUse[32];
|
||||||
|
char hardFree[32];
|
||||||
|
char rateHardUse[32];
|
||||||
|
const char * getEmmcInfo = "df -h | grep /opt";
|
||||||
|
char chRes[100];
|
||||||
|
memset(chRes, 0, 100);
|
||||||
|
system_custom(getEmmcInfo, chRes);
|
||||||
|
sscanf(chRes,"%s%s%s%s%s",hardName, hardTotal, hardUse, hardFree, rateHardUse);
|
||||||
|
std::string strhardTotal(hardTotal);
|
||||||
|
std::string strhardFree(hardFree);
|
||||||
|
std::string strrateHardUse(rateHardUse);
|
||||||
|
|
||||||
|
|
||||||
|
Json::Value jsData;
|
||||||
|
Json::FastWriter fw;
|
||||||
|
jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
|
jsData["cpuUserUse"] = rateUser;
|
||||||
|
jsData["memoryTotal"] = (int)mem_total;
|
||||||
|
jsData["memoryFree"] = (int)mem_free;
|
||||||
|
jsData["memoryUse"] = fMemRate * 100;
|
||||||
|
jsData["hardDiskTotal"] = boost::lexical_cast<double>(strhardTotal.substr(0,strhardTotal.length() - 1));
|
||||||
|
jsData["hardDiskFree"] = boost::lexical_cast<double>(strhardFree.substr(0,strhardFree.length() - 1));
|
||||||
|
|
||||||
|
double total = boost::lexical_cast<double>(strhardTotal.substr(0,strhardTotal.length() - 1));
|
||||||
|
double free = boost::lexical_cast<double>(strhardFree.substr(0,strhardFree.length() - 1));
|
||||||
|
double use = ((total - free) / total) * 100;
|
||||||
|
// jsData["hardDiskUse"] = boost::lexical_cast<double>(strrateHardUse.substr(0,strrateHardUse.length() - 1));
|
||||||
|
jsData["hardDiskUse"] = use;
|
||||||
|
jsData["cpuSystemUse"] = rateSys;
|
||||||
|
|
||||||
|
char localtimestamp[32] = { 0 };
|
||||||
|
GetTimeNet(localtimestamp, 1);
|
||||||
|
std::string nowTimetamp = std::string(localtimestamp);
|
||||||
|
jsData["updateTime"] = nowTimetamp;
|
||||||
|
std::string strJson = fw.write(jsData);
|
||||||
|
return strJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap(char *data)
|
||||||
|
{
|
||||||
|
int tmp;
|
||||||
|
tmp = data[1];
|
||||||
|
data[1] = data[0];
|
||||||
|
data[0] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* JSON_FIELD_CMD = "cmd";//协议: 命令字段
|
||||||
|
static const char* JSON_FIELD_NAME = "dataWatchName";//协议: 终端名称
|
||||||
|
static const char* JSON_FIELD_dataNodeGatewayNo = "dataNodeGatewayNo";
|
||||||
|
static const char* JSON_FIELD_ASSETID = "dataWatchAssetId";//协议: 资产编号 字段
|
||||||
|
static const char* JSON_FIELD_ADDEDBY = "dataWatchAddedBy";//协议: 添加人 字段
|
||||||
|
static const char* JSON_FIELD_DEVICETYPE = "deviceType";
|
||||||
|
static const char* JSON_FIELD_ADDEDDATE = "dataWatchAddedDate";
|
||||||
|
static const char* JSON_FIELD_IPADDRESS = "dataWatchIpAddress";
|
||||||
|
static const char* JSON_FIELD_SN = "serialNumber";
|
||||||
|
static const char* JSON_FIELD_VERSION = "softVersion";
|
||||||
|
static const char* JSON_FIELD_TIMEZONE = "timezone";
|
||||||
|
|
||||||
579
common/SH_CommonFunc.hpp
Normal file
579
common/SH_CommonFunc.hpp
Normal file
@ -0,0 +1,579 @@
|
|||||||
|
#ifndef _COMMONFUNC_
|
||||||
|
#define _COMMONFUNC_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <sys/statfs.h>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <sys/ipc.h>//ipc
|
||||||
|
#include <sys/shm.h>
|
||||||
|
#include "dirent.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//配置文件位置
|
||||||
|
#define NETWORK "/etc/network/interfaces"
|
||||||
|
#define SYSTEMINFOFILE "/opt/configenv/SystemInfo.json" //系统信息
|
||||||
|
#define SERVERCONFIG "/opt/configenv/ServerConfig.json"
|
||||||
|
#define NETWORKCONFIG "/opt/configenv/NetWorkConfig.json"
|
||||||
|
#define SOFTWARE_RUN_LOG "/opt/configenv/cidn.log"
|
||||||
|
#define BOARDTYPE "/opt/configenv/boardtype" //设备类型
|
||||||
|
#define ZIGBEECONFIG "/opt/configenv/ZigbeeConfig.json"
|
||||||
|
|
||||||
|
|
||||||
|
#define SN "/opt/system/sn" //设备序列号
|
||||||
|
#define SYSTEMSTART "/opt/system/start" //系统启动类型标志 0:正常启动 1:重启 2:
|
||||||
|
|
||||||
|
#define GENERAL_BUF_SIZE 128*1024
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
enum TIME_SIZE{
|
||||||
|
TIME_MINUTE=5,
|
||||||
|
TIME_SECEOND=8
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DevData{
|
||||||
|
char mData[128];
|
||||||
|
char mDataMing[128];
|
||||||
|
int mLen;
|
||||||
|
DevData():mLen(0){
|
||||||
|
memset(mData, 0, 128);
|
||||||
|
memset(mDataMing, 0, 128);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DevDataOfGwid{
|
||||||
|
std::string mDevdata;
|
||||||
|
std::string mDevid;
|
||||||
|
bool mIsSimulate;
|
||||||
|
DevDataOfGwid():mDevdata(""),mDevid(""),mIsSimulate(false){
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*onReceiveUart) (DevDataOfGwid &devData);
|
||||||
|
|
||||||
|
struct sys_data {
|
||||||
|
char data[10240];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int total;
|
||||||
|
int count;
|
||||||
|
int type;
|
||||||
|
int number;
|
||||||
|
int flag;
|
||||||
|
char channelId[16];
|
||||||
|
char SensorEngineeringUnit[32];
|
||||||
|
float waveData[32000];
|
||||||
|
} WAVE_CONTAIN;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct ZigbeeInfo {
|
||||||
|
int DevMode;
|
||||||
|
int Channel;
|
||||||
|
std::string PanID;
|
||||||
|
std::string MyAddr;
|
||||||
|
std::string DstAddr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ZIGBEE {
|
||||||
|
char reserve[4];
|
||||||
|
char DevName[16];
|
||||||
|
char DevPwd[16];
|
||||||
|
unsigned char DevMode;
|
||||||
|
unsigned char Chan;
|
||||||
|
short PanID;
|
||||||
|
short MyAddr;
|
||||||
|
unsigned char MyIEEE[8];
|
||||||
|
short DstAddr;
|
||||||
|
unsigned char DstIEEE[8];
|
||||||
|
unsigned char Reserve0;
|
||||||
|
unsigned char PowerLevel;
|
||||||
|
unsigned char RetryNum;
|
||||||
|
unsigned char TranTimeout;
|
||||||
|
unsigned char Serial_Rate;
|
||||||
|
unsigned char Serial_DataB;
|
||||||
|
unsigned char Serial_StopB;
|
||||||
|
unsigned char Serial_ParityB;
|
||||||
|
unsigned char Reserve[10];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct RecvData {
|
||||||
|
unsigned char Head[3];
|
||||||
|
unsigned char ShortAddr[2];
|
||||||
|
unsigned char Type;
|
||||||
|
unsigned char Order;
|
||||||
|
unsigned char Data[92];
|
||||||
|
unsigned char Crc;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DataNodeInfo {
|
||||||
|
int InitFlag;
|
||||||
|
int AccFlag;
|
||||||
|
int ZigbeeFlag;
|
||||||
|
int TemTopFlag;
|
||||||
|
int TemBotFlag;
|
||||||
|
int EquipSta;//设备状态
|
||||||
|
std::string HardVersion;
|
||||||
|
std::string SoftVersion;
|
||||||
|
std::string BpNo;
|
||||||
|
std::string SerialNo;
|
||||||
|
std::string FirstPowerTime;
|
||||||
|
int ConfigFlag;
|
||||||
|
std::string StartBrands;
|
||||||
|
std::string StopBrands;
|
||||||
|
unsigned int FeatureInterVal;
|
||||||
|
unsigned int WaveInterVal;
|
||||||
|
int SamplingRate;//采样率
|
||||||
|
int Range;//量程
|
||||||
|
std::string EnvelopeBandPass;
|
||||||
|
std::string FaultFrequency;
|
||||||
|
std::string ZigbeePanId;
|
||||||
|
int ZigbeeChannel;
|
||||||
|
std::string ZigbeeShortAddr;
|
||||||
|
std::string ZigbeeLongAddr;
|
||||||
|
std::string ZigbeeDesAddr;
|
||||||
|
std::string ConfigDate;
|
||||||
|
int VIntegralFilterFrequency;//速度积分滤波频率
|
||||||
|
|
||||||
|
int RSSI; // 接收信号强度
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DataRecvStatic {
|
||||||
|
float TemTop;
|
||||||
|
float TemBot;
|
||||||
|
int Dip;
|
||||||
|
int Voltage;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DataRecvDym {
|
||||||
|
float DiagnosisPk;
|
||||||
|
float IntegratPk;
|
||||||
|
float IntegratRMS;
|
||||||
|
float RmsValues;
|
||||||
|
float EnvelopEnergy;
|
||||||
|
float Amp1;
|
||||||
|
float Amp2;
|
||||||
|
float Amp3;
|
||||||
|
float Amp4;
|
||||||
|
float Amp5;
|
||||||
|
float Phase1;
|
||||||
|
float Phase2;
|
||||||
|
float Phase3;
|
||||||
|
float Phase4;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TopicList{
|
||||||
|
std::string mPubData; //每秒特征数据上传主题
|
||||||
|
std::string mPubStatus; //状态上传主题
|
||||||
|
std::string mPubHeart;
|
||||||
|
std::string mPubConfig; //上传配置主题
|
||||||
|
std::string mSubData; //订阅主题
|
||||||
|
std::string mPubWaveData; //原始数据发布主题
|
||||||
|
std::string mPubWaveSecondData; //原始数据发布主题
|
||||||
|
std::string mPubCmd; //命令控制发布主题
|
||||||
|
std::string mPubRep;
|
||||||
|
|
||||||
|
std::string mPubLocalWifi;
|
||||||
|
std::string mPubLocalWaveServer;
|
||||||
|
std::string mPubLocalWaveQt;
|
||||||
|
std::string mPubLocalTrigger;
|
||||||
|
std::string mPubLocalConfig;
|
||||||
|
std::string mPubLocalCmd;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//系统描述文件数据定义
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
string siteID; //Unique ID for each site
|
||||||
|
string siteName; //Controller site name
|
||||||
|
string siteCountry; //Controller location country
|
||||||
|
string siteProvince; //province
|
||||||
|
string siteCity; //city
|
||||||
|
double siteLongitude; //longitude
|
||||||
|
double siteLatitude; //latitude
|
||||||
|
string siteTimeZone;
|
||||||
|
string plantName; //Unique plant number
|
||||||
|
string plantNo;
|
||||||
|
string equipmentName; //Equipment Description in the plant
|
||||||
|
string equipmentNo;
|
||||||
|
string dataWatchName; //DNS Name for the DataWatch
|
||||||
|
long dataWachAddedDate; //Date of settings’ creation (Time Stamp)
|
||||||
|
string dataWatchAssetID; //Unique equipment Asset ID
|
||||||
|
string deviceType;
|
||||||
|
string dataWachAddedBy; //User who edited settings
|
||||||
|
string serialNumber;
|
||||||
|
string softVersion;
|
||||||
|
|
||||||
|
}SystemInfo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int number;
|
||||||
|
std::string SensorEngineeringUnit;
|
||||||
|
float waveData[GENERAL_BUF_SIZE];
|
||||||
|
} WAVE_GENERAL;
|
||||||
|
|
||||||
|
|
||||||
|
struct Param_01 {
|
||||||
|
int mMode; //0:登陆 1:更改密码
|
||||||
|
std::string mUserName;
|
||||||
|
std::string mPassWord;
|
||||||
|
std::string mPassWordNew;
|
||||||
|
Param_01():mMode(0), mUserName(""), mPassWord(""), mPassWordNew(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_02 {
|
||||||
|
int mMode; //0:配置时间 1:获取时间
|
||||||
|
int mTimeStamp;
|
||||||
|
Param_02():mMode(0),mTimeStamp(0){};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Param_20 {
|
||||||
|
int mMode; //0: 配置 1:获取
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mDataWatchName;
|
||||||
|
std::string mDataWatchAssetId;
|
||||||
|
std::string mDataWatchAddedBy;
|
||||||
|
Param_20():mMode(0), mCmdSerial(""), mDataWatchName(""), mDataWatchAssetId(""), mDataWatchAddedBy(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Param_22 {
|
||||||
|
int mMode;
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mTimeZone;
|
||||||
|
Param_22():mMode(0),mCmdSerial(""), mTimeZone(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Param_23 {
|
||||||
|
int mMode;
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mServerIp;
|
||||||
|
std::string mPort;
|
||||||
|
std::string mCommMode; // 通信模式,有线通信模式 = 1;4G LTE 无线通信模式 = 2
|
||||||
|
Param_23():mMode(0),mCmdSerial(""), mServerIp(""),mPort(""),mCommMode(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Param_24 {
|
||||||
|
int mMode;
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mFileServerIp;
|
||||||
|
std::string mFilePort;
|
||||||
|
std::string mFileServerSwitch;
|
||||||
|
Param_24():mMode(0),mCmdSerial(""), mFileServerIp(""),mFilePort(""),mFileServerSwitch(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_25 {
|
||||||
|
int mMode;
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mDnsName;
|
||||||
|
std::string mNetworkPortStatus;
|
||||||
|
std::string mGateway;
|
||||||
|
std::string mSubnetMask;
|
||||||
|
std::string mIp;
|
||||||
|
std::string mHostName;
|
||||||
|
Param_25():mMode(0),mCmdSerial(""), mDnsName(""),mGateway(""),mSubnetMask(""),mIp(""),mHostName(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Param_26 {
|
||||||
|
int mMode;
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mDataNodeNo;
|
||||||
|
Param_26():mMode(0),mCmdSerial(""),mDataNodeNo(""){};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_27 {
|
||||||
|
int mMode;
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mDataNodeNo;
|
||||||
|
Param_27():mMode(0),mCmdSerial(""),mDataNodeNo(""){};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct Param_28 {
|
||||||
|
int mMode;
|
||||||
|
std::string mDataNodeNo;
|
||||||
|
std::string mDataNodeName;
|
||||||
|
Param_28():mMode(0),mDataNodeNo(""),mDataNodeName(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_29 {
|
||||||
|
int mMode;
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mChannelId;
|
||||||
|
std::string mDataNodeNo;
|
||||||
|
int mPackageFlag;
|
||||||
|
Param_29():mMode(0),mCmdSerial(""),mChannelId(""),mDataNodeNo(""),mPackageFlag(0){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_30 {
|
||||||
|
int mMode;
|
||||||
|
std::string mChannelId;
|
||||||
|
std::string mDataNodeNo;
|
||||||
|
int mPackageFlag;
|
||||||
|
Param_30():mMode(0),mChannelId(""),mDataNodeNo(""),mPackageFlag(0){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_31 {
|
||||||
|
int mMode;
|
||||||
|
//int mChannelId;
|
||||||
|
std::string mChannelId;
|
||||||
|
Param_31():mMode(0),mChannelId(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_32 {
|
||||||
|
int mMode;
|
||||||
|
std::string mChannelId;
|
||||||
|
int mPackageFlag;
|
||||||
|
Param_32():mMode(0),mChannelId(""),mPackageFlag(0){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_33 {
|
||||||
|
int mMode;
|
||||||
|
std::string mUnit;
|
||||||
|
Param_33():mMode(0),mUnit(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_34 {
|
||||||
|
int mMode;
|
||||||
|
std::string mBeforeTime;
|
||||||
|
std::string mAfterTime;
|
||||||
|
Param_34():mMode(0),mBeforeTime(""),mAfterTime(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_35 {
|
||||||
|
int mMode;
|
||||||
|
std::string mTriggerInterValTime;
|
||||||
|
std::string mTriggerInterValSwitch;
|
||||||
|
Param_35():mMode(0),mTriggerInterValTime(""),mTriggerInterValSwitch(){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_36 {
|
||||||
|
int mMode;
|
||||||
|
std::string mTriggerTime;
|
||||||
|
std::string mTriggerTimeSwitch;
|
||||||
|
Param_36():mMode(0),mTriggerTime(""),mTriggerTimeSwitch(){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_37 {
|
||||||
|
int mMode;
|
||||||
|
std::string mTriggerDelayTime;
|
||||||
|
std::string mTriggerDelaySwitch;
|
||||||
|
Param_37():mMode(0),mTriggerDelayTime(""),mTriggerDelaySwitch(){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_39 {
|
||||||
|
int mMode;
|
||||||
|
int mPage;
|
||||||
|
int mNumber;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_45 {
|
||||||
|
int mMode; //0: 配置 1:获取
|
||||||
|
std::string mCmdSerial;
|
||||||
|
std::string mCountryId;
|
||||||
|
std::string mProvincesId ;
|
||||||
|
std::string mCityListId;
|
||||||
|
Param_45():mMode(0),mCmdSerial(""), mCountryId(""),mProvincesId(""),mCityListId(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_46 {
|
||||||
|
int mMode;
|
||||||
|
std::string mFileName;
|
||||||
|
Param_46():mMode(0),mFileName(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Param_47 {
|
||||||
|
int mMode;
|
||||||
|
std::string mFileName;
|
||||||
|
Param_47():mMode(0),mFileName(""){};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 系统运行时输入入参进行系统软件版本查询
|
||||||
|
* @param argv 输入参数 -vV版本查询 --debugmode日志调试模式
|
||||||
|
* @return 函数返回0执行成功
|
||||||
|
*/
|
||||||
|
extern int CheckFileVersion(int argc, char** argv);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取当前实时时间
|
||||||
|
* @return 时间string 例:2018-11-18 17:16:10
|
||||||
|
*/
|
||||||
|
extern std::string GetCurrentTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 和系统交互函数
|
||||||
|
* @param cmd 要发出的系统命令 例:ls
|
||||||
|
* @param buf 系统返回的数据存在buf里
|
||||||
|
* @return -1:失败 0:成功
|
||||||
|
*/
|
||||||
|
extern int system_custom(const char *cmd, char *buf);
|
||||||
|
|
||||||
|
|
||||||
|
//extern int uartreadhandle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 向日志写入内存信息
|
||||||
|
*/
|
||||||
|
extern void WriteMemoryInfo();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取当前日期
|
||||||
|
* @return 当前日期的string
|
||||||
|
*/
|
||||||
|
extern std::string GetDayDate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取当前时间 例 12:00
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
extern void GetTime_(char * time_buff,TIME_SIZE len) ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取当前时间戳
|
||||||
|
* @param timebuf 定义的buf存储数据
|
||||||
|
* @param type 0 是毫秒级的时间戳 1 秒级的时间戳
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
extern void GetTimeNet(char* timebuf, int type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 从配置文件中读取数据
|
||||||
|
* @param filename 配置文件名
|
||||||
|
* @param config 配置选项
|
||||||
|
* @param option 具体配置参数
|
||||||
|
* @return std::string 返回要获取的参数数据
|
||||||
|
*/
|
||||||
|
extern std::string ReadStrByOpt(std::string filename, std::string config, std::string option);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 写配置文件
|
||||||
|
* @param filename 配置文件名
|
||||||
|
* @param config 配置选项
|
||||||
|
* @param option 具体配置参数
|
||||||
|
* @param value 具体的数据值
|
||||||
|
* @return int 0:配置成功
|
||||||
|
*/
|
||||||
|
extern int WriteStr2Config(std::string filename, std::string config, std::string option, std::string value, bool listable = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取设备的MAC地址做为设备的唯一标识
|
||||||
|
* @return std::string Mac地址
|
||||||
|
*/
|
||||||
|
extern std::string GetLocalMac();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取设备IP
|
||||||
|
* @return std::string IP地址
|
||||||
|
*/
|
||||||
|
extern std::string IpAddrInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取正在工作的网卡
|
||||||
|
* @return std::string
|
||||||
|
*/
|
||||||
|
extern std::string GetWorkNic();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取系统基本信息
|
||||||
|
* @return std::string CPU MEM DISK info
|
||||||
|
*/
|
||||||
|
extern std::string GetSysInfo();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 去掉字符串所有空格
|
||||||
|
* @return std::string
|
||||||
|
*/
|
||||||
|
extern std::string & ClearAllSpace(std::string &str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 调用接口写入data数据
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
extern void StartWriteToDat();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 循环检测文件
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
extern void BackupDatFile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 降采样
|
||||||
|
* @return double
|
||||||
|
*/
|
||||||
|
extern float * ReSample(int WaveDataLength, int N, int *NewWaveDataLength, std::vector<float> & WaveData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置系统时间
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
extern int SetTime(unsigned long seconds, int milliseconds = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 删除配置文件
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
extern void RemoveConfig();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取文件内容
|
||||||
|
* @param filename 文件名
|
||||||
|
* @param line 第几行
|
||||||
|
* @return std::string
|
||||||
|
*/
|
||||||
|
extern std::string GetFileContent(std::string filename, int line);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 配置时区
|
||||||
|
* @param zoneid 时区ID
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
extern void ZoneConfig(std::string zoneid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取系统基本信息
|
||||||
|
* @return std::string CPU MEM DISK info
|
||||||
|
*/
|
||||||
|
extern std::string GetSysStatus();
|
||||||
|
|
||||||
|
|
||||||
|
extern void swap(char *data);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
149
common/SH_global.h
Normal file
149
common/SH_global.h
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
#ifndef _GLOBALCONFIG_H_
|
||||||
|
#define _GLOBALCONFIG_H_
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "../API_log/SH_log.h"
|
||||||
|
#include "SH_CommonFunc.hpp"
|
||||||
|
#include "../mqttclient/SH_MqttClient.h"
|
||||||
|
|
||||||
|
//******************** 全局变量**********************
|
||||||
|
enum enumZigBeeTransmitStatus {
|
||||||
|
NO_ENTER_TRANSMITTING_STATUS = 0,
|
||||||
|
ENTER_TRANSMITTING_STATUS
|
||||||
|
};
|
||||||
|
|
||||||
|
class GlobalConfig
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
static int RUN_MODE; //1调试模式 0运行模式
|
||||||
|
static int QuitFlag_G; //程序退出标志
|
||||||
|
static int LinkStatus_G; //和服务器连接状态
|
||||||
|
static int LinkCount;
|
||||||
|
static std::string Version; //软件版本号
|
||||||
|
static std::string MacAddr_G; //设备MAC地址
|
||||||
|
static std::string IpAddr_G; //设备IP
|
||||||
|
static std::string DbName_G; //数据库名字
|
||||||
|
static std::string ServerIP; //服务器地址
|
||||||
|
static int ServerPort; //服务器端口
|
||||||
|
static std::string UartName_G;
|
||||||
|
static TopicList Topic_G; //发布的主题
|
||||||
|
static ZigbeeInfo ZigbeeInfo_G; //gateway zigbee info
|
||||||
|
static ZIGBEE Zigbee_G;
|
||||||
|
|
||||||
|
static enumZigBeeTransmitStatus EnterZigBeeWaveTransmittingFlag_G; // 进入ZigBee网络原始数据传输状态标志
|
||||||
|
static int EnterZigBeeWaveTransmittingCnt_G; // 进入ZigBee网络原始数据传输状态计数器,以秒为单位进行计数
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NONE "\033[m"
|
||||||
|
#define RED "\033[0;32;31m"
|
||||||
|
#define LIGHT_RED "\033[1;31m"
|
||||||
|
#define GREEN "\033[0;32;32m"
|
||||||
|
#define LIGHT_GREEN "\033[1;32m"
|
||||||
|
#define BLUE "\033[0;32;34m"
|
||||||
|
#define LIGHT_BLUE "\033[1;34m"
|
||||||
|
#define DARY_GRAY "\033[1;30m"
|
||||||
|
#define CYAN "\033[0;36m"
|
||||||
|
#define LIGHT_CYAN "\033[1;36m"
|
||||||
|
#define PURPLE "\033[0;35m"
|
||||||
|
#define LIGHT_PURPLE "\033[1;35m"
|
||||||
|
#define BROWN "\033[0;33m"
|
||||||
|
#define YELLOW "\033[1;33m"
|
||||||
|
#define LIGHT_GRAY "\033[0;37m"
|
||||||
|
#define WHITE "\033[1;37m"
|
||||||
|
|
||||||
|
#define perror_info(info) { \
|
||||||
|
if (GlobalConfig::RUN_MODE) { \
|
||||||
|
perror(info); \
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define print_dev(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(YELLOW"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define print_error(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(LIGHT_RED"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define print_purple(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(PURPLE"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define print_control(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(GREEN"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define print_red(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(RED"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_light_green(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(LIGHT_GREEN"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_blue(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(BLUE"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), GetCurrentTime().c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_light_blue(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(LIGHT_BLUE"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid),boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_dary_gray(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(DARY_GRAY"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_cyan(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(CYAN info"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_debug(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(LIGHT_CYAN info NONE, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_light_purple(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(LIGHT_PURPLE"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_brown(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(BROWN"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_info(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(LIGHT_GRAY"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
#define print_white(info,...) {\
|
||||||
|
if (GlobalConfig::RUN_MODE) {\
|
||||||
|
printf(WHITE"[threadid:%ld][%s][%s:%d]" info NONE, syscall(SYS_gettid), boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time()).c_str(),__FUNCTION__, __LINE__, ##__VA_ARGS__);\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
|
//按8 取整
|
||||||
|
#define Length_(len) do{ \
|
||||||
|
len = ((((len>>3) + ((len&0x7)>0?1:0))<<4) + 8); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif
|
||||||
511
dbaccess/SH_SqlDB.cpp
Normal file
511
dbaccess/SH_SqlDB.cpp
Normal file
@ -0,0 +1,511 @@
|
|||||||
|
#include "SH_SqlDB.hpp"
|
||||||
|
#include "../API_log/SH_log.h"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
bool SqlSwitch()
|
||||||
|
{
|
||||||
|
if (access("./sql", 0) >= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SqliteDB *sql_ctl = SqliteDB::instance();
|
||||||
|
|
||||||
|
SqliteDB::SqliteDB()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SqliteDB::~SqliteDB()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SqliteDB::SqliteInit(const char *pDbName, bool isDB2)
|
||||||
|
{
|
||||||
|
char sql_exec[2048];
|
||||||
|
memset(sql_exec, 0, 2048);
|
||||||
|
|
||||||
|
//创建传感器信息存储表
|
||||||
|
memset(sql_exec, 0, 2048);
|
||||||
|
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||||
|
T_SENSOR_INFO(TNAME),
|
||||||
|
T_SENSOR_INFO(DATANODENO),
|
||||||
|
T_SENSOR_INFO(DATANODENAME),
|
||||||
|
T_SENSOR_INFO(INITFLAG),
|
||||||
|
T_SENSOR_INFO(ACCFLAG),
|
||||||
|
T_SENSOR_INFO(ZIGBEEFLAG),
|
||||||
|
T_SENSOR_INFO(TEMTOPFLAG),
|
||||||
|
T_SENSOR_INFO(TEMBOTFLAG),
|
||||||
|
T_SENSOR_INFO(EQUIPSTA),
|
||||||
|
T_SENSOR_INFO(HARDVERSION),
|
||||||
|
T_SENSOR_INFO(SOFTVERSION),
|
||||||
|
T_SENSOR_INFO(BPNO),
|
||||||
|
T_SENSOR_INFO(SERIALNO),
|
||||||
|
T_SENSOR_INFO(FIRSTPOWERNO),
|
||||||
|
T_SENSOR_INFO(CONFIGFLAG),
|
||||||
|
T_SENSOR_INFO(STARTBRANDS),
|
||||||
|
T_SENSOR_INFO(STOPBRANDS),
|
||||||
|
T_SENSOR_INFO(FEATUREINTERVAL),
|
||||||
|
T_SENSOR_INFO(WAVEINTERVAL),
|
||||||
|
T_SENSOR_INFO(SAMPLINGRATE),
|
||||||
|
T_SENSOR_INFO(SCOPE),
|
||||||
|
T_SENSOR_INFO(RANGE),
|
||||||
|
T_SENSOR_INFO(ENVELOPEBANDPASS),
|
||||||
|
T_SENSOR_INFO(FAULTFREQUENCY),
|
||||||
|
T_SENSOR_INFO(ZIGBEEPANID),
|
||||||
|
T_SENSOR_INFO(ZIGBEECHANNEL),
|
||||||
|
T_SENSOR_INFO(ZIGBEESHORTADDR),
|
||||||
|
T_SENSOR_INFO(ZIGBEELONGADDR),
|
||||||
|
T_SENSOR_INFO(ZIGBEEDESADDR),
|
||||||
|
T_SENSOR_INFO(STATUS),
|
||||||
|
T_SENSOR_INFO(TIMESTAMP),
|
||||||
|
T_SENSOR_INFO(VIFF),
|
||||||
|
T_SENSOR_INFO(RSSI)),
|
||||||
|
CreateTable(sql_exec, isDB2);
|
||||||
|
|
||||||
|
//创建传感器数据存储表
|
||||||
|
memset(sql_exec, 0, 2048);
|
||||||
|
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||||
|
T_DATA_INFO(TNAME),
|
||||||
|
T_DATA_INFO(DATANODENO),
|
||||||
|
T_DATA_INFO(CHANNELID),
|
||||||
|
T_DATA_INFO(DIAGNOSISEAK),
|
||||||
|
T_DATA_INFO(INTEGRATPK),
|
||||||
|
T_DATA_INFO(INTEGRATRMS),
|
||||||
|
T_DATA_INFO(RMSVALUES),
|
||||||
|
T_DATA_INFO(ENVELOPNERGY),
|
||||||
|
T_DATA_INFO(AMP1),
|
||||||
|
T_DATA_INFO(AMP2),
|
||||||
|
T_DATA_INFO(AMP3),
|
||||||
|
T_DATA_INFO(AMP4),
|
||||||
|
T_DATA_INFO(AMP5),
|
||||||
|
T_DATA_INFO(PHASE1),
|
||||||
|
T_DATA_INFO(PHASE2),
|
||||||
|
T_DATA_INFO(PHASE3),
|
||||||
|
T_DATA_INFO(PHASE4),
|
||||||
|
T_DATA_INFO(TIMESTAMP));
|
||||||
|
CreateTable(sql_exec, isDB2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//创建传感器静态数据存储表
|
||||||
|
memset(sql_exec, 0, 2048);
|
||||||
|
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s);",
|
||||||
|
T_DATASTATIC_INFO(TNAME),
|
||||||
|
T_DATASTATIC_INFO(DATANODENO),
|
||||||
|
T_DATASTATIC_INFO(CHANNELID),
|
||||||
|
T_DATASTATIC_INFO(TEMTOP),
|
||||||
|
T_DATASTATIC_INFO(TEMBOT),
|
||||||
|
T_DATASTATIC_INFO(DIP),
|
||||||
|
T_DATASTATIC_INFO(VOLTAGE),
|
||||||
|
T_DATASTATIC_INFO(TIMESTAMP));
|
||||||
|
CreateTable(sql_exec, isDB2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SqliteDB::OpenDB(const char *pDbName, bool isDB2)
|
||||||
|
{
|
||||||
|
if (isDB2 == false) {
|
||||||
|
int ret = 0;
|
||||||
|
ret = sqlite3_open(pDbName, &mDBAcess);
|
||||||
|
if (ret == SQLITE_OK) {
|
||||||
|
sqlite3_exec(mDBAcess, "PRAGMA synchronous = NORMAL;", 0, 0, 0);
|
||||||
|
sqlite3_exec(mDBAcess, "PRAGMA cache_size=8000;", 0, 0, 0);
|
||||||
|
sqlite3_exec(mDBAcess, "PRAGMA temp_store = MEMORY;", 0, 0, 0);
|
||||||
|
sqlite3_exec(mDBAcess, "PRAGMA auto_vacuum = 1;", 0, 0, 0);
|
||||||
|
print_info("Success To Open DataBase!\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print_error("Fail To Open DataBase!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int ret = 0;
|
||||||
|
ret = sqlite3_open(pDbName, &mDb2);
|
||||||
|
if (ret == SQLITE_OK) {
|
||||||
|
sqlite3_exec(mDb2, "PRAGMA synchronous = NORMAL;", 0, 0, 0);
|
||||||
|
sqlite3_exec(mDb2, "PRAGMA cache_size=8000;", 0, 0, 0);
|
||||||
|
sqlite3_exec(mDb2, "PRAGMA temp_store = MEMORY;", 0, 0, 0);
|
||||||
|
sqlite3_exec(mDb2, "PRAGMA auto_vacuum = 1;", 0, 0, 0);
|
||||||
|
print_info("Success To Open DataBase!\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print_error("Fail To Open DataBase!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::CloseDB()
|
||||||
|
{
|
||||||
|
return sqlite3_close(mDBAcess);
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3 *SqliteDB::GetDbHandle(bool isDB2)
|
||||||
|
{
|
||||||
|
if (isDB2 == false) {
|
||||||
|
return mDBAcess;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return mDb2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::CreateTable(const char *sql, bool isDB2)
|
||||||
|
{
|
||||||
|
print_light_green("%s\n", sql);
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", sql);
|
||||||
|
char *msg;
|
||||||
|
int iRet = sqlite3_exec(GetDbHandle(isDB2), sql, 0, 0, &msg);
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||||
|
sqlite3_free(msg);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::GetTableColumnCount(const char *tablename, bool isDB2)
|
||||||
|
{
|
||||||
|
std::string strSql = "select * from ";
|
||||||
|
int count = 0;
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
strSql = strSql + tablename + ";";
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
sqlite3_prepare_v2(GetDbHandle(isDB2), strSql.c_str(), -1, &stmt, 0);
|
||||||
|
count = sqlite3_column_count(stmt);
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::GetTableRows(const char *tablename, const char *whereCon)
|
||||||
|
{
|
||||||
|
int nRow = 0;
|
||||||
|
std::string strSql = "select count(*) from ";
|
||||||
|
if (whereCon != NULL) {
|
||||||
|
strSql = strSql + tablename + " where " + whereCon + ";";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + tablename + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||||
|
print_error("sqlite3_prepare_v2:%s\n",sqlite3_errmsg(mDBAcess));
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int retStep = sqlite3_step(stmt);
|
||||||
|
if (retStep == SQLITE_ROW) {
|
||||||
|
nRow = sqlite3_column_int(stmt, 0);
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return nRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::AlterTable(const char *tablename, const char *column, bool isAdd, bool isDB2)
|
||||||
|
{
|
||||||
|
int iRet = SQLITE_ERROR;
|
||||||
|
if (isAdd) {
|
||||||
|
std::string strSql = "alter table ";
|
||||||
|
strSql = strSql + tablename + " add " + column + ";";
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, NULL);
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
perror_info("sqlite3_exec");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec_t SqliteDB::GetDataSingleLine(const char *tablename, const char *column, const char *whereCon)
|
||||||
|
{
|
||||||
|
vec_t vecResult;
|
||||||
|
std::string strSql = "select ";
|
||||||
|
if (whereCon != NULL) {
|
||||||
|
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + column + " from " + tablename + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||||
|
print_error("sqlite3_prepare_v2:%s\n", sqlite3_errmsg(mDBAcess));
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return vecResult;
|
||||||
|
}
|
||||||
|
int retStep = sqlite3_step(stmt);
|
||||||
|
int column_count = sqlite3_column_count(stmt);
|
||||||
|
if (retStep == SQLITE_ROW) {
|
||||||
|
for (int iCol = 0; iCol < column_count; iCol++) {
|
||||||
|
char *columninfo = (char*)sqlite3_column_text(stmt, iCol);
|
||||||
|
std::string str = columninfo != NULL ? columninfo : "";
|
||||||
|
vecResult.push_back(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return vecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::string SqliteDB::GetData(const char *tablename, const char *column, const char *whereCon)
|
||||||
|
{
|
||||||
|
std::string strRes;
|
||||||
|
std::string strSql = "select ";
|
||||||
|
if (whereCon != NULL) {
|
||||||
|
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + column + " from " + tablename + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||||
|
print_error("sqlite3_prepare_v2:%s\n", sqlite3_errmsg(mDBAcess));
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return strRes;
|
||||||
|
}
|
||||||
|
int retStep = sqlite3_step(stmt);
|
||||||
|
if (retStep == SQLITE_ROW) {
|
||||||
|
char *columninfo = (char*)sqlite3_column_text(stmt, 0);
|
||||||
|
strRes = columninfo != NULL ? columninfo : "";
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return strRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
array_t SqliteDB::GetDataMultiLine(const char *tablename, const char *column, const char *whereCon)
|
||||||
|
{
|
||||||
|
array_t arrResult;
|
||||||
|
std::string strSql = "select ";
|
||||||
|
if (whereCon != NULL) {
|
||||||
|
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + column + " from " + tablename + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||||
|
print_error("sqlite3_prepare_v2:%s\n", sqlite3_errmsg(mDBAcess));
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return arrResult;
|
||||||
|
}
|
||||||
|
int retStep = sqlite3_step(stmt);
|
||||||
|
int column_count = sqlite3_column_count(stmt);
|
||||||
|
while (retStep == SQLITE_ROW) {
|
||||||
|
vec_t vecResult;
|
||||||
|
for (int iCol = 0; iCol < column_count; iCol++) {
|
||||||
|
char *columninfo = (char*)sqlite3_column_text(stmt, iCol);
|
||||||
|
std::string str = columninfo != NULL ? columninfo : "";
|
||||||
|
vecResult.push_back(str);
|
||||||
|
}
|
||||||
|
arrResult.push_back(vecResult);
|
||||||
|
retStep = sqlite3_step(stmt);
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return arrResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec_t SqliteDB::GetDataMultiLineOfOneColumn(const char *tablename, const char *column, const char *whereCon)
|
||||||
|
{
|
||||||
|
vec_t vecResult;
|
||||||
|
std::string strSql = "select ";
|
||||||
|
if (whereCon != NULL) {
|
||||||
|
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + column + " from " + tablename + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
if (sqlite3_prepare_v2(mDBAcess, strSql.c_str(), -1, &stmt, 0) != SQLITE_OK) {
|
||||||
|
print_error("sqlite3_prepare_v2:%s\n", sqlite3_errmsg(mDBAcess));
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return vecResult;
|
||||||
|
}
|
||||||
|
int retStep = sqlite3_step(stmt);
|
||||||
|
while (retStep == SQLITE_ROW) {
|
||||||
|
char *columninfo = (char*)sqlite3_column_text(stmt, 0);
|
||||||
|
std::string str = columninfo != NULL ? columninfo : "";
|
||||||
|
vecResult.push_back(str);
|
||||||
|
retStep = sqlite3_step(stmt);
|
||||||
|
}
|
||||||
|
sqlite3_finalize(stmt);
|
||||||
|
return vecResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int SqliteDB::DeleteTableData(const char* tablename, const char* whereCond, bool isDB2)
|
||||||
|
{
|
||||||
|
std::string strSql = "delete from ";
|
||||||
|
if (whereCond != NULL) {
|
||||||
|
strSql = strSql + tablename + " where " + whereCond + ";";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + tablename + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
char *msg;
|
||||||
|
int iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, &msg);
|
||||||
|
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||||
|
sqlite3_free(msg);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::DeleteTableDataOneConditon(const char* tablename, const char* condColumnName, const char * condColumnValue, bool isDB2)
|
||||||
|
{
|
||||||
|
std::string strSql = "delete from ";
|
||||||
|
if (condColumnName != NULL) {
|
||||||
|
strSql = strSql + tablename + " where " + condColumnName + "='" + condColumnValue + "';";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + tablename + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
char *msg;
|
||||||
|
int iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, &msg);
|
||||||
|
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||||
|
sqlite3_free(msg);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::UpdateTableData(const char* tablename, const char* updateColumn, const char* whereCond, bool isDB2)
|
||||||
|
{
|
||||||
|
std::string strSql = "update ";
|
||||||
|
if (whereCond != NULL) {
|
||||||
|
strSql = strSql + tablename + " set " + updateColumn + " where " + whereCond + ";";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + tablename + " set " + updateColumn + ";";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
char *msg;
|
||||||
|
int iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, &msg);
|
||||||
|
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||||
|
sqlite3_free(msg);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::UpdateTableData(const char* directSql, bool isDB2)
|
||||||
|
{
|
||||||
|
print_light_green("%s\n", directSql);
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", directSql);
|
||||||
|
char *msg;
|
||||||
|
int iRet = sqlite3_exec(GetDbHandle(isDB2), directSql, 0, 0, &msg);
|
||||||
|
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||||
|
sqlite3_free(msg);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::UpdateTableDataOneColumn(const char* tablename, const char* columnName, const char* columnValue, const char* whereColName, const char * whereColValue, bool isDB2)
|
||||||
|
{
|
||||||
|
std::string strSql = "update ";
|
||||||
|
if (whereColName != NULL) {
|
||||||
|
strSql = strSql + tablename + " set " + columnName + "='" + columnValue + "'" + " where " + whereColName + "='" + whereColValue + "';";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strSql = strSql + tablename + " set " + columnName + "='" + columnValue + "';";
|
||||||
|
}
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
char *msg;
|
||||||
|
int iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, &msg);
|
||||||
|
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||||
|
sqlite3_free(msg);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::InsertData(const char* tablename, const char* insertValues, int replace, bool expandable, bool isDB2)
|
||||||
|
{
|
||||||
|
char *msg;
|
||||||
|
int iRet = 0;
|
||||||
|
if (expandable) {
|
||||||
|
char *strSql = (char *)malloc(4096);
|
||||||
|
if (strSql == NULL) {
|
||||||
|
print_error("malloc error\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
char strReplace[] = "replace into ";
|
||||||
|
memset(strSql, 0, 4096);
|
||||||
|
if (replace == 0) {
|
||||||
|
memset(strReplace, 0, sizeof(strSql));
|
||||||
|
}
|
||||||
|
sprintf(strSql, "%s %s%s %s %s %s", "insert into", strReplace, tablename, "values(", insertValues, ");");
|
||||||
|
print_light_green("%s\n", strSql);
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql);
|
||||||
|
iRet = sqlite3_exec(GetDbHandle(isDB2), strSql, 0, 0, &msg);
|
||||||
|
|
||||||
|
free(strSql);
|
||||||
|
} else {
|
||||||
|
std::string strSql = "insert into ";
|
||||||
|
if (replace != 0) {
|
||||||
|
strSql = "replace into ";
|
||||||
|
}
|
||||||
|
strSql = strSql + tablename + " values(" + insertValues + ");";
|
||||||
|
print_light_green("%s\n", strSql.c_str());
|
||||||
|
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||||
|
iRet = sqlite3_exec(GetDbHandle(isDB2), strSql.c_str(), 0, 0, &msg);
|
||||||
|
}
|
||||||
|
if (iRet != SQLITE_OK) {
|
||||||
|
print_error("sqlite3 error: code=%d msg=%s\n", iRet, msg);
|
||||||
|
sqlite3_free(msg);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::TransBegin()
|
||||||
|
{
|
||||||
|
return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::TransRollback()
|
||||||
|
{
|
||||||
|
return sqlite3_exec(mDBAcess, "rollback;", 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteDB::TransCommit()
|
||||||
|
{
|
||||||
|
return sqlite3_exec(mDBAcess, "commit;", 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SqliteDB::HandError(int code)
|
||||||
|
{
|
||||||
|
if (code == SQLITE_CORRUPT) {
|
||||||
|
/*
|
||||||
|
* 用system 删除数据库
|
||||||
|
*/
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
127
dbaccess/SH_SqlDB.hpp
Normal file
127
dbaccess/SH_SqlDB.hpp
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
#ifndef _SQLDB_H_L
|
||||||
|
#define _SQLDB_H_L
|
||||||
|
extern "C"{
|
||||||
|
#include <sqlite3.h>
|
||||||
|
}
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
|
||||||
|
#define T_SENSOR_INFO(x) T_SENSOR_INFO[T_SENSOR_INFO_##x]
|
||||||
|
#define T_DATA_INFO(x) T_DATA_INFO[T_DATA_INFO_##x]
|
||||||
|
#define T_DATASTATIC_INFO(x) T_DATASTATIC_INFO[T_DATASTATIC_INFO_##x]
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::string> map_t;
|
||||||
|
typedef std::vector<std::string> vec_t;
|
||||||
|
typedef std::vector<vec_t> array_t;
|
||||||
|
|
||||||
|
class SqliteDB : public MySingleton < SqliteDB > {
|
||||||
|
public:
|
||||||
|
explicit SqliteDB();
|
||||||
|
virtual ~SqliteDB();
|
||||||
|
bool OpenDB(const char *pDbName, bool isDB2=false);
|
||||||
|
void SqliteInit(const char *pDbName, bool isDB2=false);
|
||||||
|
int TransBegin();
|
||||||
|
int TransRollback();
|
||||||
|
int TransCommit();
|
||||||
|
int CreateTable(const char *sql, bool isDB2=false);
|
||||||
|
int GetTableColumnCount(const char *tablename, bool isDB2 = false);
|
||||||
|
int GetTableRows(const char *tablename, const char *whereCon);
|
||||||
|
int AlterTable(const char *tablename, const char *column, bool isAdd = true, bool isDB2=false);
|
||||||
|
vec_t GetDataSingleLine(const char *tablename, const char *column, const char *whereCon);
|
||||||
|
std::string GetData(const char *tablename, const char *column, const char *whereCon);
|
||||||
|
array_t GetDataMultiLine(const char *tablename, const char *column, const char *whereCon);
|
||||||
|
vec_t GetDataMultiLineOfOneColumn(const char *tablename, const char *column, const char *whereCon);
|
||||||
|
int DeleteTableData(const char* tablename, const char* whereCond = NULL, bool isDB2=false);
|
||||||
|
int DeleteTableDataOneConditon(const char* tablename, const char* condColumnName, const char * condColumnValue, bool isDB2=false);
|
||||||
|
int UpdateTableData(const char* tablename, const char* updateColumn, const char* whereCond, bool isDB2 = false);
|
||||||
|
int UpdateTableDataOneColumn(const char* tablename, const char* columnName, const char* columnValue, const char* whereColName = NULL, const char * whereColValue = NULL, bool isDB2 = false);
|
||||||
|
int UpdateTableData(const char* directSql, bool isDB2 = false);
|
||||||
|
int InsertData(const char* tablename, const char* insertValues, int replace = 0, bool expandalbe = false, bool isDB2 = false);
|
||||||
|
int CloseDB();
|
||||||
|
|
||||||
|
private:
|
||||||
|
sqlite3 *GetDbHandle(bool isDB2);
|
||||||
|
void HandError(int code);
|
||||||
|
sqlite3 *mDBAcess;
|
||||||
|
sqlite3 *mDb2;
|
||||||
|
};
|
||||||
|
extern SqliteDB *sql_ctl;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
T_SENSOR_INFO_TNAME = 0,
|
||||||
|
T_SENSOR_INFO_DATANODENO,
|
||||||
|
T_SENSOR_INFO_DATANODENAME,
|
||||||
|
T_SENSOR_INFO_INITFLAG,
|
||||||
|
T_SENSOR_INFO_ACCFLAG,
|
||||||
|
T_SENSOR_INFO_ZIGBEEFLAG,
|
||||||
|
T_SENSOR_INFO_TEMTOPFLAG,
|
||||||
|
T_SENSOR_INFO_TEMBOTFLAG,
|
||||||
|
T_SENSOR_INFO_EQUIPSTA,
|
||||||
|
T_SENSOR_INFO_HARDVERSION,
|
||||||
|
T_SENSOR_INFO_SOFTVERSION,
|
||||||
|
T_SENSOR_INFO_BPNO,
|
||||||
|
T_SENSOR_INFO_SERIALNO,
|
||||||
|
T_SENSOR_INFO_FIRSTPOWERNO,
|
||||||
|
T_SENSOR_INFO_CONFIGFLAG,
|
||||||
|
T_SENSOR_INFO_STARTBRANDS,
|
||||||
|
T_SENSOR_INFO_STOPBRANDS,
|
||||||
|
T_SENSOR_INFO_FEATUREINTERVAL,
|
||||||
|
T_SENSOR_INFO_WAVEINTERVAL,
|
||||||
|
T_SENSOR_INFO_SAMPLINGRATE,
|
||||||
|
T_SENSOR_INFO_SCOPE,
|
||||||
|
T_SENSOR_INFO_RANGE,
|
||||||
|
T_SENSOR_INFO_ENVELOPEBANDPASS,
|
||||||
|
T_SENSOR_INFO_FAULTFREQUENCY,
|
||||||
|
T_SENSOR_INFO_ZIGBEEPANID,
|
||||||
|
T_SENSOR_INFO_ZIGBEECHANNEL,
|
||||||
|
T_SENSOR_INFO_ZIGBEESHORTADDR,
|
||||||
|
T_SENSOR_INFO_ZIGBEELONGADDR,
|
||||||
|
T_SENSOR_INFO_ZIGBEEDESADDR,
|
||||||
|
T_SENSOR_INFO_STATUS,
|
||||||
|
T_SENSOR_INFO_TIMESTAMP,
|
||||||
|
T_SENSOR_INFO_VIFF,
|
||||||
|
T_SENSOR_INFO_RSSI
|
||||||
|
}T_SENSOR_INFO_Index;
|
||||||
|
const static char* T_SENSOR_INFO[] = { "t_sensor_info", "dataNodeNo", "dataNodeName", "initFlag", "accFlag","zigbeeFlag","temTopFlag","temBotFlag","equipSta","hardVersion", "softVersion","bpNo","serialNo","firstPowerTime","configFlag","startBrands","stopBrands","featureInterVal","waveInterVal","samplingRate","scope","range","envelopeBandPass","faultFrequency","zigbeePanId","zigbeeChannel","zigbeeShortAddr","zigbeeLongAddr","zigbeeDesAddr","status","timeStamp","viff","RSSI"};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
T_DATA_INFO_TNAME = 0,
|
||||||
|
T_DATA_INFO_DATANODENO,
|
||||||
|
T_DATA_INFO_CHANNELID,
|
||||||
|
T_DATA_INFO_DIAGNOSISEAK,
|
||||||
|
T_DATA_INFO_INTEGRATPK,
|
||||||
|
T_DATA_INFO_INTEGRATRMS,
|
||||||
|
T_DATA_INFO_RMSVALUES,
|
||||||
|
T_DATA_INFO_ENVELOPNERGY,
|
||||||
|
T_DATA_INFO_AMP1,
|
||||||
|
T_DATA_INFO_AMP2,
|
||||||
|
T_DATA_INFO_AMP3,
|
||||||
|
T_DATA_INFO_AMP4,
|
||||||
|
T_DATA_INFO_AMP5,
|
||||||
|
T_DATA_INFO_PHASE1,
|
||||||
|
T_DATA_INFO_PHASE2,
|
||||||
|
T_DATA_INFO_PHASE3,
|
||||||
|
T_DATA_INFO_PHASE4,
|
||||||
|
T_DATA_INFO_TIMESTAMP,
|
||||||
|
}T_DATA_INFO_Index;
|
||||||
|
const static char* T_DATA_INFO[] = { "t_data_info", "dataNodeNo", "channelID", "diagnosisPk", "integratPk","integratRMS","rmsValues","envelopEnergy","Amp1","Amp2","Amp3","Amp4","Amp5","Phase1","Phase2","Phase3","Phase4","timeStamp"};
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
T_DATASTATIC_INFO_TNAME = 0,
|
||||||
|
T_DATASTATIC_INFO_DATANODENO,
|
||||||
|
T_DATASTATIC_INFO_CHANNELID,
|
||||||
|
T_DATASTATIC_INFO_TEMTOP,
|
||||||
|
T_DATASTATIC_INFO_TEMBOT,
|
||||||
|
T_DATASTATIC_INFO_DIP,
|
||||||
|
T_DATASTATIC_INFO_VOLTAGE,
|
||||||
|
T_DATASTATIC_INFO_TIMESTAMP,
|
||||||
|
}T_DATASTATIC_INFO_Index;
|
||||||
|
const static char* T_DATASTATIC_INFO[] = { "t_datastatic_info","dataNodeNo","channelID","temTop","temBot","dip","voltage","timeStamp"};
|
||||||
|
|
||||||
|
#endif
|
||||||
1226
jsonparse/SH_JsonCmd.cpp
Normal file
1226
jsonparse/SH_JsonCmd.cpp
Normal file
File diff suppressed because it is too large
Load Diff
116
jsonparse/SH_JsonCmd.hpp
Normal file
116
jsonparse/SH_JsonCmd.hpp
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
#ifndef _JSONCMD_H_
|
||||||
|
#define _JSONCMD_H_
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
#include "../calculation/Calculation.hpp"
|
||||||
|
#include "../uart/SH_Uart.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
class JsonData {
|
||||||
|
public :
|
||||||
|
void DataNodeStatusCheck();
|
||||||
|
std::string JsonCmd_20(Param_20 ¶m);
|
||||||
|
// std::string JsonCmd_21(Param_21 ¶m);
|
||||||
|
std::string JsonCmd_22(Param_22 ¶m); //时区配置
|
||||||
|
std::string JsonCmd_23(Param_23 ¶m); //服务器配置
|
||||||
|
std::string JsonCmd_25(Param_25 ¶m);
|
||||||
|
std::string JsonCmd_26(Param_26 ¶m);
|
||||||
|
std::string JsonCmd_27(Json::Value & recvBody);
|
||||||
|
std::string JsonCmd_29(Param_29 ¶m); //系统配置信息
|
||||||
|
void JsonCmd_38(Json::Value &recvBody); //获取原始数据
|
||||||
|
void JsonCmd_39(Json::Value &recvBody); //更新传感器程序
|
||||||
|
|
||||||
|
// std::string JsonCmd_Cgi_error();
|
||||||
|
std::string JsonCmd_Cgi_01(Param_01 ¶m); //用户操作处理
|
||||||
|
std::string JsonCmd_Cgi_02(Param_02 ¶m); //时间校准接口
|
||||||
|
std::string JsonCmd_Cgi_07(); //获取系统内存温度硬盘等信息
|
||||||
|
std::string JsonCmd_Cgi_08(); //重启
|
||||||
|
std::string JsonCmd_Cgi_09(); //实时数据获取
|
||||||
|
std::string JsonCmd_Cgi_20(Param_20 ¶m); //终端信息获取
|
||||||
|
std::string JsonCmd_Cgi_22(Param_22 ¶m); //时区配置
|
||||||
|
std::string JsonCmd_Cgi_23(Param_23 ¶m); //服务器配置
|
||||||
|
std::string JsonCmd_Cgi_25(Param_25 ¶m); //网口配置
|
||||||
|
|
||||||
|
std::string JsonCmd_Cgi_26();
|
||||||
|
std::string JsonCmd_Cgi_27(Param_27 ¶m);
|
||||||
|
std::string JsonCmd_Cgi_28(Param_28 ¶m);
|
||||||
|
std::string JsonCmd_Cgi_29(Param_29 ¶m); //获取原始数据
|
||||||
|
std::string JsonCmd_Cgi_30(Param_30 ¶m); //获取频域数据
|
||||||
|
std::string JsonCmd_Cgi_31(Param_31 ¶m);//配置通信通道
|
||||||
|
std::string JsonCmd_Cgi_32(Param_32 ¶m); //
|
||||||
|
std::string JsonCmd_Cgi_43(); //检测网口状态
|
||||||
|
|
||||||
|
std::string JsonCmd_Cgi_45(Param_45 ¶m); //国家区域配置
|
||||||
|
std::string JsonCmd_Cgi_46(Param_46 ¶m); //升级固件
|
||||||
|
std::string JsonCmd_Cgi_47(Param_47 ¶m); //替换Logo
|
||||||
|
std::string JsonCmd_Cgi_default();
|
||||||
|
|
||||||
|
private :
|
||||||
|
Json::FastWriter showValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
//cmd "20"
|
||||||
|
static const char* JSON_FIELD_CMD = "cmd";//协议: 命令字段
|
||||||
|
static const char* JSON_FIELD_NAME = "dataNodeGatewayName";//协议: 终端名称
|
||||||
|
static const char* JSON_FIELD_dataNodeGatewayNo = "dataNodeGatewayNo";
|
||||||
|
static const char* JSON_FIELD_ASSETID = "dataNodeGatewayAssetId";//协议: 资产编号 字段
|
||||||
|
static const char* JSON_FIELD_ADDEDBY = "dataNodeGatewayAddedBy";//协议: 添加人 字段
|
||||||
|
static const char* JSON_FIELD_DEVICETYPE = "deviceType";
|
||||||
|
static const char* JSON_FIELD_ADDEDDATE = "dataNodeGatewayAddedDate";
|
||||||
|
static const char* JSON_FIELD_IPADDRESS = "dataNodeGatewayIpAddress";
|
||||||
|
static const char* JSON_FIELD_SN = "serialNumber";
|
||||||
|
static const char* JSON_FIELD_VERSION = "softVersion";
|
||||||
|
static const char* JSON_FIELD_TIMEZONE = "timezone";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//cmd "21"
|
||||||
|
// static const char* JSON_FIELD_CMD = "cmd";//协议: 命令字段
|
||||||
|
// static const char* JSON_FIELD_NAME = "dataWatchName";//协议: 终端名称
|
||||||
|
// static const char* JSON_FIELD_ASSETID = "dataWatchAssetId";//协议: 资产编号 字段
|
||||||
|
// static const char* JSON_FIELD_ASSETID = "dataWatchAddedBy";//协议: 添加人 字段
|
||||||
|
|
||||||
|
|
||||||
|
//cmd "23"
|
||||||
|
static const char* JSON_FIELD_SERVERIP = "localServerIpAddress";
|
||||||
|
static const char* JSON_FIELD_SERVERPORT = "localServerPort";
|
||||||
|
static const char* JSON_FIELD_CommMode = "CommMode";
|
||||||
|
static const char* JSON_FIELD_SERVERSECOND = "writingPeriodLocalServer";
|
||||||
|
|
||||||
|
//cmd "24"
|
||||||
|
static const char* JSON_FIELD_FILESERVERIP = "fileServerIpAddress";
|
||||||
|
static const char* JSON_FIELD_FILESERVERPORT = "fileServerPort";
|
||||||
|
|
||||||
|
|
||||||
|
//cmd "25"
|
||||||
|
|
||||||
|
// ps pl
|
||||||
|
// static const char* JSON_FIELD_FILESERVERIP = "fileServerIpAddress";
|
||||||
|
// static const char* JSON_FIELD_FILESERVERPORT = "ServerPort";
|
||||||
|
// static const char* JSON_FIELD_FILESERVERSECOND = "secondaryDataPath";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// static const char* JSON_FIELD_FILESERVERIP = "fileServerIpAddress";
|
||||||
|
// static const char* JSON_FIELD_FILESERVERPORT = "ServerPort";
|
||||||
|
// static const char* JSON_FIELD_FILESERVERSECOND = "secondaryDataPath";
|
||||||
|
|
||||||
|
|
||||||
|
//cmd "26"
|
||||||
|
static const char* JSON_FIELD_EMAILSERVERIP = "ServerIpAddress";
|
||||||
|
static const char* JSON_FIELD_PORT = "ServerPort";
|
||||||
|
static const char* JSON_FIELD_FILESERVERSECOND = "secondaryDataPath";
|
||||||
|
|
||||||
|
|
||||||
|
#define CMD_TYPE_20 20
|
||||||
|
#define CMD_TYPE_21 21
|
||||||
|
#define CMD_TYPE_22 22
|
||||||
|
|
||||||
|
#endif
|
||||||
417
localserver/SH_LocalServer.cpp
Normal file
417
localserver/SH_LocalServer.cpp
Normal file
@ -0,0 +1,417 @@
|
|||||||
|
#include "SH_LocalServer.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
PlatformInit *platform = PlatformInit::instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalServer::LocalServer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalServer::~LocalServer()
|
||||||
|
{
|
||||||
|
print_info("~LocalServer is called!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *topic)
|
||||||
|
{
|
||||||
|
if(pLen == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string data_r = (std::string)(pData_r);
|
||||||
|
print_brown("pData base : %s \n", data_r.c_str());
|
||||||
|
char *base64_data = new char[data_r.length()];
|
||||||
|
memset(base64_data, 0, data_r.length());
|
||||||
|
Secure::instance()->Base64Decode(data_r.c_str(), (unsigned char*)base64_data);
|
||||||
|
std::string pData = std::string(base64_data);
|
||||||
|
delete[] base64_data;
|
||||||
|
|
||||||
|
print_brown("pData : %s \n", pData.c_str());
|
||||||
|
Json::Reader recvReader;
|
||||||
|
Json::Value recvValue;
|
||||||
|
Json::Value recvBody;
|
||||||
|
if (recvReader.parse(pData, recvValue)) {
|
||||||
|
/* std::string cmdBody = recvValue["cmdBody"].asString();
|
||||||
|
if (!recvReader.parse(cmdBody, recvBody)) {
|
||||||
|
print_error("recv body error");
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
recvBody = recvValue["cmdBody"];
|
||||||
|
std::string str = recvBody["timestamp"].asString();
|
||||||
|
int cmdType = atoi(recvValue["cmd"].asString().c_str());
|
||||||
|
switch (cmdType) {
|
||||||
|
case 10:{
|
||||||
|
recvValue["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
|
recvValue["status"] = "ACK";
|
||||||
|
Json::FastWriter fw;
|
||||||
|
std::string strjson = fw.write(recvValue);
|
||||||
|
data_publish(strjson.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
system("echo 1 > /CIDW/start");
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
||||||
|
system("reboot");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 12:{
|
||||||
|
/* std::string strBody = recvValue["cmdBody"].asString();
|
||||||
|
Json::Value jsBody;
|
||||||
|
if (!recvReader.parse(strBody, jsBody)) {
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
std::string timestamp = recvBody["timestamp"].asString();
|
||||||
|
unsigned long itimestamp = boost::lexical_cast<unsigned long>(timestamp);
|
||||||
|
SetTime(itimestamp);
|
||||||
|
boost::this_thread::sleep(boost::posix_time::milliseconds(200));
|
||||||
|
system("hwclock -w");
|
||||||
|
if (!recvValue["ZoneId"].isNull() && recvValue["ZoneId"].asString().length() > 0) {
|
||||||
|
std::string zoneid = recvValue["ZoneId"].asString();
|
||||||
|
ZoneConfig(zoneid);
|
||||||
|
}
|
||||||
|
Json::Value retVal;
|
||||||
|
retVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
|
retVal["cmd"] = 12;
|
||||||
|
retVal["success"] = true;
|
||||||
|
retVal["message"] = "校时成功";
|
||||||
|
Json::FastWriter fw;
|
||||||
|
std::string strjson = fw.write(retVal);
|
||||||
|
data_publish(strjson.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 13:{
|
||||||
|
std::string type = recvValue["type"].asString();
|
||||||
|
if (type.compare("delete") == 0) {
|
||||||
|
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", "0.0.0.0");
|
||||||
|
GlobalConfig::ServerIP.clear();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 20:{
|
||||||
|
Param_20 param;
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mDataWatchName = recvBody["SystemInfo"]["dataNodeGatewayName"].asString();
|
||||||
|
param.mDataWatchAssetId = recvBody["SystemInfo"]["dataNodeGatewayAssetId"].asString();
|
||||||
|
param.mDataWatchAddedBy = recvBody["SystemInfo"]["dataNodeGatewayAddedBy"].asString();
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_20(param);
|
||||||
|
print_info("20 data: %s\n", data.c_str());
|
||||||
|
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 22:{
|
||||||
|
Param_22 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mTimeZone = recvBody["timezone"].asString();
|
||||||
|
ZoneConfig(param.mTimeZone);
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_22(param);
|
||||||
|
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 23:{
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
Param_23 param;
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mServerIp = recvBody["localServerIpAddress"].asString();
|
||||||
|
param.mPort = boost::lexical_cast<std::string>(recvBody["localServerPort"].asInt());
|
||||||
|
param.mCommMode = boost::lexical_cast<std::string>(recvBody["CommMode"].asInt());
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_23(param);
|
||||||
|
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 25:{
|
||||||
|
Param_25 param;
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mDnsName = recvBody["dnsName"].asString();
|
||||||
|
param.mGateway = recvBody["gateway"].asString();
|
||||||
|
param.mHostName = recvBody["hostName"].asString();
|
||||||
|
param.mIp = recvBody["dataWatchIpAddress"].asString();
|
||||||
|
param.mSubnetMask = recvBody["subnetMask"].asString();
|
||||||
|
param.mNetworkPortStatus = recvBody["networkPortStatus"].asString();
|
||||||
|
param.mMode = 0;
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_25(param);
|
||||||
|
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
// platform->EquipIpInit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 26:{
|
||||||
|
Param_26 param;
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if (0 == type.compare("GET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_26(param);
|
||||||
|
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
// platform->EquipIpInit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 27:{
|
||||||
|
Param_27 param;
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_27(recvBody);
|
||||||
|
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// data_publish_local(pData.c_str(), GlobalConfig::Topic_G.mPubLocalCmd.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
print_brown("cmdType : %d \n", cmdType);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
print_error("parase fail \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string LocalServer::HandleCgi_cmd(std::string &pData)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
print_purple("HandleCgi Data = %s \n", pData.c_str());
|
||||||
|
Json::Features f = Json::Features::strictMode();
|
||||||
|
Json::Reader recvReader(f);
|
||||||
|
Json::Value recvValue;
|
||||||
|
Json::Value recvBody;
|
||||||
|
if (recvReader.parse(pData, recvValue)){
|
||||||
|
int cmdType = atoi(recvValue["cmd"].asString().c_str());
|
||||||
|
std::string cmdBody = "";
|
||||||
|
if (!recvValue["cmdBody"].isNull() ) {
|
||||||
|
recvBody = recvValue["cmdBody"];
|
||||||
|
Json::FastWriter fw;
|
||||||
|
cmdBody = fw.write(recvBody);
|
||||||
|
}
|
||||||
|
switch (cmdType) {
|
||||||
|
case 1:{
|
||||||
|
Param_01 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if ( 0 == type.compare("login")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mUserName = recvBody["userName"].asString();
|
||||||
|
param.mPassWord = recvBody["passWord"].asString();
|
||||||
|
} else if ( 0 == type.compare("upDate")) {
|
||||||
|
param.mMode = 1;
|
||||||
|
param.mUserName = recvBody["userName"].asString();
|
||||||
|
param.mPassWord = recvBody["passWord"].asString();
|
||||||
|
param.mPassWordNew = recvBody["passWordNew"].asString();
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_01(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:{
|
||||||
|
Param_02 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if ( 0 == type.compare("SET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mTimeStamp = recvBody["timeStamp"].asInt();
|
||||||
|
} else if (0 == type.compare("GET")) {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_02(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 7:{
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_07();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 8:{
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_08();
|
||||||
|
system("reboot");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 9:{
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_09();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 20:{
|
||||||
|
Param_20 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mDataWatchName = recvBody["SystemInfo"]["dataNodeGatewayName"].asString();
|
||||||
|
param.mDataWatchAssetId = recvBody["SystemInfo"]["dataNodeGatewayAssetId"].asString();
|
||||||
|
param.mDataWatchAddedBy = recvBody["SystemInfo"]["dataNodeGatewayAddedBy"].asString();
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_20(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 22:{
|
||||||
|
Param_22 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mTimeZone = recvBody["SystemSettings"]["timezone"].asString();
|
||||||
|
ZoneConfig(param.mTimeZone);
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_22(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 23:{
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
Param_23 param;
|
||||||
|
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mServerIp = recvBody["SystemSettings"]["ServerIpAddress"].asString();
|
||||||
|
param.mPort = boost::lexical_cast<std::string>(recvBody["SystemSettings"]["ServerPort"].asInt());
|
||||||
|
param.mCommMode = boost::lexical_cast<std::string>(recvBody["SystemSettings"]["CommMode"].asInt());
|
||||||
|
} else {
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_23(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 25:{
|
||||||
|
Param_25 param;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if (0 == type.compare("SET")) {
|
||||||
|
param.mDnsName = recvBody["dnsName"].asString();
|
||||||
|
param.mGateway = recvBody["gateway"].asString();
|
||||||
|
param.mHostName = recvBody["hostName"].asString();
|
||||||
|
param.mIp = recvBody["dataWatchIpAddress"].asString();
|
||||||
|
param.mSubnetMask = recvBody["subnetMask"].asString();
|
||||||
|
param.mNetworkPortStatus = recvBody["networkPortStatus"].asString();
|
||||||
|
param.mMode = 0;
|
||||||
|
}else{
|
||||||
|
param.mMode = 1;
|
||||||
|
}
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_25(param);
|
||||||
|
//platform->EquipIpInit();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 26:{
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_26();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 27:{
|
||||||
|
Param_27 param;
|
||||||
|
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_27(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 28:{
|
||||||
|
Param_28 param;
|
||||||
|
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||||
|
param.mDataNodeName = recvBody["dataNodeName"].asString();
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_28(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 29:{
|
||||||
|
JsonData jd;
|
||||||
|
Param_29 param;
|
||||||
|
param.mChannelId = recvBody["channelId"].asString();
|
||||||
|
param.mPackageFlag = recvBody["package"].asInt();
|
||||||
|
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||||
|
std::string data = jd.JsonCmd_Cgi_29(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 30:{
|
||||||
|
JsonData jd;
|
||||||
|
Param_30 param;
|
||||||
|
param.mChannelId = recvBody["channelId"].asString();
|
||||||
|
param.mPackageFlag = recvBody["package"].asInt();
|
||||||
|
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||||
|
std::string data = jd.JsonCmd_Cgi_30(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 31:{
|
||||||
|
JsonData jd;
|
||||||
|
Param_31 param;
|
||||||
|
std::string data;
|
||||||
|
std::string type = recvBody["type"].asString();
|
||||||
|
if(0 == type.compare("SET"))
|
||||||
|
{
|
||||||
|
param.mMode = 0;
|
||||||
|
param.mChannelId = recvBody["channel"].asString();
|
||||||
|
//param.mChannelId = recvBody["channel"].asInt();
|
||||||
|
data = jd.JsonCmd_Cgi_31(param);
|
||||||
|
sleep(1);
|
||||||
|
system("reboot");
|
||||||
|
|
||||||
|
}else{
|
||||||
|
param.mMode = 1;
|
||||||
|
data = jd.JsonCmd_Cgi_31(param);
|
||||||
|
}
|
||||||
|
// std::string data = jd.JsonCmd_Cgi_31(param);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
JsonData jd;
|
||||||
|
std::string data = jd.JsonCmd_Cgi_default();
|
||||||
|
return data;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(...){
|
||||||
|
Json::Value jsVal;
|
||||||
|
jsVal["success"] = false;
|
||||||
|
jsVal["message"] = "未知错误";
|
||||||
|
Json::FastWriter fw;
|
||||||
|
return fw.write(jsVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
30
localserver/SH_LocalServer.hpp
Normal file
30
localserver/SH_LocalServer.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef _LOCALSERVER_H_
|
||||||
|
#define _LOCALSERVER_H_
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include <boost/unordered_set.hpp>
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../platform/SH_PlatformInit.hpp"
|
||||||
|
#include "../secure/SH_Secure.hpp"
|
||||||
|
#include "../jsonparse/SH_JsonCmd.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
class LocalServer : public MySingleton<LocalServer>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
boost::mutex mMutex;
|
||||||
|
// _Event mWaveEvent;
|
||||||
|
std::vector<std::string> m_VecFileName;
|
||||||
|
public:
|
||||||
|
LocalServer();
|
||||||
|
virtual ~LocalServer();
|
||||||
|
void HandleFromServer(const char *pData, int pLen, const char *topic);
|
||||||
|
std::string HandleCgi_cmd(std::string &pData);
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif
|
||||||
97
main.cpp
Normal file
97
main.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#include <signal.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
#include "platform/SH_PlatformInit.hpp"
|
||||||
|
#include "common/SH_CommonFunc.hpp"
|
||||||
|
#include "API_log/SH_log.h"
|
||||||
|
#include "common/SH_global.h"
|
||||||
|
#include "threadfunc/SH_ThreadFunc.hpp"
|
||||||
|
#include "secure/SH_Secure.hpp"
|
||||||
|
#include "aes/aes.h"
|
||||||
|
#include "dbaccess/SH_SqlDB.hpp"
|
||||||
|
#include "uart/SH_Uart.hpp"
|
||||||
|
|
||||||
|
namespace{
|
||||||
|
PlatformInit *platform = PlatformInit::instance();
|
||||||
|
Uart *pUart = Uart::instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
// 初始化日志记录,日志缓存区,记录数,未使用,后期,命令启动
|
||||||
|
log_init(SOFTWARE_RUN_LOG, 1380, 160 * 1024);
|
||||||
|
LOG_INFO("####CIDNSOFT start####\n");
|
||||||
|
|
||||||
|
// 查看版本信息
|
||||||
|
if (CheckFileVersion(argc, argv)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置线程属性之栈空间大小
|
||||||
|
boost::thread::attributes attrs;
|
||||||
|
attrs.set_stack_size(1024*1024*2);
|
||||||
|
|
||||||
|
// 初始化平台配置文件
|
||||||
|
platform->PlatFormInit();
|
||||||
|
|
||||||
|
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||||
|
boost::thread searchT(attrs,SearchThread);
|
||||||
|
searchT.detach();
|
||||||
|
|
||||||
|
// 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
||||||
|
boost::thread uartReadTh(UartStart);
|
||||||
|
uartReadTh.detach();
|
||||||
|
|
||||||
|
// 休眠2秒,等待串口线程初始化完毕
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(2));
|
||||||
|
|
||||||
|
// 串口数据处理,读取传感器原始波形数据
|
||||||
|
boost::thread uartWaveReadTh(UartStartWave);
|
||||||
|
uartWaveReadTh.detach();
|
||||||
|
|
||||||
|
//启动 mqtt客户端
|
||||||
|
boost::thread startMqtt(StartMqttClient);
|
||||||
|
startMqtt.detach();
|
||||||
|
|
||||||
|
//启动 mqtt 心跳
|
||||||
|
boost::thread startHeart(HeartRep);
|
||||||
|
startHeart.detach();
|
||||||
|
|
||||||
|
// 通过UDP接收数据
|
||||||
|
boost::thread StartConnectSys(attrs, StartUdpSys);
|
||||||
|
StartConnectSys.detach();
|
||||||
|
|
||||||
|
//循环检测线程
|
||||||
|
boost::thread normalCheckThread(attrs,CheckThread);
|
||||||
|
normalCheckThread.detach();
|
||||||
|
|
||||||
|
//启动软件升级线程
|
||||||
|
boost::thread StartDownloadThread(attrs, RecvUpdateFile);
|
||||||
|
StartDownloadThread.detach();
|
||||||
|
|
||||||
|
//启动cgi server
|
||||||
|
boost::thread startTcpCgi(attrs,StartCgiServer);
|
||||||
|
startTcpCgi.detach();
|
||||||
|
|
||||||
|
//pUart->UpdateZigbeeInfoCtrl();
|
||||||
|
pUart->ZigbeeInit();
|
||||||
|
pUart->UpdateZigbeeInfoCtrl();
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(5));
|
||||||
|
|
||||||
|
while (GlobalConfig::QuitFlag_G) {
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(20));
|
||||||
|
// data_publish(senddata.c_str(), GlobalConfig::Topic_G.mPubData.c_str());
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
347
mqttclient/SH_MqttClient.cpp
Normal file
347
mqttclient/SH_MqttClient.cpp
Normal file
@ -0,0 +1,347 @@
|
|||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include "SH_MqttClient.h"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../secure/SH_Secure.hpp"
|
||||||
|
|
||||||
|
static char res_topic[100];
|
||||||
|
static char req_topic[100];
|
||||||
|
struct mosquitto *mosq = NULL;
|
||||||
|
static int mid_sent = 0;
|
||||||
|
struct userdata ud;
|
||||||
|
connect_callback my_connect_callback = NULL;
|
||||||
|
disconnect_callback my_disconnect_callback = NULL;
|
||||||
|
message_callback my_message_callback = NULL;
|
||||||
|
subscribe_callback my_subscribe_callback = NULL;
|
||||||
|
log_callback my_log_callback = NULL;
|
||||||
|
publish_callback my_publish_callback = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
void register_collback(connect_callback connect_c,
|
||||||
|
message_callback message_c,
|
||||||
|
subscribe_callback subscribe_c,
|
||||||
|
log_callback log_c,
|
||||||
|
disconnect_callback disconnect_c,
|
||||||
|
publish_callback publish_c)
|
||||||
|
{
|
||||||
|
my_connect_callback = connect_c;
|
||||||
|
my_message_callback = message_c;
|
||||||
|
my_subscribe_callback = subscribe_c;
|
||||||
|
my_log_callback = log_c;
|
||||||
|
my_disconnect_callback = disconnect_c;
|
||||||
|
my_publish_callback = publish_c;
|
||||||
|
}
|
||||||
|
|
||||||
|
int data_publish(const char *str, const char *topic)
|
||||||
|
{
|
||||||
|
int iRet = -1;
|
||||||
|
if(mosq != NULL){
|
||||||
|
print_blue("data_publish: %s %s\n", str, topic);
|
||||||
|
std::string strTopic = std::string(topic);
|
||||||
|
if (strTopic.find("cmd") != std::string::npos) {
|
||||||
|
std::string pData = (std::string)str;
|
||||||
|
char *base64_aes = new char[pData.length() * 2];
|
||||||
|
memset(base64_aes, 0, pData.length() * 2);
|
||||||
|
Secure::instance()->Base64Encode((unsigned char*)pData.c_str(), base64_aes, pData.length());
|
||||||
|
iRet = mosquitto_publish(mosq, &mid_sent, topic, strlen(base64_aes), base64_aes, ud.topic_qos, false);
|
||||||
|
print_blue("data_publish: %s \n",base64_aes);
|
||||||
|
// free(out);
|
||||||
|
} else {
|
||||||
|
iRet = mosquitto_publish(mosq, &mid_sent, topic, strlen(str), str, ud.topic_qos, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int data_publish_wave(WAVE_CONTAIN *str, const char *topic)
|
||||||
|
{
|
||||||
|
int iRet = -1;
|
||||||
|
if(mosq != NULL){
|
||||||
|
print_blue("data_publish:Unit : %s type:%d flag : %d channelid : %s total : %d count : %d number :%d floats:%f floate:%f\n",str->SensorEngineeringUnit, str->type, str->flag, str->channelId, str->total, str->count,str->number,str->waveData[0],str->waveData[(str->number-2)]);
|
||||||
|
iRet = mosquitto_publish(mosq, &mid_sent, topic, sizeof(WAVE_CONTAIN), str, ud.topic_qos, false);
|
||||||
|
}
|
||||||
|
return iRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
int subscribe(const char* topic, int qos)
|
||||||
|
{
|
||||||
|
int iret = mosquitto_subscribe(mosq, NULL, topic, qos);
|
||||||
|
return iret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int unsubscribe(const char* topic)
|
||||||
|
{
|
||||||
|
int iret = mosquitto_unsubscribe(mosq, NULL, topic);
|
||||||
|
return iret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int disconnect()
|
||||||
|
{
|
||||||
|
return mosquitto_disconnect(mosq);
|
||||||
|
}
|
||||||
|
|
||||||
|
int start_client(const char *boardname, const char *gwid, const char* gwip, const char *gwver, const char *gwcode, std::string &salt)
|
||||||
|
{
|
||||||
|
char *id = NULL;
|
||||||
|
char *id_prefix = NULL;
|
||||||
|
char *host;
|
||||||
|
int port = 51613;
|
||||||
|
char *bind_address = NULL;
|
||||||
|
int keepalive = 60;
|
||||||
|
bool clean_session = true;
|
||||||
|
bool debug = true;
|
||||||
|
int rc = 0;
|
||||||
|
char hostname[256];
|
||||||
|
char err[1024];
|
||||||
|
int len;
|
||||||
|
char will_payload[100];
|
||||||
|
long will_payloadlen = 0;
|
||||||
|
int will_qos = 0;
|
||||||
|
bool will_retain = false;
|
||||||
|
char *will_topic = NULL;
|
||||||
|
bool insecure = false;
|
||||||
|
char *tls_version = NULL;
|
||||||
|
char *psk = NULL;
|
||||||
|
char *psk_identity = NULL;
|
||||||
|
char *ciphers = NULL;
|
||||||
|
bool use_srv = false;
|
||||||
|
mqttsdata_t mqttsdata;
|
||||||
|
signal(SIGCHLD, SIG_IGN);//signal函数作用:为一个信号注册一个信号处理函数。其中SIGCHLD:在一个进程终止或者停止时,将SIGCHLD信号发送给父进程。而信号处理函数是一个函数指针,不过它使用的是预定义函数SIG_IGN(忽视信号)
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
int reconnect = 0;
|
||||||
|
if (my_connect_callback == NULL || my_message_callback == NULL || my_subscribe_callback == NULL || my_log_callback == NULL) {
|
||||||
|
printf("please call the register_collback function first.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mosquitto_lib_init();//使用mosquitto库函数前需进行初始化
|
||||||
|
memset(&mqttsdata, 0, sizeof(mqttsdata_t));
|
||||||
|
memcpy(mqttsdata.gwid, gwid, strlen(gwid));
|
||||||
|
|
||||||
|
// mqttsdata.username = "admin";
|
||||||
|
// mqttsdata.password = "password";
|
||||||
|
salt = std::string(mqttsdata.salt);
|
||||||
|
memset(&ud, 0, sizeof(struct userdata));
|
||||||
|
ud.eol = true;
|
||||||
|
char localip[100];
|
||||||
|
sprintf(localip, "%s", gwip);
|
||||||
|
host = localip;
|
||||||
|
mqttsdata.port = GlobalConfig::ServerPort;
|
||||||
|
port = GlobalConfig::ServerPort;
|
||||||
|
|
||||||
|
// std::string username = "root";
|
||||||
|
// std::string password = "xom!*283#@XHG";
|
||||||
|
|
||||||
|
std::string username = "chaos";
|
||||||
|
std::string password = "HSD272*#xkd";
|
||||||
|
|
||||||
|
char userName[100];
|
||||||
|
sprintf(userName, "%s", username.c_str());
|
||||||
|
|
||||||
|
char passWord[100];
|
||||||
|
sprintf(passWord, "%s", password.c_str());
|
||||||
|
|
||||||
|
ud.username = userName;
|
||||||
|
ud.password = passWord;
|
||||||
|
|
||||||
|
ud.gwid = mqttsdata.gwid;
|
||||||
|
ud.dataUrl = mqttsdata.dataUrl;
|
||||||
|
ud.fsUrl = mqttsdata.fsUrl;
|
||||||
|
will_qos = mqttsdata.qos;
|
||||||
|
ud.topic_count++;
|
||||||
|
ud.topics = (char**)realloc(ud.topics, ud.topic_count*sizeof(char *));
|
||||||
|
if (ud.topics == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(req_topic, 0, 100);
|
||||||
|
sprintf(req_topic, "dev/cidwcc");
|
||||||
|
ud.topics[ud.topic_count - 1] = req_topic;
|
||||||
|
ud.verbose = 1;
|
||||||
|
fprintf(stderr, "topic = %s!!!!!!!!!!!\n", ud.topics[ud.topic_count - 1]);
|
||||||
|
memset(res_topic, 0, 100);
|
||||||
|
sprintf(res_topic, "gw/will");
|
||||||
|
printf("res_topic:%s\n", res_topic);
|
||||||
|
will_topic = res_topic;
|
||||||
|
ud.resp_topic = res_topic;
|
||||||
|
sprintf(will_payload, "{\"cmd\":\"15\",\"gwID\":\"%s\"}", mqttsdata.gwid);
|
||||||
|
will_payloadlen = strlen(will_payload);
|
||||||
|
printf("will_payload:%s,will_payloadlen:%ld\n", will_payload, will_payloadlen);
|
||||||
|
if (clean_session == false && (id_prefix || !id)){
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ud.topic_count == 0){
|
||||||
|
fprintf(stderr, "Error: You must specify a topic to subscribe to.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (will_payload && !will_topic){
|
||||||
|
fprintf(stderr, "Error: Will payload given, but no will topic given.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (will_retain && !will_topic){
|
||||||
|
fprintf(stderr, "Error: Will retain given, but no will topic given.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (ud.password && !ud.username){
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Warning: Not using password since username not set.\n");
|
||||||
|
}
|
||||||
|
if (psk && !psk_identity){
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: --psk-identity required if --psk used.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (id_prefix){
|
||||||
|
id = (char*)malloc(strlen(id_prefix) + 10);
|
||||||
|
if (!id){
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: Out of memory.\n");
|
||||||
|
mosquitto_lib_cleanup();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
snprintf(id, strlen(id_prefix) + 10, "%s%d", id_prefix, getpid());
|
||||||
|
} else if (!id){
|
||||||
|
hostname[0] = '\0';
|
||||||
|
gethostname(hostname, 256);
|
||||||
|
hostname[255] = '\0';
|
||||||
|
len = strlen("mosqsub/-") + 6 + strlen(hostname);
|
||||||
|
id = (char*)malloc(len);
|
||||||
|
if (!id){
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: Out of memory.\n");
|
||||||
|
mosquitto_lib_cleanup();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
snprintf(id, len, "mosqsub/%d-%s", getpid(), hostname);
|
||||||
|
if (strlen(id) > MOSQ_MQTT_ID_MAX_LENGTH){
|
||||||
|
/* Enforce maximum client id length of 23 characters */
|
||||||
|
id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("id:%s\n", id);
|
||||||
|
mosq = mosquitto_new(id, clean_session, &ud);
|
||||||
|
if (!mosq){
|
||||||
|
switch (errno){
|
||||||
|
case ENOMEM:
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: Out of memory.\n");
|
||||||
|
break;
|
||||||
|
case EINVAL:
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: Invalid id and/or clean_session .\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mosquitto_lib_cleanup();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (debug){
|
||||||
|
mosquitto_log_callback_set(mosq, my_log_callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!psk) {
|
||||||
|
psk = (char *)malloc(32 * sizeof(char));
|
||||||
|
if (!psk) {
|
||||||
|
fprintf(stderr, "Error: No free space %d\n", __LINE__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(psk, 0, 32);
|
||||||
|
snprintf(psk, 32, "%ld", getpid());
|
||||||
|
psk_identity = (char *)malloc(32 * sizeof(char));
|
||||||
|
if (!psk_identity) {
|
||||||
|
fprintf(stderr, "Error: No free space %d\n", __LINE__);
|
||||||
|
free(psk);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
strncpy(psk_identity, psk, 32);
|
||||||
|
}
|
||||||
|
if (will_topic && mosquitto_will_set(mosq, will_topic, will_payloadlen, will_payload, will_qos, will_retain)) {
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: Problem setting will.\n");
|
||||||
|
mosquitto_lib_cleanup();
|
||||||
|
free(psk);
|
||||||
|
free(psk_identity);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ud.username && mosquitto_username_pw_set(mosq, ud.username, ud.password)) {
|
||||||
|
if (!ud.quiet) fprintf(stderr, "Error: Problem setting username and password.\n");
|
||||||
|
mosquitto_lib_cleanup();
|
||||||
|
free(psk);
|
||||||
|
free(psk_identity);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (insecure && mosquitto_tls_insecure_set(mosq, false)){
|
||||||
|
// if (!ud.quiet) fprintf(stderr, "Error: Problem setting TLS insecure option.\n");
|
||||||
|
// mosquitto_lib_cleanup();
|
||||||
|
// free(psk);
|
||||||
|
// free(psk_identity);
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (psk && mosquitto_tls_psk_set(mosq, psk, psk_identity, NULL)){
|
||||||
|
// if (!ud.quiet) fprintf(stderr, "Error: Problem setting TLS-PSK options.\n");
|
||||||
|
// mosquitto_lib_cleanup();
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (tls_version && mosquitto_tls_opts_set(mosq, 0, tls_version, ciphers)){
|
||||||
|
// if (!ud.quiet) fprintf(stderr, "Error: Problem setting TLS options.\n");
|
||||||
|
// mosquitto_lib_cleanup();
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
mosquitto_connect_callback_set(mosq, my_connect_callback);
|
||||||
|
mosquitto_disconnect_callback_set(mosq, my_disconnect_callback);
|
||||||
|
mosquitto_message_callback_set(mosq, my_message_callback);
|
||||||
|
mosquitto_publish_callback_set(mosq, my_publish_callback);
|
||||||
|
|
||||||
|
if (debug){
|
||||||
|
mosquitto_subscribe_callback_set(mosq, my_subscribe_callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (use_srv){
|
||||||
|
rc = mosquitto_connect_srv(mosq, host, keepalive, bind_address);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rc = mosquitto_connect_bind(mosq, host, port, keepalive, bind_address);
|
||||||
|
}
|
||||||
|
if (rc){
|
||||||
|
if (!ud.quiet){
|
||||||
|
if (rc == MOSQ_ERR_ERRNO){
|
||||||
|
strerror_r(errno, err, 1024);
|
||||||
|
fprintf(stderr, "Error_: %s\n", err);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
fprintf(stderr, "Unable to connect (%d).\n", rc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto mosq_free;
|
||||||
|
}
|
||||||
|
rc = mosquitto_loop_forever(mosq, -1, 1);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error: %s\n", mosquitto_strerror(rc));
|
||||||
|
}
|
||||||
|
mosq_free:
|
||||||
|
mosquitto_destroy(mosq);
|
||||||
|
mosquitto_lib_cleanup();
|
||||||
|
free(ud.topics);
|
||||||
|
free(id);
|
||||||
|
free(psk);
|
||||||
|
free(psk_identity);
|
||||||
|
ud.topics = NULL;
|
||||||
|
id = NULL;
|
||||||
|
mosq = NULL;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
70
mqttclient/SH_MqttClient.h
Normal file
70
mqttclient/SH_MqttClient.h
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#ifndef MQTTCLIENT_H
|
||||||
|
#define MQTTCLIENT_H
|
||||||
|
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include "mosquitto.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct userdata {
|
||||||
|
char **topics;
|
||||||
|
int topic_count;
|
||||||
|
int topic_qos;
|
||||||
|
char **filter_outs;
|
||||||
|
int filter_out_count;
|
||||||
|
char *username;
|
||||||
|
char *password;
|
||||||
|
char *resp_topic;
|
||||||
|
char *gwid;
|
||||||
|
char *dataUrl;
|
||||||
|
char *fsUrl;
|
||||||
|
int verbose;
|
||||||
|
bool quiet;
|
||||||
|
bool no_retain;
|
||||||
|
bool eol;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct mqttsinfo
|
||||||
|
{
|
||||||
|
char domain[100];
|
||||||
|
char devicekey[36];
|
||||||
|
char gwid[21];
|
||||||
|
int port;
|
||||||
|
char username[100];
|
||||||
|
char password[100];
|
||||||
|
char dataUrl[100];
|
||||||
|
char fsUrl[100];
|
||||||
|
char salt[100];
|
||||||
|
int ssl;
|
||||||
|
int qos;
|
||||||
|
int encrypt;
|
||||||
|
}mqttsdata_t;
|
||||||
|
|
||||||
|
extern struct userdata ud;
|
||||||
|
typedef void(*connect_callback)(struct mosquitto *mosq, void *obj, int result);
|
||||||
|
typedef void(*disconnect_callback)(struct mosquitto *mosq, void *obj, int result);
|
||||||
|
typedef void(*message_callback)(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message);
|
||||||
|
typedef void(*subscribe_callback)(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos);
|
||||||
|
typedef void(*log_callback)(struct mosquitto *mosq, void *obj, int level, const char *str);
|
||||||
|
typedef void(*publish_callback)(struct mosquitto *mosq, void *obj, int mid);
|
||||||
|
|
||||||
|
|
||||||
|
//mqtt注册
|
||||||
|
extern void register_collback(connect_callback connect_c,
|
||||||
|
message_callback message_c,
|
||||||
|
subscribe_callback subscribe_c,
|
||||||
|
log_callback log_c,
|
||||||
|
disconnect_callback disconnect_c,
|
||||||
|
publish_callback publish_c);
|
||||||
|
extern int data_publish(const char *str, const char* topic);
|
||||||
|
extern int data_publish_wave(WAVE_CONTAIN *str, const char *topic);
|
||||||
|
extern int disconnect();
|
||||||
|
extern int subscribe(const char* topic, int qos);
|
||||||
|
extern int unsubscribe(const char* topic);
|
||||||
|
extern int start_client(const char *boardname, const char *gwid, const char* gwip, const char *gwver, const char *gwcode, std::string &salt);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
1536
mqttclient/mosquitto.h
Normal file
1536
mqttclient/mosquitto.h
Normal file
File diff suppressed because it is too large
Load Diff
250
platform/SH_PlatformInit.cpp
Normal file
250
platform/SH_PlatformInit.cpp
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include "SH_PlatformInit.hpp"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../dbaccess/SH_SqlDB.hpp"
|
||||||
|
#include "../API_log/SH_log.h"
|
||||||
|
|
||||||
|
/*********************全局变量声明***********************/
|
||||||
|
int GlobalConfig::RUN_MODE = 0;
|
||||||
|
int GlobalConfig::QuitFlag_G = 1;
|
||||||
|
int GlobalConfig::LinkStatus_G = 0;
|
||||||
|
int GlobalConfig::LinkCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::string GlobalConfig::Version = "2.0.11";
|
||||||
|
std::string GlobalConfig::MacAddr_G = "";
|
||||||
|
std::string GlobalConfig::IpAddr_G = "";
|
||||||
|
std::string GlobalConfig::ServerIP = "";
|
||||||
|
int GlobalConfig::ServerPort = 0;
|
||||||
|
|
||||||
|
|
||||||
|
TopicList GlobalConfig::Topic_G;
|
||||||
|
ZigbeeInfo GlobalConfig::ZigbeeInfo_G;
|
||||||
|
ZIGBEE GlobalConfig::Zigbee_G;
|
||||||
|
std::string GlobalConfig::DbName_G = "/opt/configenv/cidn.db"; //数据库名称
|
||||||
|
std::string GlobalConfig::UartName_G = "/dev/ttymxc4";
|
||||||
|
|
||||||
|
// 处理ZigBee网络接收过程的PanID切换
|
||||||
|
enumZigBeeTransmitStatus GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||||
|
int GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||||
|
|
||||||
|
PlatformInit::PlatformInit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PlatformInit::~PlatformInit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformInit::PlatFormInit()
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
GlobalConfig::MacAddr_G = GetLocalMac();
|
||||||
|
transform(GlobalConfig::MacAddr_G.begin(), GlobalConfig::MacAddr_G.end(), GlobalConfig::MacAddr_G.begin(), ::toupper);
|
||||||
|
GlobalConfig::IpAddr_G = IpAddrInit();
|
||||||
|
print_info("GlobalConfig::IpAddr_G : %s\n", GlobalConfig::IpAddr_G.c_str());
|
||||||
|
this->ConfigFileCheck();
|
||||||
|
this->TopicInit();
|
||||||
|
this->ServerIpInit();
|
||||||
|
this->Sqlite3Init();
|
||||||
|
|
||||||
|
print_info("ServerIP : %s \n", GlobalConfig::ServerIP.c_str());
|
||||||
|
// sleep(10);
|
||||||
|
} catch(...){
|
||||||
|
print_error("PlatFormInit exception happend.\n");
|
||||||
|
std::string errorinfo = "系统初始化异常";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformInit::TopicInit()
|
||||||
|
{
|
||||||
|
GlobalConfig::Topic_G.mPubData = "wireless/statisticData/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubStatus = "wireless/status/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubHeart = "wireless/heart/" + GlobalConfig::MacAddr_G;//
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubConfig = "wireless/configureInfor/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubWaveData = "wireless/realTimeData/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubWaveSecondData = "wireless/secondTimeData/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubCmd = "wireless/cmd/" + GlobalConfig::MacAddr_G;//
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mSubData = "cmd/" + GlobalConfig::MacAddr_G;//
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubRep = "wireless/resp/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi";
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubLocalWaveServer = "up/" + GlobalConfig::MacAddr_G + "/recive/waveserver";
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubLocalWaveQt = "up/" + GlobalConfig::MacAddr_G + "/recive/waveqt";
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubLocalConfig = "up/" + GlobalConfig::MacAddr_G + "/recive/config";
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubLocalTrigger = "up/" + GlobalConfig::MacAddr_G + "/recive/trigger";
|
||||||
|
|
||||||
|
GlobalConfig::Topic_G.mPubLocalCmd= "up/" + GlobalConfig::MacAddr_G + "/recive/cmd";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PlatformInit::ConfigFileCheck()
|
||||||
|
{
|
||||||
|
if (access(SYSTEMINFOFILE, 0) < 0) {
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayName", "");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAssetId", "");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", "");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate", "");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "timezone", "UTC+8");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayNo", GlobalConfig::MacAddr_G);
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "Area", "countryId", "");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "Area", "provincesId", "");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "Area", "cityListId", "");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "Uint", "uint", "ST");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access(NETWORKCONFIG, 0) < 0) {
|
||||||
|
WriteStr2Config(NETWORKCONFIG, "Net", "dnsName", " ");
|
||||||
|
WriteStr2Config(NETWORKCONFIG, "Net", "networkPortStatus", "DHCP");
|
||||||
|
WriteStr2Config(NETWORKCONFIG, "Net", "gateway", "0.0.0.0");
|
||||||
|
WriteStr2Config(NETWORKCONFIG, "Net", "subnetMask", "0.0.0.0");
|
||||||
|
WriteStr2Config(NETWORKCONFIG, "Net", "ipAddress", "0.0.0.0");
|
||||||
|
WriteStr2Config(NETWORKCONFIG, "Net", "hostName", "0.0.0.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access(SERVERCONFIG, 0) < 0) {
|
||||||
|
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", "0.0.0.0");
|
||||||
|
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", "51613");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int PlatformInit::ServerIpInit()
|
||||||
|
{
|
||||||
|
if (access(SERVERCONFIG, 0) >= 0) {
|
||||||
|
GlobalConfig::ServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||||
|
GlobalConfig::ServerPort = boost::lexical_cast<int>(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformInit::Sqlite3Init()
|
||||||
|
{
|
||||||
|
sql_ctl->OpenDB(GlobalConfig::DbName_G.c_str());
|
||||||
|
sql_ctl->SqliteInit(GlobalConfig::DbName_G.c_str());
|
||||||
|
print_info("Sqlite3Init \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformInit::SystemInfoInit()
|
||||||
|
{
|
||||||
|
std::ifstream ifileOut(SYSTEMINFOFILE);
|
||||||
|
Json::Reader recvReader;
|
||||||
|
Json::Value Systeminfo;
|
||||||
|
//从配置文件中读取json数据
|
||||||
|
if (ifileOut.is_open()) {
|
||||||
|
print_blue("open %s\n", SYSTEMINFOFILE);
|
||||||
|
}
|
||||||
|
if (!recvReader.parse(ifileOut, Systeminfo, false)) {
|
||||||
|
if (ifileOut.is_open()) {
|
||||||
|
ifileOut.close();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ifileOut.close();
|
||||||
|
|
||||||
|
Systeminfo["dataWatchIpAddress"] = GlobalConfig::IpAddr_G;
|
||||||
|
Systeminfo["softVersion"] = GlobalConfig::Version;
|
||||||
|
|
||||||
|
std::string strSerialNumber = GetFileContent(SN, 1);
|
||||||
|
Systeminfo["serialNumber"] = strSerialNumber;
|
||||||
|
|
||||||
|
Json::StyledWriter sw;
|
||||||
|
std::ofstream os;
|
||||||
|
os.open(SYSTEMINFOFILE);
|
||||||
|
os << sw.write(Systeminfo);
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PlatformInit::UserInit()
|
||||||
|
{
|
||||||
|
std::string userName = ReadStrByOpt(SYSTEMINFOFILE, "UserInfo", "UserName");
|
||||||
|
if (userName.length() == 0) {
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "UserName", "Admin");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "adminPassword", "njchaos");
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "UserInfo", "userPassword", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformInit::EquipIpInit()
|
||||||
|
{
|
||||||
|
//eth0 初始化
|
||||||
|
int flag = 0;
|
||||||
|
std::string networkPortStatus = ReadStrByOpt(NETWORKCONFIG, "Net", "networkPortStatus");
|
||||||
|
std::string subnetMask = ReadStrByOpt(NETWORKCONFIG, "Net", "subnetMask");
|
||||||
|
std::string gateway = ReadStrByOpt(NETWORKCONFIG, "Net", "gateway");
|
||||||
|
std::string dataWatchIpAddress = ReadStrByOpt(NETWORKCONFIG, "Net", "ipAddress");
|
||||||
|
std::string strStatus = GetFileContent(NETWORK, 18);
|
||||||
|
print_red("strStatus:%s\n networkPortStatus:%s dataWatchIpAddress:%s subnetMask:%s gateway:%s\n",strStatus.c_str(),networkPortStatus.c_str(),dataWatchIpAddress.c_str(),subnetMask.c_str(),gateway.c_str());
|
||||||
|
|
||||||
|
if(0 == networkPortStatus.compare("DHCP"))
|
||||||
|
{
|
||||||
|
print_white("dhcp config\n");
|
||||||
|
std::string cmd = "";
|
||||||
|
system("sed -i '17c auto eth0' /etc/network/interfaces");
|
||||||
|
system("sed -i '18c iface eth0 inet dhcp' /etc/network/interfaces");
|
||||||
|
system("sed -i '20c ' /etc/network/interfaces");
|
||||||
|
system("sed -i '21c ' /etc/network/interfaces");
|
||||||
|
system("sed -i '22c ' /etc/network/interfaces");
|
||||||
|
flag = 0;
|
||||||
|
}
|
||||||
|
if(0 == networkPortStatus.compare("STATIC"))
|
||||||
|
{
|
||||||
|
std::string cmd = "";
|
||||||
|
print_red("static config\n");
|
||||||
|
|
||||||
|
system("sed -i '18c iface eth0 inet static' /etc/network/interfaces");
|
||||||
|
if(dataWatchIpAddress.length() > 0)
|
||||||
|
{
|
||||||
|
cmd = "sed -i '20c address " + dataWatchIpAddress + "' /etc/network/interfaces";
|
||||||
|
}else{
|
||||||
|
cmd = "sed -i '20c address 0.0.0.0' /etc/network/interfaces";
|
||||||
|
}
|
||||||
|
system(cmd.c_str());
|
||||||
|
cmd.clear();
|
||||||
|
|
||||||
|
if(subnetMask.length() > 0)
|
||||||
|
{
|
||||||
|
cmd = "sed -i '21c netmask " + subnetMask + "' /etc/network/interfaces";
|
||||||
|
}else{
|
||||||
|
cmd = "sed -i '21c netmask 255.255.255.0' /etc/network/interfaces";
|
||||||
|
}
|
||||||
|
system(cmd.c_str());
|
||||||
|
cmd.clear();
|
||||||
|
|
||||||
|
if(gateway.length() > 0)
|
||||||
|
{
|
||||||
|
cmd = "sed -i '22c gateway " + gateway + "' /etc/network/interfaces";
|
||||||
|
}else{
|
||||||
|
cmd = "sed -i '22c gateway 0.0.0.0' /etc/network/interfaces";
|
||||||
|
}
|
||||||
|
system(cmd.c_str());
|
||||||
|
cmd.clear();
|
||||||
|
flag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(1 == flag){ //静态直接更新
|
||||||
|
system("source /etc/config.sh");
|
||||||
|
}
|
||||||
|
if(0 == flag) //动态重新启动获取
|
||||||
|
{
|
||||||
|
system("reboot");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
66
platform/SH_PlatformInit.hpp
Normal file
66
platform/SH_PlatformInit.hpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#ifndef _PLATFORMINIT_H_
|
||||||
|
#define _PLATFORMINIT_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PlatformInit : public MySingleton<PlatformInit>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
PlatformInit();
|
||||||
|
virtual ~PlatformInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void PlatFormInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 初始化系统配置文件,初始化时间戳,初始化数据库,初始化时区
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void ConfigFileCheck();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 服务器IP初始化
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
int ServerIpInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设备信息重新校验
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void SystemInfoInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief cgi用户信息初始化
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void UserInit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 数据库初始化
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void Sqlite3Init();
|
||||||
|
/**
|
||||||
|
*@eth0 初始化
|
||||||
|
*/
|
||||||
|
void EquipIpInit();
|
||||||
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mqtt主题初始化
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void TopicInit();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
146
searchdev/SH_SearchDev.cpp
Normal file
146
searchdev/SH_SearchDev.cpp
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include "SH_SearchDev.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
static const char* MULTICAST_HOST_NAME1 = "224.0.0.1"; //组播接收平台搜索信号地址
|
||||||
|
static const int MULTICAST_PORT_RECV1 = 7301; //组播接收端口
|
||||||
|
static const int MULTICAST_PORT_SEND = 7302; //根据接收组播udp发送端口
|
||||||
|
|
||||||
|
|
||||||
|
SearchDev::SearchDev(boost::asio::io_service& ioservice):mSockRecv_1(ioservice),
|
||||||
|
mListenEP1(ip::udp::v4(),MULTICAST_PORT_RECV1),
|
||||||
|
mSendEndpoint1(ip::address::from_string(MULTICAST_HOST_NAME1),MULTICAST_PORT_SEND)
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchDev::~SearchDev()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDev::Init()
|
||||||
|
{
|
||||||
|
// GwRouteInit();
|
||||||
|
//设置组播接收地址1
|
||||||
|
try {
|
||||||
|
mSockRecv_1.open(mListenEP1.protocol());
|
||||||
|
mSockRecv_1.set_option(ip::udp::socket::reuse_address(true));
|
||||||
|
mSockRecv_1.bind(mListenEP1);
|
||||||
|
mSockRecv_1.set_option(ip::multicast::join_group(ip::address_v4::from_string(MULTICAST_HOST_NAME1)));
|
||||||
|
mSockRecv_1.set_option(boost::asio::ip::multicast::enable_loopback(false));
|
||||||
|
} catch(boost::system::system_error& e) {
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SearchDev::GwRouteInit() {
|
||||||
|
|
||||||
|
// system("route > scan_test");
|
||||||
|
// std::fstream fileOut;
|
||||||
|
// int find = 0;
|
||||||
|
// fileOut.open("scan_test",std::ios::in | std::ios::app);
|
||||||
|
// if (fileOut.is_open()) {//文件打开
|
||||||
|
// while (!fileOut.eof()) {
|
||||||
|
// std::string tmpStr("");
|
||||||
|
// getline(fileOut,tmpStr);
|
||||||
|
// //fileOut >> tmpStr;
|
||||||
|
// print_info("%s\n",tmpStr.c_str());
|
||||||
|
// if (strstr(tmpStr.c_str(), "224.0.0.0")) {
|
||||||
|
// find = 1;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// fileOut.close();
|
||||||
|
|
||||||
|
// if (!find) {
|
||||||
|
// char cmd[128]="route add -net 224.0.0.0 netmask 224.0.0.0 dev ";
|
||||||
|
// strcat(cmd,GlobalConfig::KEthname.c_str());
|
||||||
|
// print_info("%s\n",cmd);
|
||||||
|
// system(cmd);
|
||||||
|
// }
|
||||||
|
// system("rm scan_test");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDev::HandleSend_1(const char *pMsg,const boost::system::error_code &pEc)
|
||||||
|
{
|
||||||
|
if (pEc) {
|
||||||
|
print_info("send udp error 7302\n");
|
||||||
|
} else {
|
||||||
|
print_info("send udp ok 7302\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SearchDev::MultiCastRecv() {
|
||||||
|
MultiCastRecv_1();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDev::MultiCastRecv_1()
|
||||||
|
{
|
||||||
|
memset(mRecvBuf1,0,BUF_LENGTH);
|
||||||
|
|
||||||
|
mSockRecv_1.async_receive_from(boost::asio::buffer(mRecvBuf1,BUF_LENGTH),mRecvEP1,
|
||||||
|
boost::bind(&SearchDev::HandleRecv_1,this,boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDev::HandleRecv_1(const boost::system::error_code &pEc,size_t pBytesRecv)
|
||||||
|
{
|
||||||
|
if (!pEc) {
|
||||||
|
print_info("mRecvBuf1 : %s\n", mRecvBuf1);
|
||||||
|
std::string data = std::string(mRecvBuf1);
|
||||||
|
Json::Value jsData;
|
||||||
|
Json::Reader recvReader;
|
||||||
|
Json::Value JsonVal;
|
||||||
|
Json::FastWriter fw;
|
||||||
|
if (recvReader.parse(data, jsData)) {
|
||||||
|
int cmdType = atoi(jsData["cmd"].asString().c_str());
|
||||||
|
switch (cmdType) {
|
||||||
|
case 4:{
|
||||||
|
std::string status = jsData["status"].asString();
|
||||||
|
if(status.compare("REQ") == 0) {
|
||||||
|
jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G.c_str();
|
||||||
|
jsData["localServerIpAddress"] = GlobalConfig::ServerIP;
|
||||||
|
jsData["status"] = "ACK";
|
||||||
|
std::string strData = fw.write(jsData);
|
||||||
|
print_info("send info %s ip: %s\n", strData.c_str(), mRecvEP1.address().to_string().c_str());
|
||||||
|
ip::udp::endpoint remoteEP(ip::address::from_string(mRecvEP1.address().to_string()),
|
||||||
|
MULTICAST_PORT_SEND);
|
||||||
|
mSockRecv_1.async_send_to(boost::asio::buffer(strData),remoteEP,
|
||||||
|
boost::bind(&SearchDev::HandleSend_1,this,"SockRecv_1_1",boost::asio::placeholders::error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MultiCastRecv_1();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDev::Run()
|
||||||
|
{
|
||||||
|
// mIoSev.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDev::Stop()
|
||||||
|
{
|
||||||
|
// if (!mIoSev.stopped())
|
||||||
|
// mIoSev.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchDev::Restart()
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
39
searchdev/SH_SearchDev.hpp
Normal file
39
searchdev/SH_SearchDev.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef _WL_SEARCHDEV_
|
||||||
|
#define _WL_SEARCHDEV_
|
||||||
|
#include <boost/asio/ip/udp.hpp>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
|
||||||
|
using namespace boost::asio;
|
||||||
|
//using boost::system::error_code;
|
||||||
|
|
||||||
|
class SearchDev : public MySingleton<SearchDev>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
SearchDev(boost::asio::io_service& ioservice);
|
||||||
|
~SearchDev();
|
||||||
|
void MultiCastRecv();
|
||||||
|
void MultiCastRecv_1();
|
||||||
|
void Run();
|
||||||
|
void Stop();
|
||||||
|
void Restart();
|
||||||
|
private:
|
||||||
|
void Init();
|
||||||
|
void GwRouteInit();
|
||||||
|
void HandleRecv_1(const boost::system::error_code &pEc,size_t pBytesRecv );
|
||||||
|
void HandleSend_1(const char *pMsg,const boost::system::error_code &pEc);
|
||||||
|
private :
|
||||||
|
enum{BUF_LENGTH = 128};
|
||||||
|
//io_service mIoSev;
|
||||||
|
ip::udp::socket mSockRecv_1;//组播地址1
|
||||||
|
ip::udp::endpoint mRecvEP1;
|
||||||
|
ip::udp::endpoint mListenEP1;
|
||||||
|
ip::udp::endpoint mSendEndpoint1;//组播发送端点
|
||||||
|
char mRecvBuf1[BUF_LENGTH];
|
||||||
|
char mSendBuf1[BUF_LENGTH];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
1436
secure/SH_Secure.cpp
Normal file
1436
secure/SH_Secure.cpp
Normal file
File diff suppressed because it is too large
Load Diff
53
secure/SH_Secure.hpp
Normal file
53
secure/SH_Secure.hpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef _WL_SECUREAPI_H_
|
||||||
|
#define _WL_SECUREAPI_H_
|
||||||
|
#include <string>
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
|
||||||
|
typedef unsigned char u_char;
|
||||||
|
typedef unsigned long u_long;
|
||||||
|
/************************
|
||||||
|
*
|
||||||
|
* 所有的加密与解密都只针对一条指令
|
||||||
|
*
|
||||||
|
*************************/
|
||||||
|
class Secure : public MySingleton<Secure>{
|
||||||
|
public:
|
||||||
|
Secure();
|
||||||
|
virtual ~Secure();
|
||||||
|
void GetKey(char *pKey,std::string pImeiId);//获取手机KEY
|
||||||
|
void GetKey(std::string gwmac);//获取连接云服务器的KEY
|
||||||
|
|
||||||
|
char *Base64Encode(const unsigned char * bindata, char * base65, int binlength);
|
||||||
|
int Base64Decode( const char * base64, unsigned char * bindata);
|
||||||
|
|
||||||
|
int ZigbeeDataEncrypt(char *pData);//zigbee数据加密
|
||||||
|
int ZigbeeDataEncrypt_Hex(char *pData, int len);//zigbee数据加密 HEX格式
|
||||||
|
void ZigbeeDataDecrypt(char *pData,int pLen);//zigbee数据解密
|
||||||
|
|
||||||
|
int NetDataEncrypt(char* pMing, char* pMi, char* pKey);//网络数据加密
|
||||||
|
int NetDataDecrypt(char* pMing, char* pMi, char* pKey);//网络数据解密
|
||||||
|
int NetDataDecrypt(char* pMing, char* pMi,int pLen,char* pKey);
|
||||||
|
|
||||||
|
char *Md5Sum(const char* filename);
|
||||||
|
int Encrypt(u_char *plaintext, u_char *expectText, int c_len, u_char *key);
|
||||||
|
int Decrypt(u_char *expectText, u_char *currentText, int c_len, u_char *key);
|
||||||
|
void BteaEncrypt(u_char* buf, u_char len);
|
||||||
|
void BteaDecrpyt(u_char* buf, u_char len);
|
||||||
|
char* FnMD5CACL(u_char *buf, int len);
|
||||||
|
|
||||||
|
enum{KEYLen = 16};
|
||||||
|
char KEY[KEYLen];
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int nr; /*!< number of rounds */
|
||||||
|
unsigned int* rk; /*!< AES round keys */
|
||||||
|
unsigned int buf[68]; /*!< unaligned data */
|
||||||
|
}aes_context;
|
||||||
|
void aes_setkey_enc(aes_context* ctx, const unsigned char* key, int keysize);
|
||||||
|
void aes_setkey_dec(aes_context* ctx, const unsigned char* key, int keysize);
|
||||||
|
unsigned char* aes_crypt_ecb(aes_context* ctx, int mode, const unsigned char* input, int slen, int* dlen);
|
||||||
|
private:
|
||||||
|
char result[33];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
72
tcpcgi/TcpCgi.cpp
Normal file
72
tcpcgi/TcpCgi.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "TcpCgi.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace{
|
||||||
|
LocalServer *cidwServer = LocalServer::instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpCgi::TcpCgi()
|
||||||
|
{
|
||||||
|
print_light_green("TcpCgi Init\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpCgi::startCgiServer()
|
||||||
|
{
|
||||||
|
int listenfd, connfd;
|
||||||
|
int mw_optval = 1;
|
||||||
|
|
||||||
|
struct sockaddr_in servaddr;
|
||||||
|
char buff[40960];
|
||||||
|
int n;
|
||||||
|
if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ){
|
||||||
|
printf("create socket error: %s(errno: %d)\n",strerror(errno),errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&mw_optval,sizeof(mw_optval));
|
||||||
|
|
||||||
|
memset(&servaddr, 0, sizeof(servaddr));
|
||||||
|
servaddr.sin_family = AF_INET;
|
||||||
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
servaddr.sin_port = htons(7305);
|
||||||
|
|
||||||
|
if( bind(listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) == -1){
|
||||||
|
printf("bind socket error: %s(errno: %d)\n",strerror(errno),errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( listen(listenfd, 10) == -1){
|
||||||
|
printf("listen socket error: %s(errno: %d)\n",strerror(errno),errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
if( (connfd = accept(listenfd, (struct sockaddr*)NULL, NULL)) == -1) {
|
||||||
|
printf("accept socket error: %s(errno: %d)",strerror(errno),errno);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
n = recv(connfd, buff, 40960, 0);
|
||||||
|
if ( n <= 0) {
|
||||||
|
print_info("recv fail\n");
|
||||||
|
close(connfd);
|
||||||
|
} else {
|
||||||
|
buff[n] = '\0';
|
||||||
|
|
||||||
|
std::string recvData = std::string(buff);
|
||||||
|
std::string reqData = cidwServer->HandleCgi_cmd(recvData);
|
||||||
|
print_info("send cgi : %s\n", reqData.c_str());
|
||||||
|
if( send(connfd, reqData.c_str(), reqData.length(), 0) < 0){
|
||||||
|
printf("send msg error: %s(errno: %d)\n", strerror(errno), errno);
|
||||||
|
}
|
||||||
|
close(connfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(listenfd);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpCgi::~TcpCgi()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
31
tcpcgi/TcpCgi.hpp
Normal file
31
tcpcgi/TcpCgi.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef TCPCGI_H
|
||||||
|
#define TCPCGI_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <boost/array.hpp>
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
#include "../API_log/SH_log.h"
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../localserver/SH_LocalServer.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
class TcpCgi : public MySingleton<TcpCgi> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
TcpCgi();
|
||||||
|
~TcpCgi();
|
||||||
|
|
||||||
|
void startCgiServer();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
401
threadfunc/SH_ThreadFunc.cpp
Normal file
401
threadfunc/SH_ThreadFunc.cpp
Normal file
@ -0,0 +1,401 @@
|
|||||||
|
#include <map>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <linux/types.h>
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
#include <boost/typeof/typeof.hpp>
|
||||||
|
#include "SH_ThreadFunc.hpp"
|
||||||
|
#include "../API_log/SH_log.h"
|
||||||
|
#include "../uart/SH_Uart.hpp"
|
||||||
|
|
||||||
|
namespace{
|
||||||
|
Uart *pUart = Uart::instance();
|
||||||
|
LocalServer *cidwServer = LocalServer::instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string serverPort;
|
||||||
|
static std::string uptime;
|
||||||
|
static long long connect_lost_time = 0; //ms
|
||||||
|
static long long connect_time = 0; //ms
|
||||||
|
|
||||||
|
void CheckThread()
|
||||||
|
{
|
||||||
|
print_info("ENTER CHECK THREAD \n");
|
||||||
|
std::string runinfo = "系统循环检测模块启动";
|
||||||
|
|
||||||
|
int heart_count = 0;
|
||||||
|
|
||||||
|
int time_check = 0;
|
||||||
|
int reset_flag = 0;
|
||||||
|
int online_check = 0;
|
||||||
|
|
||||||
|
while (GlobalConfig::QuitFlag_G) {
|
||||||
|
if (10 == heart_count) {
|
||||||
|
// StatusPub();
|
||||||
|
if (GlobalConfig::LinkCount > 30) {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
std::string ipTemp = IpAddrInit();
|
||||||
|
if ( 0 != ipTemp.compare(GlobalConfig::IpAddr_G)) {
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
heart_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (600 == time_check) {
|
||||||
|
char buf[256] = {0};
|
||||||
|
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}",
|
||||||
|
GlobalConfig::MacAddr_G.c_str());
|
||||||
|
std::string str = std::string(buf);
|
||||||
|
data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
time_check = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (21600 == online_check) {
|
||||||
|
JsonData jd;
|
||||||
|
jd.DataNodeStatusCheck();
|
||||||
|
|
||||||
|
Param_29 param;
|
||||||
|
std::string cmd29 = jd.JsonCmd_29(param);
|
||||||
|
data_publish(cmd29.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
online_check = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( reset_flag > 7200) {
|
||||||
|
reset_flag = 0;
|
||||||
|
//exit(0);
|
||||||
|
}
|
||||||
|
reset_flag++;
|
||||||
|
time_check++;
|
||||||
|
heart_count++;
|
||||||
|
online_check++;
|
||||||
|
|
||||||
|
if(GlobalConfig::EnterZigBeeWaveTransmittingFlag_G == ENTER_TRANSMITTING_STATUS) {
|
||||||
|
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G ++;
|
||||||
|
if(GlobalConfig::EnterZigBeeWaveTransmittingCnt_G >= 180) {
|
||||||
|
GlobalConfig::EnterZigBeeWaveTransmittingFlag_G = NO_ENTER_TRANSMITTING_STATUS;
|
||||||
|
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G = 0;
|
||||||
|
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !\n");
|
||||||
|
// 重新写入 0x8888
|
||||||
|
unsigned short shortAddr = 0x8888;
|
||||||
|
pUart->WriteShortAddr2Zigbee(shortAddr);
|
||||||
|
// 延时1秒
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
||||||
|
// 重新读回 GlobalConfig::ZigbeeInfo_G.PanID
|
||||||
|
pUart->UpdateZigbeeInfoCtrl();
|
||||||
|
// 延时1秒
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
||||||
|
std::string str("8888");
|
||||||
|
if( GlobalConfig::ZigbeeInfo_G.MyAddr.compare(str) == 0 ){
|
||||||
|
LOG_INFO("[---- ZigBee INFO ----!] ZigBee PanID come back to be 8888 !\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID cannot come back to be 8888 !\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartCgiServer()
|
||||||
|
{
|
||||||
|
print_info("start deal cgi\n");
|
||||||
|
TcpCgi *tcpCgi = TcpCgi::instance();
|
||||||
|
while (1) {
|
||||||
|
tcpCgi->startCgiServer();
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HeartRep()
|
||||||
|
{
|
||||||
|
while(1) {
|
||||||
|
Json::Value jsHeart;
|
||||||
|
Json::FastWriter fw;
|
||||||
|
jsHeart["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
|
jsHeart["status"] = "online";
|
||||||
|
std::string strJson = fw.write(jsHeart);
|
||||||
|
data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartStart()
|
||||||
|
{
|
||||||
|
// onReceiveUart cb = (onReceiveUart)&ProtoConvert::HandleFromUart;
|
||||||
|
// pUart->setCallBack(cb);
|
||||||
|
while (GlobalConfig::QuitFlag_G) {
|
||||||
|
pUart->InitUart();
|
||||||
|
pUart->UpdateZigbeeInfoCtrl();
|
||||||
|
pUart->ReadFromUart();
|
||||||
|
pUart->Run();
|
||||||
|
pUart->Stop();
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UartStartWave()
|
||||||
|
{
|
||||||
|
pUart->DealWaveThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartUdpSys()
|
||||||
|
{
|
||||||
|
UdpSys *udpsys = UdpSys::instance();
|
||||||
|
udpsys->StartConnectSysUdp();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* LOCAL_WILL_TOPIC = "up/uart/will";
|
||||||
|
void my_publish_callback(struct mosquitto *mosq, void *obj, int mid)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_connect_callback(struct mosquitto *mosq, void *obj, int result)
|
||||||
|
{
|
||||||
|
struct userdata *ud;
|
||||||
|
ud = (struct userdata *)obj;
|
||||||
|
|
||||||
|
if (!result){
|
||||||
|
for (int i = 0; i < ud->topic_count; i++){
|
||||||
|
print_purple("mosquitto_subscribe ud->topics[%d]:%s\n", i, ud->topics[i]);
|
||||||
|
int iret = mosquitto_subscribe(mosq, NULL, ud->topics[i], ud->topic_qos);
|
||||||
|
print_purple("mosquitto_subscribe ret:%d\n", iret);
|
||||||
|
}
|
||||||
|
|
||||||
|
int iret = mosquitto_subscribe(mosq, NULL, GlobalConfig::Topic_G.mSubData.c_str(), 1);
|
||||||
|
print_debug("mosquitto_subscribe's return value: %d\n", iret);
|
||||||
|
|
||||||
|
char gwTime[32] = { 0 };
|
||||||
|
GetTimeNet(gwTime, 0);
|
||||||
|
connect_time = strtoll(gwTime, NULL, 10);
|
||||||
|
print_debug("connect_time:%lld\n", connect_time);
|
||||||
|
long long difftime_ms = connect_time - connect_lost_time;
|
||||||
|
//if (difftime_ms > 20*1000) { // 超过20秒,判定为连接断开
|
||||||
|
char reply_string[256] = {0};
|
||||||
|
std::string startStatus = "0";
|
||||||
|
if (access(SYSTEMSTART, 0) >= 0) {
|
||||||
|
startStatus = GetFileContent(SYSTEMSTART, 1);
|
||||||
|
}
|
||||||
|
sprintf(reply_string, "{\"dataNodeGatewayNo\":\"%s\",\"softVersion\":\"%s\",\"status\":\"%s\"}",
|
||||||
|
GlobalConfig::MacAddr_G.c_str(), GlobalConfig::Version.c_str(), startStatus.c_str());
|
||||||
|
|
||||||
|
Json::Value jsData;
|
||||||
|
Json::Value jsVal;
|
||||||
|
Json::FastWriter fw;
|
||||||
|
jsData["cmd"] = "15";
|
||||||
|
jsData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||||
|
// jsData["cmdBody"] = "";
|
||||||
|
|
||||||
|
std::string strCmd15 = fw.write(jsData);
|
||||||
|
data_publish(strCmd15.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
|
||||||
|
std::string instr = std::string(reply_string);
|
||||||
|
std::string topic = "equipment/state/" + GlobalConfig::MacAddr_G;
|
||||||
|
int ret = data_publish(instr.c_str(), topic.c_str());
|
||||||
|
system("echo 0 > /CIDW/start");
|
||||||
|
if (ret != MOSQ_ERR_SUCCESS) {
|
||||||
|
print_debug("Publish failed:%d, %s\n", ret, instr.c_str());
|
||||||
|
disconnect();
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
GlobalConfig::LinkStatus_G = 1;
|
||||||
|
print_debug("Connect to server success.\n");
|
||||||
|
|
||||||
|
// std::string cmd20 = JsonCmd_Cgi_20();
|
||||||
|
// data_publish(cmd20.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
|
||||||
|
char buf[256] = {0};
|
||||||
|
sprintf(buf, "{\"dataNodeGatewayNo\":\"%s\",\"cmd\":\"12\",\"status\":\"REQ\"}",
|
||||||
|
GlobalConfig::MacAddr_G.c_str());
|
||||||
|
std::string str = std::string(buf);
|
||||||
|
data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
std::string runinfo = "本地服务器连接成功";
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (result && !ud->quiet){
|
||||||
|
fprintf(stderr, "%s\n", mosquitto_connack_string(result));
|
||||||
|
if(result == 1) {
|
||||||
|
//Connection Refused: unacceptable protocol version
|
||||||
|
} else if (result == 2) {
|
||||||
|
//Connection Refused: identifier rejected
|
||||||
|
} else if (result == 3) {
|
||||||
|
//Connection Refused: server unavailable
|
||||||
|
} else if (result == 4) {
|
||||||
|
//Connection Refused: bad user name or password
|
||||||
|
// exit(0);
|
||||||
|
} else if (result == 5) {
|
||||||
|
//Connection Refused: not authorized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
ret = disconnect();
|
||||||
|
// LOG_ERROR("The uart connection lost:%d\n", ret);
|
||||||
|
print_debug("The uart connection lost\n");
|
||||||
|
char gwTime[32] = { 0 };
|
||||||
|
GetTimeNet(gwTime, 0);
|
||||||
|
uptime = std::string(gwTime);
|
||||||
|
connect_lost_time = strtoll(uptime.c_str(), NULL, 10);
|
||||||
|
print_debug("connect_lost_time:%lld\n", connect_lost_time);
|
||||||
|
GlobalConfig::LinkStatus_G = 0;
|
||||||
|
GlobalConfig::LinkCount = GlobalConfig::LinkCount + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
|
||||||
|
{
|
||||||
|
struct userdata *ud;
|
||||||
|
bool res;
|
||||||
|
assert(obj);
|
||||||
|
ud = (struct userdata *)obj;
|
||||||
|
|
||||||
|
if (message->retain && ud->no_retain) return;
|
||||||
|
if (ud->filter_outs) {
|
||||||
|
for (int i = 0; i < ud->filter_out_count; i++) {
|
||||||
|
mosquitto_topic_matches_sub(ud->filter_outs[i], message->topic, &res);
|
||||||
|
if (res) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ud->verbose) {
|
||||||
|
if (message->payloadlen) {
|
||||||
|
std::string strtopic(message->topic);
|
||||||
|
print_info("strtopic : %s \n", strtopic.c_str());
|
||||||
|
cidwServer->HandleFromServer((const char *)message->payload,message->payloadlen,message->topic);
|
||||||
|
if (ud->eol) {
|
||||||
|
print_brown("\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ud->eol) {
|
||||||
|
print_brown("%s (null)\n", message->topic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fflush(stdout);
|
||||||
|
} else {
|
||||||
|
if (message->payloadlen) {
|
||||||
|
fwrite(message->payload, 1, message->payloadlen, stdout);
|
||||||
|
if (ud->eol) {
|
||||||
|
print_red("\n");
|
||||||
|
}
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_subscribe_callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct userdata *ud;
|
||||||
|
assert(obj);
|
||||||
|
ud = (struct userdata *)obj;
|
||||||
|
if (!ud->quiet) print_brown("Subscribed (mid: %d): %d", mid, granted_qos[0]);
|
||||||
|
for (i = 1; i < qos_count; i++){
|
||||||
|
if (!ud->quiet) print_brown(", %d", granted_qos[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_log_callback(struct mosquitto *mosq, void *obj, int level, const char *str)
|
||||||
|
{
|
||||||
|
if (level == MOSQ_LOG_ERR) {
|
||||||
|
//LOG_ERROR("%s\n", str);
|
||||||
|
} else if (level == MOSQ_LOG_WARNING) {
|
||||||
|
// LOG_WARN("%s\n", str);
|
||||||
|
} else if (level == MOSQ_LOG_NOTICE) {
|
||||||
|
//LOG_INFO("%s\n", str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartMqttClient()
|
||||||
|
{
|
||||||
|
print_info("start mqtt \n");
|
||||||
|
std::string runinfo = "MQTT通信模块启动";
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (GlobalConfig::ServerIP.length() > 0) {
|
||||||
|
std::string strEqupNo = GlobalConfig::MacAddr_G;
|
||||||
|
std::string strVersion = GlobalConfig::Version;
|
||||||
|
std::string salt;
|
||||||
|
register_collback(my_connect_callback, my_message_callback, my_subscribe_callback, my_log_callback, my_disconnect_callback, my_publish_callback);
|
||||||
|
start_client(strEqupNo.c_str(), GlobalConfig::MacAddr_G.c_str(), GlobalConfig::ServerIP.c_str(), strVersion.c_str(), "11111111", salt);
|
||||||
|
}
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SearchThread()
|
||||||
|
{
|
||||||
|
std::string runinfo = "设备搜索模块启动";
|
||||||
|
|
||||||
|
while (GlobalConfig::QuitFlag_G) {
|
||||||
|
if (GlobalConfig::IpAddr_G.length() > 0 && 0 != GlobalConfig::IpAddr_G.compare("0.0.0.0")) {
|
||||||
|
boost::asio::io_service io_service;
|
||||||
|
SearchDev *searchDevObj = new SearchDev(io_service);
|
||||||
|
searchDevObj->MultiCastRecv();
|
||||||
|
io_service.run();
|
||||||
|
delete searchDevObj;
|
||||||
|
}
|
||||||
|
boost::this_thread::sleep(boost::posix_time::seconds(5));
|
||||||
|
print_error("SearchThred restart.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RecvUpdateFile()
|
||||||
|
{
|
||||||
|
boost::asio::io_service iosev;
|
||||||
|
boost::asio::ip::tcp::acceptor acceptor(iosev,
|
||||||
|
boost::asio::ip::tcp::endpoint(
|
||||||
|
boost::asio::ip::tcp::v4(), 7304));
|
||||||
|
for(;;) {
|
||||||
|
boost::asio::ip::tcp::socket socket(iosev);
|
||||||
|
acceptor.accept(socket);
|
||||||
|
boost::system::error_code ec;
|
||||||
|
if(ec) {
|
||||||
|
print_error("%s\n", boost::system::system_error(ec).what());
|
||||||
|
//return -1;
|
||||||
|
}
|
||||||
|
FILE *fp;
|
||||||
|
char buffer[1024];
|
||||||
|
size_t len = 0;
|
||||||
|
int write_len;
|
||||||
|
bzero(buffer,1024);
|
||||||
|
fp = fopen("/tmp/upgrade.tar.gz", "w");
|
||||||
|
if(NULL == fp ) {
|
||||||
|
print_info("File:\t Can Not Open To Write\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
while(len = socket.read_some(boost::asio::buffer(buffer),ec)) {
|
||||||
|
if(len < 0) {
|
||||||
|
print_info("Receive Data From Server Failed! \n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
write_len = fwrite(buffer, sizeof(char), len, fp);
|
||||||
|
if(write_len < len) {
|
||||||
|
print_info("File:test Write Failed!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bzero(buffer, 1024);
|
||||||
|
}
|
||||||
|
print_info("Receive File From Server Finished! \n");
|
||||||
|
fclose(fp);
|
||||||
|
Json::Value jsData;
|
||||||
|
Json::FastWriter fw;
|
||||||
|
jsData["cmd"] = "03";
|
||||||
|
jsData["updatefilename"] = "updatefile";
|
||||||
|
std::string str = fw.write(jsData);
|
||||||
|
system("/etc/init.d/sysupgrade.sh");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
31
threadfunc/SH_ThreadFunc.hpp
Normal file
31
threadfunc/SH_ThreadFunc.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <signal.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
#include "../mqttclient/SH_MqttClient.h"
|
||||||
|
#include "../localserver/SH_LocalServer.hpp"
|
||||||
|
#include "../searchdev/SH_SearchDev.hpp"
|
||||||
|
#include "../tcpcgi/TcpCgi.hpp"
|
||||||
|
#include "../udpqt/SH_UdpQt.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************
|
||||||
|
*************线程处理函数***********
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
extern void CheckThread(); //循环检测线程
|
||||||
|
extern void StartMqttClient(); //启动mqtt服务
|
||||||
|
extern void SearchThread(); //组播功能, 提供发现设备功能
|
||||||
|
extern void RecvUpdateFile(); //更新升级包
|
||||||
|
extern void StartCgiServer(); //启动cgi处理服务端
|
||||||
|
extern void HeartRep();
|
||||||
|
extern void UartStart(); //
|
||||||
|
extern void UartStartWave();
|
||||||
|
extern void StartUdpSys(); //组播通信
|
||||||
2029
uart/SH_Uart.cpp
Normal file
2029
uart/SH_Uart.cpp
Normal file
File diff suppressed because it is too large
Load Diff
71
uart/SH_Uart.hpp
Normal file
71
uart/SH_Uart.hpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#ifndef _UART_H_
|
||||||
|
#define _UART_H_
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
#include <boost/unordered_set.hpp>
|
||||||
|
#include <boost/unordered_map.hpp>
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../dbaccess/SH_SqlDB.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//using namespace boost::asio;
|
||||||
|
//using std::string;
|
||||||
|
//using boost::system::error_code;
|
||||||
|
typedef unsigned int UINT;
|
||||||
|
|
||||||
|
|
||||||
|
class Uart : public MySingleton<Uart>
|
||||||
|
{
|
||||||
|
private :
|
||||||
|
boost::posix_time::ptime mLocalTime;
|
||||||
|
boost::asio::io_service mIoSev;
|
||||||
|
boost::asio::serial_port mUart;
|
||||||
|
int mRdLength;
|
||||||
|
enum{BUF_LENGTH = 1024};
|
||||||
|
char mUartRecvBuf[BUF_LENGTH];
|
||||||
|
boost::mutex mLock;
|
||||||
|
boost::asio::io_service::strand mStrand;
|
||||||
|
|
||||||
|
public :
|
||||||
|
Uart();
|
||||||
|
void InitUart();
|
||||||
|
~Uart();
|
||||||
|
void WriteToUart(const char *strSend,int pLen);
|
||||||
|
void ReadFromUart();
|
||||||
|
void setCallBack(onReceiveUart _callback);
|
||||||
|
void Run();
|
||||||
|
void Stop();
|
||||||
|
void UpdateZigbeeInfoCtrl();
|
||||||
|
void UpdateZigbeeInfo(const char *pData);
|
||||||
|
void DealRecvData(const char *pData);
|
||||||
|
void DealDataNodeInfo(const char *pData);
|
||||||
|
void DealDataNodeFeature(const char *pData, int flag);
|
||||||
|
void DealDataNodeWave(const char *pData);
|
||||||
|
void DealWaveThread();
|
||||||
|
void DealWave();
|
||||||
|
void ZigbeeInit();
|
||||||
|
|
||||||
|
void modify_info(unsigned short id, char * zigbee);
|
||||||
|
void zigbee_reset(unsigned short pad, unsigned short type);
|
||||||
|
void WriteChanl2Zigbee(unsigned char pad);
|
||||||
|
void WritePanId2Zigbee(unsigned short pad);
|
||||||
|
void WriteShortAddr2Zigbee(unsigned short pad);
|
||||||
|
virtual void DataAnalysis_R(DevDataOfGwid &pData);
|
||||||
|
virtual void DataAnalysis_W(DevData &pData,bool pFlag);
|
||||||
|
virtual void ThreadInit();
|
||||||
|
private :
|
||||||
|
void ReadHandle(const boost::system::error_code &ec,size_t bytesRead);
|
||||||
|
void WriteHandle(const char *strSend,const boost::system::error_code &ec,size_t bytesWrite);
|
||||||
|
onReceiveUart m_callback;
|
||||||
|
std::vector<RecvData> m_VecWaveData;
|
||||||
|
unsigned long m_TimeStamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
194
udpqt/SH_UdpQt.cpp
Normal file
194
udpqt/SH_UdpQt.cpp
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
#include "SH_UdpQt.hpp"
|
||||||
|
#include "../common/SH_CommonFunc.hpp"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
#include "../API_log/SH_log.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
UdpSys::UdpSys():
|
||||||
|
mIoSev(), udpSock(mIoSev, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 7303))
|
||||||
|
{
|
||||||
|
print_light_green("UdpQt Init\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UdpSys::ClearConnect()
|
||||||
|
{
|
||||||
|
remoteIp.clear();
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UdpSys::StartConnectSysUdp()
|
||||||
|
{
|
||||||
|
print_light_green("start connect QT\n");
|
||||||
|
if (udpSock.is_open()) {
|
||||||
|
boost::asio::socket_base::linger option1(true, 0);
|
||||||
|
udpSock.set_option(option1);
|
||||||
|
boost::asio::socket_base::send_buffer_size option4(125000);
|
||||||
|
udpSock.set_option(option4);
|
||||||
|
remoteEndPoint = boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 9998);
|
||||||
|
remoteEndPoint.address(boost::asio::ip::address::from_string("127.0.0.1"));
|
||||||
|
recvUdpData();
|
||||||
|
// boost::thread sendHeartTh(boost::bind(&UdpQt::ConfirmStatus, this));
|
||||||
|
// sendHeartTh.detach();
|
||||||
|
mIoSev.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UdpSys::handle_send_to(const boost::system::error_code& ec,
|
||||||
|
size_t trans)
|
||||||
|
{
|
||||||
|
if (ec) {
|
||||||
|
print_error("send the udp to sys error! \n");
|
||||||
|
} else {
|
||||||
|
print_info("send the udp to sys ok! \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UdpSys::SendUdpToSingle(std::string pData)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(udpMutex);
|
||||||
|
int len = pData.length();
|
||||||
|
if (len <= 0)
|
||||||
|
return ;
|
||||||
|
char *mi = new char[len + 3];
|
||||||
|
memset(mi, 0, len + 3);
|
||||||
|
strcpy(mi, pData.c_str());
|
||||||
|
strcat(mi, "\r\n");
|
||||||
|
// std::cout << "sys send single:" << pData << remoteEndPoint.address() << remoteEndPoint.port() <<std::endl;
|
||||||
|
print_brown("sys send single : %s \n", pData.c_str());
|
||||||
|
udpSock.async_send_to(boost::asio::buffer(mi,len + 3), remoteEndPoint,
|
||||||
|
boost::bind(&UdpSys::handle_send_to, this,
|
||||||
|
boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
delete [] mi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UdpSys::recvUdpData()
|
||||||
|
{
|
||||||
|
udpSock.async_receive_from(boost::asio::buffer(m_buffer), senderEndPoint,
|
||||||
|
boost::bind(&UdpSys::HandleRead, this,
|
||||||
|
boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UdpSys::HandleRead(const boost::system::error_code& pEc,
|
||||||
|
std::size_t pBytesTransferred)
|
||||||
|
{
|
||||||
|
std::string ip = senderEndPoint.address().to_string();
|
||||||
|
if (pEc) {
|
||||||
|
std::cerr << pEc.value() <<std::endl;
|
||||||
|
std::cerr << pEc.category().name() << std::endl;
|
||||||
|
std::cerr << pEc.message() << std::endl;
|
||||||
|
} else if (pBytesTransferred == 0) {
|
||||||
|
std::cout << "rev has rec!" << std::endl;
|
||||||
|
if (pBytesTransferred == 0) {
|
||||||
|
std::cerr << "[ Read 0 Bytes ][ " << ip << " Quit ! ]" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::string read_cmd(m_buffer.data(), pBytesTransferred);
|
||||||
|
print_light_purple("%s", read_cmd.c_str());
|
||||||
|
if(read_cmd.length()>0){
|
||||||
|
AnalysisDataSys(read_cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recvUdpData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UdpSys::AnalysisDataSys(std::string cmd)
|
||||||
|
{
|
||||||
|
printf("%s", cmd.c_str());
|
||||||
|
Json::Reader recvReader;
|
||||||
|
Json::Value JsonVal;
|
||||||
|
if(recvReader.parse(cmd,JsonVal)) {
|
||||||
|
int cmdType = atoi(JsonVal["cmd"].asString().c_str());
|
||||||
|
switch (cmdType) {
|
||||||
|
case 3:{ //配置服务器
|
||||||
|
std::string strServerIp = JsonVal["localServerIpAddress"].asString();
|
||||||
|
int localServerPort = JsonVal["localServerPort"].asInt();
|
||||||
|
|
||||||
|
std::string strDataWatchAddedBy = "system";
|
||||||
|
if (!JsonVal["dataNodeGatewayAddedBy"].isNull()) {
|
||||||
|
strDataWatchAddedBy = JsonVal["dataNodeGatewayAddedBy"].asString();
|
||||||
|
WriteStr2Config(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy", strDataWatchAddedBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
print_info("strServerIp : %s \n", strServerIp.c_str());
|
||||||
|
if (strServerIp.compare(GlobalConfig::ServerIP) != 0 || localServerPort != GlobalConfig::ServerPort)
|
||||||
|
{
|
||||||
|
GlobalConfig::ServerIP = strServerIp;
|
||||||
|
GlobalConfig::ServerPort = localServerPort;
|
||||||
|
|
||||||
|
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", GlobalConfig::ServerIP);
|
||||||
|
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", boost::lexical_cast<std::string>(GlobalConfig::ServerPort));
|
||||||
|
|
||||||
|
std::string fileserver = ReadStrByOpt(SERVERCONFIG, "FileServer", "FileServerIpAddress");
|
||||||
|
if (0 == fileserver.compare("0.0.0.0") || 0 == fileserver.length()) {
|
||||||
|
WriteStr2Config(SERVERCONFIG, "FileServer", "FileServerIpAddress", GlobalConfig::ServerIP);
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonVal["status"] = "ACK";
|
||||||
|
Json::FastWriter fw;
|
||||||
|
std::string str = fw.write(JsonVal);
|
||||||
|
print_info("send info : %s \n", str.c_str());
|
||||||
|
boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()),
|
||||||
|
MULTICAST_PORT_SEND);
|
||||||
|
udpSock.async_send_to(boost::asio::buffer(str),remoteEP,
|
||||||
|
boost::bind(&UdpSys::handle_send_to,this,boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
|
||||||
|
// Json::Value jsValue;
|
||||||
|
// Json::FastWriter fw1;
|
||||||
|
// jsValue["type"] = "set";
|
||||||
|
// std::string data = fw1.write(jsValue);
|
||||||
|
// data_publish_local(data.c_str(), GlobalConfig::Topic_G.mPubLocalConfig.c_str());
|
||||||
|
|
||||||
|
// boost::this_thread::sleep(boost::posix_time::seconds(2));
|
||||||
|
// exit(0);
|
||||||
|
} else {
|
||||||
|
// char reply_string[256] = {0};
|
||||||
|
// sprintf(reply_string, "{\"dataNodeGatewayNo\":\"%s\",\"softVersion\":\"%s\",\"status\":\"0\"}",
|
||||||
|
// GlobalConfig::MacAddr_G.c_str(), GlobalConfig::Version.c_str());
|
||||||
|
|
||||||
|
// std::string instr = std::string(reply_string);
|
||||||
|
// std::string topic = "equipment/state/" + GlobalConfig::MacAddr_G;
|
||||||
|
|
||||||
|
// int ret = data_publish(instr.c_str(), topic.c_str());
|
||||||
|
|
||||||
|
// std::string cmd20 = JsonCmd_Cgi_20();
|
||||||
|
// data_publish(cmd20.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:{
|
||||||
|
Json::FastWriter fw;
|
||||||
|
std::string status = JsonVal["status"].asString();
|
||||||
|
if(status.compare("REQ") == 0)
|
||||||
|
{
|
||||||
|
JsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G.c_str();
|
||||||
|
JsonVal["localServerIpAddress"] = GlobalConfig::ServerIP;
|
||||||
|
JsonVal["status"] = "ACK";
|
||||||
|
std::string data = fw.write(JsonVal);
|
||||||
|
boost::asio::ip::udp::endpoint remoteEP(boost::asio::ip::address::from_string(senderEndPoint.address().to_string()),
|
||||||
|
MULTICAST_PORT_SEND);
|
||||||
|
udpSock.async_send_to(boost::asio::buffer(data),remoteEP,
|
||||||
|
boost::bind(&UdpSys::handle_send_to,this,boost::asio::placeholders::error,
|
||||||
|
boost::asio::placeholders::bytes_transferred));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
print_error("json parse failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UdpSys::~UdpSys()
|
||||||
|
{
|
||||||
|
if (udpSock.is_open())
|
||||||
|
udpSock.close();
|
||||||
|
}
|
||||||
105
udpqt/SH_UdpQt.hpp
Normal file
105
udpqt/SH_UdpQt.hpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#ifndef UDPQT_H
|
||||||
|
#define UDPQT_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/thread/thread.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <boost/array.hpp>
|
||||||
|
#include "../utility/SH_MySingleton.hpp"
|
||||||
|
#include "../common/SH_global.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define MULTICAST_PORT_SEND 7302 //根据接收组播udp发送端口
|
||||||
|
|
||||||
|
#define SYSUDPIP "127.0.0.1"
|
||||||
|
#define SYSUDPPORT "9999"
|
||||||
|
|
||||||
|
#define RECIEVE_CONNECT_STATUS 1 //QT连接确认
|
||||||
|
#define RECIEVE_CONFIG_GET 3 //获取配置信息
|
||||||
|
#define RECIEVE_WIFI_CONTROL 4 //wifi操作
|
||||||
|
#define RECIEVE_WAVEDATA_CONTROL 7 //原始数据操作
|
||||||
|
|
||||||
|
|
||||||
|
#define CMD_TYPE_CONNECTQT 1
|
||||||
|
#define RECIEVE_CONFIG_GET 3
|
||||||
|
#define RECIEVE_WIFI_CONTROL 4
|
||||||
|
#define RECIEVE_WAVEDATA_CONTROL 7
|
||||||
|
|
||||||
|
|
||||||
|
class UdpSys : public MySingleton<UdpSys> {
|
||||||
|
public:
|
||||||
|
UdpSys();
|
||||||
|
~UdpSys();
|
||||||
|
/**
|
||||||
|
* @brief 发送数据
|
||||||
|
* @param pData 发送的字符串数据
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void SendUdpToSingle(std::string pData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 连接子程序
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void StartConnectSysUdp();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 清除连接
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void ClearConnect();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 确认连接
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
// void ConfirmStatus();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 发送数据的回调函数
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void handle_send_to(const boost::system::error_code& ec,
|
||||||
|
size_t trans);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 接收数据
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void recvUdpData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 数据分析
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void AnalysisDataSys(std::string cmd);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 接收数据的回调函数
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void HandleRead(const boost::system::error_code& pEc,
|
||||||
|
std::size_t pBytesTransferred);
|
||||||
|
private:
|
||||||
|
boost::mutex udpMutex;
|
||||||
|
std::string remoteIp;
|
||||||
|
int remoteport;
|
||||||
|
boost::asio::ip::udp::endpoint remoteEndPoint;
|
||||||
|
boost::asio::ip::udp::endpoint senderEndPoint;
|
||||||
|
boost::asio::io_service mIoSev;
|
||||||
|
boost::asio::ip::udp::socket udpSock;
|
||||||
|
boost::array<char,8192> m_buffer;
|
||||||
|
std::string mData;
|
||||||
|
bool status;
|
||||||
|
int times;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
201
utility/Caculation.h
Normal file
201
utility/Caculation.h
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
#ifndef CACULATION_H_
|
||||||
|
#define CACULATION_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <math.h>
|
||||||
|
#include <fftw3.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Caculation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Caculation();
|
||||||
|
~Caculation();
|
||||||
|
|
||||||
|
template<typename T, int N>
|
||||||
|
static T maxValue(T(&data)[N]);
|
||||||
|
|
||||||
|
template<typename T, int N>
|
||||||
|
static T minValue(T(&data)[N]);
|
||||||
|
|
||||||
|
template<typename T, int N> //<2F><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>ֵ
|
||||||
|
static T dcValue(T(&data)[N]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T, int N> //<2F><><EFBFBD><EFBFBD>RMS
|
||||||
|
static T caculateRMS(T(&data)[N]);
|
||||||
|
|
||||||
|
template<typename T, int N> //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||||
|
static T caculatePKtoPk(T(&data)[N]);
|
||||||
|
|
||||||
|
|
||||||
|
//<2F><><EFBFBD>ٸ<EFBFBD><D9B8><EFBFBD>Ҷ<EFBFBD>任<EFBFBD><E4BBBB><EFBFBD><EFBFBD>
|
||||||
|
static void FFT(int n, fftw_complex* in, fftw_complex* out);
|
||||||
|
|
||||||
|
//ͨ<><CDA8><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ȡ
|
||||||
|
//<2F><><EFBFBD><EFBFBD>ΪFFT<46>任<EFBFBD><E4BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ݣ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ķ<EFBFBD>ֵ <20><> <20><>λ
|
||||||
|
static void caculateAmp_Pha(int n, fftw_complex* in, int frequency, double &litude, double &phase);
|
||||||
|
|
||||||
|
template <typename T> //<2F><><EFBFBD><EFBFBD>hanning<6E><67><EFBFBD><EFBFBD>
|
||||||
|
static vector<T> hanning(int N, T amp);
|
||||||
|
|
||||||
|
template <typename T> //<2F><><EFBFBD><EFBFBD>hamming<6E><67><EFBFBD><EFBFBD>
|
||||||
|
static vector<T> hamming(int N, T amp);
|
||||||
|
|
||||||
|
//ͳ<>Ƽ<EFBFBD><C6BC><EFBFBD>
|
||||||
|
};
|
||||||
|
|
||||||
|
Caculation::Caculation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Caculation::~Caculation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ֵ */
|
||||||
|
/************************************************************************/
|
||||||
|
template<typename T, int N>
|
||||||
|
T Caculation::maxValue(T(&data)[N])
|
||||||
|
{
|
||||||
|
if (0 == N) return 0;
|
||||||
|
T max = data[0];
|
||||||
|
for (int i = 1; i < N; i++)
|
||||||
|
if (max < data[i])
|
||||||
|
max = data[i];
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>Сֵ */
|
||||||
|
/************************************************************************/
|
||||||
|
template<typename T, int N>
|
||||||
|
T Caculation::minValue(T(&data)[N])
|
||||||
|
{
|
||||||
|
if (0 == N) return 0;
|
||||||
|
T min = data[0];
|
||||||
|
for (int i = 1; i < N; i++)
|
||||||
|
if (min > data[i])
|
||||||
|
min = data[i];
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ƽ<EFBFBD><C6BD>ֵ */
|
||||||
|
/************************************************************************/
|
||||||
|
template<typename T, int N>
|
||||||
|
T Caculation::dcValue(T(&data)[N])
|
||||||
|
{
|
||||||
|
if (0 == N) return 0;
|
||||||
|
T sum = 0;
|
||||||
|
for (int i = 0; i < N; i++)
|
||||||
|
sum += data[i];
|
||||||
|
return sum / N;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RMS */
|
||||||
|
/************************************************************************/
|
||||||
|
template<typename T, int N>
|
||||||
|
T Caculation::caculateRMS(T(&data)[N])
|
||||||
|
{
|
||||||
|
if (0 == N) return 0;
|
||||||
|
T fSum = 0;
|
||||||
|
for (int i = 0; i < N; i++)
|
||||||
|
fSum += data[i] * data[i];
|
||||||
|
return sqrt(fSum / N);
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ֵ */
|
||||||
|
/************************************************************************/
|
||||||
|
template<typename T, int N>
|
||||||
|
T Caculation::caculatePKtoPk(T(&data)[N])
|
||||||
|
{
|
||||||
|
if (0 == N) return 0;
|
||||||
|
T min = data[0];
|
||||||
|
T max = data[0];
|
||||||
|
for (int i = 1; i < N; i++)
|
||||||
|
{
|
||||||
|
if (data[i] < min) min = data[i];
|
||||||
|
if (data[i] > max) max = data[i];
|
||||||
|
}
|
||||||
|
return max - min;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* һά<D2BB><CEAC><EFBFBD>ݵĿ<DDB5><C4BF>ٸ<EFBFBD><D9B8><EFBFBD>Ҷ<EFBFBD>任 */
|
||||||
|
/************************************************************************/
|
||||||
|
void Caculation::FFT(int n, fftw_complex* in, fftw_complex* out)
|
||||||
|
{
|
||||||
|
if (in == NULL || out == NULL) return;
|
||||||
|
fftw_plan p;
|
||||||
|
p = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||||
|
fftw_execute(p);
|
||||||
|
fftw_destroy_plan(p);
|
||||||
|
fftw_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
//************************************
|
||||||
|
// Method: caculateAmp_Pha
|
||||||
|
// FullName: Caculation::caculateAmp_Pha
|
||||||
|
// Access: public static
|
||||||
|
// Returns: void
|
||||||
|
// Qualifier:
|
||||||
|
// Parameter: int n
|
||||||
|
// Parameter: fftw_complex * in
|
||||||
|
// Parameter: int frequency
|
||||||
|
// Parameter: double & amplitude
|
||||||
|
// Parameter: double & phase
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD><EFBFBD>ض<EFBFBD>Ƶ<EFBFBD>ʵķ<CAB5>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD><C7B4><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>Χ<EFBFBD><CEA7><EFBFBD>ҷ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>λ
|
||||||
|
// Ŀǰ<C4BF>ĺ<EFBFBD><C4BA><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD>FFT<46>任<EFBFBD><E4BBBB><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>ķ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>λ
|
||||||
|
// Ȼ<><C8BB><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ط<EFBFBD><D8B7><EFBFBD>Ҫ<EFBFBD>ģ<DEB8><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʺ<EFBFBD>FFT<46>任<EFBFBD><E4BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
//************************************
|
||||||
|
void Caculation::caculateAmp_Pha(int n, fftw_complex* in, int frequency, double &litude, double &phase)
|
||||||
|
{
|
||||||
|
int index = frequency;
|
||||||
|
amplitude = 2 * sqrt((in[index][0] / n) * (in[index][0] / n) + (in[index][1] / n) * (in[index][1] / n));
|
||||||
|
phase = 180 * atan(in[index][1] / in[index][0]) / M_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* <20><><EFBFBD><EFBFBD>hanning<6E><67><EFBFBD><EFBFBD> */
|
||||||
|
/************************************************************************/
|
||||||
|
template <typename T>
|
||||||
|
vector<T> Caculation::hanning(int N, T amp)
|
||||||
|
{
|
||||||
|
vector<T> win(N);
|
||||||
|
|
||||||
|
for (int i = 0; i < (N + 1) / 2; ++i)
|
||||||
|
{
|
||||||
|
win[i] = amp * T(0.5 - 0.5*cos(2 * M_PI*i / (N - 1)));
|
||||||
|
win[N - 1 - i] = win[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* <20><><EFBFBD><EFBFBD>hamming<6E><67><EFBFBD><EFBFBD> */
|
||||||
|
/************************************************************************/
|
||||||
|
template <typename T>
|
||||||
|
vector<T> Caculation::hamming(int N, T amp)
|
||||||
|
{
|
||||||
|
vector<T> win(N);
|
||||||
|
|
||||||
|
for (int i = 0; i < (N + 1) / 2; ++i)
|
||||||
|
{
|
||||||
|
win[i] = amp * T(0.54 - 0.46*cos(2 * M_PI*i / (N - 1.0)));
|
||||||
|
win[N - 1 - i] = win[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
44
utility/RuleCheck.cpp
Normal file
44
utility/RuleCheck.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* Function Name: valiFoldername
|
||||||
|
* Description: The ength of folder name should be less than 255.
|
||||||
|
* Illegal characters are \<>()[]&:,/|?* \0 ~ \31
|
||||||
|
* Return: 0 for success, otherwise 1.
|
||||||
|
****************************************************************************/
|
||||||
|
#define MAX_FOLDER_NAME_LEN 255
|
||||||
|
|
||||||
|
int validFoldername(const char *pName)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
unsigned int u32Length = 0, u32Index = 0;
|
||||||
|
const char u8SpecialChar[] = { '\\','<','>','(',')','[',']','&',':',',','/','|','?','*' };
|
||||||
|
const unsigned char u8CtrlCharBegin = 0x0, u8CtrlCharEnd = 0x31;
|
||||||
|
|
||||||
|
if (pName == NULL)
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
u32Length = strlen(pName);
|
||||||
|
if (u32Length >= MAX_FOLDER_NAME_LEN)
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
for (u32Index = 0; (u32Index < u32Length) && (ret == 0);
|
||||||
|
u32Index++)
|
||||||
|
{
|
||||||
|
if (u8CtrlCharBegin <= pName[u32Index] <= u8CtrlCharEnd)
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else if (strchr(u8SpecialChar, pName[u32Index]) != NULL)
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
23
utility/SH_MySingleton.hpp
Normal file
23
utility/SH_MySingleton.hpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef MYSINGLETON_H_
|
||||||
|
#define MYSINGLETON_H_
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class MySingleton {
|
||||||
|
public:
|
||||||
|
static T* instance() {
|
||||||
|
static T _instance;
|
||||||
|
return &_instance;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
protected:
|
||||||
|
MySingleton() {
|
||||||
|
}
|
||||||
|
;
|
||||||
|
virtual ~MySingleton() {
|
||||||
|
}
|
||||||
|
;
|
||||||
|
MySingleton(const MySingleton &);
|
||||||
|
MySingleton& operator=(const MySingleton &);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user