no message
This commit is contained in:
parent
072f3d6d17
commit
3e6c3aaf4c
68
.cproject
68
.cproject
@ -14,27 +14,28 @@
|
||||
</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="">
|
||||
<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" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" 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"/>
|
||||
<option id="cdt.managedbuild.option.gnu.cross.path.455008995" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" useByScannerDiscovery="false" value="/home/chaos/WorkSpace/Tools/GatewayToolChain/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"/>
|
||||
<option id="gnu.c.compiler.option.dialect.std.1161366212" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" 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/curl/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"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include"/>
|
||||
</option>
|
||||
<option id="gnu.cpp.compiler.option.dialect.std.745589380" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1387553514" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
@ -42,13 +43,13 @@
|
||||
<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/DataWatchThirdParty/curl/lib"/>
|
||||
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/DataWatchThirdParty/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/DataWatchThirdParty/mqtt1410/lib"/>
|
||||
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/sqlite/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/ssl/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/mqtt1410/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/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"/>
|
||||
@ -74,6 +75,10 @@
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="wifi"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
@ -91,41 +96,42 @@
|
||||
</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="" 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.release.770635657" name="Release" parent="cdt.managedbuild.config.gnu.cross.exe.release" postannouncebuildStep="" postbuildStep="cp WirelessGateway Cidn-SH;arm-linux-gnueabihf-strip Cidn-SH" preannouncebuildStep="" prebuildStep="">
|
||||
<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="" 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.release.770635657" name="Release" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" parent="cdt.managedbuild.config.gnu.cross.exe.release" postannouncebuildStep="" postbuildStep="cp WirelessGateway Cidn-SH;arm-linux-gnueabihf-strip Cidn-SH" preannouncebuildStep="" prebuildStep="">
|
||||
<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.770635657." name="/" resourcePath="">
|
||||
<toolChain errorParsers="" 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"/>
|
||||
<option id="cdt.managedbuild.option.gnu.cross.path.198654844" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" useByScannerDiscovery="false" value="/home/chaos/WorkSpace/Tools/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" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="cdt.managedbuild.builder.gnu.cross.2122902688" 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.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"/>
|
||||
<option id="gnu.c.compiler.option.dialect.std.1960343877" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.842673130" 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.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/curl/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"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp/include"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/sqlite/include"/>
|
||||
</option>
|
||||
<option id="gnu.cpp.compiler.option.dialect.std.411963263" superClass="gnu.cpp.compiler.option.dialect.std" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.option.dialect.std.411963263" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/>
|
||||
<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 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.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/DataWatchThirdParty/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/DataWatchThirdParty/mqtt1410/lib"/>
|
||||
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/DataWatchThirdParty/curl/lib"/>
|
||||
<listOptionValue builtIn="false" value="/nfsroot/eclipse-workspace/GatewayThirdParty/sqlite/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/boost/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/ssl/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/fftw/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/jsoncpp"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/mqtt1410/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/GatewayThirdParty/curl/lib"/>
|
||||
<listOptionValue builtIn="false" value="/home/chaos/WorkSpace/Tools/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"/>
|
||||
@ -151,6 +157,10 @@
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry excluding="wifi" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="wifi"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
|
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
36
.idea/deployment.xml
generated
Normal file
36
.idea/deployment.xml
generated
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PublishConfigData" autoUpload="Always" remoteFilesAllowedToDisappearOnAutoupload="false" autoUploadExternalChanges="true">
|
||||
<serverData>
|
||||
<paths name="2700">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
<paths name="GateWay">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping deploy="/WirelessGateWay" local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
<paths name="Ubuntu 1804 (0bf4dd96-fa07-4e30-b3dd-7b6866ef1d45)">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping deploy="/tmp/tmp.smSOGUIwPR" local="$PROJECT_DIR$" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
<paths name="Ubuntu 1804 (bcc6a232-7b58-4395-91a4-9b50b85b5138)">
|
||||
<serverdata>
|
||||
<mappings>
|
||||
<mapping local="$PROJECT_DIR$" web="/" />
|
||||
</mappings>
|
||||
</serverdata>
|
||||
</paths>
|
||||
</serverData>
|
||||
<option name="myAutoUpload" value="ALWAYS" />
|
||||
</component>
|
||||
</project>
|
18
.idea/misc.xml
generated
Normal file
18
.idea/misc.xml
generated
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MakefileSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<MakefileProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="version" value="2" />
|
||||
</MakefileProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
<component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
</project>
|
10
.idea/other.xml
generated
Normal file
10
.idea/other.xml
generated
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoUploadManager">
|
||||
<option name="hosts">
|
||||
<list>
|
||||
<option value="0bf4dd96-fa07-4e30-b3dd-7b6866ef1d45" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
0
.metadata/.lock
Normal file
0
.metadata/.lock
Normal file
1292
.metadata/.log
Normal file
1292
.metadata/.log
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding=UTF-8
|
||||
version=1
|
@ -5,7 +5,7 @@
|
||||
<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="-1795775469460424669" 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">
|
||||
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="404423593970676640" 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>
|
||||
@ -16,7 +16,7 @@
|
||||
<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="-1795775469460424669" 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">
|
||||
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-512096857405592295" 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>
|
||||
|
73
.vscode/settings.json
vendored
Normal file
73
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"csignal": "cpp",
|
||||
"ctime": "cpp",
|
||||
"strstream": "cpp",
|
||||
"bitset": "cpp",
|
||||
"chrono": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"complex": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"ratio": "cpp",
|
||||
"future": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"mutex": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"thread": "cpp",
|
||||
"cfenv": "cpp",
|
||||
"typeindex": "cpp"
|
||||
}
|
||||
}
|
@ -7,7 +7,8 @@
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/SH_global.h"
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
|
||||
struct _LogParam {
|
||||
pthread_mutex_t *m_mutex;
|
||||
@ -33,7 +34,8 @@ int log_init(const char* file_name, int log_buf_size, int limit_size)
|
||||
|
||||
struct timeval now = {0,0};
|
||||
gettimeofday(&now, NULL);
|
||||
time_t t = now.tv_sec;
|
||||
time_t t ;
|
||||
t = now.tv_sec;
|
||||
struct tm* sys_tm = localtime(&t);
|
||||
char fileTime[20]={0x00};
|
||||
char fileName[100]={0x00};
|
||||
@ -46,6 +48,16 @@ int log_init(const char* file_name, int log_buf_size, int limit_size)
|
||||
|
||||
void log_write(const char *level, const char* format, ...)
|
||||
{
|
||||
struct timeval now = {0,0};
|
||||
gettimeofday(&now, NULL);
|
||||
time_t t;
|
||||
t = now.tv_sec;
|
||||
struct tm* sys_tm = localtime(&t);
|
||||
char fileTime[20]={0x00};
|
||||
char fileName[100]={0x00};
|
||||
int n = snprintf(fileTime, 64, "%d-%02d-%02d.log", sys_tm->tm_year+1900, sys_tm->tm_mon+1, sys_tm->tm_mday);
|
||||
sprintf(fileName,"%s%s",SOFTWARE_RUN_LOG,fileTime);
|
||||
strcpy(gLogParam.m_log_full_name, fileName);
|
||||
FILE *fp = fopen(gLogParam.m_log_full_name, "a");
|
||||
if(fp == NULL) {
|
||||
return;
|
||||
@ -53,15 +65,10 @@ void log_write(const char *level, const char* format, ...)
|
||||
|
||||
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,
|
||||
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);
|
||||
|
||||
|
||||
|
304
MD5/md5.cpp
Normal file
304
MD5/md5.cpp
Normal file
@ -0,0 +1,304 @@
|
||||
#include "md5.h"
|
||||
|
||||
#ifndef HAVE_OPENSSL
|
||||
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
|
||||
#define STEP(f, a, b, c, d, x, t, s) \
|
||||
(a) += f((b), (c), (d)) + (x) + (t); \
|
||||
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
|
||||
(a) += (b);
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||
#define SET(n) \
|
||||
(*(MD5_u32 *)&ptr[(n) * 4])
|
||||
#define GET(n) \
|
||||
SET(n)
|
||||
#else
|
||||
#define SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(MD5_u32)ptr[(n) * 4] | \
|
||||
((MD5_u32)ptr[(n) * 4 + 1] << 8) | \
|
||||
((MD5_u32)ptr[(n) * 4 + 2] << 16) | \
|
||||
((MD5_u32)ptr[(n) * 4 + 3] << 24))
|
||||
#define GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
typedef unsigned int MD5_u32;
|
||||
|
||||
typedef struct {
|
||||
MD5_u32 lo, hi;
|
||||
MD5_u32 a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
MD5_u32 block[16];
|
||||
} MD5_CTX;
|
||||
|
||||
static void MD5_Init(MD5_CTX *ctx);
|
||||
static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
|
||||
static void MD5_Final(unsigned char *result, MD5_CTX *ctx);
|
||||
|
||||
static const void *body(MD5_CTX *ctx, const void *data, unsigned long size){
|
||||
const unsigned char *ptr;
|
||||
MD5_u32 a, b, c, d;
|
||||
MD5_u32 saved_a, saved_b, saved_c, saved_d;
|
||||
|
||||
ptr = (const unsigned char*)data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
|
||||
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
|
||||
STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
|
||||
STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
|
||||
STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
|
||||
STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
|
||||
STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
|
||||
STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
|
||||
STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
|
||||
STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
|
||||
STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
|
||||
STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
|
||||
STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
|
||||
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
|
||||
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
|
||||
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
|
||||
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
|
||||
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
|
||||
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
|
||||
STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
|
||||
STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
|
||||
STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
|
||||
STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
|
||||
STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
|
||||
STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
|
||||
STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
|
||||
STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
|
||||
STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
|
||||
STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
|
||||
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
|
||||
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
|
||||
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
|
||||
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
|
||||
STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
|
||||
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
|
||||
STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
|
||||
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
|
||||
STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
|
||||
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
|
||||
STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
|
||||
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
|
||||
STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
|
||||
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
|
||||
STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
|
||||
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
|
||||
STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
|
||||
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
|
||||
STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
|
||||
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
|
||||
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
|
||||
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
|
||||
STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
|
||||
STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
|
||||
STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
|
||||
STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
|
||||
STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
|
||||
STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
|
||||
STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
|
||||
STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
|
||||
STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
|
||||
STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
|
||||
STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
|
||||
STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
|
||||
STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MD5_Init(MD5_CTX *ctx){
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size){
|
||||
MD5_u32 saved_lo;
|
||||
unsigned long used, free;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += size >> 29;
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used){
|
||||
free = 64 - used;
|
||||
if (size < free) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, free);
|
||||
data = (unsigned char *)data + free;
|
||||
size -= free;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(unsigned long)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
void MD5_Final(unsigned char *result, MD5_CTX *ctx){
|
||||
unsigned long used, free;
|
||||
used = ctx->lo & 0x3f;
|
||||
ctx->buffer[used++] = 0x80;
|
||||
free = 64 - used;
|
||||
|
||||
if (free < 8) {
|
||||
memset(&ctx->buffer[used], 0, free);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
free = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, free - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
ctx->buffer[56] = ctx->lo;
|
||||
ctx->buffer[57] = ctx->lo >> 8;
|
||||
ctx->buffer[58] = ctx->lo >> 16;
|
||||
ctx->buffer[59] = ctx->lo >> 24;
|
||||
ctx->buffer[60] = ctx->hi;
|
||||
ctx->buffer[61] = ctx->hi >> 8;
|
||||
ctx->buffer[62] = ctx->hi >> 16;
|
||||
ctx->buffer[63] = ctx->hi >> 24;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
result[0] = ctx->a;
|
||||
result[1] = ctx->a >> 8;
|
||||
result[2] = ctx->a >> 16;
|
||||
result[3] = ctx->a >> 24;
|
||||
result[4] = ctx->b;
|
||||
result[5] = ctx->b >> 8;
|
||||
result[6] = ctx->b >> 16;
|
||||
result[7] = ctx->b >> 24;
|
||||
result[8] = ctx->c;
|
||||
result[9] = ctx->c >> 8;
|
||||
result[10] = ctx->c >> 16;
|
||||
result[11] = ctx->c >> 24;
|
||||
result[12] = ctx->d;
|
||||
result[13] = ctx->d >> 8;
|
||||
result[14] = ctx->d >> 16;
|
||||
result[15] = ctx->d >> 24;
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
#else
|
||||
#include <openssl/md5.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* Return Calculated raw result(always little-endian), the size is always 16 */
|
||||
void md5bin(const void* dat, size_t len, unsigned char out[16]) {
|
||||
MD5_CTX c;
|
||||
MD5_Init(&c);
|
||||
MD5_Update(&c, dat, len);
|
||||
MD5_Final(out, &c);
|
||||
}
|
||||
|
||||
static char hb2hex(unsigned char hb) {
|
||||
hb = hb & 0xF;
|
||||
return hb < 10 ? '0' + hb : hb - 10 + 'a';
|
||||
}
|
||||
|
||||
string md5file(const char* filename){
|
||||
printf("file = %s\n",filename);
|
||||
FILE* file = fopen(filename, "rb");
|
||||
string res = md5file(file);
|
||||
fclose(file);
|
||||
return res;
|
||||
}
|
||||
|
||||
string md5file(FILE* file){
|
||||
|
||||
MD5_CTX c;
|
||||
MD5_Init(&c);
|
||||
|
||||
char buff[BUFSIZ];
|
||||
unsigned char out[16];
|
||||
size_t len = 0;
|
||||
while( ( len = fread(buff ,sizeof(char), BUFSIZ, file) ) > 0) {
|
||||
MD5_Update(&c, buff, len);
|
||||
}
|
||||
MD5_Final(out, &c);
|
||||
|
||||
string res;
|
||||
for(size_t i = 0; i < 16; ++ i) {
|
||||
res.push_back(hb2hex(out[i] >> 4));
|
||||
res.push_back(hb2hex(out[i]));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
string md5(const void* dat, size_t len) {
|
||||
string res;
|
||||
unsigned char out[16];
|
||||
md5bin(dat, len, out);
|
||||
for(size_t i = 0; i < 16; ++ i) {
|
||||
res.push_back(hb2hex(out[i] >> 4));
|
||||
res.push_back(hb2hex(out[i]));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string md5(std::string dat){
|
||||
return md5(dat.c_str(), dat.length());
|
||||
}
|
||||
|
||||
/* Generate shorter md5sum by something like base62 instead of base16 or base10. 0~61 are represented by 0-9a-zA-Z */
|
||||
string md5sum6(const void* dat, size_t len){
|
||||
static const char* tbl = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
string res;
|
||||
unsigned char out[16];
|
||||
md5bin(dat, len, out);
|
||||
for(size_t i = 0; i < 6; ++i) {
|
||||
res.push_back(tbl[out[i] % 62]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string md5sum6(std::string dat){
|
||||
return md5sum6(dat.c_str(), dat.length() );
|
||||
}
|
16
MD5/md5.h
Normal file
16
MD5/md5.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef MD5_H
|
||||
#define MD5_H
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
std::string md5(std::string dat);
|
||||
std::string md5(const void* dat, size_t len);
|
||||
extern std::string md5file(const char* filename);
|
||||
std::string md5file(FILE* file);
|
||||
std::string md5sum6(std::string dat);
|
||||
std::string md5sum6(const void* dat, size_t len);
|
||||
|
||||
#endif // end of MD5_H
|
30
Makefile
30
Makefile
@ -2,22 +2,24 @@ 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/
|
||||
CC = ${CXX}
|
||||
STRIP = aarch64-poky-linux-strip
|
||||
INCLUDES = -I../Tools/GatewayThirdParty/boost/include \
|
||||
-I../Tools/GatewayThirdParty/fftw/include \
|
||||
-I../Tools/GatewayThirdParty/jsoncpp/include \
|
||||
-I../Tools/GatewayThirdParty/sqlite/include/ \
|
||||
-I../Tools/GatewayThirdParty/curl/include/ \
|
||||
-I ./ \
|
||||
|
||||
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
|
||||
LIBS = -L../Tools/renesas_thirdparty/lib \
|
||||
-L../Tools/renesas_thirdparty/lib \
|
||||
-L../Tools/renesas_thirdparty/lib \
|
||||
-L../Tools/renesas_thirdparty/lib \
|
||||
-L../Tools/renesas_thirdparty/lib \
|
||||
-L../Tools/renesas_thirdparty/lib \
|
||||
-lsqlite3 -lboost_system -lpthread -lboost_thread -lboost_date_time -lfftw3 -ljsoncpp -lmosquitto -lcurl
|
||||
|
||||
CFLAGS = -O2 #-Wall -Werror
|
||||
CFLAGS = -O0 -fpermissive #-Wall -Werror
|
||||
LINKFLAGS =
|
||||
|
||||
AllDirs :=$(shell ls -R | grep '^\./.*:' | awk '{if( \
|
||||
|
@ -60,7 +60,46 @@ void Calculation::iFFT(int n, fftw_complex* in, fftw_complex* out)
|
||||
fftw_destroy_plan(p);
|
||||
fftw_cleanup();
|
||||
}
|
||||
void Calculation::_iFFT( std::vector<float> & vecrealData,std::vector<float> & vecimageData,std::vector<float> & veciFFTData)
|
||||
{
|
||||
fftw_complex *inFFt, *outFFt;
|
||||
int N = vecrealData.size();
|
||||
inFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);
|
||||
outFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * N);
|
||||
|
||||
for (int j = 0; j < N; j++) {
|
||||
inFFt[j][0] = (double)vecrealData[j];
|
||||
inFFt[j][1] = (double)vecimageData[j];
|
||||
}
|
||||
iFFT(N,inFFt, outFFt);
|
||||
for (int i = 0; i < N; i++) {
|
||||
outFFt[i][0] *= 1./N;
|
||||
outFFt[i][1] *= 1./N;
|
||||
veciFFTData.push_back(outFFt[i][0]);
|
||||
}
|
||||
fftw_free(inFFt);
|
||||
fftw_free(outFFt);
|
||||
}
|
||||
void Calculation::_FFT(std::vector<float> & vecData, std::vector<float> & vecFFTrealData,std::vector<float> & vecFFTimageData)
|
||||
{
|
||||
fftw_complex *inHilFFt, *outHilFFt;
|
||||
inHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecData.size());
|
||||
outHilFFt = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * vecData.size());
|
||||
|
||||
for (int j = 0; j < vecData.size(); j++) {
|
||||
inHilFFt[j][0] = (double)vecData[j];
|
||||
inHilFFt[j][1] = 0;
|
||||
}
|
||||
|
||||
FFT(vecData.size(), inHilFFt, outHilFFt);
|
||||
fftShift(outHilFFt, vecData.size());
|
||||
for (int i = 0; i < vecData.size(); i++) {
|
||||
vecFFTrealData.push_back(outHilFFt[i][0]);
|
||||
vecFFTimageData.push_back(outHilFFt[i][1]);
|
||||
}
|
||||
fftw_free(inHilFFt);
|
||||
fftw_free(outHilFFt);
|
||||
}
|
||||
//************************************
|
||||
// Method: caculateAmp_Pha
|
||||
// FullName: Calculation::caculateAmp_Pha
|
||||
@ -155,6 +194,22 @@ float Calculation::rms(std::vector<float> & vecData)
|
||||
}
|
||||
|
||||
|
||||
|
||||
float Calculation::getSample_variance(std::vector<float> a)
|
||||
{
|
||||
float ss = 0;
|
||||
float s = 0;
|
||||
float mx = mean(a);
|
||||
int len = a.size();
|
||||
for (int i = 0; i < len; i++) {
|
||||
s = a[i] - mx;
|
||||
ss += pow(s, 2);
|
||||
}
|
||||
return ss / (len - 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float Calculation::variance(std::vector<float> & vecDropMeanData)
|
||||
{
|
||||
double varianceTemp = 0;
|
||||
@ -187,7 +242,43 @@ float Calculation::kurtosis(std::vector<float> & vecDropMeanData, float fVarianc
|
||||
tempkurtosis = tempkurtosis / pow(fVariance, 2);
|
||||
return tempkurtosis;
|
||||
}
|
||||
void Calculation::Hanning(std::vector<float> & vecData,std::vector<float> & vecHanningData)
|
||||
{
|
||||
int N = vecData.size();
|
||||
|
||||
float* w = NULL;
|
||||
w = (float*)calloc(N, sizeof(float));
|
||||
int half, i, idx;
|
||||
if (N % 2 == 0)
|
||||
{
|
||||
half = N / 2;
|
||||
for (i = 0; i < half; i++) //CALC_HANNING Calculates Hanning window samples.
|
||||
w[i] = 0.5 * (1 - cos(2 * pi * (i + 1) / (N + 1)));
|
||||
|
||||
|
||||
idx = half - 1;
|
||||
for (i = half; i < N; i++) {
|
||||
w[i] = w[idx];
|
||||
idx--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
half = (N + 1) / 2;
|
||||
for (i = 0; i < half; i++) //CALC_HANNING Calculates Hanning window samples.
|
||||
w[i] = 0.5 * (1 - cos(2 * pi * (i + 1) / (N + 1)));
|
||||
|
||||
idx = half - 2;
|
||||
for (i = half; i < N; i++) {
|
||||
w[i] = w[idx];
|
||||
idx--;
|
||||
}
|
||||
}
|
||||
for(int j = 0; j < N;j++){
|
||||
vecHanningData.push_back(w[j]);
|
||||
}
|
||||
free(w);
|
||||
}
|
||||
void Calculation::hilbert(std::vector<float> & vecData, std::vector<float> & vecHilbertData, int N)
|
||||
{
|
||||
|
||||
@ -253,6 +344,7 @@ void Calculation::hilbert(std::vector<float> & vecData, std::vector<float> & vec
|
||||
vecHilbertData.push_back(amp);
|
||||
// printf("%d %f\n",n,vecHilbertData[n]);
|
||||
}
|
||||
fftw_free(out);
|
||||
}
|
||||
|
||||
|
||||
@ -289,9 +381,9 @@ void Calculation::FFTSpec(std::vector<float> & vecData, std::vector<float> & vec
|
||||
|
||||
}
|
||||
|
||||
void Calculation::envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData)
|
||||
void Calculation::envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData,int StartFrequency,int EndFrequency)
|
||||
{
|
||||
std::vector<float> vecDropMeanData;
|
||||
/*std::vector<float> vecDropMeanData;
|
||||
drop_mean(vecDropMeanData, vecData);
|
||||
|
||||
std::vector<float> vecHilbertData;
|
||||
@ -313,5 +405,42 @@ void Calculation::envSpec(std::vector<float> & vecData, std::vector<float> & vec
|
||||
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);
|
||||
}*/
|
||||
std::vector<float> vecFFTrealData,vecFFTimageData;
|
||||
std::vector<float> vecRealData,vecImageData;
|
||||
std::vector<float> veciFFtData;
|
||||
std::vector<float> veciFFtData2;
|
||||
std::vector<float> vecHilbertData;
|
||||
_FFT(vecData,vecFFTrealData,vecFFTimageData);
|
||||
for(int i = 0; i < vecFFTrealData.size();i++){
|
||||
if(i > StartFrequency && i < EndFrequency){
|
||||
vecRealData.push_back(vecFFTrealData.at(i));
|
||||
vecImageData.push_back(vecFFTimageData.at(i));
|
||||
}else{
|
||||
vecRealData.push_back(0);
|
||||
vecImageData.push_back(0);
|
||||
}
|
||||
}
|
||||
_iFFT(vecRealData,vecImageData,veciFFtData);
|
||||
for(int j = 0; j < veciFFtData.size();j++){
|
||||
veciFFtData2.push_back(veciFFtData[j]*2);
|
||||
}
|
||||
hilbert(veciFFtData2,vecHilbertData,veciFFtData2.size());
|
||||
FFTSpec(vecHilbertData, vecEnvSpecData);
|
||||
}
|
||||
|
||||
|
||||
void Calculation::GenerateSin(std::vector<float> & vecData)
|
||||
{
|
||||
int i;
|
||||
int ft = 1; /* 周期 hz */
|
||||
int fs = 12800; /* 采样频率*/
|
||||
|
||||
/* generate data */
|
||||
int data_len = (8*1024);
|
||||
|
||||
for (i = 0; i < data_len; i++) {
|
||||
vecData.push_back(sin(1000 * 2 *3.1415926*ft*i/fs));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -75,7 +75,8 @@ public:
|
||||
|
||||
float rms(std::vector<float> & vecData);
|
||||
|
||||
|
||||
//获取样本方差
|
||||
float getSample_variance(std::vector<float> a);
|
||||
|
||||
//去数据的直流分量
|
||||
|
||||
@ -105,7 +106,8 @@ public:
|
||||
|
||||
float kurtosis(std::vector<float> & vecDropMeanData, float fVariance);
|
||||
|
||||
|
||||
//hanning 窗
|
||||
void Hanning(std::vector<float> & vecData,std::vector<float> & vecHanningData);
|
||||
|
||||
//快速傅里叶变换函数
|
||||
|
||||
@ -122,8 +124,8 @@ public:
|
||||
//快速傅里叶逆变换
|
||||
|
||||
void iFFT(int n, fftw_complex* in, fftw_complex* out);
|
||||
|
||||
|
||||
void _iFFT(std::vector<float> & vecData, std::vector<float> & vecFFTSpecData,std::vector<float> & veciFFTData);
|
||||
void _FFT(std::vector<float> & vecData, std::vector<float> & vecFFTrealData,std::vector<float> & vecFFTimageData);
|
||||
|
||||
//通道幅值和相位提取
|
||||
|
||||
@ -139,7 +141,8 @@ public:
|
||||
|
||||
|
||||
|
||||
|
||||
//生成正弦信号
|
||||
void GenerateSin(std::vector<float> & vecData);
|
||||
|
||||
//FFT shift
|
||||
|
||||
@ -147,7 +150,7 @@ public:
|
||||
//频谱图数据
|
||||
void FFTSpec(std::vector<float> & vecData, std::vector<float> & vecFFTSpecData);
|
||||
//包络图谱数据
|
||||
void envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData);
|
||||
void envSpec(std::vector<float> & vecData, std::vector<float> & vecEnvSpecData,int StartFrequency,int EndFrequency);
|
||||
};
|
||||
|
||||
|
||||
|
20
common/Mutex.h
Normal file
20
common/Mutex.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef _MY_COMM_H_
|
||||
#define _MY_COMM_H_
|
||||
#include <pthread.h>
|
||||
|
||||
class Mutex {
|
||||
private:
|
||||
pthread_mutex_t mutex;
|
||||
public:
|
||||
Mutex() { mutex = PTHREAD_MUTEX_INITIALIZER;pthread_mutex_init(&mutex,NULL); /*printf("\n pthread_mutex_init \n");*/}
|
||||
virtual ~Mutex() {pthread_mutex_destroy(&mutex); /*printf("\n pthread_mutex_destroy \n");*/}
|
||||
void Lock() {pthread_mutex_lock(&mutex); /*printf("\n mutex lock \n");*/}
|
||||
void UnLock() {pthread_mutex_unlock(&mutex); /*printf("\n mutex unlock \n");*/}
|
||||
};
|
||||
//Mutex g_Mutex;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //_MY_COMM_H_
|
File diff suppressed because it is too large
Load Diff
@ -26,10 +26,19 @@
|
||||
#include <sys/ipc.h>//ipc
|
||||
#include <sys/shm.h>
|
||||
#include "dirent.h"
|
||||
#include <iconv.h>
|
||||
#include <termios.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netdb.h>
|
||||
#include "Mutex.h"
|
||||
|
||||
typedef struct statfs DISK,*pDISK;
|
||||
|
||||
|
||||
|
||||
#define SECTION_MAX_LEN 256
|
||||
#define STRVALUE_MAX_LEN 256
|
||||
#define LINE_CONTENT_MAX_LEN 256
|
||||
//配置文件位置
|
||||
#define NETWORK "/etc/network/interfaces"
|
||||
#define SYSTEMINFOFILE "/opt/configenv/SystemInfo.json" //系统信息
|
||||
@ -43,6 +52,7 @@
|
||||
#define SN "/opt/system/sn" //设备序列号
|
||||
#define SYSTEMSTART "/opt/system/start" //系统启动类型标志 0:正常启动 1:重启 2:
|
||||
#define BUILD_UINT16(x,y) (((x & 0x00FFu) << 8u) | (y & 0x00FFu))
|
||||
#define BUILD_UINT2(x,y) (((x) << 2u) | (y))
|
||||
// 生成UINT32 数据
|
||||
#define BUILD_UINT32(u,v,x,y) (((u & 0x00FFu) << 24u) | (v & 0x00FFu) << 16u) | (((x & 0x00FFu) << 8u) | (y & 0x00FFu))
|
||||
// 获取UINT32的高低字节
|
||||
@ -50,16 +60,18 @@
|
||||
#define UINT32_HIGH_2(x) ((x & 0x00FF0000u) >> 16u)
|
||||
#define UINT32_LOW_1(x) ((x & 0x0000FF00u) >> 8u)
|
||||
#define UINT32_LOW_2(x) ((x & 0x000000FFu))
|
||||
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit) /* 获取第bit位 */
|
||||
// 获取UINT32的高低字节
|
||||
#define UINT16_HIGH(x) ((x & 0xFF00u) >> 8u)
|
||||
#define UINT16_LOW(x) ((x & 0x00FFu))
|
||||
|
||||
#define onlineCheck 21600
|
||||
|
||||
#define GENERAL_BUF_SIZE 128*1024*10
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
enum TIME_SIZE{
|
||||
TIME_MINUTE=5,
|
||||
TIME_SECEOND=8
|
||||
@ -108,6 +120,8 @@ struct ZigbeeInfo {
|
||||
std::string PanID;
|
||||
std::string MyAddr;
|
||||
std::string DstAddr;
|
||||
std::string RetryNum;
|
||||
std::string TranTimeout;
|
||||
};
|
||||
|
||||
struct ZIGBEE {
|
||||
@ -183,7 +197,9 @@ struct DataNodeInfo {
|
||||
|
||||
std::string ConfigDate;//配置时间
|
||||
int VIntegralFilterFrequency;//速度积分滤波频率
|
||||
|
||||
DataNodeInfo(){
|
||||
FeatureInterVal = 0;WaveInterVal = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -205,6 +221,7 @@ struct DataRecvDym {
|
||||
float Amp3;
|
||||
float Amp4;
|
||||
float Amp5;
|
||||
long Time;
|
||||
float Phase1;
|
||||
float Phase2;
|
||||
float Phase3;
|
||||
@ -221,6 +238,7 @@ struct TopicList{
|
||||
std::string mPubWaveSecondData; //原始数据发布主题
|
||||
std::string mPubCmd; //命令控制发布主题
|
||||
std::string mPubRep;
|
||||
std::string mPubTiming; //校时
|
||||
|
||||
std::string mPubLocalWifi;
|
||||
std::string mPubLocalWaveServer;
|
||||
@ -263,6 +281,25 @@ typedef struct {
|
||||
} WAVE_GENERAL;
|
||||
|
||||
|
||||
typedef struct{
|
||||
int zigAckrep;
|
||||
int zigAckreset;
|
||||
int zigReset;
|
||||
int zigDef;
|
||||
int alarmLight;
|
||||
int commPower;//4G,5G 电源开关
|
||||
int vol3_8;//5G 3.8v电源
|
||||
int commRest;//4G,5G复位
|
||||
int wifiPower;//WiFi 电源开关
|
||||
int wifiReset;//WiFi 复位
|
||||
int hardWatchDog;
|
||||
int power;
|
||||
int runLed;
|
||||
int errorLed;
|
||||
int netResetNet0;
|
||||
int netResetNet1;
|
||||
} GPIOInfo;
|
||||
|
||||
struct Param_01 {
|
||||
int mMode; //0:登陆 1:更改密码
|
||||
std::string mUserName;
|
||||
@ -302,7 +339,10 @@ struct Param_23 {
|
||||
std::string mServerIp;
|
||||
std::string mPort;
|
||||
std::string mCommMode; // 通信模式,有线通信模式 = 1;4G LTE 无线通信模式 = 2
|
||||
Param_23():mMode(0),mCmdSerial(""), mServerIp(""),mPort(""),mCommMode(""){};
|
||||
std::string mUserName;
|
||||
std::string mPassword;
|
||||
std::string mAPN;
|
||||
Param_23():mMode(0),mCmdSerial(""), mServerIp(""),mPort(""),mCommMode(""),mUserName("chaos"),mPassword("HSD272*#xkd"),mAPN(""){};
|
||||
};
|
||||
|
||||
|
||||
@ -317,6 +357,7 @@ struct Param_24 {
|
||||
|
||||
struct Param_25 {
|
||||
int mMode;
|
||||
std::string mNet;
|
||||
std::string mCmdSerial;
|
||||
std::string mDnsName;
|
||||
std::string mNetworkPortStatus;
|
||||
@ -327,12 +368,29 @@ struct Param_25 {
|
||||
Param_25():mMode(0),mCmdSerial(""), mDnsName(""),mGateway(""),mSubnetMask(""),mIp(""),mHostName(""){};
|
||||
};
|
||||
|
||||
|
||||
struct Param_09 {
|
||||
int mPackageFlag;
|
||||
Param_09():mPackageFlag(0){};
|
||||
};
|
||||
struct Param_10 {
|
||||
std::string strDataNode;
|
||||
std::string strStatic;
|
||||
std::string straxis;
|
||||
std::string timeStart;
|
||||
std::string timeEnd;
|
||||
int mPackageFlag;
|
||||
Param_10():strDataNode(""),strStatic(""),mPackageFlag(0){};
|
||||
};
|
||||
struct Param_11 {
|
||||
std::string DataNodeNo;
|
||||
Param_11():DataNodeNo(""){};
|
||||
};
|
||||
struct Param_26 {
|
||||
int mMode;
|
||||
std::string mCmdSerial;
|
||||
std::string mDataNodeNo;
|
||||
Param_26():mMode(0),mCmdSerial(""),mDataNodeNo(""){};
|
||||
int mPackageFlag;
|
||||
Param_26():mMode(0),mCmdSerial(""),mDataNodeNo(""),mPackageFlag(0){};
|
||||
|
||||
};
|
||||
|
||||
@ -368,6 +426,34 @@ struct Param_30 {
|
||||
int mPackageFlag;
|
||||
Param_30():mMode(0),mChannelId(""),mDataNodeNo(""),mPackageFlag(0){};
|
||||
};
|
||||
struct Param_40 {
|
||||
int mMode;
|
||||
std::string mChannelId;
|
||||
std::string mDataNodeNo;
|
||||
int mPackageFlag;
|
||||
int StartFrequency;
|
||||
int EndFrequency;
|
||||
Param_40():mMode(0),mChannelId(""),mDataNodeNo(""),mPackageFlag(0),StartFrequency(0),EndFrequency(0){};
|
||||
};
|
||||
struct Param_41 {
|
||||
std::string mdataNodeNo;
|
||||
int mfeatureInterVal;
|
||||
int mwaveInterVal;
|
||||
int msamplingRate;
|
||||
int mrange;
|
||||
int mAccSampleTime;
|
||||
std::string mstartBrands;
|
||||
std::string mstopBrands;
|
||||
std::string menvelopeBandPass;
|
||||
int mviff;
|
||||
std::string mfaultFrequency;
|
||||
Param_41():mdataNodeNo(""),mfeatureInterVal(0),mwaveInterVal(0),msamplingRate(0),mrange(0),mAccSampleTime(0),\
|
||||
mstartBrands(""),mstopBrands(""),menvelopeBandPass(""),mviff(0),mfaultFrequency(""){};
|
||||
};
|
||||
struct Param_42 {
|
||||
string fileName;
|
||||
Param_42():fileName(""){};
|
||||
};
|
||||
|
||||
struct Param_31 {
|
||||
int mMode;
|
||||
@ -376,13 +462,13 @@ struct Param_31 {
|
||||
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;
|
||||
@ -443,11 +529,53 @@ struct Param_47 {
|
||||
std::string mFileName;
|
||||
Param_47():mMode(0),mFileName(""){};
|
||||
};
|
||||
struct Param_51 {
|
||||
int mMode;
|
||||
string strGateWayMAC;
|
||||
string strGateWayLocation;
|
||||
Param_51():mMode(-1),strGateWayLocation(""){};
|
||||
};
|
||||
struct Param_52 {
|
||||
int mMode;
|
||||
std::string mCmdSerial;
|
||||
string mSsid;
|
||||
string mPassWord;
|
||||
};
|
||||
struct Param_53 {
|
||||
int mMode;
|
||||
string mdataNodeNo;
|
||||
string mUpdateKey;
|
||||
string mUpdateValue;
|
||||
string mUpdateKey2;
|
||||
string mUpdateValue2;
|
||||
string mUpdateKey3;
|
||||
string mUpdateValue3;
|
||||
Param_53():mUpdateKey2(""),mUpdateValue2(""),mUpdateKey3(""),mUpdateValue3(""){};
|
||||
};
|
||||
|
||||
typedef struct DataNodeUpdate{
|
||||
std::string strUpdataFileName;
|
||||
std::string strSoftVersion;
|
||||
std::vector <std::string> hwVersion;
|
||||
};
|
||||
|
||||
|
||||
struct ethtool_value {
|
||||
unsigned int cmd;
|
||||
unsigned int data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
extern std::string GBKToUTF8(const std::string& strGBK);
|
||||
extern std::string UTFtoGBK(const char* utf8);
|
||||
extern string GetLocalTimeWithMs(void);
|
||||
extern void InitGpio(unsigned int gpioN,unsigned int inout);
|
||||
extern int gpio_set(unsigned int gpioN,char x);
|
||||
extern int gpio_read(unsigned int gpioN);
|
||||
extern int config_uart(const char* Port,speed_t speed);
|
||||
extern int write_data(int fd, char *buff, int len);
|
||||
extern int read_data(int fd, char *buff, int len, int timeout);
|
||||
extern int ModifyMac(char* buff);
|
||||
//extern int str_recv(int fd, char srcshow,char* buffer);
|
||||
/**
|
||||
* @brief 系统运行时输入入参进行系统软件版本查询
|
||||
* @param argv 输入参数 -vV版本查询 --debugmode日志调试模式
|
||||
@ -477,7 +605,6 @@ extern int system_custom(const char *cmd, char *buf);
|
||||
*/
|
||||
extern void WriteMemoryInfo();
|
||||
|
||||
|
||||
/**
|
||||
* @brief 获取当前日期
|
||||
* @return 当前日期的string
|
||||
@ -497,7 +624,7 @@ extern void GetTime_(char * time_buff,TIME_SIZE len) ;
|
||||
* @return void
|
||||
*/
|
||||
extern void GetTimeNet(char* timebuf, int type);
|
||||
|
||||
extern std::string GetRTC(char* timebuf, int& millisecond);
|
||||
/**
|
||||
* @brief 从配置文件中读取数据
|
||||
* @param filename 配置文件名
|
||||
@ -521,7 +648,7 @@ extern int WriteStr2Config(std::string filename, std::string config, std::string
|
||||
* @brief 获取设备的MAC地址做为设备的唯一标识
|
||||
* @return std::string Mac地址
|
||||
*/
|
||||
extern std::string GetLocalMac();
|
||||
extern std::string GetLocalMac(const char* net);
|
||||
|
||||
/**
|
||||
* @brief 获取设备IP
|
||||
@ -597,14 +724,45 @@ extern void ZoneConfig(std::string zoneid);
|
||||
* @return std::string CPU MEM DISK info
|
||||
*/
|
||||
extern std::string GetSysStatus();
|
||||
|
||||
double GetHardDiskFree();
|
||||
extern bool CheckIP(const char *ip);
|
||||
|
||||
bool IsValidMask(std::string mask);
|
||||
//read update config file
|
||||
extern std::vector <std::string> ReadStrByOpt(std::string filename,std::string& strUpdataFileName);
|
||||
extern std::vector <DataNodeUpdate> ReadStrUpdate(std::string filename);
|
||||
|
||||
extern void ReadStrConfig(std::string filename);
|
||||
extern int UpdataDataNodeConfig(std::string filename);
|
||||
extern char* solve(char *dest,const char *src);
|
||||
extern void swap(char *data);
|
||||
|
||||
extern int OpenWatchDog();
|
||||
extern int WriteWatchDog(int fd);
|
||||
extern int CloseWatchDog(int fd);
|
||||
//获取4G信号强度
|
||||
extern int getcsq();
|
||||
extern std::string GetGwIp_(const char *eth_name);
|
||||
extern string GetOneContent(const char* szData, int nRow, const char* szSeparate);
|
||||
extern int readStringValue(const char* section, char* key, char* val, const char* file);
|
||||
extern int writeStringVlaue(const char* section, char* key, char* val, const char* file);
|
||||
extern int readIntValue(const char* section, char* key, const char* file);
|
||||
extern int writeIntValue(const char* section, char* key, int val, const char* file);
|
||||
|
||||
int getDiskInfo(char* diskTotal,char* diskFree);
|
||||
|
||||
void timeout(int signo);
|
||||
unsigned short cal_chksum(unsigned short *addr,int len);
|
||||
int pack(int pkt_no,char *sendpacket);
|
||||
int send_packet(int pkt_no,char *sendpacket);
|
||||
int recv_packet(int pkt_no,char *recvpacket);
|
||||
int unpack(int cur_seq,char *buf,int len);
|
||||
void tv_sub(struct timeval *out,struct timeval *in);
|
||||
void _CloseSocket();
|
||||
|
||||
int socketHeart(const char* pSendData);
|
||||
|
||||
extern bool NetIsOk();
|
||||
extern int Ping( const char *ips, int timeout);
|
||||
extern int get_netlink_status(const char *if_name);
|
||||
extern Mutex g_tDbMutex;
|
||||
#endif
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "SH_CommonFunc.hpp"
|
||||
#include "../mqttclient/SH_MqttClient.h"
|
||||
|
||||
|
||||
#define SECTION_MAX_LEN 1024
|
||||
//******************** 全局变量**********************
|
||||
enum enumZigBeeTransmitStatus {
|
||||
NO_ENTER_TRANSMITTING_STATUS = 0,
|
||||
@ -17,6 +19,13 @@ enum enumZigBeeTransmitStatus {
|
||||
};
|
||||
|
||||
|
||||
//#define NR5G_MODULE
|
||||
//#define Q4G_MODULE
|
||||
//#define WIFI_MODULE
|
||||
//#define NR5G_MEIGE
|
||||
#define G2UL_GATEWAY
|
||||
//#define IMX6UL_GATEWAY
|
||||
|
||||
class GlobalConfig
|
||||
{
|
||||
public :
|
||||
@ -24,17 +33,25 @@ public :
|
||||
static int QuitFlag_G; //程序退出标志
|
||||
static int LinkStatus_G; //和服务器连接状态
|
||||
static int LinkCount;
|
||||
static int NetSignal;
|
||||
static int serverStatus;
|
||||
static int net0Status;
|
||||
static std::string NR5GTemp;
|
||||
static std::string NetStatus;
|
||||
static std::string NetType;
|
||||
static std::string Version; //软件版本号
|
||||
static std::string MacAddr_G; //设备MAC地址
|
||||
static std::string MacAddr_G2; //设备光纤MAC地址
|
||||
static std::string IpAddr_G; //设备IP
|
||||
static std::string DbName_G; //数据库名字
|
||||
static std::string Config_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 GPIOInfo GPIO_G;
|
||||
static enumZigBeeTransmitStatus EnterZigBeeWaveTransmittingFlag_G; // 进入ZigBee网络原始数据传输状态标志
|
||||
static int EnterZigBeeWaveTransmittingCnt_G; // 进入ZigBee网络原始数据传输状态计数器,以秒为单位进行计数
|
||||
};
|
||||
@ -56,6 +73,17 @@ public :
|
||||
#define LIGHT_GRAY "\033[0;37m"
|
||||
#define WHITE "\033[1;37m"
|
||||
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
#define SAVE_COUNT 2058 //2058,4800
|
||||
#define OneWeek 259359//259359,604800
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
#define SAVE_COUNT 4800*4
|
||||
#define OneWeek 604800*7
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define perror_info(info) { \
|
||||
if (GlobalConfig::RUN_MODE) { \
|
||||
perror(info); \
|
||||
|
@ -54,6 +54,7 @@ static size_t OnWriteData(void* buffer, size_t size, size_t nmemb, void* lpVoid)
|
||||
|
||||
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
printf("size = %d\n",size);
|
||||
struct DowloadFile *out=(struct DowloadFile *)stream;
|
||||
if(out && !out->stream) {
|
||||
out->stream=fopen(out->filename, "wb");//打开文件进行写入
|
||||
@ -116,6 +117,73 @@ int DataTrans::download(char* pFilename,string& strUrl,string& strResponse,bool
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
//下载文件数据接收函数
|
||||
|
||||
size_t writedata2file(void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
||||
size_t written = fwrite(ptr, size, nmemb, stream);
|
||||
return written;
|
||||
}
|
||||
//http POST请求文件下载
|
||||
int DataTrans::dl_curl_post_req(const string &url, const string &postParams, string& filename)
|
||||
{
|
||||
CURL *curl;
|
||||
FILE *fp;
|
||||
CURLcode res;
|
||||
/* 调用curl_global_init()初始化libcurl */
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if (CURLE_OK != res)
|
||||
{
|
||||
printf("init libcurl failed.");
|
||||
curl_global_cleanup();
|
||||
return -1;
|
||||
}
|
||||
/* 调用curl_easy_init()函数得到 easy interface型指针 */
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
fp = fopen(filename.c_str(),"wb");
|
||||
|
||||
/* 调用curl_easy_setopt()设置传输选项 */
|
||||
res = curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
fclose(fp);
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
/* 根据curl_easy_setopt()设置的传输选项,实现回调函数以完成用户特定任务 */
|
||||
res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writedata2file);
|
||||
if (res != CURLE_OK){
|
||||
fclose(fp);
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
/* 根据curl_easy_setopt()设置的传输选项,实现回调函数以完成用户特定任务 */
|
||||
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
fclose(fp);
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
// 调用curl_easy_perform()函数完成传输任务
|
||||
fclose(fp);
|
||||
/* Check for errors */
|
||||
if(res != CURLE_OK){
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
|
||||
curl_easy_cleanup(curl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
// 调用curl_easy_cleanup()释放内存
|
||||
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DataTrans::Post(const std::string & strUrl, const std::string & strPost, std::string & strResponse)
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
int Send_Dir_socket(const char *dirname);
|
||||
|
||||
int download(char* pFilename,string& strUrl,string& strResponse,bool bDownload);
|
||||
|
||||
int dl_curl_post_req(const string &url, const string &postParams, string& filename);
|
||||
public:
|
||||
void SetDebug(bool bDebug);
|
||||
private:
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "../API_log/SH_log.h"
|
||||
#include "../common/SH_global.h"
|
||||
#include <unistd.h>
|
||||
#include "../calculation/Calculation.hpp"
|
||||
|
||||
bool SqlSwitch()
|
||||
{
|
||||
@ -12,6 +13,7 @@ bool SqlSwitch()
|
||||
}
|
||||
|
||||
SqliteDB *sql_ctl = SqliteDB::instance();
|
||||
Calculation *pCalculation = Calculation::instance();
|
||||
|
||||
SqliteDB::SqliteDB()
|
||||
{
|
||||
@ -28,7 +30,7 @@ void SqliteDB::SqliteInit(const char *pDbName, bool 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,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||
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,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||
T_SENSOR_INFO(TNAME),
|
||||
T_SENSOR_INFO(DATANODENO),
|
||||
T_SENSOR_INFO(DATANODENAME),
|
||||
@ -43,6 +45,11 @@ void SqliteDB::SqliteInit(const char *pDbName, bool isDB2)
|
||||
T_SENSOR_INFO(BPNO),
|
||||
T_SENSOR_INFO(SERIALNO),
|
||||
T_SENSOR_INFO(FIRSTPOWERNO),
|
||||
"WakeupTime",
|
||||
"StaticTime",
|
||||
"WaveTime",
|
||||
"BateryV",
|
||||
"ProductNo",
|
||||
T_SENSOR_INFO(CONFIGFLAG),
|
||||
T_SENSOR_INFO(STARTBRANDS),
|
||||
T_SENSOR_INFO(STOPBRANDS),
|
||||
@ -58,15 +65,32 @@ void SqliteDB::SqliteInit(const char *pDbName, bool isDB2)
|
||||
T_SENSOR_INFO(ZIGBEESHORTADDR),
|
||||
T_SENSOR_INFO(ZIGBEELONGADDR),
|
||||
T_SENSOR_INFO(ZIGBEEDESADDR),
|
||||
"ZigbeePower",
|
||||
"ZigbeeRetry",
|
||||
"ZigbeeRetryGap",
|
||||
"ACCSampleTime",
|
||||
T_SENSOR_INFO(STATUS),
|
||||
T_SENSOR_INFO(TIMESTAMP),
|
||||
T_SENSOR_INFO(VIFF),
|
||||
T_SENSOR_INFO(RSSI)),
|
||||
T_SENSOR_INFO(RSSI),
|
||||
"UpdateFlag",
|
||||
"LooseValue",
|
||||
"batteryPower"),
|
||||
CreateTable(sql_exec, isDB2);
|
||||
|
||||
int iRet = GetTableRows(" sqlite_master "," name = 't_sensor_info' and sql LIKE '%LooseValue%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_sensor_info ADD COLUMN 'LooseValue'");
|
||||
}
|
||||
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_sensor_info' and sql LIKE '%batteryPower%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_sensor_info ADD COLUMN 'batteryPower'");
|
||||
}
|
||||
|
||||
//创建传感器数据存储表
|
||||
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);",
|
||||
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 integer,%s,%s);",
|
||||
T_DATA_INFO(TNAME),
|
||||
T_DATA_INFO(DATANODENO),
|
||||
T_DATA_INFO(CHANNELID),
|
||||
@ -84,14 +108,20 @@ void SqliteDB::SqliteInit(const char *pDbName, bool isDB2)
|
||||
T_DATA_INFO(PHASE2),
|
||||
T_DATA_INFO(PHASE3),
|
||||
T_DATA_INFO(PHASE4),
|
||||
T_DATA_INFO(TIMESTAMP));
|
||||
T_DATA_INFO(STATICINDEX),
|
||||
T_DATA_INFO(TIMESTAMP),
|
||||
T_DATA_INFO(SENDMSG),
|
||||
T_DATA_INFO(NODERESEND));
|
||||
CreateTable(sql_exec, isDB2);
|
||||
|
||||
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_info' and sql LIKE '%nodeResend%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_data_info ADD COLUMN 'nodeResend'");
|
||||
}
|
||||
|
||||
//创建传感器静态数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s);",
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s);",
|
||||
T_DATASTATIC_INFO(TNAME),
|
||||
T_DATASTATIC_INFO(DATANODENO),
|
||||
T_DATASTATIC_INFO(CHANNELID),
|
||||
@ -99,10 +129,152 @@ void SqliteDB::SqliteInit(const char *pDbName, bool isDB2)
|
||||
T_DATASTATIC_INFO(TEMBOT),
|
||||
T_DATASTATIC_INFO(DIP),
|
||||
T_DATASTATIC_INFO(VOLTAGE),
|
||||
T_DATASTATIC_INFO(TIMESTAMP));
|
||||
"Battery",
|
||||
T_DATASTATIC_INFO(STATICINDEX),
|
||||
T_DATASTATIC_INFO(TIMESTAMP),
|
||||
T_DATASTATIC_INFO(SENDMSG),
|
||||
T_DATASTATIC_INFO(NODERESEND));
|
||||
CreateTable(sql_exec, isDB2);
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_datastatic_info' and sql LIKE '%nodeResend%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_datastatic_info ADD COLUMN 'nodeResend'");
|
||||
}
|
||||
|
||||
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);",
|
||||
T_GATEWAY_INFO(TNAME),
|
||||
T_GATEWAY_INFO(GATEWAYMAC),
|
||||
T_GATEWAY_INFO(SENSORVER),
|
||||
T_GATEWAY_INFO(GATEWAYLOCATION),
|
||||
T_GATEWAY_INFO(ZIGBEEPANID),
|
||||
T_GATEWAY_INFO(ZIGBEECHANNEL),
|
||||
T_GATEWAY_INFO(COMMUNICATIONTYPE),
|
||||
T_GATEWAY_INFO(SIGNAL),
|
||||
T_GATEWAY_INFO(LOCALIP),
|
||||
T_GATEWAY_INFO(SYSTEMVERSION),
|
||||
T_GATEWAY_INFO(PROGRAMVERSION),
|
||||
T_GATEWAY_INFO(WEBVERSION),
|
||||
T_GATEWAY_INFO(SERVERIP),
|
||||
T_GATEWAY_INFO(SERVERPORT),
|
||||
T_GATEWAY_INFO(STATUS),
|
||||
T_GATEWAY_INFO(GATEWAYUPDATE),
|
||||
T_GATEWAY_INFO(MAC2));
|
||||
CreateTable(sql_exec, isDB2);
|
||||
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s);",
|
||||
"t_data_waveSend","channelID","waveName","timeStamp","sendMsg","save");
|
||||
CreateTable(sql_exec, isDB2);
|
||||
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_waveSend' and sql LIKE '%sendMsg%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_data_waveSend ADD COLUMN 'sendMsg'");
|
||||
}
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_waveSend' and sql LIKE '%save%' ");
|
||||
if(iRet == 0){
|
||||
CreateTable("ALTER TABLE t_data_waveSend ADD COLUMN 'save'");
|
||||
}
|
||||
/*memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s integer,%s integer ,%s integer ,%s integer,%s integer);",
|
||||
T_DATANODE_TIME(TNAME),
|
||||
T_DATANODE_TIME(DATANODENO),
|
||||
T_DATANODE_TIME(SHORTADDR),
|
||||
T_DATANODE_TIME(STATICCYCLE),
|
||||
T_DATANODE_TIME(WAVECYCLE),
|
||||
T_DATANODE_TIME(NODEGROUP),
|
||||
T_DATANODE_TIME(NODEINDEX),
|
||||
T_DATANODE_TIME(NODEWAVEINDEX),
|
||||
T_DATANODE_TIME(STATICTIME),
|
||||
T_DATANODE_TIME(STATICSTARTTIME));
|
||||
CreateTable(sql_exec, isDB2);*/
|
||||
|
||||
}
|
||||
void SqliteDB::Createtable(const char *ptableName)
|
||||
{
|
||||
char sql_exec[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 integer,%s,%s,%s);",
|
||||
ptableName,
|
||||
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),
|
||||
"StaticIndex",
|
||||
T_DATA_INFO(TIMESTAMP),
|
||||
"sendMsg",
|
||||
"nodeResend");
|
||||
CreateTable(sql_exec, 0);
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec,"CREATE INDEX %s_1 \
|
||||
ON %s (%s)",ptableName,ptableName,T_DATA_INFO(DATANODENO));
|
||||
CreateTable(sql_exec, 0);
|
||||
}
|
||||
|
||||
void SqliteDB::SqliteInitDel(const char *pDbName)
|
||||
{
|
||||
Deletetable(T_DATA_INFO(TNAME));
|
||||
Deletetable(T_DATASTATIC_INFO(TNAME));
|
||||
vec_t vecResult = GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME),T_SENSOR_INFO(ZIGBEELONGADDR),NULL);
|
||||
for(int i = 0; i < vecResult.size() && vecResult.size() > 0;i++)
|
||||
{
|
||||
char sztableName[100]={0x00};
|
||||
sprintf(sztableName,"t_data_%s",vecResult[i].c_str());
|
||||
Deletetable(sztableName);
|
||||
sprintf(sztableName,"t_dataStatic_%s",vecResult[i].c_str());
|
||||
Deletetable(sztableName);
|
||||
}
|
||||
}
|
||||
void SqliteDB::Deletetable(const char *ptableName)
|
||||
{
|
||||
char sql_exec[2048];
|
||||
//创建传感器数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec,"DROP TABLE %s ;",ptableName);
|
||||
int iRet = sqlite3_exec(GetDbHandle(false), sql_exec, 0, 0, NULL);
|
||||
if (iRet != SQLITE_OK) {
|
||||
perror_info("sqlite3_exec");
|
||||
}
|
||||
|
||||
}
|
||||
void SqliteDB::CreatedataStatictable(const char *ptableName)
|
||||
{
|
||||
char sql_exec[2048];
|
||||
//创建传感器数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s);",
|
||||
ptableName,
|
||||
T_DATASTATIC_INFO(DATANODENO),
|
||||
T_DATASTATIC_INFO(CHANNELID),
|
||||
T_DATASTATIC_INFO(TEMTOP),
|
||||
T_DATASTATIC_INFO(TEMBOT),
|
||||
T_DATASTATIC_INFO(DIP),
|
||||
T_DATASTATIC_INFO(VOLTAGE),
|
||||
"zigbeeSignal",
|
||||
"StaticIndex",
|
||||
T_DATASTATIC_INFO(TIMESTAMP),
|
||||
"sendMsg",
|
||||
"nodeResend"
|
||||
//"zigbeeRSSIType"
|
||||
);
|
||||
CreateTable(sql_exec, 0);
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec,"CREATE INDEX %s_1 \
|
||||
ON %s (%s)",ptableName,ptableName,T_DATA_INFO(DATANODENO));
|
||||
CreateTable(sql_exec, 0);
|
||||
}
|
||||
bool SqliteDB::OpenDB(const char *pDbName, bool isDB2)
|
||||
{
|
||||
if (isDB2 == false) {
|
||||
@ -255,11 +427,9 @@ vec_t SqliteDB::GetDataSingleLine(const char *tablename, const char *column, con
|
||||
return vecResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string SqliteDB::GetData(const char *tablename, const char *column, const char *whereCon)
|
||||
char* SqliteDB::GetDataChar(const char *tablename, const char *column, const char *whereCon)
|
||||
{
|
||||
std::string strRes;
|
||||
char szRes[100]={0x00};
|
||||
std::string strSql = "select ";
|
||||
if (whereCon != NULL) {
|
||||
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
||||
@ -273,6 +443,35 @@ std::string SqliteDB::GetData(const char *tablename, const char *column, const c
|
||||
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 NULL;
|
||||
}
|
||||
int retStep = sqlite3_step(stmt);
|
||||
if (retStep == SQLITE_ROW) {
|
||||
char *columninfo = (char*)sqlite3_column_text(stmt, 0);
|
||||
memcpy(szRes,columninfo,sizeof(szRes));
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return szRes;
|
||||
}
|
||||
|
||||
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;
|
||||
g_tDbMutex.Lock();
|
||||
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);
|
||||
g_tDbMutex.UnLock();
|
||||
return strRes;
|
||||
}
|
||||
int retStep = sqlite3_step(stmt);
|
||||
@ -281,6 +480,7 @@ std::string SqliteDB::GetData(const char *tablename, const char *column, const c
|
||||
strRes = columninfo != NULL ? columninfo : "";
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
g_tDbMutex.UnLock();
|
||||
return strRes;
|
||||
}
|
||||
|
||||
@ -294,12 +494,15 @@ array_t SqliteDB::GetDataMultiLine(const char *tablename, const char *column, co
|
||||
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;
|
||||
g_tDbMutex.Lock();
|
||||
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);
|
||||
g_tDbMutex.UnLock();
|
||||
return arrResult;
|
||||
}
|
||||
int retStep = sqlite3_step(stmt);
|
||||
@ -315,9 +518,47 @@ array_t SqliteDB::GetDataMultiLine(const char *tablename, const char *column, co
|
||||
retStep = sqlite3_step(stmt);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
g_tDbMutex.UnLock();
|
||||
return arrResult;
|
||||
}
|
||||
array_t SqliteDB::GetDataMultiLineTransaction(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_exec(mDBAcess, "BEGIN", 0, 0, NULL);
|
||||
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;
|
||||
}
|
||||
sqlite3_reset(stmt);
|
||||
sqlite3_bind_int(stmt, 1, 0);
|
||||
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);
|
||||
sqlite3_exec(mDBAcess, "COMMIT", 0, 0, NULL);
|
||||
return arrResult;
|
||||
}
|
||||
vec_t SqliteDB::GetDataMultiLineOfOneColumn(const char *tablename, const char *column, const char *whereCon)
|
||||
{
|
||||
vec_t vecResult;
|
||||
@ -346,7 +587,33 @@ vec_t SqliteDB::GetDataMultiLineOfOneColumn(const char *tablename, const char *c
|
||||
sqlite3_finalize(stmt);
|
||||
return vecResult;
|
||||
}
|
||||
|
||||
vec_Value SqliteDB::GetDataMultiLineOfOneColumnDouble(const char *tablename, const char *column, const char *whereCon)
|
||||
{
|
||||
vec_Value 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) {
|
||||
double columninfo = sqlite3_column_double(stmt, 0);
|
||||
vecResult.push_back(columninfo);
|
||||
retStep = sqlite3_step(stmt);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return vecResult;
|
||||
}
|
||||
|
||||
|
||||
int SqliteDB::DeleteTableData(const char* tablename, const char* whereCond, bool isDB2)
|
||||
@ -358,6 +625,7 @@ int SqliteDB::DeleteTableData(const char* tablename, const char* whereCond, bool
|
||||
else {
|
||||
strSql = strSql + tablename + ";";
|
||||
}
|
||||
// LOG_INFO("strSql = %s",strSql.c_str());
|
||||
print_light_green("%s\n", strSql.c_str());
|
||||
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||
char *msg;
|
||||
@ -390,7 +658,34 @@ int SqliteDB::DeleteTableDataOneConditon(const char* tablename, const char* cond
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
int SqliteDB::UpdateNodeNameData(const char* tablename, const char* updateColumn, const char* whereCond, bool isDB2)
|
||||
{
|
||||
std::string strSql = "update ";
|
||||
char szSql[1024] = {0x00};
|
||||
strcat(szSql,"update ");
|
||||
if (whereCond != NULL) {
|
||||
strcat(szSql,tablename);
|
||||
strcat(szSql," set ");
|
||||
strcat(szSql,updateColumn);
|
||||
strcat(szSql," where ");
|
||||
strcat(szSql,whereCond);
|
||||
strcat(szSql,";");
|
||||
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), szSql, 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 ";
|
||||
@ -403,12 +698,14 @@ int SqliteDB::UpdateTableData(const char* tablename, const char* updateColumn, c
|
||||
print_light_green("%s\n", strSql.c_str());
|
||||
// if (SqlSwitch()) log_system->log_write_system("[info]","%s\n", strSql.c_str());
|
||||
char *msg;
|
||||
g_tDbMutex.Lock();
|
||||
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);
|
||||
}
|
||||
g_tDbMutex.UnLock();
|
||||
return iRet;
|
||||
}
|
||||
|
||||
@ -484,7 +781,357 @@ int SqliteDB::InsertData(const char* tablename, const char* insertValues, int re
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
int SqliteDB::InsertData(const char* insertSql)
|
||||
{
|
||||
char *msg;
|
||||
int iRet = sqlite3_exec(GetDbHandle(false), insertSql, 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::CalculateBattery()
|
||||
{
|
||||
float dayStaticPower = 6.5,dayWavePower = 237;//
|
||||
char whereCon[1024] = {0};
|
||||
char selectSql[1024] = { 0 };
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
memset(selectSql,0x00,sizeof(selectSql));
|
||||
sprintf(selectSql," DataNodeNo,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate ");
|
||||
array_t vecRes ;
|
||||
vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
||||
if(vecRes.size() > 0){
|
||||
for(int i = 0; i < vecRes.size(); i++){
|
||||
if(vecRes[i][5] == "12800"){
|
||||
|
||||
}else if(vecRes[i][5] == "3200"){
|
||||
|
||||
}
|
||||
float dayStaticTime = 0.0;
|
||||
float dayWaveTime = 0.0;
|
||||
if(atoi(vecRes[i][3].c_str()) == 0){
|
||||
dayStaticTime = 0;
|
||||
}else{
|
||||
dayStaticTime = 24*60/atoi(vecRes[i][3].c_str());
|
||||
}
|
||||
if(atoi(vecRes[i][4].c_str()) == 0){
|
||||
dayWaveTime = 0;
|
||||
}else{
|
||||
dayWaveTime = 24*60/atoi(vecRes[i][4].c_str());
|
||||
}
|
||||
|
||||
float dayPower = dayStaticTime * dayStaticPower + dayWaveTime * dayWavePower + 24*3.26;//static + wave + sleep
|
||||
float usePower = atoi(vecRes[i][1].c_str()) * dayStaticPower + atoi(vecRes[i][2].c_str()) * dayWavePower;
|
||||
if(dayPower == 0)
|
||||
dayPower = 1;
|
||||
float remainDay = (19000000*0.5 - usePower)/dayPower;
|
||||
float bateryProportion = remainDay/(19000000*0.5/dayPower);
|
||||
char updateSql[1024] = { 0x00 };
|
||||
char tmpParam[1024] = {0x00};
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
memset(updateSql,0x00,sizeof(updateSql));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' ",vecRes[i][0].c_str());
|
||||
sprintf(updateSql,"batteryPower = '%f,%f' ",bateryProportion,remainDay);
|
||||
int iRet = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||
print_info("iRet = %d\n",iRet);
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
print_info("CalculateBattery \n");
|
||||
return 0;
|
||||
}
|
||||
int SqliteDB::CalculateDip()
|
||||
{
|
||||
char whereCon[1024] = {0};
|
||||
char selectSql[1024] = { 0 };
|
||||
char updateSql[1024] = { 0 };
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
memset(selectSql,0x00,sizeof(selectSql));
|
||||
sprintf(selectSql," DataNodeNo");
|
||||
array_t vecRes ;
|
||||
vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
||||
for(int i = 0 ; i < vecRes.size(); i++){
|
||||
char szTablename[32]={0x00};
|
||||
sprintf(szTablename,"t_dataStatic_%s",vecRes[i][0].c_str());
|
||||
vec_Value vecResDip = GetDataMultiLineOfOneColumnDouble(szTablename," Dip ", NULL);
|
||||
float sample_variance = pCalculation->getSample_variance(vecResDip);
|
||||
print_info("sample_variance = %f\n",sample_variance);
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
memset(updateSql,0x00,sizeof(updateSql));
|
||||
sprintf(whereCon,"dataNodeNo = '%s' ",vecRes[i][0].c_str());
|
||||
sprintf(updateSql,"LooseValue = '%f' ",sample_variance);
|
||||
UpdateTableData(T_SENSOR_INFO(TNAME),updateSql,whereCon);
|
||||
}
|
||||
}
|
||||
int SqliteDB::InintGateway()
|
||||
{
|
||||
//更新网关配置表
|
||||
string strIP = GetGwIp_("eth0");
|
||||
string strServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||
string strServerPort = ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort");
|
||||
string strwebVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "WebVersion");
|
||||
string strsystemVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "SystemVersion");
|
||||
string strGatewayVersion = ReadStrByOpt(SYSTEMINFOFILE, "Version", "GateWayVersion");
|
||||
std::string strchan = ReadStrByOpt(ZIGBEECONFIG, "Zigbee", "channel");
|
||||
if(0 == sql_ctl->GetTableRows(T_GATEWAY_INFO(TNAME), NULL)){
|
||||
|
||||
char strSql[1024] = { 0 };
|
||||
sprintf(strSql,"insert into t_gateway_info(gatewayMAC,zigbeePanID,zigbeeChannel,\
|
||||
localIP,systemVersion,programVersion,webVersion,serverIP,serverPort,MAC2)\
|
||||
values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');",GlobalConfig::MacAddr_G.c_str(),GlobalConfig::MacAddr_G.substr(8).c_str(),strchan.c_str(),strIP.c_str(),\
|
||||
strsystemVersion.c_str(),strGatewayVersion.c_str(),strwebVersion.c_str(),strServerIP.c_str(),strServerPort.c_str(),GlobalConfig::MacAddr_G2.c_str());
|
||||
sql_ctl->InsertData(strSql);
|
||||
print_info("strSql = %s\n",strSql);
|
||||
}else{
|
||||
char whereCon[1024] = {0};
|
||||
char updateSql[1024] = { 0 };
|
||||
sprintf(updateSql, "zigbeePanID = '%s',zigbeeChannel = '%s',localIP = '%s',systemVersion='%s',programVersion='%s',webVersion='%s',serverIP='%s',serverPort='%s'",\
|
||||
GlobalConfig::MacAddr_G.substr(8).c_str(),strchan.c_str(),strIP.c_str(),\
|
||||
strsystemVersion.c_str(),strGatewayVersion.c_str(),strwebVersion.c_str(),strServerIP.c_str(),strServerPort.c_str());
|
||||
sprintf(whereCon, "gatewayMAC='%s'", GlobalConfig::MacAddr_G.c_str());
|
||||
sql_ctl->UpdateTableData(T_GATEWAY_INFO(TNAME), updateSql, whereCon);
|
||||
}
|
||||
|
||||
//上传网关配置到MQTT
|
||||
Json::Value jsSystemSetting;
|
||||
Json::Value jsBody;
|
||||
Json::FastWriter showValue;
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
|
||||
jsonVal["cmd"] = "23";
|
||||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsSystemSetting["WebVersion"] = strwebVersion;
|
||||
jsSystemSetting["SystemVersion"] = strsystemVersion;
|
||||
jsSystemSetting["GateWayVersion"] = strGatewayVersion;
|
||||
jsBody["localServerIpAddress"] = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||
jsBody["localServerPort"] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||||
jsBody["CommMode"] = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "CommMode").c_str());
|
||||
jsBody["Password"] = (ReadStrByOpt(SERVERCONFIG, "Server", "Password"));
|
||||
jsBody["UserName"] = (ReadStrByOpt(SERVERCONFIG, "Server", "UserName"));
|
||||
std::string dataBody = showValue.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
|
||||
jsBody.clear();
|
||||
jsonVal["cmd"] = "25";
|
||||
jsBody["dnsName"] = ReadStrByOpt(NETWORKCONFIG, "Net", "dnsName");
|
||||
jsBody["networkPortStatus"] = ReadStrByOpt(NETWORKCONFIG, "Net", "networkPortStatus");
|
||||
jsBody["gateway"] = ReadStrByOpt(NETWORKCONFIG, "Net", "gateway");
|
||||
jsBody["subnetMask"] = ReadStrByOpt(NETWORKCONFIG, "Net", "subnetMask");
|
||||
jsBody["dataWatchIpAddress"] = ReadStrByOpt(NETWORKCONFIG, "Net", "ipAddress");
|
||||
jsBody["hostName"] = ReadStrByOpt(NETWORKCONFIG, "Net", "hostName");
|
||||
|
||||
dataBody = showValue.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
}
|
||||
|
||||
std::string SqliteDB::GetNodeConfigureInfor(const char* whereCon)
|
||||
{
|
||||
vec_t vecRes = GetDataSingleLine(T_SENSOR_INFO(TNAME), "*", whereCon);
|
||||
printf("vecRes = %d\n",vecRes.size());
|
||||
if(vecRes.size() < 1)
|
||||
return "";
|
||||
Json::Value jsSensorData;
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsonVal["cmd"] = "26";
|
||||
jsSensorData["dataNodeNo"] = vecRes[0];
|
||||
jsSensorData["dataNodeName"] = vecRes[1];
|
||||
jsSensorData["initFlag"] = atoi(vecRes[2].c_str());
|
||||
jsSensorData["accFlag"] = atoi(vecRes[3].c_str());
|
||||
jsSensorData["zigbeeFlag"] = atoi(vecRes[4].c_str());
|
||||
jsSensorData["temTopFlag"] = atoi(vecRes[5].c_str());
|
||||
jsSensorData["temBotFlag"] = atoi(vecRes[6].c_str());
|
||||
jsSensorData["hardVersion"] = vecRes[8];
|
||||
jsSensorData["softVersion"] = vecRes[9];
|
||||
jsSensorData["bpNo"] = vecRes[10];
|
||||
jsSensorData["serialNo"] = vecRes[11];
|
||||
jsSensorData["firstPowerTime"] = vecRes[12];
|
||||
jsSensorData["WakeupTime"] = atoi(vecRes[13].c_str());
|
||||
jsSensorData["StaticTime"] = atoi(vecRes[14].c_str());
|
||||
jsSensorData["WaveTime"] = atoi(vecRes[15].c_str());
|
||||
jsSensorData["BateryV"] = vecRes[16];
|
||||
jsSensorData["ProductNo"] = vecRes[17];
|
||||
jsSensorData["configFlag"] = atoi(vecRes[18].c_str());
|
||||
jsSensorData["startBrands"] = vecRes[19];
|
||||
jsSensorData["stopBrands"] = vecRes[20];
|
||||
jsSensorData["featureInterVal"] = (vecRes[21]);
|
||||
jsSensorData["waveInterVal"] = atoi(vecRes[22].c_str());
|
||||
jsSensorData["samplingRate"] = atoi(vecRes[23].c_str());
|
||||
jsSensorData["range"] = atoi(vecRes[25].c_str());
|
||||
jsSensorData["envelopeBandPass"] = vecRes[26];
|
||||
jsSensorData["faultFrequency"] = vecRes[27];
|
||||
jsSensorData["zigbeePanId"] = vecRes[28];
|
||||
jsSensorData["zigbeeChannel"] = (vecRes[29]);
|
||||
jsSensorData["zigbeeAddr"] = vecRes[30];
|
||||
jsSensorData["zigbeeLongAddr"] = vecRes[31];
|
||||
jsSensorData["zigbeeDesAddr"] = vecRes[32];
|
||||
jsSensorData["ZigbeePower"] = atoi(vecRes[33].c_str());
|
||||
jsSensorData["ZigbeeRetry"] = atoi(vecRes[34].c_str());
|
||||
jsSensorData["ZigbeeRetryGap"] = atoi(vecRes[35].c_str());
|
||||
jsSensorData["ACCSampleTime"] = atoi(vecRes[36].c_str());
|
||||
jsSensorData["status"] = atoi(vecRes[37].c_str());
|
||||
jsSensorData["timeStamp"] = vecRes[38];
|
||||
jsSensorData["viff"] = atoi(vecRes[39].c_str());
|
||||
jsSensorData["RSSI"] = atoi(vecRes[40].c_str());
|
||||
jsSensorData["Update"] = atoi(vecRes[41].c_str());
|
||||
jsSensorData["LooseValue"] = (vecRes[42].c_str());
|
||||
jsSensorData["batteryPower"] = (vecRes[43].c_str());
|
||||
|
||||
Json::FastWriter showValue;
|
||||
Json::Value jsBody;
|
||||
jsBody["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsBody["dataNodeData"] = jsSensorData;
|
||||
std::string dataBody = showValue.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
return showValue.write(jsonVal);
|
||||
}
|
||||
|
||||
int SqliteDB::QueryofflineData()
|
||||
{
|
||||
vec_t vecRet = GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME),T_SENSOR_INFO(DATANODENO),NULL);
|
||||
for(int i = 0; i < vecRet.size();i++){
|
||||
char StaticTableName[50]={0x00};
|
||||
sprintf(StaticTableName,"t_dataStatic_%s",vecRet[i].c_str());
|
||||
|
||||
array_t arrRetData = GetDataMultiLine(StaticTableName, "*","sendMsg = '0' order by timeStamp asc");
|
||||
LOG_INFO("mqttresend check datanodeNo %s,data count %d\n",vecRet[i].c_str(),arrRetData.size());
|
||||
if(arrRetData.size() < 1)
|
||||
continue;
|
||||
for(int j = 0; j < arrRetData.size();j++){
|
||||
char dataTableName[50]={0x00};
|
||||
sprintf(dataTableName,"t_data_%s",vecRet[i].c_str());
|
||||
char tmpWhere[128]={0x00};
|
||||
sprintf(tmpWhere,"sendMsg = '0' and timeStamp = '%s'",arrRetData[j][8].c_str());
|
||||
array_t arrRet = GetDataMultiLine(dataTableName, "*","sendMsg = '0'");
|
||||
if(arrRet.size() > 0){
|
||||
Json::Value valNodeData;
|
||||
Json::Value valNodeFeature;
|
||||
for(int k = 0; k < arrRet.size();k++){
|
||||
|
||||
valNodeFeature["dataNodeNo"] = arrRet[k][0].c_str();
|
||||
valNodeFeature["ChannelId"] = arrRet[k][1].c_str();
|
||||
valNodeFeature["diagnosisPk"] = atof(arrRet[k][2].c_str());
|
||||
valNodeFeature["integratPk"] = atof(arrRet[k][3].c_str());
|
||||
valNodeFeature["integratRMS"] = atof(arrRet[k][4].c_str());
|
||||
valNodeFeature["rmsValues"] = atof(arrRet[k][5].c_str());
|
||||
valNodeFeature["envelopEnergy"] = atof(arrRet[k][6].c_str());
|
||||
valNodeFeature["Amp1"] = atof(arrRet[k][7].c_str());
|
||||
valNodeFeature["Amp2"] = atof(arrRet[k][8].c_str());
|
||||
valNodeFeature["Amp3"] = atof(arrRet[k][9].c_str());
|
||||
valNodeFeature["Amp4"] = atof(arrRet[k][10].c_str());
|
||||
valNodeFeature["Amp5"] = atof(arrRet[k][1].c_str());
|
||||
valNodeFeature["Phase1"] = atof(arrRet[k][12].c_str());
|
||||
valNodeFeature["Phase2"] = atof(arrRet[k][13].c_str());
|
||||
valNodeFeature["Phase3"] = atof(arrRet[k][14].c_str());
|
||||
valNodeFeature["Phase4"] = atof(arrRet[k][15].c_str());
|
||||
valNodeFeature["timeStamp"] = atoi(arrRet[k][17].c_str());
|
||||
valNodeData.append(valNodeFeature);
|
||||
}
|
||||
}
|
||||
//无线传感器信息
|
||||
Json::Value root;
|
||||
Json::Value valdatastatic;
|
||||
Json::Value valNodeData;
|
||||
valdatastatic["TemperatureTop"] = atof(arrRetData[j][2].c_str());
|
||||
valdatastatic["TemperatureBot"] = atof(arrRetData[j][3].c_str());
|
||||
valdatastatic["Dip"] = atof(arrRetData[j][4].c_str());
|
||||
valdatastatic["Voltage"] = atof(arrRetData[j][5].c_str());
|
||||
valdatastatic["ChannelType"] = "STATUS";
|
||||
valdatastatic["ChannelId"] = (arrRetData[j][1].c_str());
|
||||
valdatastatic["TimeStamp"] = atoi(arrRetData[j][8].c_str());
|
||||
|
||||
valdatastatic["dataNodeNo"] = arrRetData[j][0].c_str();
|
||||
valNodeData.append(valdatastatic);
|
||||
|
||||
root["data"] = valNodeData;
|
||||
root["TimeStamp"] = atoi(arrRetData[j][8].c_str());
|
||||
root["dataNodeNo"] = arrRetData[j][0].c_str();
|
||||
root["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
root["status"] = "resend";
|
||||
Json::FastWriter featureValue;
|
||||
std::string strstatisticData = featureValue.write(root);
|
||||
|
||||
int iRet = data_publish(strstatisticData.c_str(), GlobalConfig::Topic_G.mPubData.c_str());
|
||||
//print_info("dataNodeNo = '%s' and TimeStamp = '%s',MQTT ret = %d\n",arrRetData[j][0].c_str(),nowTimetamp.c_str(),iRet);
|
||||
if(iRet == 0){
|
||||
char updateSql[1024] = { 0 };
|
||||
char whereCon[64] = { 0 };
|
||||
memset(whereCon, 0, 64);
|
||||
sprintf(whereCon, "dataNodeNo = '%s' and TimeStamp = '%s'", arrRetData[j][0].c_str(),arrRetData[j][8].c_str());
|
||||
memcpy(updateSql, "sendMsg='1'",sizeof(updateSql));
|
||||
sql_ctl->UpdateTableData(StaticTableName, updateSql, whereCon);
|
||||
sql_ctl->UpdateTableData(dataTableName, updateSql, whereCon);
|
||||
LOG_INFO("resend success dataNodeNo = %s,TimeStamp = '%s'\n",arrRetData[j][0].c_str(),arrRetData[j][8].c_str());
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
char whereCon[1024] = {0x00};
|
||||
sprintf(whereCon, " SendMsg = 0 ");
|
||||
array_t arrRetData = GetDataMultiLine("t_data_waveSend", "*",whereCon);
|
||||
LOG_INFO("mqttresend check wave count %d\n",arrRetData.size());
|
||||
if(arrRetData.size() > 0){
|
||||
for(int i = 0; i < arrRetData.size();i++){
|
||||
std::string strWaveData = "";
|
||||
if (access(arrRetData[i][1].c_str(), 0) >= 0)
|
||||
{
|
||||
std::vector<float> vecWave;
|
||||
char localtimestamp[32] = { 0 };
|
||||
float fTemp = 0;
|
||||
std::ifstream inFile(arrRetData[i][1].c_str(),ios::in|ios::binary);
|
||||
inFile.read((char *)localtimestamp,sizeof(localtimestamp));
|
||||
while(inFile.read((char *)&fTemp,sizeof(fTemp))){
|
||||
vecWave.push_back(fTemp);
|
||||
}
|
||||
|
||||
for (int i = 0; i < vecWave.size(); i++) {
|
||||
char buf[33]={0x00};
|
||||
memset(buf,0x00,sizeof(buf));
|
||||
sprintf(buf, "%.2f", vecWave[i]);
|
||||
std::string waveTemp(buf);
|
||||
if(i == 0){
|
||||
strWaveData = waveTemp;
|
||||
}
|
||||
strWaveData = strWaveData + "," + waveTemp;
|
||||
}
|
||||
inFile.close();
|
||||
}
|
||||
Json::Value valWaveData;
|
||||
int length = strWaveData.length();
|
||||
valWaveData["number"] = length;
|
||||
valWaveData["channelId"] = arrRetData[i][0];
|
||||
valWaveData["dataNodeNo"] = arrRetData[i][0];
|
||||
valWaveData["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
valWaveData["SensorEngineeringUnit"] = "";
|
||||
valWaveData["timeStamp"] = arrRetData[i][2];
|
||||
valWaveData["waveData"] = strWaveData;
|
||||
Json::FastWriter WaveValue;
|
||||
std::string WaveData = WaveValue.write(valWaveData);
|
||||
int iRet = data_publish(WaveData.c_str(), GlobalConfig::Topic_G.mPubWaveData.c_str());
|
||||
if(iRet == 0){
|
||||
char whereCon[1024] = {0x00};
|
||||
char updateSql[1024] = {0x00};
|
||||
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' ", arrRetData[i][0].c_str(),arrRetData[i][2].c_str());
|
||||
sprintf(updateSql, "SendMsg = 1");
|
||||
sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
|
||||
//char whereCon[64]={0x00};
|
||||
//sprintf(whereCon,"waveName = '%s'",arrRetData[i][1].c_str());
|
||||
//DeleteTableData("t_data_waveSend", whereCon);
|
||||
std::string strCmd = "rm " + arrRetData[i][1];
|
||||
system(strCmd.c_str());
|
||||
LOG_INFO("resend success waveName = %s\n",arrRetData[i][1].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
int SqliteDB::TransBegin()
|
||||
{
|
||||
return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0);
|
||||
|
@ -14,9 +14,12 @@ extern "C"{
|
||||
#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]
|
||||
#define T_GATEWAY_INFO(x) T_GATEWAY_INFO[T_GATEWAY_INFO_##x]
|
||||
#define T_DATANODE_TIME(x) T_DATANODE_TIME[T_DATANODE_TIME_##x]
|
||||
|
||||
typedef std::map<std::string, std::string> map_t;
|
||||
typedef std::vector<std::string> vec_t;
|
||||
typedef std::vector<float> vec_Value;
|
||||
typedef std::vector<vec_t> array_t;
|
||||
|
||||
class SqliteDB : public MySingleton < SqliteDB > {
|
||||
@ -25,6 +28,10 @@ public:
|
||||
virtual ~SqliteDB();
|
||||
bool OpenDB(const char *pDbName, bool isDB2=false);
|
||||
void SqliteInit(const char *pDbName, bool isDB2=false);
|
||||
void SqliteInitDel(const char *pDbName);
|
||||
void Createtable(const char *ptableName);
|
||||
void Deletetable(const char *ptableName);
|
||||
void CreatedataStatictable(const char *ptableName);
|
||||
int TransBegin();
|
||||
int TransRollback();
|
||||
int TransCommit();
|
||||
@ -34,14 +41,24 @@ public:
|
||||
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);
|
||||
char* GetDataChar(const char *tablename, const char *column, const char *whereCon);
|
||||
array_t GetDataMultiLine(const char *tablename, const char *column, const char *whereCon);
|
||||
array_t GetDataMultiLineTransaction(const char *tablename, const char *column, const char *whereCon);
|
||||
vec_t GetDataMultiLineOfOneColumn(const char *tablename, const char *column, const char *whereCon);
|
||||
vec_Value GetDataMultiLineOfOneColumnDouble(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 UpdateNodeNameData(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 InsertData(const char* insertSql);
|
||||
int CalculateBattery();
|
||||
int CalculateDip();
|
||||
int InintGateway();
|
||||
int QueryofflineData();
|
||||
std::string GetNodeConfigureInfor(const char* whereCon);
|
||||
int CloseDB();
|
||||
|
||||
private:
|
||||
@ -107,9 +124,12 @@ typedef enum {
|
||||
T_DATA_INFO_PHASE2,
|
||||
T_DATA_INFO_PHASE3,
|
||||
T_DATA_INFO_PHASE4,
|
||||
T_DATA_INFO_STATICINDEX,
|
||||
T_DATA_INFO_TIMESTAMP,
|
||||
T_DATA_INFO_SENDMSG,
|
||||
T_DATA_INFO_NODERESEND
|
||||
}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"};
|
||||
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","StaticIndex","timeStamp","sendMsg","nodeResend"};
|
||||
|
||||
|
||||
typedef enum {
|
||||
@ -120,8 +140,46 @@ typedef enum {
|
||||
T_DATASTATIC_INFO_TEMBOT,
|
||||
T_DATASTATIC_INFO_DIP,
|
||||
T_DATASTATIC_INFO_VOLTAGE,
|
||||
T_DATASTATIC_INFO_STATICINDEX,
|
||||
T_DATASTATIC_INFO_TIMESTAMP,
|
||||
T_DATASTATIC_INFO_SENDMSG,
|
||||
T_DATASTATIC_INFO_NODERESEND
|
||||
}T_DATASTATIC_INFO_Index;
|
||||
const static char* T_DATASTATIC_INFO[] = { "t_datastatic_info","dataNodeNo","channelID","temTop","temBot","dip","voltage","timeStamp"};
|
||||
const static char* T_DATASTATIC_INFO[] = { "t_datastatic_info","dataNodeNo","channelID","temTop","temBot","dip","voltage","StaticIndex","timeStamp","sendMsg","nodeResend"};
|
||||
|
||||
typedef enum {
|
||||
T_DATANODE_TIME_TNAME = 0,
|
||||
T_DATANODE_TIME_DATANODENO,
|
||||
T_DATANODE_TIME_SHORTADDR,
|
||||
T_DATANODE_TIME_STATICCYCLE,
|
||||
T_DATANODE_TIME_WAVECYCLE,
|
||||
T_DATANODE_TIME_NODEGROUP,
|
||||
T_DATANODE_TIME_NODEINDEX,
|
||||
T_DATANODE_TIME_NODEWAVEINDEX,
|
||||
T_DATANODE_TIME_STATICTIME,
|
||||
T_DATANODE_TIME_STATICSTARTTIME
|
||||
}T_DATANODE_TIME_Index;
|
||||
const static char* T_DATANODE_TIME[] = { "t_datanode_time","dataNodeNo","shortaddr","staticcycle","wavecycle","nodegroup","nodeindex","nodewaveindex","statictime","staticstarttime"};
|
||||
|
||||
|
||||
typedef enum {
|
||||
T_GATEWAY_INFO_TNAME = 0,
|
||||
T_GATEWAY_INFO_GATEWAYMAC,
|
||||
T_GATEWAY_INFO_SENSORVER,
|
||||
T_GATEWAY_INFO_GATEWAYLOCATION,
|
||||
T_GATEWAY_INFO_ZIGBEEPANID,
|
||||
T_GATEWAY_INFO_ZIGBEECHANNEL,
|
||||
T_GATEWAY_INFO_COMMUNICATIONTYPE,
|
||||
T_GATEWAY_INFO_SIGNAL,
|
||||
T_GATEWAY_INFO_LOCALIP,
|
||||
T_GATEWAY_INFO_SYSTEMVERSION,
|
||||
T_GATEWAY_INFO_PROGRAMVERSION,
|
||||
T_GATEWAY_INFO_WEBVERSION,
|
||||
T_GATEWAY_INFO_SERVERIP,
|
||||
T_GATEWAY_INFO_SERVERPORT,
|
||||
T_GATEWAY_INFO_STATUS,
|
||||
T_GATEWAY_INFO_GATEWAYUPDATE,
|
||||
T_GATEWAY_INFO_MAC2,
|
||||
}T_GATEWAY_INFO_Index;
|
||||
const static char* T_GATEWAY_INFO[] = { "t_gateway_info","gatewayMAC","sensorVersion","gatewayLocation","zigbeePanID","zigbeeChannel","communicationType","signal","localIP","systemVersion","programVersion","webVersion","serverIP","serverPort","status","gateWayUpdate","MAC2"};
|
||||
#endif
|
||||
|
296
dial5G/Dial.cpp
Normal file
296
dial5G/Dial.cpp
Normal file
@ -0,0 +1,296 @@
|
||||
/*
|
||||
* Dial.cpp
|
||||
*
|
||||
* Created on: 2023年6月13日
|
||||
* Author: chaos
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
#include "Dial.h"
|
||||
|
||||
|
||||
Dial::Dial() {
|
||||
// TODO Auto-generated constructor stub
|
||||
m_fd = 0;
|
||||
m_curState = CPIN;
|
||||
m_dial = 0;
|
||||
m_APN = 0;
|
||||
}
|
||||
|
||||
Dial::~Dial() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
int Dial::openPort(const char* pPort)
|
||||
{
|
||||
m_fd = config_uart(pPort,115200);
|
||||
print_info("m_fd = %d\n",m_fd);
|
||||
return m_fd;
|
||||
}
|
||||
int Dial::parseData(Event event,const char* pData)
|
||||
{
|
||||
print_info("m_curState = %d,event = %d\n",m_curState,event);
|
||||
string signal;
|
||||
string ret;
|
||||
std::string str;
|
||||
int pos = 0;
|
||||
switch(event){
|
||||
case Event_CPIN:
|
||||
if(!strncmp(pData,"READY",5)){
|
||||
m_curState = QCFGNET;
|
||||
}else if(!strncmp(pData,"NOT READY",9)){
|
||||
m_curState = CPIN;
|
||||
GlobalConfig::NetStatus = "\"LIMSRV\"";
|
||||
}
|
||||
break;
|
||||
case Event_QCFGNET:
|
||||
case Event_QCFGSMS:
|
||||
/*ret = GetOneContent(pData,1,",");
|
||||
if(ret == "0")
|
||||
{
|
||||
m_curState = QICSGPAPN;
|
||||
}*/
|
||||
break;
|
||||
case Event_QICSGPAPN:
|
||||
//if(!strcmp(pData,"OK"))
|
||||
{
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
break;
|
||||
case Event_QENG:
|
||||
GlobalConfig::NetStatus = GetOneContent(pData,1,",");
|
||||
GlobalConfig::NetType = GetOneContent(pData,2,",");
|
||||
signal = GetOneContent(pData,12,",");
|
||||
GlobalConfig::NetSignal = atoi(signal.c_str());
|
||||
print_info("NetStatus = %s,NetSignal = %d\n",GlobalConfig::NetStatus.c_str(),GlobalConfig::NetSignal);
|
||||
break;
|
||||
case Event_QNETDEVCTL:
|
||||
print_info("m_curState Event_QNETDEVCTL = %d\n",m_curState);
|
||||
if(m_dial == 1){
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
break;
|
||||
case Event_QNETDEVSTATUS:
|
||||
ret = GetOneContent(pData,3,",");
|
||||
if(ret == "0" || ret == "")
|
||||
m_curState = QDCHPC;
|
||||
else
|
||||
m_curState = QNETDEVSTATUS;
|
||||
break;
|
||||
case Event_OK:
|
||||
if(m_curState == QNETDEVCTL && m_dial == 1)
|
||||
{
|
||||
m_dial = 0;
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
if(m_curState == Event_QCFGNET){
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
if(m_curState == QICSGPAPN && m_APN == 1)
|
||||
{
|
||||
m_APN = 0;
|
||||
m_curState = QNETDEVCTL;
|
||||
}
|
||||
|
||||
break;
|
||||
case Event_ERROR:
|
||||
if(m_curState == CPIN && !strcmp(pData,"3")){
|
||||
m_curState = CPIN;
|
||||
GlobalConfig::NetStatus = "\"LIMSRV\"";
|
||||
}
|
||||
if(m_curState == QNETDEVCTL){
|
||||
m_curState = QNETDEVSTATUS;
|
||||
}
|
||||
break;
|
||||
case Event_TEMP:
|
||||
str = string(pData);
|
||||
pos = str.find("soc-thermal");
|
||||
if(pos > 0){
|
||||
std::string socTmp = str.substr(pos+14,2);
|
||||
GlobalConfig::NR5GTemp = socTmp;
|
||||
print_info("NR5GTemp = %s\n",GlobalConfig::NR5GTemp.c_str());
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
int Dial::recvData()
|
||||
{
|
||||
|
||||
char szbuffer[200]={0x00};
|
||||
int offSize = 0;
|
||||
int timeoutflag = 0;
|
||||
while(1)
|
||||
{
|
||||
char buff[1024]={0x00};
|
||||
|
||||
int ret = read_data(m_fd, buff, 1024, 10);
|
||||
if(ret <= 0){
|
||||
timeoutflag ++;
|
||||
if(timeoutflag > 5)
|
||||
{
|
||||
timeoutflag = 0;
|
||||
const char *strQENG = "+QENG: ";
|
||||
const char *strQNETDEVCTL = "+QNETDEVCTL: ";
|
||||
const char *strQICSGP = "+QICSGP: ";
|
||||
const char *strQNETDEVSTATUS= "+QNETDEVSTATUS: ";
|
||||
const char *strQCFG= "+QCFG: ";
|
||||
const char *strCPIN= "+CPIN: ";
|
||||
const char *strERROR= "+CME ERROR: ";
|
||||
const char *strQTEMP= "+QTEMP: ";
|
||||
const char *strOK= "OK";
|
||||
char data[128] = {0};
|
||||
char *pdata = strstr((char*)szbuffer, strQENG);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+7, sizeof(data));
|
||||
print_purple("strQENG = %s\n",data);
|
||||
parseData(Event_QENG,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQNETDEVCTL);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+13, sizeof(data));
|
||||
print_purple("strQNETDEVCTL = %s\n",data);
|
||||
parseData(Event_QNETDEVCTL,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQICSGP);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+9, sizeof(data));
|
||||
print_purple("strQICSGP = %s\n",data);
|
||||
parseData(Event_QICSGPAPN,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQNETDEVSTATUS);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+16, sizeof(data));
|
||||
print_purple("strQNETDEVSTATUS = %s\n",data);
|
||||
parseData(Event_QNETDEVSTATUS,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQCFG);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+7, sizeof(data));
|
||||
print_purple("strQCFG = %s\n",data);
|
||||
parseData(Event_QCFGNET,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strCPIN);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+7, sizeof(data));
|
||||
print_purple("strCPIN = %s\n",data);
|
||||
parseData(Event_CPIN,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strQTEMP);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+8, sizeof(data));
|
||||
print_purple("strQTEMP = %s\n",data);
|
||||
parseData(Event_TEMP,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strERROR);
|
||||
if(pdata){
|
||||
strncpy(data, pdata+12, sizeof(data));
|
||||
print_purple("strERROR = %s\n",data);
|
||||
parseData(Event_ERROR,data);
|
||||
}
|
||||
pdata = strstr((char*)szbuffer, strOK);
|
||||
if(pdata){
|
||||
parseData(Event_OK,data);
|
||||
}
|
||||
memset(szbuffer,0x00,sizeof(szbuffer));
|
||||
offSize = 0;
|
||||
}
|
||||
usleep(100);
|
||||
}else if(ret > 0){
|
||||
print_info("ret = %d,buff = %s\n",ret,buff);
|
||||
memcpy(szbuffer + offSize,buff,ret);
|
||||
offSize = offSize + ret;
|
||||
print_info("szbuffer = %s\n",szbuffer);
|
||||
continue;
|
||||
}
|
||||
usleep(500000);
|
||||
}
|
||||
}
|
||||
int Dial::queryPin()
|
||||
{
|
||||
int iRet = write_data(m_fd,"AT+CPIN?\r\n",12);
|
||||
}
|
||||
int Dial::configNet()
|
||||
{
|
||||
write_data(m_fd,"AT+QCFG=\"NAT\"\r\n",19);
|
||||
}
|
||||
int Dial::configApn()
|
||||
{
|
||||
m_APN = 1;
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
char szCmd[100]={0x00};
|
||||
sprintf(szCmd,"AT+QICSGP=1,1,\"%s\",\"\",\"\",1\r\n",strAPN.c_str());
|
||||
int iRet = write_data(m_fd,szCmd,strlen(strAPN.c_str()) + 34);
|
||||
print_info("configApn = %d,data = %s\n",iRet,szCmd);
|
||||
}
|
||||
int Dial::getCsq()
|
||||
{
|
||||
write_data(m_fd,"AT+QENG=\"servingcell\"\r\n",27);
|
||||
}
|
||||
int Dial::getTemp()
|
||||
{
|
||||
write_data(m_fd,"AT+QTEMP\r\n",12);
|
||||
}
|
||||
int Dial::conncectUSB()
|
||||
{
|
||||
int iRet = write_data(m_fd,"AT+QNETDEVCTL=1,1,1\r\n",23);
|
||||
print_info("conncectUSB = %d\n",iRet);
|
||||
}
|
||||
int Dial::dial5G()
|
||||
{
|
||||
while(1){
|
||||
|
||||
if(m_curState == CPIN){
|
||||
queryPin();
|
||||
}
|
||||
if(m_curState == QCFGNET){
|
||||
configNet();
|
||||
//configims();
|
||||
}
|
||||
if(m_curState == QICSGPAPN){
|
||||
configApn();
|
||||
}
|
||||
if(m_curState == QENG){
|
||||
getCsq();
|
||||
|
||||
}
|
||||
if(m_curState == QNETDEVCTL){
|
||||
conncectUSB();
|
||||
m_dial = 1;
|
||||
}
|
||||
if(m_curState == QNETDEVSTATUS){
|
||||
write_data(m_fd,"AT+QNETDEVSTATUS=1\r\n",22);
|
||||
}
|
||||
if(m_curState == QDCHPC){
|
||||
configdhcp();
|
||||
m_curState = QENG;
|
||||
}
|
||||
sleep(5);
|
||||
getTemp();
|
||||
sleep(15);
|
||||
}
|
||||
}
|
||||
int Dial::configims()
|
||||
{
|
||||
write_data(m_fd,"AT+QCFG=\"ims\",0\r\n",21);
|
||||
}
|
||||
int Dial::configdhcp()
|
||||
{
|
||||
system("busybox udhcpc -f -n -q -t 5 -i usb0");
|
||||
}
|
||||
int Dial::setState()
|
||||
{
|
||||
m_curState = CPIN;
|
||||
}
|
||||
int Dial::closePort()
|
||||
{
|
||||
close(m_fd);
|
||||
}
|
70
dial5G/Dial.h
Normal file
70
dial5G/Dial.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Dial.h
|
||||
*
|
||||
* Created on: 2023年6月13日
|
||||
* Author: chaos
|
||||
*/
|
||||
|
||||
#ifndef DIAL5G_DIAL_H_
|
||||
#define DIAL5G_DIAL_H_
|
||||
#include <string>
|
||||
#include "../common/SH_global.h"
|
||||
using namespace std;
|
||||
class Dial {
|
||||
public:
|
||||
Dial();
|
||||
virtual ~Dial();
|
||||
|
||||
//枚举所有状态
|
||||
enum State
|
||||
{
|
||||
CPIN = 0,
|
||||
QCFGNET,
|
||||
QICSGPAPN,
|
||||
QCFGSMS,
|
||||
QENG,
|
||||
QNETDEVCTL,
|
||||
QNETDEVSTATUS,
|
||||
QDCHPC,
|
||||
NORMAL
|
||||
};
|
||||
|
||||
//枚举所有事件
|
||||
enum Event
|
||||
{
|
||||
Event_CPIN = 0,
|
||||
Event_QCFGNET,
|
||||
Event_QICSGPAPN,
|
||||
Event_QCFGSMS,
|
||||
Event_QENG,
|
||||
Event_QNETDEVCTL,
|
||||
Event_QNETDEVSTATUS,
|
||||
Event_OK,
|
||||
Event_ERROR,
|
||||
Event_TEMP
|
||||
};
|
||||
|
||||
State m_curState;
|
||||
int m_fd;
|
||||
int m_dial;
|
||||
int m_APN;
|
||||
int openPort(const char* pPort);
|
||||
int closePort();
|
||||
int recvData();
|
||||
int queryPin();
|
||||
int configNet();
|
||||
int configApn();
|
||||
int getCsq();
|
||||
int getTemp();
|
||||
int conncectUSB();
|
||||
int dial5G();
|
||||
int configims();
|
||||
int configdhcp();
|
||||
int parseData(Event event,const char* pData);
|
||||
int setState();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* DIAL5G_DIAL_H_ */
|
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,7 @@
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
@ -13,6 +14,7 @@
|
||||
#include "../calculation/Calculation.hpp"
|
||||
#include "../uart/SH_Uart.hpp"
|
||||
#include "../datatransfer/SH_Datatrans.hpp"
|
||||
#include "../wifi/wpa_client.h"
|
||||
|
||||
|
||||
class JsonData {
|
||||
@ -26,8 +28,10 @@ public :
|
||||
std::string JsonCmd_26(Param_26 ¶m);
|
||||
std::string JsonCmd_27(Json::Value & recvBody);
|
||||
std::string JsonCmd_29(Param_29 ¶m); //系统配置信息
|
||||
std::string JsonCmd_50(Json::Value & recvBody);
|
||||
std::string JsonCmd_50(Json::Value & recvBody); //download update file
|
||||
std::string JsonCmd_51(Json::Value & recvBody);
|
||||
std::string JsonCmd_52();//upload static data
|
||||
std::string JsonCmd_53(Json::Value & recvBody);
|
||||
void JsonCmd_38(Json::Value &recvBody); //获取原始数据
|
||||
void JsonCmd_39(Json::Value &recvBody); //更新传感器程序
|
||||
|
||||
@ -37,24 +41,34 @@ public :
|
||||
std::string JsonCmd_Cgi_07(); //获取系统内存温度硬盘等信息
|
||||
std::string JsonCmd_07(); //获取系统内存温度硬盘等信息
|
||||
std::string JsonCmd_Cgi_08(); //重启
|
||||
std::string JsonCmd_Cgi_09(); //实时数据获取
|
||||
std::string JsonCmd_Cgi_09(Param_09 ¶m); //实时数据获取
|
||||
std::string JsonCmd_Cgi_10(Param_10 ¶m); //
|
||||
std::string JsonCmd_Cgi_11(Param_11 ¶m); //
|
||||
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_26(Param_26 ¶m);
|
||||
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_40(Param_40 ¶m); //
|
||||
std::string JsonCmd_Cgi_41(std::vector<Param_41> ¶m); //
|
||||
std::string JsonCmd_Cgi_42(Param_42 ¶m); //从web端更新程序
|
||||
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_50(); //
|
||||
std::string JsonCmd_Cgi_51(Param_51 ¶m); //
|
||||
std::string JsonCmd_Cgi_52(Param_52 ¶m);
|
||||
std::string JsonCmd_Cgi_53(std::vector<Param_53> ¶m);
|
||||
std::string JsonCmd_Cgi_default();
|
||||
|
||||
private :
|
||||
|
@ -21,26 +21,30 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
}
|
||||
|
||||
std::string data_r = (std::string)(pData_r);
|
||||
LOG_INFO("MQTT recv base64 %s\n",data_r.c_str());
|
||||
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;
|
||||
|
||||
LOG_INFO("MQTT recv %s\n",pData.c_str());
|
||||
print_brown("pData : %s \n", pData.c_str());
|
||||
Json::Reader recvReader;
|
||||
Json::Value recvValue;
|
||||
Json::Value recvBody;
|
||||
if (recvReader.parse(pData, recvValue)) {
|
||||
int cmdType = atoi(recvValue["cmd"].asString().c_str());
|
||||
if(cmdType == 41){
|
||||
recvBody = recvValue["cmdBody"];
|
||||
}else{
|
||||
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 7:{
|
||||
JsonData jd;
|
||||
@ -53,8 +57,8 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
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("echo 1 > /CIDW/start");
|
||||
sleep(1);
|
||||
system("reboot");
|
||||
}
|
||||
break;
|
||||
@ -65,9 +69,9 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
return;
|
||||
}*/
|
||||
std::string timestamp = recvBody["timestamp"].asString();
|
||||
unsigned long itimestamp = boost::lexical_cast<unsigned long>(timestamp);
|
||||
unsigned long itimestamp = atol(timestamp.c_str());
|
||||
SetTime(itimestamp);
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(200));
|
||||
usleep(200);
|
||||
system("hwclock -w");
|
||||
if (!recvValue["ZoneId"].isNull() && recvValue["ZoneId"].asString().length() > 0) {
|
||||
std::string zoneid = recvValue["ZoneId"].asString();
|
||||
@ -134,8 +138,8 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
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());
|
||||
param.mPort = to_string(recvBody["localServerPort"].asInt());
|
||||
param.mCommMode = to_string(recvBody["CommMode"].asInt());
|
||||
} else {
|
||||
param.mMode = 1;
|
||||
}
|
||||
@ -194,11 +198,49 @@ void LocalServer::HandleFromServer(const char *pData_r, int pLen, const char *to
|
||||
std::string data = jd.JsonCmd_50(recvBody);
|
||||
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
}break;
|
||||
case 41:{
|
||||
|
||||
JsonData jd;
|
||||
Param_41 param;
|
||||
std::vector<Param_41> param41;
|
||||
for(int i = 0; i < recvBody.size();i++){
|
||||
param.mdataNodeNo = recvBody[i]["dataNodeNo"].asString();
|
||||
param.mfeatureInterVal = recvBody[i]["featureInterVal"].asInt();
|
||||
param.mwaveInterVal = recvBody[i]["waveInterVal"].asInt();
|
||||
param.msamplingRate = recvBody[i]["samplingRate"].asInt();
|
||||
param.mrange = recvBody[i]["range"].asInt();
|
||||
param.mAccSampleTime = recvBody[i]["ACCSampleTime"].asInt();
|
||||
param.mstartBrands = recvBody[i]["startBrands"].asString();
|
||||
param.mstopBrands = recvBody[i]["stopBrands"].asString();
|
||||
param.menvelopeBandPass = recvBody[i]["envelopeBandPass"].asString();
|
||||
param.mviff = recvBody[i]["viff"].asInt();
|
||||
param.mfaultFrequency = recvBody[i]["faultFrequency"].asString();
|
||||
param41.push_back(param);
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_41(param41);
|
||||
char whereCon[64] = { 0 };
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mdataNodeNo.c_str());
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
|
||||
}
|
||||
break;
|
||||
case 51:{
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_51(recvBody);
|
||||
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
}break;
|
||||
case 52:{
|
||||
// JsonData jd;
|
||||
// std::string data = jd.JsonCmd_52(recvBody);
|
||||
// data_publish(data.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
}break;
|
||||
case 53:{
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_53(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;
|
||||
@ -274,7 +316,30 @@ try{
|
||||
break;
|
||||
case 9:{
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_09();
|
||||
Param_09 param;
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_09(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 10:{
|
||||
JsonData jd;
|
||||
Param_10 param;
|
||||
param.strDataNode = recvBody["DataNode"].asString();
|
||||
param.strStatic = recvBody["Static"].asString();
|
||||
param.straxis = recvBody["Raxis"].asString();
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
param.timeStart = recvBody["timeStart"].asString();
|
||||
param.timeEnd = recvBody["timeEnd"].asString();
|
||||
std::string data = jd.JsonCmd_Cgi_10(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 11:{
|
||||
JsonData jd;
|
||||
Param_11 param;
|
||||
param.DataNodeNo = recvBody["DataNode"].asString();
|
||||
std::string data = jd.JsonCmd_Cgi_11(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
@ -319,7 +384,10 @@ try{
|
||||
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());
|
||||
param.mCommMode = recvBody["SystemSettings"]["CommMode"].asString();
|
||||
param.mUserName = recvBody["SystemSettings"]["UserName"].asString();
|
||||
param.mPassword = recvBody["SystemSettings"]["Password"].asString();
|
||||
param.mAPN = recvBody["SystemSettings"]["APN"].asString();
|
||||
} else {
|
||||
param.mMode = 1;
|
||||
}
|
||||
@ -333,10 +401,11 @@ try{
|
||||
Param_25 param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("SET")) {
|
||||
param.mNet = recvBody["net"].asString();
|
||||
param.mDnsName = recvBody["dnsName"].asString();
|
||||
param.mGateway = recvBody["gateway"].asString();
|
||||
param.mHostName = recvBody["hostName"].asString();
|
||||
param.mIp = recvBody["dataNodeGatewayIpAddress"].asString();
|
||||
param.mIp = recvBody["dataWatchIpAddress"].asString();
|
||||
param.mSubnetMask = recvBody["subnetMask"].asString();
|
||||
param.mNetworkPortStatus = recvBody["networkPortStatus"].asString();
|
||||
param.mMode = 0;
|
||||
@ -351,8 +420,10 @@ try{
|
||||
break;
|
||||
case 26:{
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_26();
|
||||
printf("data = %s\n",data.c_str());
|
||||
Param_26 param;
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_26(param);
|
||||
// print_info("data = %s\n",data.c_str());
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
@ -415,6 +486,119 @@ try{
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 40:{
|
||||
JsonData jd;
|
||||
Param_40 param;
|
||||
param.mChannelId = recvBody["channelId"].asString();
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
|
||||
param.StartFrequency = recvBody["StartFrequency"].asInt();
|
||||
param.EndFrequency = recvBody["EndFrequency"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_40(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 41:{
|
||||
JsonData jd;
|
||||
Param_41 param;
|
||||
std::vector<Param_41> param41;
|
||||
for(int i = 0; i < recvBody.size();i++){
|
||||
param.mdataNodeNo = recvBody[i]["dataNodeNo"].asString();
|
||||
param.mfeatureInterVal = recvBody[i]["featureInterVal"].asInt();
|
||||
param.mwaveInterVal = recvBody[i]["waveInterVal"].asInt();
|
||||
param.msamplingRate = recvBody[i]["samplingRate"].asInt();
|
||||
param.mrange = recvBody[i]["range"].asInt();
|
||||
param.mAccSampleTime = recvBody[i]["ACCSampleTime"].asInt();
|
||||
param.mstartBrands = recvBody[i]["startBrands"].asString();
|
||||
param.mstopBrands = recvBody[i]["stopBrands"].asString();
|
||||
param.menvelopeBandPass = recvBody[i]["envelopeBandPass"].asString();
|
||||
param.mviff = recvBody[i]["viff"].asInt();
|
||||
param.mfaultFrequency = recvBody[i]["faultFrequency"].asString();
|
||||
param41.push_back(param);
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_41(param41);
|
||||
char whereCon[64] = { 0 };
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mdataNodeNo.c_str());
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 42:{
|
||||
JsonData jd;
|
||||
Param_42 param;
|
||||
param.fileName = recvBody["fileName"].asString();
|
||||
std::string data = jd.JsonCmd_Cgi_42(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 50:{
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_50();
|
||||
return data;
|
||||
}
|
||||
|
||||
break;
|
||||
case 51:{
|
||||
JsonData jd;
|
||||
Param_51 param;
|
||||
std::string type = recvBody["type"].asString();
|
||||
if(0 == type.compare("SET")){
|
||||
param.mMode = 0;
|
||||
param.strGateWayMAC = recvBody["gateWayNo"].asString();
|
||||
param.strGateWayLocation = recvBody["gateWayLocation"].asString();
|
||||
|
||||
}else{
|
||||
param.mMode = 1;
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_51(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 52:{
|
||||
Param_52 param;
|
||||
param.mCmdSerial = recvValue["cmdSerial"].asString();
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("SCAN")) {
|
||||
param.mMode = 0;
|
||||
}
|
||||
if (0 == type.compare("SET")) {
|
||||
param.mMode = 1;
|
||||
param.mSsid = recvBody["ssid"].asString();
|
||||
param.mPassWord = recvBody["password"].asString();
|
||||
}
|
||||
if (0 == type.compare("GET")) {
|
||||
param.mMode = 2;
|
||||
}
|
||||
if (0 == type.compare("CLEAN")) {
|
||||
param.mMode = 3;
|
||||
}
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_52(param);
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
case 53:{
|
||||
JsonData jd;
|
||||
Param_53 param;
|
||||
std::vector<Param_53> param53;
|
||||
for(int i = 0; i < recvBody.size();i++){
|
||||
param.mdataNodeNo = recvBody[i]["dataNodeNo"].asString();
|
||||
param.mUpdateKey = recvBody[i]["updateKey"].asString();
|
||||
param.mUpdateValue = recvBody[i]["updateValue"].asString();
|
||||
param.mUpdateKey2 = recvBody[i]["updateKey2"].asString();
|
||||
param.mUpdateValue2 = recvBody[i]["updateValue2"].asString();
|
||||
param.mUpdateKey3 = recvBody[i]["updateKey3"].asString();
|
||||
param.mUpdateValue3 = recvBody[i]["updateValue3"].asString();
|
||||
param53.push_back(param);
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_53(param53);
|
||||
char whereCon[64] = { 0 };
|
||||
sprintf(whereCon, "dataNodeNo='%s'", param.mdataNodeNo.c_str());
|
||||
string strData = sql_ctl->GetNodeConfigureInfor(whereCon);
|
||||
data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
return data;
|
||||
}break;
|
||||
default:
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_default();
|
||||
|
73
main.cpp
73
main.cpp
@ -42,29 +42,69 @@ int main(int argc, char *argv[])
|
||||
// 初始化平台配置文件
|
||||
platform->PlatFormInit();
|
||||
|
||||
//启动 mqtt客户端
|
||||
boost::thread startMqtt(StartMqttClient);
|
||||
startMqtt.detach();
|
||||
|
||||
|
||||
sql_ctl->InintGateway();
|
||||
sql_ctl->CalculateDip();
|
||||
sql_ctl->CalculateBattery();
|
||||
pUart->InitZigbee();
|
||||
// UDP,接收客户端发来的组播消息,用于外接 QT 专家系统,屏蔽之
|
||||
boost::thread searchT(attrs,SearchThread);
|
||||
boost::thread searchT(SearchThread);
|
||||
searchT.detach();
|
||||
|
||||
// 串口处理线程,用于与 ZigBee 模块通信,通过ZigBee无线通信技术与无线传感器通信
|
||||
boost::thread uartReadTh(UartStart);
|
||||
uartReadTh.detach();
|
||||
|
||||
boost::thread uartTestReadTh(TestUart);
|
||||
uartReadTh.detach();
|
||||
|
||||
boost::thread InitModuleReadTh(InitModule);
|
||||
InitModuleReadTh.detach();
|
||||
//boost::thread uartWatchDogReadTh(WatchDog);
|
||||
//uartWatchDogReadTh.detach();
|
||||
|
||||
// 休眠2秒,等待串口线程初始化完毕
|
||||
boost::this_thread::sleep(boost::posix_time::seconds(2));
|
||||
sleep(2);
|
||||
|
||||
// 串口数据处理,读取传感器原始波形数据
|
||||
boost::thread uartWaveReadTh(UartStartWave);
|
||||
uartWaveReadTh.detach();
|
||||
|
||||
//启动 mqtt客户端
|
||||
boost::thread startMqtt(StartMqttClient);
|
||||
startMqtt.detach();
|
||||
|
||||
|
||||
//启动 mqtt 心跳
|
||||
boost::thread startHeart(HeartRep);
|
||||
startHeart.detach();
|
||||
|
||||
//启动 mqtt 心跳
|
||||
boost::thread startRunLED(RunLED);
|
||||
startRunLED.detach();
|
||||
|
||||
#ifdef NR5G_MODULE
|
||||
print_info("NR5G_MODULE \n");
|
||||
//5G
|
||||
boost::thread startCSQ(GetCSQ);
|
||||
startCSQ.detach();
|
||||
#ifndef NR5G_MEIGE
|
||||
boost::thread startDial(Dial5G);
|
||||
startDial.detach();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef Q4G_MODULE
|
||||
boost::thread startCSQ(GetCSQ);
|
||||
startCSQ.detach();
|
||||
print_info("4G_MODULE \n");
|
||||
|
||||
#endif
|
||||
#ifdef WIFI_MODULE
|
||||
print_info("WiFi_MODULE \n");
|
||||
#endif
|
||||
|
||||
// 通过UDP接收数据
|
||||
boost::thread StartConnectSys(attrs, StartUdpSys);
|
||||
StartConnectSys.detach();
|
||||
@ -81,13 +121,30 @@ int main(int argc, char *argv[])
|
||||
boost::thread startTcpCgi(attrs,StartCgiServer);
|
||||
startTcpCgi.detach();
|
||||
|
||||
//pUart->UpdateZigbeeInfoCtrl();
|
||||
|
||||
sleep(5);
|
||||
pUart->ZigbeeInit();
|
||||
sleep(1);
|
||||
pUart->UpdateZigbeeInfoCtrl();
|
||||
boost::this_thread::sleep(boost::posix_time::seconds(5));
|
||||
|
||||
bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
|
||||
print_info("===========status ======== %d\n",status);
|
||||
|
||||
/* char * szRes = sql_ctl->GetDataChar(T_SENSOR_INFO(TNAME), "dataNodeName", "dataNodeNo = '074cfd0000158d00'");
|
||||
printf("szRes = %s\n",szRes);
|
||||
for(int i = 0; i < 64;i++){
|
||||
printf("temp = %02x ",szRes[i]);
|
||||
}*/
|
||||
|
||||
int fd = OpenWatchDog();
|
||||
|
||||
while (GlobalConfig::QuitFlag_G) {
|
||||
boost::this_thread::sleep(boost::posix_time::seconds(20));
|
||||
|
||||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,1);
|
||||
usleep(20000);
|
||||
gpio_set(GlobalConfig::GPIO_G.hardWatchDog,0);
|
||||
WriteWatchDog(fd);
|
||||
sleep(20);
|
||||
// data_publish(senddata.c_str(), GlobalConfig::Topic_G.mPubData.c_str());
|
||||
|
||||
}
|
||||
|
@ -48,21 +48,31 @@ int data_publish(const char *str, const char *topic)
|
||||
{
|
||||
int iRet = -1;
|
||||
if(mosq != NULL){
|
||||
print_blue("data_publish: %s %s\n", str, topic);
|
||||
//print_blue("data_publish: %s %s\n", str, topic);
|
||||
std::string strTopic = std::string(topic);
|
||||
if (strTopic.find("cmd") != std::string::npos) {
|
||||
if (strTopic.find("cmd") != std::string::npos || \
|
||||
strTopic.find("configureInfo") != 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);
|
||||
//char *base64_data = new char[pData.length() * 2];
|
||||
//memset(base64_data, 0, pData.length() *2);
|
||||
//Secure::instance()->Base64Decode(base64_aes, (unsigned char*)base64_data);
|
||||
//std::string pData = std::string(base64_data);
|
||||
if(base64_aes != NULL)
|
||||
delete[] base64_aes;
|
||||
// free(out);
|
||||
} else {
|
||||
iRet = mosquitto_publish(mosq, &mid_sent, topic, strlen(str), str, ud.topic_qos, false);
|
||||
}
|
||||
|
||||
}
|
||||
if(iRet != 0)
|
||||
{
|
||||
reconnect();
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
@ -93,6 +103,10 @@ int disconnect()
|
||||
return mosquitto_disconnect(mosq);
|
||||
}
|
||||
|
||||
int reconnect()
|
||||
{
|
||||
return mosquitto_reconnect(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;
|
||||
@ -123,11 +137,11 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons
|
||||
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");
|
||||
print_info("please call the register_collback function first.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int qos = readIntValue( "config", "qos",(char*)GlobalConfig::Config_G.c_str());
|
||||
mosquitto_lib_init();//使用mosquitto库函数前需进行初始化
|
||||
memset(&mqttsdata, 0, sizeof(mqttsdata_t));
|
||||
memcpy(mqttsdata.gwid, gwid, strlen(gwid));
|
||||
@ -142,19 +156,28 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons
|
||||
host = localip;
|
||||
mqttsdata.port = GlobalConfig::ServerPort;
|
||||
port = GlobalConfig::ServerPort;
|
||||
|
||||
#ifdef WIFI_MODULE
|
||||
mqttsdata.qos = 0;
|
||||
#else
|
||||
mqttsdata.qos = qos;
|
||||
#endif
|
||||
print_info("mqttsdata.qos = %d\n",mqttsdata.qos);
|
||||
// std::string username = "root";
|
||||
// std::string password = "xom!*283#@XHG";
|
||||
|
||||
std::string username = "chaos";
|
||||
std::string password = "HSD272*#xkd";
|
||||
std::string username = ReadStrByOpt(SERVERCONFIG, "Server", "UserName");
|
||||
std::string password = ReadStrByOpt(SERVERCONFIG, "Server", "Password");
|
||||
if(username == "" || password == ""){
|
||||
username = "chaos";
|
||||
password = "HSD272*#xkd";
|
||||
}
|
||||
|
||||
char userName[100];
|
||||
sprintf(userName, "%s", username.c_str());
|
||||
|
||||
char passWord[100];
|
||||
sprintf(passWord, "%s", password.c_str());
|
||||
|
||||
print_info("userName = %s , passWord = %s\n",userName,passWord);
|
||||
ud.username = userName;
|
||||
ud.password = passWord;
|
||||
|
||||
@ -162,6 +185,7 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons
|
||||
ud.dataUrl = mqttsdata.dataUrl;
|
||||
ud.fsUrl = mqttsdata.fsUrl;
|
||||
will_qos = mqttsdata.qos;
|
||||
ud.topic_qos = will_qos;
|
||||
ud.topic_count++;
|
||||
ud.topics = (char**)realloc(ud.topics, ud.topic_count*sizeof(char *));
|
||||
if (ud.topics == NULL) {
|
||||
@ -172,15 +196,15 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons
|
||||
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]);
|
||||
//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);
|
||||
print_info("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);
|
||||
print_info("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;
|
||||
@ -230,7 +254,7 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons
|
||||
id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0';
|
||||
}
|
||||
}
|
||||
printf("id:%s\n", id);
|
||||
print_info("id:%s\n", id);
|
||||
mosq = mosquitto_new(id, clean_session, &ud);
|
||||
if (!mosq){
|
||||
switch (errno){
|
||||
@ -316,15 +340,17 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons
|
||||
else{
|
||||
rc = mosquitto_connect_bind(mosq, host, port, keepalive, bind_address);
|
||||
}
|
||||
printf("host = %s port = %d rc = %d\n",host,port,rc);
|
||||
print_info("host = %s port = %d rc = %d\n",host,port,rc);
|
||||
if (rc){
|
||||
if (!ud.quiet){
|
||||
if (rc == MOSQ_ERR_ERRNO){
|
||||
strerror_r(errno, err, 1024);
|
||||
fprintf(stderr, "Error_: %s\n", err);
|
||||
//strerror_r(errno, err, 1024);
|
||||
//fprintf(stderr, "Error_: %s\n", err);
|
||||
//print_info("%s",stderr);
|
||||
}
|
||||
else{
|
||||
fprintf(stderr, "Unable to connect (%d).\n", rc);
|
||||
print_info("%s",stderr);
|
||||
}
|
||||
}
|
||||
goto mosq_free;
|
||||
@ -332,7 +358,8 @@ int start_client(const char *boardname, const char *gwid, const char* gwip, cons
|
||||
rc = mosquitto_loop_forever(mosq, -1, 1);
|
||||
if (rc)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", mosquitto_strerror(rc));
|
||||
//fprintf(stderr, "Error: %s\n", mosquitto_strerror(rc));
|
||||
//print_info("%s",stderr);
|
||||
}
|
||||
mosq_free:
|
||||
mosquitto_destroy(mosq);
|
||||
|
@ -61,6 +61,7 @@ extern void register_collback(connect_callback connect_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 reconnect();
|
||||
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);
|
||||
|
@ -9,20 +9,28 @@ int GlobalConfig::RUN_MODE = 0;
|
||||
int GlobalConfig::QuitFlag_G = 1;
|
||||
int GlobalConfig::LinkStatus_G = 0;
|
||||
int GlobalConfig::LinkCount = 0;
|
||||
int GlobalConfig::net0Status = 1;
|
||||
|
||||
|
||||
|
||||
std::string GlobalConfig::Version = "2.0.11";
|
||||
std::string GlobalConfig::Version = "3.0";
|
||||
std::string GlobalConfig::MacAddr_G = "";
|
||||
std::string GlobalConfig::MacAddr_G2 = "";
|
||||
std::string GlobalConfig::IpAddr_G = "";
|
||||
std::string GlobalConfig::ServerIP = "";
|
||||
std::string GlobalConfig::NetStatus = "";
|
||||
std::string GlobalConfig::NetType = "";
|
||||
std::string GlobalConfig::NR5GTemp = "";
|
||||
int GlobalConfig::serverStatus = 0;
|
||||
int GlobalConfig::NetSignal = 0;
|
||||
int GlobalConfig::ServerPort = 0;
|
||||
|
||||
|
||||
TopicList GlobalConfig::Topic_G;
|
||||
ZigbeeInfo GlobalConfig::ZigbeeInfo_G;
|
||||
ZIGBEE GlobalConfig::Zigbee_G;
|
||||
GPIOInfo GlobalConfig::GPIO_G;
|
||||
std::string GlobalConfig::DbName_G = "/opt/configenv/cidn.db"; //数据库名称
|
||||
std::string GlobalConfig::Config_G = "/opt/configenv/config.ini";
|
||||
std::string GlobalConfig::UartName_G = "/dev/ttymxc4";
|
||||
|
||||
// 处理ZigBee网络接收过程的PanID切换
|
||||
@ -41,16 +49,57 @@ PlatformInit::~PlatformInit()
|
||||
void PlatformInit::PlatFormInit()
|
||||
{
|
||||
try{
|
||||
GlobalConfig::MacAddr_G = GetLocalMac();
|
||||
GlobalConfig::MacAddr_G = GetLocalMac("eth0");
|
||||
GlobalConfig::MacAddr_G2 = GetLocalMac("eth1");
|
||||
transform(GlobalConfig::MacAddr_G.begin(), GlobalConfig::MacAddr_G.end(), GlobalConfig::MacAddr_G.begin(), ::toupper);
|
||||
transform(GlobalConfig::MacAddr_G2.begin(), GlobalConfig::MacAddr_G2.end(), GlobalConfig::MacAddr_G2.begin(), ::toupper);
|
||||
GlobalConfig::IpAddr_G = IpAddrInit();
|
||||
print_info("GlobalConfig::IpAddr_G : %s\n", GlobalConfig::IpAddr_G.c_str());
|
||||
this->ConfigFileCheck();
|
||||
print_info("ConfigFileCheck\n");
|
||||
this->TopicInit();
|
||||
print_info("TopicInit\n");
|
||||
this->ServerIpInit();
|
||||
print_info("TopicInit\n");
|
||||
this->Sqlite3Init();
|
||||
this->GPIOInit();
|
||||
|
||||
print_info("ServerIP : %s \n", GlobalConfig::ServerIP.c_str());
|
||||
std::string strMac = sql_ctl->GetData("t_gateway_info","gatewayMAC",NULL);
|
||||
if(strMac == "60294D208517"){
|
||||
char szUpdateSql[100]={0x00};
|
||||
sprintf(szUpdateSql,"gatewayMAC = '%s'",GlobalConfig::MacAddr_G.c_str());
|
||||
sql_ctl->UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
||||
}
|
||||
else if(strMac != GlobalConfig::MacAddr_G ){
|
||||
LOG_ERROR("MAC error strMac1 = %s,MacAddr_G1 = %s\n",strMac.c_str(),GlobalConfig::MacAddr_G.c_str());
|
||||
strMac.insert(2,":");
|
||||
strMac.insert(5,":");
|
||||
strMac.insert(8,":");
|
||||
strMac.insert(11,":");
|
||||
strMac.insert(14,":");
|
||||
ModifyMac((char*)strMac.c_str());
|
||||
//system("reboot");
|
||||
}
|
||||
#ifdef G2UL_GATEWAY
|
||||
std::string strMac2 = sql_ctl->GetData("t_gateway_info","MAC2",NULL);
|
||||
if(strMac2 == "60294D208518"){
|
||||
char szUpdateSql[100]={0x00};
|
||||
sprintf(szUpdateSql,"MAC2 = '%s'",GlobalConfig::MacAddr_G2.c_str());
|
||||
sql_ctl->UpdateTableData("t_gateway_info",szUpdateSql,NULL);
|
||||
}
|
||||
else if(strMac2 != GlobalConfig::MacAddr_G2 ){
|
||||
LOG_ERROR("MAC error strMac2 = %s,MacAddr_G2 = %s\n",strMac2.c_str(),GlobalConfig::MacAddr_G2.c_str());
|
||||
strMac2.insert(2,":");
|
||||
strMac2.insert(5,":");
|
||||
strMac2.insert(8,":");
|
||||
strMac2.insert(11,":");
|
||||
strMac2.insert(14,":");
|
||||
ModifyMac((char*)strMac2.c_str());
|
||||
//system("reboot");
|
||||
}
|
||||
#endif
|
||||
|
||||
// sleep(10);
|
||||
} catch(...){
|
||||
print_error("PlatFormInit exception happend.\n");
|
||||
@ -66,7 +115,7 @@ void PlatformInit::TopicInit()
|
||||
|
||||
GlobalConfig::Topic_G.mPubHeart = "wireless/heart/" + GlobalConfig::MacAddr_G;//
|
||||
|
||||
GlobalConfig::Topic_G.mPubConfig = "wireless/configureInfor/" + GlobalConfig::MacAddr_G;
|
||||
GlobalConfig::Topic_G.mPubConfig = "wireless/configureInfo/" + GlobalConfig::MacAddr_G;
|
||||
|
||||
GlobalConfig::Topic_G.mPubWaveData = "wireless/realTimeData/" + GlobalConfig::MacAddr_G;
|
||||
|
||||
@ -78,6 +127,8 @@ void PlatformInit::TopicInit()
|
||||
|
||||
GlobalConfig::Topic_G.mPubRep = "wireless/resp/" + GlobalConfig::MacAddr_G;
|
||||
|
||||
GlobalConfig::Topic_G.mPubTiming = "equipment/cmd/" + GlobalConfig::MacAddr_G;
|
||||
|
||||
|
||||
GlobalConfig::Topic_G.mPubLocalWifi = "up/" + GlobalConfig::MacAddr_G + "/recive/wifi";
|
||||
|
||||
@ -128,7 +179,7 @@ int PlatformInit::ServerIpInit()
|
||||
{
|
||||
if (access(SERVERCONFIG, 0) >= 0) {
|
||||
GlobalConfig::ServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||
GlobalConfig::ServerPort = boost::lexical_cast<int>(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort"));
|
||||
GlobalConfig::ServerPort = atoi(ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort").c_str());
|
||||
}
|
||||
|
||||
}
|
||||
@ -136,10 +187,43 @@ int PlatformInit::ServerIpInit()
|
||||
void PlatformInit::Sqlite3Init()
|
||||
{
|
||||
sql_ctl->OpenDB(GlobalConfig::DbName_G.c_str());
|
||||
char szValue[10] = {0x00};
|
||||
int nType = readIntValue( "Update", "type",(char*)GlobalConfig::Config_G.c_str());
|
||||
if(nType== 1){
|
||||
sql_ctl->SqliteInitDel(GlobalConfig::DbName_G.c_str());
|
||||
writeIntValue("Update", "type",0,(char*)GlobalConfig::Config_G.c_str());
|
||||
}
|
||||
print_info("szValue = %d\n",nType);
|
||||
sql_ctl->SqliteInit(GlobalConfig::DbName_G.c_str());
|
||||
print_info("Sqlite3Init \n");
|
||||
}
|
||||
|
||||
void PlatformInit::GPIOInit()
|
||||
{
|
||||
#ifdef G2UL_GATEWAY
|
||||
GlobalConfig::GPIO_G.zigAckrep = 507;
|
||||
GlobalConfig::GPIO_G.zigAckreset = 499;
|
||||
GlobalConfig::GPIO_G.zigReset = 496;
|
||||
GlobalConfig::GPIO_G.commPower = 363;
|
||||
GlobalConfig::GPIO_G.vol3_8 = 498;
|
||||
GlobalConfig::GPIO_G.commRest = 466;
|
||||
GlobalConfig::GPIO_G.wifiPower = 488;
|
||||
GlobalConfig::GPIO_G.wifiReset = 474;
|
||||
GlobalConfig::GPIO_G.hardWatchDog = 497;
|
||||
GlobalConfig::GPIO_G.zigDef = 408;
|
||||
GlobalConfig::GPIO_G.runLed = 409;
|
||||
GlobalConfig::GPIO_G.errorLed = 410;
|
||||
GlobalConfig::GPIO_G.netResetNet0 = 489;
|
||||
#else if IMX6UL_GATEWAY
|
||||
GlobalConfig::GPIO_G.zigAckrep = 119;
|
||||
GlobalConfig::GPIO_G.zigAckreset = 120;
|
||||
GlobalConfig::GPIO_G.zigReset = 116;
|
||||
GlobalConfig::GPIO_G.wifiReset = 8;
|
||||
GlobalConfig::GPIO_G.commRest = 8;
|
||||
GlobalConfig::GPIO_G.power = 9;
|
||||
GlobalConfig::GPIO_G.errorLed = 130;
|
||||
#endif
|
||||
}
|
||||
void PlatformInit::SystemInfoInit()
|
||||
{
|
||||
std::ifstream ifileOut(SYSTEMINFOFILE);
|
||||
@ -182,14 +266,14 @@ void PlatformInit::UserInit()
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformInit::EquipIpInit()
|
||||
void PlatformInit::EquipIpInit(std::string eth)
|
||||
{
|
||||
//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 networkPortStatus = ReadStrByOpt(NETWORKCONFIG, eth, "networkPortStatus");
|
||||
std::string subnetMask = ReadStrByOpt(NETWORKCONFIG, eth, "subnetMask");
|
||||
std::string gateway = ReadStrByOpt(NETWORKCONFIG, eth, "gateway");
|
||||
std::string dataWatchIpAddress = ReadStrByOpt(NETWORKCONFIG, eth, "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());
|
||||
|
||||
@ -197,18 +281,31 @@ void PlatformInit::EquipIpInit()
|
||||
{
|
||||
print_white("dhcp config\n");
|
||||
std::string cmd = "";
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
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");
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
if(eth == "eth0"){
|
||||
system("sed -i '5c DHCP=ipv4' /etc/systemd/network/static/10-eth0-static.network");
|
||||
system("sed -i '6c ' /etc/systemd/network/static/10-eth0-static.network");
|
||||
system("sed -i '7c ' /etc/systemd/network/static/10-eth0-static.network");
|
||||
}else if(eth == "eth1"){
|
||||
system("sed -i '5c DHCP=ipv4' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
||||
system("sed -i '6c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
||||
system("sed -i '7c ' /etc/systemd/network/dynamic/20-eth1-dynamic.network");
|
||||
}
|
||||
#endif
|
||||
flag = 0;
|
||||
}
|
||||
if(0 == networkPortStatus.compare("STATIC"))
|
||||
{
|
||||
std::string cmd = "";
|
||||
print_red("static config\n");
|
||||
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
system("sed -i '18c iface eth0 inet static' /etc/network/interfaces");
|
||||
if(dataWatchIpAddress.length() > 0)
|
||||
{
|
||||
@ -236,15 +333,34 @@ void PlatformInit::EquipIpInit()
|
||||
}
|
||||
system(cmd.c_str());
|
||||
cmd.clear();
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
if(eth == "eth0"){
|
||||
cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/static/10-eth0-static.network";
|
||||
system(cmd.c_str());
|
||||
cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/static/10-eth0-static.network";
|
||||
system(cmd.c_str());
|
||||
cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/static/10-eth0-static.network";
|
||||
system(cmd.c_str());
|
||||
}else if(eth == "eth1"){
|
||||
cmd = "sed -i '5c Address=" + dataWatchIpAddress + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
||||
system(cmd.c_str());
|
||||
cmd = "sed -i '6c Netmask=" + subnetMask + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
||||
system(cmd.c_str());
|
||||
cmd = "sed -i '7c Gateway=" + gateway + "' /etc/systemd/network/dynamic/20-eth1-dynamic.network";
|
||||
system(cmd.c_str());
|
||||
}
|
||||
#endif
|
||||
flag = 1;
|
||||
}
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
|
||||
|
||||
if(1 == flag){ //静态直接更新
|
||||
system("source /etc/config.sh");
|
||||
}
|
||||
if(0 == flag) //动态重新启动获取
|
||||
{
|
||||
system("reboot");
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
system("systemctl restart systemd-networkd.service");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,9 @@ public :
|
||||
/**
|
||||
*@eth0 初始化
|
||||
*/
|
||||
void EquipIpInit();
|
||||
void EquipIpInit(std::string eth);
|
||||
|
||||
void GPIOInit();
|
||||
private:
|
||||
|
||||
/**
|
||||
|
@ -107,7 +107,7 @@ void SearchDev::HandleRecv_1(const boost::system::error_code &pEc,size_t pBytesR
|
||||
std::string status = jsData["status"].asString();
|
||||
if(status.compare("REQ") == 0) {
|
||||
jsData["dataWatchNo"] = GlobalConfig::MacAddr_G.c_str();
|
||||
jsData["localServerIpAddress"] = GlobalConfig::ServerIP;
|
||||
jsData["localServerIpAddress"] = GlobalConfig::IpAddr_G;
|
||||
jsData["status"] = "ACK";
|
||||
jsData["DeviceType"] = "WirelessGateWay";
|
||||
std::string strData = fw.write(jsData);
|
||||
@ -122,6 +122,8 @@ void SearchDev::HandleRecv_1(const boost::system::error_code &pEc,size_t pBytesR
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
print_error("parse error\n");
|
||||
}
|
||||
MultiCastRecv_1();
|
||||
} else {
|
||||
|
503
serial/serial.c
Normal file
503
serial/serial.c
Normal file
@ -0,0 +1,503 @@
|
||||
/*
|
||||
* A library for Linux serial communication
|
||||
*
|
||||
* Author: JoStudio, 2016
|
||||
*
|
||||
* Version: 0.5
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "serial.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <sys/select.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef CMSPAR
|
||||
#define CMSPAR 010000000000
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* convert baud_rate to speed_t
|
||||
*/
|
||||
static speed_t get_speed(unsigned int baud_rate)
|
||||
{
|
||||
switch (baud_rate) {
|
||||
case 0:
|
||||
return B0;
|
||||
case 50:
|
||||
return B50;
|
||||
case 75:
|
||||
return B75;
|
||||
case 110:
|
||||
return B110;
|
||||
case 150:
|
||||
return B150;
|
||||
case 200:
|
||||
return B200;
|
||||
case 300:
|
||||
return B300;
|
||||
case 600:
|
||||
return B600;
|
||||
case 1200:
|
||||
return B1200;
|
||||
case 1800:
|
||||
return B1800;
|
||||
case 2400:
|
||||
return B2400;
|
||||
case 4800:
|
||||
return B4800;
|
||||
case 9600:
|
||||
return B9600;
|
||||
case 19200:
|
||||
return B19200;
|
||||
case 38400:
|
||||
return B38400;
|
||||
case 57600:
|
||||
return B57600;
|
||||
case 115200:
|
||||
return B115200;
|
||||
case 230400:
|
||||
return B230400;
|
||||
case 460800:
|
||||
return B460800;
|
||||
case 500000:
|
||||
return B500000;
|
||||
case 576000:
|
||||
return B576000;
|
||||
case 921600:
|
||||
return B921600;
|
||||
case 1000000:
|
||||
return B1000000;
|
||||
case 1152000:
|
||||
return B1152000;
|
||||
case 1500000:
|
||||
return B1500000;
|
||||
case 2000000:
|
||||
return B2000000;
|
||||
case 2500000:
|
||||
return B2500000;
|
||||
case 3000000:
|
||||
return B3000000;
|
||||
case 3500000:
|
||||
return B3500000;
|
||||
case 4000000:
|
||||
return B4000000;
|
||||
default:
|
||||
//unsupported baud rate
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set baud rate of serial port
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial device
|
||||
* @param baud_rate baud rate
|
||||
*
|
||||
* @return 1 if success
|
||||
* return negative error code if fail
|
||||
*/
|
||||
int serial_set_baud_rate(int file_descriptor, int baud_rate) {
|
||||
/* struct termios termio;
|
||||
speed_t speed;
|
||||
int fd = file_descriptor;
|
||||
|
||||
if ( fd < 0 ) {
|
||||
return SERIAL_INVALID_FILE;
|
||||
}
|
||||
|
||||
memset(&termio, 0, sizeof(termio));
|
||||
|
||||
//get old attribute
|
||||
if (tcgetattr(fd, &termio)) {
|
||||
return SERIAL_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
//calculate baud rate
|
||||
speed = get_speed(baud_rate);
|
||||
if (speed == 0) {
|
||||
return SERIAL_ERROR_BAUDRATE;
|
||||
}
|
||||
cfsetispeed(&termio, speed);
|
||||
cfsetospeed(&termio, speed);
|
||||
|
||||
// set baud rate
|
||||
if (tcsetattr(fd, TCSAFLUSH, &termio) < 0) {
|
||||
return SERIAL_ERROR_BAUDRATE;
|
||||
}*/
|
||||
int iFd = file_descriptor;
|
||||
int len,ret;
|
||||
struct termios opt;
|
||||
tcgetattr(iFd, &opt);
|
||||
cfsetispeed(&opt, B115200);
|
||||
cfsetospeed(&opt, B115200);
|
||||
if (tcgetattr(iFd, &opt)<0) {
|
||||
return -1;
|
||||
}
|
||||
opt.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
|
||||
opt.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
||||
opt.c_oflag &= ~(OPOST);
|
||||
opt.c_cflag &= ~(CSIZE | PARENB | CBAUD);
|
||||
opt.c_cflag |= (CS8 | B115200);
|
||||
opt.c_cc[VMIN] = 255;
|
||||
opt.c_cc[VTIME] = 5;
|
||||
if (tcsetattr(iFd, TCSANOW, &opt)<0) {
|
||||
return -1;
|
||||
}
|
||||
tcflush(iFd,TCIOFLUSH);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set serial attributes
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial device
|
||||
* @param flow_ctrl
|
||||
* @param data_bits how many bits per data, could be 7, 8, 5
|
||||
* @param parity which parity method, could be PARITY_NONE, PARITY_ODD, PARITY_EVEN
|
||||
* @param stop_bits how many stop bits
|
||||
*
|
||||
* @return 1 if success.
|
||||
* return negative error code if fail.
|
||||
*/
|
||||
int serial_set_attr(int file_descriptor, int data_bits, char parity, int stop_bits, int flow_ctrl)
|
||||
{
|
||||
struct termios termio;
|
||||
int fd = file_descriptor;
|
||||
|
||||
if ( fd < 0 ) {
|
||||
return SERIAL_INVALID_FILE;
|
||||
}
|
||||
|
||||
memset(&termio, 0, sizeof(termio));
|
||||
|
||||
if (tcgetattr(fd, &termio)) {
|
||||
return SERIAL_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
//set flow control
|
||||
switch(flow_ctrl) {
|
||||
case FLOW_CONTROL_NONE :
|
||||
termio.c_cflag &= ~CRTSCTS;
|
||||
break;
|
||||
case FLOW_CONTROL_HARDWARE :
|
||||
termio.c_cflag |= CRTSCTS;
|
||||
break;
|
||||
case FLOW_CONTROL_SOFTWARE :
|
||||
termio.c_cflag |= IXON | IXOFF | IXANY;
|
||||
break;
|
||||
}
|
||||
|
||||
//set data bit
|
||||
termio.c_cflag &= ~CSIZE;
|
||||
switch (data_bits) {
|
||||
case 8:
|
||||
termio.c_cflag |= CS8;
|
||||
break;
|
||||
case 7:
|
||||
termio.c_cflag |= CS7;
|
||||
break;
|
||||
case 6:
|
||||
termio.c_cflag |= CS6;
|
||||
break;
|
||||
case 5:
|
||||
termio.c_cflag |= CS5;
|
||||
break;
|
||||
default:
|
||||
termio.c_cflag |= CS8;
|
||||
break;
|
||||
}
|
||||
|
||||
//set stop bits
|
||||
switch (stop_bits) {
|
||||
case 1:
|
||||
termio.c_cflag &= ~CSTOPB;
|
||||
break;
|
||||
case 2:
|
||||
termio.c_cflag |= CSTOPB;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//set parity bit
|
||||
switch (parity) {
|
||||
case PARITY_NONE:
|
||||
termio.c_cflag &= ~(PARENB | PARODD);
|
||||
break;
|
||||
case PARITY_EVEN:
|
||||
termio.c_cflag |= PARENB;
|
||||
termio.c_cflag &= ~PARODD;
|
||||
break;
|
||||
case PARITY_ODD:
|
||||
termio.c_cflag |= PARENB | PARODD;
|
||||
break;
|
||||
case PARITY_MARK:
|
||||
termio.c_cflag |= PARENB | CMSPAR | PARODD;
|
||||
break;
|
||||
case PARITY_SPACE:
|
||||
termio.c_cflag |= PARENB | CMSPAR;
|
||||
termio.c_cflag &= ~PARODD;
|
||||
break;
|
||||
}
|
||||
|
||||
if (tcsetattr(fd, TCSAFLUSH, &termio) < 0) {
|
||||
return SERIAL_ERROR_SETTING;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* open serial port
|
||||
*
|
||||
* @param device_filename device file name, such as "/dev/ttyS0"
|
||||
* @param baund_rate could be 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300
|
||||
*
|
||||
* @return file descriptor which could be used in read() or write()
|
||||
* return -1 if failed, and errno is set
|
||||
*/
|
||||
int serial_open_file(char *device_filename, int baud_rate) {
|
||||
int fd;
|
||||
struct termios termio;
|
||||
|
||||
if ((fd = open(device_filename, O_RDWR | O_NOCTTY )) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&termio, 0, sizeof(termio));
|
||||
|
||||
// setup the tty and the selected baud rate
|
||||
// get current modes
|
||||
if (tcgetattr(fd, &termio)) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// setup initial mode: 8 bit data, No parity, 1 stop bit, no echo, no flow control
|
||||
cfmakeraw(&termio);
|
||||
if (tcsetattr(fd, TCSAFLUSH, &termio) < 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (serial_set_baud_rate(fd, baud_rate) != 1) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* open serial port
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial device
|
||||
* @param timeout timeout in second
|
||||
*
|
||||
* @return 1 if success
|
||||
* return negative error code if fail
|
||||
*/
|
||||
int serial_set_timeout(int file_descriptor, int timeout)
|
||||
{
|
||||
int fd = file_descriptor;
|
||||
struct termios termio;
|
||||
|
||||
if (fd < 0) {
|
||||
return SERIAL_INVALID_FILE;
|
||||
}
|
||||
|
||||
|
||||
// get current attributes
|
||||
if (tcgetattr(fd, &termio)) {
|
||||
return SERIAL_INVALID_RESOURCE;
|
||||
}
|
||||
|
||||
//set read timeout
|
||||
if (timeout > 0) {
|
||||
timeout = timeout / 100;
|
||||
if (timeout == 0)
|
||||
timeout = 1;
|
||||
}
|
||||
termio.c_lflag &= ~ICANON; /* Set non-canonical mode */
|
||||
termio.c_cc[VTIME] = timeout; /* Set timeout in tenth seconds */
|
||||
if (tcsetattr(fd, TCSANOW, &termio) < 0) {
|
||||
return SERIAL_ERROR_SETTING;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* open serial port
|
||||
*
|
||||
* @param port number of port, could be 0, 1 ... , the device file is /dev/ttyS0, /dev/ttyS1 respectively
|
||||
* @param baund_rate could be 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300
|
||||
*
|
||||
* @return file descriptor which could be used in read() or write()
|
||||
* return -1 if failed, and errno is set
|
||||
*/
|
||||
int serial_open(char* port, int baud_rate) {
|
||||
char buf[128];
|
||||
|
||||
snprintf(buf, sizeof(buf), "/dev/ttyS%d", port);
|
||||
return serial_open_file(port, baud_rate);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* close serial port
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
*
|
||||
* @return 0 if success.
|
||||
* return -1 if failed, and errno is set.
|
||||
*/
|
||||
int serial_close(int file_descriptor) {
|
||||
return close(file_descriptor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The function waits until all queued output to the terminal filedes has been transmitted.
|
||||
*
|
||||
* tcdrain() is called.
|
||||
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
*
|
||||
* @return 0 if success.
|
||||
* return -1 if fail, and errno is set.
|
||||
*/
|
||||
int serial_flush(int file_descriptor)
|
||||
{
|
||||
return tcdrain(file_descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* whether data is available
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
* @param timeout_millisec timeout in millisecond
|
||||
*
|
||||
* @return 1 if data is available
|
||||
* return 0 if data is not available
|
||||
*/
|
||||
int serial_data_available(int file_descriptor, unsigned int timeout_millisec)
|
||||
{
|
||||
int fd = file_descriptor;
|
||||
struct timeval timeout;
|
||||
fd_set readfds;
|
||||
|
||||
if (fd < 0) {
|
||||
return SERIAL_INVALID_FILE;
|
||||
}
|
||||
|
||||
if (timeout_millisec == 0) {
|
||||
// no waiting
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
} else {
|
||||
timeout.tv_sec = timeout_millisec / 1000;
|
||||
timeout.tv_usec = (timeout_millisec % 1000) * 1000;
|
||||
}
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(fd, &readfds);
|
||||
|
||||
if (select(fd + 1, &readfds, NULL, NULL, &timeout) > 0) {
|
||||
return 1; // data is ready
|
||||
} else {
|
||||
return 0; // no data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* send data
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
* @param buffer buffer of data to send
|
||||
* @param data_len data length
|
||||
*
|
||||
* @return positive integer of bytes sent if success.
|
||||
* return -1 if failed.
|
||||
*/
|
||||
int serial_send(int file_descriptor, char *buffer, size_t data_len)
|
||||
{
|
||||
ssize_t len = 0;
|
||||
len = write(file_descriptor, buffer, data_len);
|
||||
if ( len == data_len ) {
|
||||
return len;
|
||||
} else {
|
||||
tcflush(file_descriptor, TCOFLUSH);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* receive data
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
* @param buffer buffer to receive data
|
||||
* @param data_len max data length
|
||||
*
|
||||
* @return positive integer of bytes received if success.
|
||||
* return -1 if failed.
|
||||
*/
|
||||
int serial_receive(int file_descriptor, char *buffer,size_t data_len)
|
||||
{
|
||||
int len,fs_sel;
|
||||
fd_set fs_read;
|
||||
struct timeval time;
|
||||
int fd = file_descriptor;
|
||||
|
||||
FD_ZERO(&fs_read);
|
||||
FD_SET(fd, &fs_read);
|
||||
|
||||
time.tv_sec = 10;
|
||||
time.tv_usec = 0;
|
||||
|
||||
//use select() to achieve multiple channel communication
|
||||
fs_sel = select(fd + 1, &fs_read, NULL, NULL, &time);
|
||||
if ( fs_sel ) {
|
||||
len = read(fd, buffer, data_len);
|
||||
return len;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
193
serial/serial.h
Normal file
193
serial/serial.h
Normal file
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* A library for Linux serial communication
|
||||
*
|
||||
* Author: JoStudio, 2016
|
||||
*
|
||||
* Version: 0.5
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __SERIAL_H__
|
||||
#define __SERIAL_H__
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* serial error code */
|
||||
#define SERIAL_ERROR_OPEN -1
|
||||
#define SERIAL_ERROR_READ -2
|
||||
#define SERIAL_ERROR_WRITE -3
|
||||
#define SERIAL_ERROR_BAUDRATE -4
|
||||
#define SERIAL_ERROR_SETTING -5
|
||||
#define SERIAL_INVALID_RESOURCE -6
|
||||
#define SERIAL_INVALID_FILE -7
|
||||
|
||||
|
||||
/* flow control */
|
||||
#define FLOW_CONTROL_NONE 0
|
||||
#define FLOW_CONTROL_HARDWARE 1
|
||||
#define FLOW_CONTROL_SOFTWARE 2
|
||||
|
||||
/* parity */
|
||||
#define PARITY_NONE 'N'
|
||||
#define PARITY_EVEN 'E'
|
||||
#define PARITY_ODD 'O'
|
||||
#define PARITY_SPACE 'S'
|
||||
#define PARITY_MARK 'M'
|
||||
|
||||
|
||||
/**
|
||||
* open serial port
|
||||
*
|
||||
* @param port number of port, could be 0, 1 ... , the device file is /etc/ttyS0, /etc/ttyS1 respectively
|
||||
* @param baund_rate could be 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300
|
||||
*
|
||||
* @return file descriptor which could be used in read() or write()
|
||||
* return -1 if failed, and errno is set
|
||||
*/
|
||||
int serial_open(char* port, int baud_rate);
|
||||
|
||||
|
||||
/**
|
||||
* close serial port
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
*
|
||||
* @return 0 if success.
|
||||
* return -1 if failed, and errno is set.
|
||||
*/
|
||||
int serial_close(int file_descriptor);
|
||||
|
||||
/**
|
||||
* open serial port
|
||||
*
|
||||
* @param device_filename device file name, such as "/etc/ttyS0"
|
||||
* @param baund_rate could be 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300
|
||||
*
|
||||
* @return file descriptor which could be used in read() or write()
|
||||
* return -1 if failed, and errno is set
|
||||
*/
|
||||
int serial_open_file(char *device_filename, int baud_rate);
|
||||
|
||||
|
||||
/**
|
||||
* set serial attributes
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial device
|
||||
* @param flow_ctrl
|
||||
* @param data_bits how many bits per data, could be 7, 8, 5
|
||||
* @param parity which parity method, could be PARITY_NONE, PARITY_ODD, PARITY_EVEN
|
||||
* @param stop_bits how many stop bits
|
||||
*
|
||||
* @return 1 if success.
|
||||
* return negative error code if fail.
|
||||
*/
|
||||
int serial_set_attr(int file_descriptor, int data_bits, char parity, int stop_bits, int flow_ctrl);
|
||||
|
||||
|
||||
/**
|
||||
* open serial port
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial device
|
||||
* @param timeout timeout in second
|
||||
*
|
||||
* @return 1 if success
|
||||
* return negative error code if fail
|
||||
*/
|
||||
int serial_set_timeout(int file_descriptor, int timeout);
|
||||
|
||||
|
||||
/**
|
||||
* set baud rate of serial port
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial device
|
||||
* @param baud_rate baud rate
|
||||
*
|
||||
* @return 1 if success
|
||||
* return negative error code if fail
|
||||
*/
|
||||
int serial_set_baud_rate(int file_descriptor, int baud_rate) ;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The function waits until all queued output to the terminal filedes has been transmitted.
|
||||
*
|
||||
* tcdrain() is called.
|
||||
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
*
|
||||
* @return 0 if success.
|
||||
* return -1 if fail, and errno is set.
|
||||
*/
|
||||
int serial_flush(int file_descriptor);
|
||||
|
||||
/**
|
||||
* whether data is available
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
* @param timeout_millisec timeout in millisecond
|
||||
*
|
||||
* @return 1 if data is available
|
||||
* return 0 if data is not available
|
||||
*/
|
||||
int serial_data_available(int file_descriptor, unsigned int timeout_millisec);
|
||||
|
||||
|
||||
/**
|
||||
* send data
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
* @param buffer buffer of data to send
|
||||
* @param data_len data length
|
||||
*
|
||||
* @return positive integer of bytes sent if success.
|
||||
* return -1 if failed.
|
||||
*/
|
||||
int serial_send(int file_descriptor, char *buffer, size_t data_len);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* receive data
|
||||
*
|
||||
* @param file_descriptor file descriptor of serial port device file
|
||||
* @param buffer buffer to receive data
|
||||
* @param data_len max data length
|
||||
*
|
||||
* @return positive integer of bytes received if success.
|
||||
* return -1 if failed.
|
||||
*/
|
||||
int serial_receive(int file_descriptor, char *buffer,size_t data_len);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __SERIAL_H__ */
|
@ -53,7 +53,7 @@ void TcpCgi::startCgiServer()
|
||||
|
||||
std::string recvData = std::string(buff);
|
||||
std::string reqData = cidwServer->HandleCgi_cmd(recvData);
|
||||
print_info("send cgi : %s\n", reqData.c_str());
|
||||
//print_info("send cgi : %s\n length = %d\n", reqData.c_str(),reqData.length());
|
||||
if( send(connfd, reqData.c_str(), reqData.length(), 0) < 0){
|
||||
printf("send msg error: %s(errno: %d)\n", strerror(errno), errno);
|
||||
}
|
||||
|
@ -9,6 +9,10 @@
|
||||
#include "SH_ThreadFunc.hpp"
|
||||
#include "../API_log/SH_log.h"
|
||||
#include "../uart/SH_Uart.hpp"
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
#include "../dial5G/Dial.h"
|
||||
#include "../wifi/wpa_client.h"
|
||||
#include <dirent.h>
|
||||
|
||||
namespace{
|
||||
Uart *pUart = Uart::instance();
|
||||
@ -20,6 +24,8 @@ static std::string uptime;
|
||||
static long long connect_lost_time = 0; //ms
|
||||
static long long connect_time = 0; //ms
|
||||
|
||||
Dial dial;
|
||||
|
||||
void CheckThread()
|
||||
{
|
||||
print_info("ENTER CHECK THREAD \n");
|
||||
@ -31,27 +37,123 @@ void CheckThread()
|
||||
int reset_flag = 0;
|
||||
int online_check = 0;
|
||||
int HardStatus = 0;
|
||||
int logClean = 0;
|
||||
int Battery = 0;
|
||||
int UpdateZigbee = 0;
|
||||
int commSignal = 0;
|
||||
int loose_check = 0;
|
||||
int mqttresend = 0;
|
||||
int rebootsystem = 0;
|
||||
int ModifyAddr = 0;
|
||||
int wifi_reconnect_count = 0;
|
||||
int checkNet0 = 0;
|
||||
int connectCount = 0;
|
||||
|
||||
while (GlobalConfig::QuitFlag_G) {
|
||||
if (10 == heart_count) {
|
||||
// StatusPub();
|
||||
if (GlobalConfig::LinkCount > 30) {
|
||||
exit(0);
|
||||
//exit(0);
|
||||
}
|
||||
std::string ipTemp = IpAddrInit();
|
||||
GlobalConfig::IpAddr_G = ipTemp;
|
||||
if ( 0 != ipTemp.compare(GlobalConfig::IpAddr_G)) {
|
||||
exit(0);
|
||||
//exit(0);
|
||||
}
|
||||
heart_count = 0;
|
||||
}
|
||||
|
||||
if (600 == time_check) {
|
||||
#ifdef G2UL_GATEWAY
|
||||
if(checkNet0 == 5){
|
||||
checkNet0 = 0;
|
||||
int iStatus = get_netlink_status("eth0");
|
||||
if(iStatus == 1 && GlobalConfig::net0Status == 0){
|
||||
system("ifconfig eth0:1 192.168.188.188 netmask 255.255.255.0");
|
||||
}
|
||||
GlobalConfig::net0Status = iStatus;
|
||||
}
|
||||
#endif
|
||||
if (300 == 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;
|
||||
int iRet = data_publish(str.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
if(iRet != 0 )
|
||||
{
|
||||
LOG_ERROR("MQTT connect failed\n");
|
||||
//bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
|
||||
#ifdef NR5G_MODULE
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
dial.closePort();
|
||||
gpio_set(GlobalConfig::GPIO_G.commRest,0);
|
||||
LOG_DEBUG("GPIO 8 start\n");
|
||||
sleep(2);
|
||||
gpio_set(GlobalConfig::GPIO_G.commRest,1);
|
||||
LOG_DEBUG("GPIO 8 End\n");
|
||||
sleep(20);
|
||||
dial.openPort("/dev/ttyUSB2");
|
||||
dial.setState();
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
dial.closePort();
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower,0);
|
||||
LOG_DEBUG("commPower start\n");
|
||||
sleep(2);
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower,1);
|
||||
LOG_DEBUG("commPower End\n");
|
||||
sleep(20);
|
||||
connectCount ++;
|
||||
if(connectCount > 10){
|
||||
LOG_ERROR("5G reset error ,reboot!\n");
|
||||
system("reboot");
|
||||
}
|
||||
#ifndef NR5G_MEIGE
|
||||
dial.openPort("/dev/ttyUSB2");
|
||||
dial.setState();
|
||||
#else
|
||||
char szquectel[100]={0x00};
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
sprintf(szquectel,"/opt/quectel-CM/Meig-CM -s %s &",strAPN.c_str());
|
||||
system(szquectel);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef WIFI_MODULE
|
||||
LOG_ERROR("WiFi reset!\n");
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
gpio_set(GlobalConfig::GPIO_G.wifiReset,0);
|
||||
sleep(5);
|
||||
gpio_set(GlobalConfig::GPIO_G.wifiReset,1);
|
||||
sleep(5);
|
||||
wifi::WPAClient wpa;
|
||||
wpa.ReconnectWiFi();
|
||||
system("/etc/init.d/wpa_restart");
|
||||
system("udhcpc -i wlan2 &");
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
system("/etc/init.d/wpa_restart");
|
||||
sleep(5);
|
||||
string strip = GetGwIp_("wlan0");
|
||||
print_info("strip = %s\n",strip.c_str());
|
||||
if (strip.compare("0.0.0.0") != 0) {
|
||||
|
||||
}else{
|
||||
gpio_set(GlobalConfig::GPIO_G.wifiReset,1);
|
||||
sleep(5);
|
||||
gpio_set(GlobalConfig::GPIO_G.wifiReset,0);
|
||||
sleep(30);
|
||||
wifi::WPAClient wpa;
|
||||
wpa.ReconnectWiFi();
|
||||
system("/etc/init.d/wpa_restart");
|
||||
sleep(5);
|
||||
system("udhcpc -b -i wlan0 &");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}else{
|
||||
connectCount = 0;
|
||||
}
|
||||
}
|
||||
if(HardStatus == 3600){//one hour 3600
|
||||
JsonData jd;
|
||||
@ -59,26 +161,227 @@ void CheckThread()
|
||||
data_publish(data.c_str(), GlobalConfig::Topic_G.mPubStatus.c_str());
|
||||
HardStatus = 0;
|
||||
}
|
||||
if(mqttresend == 1800){
|
||||
mqttresend = 0;
|
||||
#ifdef WIFI_MODULE
|
||||
bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
|
||||
if(status != 0){
|
||||
LOG_INFO("===========net status ========failed \n");
|
||||
LOG_ERROR("openSwitch\n");
|
||||
sleep(20);
|
||||
gpio_set(GlobalConfig::GPIO_G.power,1);
|
||||
}
|
||||
#endif
|
||||
LOG_INFO("mqttresend check\n");
|
||||
Json::Value jsHeart;
|
||||
Json::FastWriter fw;
|
||||
jsHeart["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsHeart["status"] = "online_V" + GlobalConfig::Version;
|
||||
jsHeart["IP"] = GlobalConfig::IpAddr_G;
|
||||
std::string strJson = fw.write(jsHeart);
|
||||
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||||
if(iRet == 0){
|
||||
sql_ctl->QueryofflineData();
|
||||
}
|
||||
|
||||
if (onlineCheck == online_check) {
|
||||
}
|
||||
|
||||
if (600 == online_check) {
|
||||
online_check = 0;
|
||||
int Count = sql_ctl->GetTableRows(T_SENSOR_INFO(TNAME), NULL);
|
||||
if(Count > 0){
|
||||
JsonData jd;
|
||||
jd.DataNodeStatusCheck();
|
||||
LOG_INFO("online_check = %d",online_check);
|
||||
Param_29 param;
|
||||
std::string cmd29 = jd.JsonCmd_29(param);
|
||||
data_publish(cmd29.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
online_check = 0;
|
||||
int iRet = data_publish(cmd29.c_str(), GlobalConfig::Topic_G.mPubCmd.c_str());
|
||||
char localtimestamp[32] = { 0 };
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
std::string nowTimetamp = std::string(localtimestamp);
|
||||
char selectCon[128] = { 0 };
|
||||
sprintf(selectCon, " sendMsg <> '' ORDER BY timeStamp DESC LIMIT 0,1");
|
||||
sleep(1);
|
||||
std::string strTime = sql_ctl->GetData(T_DATASTATIC_INFO(TNAME), "timeStamp", selectCon);
|
||||
long lTime = atol(nowTimetamp.c_str())-atol(strTime.c_str());
|
||||
LOG_INFO("online check = %d\n",lTime);
|
||||
if(lTime > 1800){
|
||||
LOG_ERROR("nowTimetamp = %s,lastTime = %s,lTime = %d\n",nowTimetamp.c_str(),strTime.c_str(),lTime);
|
||||
}
|
||||
}
|
||||
}if(21000 == Battery){
|
||||
Battery = 0;
|
||||
sql_ctl->CalculateBattery();
|
||||
}
|
||||
// if(10800 == UpdateZigbee){
|
||||
// UpdateZigbee = 0;
|
||||
// pUart->UpdateZigbeeInfoCtrl();
|
||||
// }
|
||||
if(21000 == loose_check){
|
||||
loose_check = 0;
|
||||
sql_ctl->CalculateDip();
|
||||
}
|
||||
if(ModifyAddr == 21000 && pUart->bModifyAddr){
|
||||
//#ifdef IMX6UL_GATEWAY
|
||||
LOG_ERROR("ModifyAddr failed \n");
|
||||
exit(0);
|
||||
//#endif
|
||||
}
|
||||
if(ModifyAddr == 21000){
|
||||
ModifyAddr = 0;
|
||||
}
|
||||
|
||||
if(18000 == commSignal){ //5h
|
||||
Json::Value jsBody,jsonVal;
|
||||
Json::FastWriter showValue;
|
||||
if(GlobalConfig::NetStatus == "\"NOCONN\"" || GlobalConfig::NetStatus == "\"CONNECT\""){
|
||||
if(GlobalConfig::NetSignal == 0){
|
||||
jsBody["communicationSignal"] = "未知";
|
||||
}
|
||||
else if(GlobalConfig::NetSignal > -80){
|
||||
jsBody["commSignal"] = "优";
|
||||
}else if(GlobalConfig::NetSignal > -90 && GlobalConfig::NetSignal < -80){
|
||||
jsBody["commSignal"] = "良";
|
||||
}else if(GlobalConfig::NetSignal > -105 && GlobalConfig::NetSignal < -90){
|
||||
jsBody["commSignal"] = "一般";
|
||||
}else if(GlobalConfig::NetSignal < -105){
|
||||
jsBody["commSignal"] = "弱";
|
||||
}else if(GlobalConfig::NetSignal < -115){
|
||||
jsBody["commSignal"] = "不稳定";
|
||||
}
|
||||
|
||||
}else if(GlobalConfig::NetStatus == "\"SEARCH\""){
|
||||
jsBody["commSignal"] = "搜索网络";
|
||||
}else if(GlobalConfig::NetStatus == "\"LIMSRV\""){
|
||||
jsBody["commSignal"] = "未插卡";
|
||||
}else{
|
||||
jsBody["commSignal"] = "未知";
|
||||
}
|
||||
|
||||
jsonVal["cmd"] = "53";
|
||||
std::string dataBody = showValue.write(jsBody);
|
||||
jsonVal["cmdBody"] = dataBody;
|
||||
data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||
}
|
||||
if(21000 == logClean){
|
||||
logClean = 0;
|
||||
DIR *dp; //创建一个指向root路径下每个文件的指针
|
||||
struct dirent *dirp;
|
||||
string root="/opt/log/";
|
||||
if((dp = opendir(root.c_str()))==NULL)
|
||||
cout << "can't open"<< root << endl;
|
||||
while((dirp = readdir(dp)) != NULL){
|
||||
|
||||
if((!strcmp(dirp->d_name,".")||(!strcmp(dirp->d_name,".."))))
|
||||
continue;
|
||||
struct timeval curTime;
|
||||
gettimeofday(&curTime, NULL);
|
||||
char buffer[80] = {0};
|
||||
char fileMonth[11] = {0};
|
||||
char todayMonth[11]={0};
|
||||
char fileDay[11] = {0};
|
||||
char todayDay[11]={0};
|
||||
struct tm nowTime;
|
||||
localtime_r(&curTime.tv_sec, &nowTime);//把得到的值存入临时分配的内存中,线程安全
|
||||
strftime(buffer, sizeof(buffer), "%Y-%m-%d", &nowTime);
|
||||
memcpy(fileDay,dirp->d_name+8,2);
|
||||
memcpy(todayDay,buffer+8,2);
|
||||
memcpy(fileMonth,dirp->d_name+5,2);
|
||||
memcpy(todayMonth,buffer+5,2);
|
||||
string filename = root+ string(dirp->d_name);
|
||||
if(atoi(fileMonth) == atoi(todayMonth) ? abs(atoi(todayDay) - atoi(fileDay)) > 15: abs(abs(30-(atoi(fileDay)) + atoi(todayDay))) > 15){
|
||||
LOG_INFO("filename = %s\n",filename.c_str());
|
||||
remove(filename.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*staticData = 0;
|
||||
Json::Value jsHeart;
|
||||
Json::FastWriter fw;
|
||||
jsHeart["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsHeart["status"] = "online";
|
||||
std::string strJson = fw.write(jsHeart);
|
||||
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||||
if(iRet == 0){
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_52();
|
||||
}
|
||||
double freeDisk = GetHardDiskFree();
|
||||
if(freeDisk < 90){
|
||||
char whereCon[512] = {0x00};
|
||||
time_t timestamp;
|
||||
long timeStamp = time(×tamp) ;//秒级时间戳
|
||||
memset(whereCon,0x00,sizeof(whereCon));
|
||||
sprintf(whereCon,"sendMsg = '0' and timeStamp < '%s'",timeStamp-1); //1 week
|
||||
sql_ctl->DeleteTableData(T_DATA_INFO(TNAME),whereCon,0);
|
||||
sql_ctl->DeleteTableData(T_DATASTATIC_INFO(TNAME),whereCon,0);
|
||||
}*/
|
||||
|
||||
}
|
||||
#ifdef WIFI_MODULE
|
||||
if (wifi_reconnect_count == 600) { // 每 10分钟,重连WiFi网络
|
||||
wifi_reconnect_count = 0;
|
||||
wifi::WPAClient wpa;
|
||||
std::string netssid = wpa.GetNetSsid();
|
||||
std::string currentssid = "";
|
||||
if (0 == netssid.compare("")) {
|
||||
netssid = wpa.GetNetSsid();
|
||||
}
|
||||
|
||||
if (netssid.length() > 0) {
|
||||
currentssid = wpa.GetCurrentSSID();
|
||||
if (currentssid.length() > 0) {
|
||||
char buf[64] = {0};
|
||||
std::string rssiSend = "";
|
||||
#ifdef G2UL_GATEWAY
|
||||
rssiSend = "/usr/sbin/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='";
|
||||
#endif
|
||||
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
rssiSend = "/opt/Cidn/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='";
|
||||
#endif
|
||||
system_custom(rssiSend.c_str(), buf);
|
||||
std::string Rssi = std::string(buf);
|
||||
|
||||
memset(buf, 0, 64);
|
||||
sprintf(buf, "wifi:true Rssi:%s", Rssi.c_str());
|
||||
print_info("%s\n", buf);
|
||||
LOG_INFO("%s\n",buf);
|
||||
|
||||
} else {
|
||||
std::string runinfo = "wifi:false\n";
|
||||
print_info("%s\n", runinfo.c_str());
|
||||
}
|
||||
}
|
||||
if (wpa.ReconnectWiFi()) {
|
||||
print_info("wifi reconnect ok\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( reset_flag > 7200) {
|
||||
reset_flag = 0;
|
||||
//exit(0);
|
||||
}
|
||||
Battery ++;
|
||||
reset_flag++;
|
||||
time_check++;
|
||||
heart_count++;
|
||||
online_check++;
|
||||
HardStatus ++;
|
||||
//UpdateZigbee ++;
|
||||
logClean ++ ;
|
||||
loose_check ++;
|
||||
ModifyAddr ++;
|
||||
mqttresend ++;
|
||||
#ifdef G2UL_GATEWAY
|
||||
checkNet0 ++;
|
||||
#endif
|
||||
#ifdef WIFI_MODULE
|
||||
wifi_reconnect_count ++;
|
||||
#endif
|
||||
|
||||
//rebootsystem ++;
|
||||
if(GlobalConfig::EnterZigBeeWaveTransmittingFlag_G == ENTER_TRANSMITTING_STATUS) {
|
||||
GlobalConfig::EnterZigBeeWaveTransmittingCnt_G ++;
|
||||
if(GlobalConfig::EnterZigBeeWaveTransmittingCnt_G >= 180) {
|
||||
@ -87,13 +390,17 @@ void CheckThread()
|
||||
LOG_ERROR("[---- ZigBee error--!] ZigBee PanID is 9999 over time for 3 minutes !\n");
|
||||
// 重新写入 0x8888
|
||||
unsigned short shortAddr = 0x8888;
|
||||
pUart->WriteShortAddr2Zigbee(shortAddr);
|
||||
pUart->modify_LocalAddr(0x8888);
|
||||
GlobalConfig::Zigbee_G.MyAddr = 0x8888;
|
||||
// pUart->WriteShortAddr2Zigbee(shortAddr);
|
||||
// 延时1秒
|
||||
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
||||
sleep(1);
|
||||
// 重新读回 GlobalConfig::ZigbeeInfo_G.PanID
|
||||
pUart->UpdateZigbeeInfoCtrl();
|
||||
pUart->bUpdateconfig = false;
|
||||
pUart->bUpdate = false;
|
||||
// 延时1秒
|
||||
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
||||
sleep(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");
|
||||
@ -103,8 +410,7 @@ void CheckThread()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
sleep(1);;
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,40 +420,277 @@ void StartCgiServer()
|
||||
TcpCgi *tcpCgi = TcpCgi::instance();
|
||||
while (1) {
|
||||
tcpCgi->startCgiServer();
|
||||
boost::this_thread::sleep(boost::posix_time::seconds(10));
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
void RunLED()
|
||||
{
|
||||
while(1){
|
||||
gpio_set(GlobalConfig::GPIO_G.runLed,1);
|
||||
sleep(1);
|
||||
gpio_set(GlobalConfig::GPIO_G.runLed,0);
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HeartRep()
|
||||
{
|
||||
int count = 0;
|
||||
while(1) {
|
||||
Json::Value jsHeart;
|
||||
Json::FastWriter fw;
|
||||
jsHeart["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G;
|
||||
jsHeart["status"] = "online";
|
||||
jsHeart["status"] = "online_V" + GlobalConfig::Version;
|
||||
jsHeart["IP"] = GlobalConfig::IpAddr_G;
|
||||
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));
|
||||
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
|
||||
print_info("heart = %s,iRet = %d\n",strJson.c_str(),iRet);
|
||||
if(iRet != 0){
|
||||
count ++;
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,1);
|
||||
sleep(1);
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
sleep(1);
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,1);
|
||||
sleep(1);
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
sleep(1);
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,1);
|
||||
sleep(1);
|
||||
GlobalConfig::serverStatus = 1;
|
||||
}else{
|
||||
GlobalConfig::serverStatus = 0;
|
||||
count = 0;
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
}
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
// if(count > 0){
|
||||
// bool status = Ping( GlobalConfig::ServerIP.c_str(), 10000);
|
||||
// if(status != 0)
|
||||
// //LOG_INFO("===========net status ========failed heart count %d\n",count);
|
||||
// if(status != 0 && count > 30){
|
||||
// LOG_ERROR("heart send failed,heart count %d\n",count);
|
||||
// count = 0;
|
||||
// sleep(20);
|
||||
// gpio_set(GlobalConfig::GPIO_G.power,1);
|
||||
// }
|
||||
// }
|
||||
// if(count > 1000){
|
||||
// gpio_set(GlobalConfig::GPIO_G.power,1);
|
||||
// count = 0;
|
||||
// }
|
||||
// write_data(fd,"AT+QENG=\"servingcell\"\r\n",27);
|
||||
// //sleep(1);
|
||||
// char buff[1024]={0x00};
|
||||
// int ret = read_data(fd, buff, 1024, 10);
|
||||
// print_info("ret = %d,buff = %s\n",ret,buff);
|
||||
// const char *str2 = "+QENG: ";
|
||||
// char csq[128] = {0};
|
||||
// char *pdata = strstr((char*)buff, str2);
|
||||
// if(pdata){
|
||||
// strncpy(csq, pdata+7, sizeof(csq));
|
||||
// }
|
||||
// else {
|
||||
// }
|
||||
//
|
||||
// //printf("SIM-CSQ: %s\n", csq);
|
||||
// GlobalConfig::NetStatus = GetOneContent(csq,1,",");
|
||||
// string signal = GetOneContent(csq,13,",");
|
||||
// GlobalConfig::NetSignal = atoi(signal.c_str());
|
||||
// print_info("NetStatus = %s,NetSignal = %d\n",GlobalConfig::NetStatus.c_str(),GlobalConfig::NetSignal);
|
||||
|
||||
//GlobalConfig::NetSignal = getcsq();
|
||||
/*if(GlobalConfig::NetSignal <= -105 ){
|
||||
gpio_set(130,1);
|
||||
}else if(GlobalConfig::NetSignal > -105 ){
|
||||
gpio_set(130,0);
|
||||
}else{
|
||||
gpio_set(130,1);
|
||||
}*/
|
||||
sleep(10);
|
||||
//socketHeart(strJson.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void GetCSQ()
|
||||
{
|
||||
#ifdef NR5G_MODULE
|
||||
//5G
|
||||
int iRet = -1;
|
||||
open5G:
|
||||
iRet = dial.openPort("/dev/ttyUSB2");
|
||||
if (iRet < 0){
|
||||
sleep(5);
|
||||
goto open5G;
|
||||
}
|
||||
#ifdef NR5G_MEIGE
|
||||
dial.closePort();
|
||||
char szquectel[100]={0x00};
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
sprintf(szquectel,"/opt/quectel-CM/Meig-CM -s %s &",strAPN.c_str());
|
||||
system(szquectel);
|
||||
#else
|
||||
dial.recvData();
|
||||
#endif
|
||||
#endif
|
||||
#ifdef Q4G_MODULE
|
||||
//4G
|
||||
int fd = -1;
|
||||
open4G:
|
||||
fd = config_uart("/dev/ttyUSB2",115200);
|
||||
if (fd < 0){
|
||||
sleep(5);
|
||||
goto open4G;
|
||||
}
|
||||
char szbuffer[200]={0x00};
|
||||
int offSize = 0;
|
||||
int timeoutflag = 0;
|
||||
write_data(fd,"AT+QENG=\"servingcell\"\r\n",27);
|
||||
while(1){
|
||||
char buff[1024]={0x00};
|
||||
int ret = read_data(fd, buff, 1024, 10);
|
||||
if(ret <= 0){
|
||||
timeoutflag ++;
|
||||
if(timeoutflag > 5){
|
||||
print_info("timeoutflag = %d\n",timeoutflag);
|
||||
timeoutflag = 0;
|
||||
const char *str2 = "+QENG: ";
|
||||
char csq[128] = {0};
|
||||
char *pdata = strstr((char*)szbuffer, str2);
|
||||
if(pdata){
|
||||
strncpy(csq, pdata+7, sizeof(csq));
|
||||
|
||||
//printf("SIM-CSQ: %s\n", csq);
|
||||
GlobalConfig::NetStatus = GetOneContent(csq,1,",");
|
||||
string signal = GetOneContent(csq,13,",");
|
||||
GlobalConfig::NetSignal = atoi(signal.c_str());
|
||||
GlobalConfig::NetType = GetOneContent(csq,2,",");
|
||||
print_info("NetStatus = %s,NetSignal = %d\n",GlobalConfig::NetStatus.c_str(),GlobalConfig::NetSignal);
|
||||
|
||||
}
|
||||
memset(szbuffer,0x00,sizeof(szbuffer));
|
||||
offSize = 0;
|
||||
write_data(fd,"AT+QENG=\"servingcell\"\r\n",27);
|
||||
}
|
||||
usleep(10000);
|
||||
}else if(ret > 0){
|
||||
print_info("ret = %d,buff = %s\n",ret,buff);
|
||||
memcpy(szbuffer + offSize,buff,ret);
|
||||
offSize = offSize + ret;
|
||||
print_info("szbuffer = %s\n",szbuffer);
|
||||
continue;
|
||||
}
|
||||
sleep(10);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void Dial5G()
|
||||
{
|
||||
sleep(2);
|
||||
dial5G:
|
||||
if(dial.m_fd > 0){
|
||||
dial.dial5G();
|
||||
}else{
|
||||
sleep(5);
|
||||
goto dial5G;
|
||||
}
|
||||
}
|
||||
void UartStart()
|
||||
{
|
||||
// onReceiveUart cb = (onReceiveUart)&ProtoConvert::HandleFromUart;
|
||||
// pUart->setCallBack(cb);
|
||||
pUart->InitUart();
|
||||
InitGpio(GlobalConfig::GPIO_G.zigAckrep,0);//ACK
|
||||
InitGpio(GlobalConfig::GPIO_G.zigAckreset,1);//ACK reset
|
||||
InitGpio(GlobalConfig::GPIO_G.zigReset,1);//Zigbee reset
|
||||
gpio_set(GlobalConfig::GPIO_G.zigAckreset,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.zigReset,1);
|
||||
|
||||
while (GlobalConfig::QuitFlag_G) {
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
InitGpio(GlobalConfig::GPIO_G.errorLed,1);//指示灯
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
InitGpio(GlobalConfig::GPIO_G.power,1);//power reset
|
||||
gpio_set(GlobalConfig::GPIO_G.power,0);
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
InitGpio(GlobalConfig::GPIO_G.runLed,1);
|
||||
InitGpio(GlobalConfig::GPIO_G.errorLed,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.runLed,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.errorLed,0);
|
||||
InitGpio(GlobalConfig::GPIO_G.netResetNet0,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.netResetNet0,0);
|
||||
#endif
|
||||
GlobalConfig::Zigbee_G.Serial_Rate = 0x07;
|
||||
GlobalConfig::Zigbee_G.Serial_DataB = 0x08;
|
||||
GlobalConfig::Zigbee_G.Serial_StopB = 0x01;
|
||||
pUart->InitUart(B115200);
|
||||
char buffer[1100]={0x00};
|
||||
|
||||
sleep(1);
|
||||
pUart->UartRecv(pUart->fd,1,buffer);
|
||||
sleep(1);
|
||||
|
||||
pUart->UpdateZigbeeInfoCtrl();
|
||||
pUart->ReadFromUart();
|
||||
pUart->Run();
|
||||
// pUart->Stop();
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
||||
}
|
||||
}
|
||||
void InitModule()
|
||||
{
|
||||
#ifdef NR5G_MODULE
|
||||
#ifdef G2UL_GATEWAY
|
||||
|
||||
InitGpio(GlobalConfig::GPIO_G.commPower,1);//4G,5G模组供电,
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower,1);
|
||||
InitGpio(GlobalConfig::GPIO_G.vol3_8,1);//5G 高电平3.8V,低电平3.3V
|
||||
gpio_set(GlobalConfig::GPIO_G.vol3_8,1);
|
||||
|
||||
InitGpio(GlobalConfig::GPIO_G.commRest,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.commRest,0);//高电平复位
|
||||
#endif
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
InitGpio(GlobalConfig::GPIO_G.commRest,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.commRest,1);//
|
||||
#endif
|
||||
#endif
|
||||
#ifdef Q4G_MODULE
|
||||
#ifdef G2UL_GATEWAY
|
||||
InitGpio(GlobalConfig::GPIO_G.commPower,1);//4G,5G模组供电,
|
||||
gpio_set(GlobalConfig::GPIO_G.commPower,1);
|
||||
InitGpio(GlobalConfig::GPIO_G.commRest,1);
|
||||
gpio_set(GlobalConfig::GPIO_G.commRest,0);//高电平复位
|
||||
sleep(10);
|
||||
char szquectel[100]={0x00};
|
||||
std::string strAPN = ReadStrByOpt(SERVERCONFIG, "Server", "APN");
|
||||
sprintf(szquectel,"/opt/quectel-CM/quectel-CM -s %s &",strAPN.c_str());
|
||||
system(szquectel);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef WIFI_MODULE
|
||||
print_info("Init WiFi!\n");
|
||||
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
InitGpio(GlobalConfig::GPIO_G.wifiReset,1);//WiFi模组复位,0复位,1取消复位
|
||||
gpio_set(GlobalConfig::GPIO_G.wifiReset,1);
|
||||
sleep(10);
|
||||
wifi::WPAClient wpa;
|
||||
wpa.ReconnectWiFi();
|
||||
system("/etc/init.d/wpa_restart");
|
||||
system("udhcpc -i wlan2 &");
|
||||
#endif
|
||||
#ifdef G2UL_GATEWAY
|
||||
InitGpio(GlobalConfig::GPIO_G.wifiReset,1);//WiFi模组复位,1复位,0取消复位
|
||||
gpio_set(GlobalConfig::GPIO_G.wifiReset,0);
|
||||
InitGpio(GlobalConfig::GPIO_G.wifiPower,1);//WiFi模组上电
|
||||
gpio_set(GlobalConfig::GPIO_G.wifiPower,1);
|
||||
sleep(10);
|
||||
wifi::WPAClient wpa;
|
||||
wpa.ReconnectWiFi();
|
||||
system("/usr/sbin/wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf &");
|
||||
system("udhcpc -b -i wlan0 &");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
void TestUart()
|
||||
{
|
||||
pUart->InitTestUart(B115200);
|
||||
pUart->ReadTestUart();
|
||||
}
|
||||
void UartStartWave()
|
||||
{
|
||||
pUart->DealWaveThread();
|
||||
@ -158,7 +701,15 @@ void StartUdpSys()
|
||||
UdpSys *udpsys = UdpSys::instance();
|
||||
udpsys->StartConnectSysUdp();
|
||||
}
|
||||
|
||||
void WatchDog()
|
||||
{
|
||||
int fd = OpenWatchDog();
|
||||
while(1){
|
||||
WriteWatchDog(fd);
|
||||
sleep(50);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
static const char* LOCAL_WILL_TOPIC = "up/uart/will";
|
||||
void my_publish_callback(struct mosquitto *mosq, void *obj, int mid)
|
||||
{
|
||||
@ -185,7 +736,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result)
|
||||
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秒,判定为连接断开
|
||||
if (difftime_ms > 20*1000) { // 超过20秒,判定为连接断开
|
||||
char reply_string[256] = {0};
|
||||
std::string startStatus = "0";
|
||||
if (access(SYSTEMSTART, 0) >= 0) {
|
||||
@ -199,20 +750,17 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result)
|
||||
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");
|
||||
|
||||
@ -250,8 +798,8 @@ 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");
|
||||
//LOG_ERROR("The MQTT connection lost:%d\n", ret);
|
||||
print_debug("The MQTT connection lost\n");
|
||||
char gwTime[32] = { 0 };
|
||||
GetTimeNet(gwTime, 0);
|
||||
uptime = std::string(gwTime);
|
||||
@ -259,6 +807,41 @@ void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result)
|
||||
print_debug("connect_lost_time:%lld\n", connect_lost_time);
|
||||
GlobalConfig::LinkStatus_G = 0;
|
||||
GlobalConfig::LinkCount = GlobalConfig::LinkCount + 1;
|
||||
|
||||
#ifdef WIFI_MODULE
|
||||
char buf[128] = {0};
|
||||
std::string wpa_state = "";
|
||||
#ifdef G2UL_GATEWAY
|
||||
wpa_state = "/usr/sbin/wpa_cli status|grep wpa_state | cut -f 2 -d '='";
|
||||
#endif
|
||||
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
wpa_state = "/opt/Cidn/wpa_cli status|grep wpa_state | cut -f 2 -d '='";
|
||||
#endif
|
||||
system_custom(wpa_state.c_str(), buf);
|
||||
std::string state = std::string(buf);
|
||||
std::string RSSI_cmd = "";
|
||||
#ifdef G2UL_GATEWAY
|
||||
RSSI_cmd = "/usr/sbin/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='";
|
||||
#endif
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
RSSI_cmd = "/opt/Cidn/wpa_cli signal_poll|grep RSSI | cut -f 2 -d '='";
|
||||
#endif
|
||||
system_custom(RSSI_cmd.c_str(), buf);
|
||||
std::string RSSI = std::string(buf);
|
||||
|
||||
int iRet = reconnect();
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sprintf(buf, "wifi RSSI:%s,state:%s,MQTT reconnect :%d\n", RSSI.c_str(),state.c_str(),iRet);
|
||||
//LOG_WARN(" %s\n",buf);
|
||||
int status = Ping( GlobalConfig::ServerIP.c_str(), 10000);;
|
||||
//LOG_WARN(" netStatus %d\n",status);
|
||||
print_info("%s\n", buf);
|
||||
|
||||
#else
|
||||
int iRet = reconnect();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
|
||||
@ -337,7 +920,7 @@ void StartMqttClient()
|
||||
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));
|
||||
sleep(3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,13 +931,14 @@ void SearchThread()
|
||||
|
||||
while (GlobalConfig::QuitFlag_G) {
|
||||
if (GlobalConfig::IpAddr_G.length() > 0 && 0 != GlobalConfig::IpAddr_G.compare("0.0.0.0")) {
|
||||
print_info("%s\n",runinfo.c_str());
|
||||
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));
|
||||
sleep(5);
|
||||
print_error("SearchThred restart.\n");
|
||||
}
|
||||
}
|
||||
|
@ -27,5 +27,11 @@ extern void RecvUpdateFile(); //更新升级包
|
||||
extern void StartCgiServer(); //启动cgi处理服务端
|
||||
extern void HeartRep();
|
||||
extern void UartStart(); //
|
||||
extern void TestUart();
|
||||
extern void WatchDog();
|
||||
extern void UartStartWave();
|
||||
extern void StartUdpSys(); //组播通信
|
||||
extern void GetCSQ();
|
||||
extern void Dial5G();
|
||||
extern void InitModule();
|
||||
extern void RunLED();
|
||||
|
2908
uart/SH_Uart.cpp
2908
uart/SH_Uart.cpp
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,7 @@
|
||||
#include "../common/SH_CommonFunc.hpp"
|
||||
#include "../common/SH_global.h"
|
||||
#include "../dbaccess/SH_SqlDB.hpp"
|
||||
|
||||
#include "../calculation/Calculation.hpp"
|
||||
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
//using boost::system::error_code;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
typedef void (*pTestRecvCallBack)(int Status);
|
||||
|
||||
class Uart : public MySingleton<Uart>
|
||||
{
|
||||
@ -28,17 +29,38 @@ private :
|
||||
boost::asio::io_service mIoSev;
|
||||
boost::asio::serial_port mUart;
|
||||
int mRdLength;
|
||||
enum{BUF_LENGTH = 1107};
|
||||
char mUartRecvBuf[BUF_LENGTH];
|
||||
int mlastSize;
|
||||
int mPackgeIndex;
|
||||
string strTimetamp;
|
||||
|
||||
//DataNodeInfo dataNodeInfo;
|
||||
std::string m_strDestShortAddr;
|
||||
int waittime;
|
||||
enum{BUF_LENGTH = 40960};
|
||||
unsigned char mUartRecvBuf[BUF_LENGTH];
|
||||
char mUartRecvTmpBuf[BUF_LENGTH*15];
|
||||
boost::mutex mLock;
|
||||
boost::asio::io_service::strand mStrand;
|
||||
|
||||
public :
|
||||
Uart();
|
||||
void InitUart();
|
||||
~Uart();
|
||||
void InitZigbee();
|
||||
void InitUart(speed_t speed);
|
||||
void Close();
|
||||
void InitTestUart(speed_t speed);
|
||||
void ReadTestUart();
|
||||
int fd,TestFd;
|
||||
bool bUpdate;
|
||||
bool bUpdatePre;
|
||||
bool bUpdateconfig;
|
||||
bool bTest;
|
||||
bool bZigbeeSinal;
|
||||
bool bModifyAddr;
|
||||
bool bSendTimeStamp;
|
||||
std::string DataNodeUpdateFile;
|
||||
void WriteToUart(const char *strSend,int pLen);
|
||||
void ReadFromUart();
|
||||
int ReadFromUart();
|
||||
void setCallBack(onReceiveUart _callback);
|
||||
void Run();
|
||||
void Stop();
|
||||
@ -46,30 +68,48 @@ public :
|
||||
void UpdateZigbeeInfo(const char *pData);
|
||||
void DealRecvData(const char *pData);
|
||||
void DealDataNodeInfo(const char *pData);
|
||||
void DealDataNodeName(const char *pData);
|
||||
void DealDataNodeFeature(const char *pData, int flag);
|
||||
void DealDataNodeWave(const char *pData);
|
||||
void DealWaveThread();
|
||||
void DealWave();
|
||||
void DealNodeSendTime(unsigned char* shortaddr);
|
||||
void ZigbeeInit();
|
||||
int ZigbeeTest();
|
||||
|
||||
void modify_info(unsigned short id, char * zigbee);
|
||||
void modify_distaddr_info(unsigned short id, char * zigbee,unsigned char* distAddr);
|
||||
void modify_LocalAddr(unsigned short id);
|
||||
void modify_DistAddr(unsigned char* distAddr);
|
||||
void modify_Localchannel(unsigned char pad);
|
||||
void modify_LocalPanID(unsigned short padID);
|
||||
void getZigbeeSignal(unsigned char* distAddr);
|
||||
void zigbee_reset(unsigned short pad, unsigned short type);
|
||||
void WriteChanl2Zigbee(unsigned char pad);
|
||||
void WritePanId2Zigbee(unsigned short pad);
|
||||
void WriteSpeed2Zigbee();
|
||||
//void WriteLocalAddr(unsigned short id);
|
||||
void WriteTranTimeout2Zigbee(unsigned char Time);
|
||||
void WriteShortAddr2Zigbee(unsigned short pad);
|
||||
void WriteShortAddr_DistAddr2Zigbee(unsigned short pad,unsigned char* pDestShortAddr);
|
||||
void UpdateWirelessNode(unsigned short shortAdd);
|
||||
void UpdateWirelessNodeTime(unsigned char* pDestShortAddr,int modifyaddr/*,int nodewaveindex,int nodetime,int nodeindex*/);
|
||||
int UpdateConfig(unsigned char* pDestShortAddr);
|
||||
bool ReadUpdatePackge(unsigned char* shortAddr);
|
||||
bool CheckCrc(char* pCheckBuff,int No);
|
||||
int FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head);
|
||||
virtual void DataAnalysis_R(DevDataOfGwid &pData);
|
||||
virtual void DataAnalysis_W(DevData &pData,bool pFlag);
|
||||
virtual void ThreadInit();
|
||||
int UartRecv(int fd, char srcshow,char* buffer);
|
||||
void openSwitch();
|
||||
private :
|
||||
void ReadHandle(const boost::system::error_code &ec,size_t bytesRead);
|
||||
void ReadHandle(char* pUartRecvBuf,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;
|
||||
bool m_waveTrans;
|
||||
};
|
||||
|
||||
|
||||
|
@ -121,7 +121,7 @@ void UdpSys::AnalysisDataSys(std::string cmd)
|
||||
GlobalConfig::ServerPort = localServerPort;
|
||||
|
||||
WriteStr2Config(SERVERCONFIG, "Server", "localServerIpAddress", GlobalConfig::ServerIP);
|
||||
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", boost::lexical_cast<std::string>(GlobalConfig::ServerPort));
|
||||
WriteStr2Config(SERVERCONFIG, "Server", "localServerPort", to_string(GlobalConfig::ServerPort));
|
||||
|
||||
std::string fileserver = ReadStrByOpt(SERVERCONFIG, "FileServer", "FileServerIpAddress");
|
||||
if (0 == fileserver.compare("0.0.0.0") || 0 == fileserver.length()) {
|
||||
|
555
wifi/wpa_client.cpp
Normal file
555
wifi/wpa_client.cpp
Normal file
@ -0,0 +1,555 @@
|
||||
#include "wpa_client.h"
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace wifi {
|
||||
|
||||
size_t strlcpy (char *dst, const char *src, size_t dst_sz)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
for (n = 0; n < dst_sz; n++) {
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
if (n < dst_sz)
|
||||
return n;
|
||||
if (n > 0)
|
||||
*(dst - 1) = '\0';
|
||||
return n + strlen (src);
|
||||
}
|
||||
|
||||
static std::string to_string(int val) {
|
||||
char *buf = NULL;
|
||||
int size;
|
||||
int temp;
|
||||
if (val < 0)
|
||||
{
|
||||
temp = -val;
|
||||
size = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = val;
|
||||
size = 1;
|
||||
}
|
||||
for(; temp > 0; temp = temp / 10, size++);
|
||||
size++;
|
||||
|
||||
buf = (char *)malloc(size);
|
||||
if (buf == NULL)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
memset(buf, 0, size);
|
||||
sprintf(buf, "%d", val);
|
||||
std::string re(buf);
|
||||
free(buf);
|
||||
return re;
|
||||
}
|
||||
|
||||
|
||||
MXDHCP::MXDHCP()
|
||||
{
|
||||
pstream = NULL;
|
||||
}
|
||||
|
||||
MXDHCP::~MXDHCP()
|
||||
{
|
||||
if(pstream!=NULL)
|
||||
{
|
||||
pclose(pstream);
|
||||
pstream = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool MXDHCP::Start(const std::string & net_interface)
|
||||
{
|
||||
if(pstream!=NULL)
|
||||
{
|
||||
pclose(pstream);
|
||||
pstream = NULL;
|
||||
}
|
||||
std::string cmd = "udhcpc -b -i " + net_interface + " &";
|
||||
system("killall -9 udhcpc &");
|
||||
usleep(1000*100);
|
||||
pstream = popen(cmd.data(),"r");
|
||||
if(pstream == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* dhcp 这个类的主要原理是通过读取udhcpc 的输出来判断是否拿到了ip地址,实际情况中可以使用别的方法
|
||||
*/
|
||||
bool MXDHCP::GetDHCPStatus()
|
||||
{
|
||||
if(pstream == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int len = 1024;
|
||||
char *buff = (char *)malloc(sizeof(char)*len);
|
||||
if(buff==NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int res = fread(buff,sizeof(char),len,pstream);
|
||||
if(res<=0)
|
||||
{
|
||||
free(buff);
|
||||
return false;
|
||||
}
|
||||
if(!CheckString(buff,res))
|
||||
{
|
||||
free(buff);
|
||||
return false;
|
||||
}
|
||||
pclose(pstream);
|
||||
pstream = NULL;
|
||||
free(buff);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MXDHCP::CheckString(char *buf ,int len)
|
||||
{
|
||||
if(strstr(buf,"adding dns")==NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
WPAClient::WPAClient(const std::string & wpa_control_path)
|
||||
{
|
||||
wpa_context_ = NULL;
|
||||
wpa_control_path_ = wpa_control_path;
|
||||
SetConnStatus(STEP_SCAN);
|
||||
Init();
|
||||
}
|
||||
|
||||
WPAClient::~WPAClient()
|
||||
{
|
||||
Close(wpa_context_);
|
||||
}
|
||||
|
||||
bool WPAClient::Init()
|
||||
{
|
||||
wpa_context_ = Open(wpa_control_path_);
|
||||
if (wpa_context_ == NULL)
|
||||
{
|
||||
print_error("open wpa failed\n");
|
||||
return false;
|
||||
}
|
||||
SetConnStatus(STEP_SCAN);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string WPAClient::GetCurrentSSID()
|
||||
{
|
||||
std::string cmd = "STATUS";
|
||||
std::string ssid_key = "\nssid=";
|
||||
std::string recv;
|
||||
std::string ssid = "";
|
||||
|
||||
if (!Request(wpa_context_, cmd, recv))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
char temp[1024] = {0};
|
||||
strcpy(temp, recv.data());
|
||||
char *key = NULL;
|
||||
key = strstr(temp, ssid_key.data());
|
||||
if (key == NULL)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
key += ssid_key.length();
|
||||
for(; (*key != '\0') && (*key != '\n') && (*key != '\r'); key++)
|
||||
{
|
||||
ssid += *key;
|
||||
}
|
||||
|
||||
return ssid;
|
||||
}
|
||||
|
||||
std::string WPAClient::GetNetSsid()
|
||||
{
|
||||
std::string cmd = "SCAN";
|
||||
std::string recv;
|
||||
if (!Request(wpa_context_, cmd, recv))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
recv.clear();
|
||||
cmd = "SCAN_RESULTS";
|
||||
|
||||
if (!Request(wpa_context_, cmd, recv))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return recv;
|
||||
}
|
||||
int WPAClient::GetWiFiRssi()
|
||||
{
|
||||
std::string cmd = "SIGNAL_POLL";
|
||||
std::string rssi_key = "RSSI";
|
||||
std::string recv;
|
||||
if (!Request(wpa_context_, cmd, recv))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
char temp[1024] = {0};
|
||||
strcpy(temp, recv.data());
|
||||
print_info("recv = %s\n",recv.c_str());
|
||||
char *key = NULL;
|
||||
key = strstr(temp, rssi_key.data());
|
||||
if (key == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for(; (*key != '\0') && (*key != '\n') && (*key != '\r'); key++)
|
||||
{
|
||||
if ((*key >= '0') && (*key <= '9'))
|
||||
{
|
||||
return atoi(key);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WPAClient::ConnectWiFi(const std::string & ssid, const std::string & password) {
|
||||
int net_id;
|
||||
SetConnStatus(STEP_SCAN);
|
||||
if (!CleanAllWiFi())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("CleanAllWiFi \n");
|
||||
if (!AddWiFi(net_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("AddWiFi \n");
|
||||
if (!SetSSID(ssid, net_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("SetSSID \n");
|
||||
if (!SetPassword(password, 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!SetProtocol(net_id, 1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("SetProtocol\n");
|
||||
SetScanSSID(net_id);
|
||||
if (!EnableWiFi(net_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("EnableWiFi\n");
|
||||
return CheckCommandWithOk("SAVE_CONFIG");
|
||||
//return true;
|
||||
}
|
||||
|
||||
bool WPAClient::ConnectWiFiWithNoPassword(const std::string & ssid)
|
||||
{
|
||||
int net_id;
|
||||
SetConnStatus(STEP_SCAN);
|
||||
if (!CleanAllWiFi())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("CleanAllWiFi\n");
|
||||
if (!AddWiFi(net_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("AddWiFi\n");
|
||||
if (!SetSSID(ssid, net_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("SetSSID\n");
|
||||
if (!SetProtocol(net_id, 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("SetProtocol\n");
|
||||
SetScanSSID(net_id);
|
||||
if (!EnableWiFi(net_id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
print_info("EnableWiFi\n");
|
||||
|
||||
return CheckCommandWithOk("SAVE_CONFIG");
|
||||
}
|
||||
|
||||
bool WPAClient::ConnectWiFiWithLast()
|
||||
{
|
||||
SetConnStatus(STEP_SCAN);
|
||||
if (!CheckCommandWithOk("ENABLE_NETWORK all"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WPAClient::GetConnectStatus() {
|
||||
std::string cmd = "STATUS";
|
||||
std::string recv;
|
||||
int addr;
|
||||
switch (step_) {
|
||||
case STEP_SCAN:
|
||||
if (!Request(wpa_context_, cmd, recv)) {
|
||||
return false;
|
||||
}
|
||||
addr = recv.find("COMPLETED");
|
||||
if (addr == -1) {
|
||||
return false;
|
||||
}
|
||||
SetConnStatus(STEP_CONNECT_AP_OK);
|
||||
case STEP_CONNECT_AP_OK:
|
||||
if (!dhcp_.Start("wlan0")) {
|
||||
return false;
|
||||
}
|
||||
SetConnStatus(STEP_DHCP_IP);
|
||||
case STEP_DHCP_IP:
|
||||
if (!dhcp_.GetDHCPStatus()) {
|
||||
return false;
|
||||
}
|
||||
SetConnStatus(STEP_SUCCESS);
|
||||
case STEP_SUCCESS:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WPAClient::SetConnStatus(ConnectStatus status) {
|
||||
step_ = status;
|
||||
}
|
||||
|
||||
void WPAClient::wifiup()
|
||||
{
|
||||
system("ifconfig mlan0 up");
|
||||
system("ifconfig mlan0 up");
|
||||
system("ifconfig mlan0 up");
|
||||
}
|
||||
|
||||
bool WPAClient::CleanWifi()
|
||||
{
|
||||
bool flag = CleanAllWiFi();
|
||||
CheckCommandWithOk("SAVE_CONFIG");
|
||||
return flag;
|
||||
}
|
||||
|
||||
int WPAClient::GetConnStatus() {
|
||||
return step_;
|
||||
}
|
||||
|
||||
WPAContext * WPAClient::Open(const std::string & path) {
|
||||
struct WPAContext *ctrl;
|
||||
ctrl = (struct WPAContext*)malloc(sizeof(struct WPAContext));
|
||||
if (ctrl == NULL) {
|
||||
print_error("malloc failed\n");
|
||||
return NULL;
|
||||
}
|
||||
memset(ctrl, 0, sizeof(struct WPAContext));
|
||||
static int counter = 0;
|
||||
int ret;
|
||||
int tries = 0;
|
||||
size_t res;
|
||||
ctrl->s = socket(PF_UNIX, SOCK_DGRAM, 0);
|
||||
if (ctrl->s < 0) {
|
||||
print_error("socket failed\n");
|
||||
free(ctrl);
|
||||
return NULL;
|
||||
}
|
||||
ctrl->local.sun_family = AF_UNIX;
|
||||
counter++;
|
||||
try_again:
|
||||
ret = snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
|
||||
"/tmp" "/"
|
||||
"wpa_ctrl_" "%d-%d",
|
||||
(int)getpid(), counter);
|
||||
if (ret < 0 || (size_t)ret >= sizeof(ctrl->local.sun_path)) {
|
||||
print_error("snprintf failed\n");
|
||||
close(ctrl->s);
|
||||
free(ctrl);
|
||||
return NULL;
|
||||
}
|
||||
tries++;
|
||||
if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
|
||||
sizeof(ctrl->local)) < 0) {
|
||||
if (errno == EADDRINUSE && tries < 2) {
|
||||
/*
|
||||
* getpid() returns unique identifier for this instance
|
||||
* of wpa_ctrl, so the existing socket file must have
|
||||
* been left by unclean termination of an earlier run.
|
||||
* Remove the file and try again.
|
||||
*/
|
||||
unlink(ctrl->local.sun_path);
|
||||
goto try_again;
|
||||
}
|
||||
print_error("bind failed\n");
|
||||
close(ctrl->s);
|
||||
free(ctrl);
|
||||
return NULL;
|
||||
}
|
||||
ctrl->dest.sun_family = AF_UNIX;
|
||||
res = strlcpy(ctrl->dest.sun_path, wpa_control_path_.data(),
|
||||
sizeof(ctrl->dest.sun_path));
|
||||
if (res >= sizeof(ctrl->dest.sun_path)) {
|
||||
close(ctrl->s);
|
||||
free(ctrl);
|
||||
return NULL;
|
||||
}
|
||||
if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
|
||||
sizeof(ctrl->dest)) < 0) {
|
||||
print_error("connect failed\n");
|
||||
close(ctrl->s);
|
||||
unlink(ctrl->local.sun_path);
|
||||
free(ctrl);
|
||||
return NULL;
|
||||
}
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
void WPAClient::Close(WPAContext * context) {
|
||||
if (context == NULL)
|
||||
return;
|
||||
unlink(context->local.sun_path);
|
||||
if (context->s >= 0)
|
||||
close(context->s);
|
||||
free(context);
|
||||
}
|
||||
|
||||
bool WPAClient::Request(WPAContext * context, const std::string & cmd, std::string& reply) {
|
||||
int res;
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
const char *_cmd;
|
||||
char *cmd_buf = NULL;
|
||||
size_t _cmd_len;
|
||||
_cmd = cmd.data();
|
||||
_cmd_len = cmd.length();
|
||||
if (wpa_context_ == NULL) {
|
||||
print_error("wpa_context_ is null\n");
|
||||
return false;
|
||||
}
|
||||
if (send(wpa_context_->s, _cmd, _cmd_len, 0) < 0) {
|
||||
free(cmd_buf);
|
||||
return -1;
|
||||
}
|
||||
free(cmd_buf);
|
||||
for (;;) {
|
||||
tv.tv_sec = 10;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(wpa_context_->s, &rfds);
|
||||
res = select(wpa_context_->s + 1, &rfds, NULL, NULL, &tv);
|
||||
if (res < 0)
|
||||
return false;
|
||||
if (FD_ISSET(wpa_context_->s, &rfds)) {
|
||||
char temp[1024] = {0};
|
||||
int temp_len = 1024;
|
||||
res = recv(wpa_context_->s, temp, temp_len, 0);
|
||||
if (res < 0)
|
||||
return false;
|
||||
if (res > 0 && temp[0] == '<') {
|
||||
continue;
|
||||
}
|
||||
reply = temp;
|
||||
break;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WPAClient::CheckCommandWithOk(const std::string cmd) {
|
||||
std::string recv;
|
||||
if (!Request(wpa_context_, cmd, recv)) {
|
||||
print_error("send cmd falied\n");
|
||||
return false;
|
||||
}
|
||||
print_error("recv cmd %s\n",recv.data());
|
||||
if (strstr(recv.data(), "OK") == NULL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WPAClient::AddWiFi(int & id) {
|
||||
std::string add_cmd = "ADD_NETWORK";
|
||||
std::string recv;
|
||||
if (!Request(wpa_context_, add_cmd, recv)) {
|
||||
return false;
|
||||
}
|
||||
id = atoi(recv.data());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WPAClient::SetScanSSID(int id) {
|
||||
std::string cmd = "SET_NETWORK " + to_string(id) + " scan_ssid 1";
|
||||
return CheckCommandWithOk(cmd);
|
||||
}
|
||||
bool WPAClient::SetSSID(const std::string & ssid, int id) {
|
||||
std::string cmd = "SET_NETWORK " + to_string(id) + " ssid " + "\"" + ssid + "\"";
|
||||
return CheckCommandWithOk(cmd);
|
||||
}
|
||||
bool WPAClient::SetPassword(const std::string & password, int id) {
|
||||
std::string cmd = "SET_NETWORK " + to_string(id) + " psk " + "\"" + password + "\"";
|
||||
return CheckCommandWithOk(cmd);
|
||||
}
|
||||
bool WPAClient::SetProtocol(int id, int en_crypt) {
|
||||
std::string cmd = "SET_NETWORK " + to_string(id);
|
||||
if (en_crypt) {
|
||||
cmd += " key_mgmt WPA-PSK";
|
||||
return CheckCommandWithOk(cmd);
|
||||
} else {
|
||||
cmd += " key_mgmt NONE";
|
||||
return CheckCommandWithOk(cmd);
|
||||
}
|
||||
}
|
||||
bool WPAClient::CleanAllWiFi() {
|
||||
CheckCommandWithOk("REMOVE_NETWORK all");
|
||||
CheckCommandWithOk("DISABLE_NETWORK all");
|
||||
return true;
|
||||
}
|
||||
bool WPAClient::EnableWiFi(int id) {
|
||||
std::string cmd = "ENABLE_NETWORK " + to_string(id);
|
||||
return CheckCommandWithOk(cmd);
|
||||
}
|
||||
|
||||
bool WPAClient::ReconnectWiFi() {
|
||||
std::string cmd = "RECONNECT";
|
||||
return CheckCommandWithOk(cmd);
|
||||
}
|
||||
}
|
90
wifi/wpa_client.h
Normal file
90
wifi/wpa_client.h
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
#
|
||||
# wifi连接接口
|
||||
# 说明:通过进程间通信与wpa_supplicant进行交互实现wifi连接
|
||||
# 注意:使用该接口的应用运行前要确保wpa_supplicant应用已经启动
|
||||
# 并且能明确进程间通信地址。
|
||||
#
|
||||
*/
|
||||
#ifndef __WPA_CLIENT_H__
|
||||
#define __WPA_CLIENT_H__
|
||||
#include <string>
|
||||
#include <sys/un.h>
|
||||
#include "../utility/SH_MySingleton.hpp"
|
||||
#include "../common/SH_global.h"
|
||||
|
||||
namespace wifi
|
||||
{
|
||||
#ifdef G2UL_GATEWAY
|
||||
const std::string WPA_PATH = "/var/run/wpa_supplicant/wlan0"; //进程间通信地址加上网络接口额名称
|
||||
#endif
|
||||
#ifdef IMX6UL_GATEWAY
|
||||
const std::string WPA_PATH = "/var/run/wpa_supplicant/wlan2"; //进程间通信地址加上网络接口额名称
|
||||
#endif
|
||||
struct WPAContext
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_un local;
|
||||
struct sockaddr_un dest;
|
||||
};
|
||||
|
||||
enum ConnectStatus
|
||||
{
|
||||
STEP_SCAN = 0,
|
||||
STEP_CONNECT_AP_OK,
|
||||
STEP_DHCP_IP,
|
||||
STEP_SUCCESS
|
||||
};
|
||||
class MXDHCP
|
||||
{ //dhcp ip地址的工具类,实现方法不算特别合理。可以根据具体情况进行更改
|
||||
public:
|
||||
MXDHCP();
|
||||
~MXDHCP();
|
||||
bool Start(const std::string& net_interface);
|
||||
bool GetDHCPStatus();
|
||||
private:
|
||||
bool CheckString(char *buf,int len);
|
||||
FILE *pstream;
|
||||
};
|
||||
|
||||
class WPAClient //: public MySingleton<WPAClient>
|
||||
{
|
||||
public:
|
||||
WPAClient(const std::string& wpa_control_path = WPA_PATH);
|
||||
~WPAClient();
|
||||
bool GetInitStatus(){return wpa_context_!=NULL;} //获取wpa进程间通信是否建立连接
|
||||
int GetWiFiRssi(); //获取wifi信号强度,需要在连接成功之后调用
|
||||
std::string GetCurrentSSID(); //获取当前连接的wifi的名称
|
||||
bool ConnectWiFi(const std::string& ssid, const std::string& password); //连接加密wifi,传入wifi名称和密码
|
||||
bool ConnectWiFiWithNoPassword(const std::string& ssid); //连接无加密的wifi,传入wifi名称即可
|
||||
bool ConnectWiFiWithLast(); //直接连接上次已保存的wifi
|
||||
bool GetConnectStatus(); //获取wifi连接状态
|
||||
std::string GetNetSsid();
|
||||
void wifiup(); //mlan0 up
|
||||
bool CleanWifi();
|
||||
bool ReconnectWiFi(); //重新连接WIFI
|
||||
protected:
|
||||
bool Init();
|
||||
struct WPAContext* Open(const std::string& path);
|
||||
void Close(struct WPAContext* context);
|
||||
bool Request(struct WPAContext* context, const std::string& cmd,std::string& reply);
|
||||
bool CheckCommandWithOk(const std::string cmd);
|
||||
bool AddWiFi(int& id);
|
||||
bool SetScanSSID(int id);
|
||||
bool SetSSID(const std::string& ssid, int id);
|
||||
bool SetPassword(const std::string& password, int id);
|
||||
bool SetProtocol(int id, int en_crypt);
|
||||
bool CleanAllWiFi();
|
||||
bool EnableWiFi(int id);
|
||||
void SetConnStatus(ConnectStatus status);
|
||||
int GetConnStatus();
|
||||
protected:
|
||||
struct WPAContext* wpa_context_;
|
||||
std::string wpa_control_path_;
|
||||
MXDHCP dhcp_;
|
||||
private:
|
||||
int step_;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // __WPA_CLIENT_H__
|
Loading…
x
Reference in New Issue
Block a user