mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-15 16:36:52 +01:00
Merge pull request #29 from ty4tw/gateway
Serious BugFix of Que Element, TLS connection, XBee API mode and CTRL+C termination update
This commit is contained in:
43
.cproject
43
.cproject
@@ -5,28 +5,29 @@
|
|||||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1685199227" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1685199227" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
||||||
<externalSettings/>
|
<externalSettings/>
|
||||||
<extensions>
|
<extensions>
|
||||||
|
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1685199227" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
|
<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="" id="cdt.managedbuild.config.gnu.exe.debug.1685199227" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
|
||||||
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1685199227." name="/" resourcePath="">
|
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1685199227." name="/" resourcePath="">
|
||||||
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.102264757" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
|
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.102264757" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
|
||||||
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.2137160061" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
|
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.2137160061" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
|
||||||
<builder buildPath="${workspace_loc:/MQTTSN-embedded-C}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.767762182" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
|
<builder buildPath="${workspace_loc:/MQTTSN-embedded-C}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.767762182" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.602829827" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
<tool id="cdt.managedbuild.tool.gnu.archiver.base.602829827" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.109068141" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
|
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.109068141" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
|
||||||
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1710260957" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
|
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1710260957" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
|
||||||
<option id="gnu.cpp.compiler.exe.debug.option.debugging.level.1258567310" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
|
<option id="gnu.cpp.compiler.exe.debug.option.debugging.level.1258567310" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
|
||||||
<option id="gnu.cpp.compiler.option.dialect.std.1678347248" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
|
<option id="gnu.cpp.compiler.option.dialect.std.1678347248" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
|
||||||
<option id="gnu.cpp.compiler.option.dialect.flags.1711182709" name="Other dialect flags" superClass="gnu.cpp.compiler.option.dialect.flags" value="-std=c++11" valueType="string"/>
|
<option id="gnu.cpp.compiler.option.dialect.flags.1711182709" name="Other dialect flags" superClass="gnu.cpp.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=c++11" valueType="string"/>
|
||||||
<option id="gnu.cpp.compiler.option.include.paths.1361987608" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
|
<option id="gnu.cpp.compiler.option.include.paths.1361987608" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src"/>
|
||||||
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/GatewayTester/src"/>
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src/linux"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src/linux"/>
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNPacket/src"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNPacket/src"/>
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNClient/src"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNClient/src"/>
|
||||||
@@ -35,8 +36,8 @@
|
|||||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1626802967" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1626802967" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.2017162618" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
|
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.2017162618" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
|
||||||
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.1941536725" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" valueType="enumerated"/>
|
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.1941536725" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||||
<option id="gnu.c.compiler.exe.debug.option.debugging.level.1668726974" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
|
<option id="gnu.c.compiler.exe.debug.option.debugging.level.1668726974" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
|
||||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.814497727" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.814497727" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1881440001" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug">
|
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1881440001" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug">
|
||||||
@@ -46,7 +47,7 @@
|
|||||||
</inputType>
|
</inputType>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.581660133" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
|
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.581660133" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
|
||||||
<option id="gnu.cpp.link.option.libs.1848275182" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
|
<option id="gnu.cpp.link.option.libs.1848275182" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
|
||||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="pthread"/>
|
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="pthread"/>
|
||||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="ssl"/>
|
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="ssl"/>
|
||||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="crypto"/>
|
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="crypto"/>
|
||||||
@@ -62,7 +63,7 @@
|
|||||||
</toolChain>
|
</toolChain>
|
||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry excluding="MQTTSNGateway/src/linux/xbee|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
<entry excluding="MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/GatewayTester/samples/mainTest.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
</configuration>
|
</configuration>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
@@ -72,37 +73,37 @@
|
|||||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.561557339" moduleId="org.eclipse.cdt.core.settings" name="Release">
|
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.561557339" moduleId="org.eclipse.cdt.core.settings" name="Release">
|
||||||
<externalSettings/>
|
<externalSettings/>
|
||||||
<extensions>
|
<extensions>
|
||||||
|
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
|
||||||
</extensions>
|
</extensions>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.561557339" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
|
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.561557339" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
|
||||||
<folderInfo id="cdt.managedbuild.config.gnu.exe.release.561557339." name="/" resourcePath="">
|
<folderInfo id="cdt.managedbuild.config.gnu.exe.release.561557339." name="/" resourcePath="">
|
||||||
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.474335535" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
|
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.474335535" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
|
||||||
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.338327831" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
|
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.338327831" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
|
||||||
<builder buildPath="${workspace_loc:/MQTTSN-embedded-C}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.1268563010" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
|
<builder buildPath="${workspace_loc:/MQTTSN-embedded-C}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.1268563010" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1908794347" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1908794347" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1903732701" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
|
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1903732701" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
|
||||||
<option id="gnu.cpp.compiler.exe.release.option.optimization.level.15425920" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
|
<option id="gnu.cpp.compiler.exe.release.option.optimization.level.15425920" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
|
||||||
<option id="gnu.cpp.compiler.exe.release.option.debugging.level.857802503" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
|
<option id="gnu.cpp.compiler.exe.release.option.debugging.level.857802503" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
|
||||||
<option id="gnu.cpp.compiler.option.dialect.flags.1078302249" name="Other dialect flags" superClass="gnu.cpp.compiler.option.dialect.flags" value="-std=c++11" valueType="string"/>
|
<option id="gnu.cpp.compiler.option.dialect.flags.1078302249" name="Other dialect flags" superClass="gnu.cpp.compiler.option.dialect.flags" useByScannerDiscovery="true" value="-std=c++11" valueType="string"/>
|
||||||
<option id="gnu.cpp.compiler.option.include.paths.2114194326" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
|
<option id="gnu.cpp.compiler.option.include.paths.2114194326" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src/linux/udp"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src/linux/udp"/>
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src"/>
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src/linux"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNGateway/src/linux"/>
|
||||||
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNPacket/src"/>
|
<listOptionValue builtIn="false" value="/home/tomoaki/git/paho.mqtt-sn.embedded-c/MQTTSNPacket/src"/>
|
||||||
</option>
|
</option>
|
||||||
<option id="gnu.cpp.compiler.option.dialect.std.216116103" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
|
<option id="gnu.cpp.compiler.option.dialect.std.216116103" 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.1606625536" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1606625536" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.246546722" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
|
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.246546722" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
|
||||||
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.1094525037" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/>
|
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.1094525037" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||||
<option id="gnu.c.compiler.exe.release.option.debugging.level.162341902" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
|
<option id="gnu.c.compiler.exe.release.option.debugging.level.162341902" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
|
||||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.456127079" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.456127079" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.2140499460" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release">
|
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.2140499460" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release">
|
||||||
@@ -128,7 +129,7 @@
|
|||||||
</toolChain>
|
</toolChain>
|
||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry excluding="MQTTSNPacket/src|MQTTSNGateway/src|MQTTSNGateway/src/linux|MQTTSNGateway/src/linux/udp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
<entry excluding="MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/GatewayTester/samples/mainTest.cpp|MQTTSNPacket/src|MQTTSNGateway/src|MQTTSNGateway/src/linux|MQTTSNGateway/src/linux/udp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||||
<entry excluding="mainLogmonitor.cpp|linux|linux/udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src"/>
|
<entry excluding="mainLogmonitor.cpp|linux|linux/udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src"/>
|
||||||
<entry excluding="xbee" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
<entry excluding="xbee" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>
|
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>
|
||||||
|
|||||||
@@ -28,16 +28,20 @@ $ ./MQTT-SNGateway [-f Config file name]
|
|||||||
|
|
||||||
BrokerName=iot.eclipse.org
|
BrokerName=iot.eclipse.org
|
||||||
BrokerPortNo=1883
|
BrokerPortNo=1883
|
||||||
SecureConnection=NO
|
BrokerSecurePortNo=8883
|
||||||
#BrokerPortNo=8883
|
|
||||||
#SecureConnection=YES
|
|
||||||
ClientAuthentication=NO
|
ClientAuthentication=NO
|
||||||
ClientList=clients.conf
|
#ClientsList=/path/to/your_clients.conf
|
||||||
|
|
||||||
|
#RootCAfile=/path/to/your_Root_CA.crt
|
||||||
|
#RootCApath=/path/to/your_certs_directory/
|
||||||
|
#CertsDirectory=/path/to/your_client_certs_directory/
|
||||||
|
|
||||||
GatewayID=1
|
GatewayID=1
|
||||||
GatewayName=PahoGateway-01
|
GatewayName=PahoGateway-01
|
||||||
KeepAlive=900
|
KeepAlive=900
|
||||||
#LoginID=
|
#LoginID=your_ID
|
||||||
#Password=
|
#Password=your_Password
|
||||||
|
|
||||||
# UDP
|
# UDP
|
||||||
GatewayPortNo=10000
|
GatewayPortNo=10000
|
||||||
@@ -47,14 +51,15 @@ MulticastPortNo=1883
|
|||||||
# XBee
|
# XBee
|
||||||
Baudrate=38400
|
Baudrate=38400
|
||||||
SerialDevice=/dev/ttyUSB0
|
SerialDevice=/dev/ttyUSB0
|
||||||
|
ApiMode=2
|
||||||
```
|
```
|
||||||
|
|
||||||
**BrokerName** to specify a domain name of the Broker, and **BrokerPortNo** is a port No of the Broker. If the Broker have to connected via TLS, set BrokerPortNo=8883 and **SecureConnection=YES**.
|
**BrokerName** to specify a domain name of the Broker, and **BrokerPortNo** is a port No of the Broker. **BrokerSecurePortNo** is for TLS connection.
|
||||||
**MulticastIP** and **MulticastPortNo** is a multicast address for ADVERTISE, GWSEARCH and GWINFO messages. Gateway is waiting GWSEARCH multicast message and when receiving it send GWINFO message via Broadcast address. Clients can get the gateway address (Gateway IP address and **GatewayPortNo**) from GWINFO message by means of std::recvfrom(),
|
**MulticastIP** and **MulticastPortNo** is a multicast address for ADVERTISE, GWSEARCH and GWINFO messages. Gateway is waiting GWSEARCH multicast message and when receiving it send GWINFO message via Broadcast address. Clients can get the gateway address (Gateway IP address and **GatewayPortNo**) from GWINFO message by means of std::recvfrom(),
|
||||||
Client should know the BroadcastIP and PortNo to send a SEARCHGW message.
|
Client should know the BroadcastIP and PortNo to send a SEARCHGW message.
|
||||||
**GatewayId** is defined by GWSEARCH message.
|
**GatewayId** is defined by GWSEARCH message.
|
||||||
**KeepAlive** is a duration of ADVERTISE message in seconds.
|
**KeepAlive** is a duration of ADVERTISE message in seconds.
|
||||||
when **ClientAuthentication** is YES, see MQTTSNGWClient.cpp line53, clients file specified by ClientList is required. This file defines connect allowed clients by ClientId, IPaddress and PortNo.
|
when **ClientAuthentication** is YES, see MQTTSNGWClient.cpp line53, clients file specified by ClientsList is required. This file defines connect allowed clients by ClientId, IPaddress and PortNo.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,14 +16,19 @@
|
|||||||
BrokerName=iot.eclipse.org
|
BrokerName=iot.eclipse.org
|
||||||
BrokerPortNo=1883
|
BrokerPortNo=1883
|
||||||
BrokerSecurePortNo=8883
|
BrokerSecurePortNo=8883
|
||||||
#SecureConnection=YES
|
|
||||||
ClientAuthentication=NO
|
ClientAuthentication=NO
|
||||||
ClientList=clients.conf
|
#ClientsList=/path/to/your_clients.conf
|
||||||
|
|
||||||
|
#RootCAfile=/etc/ssl/certs/ca-certificates.crt
|
||||||
|
#RootCApath=/etc/ssl/certs/
|
||||||
|
#CertsDirectory=/usr/share/GW/IoTcerts/
|
||||||
|
|
||||||
GatewayID=1
|
GatewayID=1
|
||||||
GatewayName=PahoGateway-01
|
GatewayName=PahoGateway-01
|
||||||
KeepAlive=900
|
KeepAlive=900
|
||||||
#LoginID=
|
#LoginID=your_ID
|
||||||
#Password=
|
#Password=your_Password
|
||||||
|
|
||||||
# UDP
|
# UDP
|
||||||
GatewayPortNo=10000
|
GatewayPortNo=10000
|
||||||
@@ -33,3 +38,5 @@ MulticastPortNo=1883
|
|||||||
# XBee
|
# XBee
|
||||||
Baudrate=38400
|
Baudrate=38400
|
||||||
SerialDevice=/dev/ttyUSB0
|
SerialDevice=/dev/ttyUSB0
|
||||||
|
ApiMode=2
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "MQTTGWPacket.h"
|
#include "MQTTGWPacket.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace MQTTSNGW;
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ void BrokerRecvTask::run(void)
|
|||||||
{
|
{
|
||||||
/* Check sockets is ready to read */
|
/* Check sockets is ready to read */
|
||||||
int activity = select(maxSock + 1, &rset, 0, 0, &timeout);
|
int activity = select(maxSock + 1, &rset, 0, 0, &timeout);
|
||||||
|
|
||||||
if (activity > 0)
|
if (activity > 0)
|
||||||
{
|
{
|
||||||
client = _gateway->getClientList()->getClient();
|
client = _gateway->getClientList()->getClient();
|
||||||
@@ -110,6 +109,7 @@ void BrokerRecvTask::run(void)
|
|||||||
if ( rc > 0 )
|
if ( rc > 0 )
|
||||||
{
|
{
|
||||||
if ( log(client, packet) == -1 )
|
if ( log(client, packet) == -1 )
|
||||||
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,10 @@ void BrokerRecvTask::run(void)
|
|||||||
/* post a BrokerRecvEvent */
|
/* post a BrokerRecvEvent */
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setBrokerRecvEvent(client, packet);
|
ev->setBrokerRecvEvent(client, packet);
|
||||||
_gateway->getPacketEventQue()->post(ev);
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
|
{
|
||||||
|
delete ev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -166,7 +169,7 @@ void BrokerRecvTask::run(void)
|
|||||||
*/
|
*/
|
||||||
int BrokerRecvTask::log(Client* client, MQTTGWPacket* packet)
|
int BrokerRecvTask::log(Client* client, MQTTGWPacket* packet)
|
||||||
{
|
{
|
||||||
char pbuf[(SIZEOF_LOG_PACKET + 5 )* 3];
|
char pbuf[(SIZE_OF_LOG_PACKET + 5 )* 3];
|
||||||
char msgId[6];
|
char msgId[6];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
namespace MQTTSNGW
|
namespace MQTTSNGW
|
||||||
{
|
{
|
||||||
|
|
||||||
#define ERRNO_APL_03 13 // Task Initialize Error
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
Class BrokerRecvTask
|
Class BrokerRecvTask
|
||||||
=====================================*/
|
=====================================*/
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "MQTTSNGateway.h"
|
#include "MQTTSNGateway.h"
|
||||||
#include "MQTTSNGWClient.h"
|
#include "MQTTSNGWClient.h"
|
||||||
#include "MQTTGWPacket.h"
|
#include "MQTTGWPacket.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace MQTTSNGW;
|
using namespace MQTTSNGW;
|
||||||
@@ -34,8 +35,11 @@ BrokerSendTask::BrokerSendTask(Gateway* gateway)
|
|||||||
_gateway = gateway;
|
_gateway = gateway;
|
||||||
_gateway->attach((Thread*)this);
|
_gateway->attach((Thread*)this);
|
||||||
_host = 0;
|
_host = 0;
|
||||||
_service = 0;
|
_port = 0;
|
||||||
_serviceSecure = 0;
|
_portSecure = 0;
|
||||||
|
_certDirectory = 0;
|
||||||
|
_rootCAfile = 0;
|
||||||
|
|
||||||
_light = 0;
|
_light = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,13 +49,25 @@ BrokerSendTask::~BrokerSendTask()
|
|||||||
{
|
{
|
||||||
free(_host);
|
free(_host);
|
||||||
}
|
}
|
||||||
if (_service)
|
if (_port)
|
||||||
{
|
{
|
||||||
free(_service);
|
free(_port);
|
||||||
}
|
}
|
||||||
if (_serviceSecure)
|
if (_portSecure)
|
||||||
{
|
{
|
||||||
free(_serviceSecure);
|
free(_portSecure);
|
||||||
|
}
|
||||||
|
if (_certDirectory)
|
||||||
|
{
|
||||||
|
free(_certDirectory);
|
||||||
|
}
|
||||||
|
if (_rootCApath)
|
||||||
|
{
|
||||||
|
free(_rootCApath);
|
||||||
|
}
|
||||||
|
if (_rootCAfile)
|
||||||
|
{
|
||||||
|
free(_rootCAfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,12 +84,26 @@ void BrokerSendTask::initialize(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
if (_gateway->getParam("BrokerPortNo", param) == 0)
|
if (_gateway->getParam("BrokerPortNo", param) == 0)
|
||||||
{
|
{
|
||||||
_service = strdup(param);
|
_port = strdup(param);
|
||||||
}
|
}
|
||||||
if (_gateway->getParam("BrokerSecurePortNo", param) == 0)
|
if (_gateway->getParam("BrokerSecurePortNo", param) == 0)
|
||||||
{
|
{
|
||||||
_serviceSecure = strdup(param);
|
_portSecure = strdup(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_gateway->getParam("CertsDirectory", param) == 0)
|
||||||
|
{
|
||||||
|
_certDirectory = strdup(param);
|
||||||
|
}
|
||||||
|
if (_gateway->getParam("RootCApath", param) == 0)
|
||||||
|
{
|
||||||
|
_rootCApath = strdup(param);
|
||||||
|
}
|
||||||
|
if (_gateway->getParam("RootCAfile", param) == 0)
|
||||||
|
{
|
||||||
|
_rootCAfile = strdup(param);
|
||||||
|
}
|
||||||
|
|
||||||
_light = _gateway->getLightIndicator();
|
_light = _gateway->getLightIndicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +123,7 @@ void BrokerSendTask::run()
|
|||||||
client = ev->getClient();
|
client = ev->getClient();
|
||||||
packet = ev->getMQTTGWPacket();
|
packet = ev->getMQTTGWPacket();
|
||||||
|
|
||||||
if ( client->getNetwork()->isValid() && packet->getType() == CONNECT )
|
if ( client->getNetwork()->isValid() && !client->getNetwork()->isSecure() && packet->getType() == CONNECT )
|
||||||
{
|
{
|
||||||
client->getNetwork()->close();
|
client->getNetwork()->close();
|
||||||
}
|
}
|
||||||
@@ -101,16 +131,37 @@ void BrokerSendTask::run()
|
|||||||
if ( !client->getNetwork()->isValid() )
|
if ( !client->getNetwork()->isValid() )
|
||||||
{
|
{
|
||||||
/* connect to the broker and send a packet */
|
/* connect to the broker and send a packet */
|
||||||
char* service = _service;
|
char* portNo = _port;
|
||||||
|
const char* cert = 0;
|
||||||
|
const char* keyFile = 0;
|
||||||
|
string certFile;
|
||||||
|
string privateKeyFile;
|
||||||
|
|
||||||
if (client->isSecureNetwork())
|
if (client->isSecureNetwork())
|
||||||
{
|
{
|
||||||
service = _serviceSecure;
|
portNo = _portSecure;
|
||||||
|
if ( _certDirectory )
|
||||||
|
{
|
||||||
|
certFile = _certDirectory;
|
||||||
|
certFile += client->getClientId();
|
||||||
|
certFile += ".crt";
|
||||||
|
cert = certFile.c_str();
|
||||||
|
privateKeyFile = _certDirectory;
|
||||||
|
privateKeyFile += client->getClientId();
|
||||||
|
privateKeyFile += ".key";
|
||||||
|
keyFile = privateKeyFile.c_str();
|
||||||
|
}
|
||||||
|
rc = client->getNetwork()->connect(_host, portNo, _rootCApath, _rootCAfile, cert, keyFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rc = client->getNetwork()->connect(_host, portNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !client->getNetwork()->connect(_host, service) )
|
if ( !rc )
|
||||||
{
|
{
|
||||||
/* disconnect the broker and chage the client's status */
|
/* disconnect the broker and change the client's status */
|
||||||
WRITELOG("%s BrokerSendTask can't open the socket. errno=%d %s%s\n",
|
WRITELOG("%s BrokerSendTask can't connect to the broker. errno=%d %s%s\n",
|
||||||
ERRMSG_HEADER, rc == -1 ? errno : 0, client->getClientId(), ERRMSG_FOOTER);
|
ERRMSG_HEADER, rc == -1 ? errno : 0, client->getClientId(), ERRMSG_FOOTER);
|
||||||
client->disconnected();
|
client->disconnected();
|
||||||
client->getNetwork()->disconnect();
|
client->getNetwork()->disconnect();
|
||||||
@@ -151,7 +202,7 @@ void BrokerSendTask::run()
|
|||||||
*/
|
*/
|
||||||
void BrokerSendTask::log(Client* client, MQTTGWPacket* packet)
|
void BrokerSendTask::log(Client* client, MQTTGWPacket* packet)
|
||||||
{
|
{
|
||||||
char pbuf[(SIZEOF_LOG_PACKET + 5 )* 3];
|
char pbuf[(SIZE_OF_LOG_PACKET + 5 )* 3];
|
||||||
char msgId[6];
|
char msgId[6];
|
||||||
|
|
||||||
switch (packet->getType())
|
switch (packet->getType())
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
namespace MQTTSNGW
|
namespace MQTTSNGW
|
||||||
{
|
{
|
||||||
#define ERRNO_APL_04 14 // Task Initialize Error
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
Class BrokerSendTask
|
Class BrokerSendTask
|
||||||
=====================================*/
|
=====================================*/
|
||||||
@@ -39,8 +38,11 @@ private:
|
|||||||
|
|
||||||
Gateway* _gateway;
|
Gateway* _gateway;
|
||||||
char* _host;
|
char* _host;
|
||||||
char* _service;
|
char* _port;
|
||||||
char* _serviceSecure;
|
char* _portSecure;
|
||||||
|
char* _rootCApath;
|
||||||
|
char* _rootCAfile;
|
||||||
|
char* _certDirectory;
|
||||||
LightIndicator* _light;
|
LightIndicator* _light;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* anonimous clients */
|
/* anonimous clients */
|
||||||
if ( _clientCnt > DEFAULT_MAX_CLIENTS )
|
if ( _clientCnt > MAX_CLIENTS )
|
||||||
{
|
{
|
||||||
return 0; // full of clients
|
return 0; // full of clients
|
||||||
}
|
}
|
||||||
@@ -951,14 +951,7 @@ TopicIdMapelement::~TopicIdMapelement()
|
|||||||
|
|
||||||
TopicIdMap::TopicIdMap()
|
TopicIdMap::TopicIdMap()
|
||||||
{
|
{
|
||||||
char param[MQTTSNGW_PARAM_MAX];
|
_maxInflight = MAX_INFLIGHTMESSAGES;
|
||||||
|
|
||||||
_maxInflight = DEFAULT_INFLIGHTMESSAGE;
|
|
||||||
if ( theProcess->getParam("MaxInflightMsg", param) == 0 )
|
|
||||||
{
|
|
||||||
_maxInflight = atoi(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
_msgIds = 0;
|
_msgIds = 0;
|
||||||
_first = 0;
|
_first = 0;
|
||||||
_end = 0;
|
_end = 0;
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ private:
|
|||||||
uint8_t _snMsgId;
|
uint8_t _snMsgId;
|
||||||
|
|
||||||
Network* _network; // Broker
|
Network* _network; // Broker
|
||||||
bool _secureNetwork; // SSL
|
bool _secureNetwork; // SSL
|
||||||
bool _sensorNetype; // false: unstable network like a G3
|
bool _sensorNetype; // false: unstable network like a G3
|
||||||
SensorNetAddress _sensorNetAddr;
|
SensorNetAddress _sensorNetAddr;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "MQTTSNGWClientRecvTask.h"
|
#include "MQTTSNGWClientRecvTask.h"
|
||||||
#include "MQTTSNGateway.h"
|
#include "MQTTSNGateway.h"
|
||||||
|
#include <string.h>
|
||||||
char* currentDateTime(void);
|
char* currentDateTime(void);
|
||||||
/*=====================================
|
/*=====================================
|
||||||
Class ClientRecvTask
|
Class ClientRecvTask
|
||||||
@@ -76,7 +77,10 @@ void ClientRecvTask::run()
|
|||||||
log(0, packet);
|
log(0, packet);
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setBrodcastEvent(packet);
|
ev->setBrodcastEvent(packet);
|
||||||
_gateway->getPacketEventQue()->post(ev);
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
|
{
|
||||||
|
delete ev;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +93,10 @@ void ClientRecvTask::run()
|
|||||||
log(client, packet);
|
log(client, packet);
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setClientRecvEvent(client,packet);
|
ev->setClientRecvEvent(client,packet);
|
||||||
_gateway->getPacketEventQue()->post(ev);
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
|
{
|
||||||
|
delete ev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -101,7 +108,7 @@ void ClientRecvTask::run()
|
|||||||
packet->getCONNECT(&data);
|
packet->getCONNECT(&data);
|
||||||
|
|
||||||
/* create a client */
|
/* create a client */
|
||||||
client = _gateway->getClientList()->createClient(_sensorNetwork->getSenderAddress(), &data.clientID, false, _gateway->getGWParams()->secureConnection);
|
client = _gateway->getClientList()->createClient(_sensorNetwork->getSenderAddress(), &data.clientID, false, false); //_gateway->getGWParams()->secureConnection);
|
||||||
|
|
||||||
if (!client)
|
if (!client)
|
||||||
{
|
{
|
||||||
@@ -116,7 +123,10 @@ void ClientRecvTask::run()
|
|||||||
client->setClientAddress(_sensorNetwork->getSenderAddress());
|
client->setClientAddress(_sensorNetwork->getSenderAddress());
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setClientRecvEvent(client, packet);
|
ev->setClientRecvEvent(client, packet);
|
||||||
_gateway->getPacketEventQue()->post(ev);
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
|
{
|
||||||
|
delete ev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -130,7 +140,7 @@ void ClientRecvTask::run()
|
|||||||
|
|
||||||
void ClientRecvTask::log(Client* client, MQTTSNPacket* packet)
|
void ClientRecvTask::log(Client* client, MQTTSNPacket* packet)
|
||||||
{
|
{
|
||||||
char pbuf[SIZEOF_LOG_PACKET * 3];
|
char pbuf[SIZE_OF_LOG_PACKET * 3];
|
||||||
char msgId[6];
|
char msgId[6];
|
||||||
const char* clientId = client ? (const char*)client->getClientId() :"Non Active Client !" ;
|
const char* clientId = client ? (const char*)client->getClientId() :"Non Active Client !" ;
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ void ClientSendTask::run()
|
|||||||
|
|
||||||
void ClientSendTask::log(Client* client, MQTTSNPacket* packet)
|
void ClientSendTask::log(Client* client, MQTTSNPacket* packet)
|
||||||
{
|
{
|
||||||
char pbuf[SIZEOF_LOG_PACKET * 3];
|
char pbuf[SIZE_OF_LOG_PACKET * 3];
|
||||||
char msgId[6];
|
char msgId[6];
|
||||||
|
|
||||||
switch (packet->getType())
|
switch (packet->getType())
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "MQTTSNGateway.h"
|
#include "MQTTSNGateway.h"
|
||||||
#include "MQTTSNGWPacket.h"
|
#include "MQTTSNGWPacket.h"
|
||||||
#include "MQTTGWPacket.h"
|
#include "MQTTGWPacket.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace MQTTSNGW;
|
using namespace MQTTSNGW;
|
||||||
@@ -54,7 +55,7 @@ void MQTTSNConnectionHandler::handleSearchgw(MQTTSNPacket* packet)
|
|||||||
{
|
{
|
||||||
if (packet->getType() == MQTTSN_SEARCHGW)
|
if (packet->getType() == MQTTSN_SEARCHGW)
|
||||||
{
|
{
|
||||||
if (_gateway->getClientList()->getClientCount() < DEFAULT_MAX_CLIENTS)
|
if (_gateway->getClientList()->getClientCount() < MAX_CLIENTS)
|
||||||
{
|
{
|
||||||
MQTTSNPacket* gwinfo = new MQTTSNPacket();
|
MQTTSNPacket* gwinfo = new MQTTSNPacket();
|
||||||
gwinfo->setGWINFO(_gateway->getGWParams()->gatewayId);
|
gwinfo->setGWINFO(_gateway->getGWParams()->gatewayId);
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ namespace MQTTSNGW
|
|||||||
//#define DEBUG_NWSTACK // print out SensorNetwork log
|
//#define DEBUG_NWSTACK // print out SensorNetwork log
|
||||||
|
|
||||||
/*=================================
|
/*=================================
|
||||||
* Parametrs
|
* MQTT-SN Parametrs
|
||||||
==================================*/
|
==================================*/
|
||||||
|
#define MAX_CLIENTS (100) // Number of Clients can be handled.
|
||||||
#define MAX_CLIENTID_LENGTH (64) // Max length of clientID
|
#define MAX_CLIENTID_LENGTH (64) // Max length of clientID
|
||||||
|
#define MAX_INFLIGHTMESSAGES (10) // Number of inflight messages
|
||||||
#define MQTTSNGW_MAX_PACKET_SIZE (1024) // Max Packet size (5+2+TopicLen+PayloadLen)
|
#define MQTTSNGW_MAX_PACKET_SIZE (1024) // Max Packet size (5+2+TopicLen+PayloadLen)
|
||||||
#define SIZEOF_LOG_PACKET (500) // Length of the packet log in bytes
|
#define SIZE_OF_LOG_PACKET (500) // Length of the packet log in bytes
|
||||||
|
|
||||||
#define MQTTSNGW_TLS_CA_DIR "/etc/ssl/certs"
|
|
||||||
|
|
||||||
/*=================================
|
/*=================================
|
||||||
* Data Type
|
* Data Type
|
||||||
|
|||||||
@@ -354,7 +354,7 @@ char* MQTTSNPacket::print(char* pbuf)
|
|||||||
int value = 0;
|
int value = 0;
|
||||||
|
|
||||||
int i = MQTTSNPacket_decode(_buf, _bufLen, &value);
|
int i = MQTTSNPacket_decode(_buf, _bufLen, &value);
|
||||||
int size = _bufLen > SIZEOF_LOG_PACKET ? SIZEOF_LOG_PACKET : _bufLen;
|
int size = _bufLen > SIZE_OF_LOG_PACKET ? SIZE_OF_LOG_PACKET : _bufLen;
|
||||||
|
|
||||||
for (; i < size; i++)
|
for (; i < size; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "MQTTSNGWConnectionHandler.h"
|
#include "MQTTSNGWConnectionHandler.h"
|
||||||
#include "MQTTSNGWPublishHandler.h"
|
#include "MQTTSNGWPublishHandler.h"
|
||||||
#include "MQTTSNGWSubscribeHandler.h"
|
#include "MQTTSNGWSubscribeHandler.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace MQTTSNGW;
|
using namespace MQTTSNGW;
|
||||||
|
|||||||
@@ -91,12 +91,12 @@ void Process::initialize(int argc, char** argv)
|
|||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
if ( (pos = config.find_last_of("/")) == string::npos )
|
if ( (pos = config.find_last_of("/")) == string::npos )
|
||||||
{
|
{
|
||||||
_configFile = config;
|
_configFile = optarg;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_configFile = config.substr(pos + 1, config.size() - pos - 1);;
|
||||||
_configDir = config.substr(0, pos + 1);
|
_configDir = config.substr(0, pos + 1);
|
||||||
_configFile = config.substr(pos + 1, config.size() - pos - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,11 +121,11 @@ int Process::getParam(const char* parameter, char* value)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
string config = _configDir + _configFile;
|
string configPath = _configDir + _configFile;
|
||||||
|
|
||||||
if ((fp = fopen(config.c_str(), "r")) == NULL)
|
if ((fp = fopen(configPath.c_str(), "r")) == NULL)
|
||||||
{
|
{
|
||||||
WRITELOG("No config file:[%s]\n", config.c_str());
|
WRITELOG("No config file:[%s]\n", configPath.c_str());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,13 +232,7 @@ MultiTaskProcess::MultiTaskProcess()
|
|||||||
|
|
||||||
MultiTaskProcess::~MultiTaskProcess()
|
MultiTaskProcess::~MultiTaskProcess()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _threadCount; i++)
|
|
||||||
{
|
|
||||||
if ( _threadList[i] )
|
|
||||||
{
|
|
||||||
delete _threadList[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiTaskProcess::initialize(int argc, char** argv)
|
void MultiTaskProcess::initialize(int argc, char** argv)
|
||||||
@@ -264,6 +258,13 @@ void MultiTaskProcess::run(void)
|
|||||||
}
|
}
|
||||||
catch (Exception* ex)
|
catch (Exception* ex)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < _threadCount; i++)
|
||||||
|
{
|
||||||
|
if ( _threadList[i] )
|
||||||
|
{
|
||||||
|
_threadList[i]->cancel();;
|
||||||
|
}
|
||||||
|
}
|
||||||
ex->writeMessage();
|
ex->writeMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -363,7 +364,7 @@ void Exception::writeMessage()
|
|||||||
{
|
{
|
||||||
if (getExceptionNo() == 0 )
|
if (getExceptionNo() == 0 )
|
||||||
{
|
{
|
||||||
WRITELOG("%s : %s\n", currentDateTime(), what());
|
WRITELOG("%s %s\n", currentDateTime(), what());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <signal.h>
|
||||||
#include "MQTTSNGWDefines.h"
|
#include "MQTTSNGWDefines.h"
|
||||||
#include "Threading.h"
|
#include "Threading.h"
|
||||||
|
|
||||||
@@ -71,8 +72,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
int _argc;
|
int _argc;
|
||||||
char** _argv;
|
char** _argv;
|
||||||
string _configDir;
|
string _configDir;
|
||||||
string _configFile;
|
string _configFile;
|
||||||
RingBuffer* _rb;
|
RingBuffer* _rb;
|
||||||
Semaphore* _rbsem;
|
Semaphore* _rbsem;
|
||||||
Mutex _mt;
|
Mutex _mt;
|
||||||
@@ -164,6 +165,7 @@ public:
|
|||||||
_head = 0;
|
_head = 0;
|
||||||
_tail = 0;
|
_tail = 0;
|
||||||
_cnt = 0;
|
_cnt = 0;
|
||||||
|
_maxSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Que()
|
~Que()
|
||||||
@@ -213,28 +215,33 @@ public:
|
|||||||
|
|
||||||
int post(T* t)
|
int post(T* t)
|
||||||
{
|
{
|
||||||
QueElement<T>* elm = new QueElement<T>(t);
|
if ( t && ( _maxSize == 0 || size() < _maxSize ))
|
||||||
if ( _head )
|
|
||||||
{
|
{
|
||||||
if ( _tail == _head )
|
QueElement<T>* elm = new QueElement<T>(t);
|
||||||
|
if ( _head )
|
||||||
{
|
{
|
||||||
|
if ( _tail == _head )
|
||||||
|
{
|
||||||
|
elm->_prev = _tail;
|
||||||
|
_tail = elm;
|
||||||
|
_head->_next = elm;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_tail->_next = elm;
|
||||||
elm->_prev = _tail;
|
elm->_prev = _tail;
|
||||||
_tail = elm;
|
_tail = elm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_tail->_next = elm;
|
_head = elm;
|
||||||
elm->_prev = _tail;
|
_tail = elm;
|
||||||
_tail = elm;
|
|
||||||
}
|
}
|
||||||
|
_cnt++;
|
||||||
|
return _cnt;
|
||||||
}
|
}
|
||||||
else
|
return 0;
|
||||||
{
|
|
||||||
_head = elm;
|
|
||||||
_tail = elm;
|
|
||||||
}
|
|
||||||
_cnt++;
|
|
||||||
return _cnt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int size(void)
|
int size(void)
|
||||||
@@ -242,8 +249,14 @@ public:
|
|||||||
return _cnt;
|
return _cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setMaxSize(int maxSize)
|
||||||
|
{
|
||||||
|
_maxSize = maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _cnt;
|
int _cnt;
|
||||||
|
int _maxSize;
|
||||||
QueElement<T>* _head;
|
QueElement<T>* _head;
|
||||||
QueElement<T>* _tail;
|
QueElement<T>* _tail;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include "MQTTGWPacket.h"
|
#include "MQTTGWPacket.h"
|
||||||
#include "MQTTSNGateway.h"
|
#include "MQTTSNGateway.h"
|
||||||
#include "MQTTSNGWClient.h"
|
#include "MQTTSNGWClient.h"
|
||||||
|
#include <string.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace MQTTSNGW;
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
**************************************************************************************/
|
**************************************************************************************/
|
||||||
|
|
||||||
#include "MQTTSNGateway.h"
|
#include "MQTTSNGateway.h"
|
||||||
#include "MQTTSNGWProcess.h"
|
|
||||||
#include "SensorNetwork.h"
|
#include "SensorNetwork.h"
|
||||||
|
#include "MQTTSNGWProcess.h"
|
||||||
|
#include <string.h>
|
||||||
using namespace MQTTSNGW;
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
char* currentDateTime(void);
|
char* currentDateTime(void);
|
||||||
@@ -31,6 +31,7 @@ Gateway::Gateway()
|
|||||||
theProcess = this;
|
theProcess = this;
|
||||||
_params.loginId = 0;
|
_params.loginId = 0;
|
||||||
_params.password = 0;
|
_params.password = 0;
|
||||||
|
_packetEventQue.setMaxSize(MAX_INFLIGHTMESSAGES * MAX_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gateway::~Gateway()
|
Gateway::~Gateway()
|
||||||
@@ -106,7 +107,7 @@ void Gateway::initialize(int argc, char** argv)
|
|||||||
string fileName;
|
string fileName;
|
||||||
if (!strcasecmp(param, "YES"))
|
if (!strcasecmp(param, "YES"))
|
||||||
{
|
{
|
||||||
if (getParam("ClientList", param) == 0)
|
if (getParam("ClientsList", param) == 0)
|
||||||
{
|
{
|
||||||
fileName = string(param);
|
fileName = string(param);
|
||||||
}
|
}
|
||||||
@@ -117,20 +118,10 @@ void Gateway::initialize(int argc, char** argv)
|
|||||||
|
|
||||||
if (!_clientList.authorize(fileName.c_str()))
|
if (!_clientList.authorize(fileName.c_str()))
|
||||||
{
|
{
|
||||||
throw Exception("Gateway::initialize: No client list which defined by configuration.");
|
throw Exception("Gateway::initialize: No client list defined by configuration.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getParam("SecureConnection", param) == 0)
|
|
||||||
{
|
|
||||||
_params.secureConnection = !strcasecmp(param, "YES");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_params.secureConnection = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gateway::run(void)
|
void Gateway::run(void)
|
||||||
@@ -205,6 +196,11 @@ EventQue::~EventQue()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventQue::setMaxSize(uint16_t maxSize)
|
||||||
|
{
|
||||||
|
_que.setMaxSize((int)maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
Event* EventQue::wait(void)
|
Event* EventQue::wait(void)
|
||||||
{
|
{
|
||||||
Event* ev;
|
Event* ev;
|
||||||
@@ -249,14 +245,12 @@ Event* EventQue::timedwait(uint16_t millsec)
|
|||||||
|
|
||||||
int EventQue::post(Event* ev)
|
int EventQue::post(Event* ev)
|
||||||
{
|
{
|
||||||
if ( ev )
|
int rc = 0;
|
||||||
{
|
_mutex.lock();
|
||||||
_mutex.lock();
|
rc = _que.post(ev);
|
||||||
_que.post(ev);
|
_sem.post();
|
||||||
_sem.post();
|
_mutex.unlock();
|
||||||
_mutex.unlock();
|
return rc;
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int EventQue::size()
|
int EventQue::size()
|
||||||
|
|||||||
@@ -16,10 +16,9 @@
|
|||||||
#ifndef MQTTSNGATEWAY_H_
|
#ifndef MQTTSNGATEWAY_H_
|
||||||
#define MQTTSNGATEWAY_H_
|
#define MQTTSNGATEWAY_H_
|
||||||
|
|
||||||
#include "MQTTSNGWProcess.h"
|
|
||||||
#include "MQTTSNGWClient.h"
|
#include "MQTTSNGWClient.h"
|
||||||
|
#include "MQTTSNGWProcess.h"
|
||||||
#include "MQTTSNPacket.h"
|
#include "MQTTSNPacket.h"
|
||||||
#include "MQTTGWPacket.h"
|
|
||||||
|
|
||||||
namespace MQTTSNGW
|
namespace MQTTSNGW
|
||||||
{
|
{
|
||||||
@@ -27,14 +26,12 @@ namespace MQTTSNGW
|
|||||||
* Gateway default parameters
|
* Gateway default parameters
|
||||||
===========================================================*/
|
===========================================================*/
|
||||||
#define DEFAULT_KEEP_ALIVE_TIME (900) // 900 secs = 15 mins
|
#define DEFAULT_KEEP_ALIVE_TIME (900) // 900 secs = 15 mins
|
||||||
#define DEFAULT_MAX_CLIENTS (100) // Number of Clients can be handled.
|
|
||||||
#define DEFAULT_MQTT_VERSION (4) // Defualt MQTT version
|
#define DEFAULT_MQTT_VERSION (4) // Defualt MQTT version
|
||||||
#define DEFAULT_INFLIGHTMESSAGE (10) // Number of inflight messages
|
|
||||||
|
|
||||||
/*=================================
|
/*=================================
|
||||||
* Starting prompt
|
* Starting prompt
|
||||||
==================================*/
|
==================================*/
|
||||||
#define GATEWAY_VERSION " * Version: 0.3.3"
|
#define GATEWAY_VERSION " * Version: 0.6.0"
|
||||||
|
|
||||||
#define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway"
|
#define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway"
|
||||||
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"
|
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"
|
||||||
@@ -133,6 +130,7 @@ public:
|
|||||||
~EventQue();
|
~EventQue();
|
||||||
Event* wait(void);
|
Event* wait(void);
|
||||||
Event* timedwait(uint16_t millsec);
|
Event* timedwait(uint16_t millsec);
|
||||||
|
void setMaxSize(uint16_t maxSize);
|
||||||
int post(Event*);
|
int post(Event*);
|
||||||
int size();
|
int size();
|
||||||
|
|
||||||
@@ -154,7 +152,6 @@ typedef struct
|
|||||||
uint8_t mqttVersion;
|
uint8_t mqttVersion;
|
||||||
uint16_t maxInflightMsgs;
|
uint16_t maxInflightMsgs;
|
||||||
uint8_t* gatewayName;
|
uint8_t* gatewayName;
|
||||||
bool secureConnection;
|
|
||||||
}GatewayParams;
|
}GatewayParams;
|
||||||
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
#include "MQTTSNGWDefines.h"
|
#include "MQTTSNGWDefines.h"
|
||||||
@@ -232,54 +233,27 @@ int TCPStack::getSock()
|
|||||||
=======================================*/
|
=======================================*/
|
||||||
int Network::_numOfInstance = 0;
|
int Network::_numOfInstance = 0;
|
||||||
SSL_CTX* Network::_ctx = 0;
|
SSL_CTX* Network::_ctx = 0;
|
||||||
SSL_SESSION* Network::_session = 0;
|
|
||||||
|
|
||||||
Network::Network(bool secure) :
|
Network::Network(bool secure) :
|
||||||
TCPStack()
|
TCPStack()
|
||||||
{
|
{
|
||||||
char error[256];
|
|
||||||
if (secure)
|
|
||||||
{
|
|
||||||
_numOfInstance++;
|
|
||||||
if (_ctx == 0)
|
|
||||||
{
|
|
||||||
SSL_load_error_strings();
|
|
||||||
SSL_library_init();
|
|
||||||
_ctx = SSL_CTX_new(TLSv1_2_client_method());
|
|
||||||
if (_ctx == 0)
|
|
||||||
{
|
|
||||||
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
|
|
||||||
WRITELOG("SSL_CTX_new() %s\n", error);
|
|
||||||
throw Exception( ERR_get_error(), "Network can't create SSL context.");
|
|
||||||
}
|
|
||||||
if (!SSL_CTX_load_verify_locations(_ctx, 0, MQTTSNGW_TLS_CA_DIR))
|
|
||||||
{
|
|
||||||
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
|
|
||||||
WRITELOG("SSL_CTX_load_verify_locations() %s\n", error);
|
|
||||||
throw Exception( ERR_get_error(), "Network can't load CA_LIST.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ssl = 0;
|
_ssl = 0;
|
||||||
_disconReq = false;
|
|
||||||
_secureFlg = secure;
|
_secureFlg = secure;
|
||||||
_busy = false;
|
_busy = false;
|
||||||
|
_session = 0;
|
||||||
|
_sslValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Network::~Network()
|
Network::~Network()
|
||||||
{
|
{
|
||||||
if (_secureFlg)
|
|
||||||
{
|
|
||||||
_numOfInstance--;
|
|
||||||
}
|
|
||||||
if (_ssl)
|
if (_ssl)
|
||||||
{
|
{
|
||||||
SSL_free(_ssl);
|
SSL_free(_ssl);
|
||||||
|
_numOfInstance--;
|
||||||
}
|
}
|
||||||
if (_session && _numOfInstance == 0)
|
if (_session )
|
||||||
{
|
{
|
||||||
SSL_SESSION_free(_session);
|
SSL_SESSION_free(_session);
|
||||||
_session = 0;
|
|
||||||
}
|
}
|
||||||
if (_ctx && _numOfInstance == 0)
|
if (_ctx && _numOfInstance == 0)
|
||||||
{
|
{
|
||||||
@@ -289,78 +263,172 @@ Network::~Network()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Network::connect(const char* host, const char* service)
|
bool Network::connect(const char* host, const char* port)
|
||||||
|
{
|
||||||
|
if (_secureFlg)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getSock() == 0)
|
||||||
|
{
|
||||||
|
if (!TCPStack::connect(host, port))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Network::connect(const char* host, const char* port, const char* caPath, const char* caFile, const char* cert, const char* prvkey)
|
||||||
{
|
{
|
||||||
char errmsg[256];
|
char errmsg[256];
|
||||||
int rc = 0;
|
|
||||||
char peer_CN[256];
|
char peer_CN[256];
|
||||||
SSL_SESSION* sess = 0;
|
int rc = 0;
|
||||||
X509* peer;
|
|
||||||
|
|
||||||
if (isValid())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!TCPStack::connect(host, service))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!_secureFlg)
|
if (!_secureFlg)
|
||||||
{
|
{
|
||||||
return true;
|
WRITELOG("TLS is not required.\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL* ssl = SSL_new(_ctx);
|
if (_ctx == 0)
|
||||||
if (ssl == 0)
|
{
|
||||||
|
SSL_load_error_strings();
|
||||||
|
SSL_library_init();
|
||||||
|
_ctx = SSL_CTX_new(TLS_client_method());
|
||||||
|
if (_ctx == 0)
|
||||||
|
{
|
||||||
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("SSL_CTX_new() %s\n", errmsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SSL_CTX_load_verify_locations(_ctx, caFile, caPath))
|
||||||
|
{
|
||||||
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("SSL_CTX_load_verify_locations() %s\n", errmsg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_sslValid)
|
||||||
|
{
|
||||||
|
if ( !TCPStack::connect(host, port) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if ( _ssl )
|
||||||
|
{
|
||||||
|
if (!SSL_set_fd(_ssl, getSock()))
|
||||||
|
{
|
||||||
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("SSL_set_fd() %s\n", errmsg);
|
||||||
|
SSL_free(_ssl);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_sslValid = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
_ssl = SSL_new(_ctx);
|
||||||
|
if (_ssl == 0)
|
||||||
{
|
{
|
||||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
WRITELOG("SSL_new() %s\n", errmsg);
|
WRITELOG("SSL_new() %s\n", errmsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = SSL_set_fd(ssl, TCPStack::getSock());
|
if (!SSL_set_fd(_ssl, getSock()))
|
||||||
if (rc == 0)
|
|
||||||
{
|
{
|
||||||
SSL_free(ssl);
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("SSL_set_fd() %s\n", errmsg);
|
||||||
|
SSL_free(_ssl);
|
||||||
|
}
|
||||||
|
|
||||||
|
SSL_set_options(_ssl, SSL_OP_NO_TICKET);
|
||||||
|
|
||||||
|
if ( cert )
|
||||||
|
{
|
||||||
|
if ( SSL_use_certificate_file(_ssl, cert, SSL_FILETYPE_PEM) <= 0 )
|
||||||
|
{
|
||||||
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("SSL_use_certificate_file() %s %s\n", cert, errmsg);
|
||||||
|
SSL_free(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( prvkey )
|
||||||
|
{
|
||||||
|
if ( SSL_use_PrivateKey_file(_ssl, prvkey, SSL_FILETYPE_PEM) <= 0 )
|
||||||
|
{
|
||||||
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("SSL_use_PrivateKey_file() %s %s\n", prvkey, errmsg);
|
||||||
|
SSL_free(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SSL_set_fd(_ssl, TCPStack::getSock()))
|
||||||
|
{
|
||||||
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("SSL_set_fd() %s\n", errmsg);
|
||||||
|
SSL_free(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_session)
|
if (_session)
|
||||||
{
|
{
|
||||||
rc = SSL_set_session(ssl, sess);
|
rc = SSL_set_session(_ssl, _session);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (SSL_connect(_ssl) != 1)
|
||||||
rc = SSL_connect(ssl);
|
|
||||||
}
|
|
||||||
if (rc != 1)
|
|
||||||
{
|
{
|
||||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
WRITELOG("SSL_connect() %s\n", errmsg);
|
WRITELOG("SSL_connect() %s\n", errmsg);
|
||||||
SSL_free(ssl);
|
SSL_free(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SSL_get_verify_result(ssl) != X509_V_OK)
|
if ( (rc = SSL_get_verify_result(_ssl)) != X509_V_OK)
|
||||||
{
|
{
|
||||||
WRITELOG("SSL_get_verify_result() error: Certificate doesn't verify.\n");
|
WRITELOG("SSL_get_verify_result() error: %s.\n", X509_verify_cert_error_string(rc));
|
||||||
SSL_free(ssl);
|
SSL_free(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
peer = SSL_get_peer_certificate(ssl);
|
X509* peer = SSL_get_peer_certificate(_ssl);
|
||||||
X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, peer_CN, 256);
|
X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, peer_CN, 256);
|
||||||
if (strcasecmp(peer_CN, host))
|
char* pos = peer_CN;
|
||||||
|
if ( *pos == '*')
|
||||||
{
|
{
|
||||||
WRITELOG("SSL_get_peer_certificate() error: Broker dosen't much host name.\n");
|
while (*host++ != '.');
|
||||||
SSL_free(ssl);
|
pos += 2;
|
||||||
|
}
|
||||||
|
if ( strcmp(host, pos))
|
||||||
|
{
|
||||||
|
WRITELOG("SSL_get_peer_certificate() error: Broker %s dosen't match the host name %s\n", peer_CN, host);
|
||||||
|
SSL_free(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_session == 0)
|
if (_session == 0)
|
||||||
{
|
{
|
||||||
_session = sess;
|
_session = SSL_get1_session(_ssl);
|
||||||
}
|
}
|
||||||
_ssl = ssl;
|
_numOfInstance++;
|
||||||
|
_sslValid = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +440,11 @@ int Network::send(const uint8_t* buf, uint16_t length)
|
|||||||
bool writeBlockedOnRead = false;
|
bool writeBlockedOnRead = false;
|
||||||
int bpos = 0;
|
int bpos = 0;
|
||||||
|
|
||||||
if (_secureFlg)
|
if (!_secureFlg)
|
||||||
|
{
|
||||||
|
return TCPStack::send(buf, length);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
_busy = true;
|
_busy = true;
|
||||||
@@ -387,7 +459,7 @@ int Network::send(const uint8_t* buf, uint16_t length)
|
|||||||
int activity = select(getSock() + 1, &rset, &wset, 0, 0);
|
int activity = select(getSock() + 1, &rset, &wset, 0, 0);
|
||||||
if (activity > 0)
|
if (activity > 0)
|
||||||
{
|
{
|
||||||
if (FD_ISSET(getSock(), &wset) || (writeBlockedOnRead && FD_ISSET(getSock(), &rset)))
|
if (FD_ISSET(getSock(), &wset) || (writeBlockedOnRead && FD_ISSET(getSock(), &rset)))
|
||||||
{
|
{
|
||||||
|
|
||||||
writeBlockedOnRead = false;
|
writeBlockedOnRead = false;
|
||||||
@@ -421,10 +493,6 @@ int Network::send(const uint8_t* buf, uint16_t length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return TCPStack::send(buf, length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Network::recv(uint8_t* buf, uint16_t len)
|
int Network::recv(uint8_t* buf, uint16_t len)
|
||||||
@@ -438,92 +506,107 @@ int Network::recv(uint8_t* buf, uint16_t len)
|
|||||||
fd_set rset;
|
fd_set rset;
|
||||||
fd_set wset;
|
fd_set wset;
|
||||||
|
|
||||||
if (_secureFlg)
|
if (!_secureFlg)
|
||||||
{
|
{
|
||||||
if (_busy)
|
return TCPStack::recv(buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_busy)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
_mutex.lock();
|
||||||
|
_busy = true;
|
||||||
|
|
||||||
|
loop: do
|
||||||
|
{
|
||||||
|
readBlockedOnWrite = false;
|
||||||
|
readBlocked = false;
|
||||||
|
|
||||||
|
rlen = SSL_read(_ssl, buf + bpos, len - bpos);
|
||||||
|
|
||||||
|
switch (SSL_get_error(_ssl, rlen))
|
||||||
{
|
{
|
||||||
return 0;
|
case SSL_ERROR_NONE:
|
||||||
|
_busy = false;
|
||||||
|
_mutex.unlock();
|
||||||
|
return rlen + bpos;
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
|
SSL_shutdown(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
|
TCPStack::close();
|
||||||
|
_busy = false;
|
||||||
|
_mutex.unlock();
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_WANT_READ:
|
||||||
|
readBlocked = true;
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_WANT_WRITE:
|
||||||
|
readBlockedOnWrite = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
|
WRITELOG("Network::recv() %s\n", errmsg);
|
||||||
|
_busy = false;
|
||||||
|
_mutex.unlock();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
_mutex.lock();
|
} while (SSL_pending(_ssl) && !readBlocked);
|
||||||
_busy = true;
|
|
||||||
|
|
||||||
loop: do
|
bpos += rlen;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
FD_ZERO(&rset);
|
||||||
|
FD_ZERO(&wset);
|
||||||
|
FD_SET(getSock(), &rset);
|
||||||
|
FD_SET(getSock(), &wset);
|
||||||
|
|
||||||
|
int activity = select(getSock() + 1, &rset, &wset, 0, 0);
|
||||||
|
if (activity > 0)
|
||||||
{
|
{
|
||||||
readBlockedOnWrite = false;
|
if ((FD_ISSET(getSock(),&rset) && !writeBlockedOnRead)
|
||||||
readBlocked = false;
|
|| (readBlockedOnWrite && FD_ISSET(getSock(), &wset)))
|
||||||
|
|
||||||
rlen = SSL_read(_ssl, buf + bpos, len - bpos);
|
|
||||||
|
|
||||||
switch (SSL_get_error(_ssl, rlen))
|
|
||||||
{
|
{
|
||||||
case SSL_ERROR_NONE:
|
goto loop;
|
||||||
_busy = false;
|
|
||||||
_mutex.unlock();
|
|
||||||
return rlen + bpos;
|
|
||||||
break;
|
|
||||||
case SSL_ERROR_ZERO_RETURN:
|
|
||||||
SSL_shutdown(_ssl);
|
|
||||||
_ssl = 0;
|
|
||||||
TCPStack::close();
|
|
||||||
_busy = false;
|
|
||||||
_mutex.unlock();
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case SSL_ERROR_WANT_READ:
|
|
||||||
readBlocked = true;
|
|
||||||
break;
|
|
||||||
case SSL_ERROR_WANT_WRITE:
|
|
||||||
readBlockedOnWrite = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
|
||||||
WRITELOG("TLSStack::recv() default %s\n", errmsg);
|
|
||||||
_busy = false;
|
|
||||||
_mutex.unlock();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
} while (SSL_pending(_ssl) && !readBlocked);
|
}
|
||||||
|
else
|
||||||
bpos += rlen;
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
FD_ZERO(&rset);
|
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
||||||
FD_ZERO(&wset);
|
WRITELOG("TLSStack::recv() select %s\n", errmsg);
|
||||||
FD_SET(getSock(), &rset);
|
_busy = false;
|
||||||
FD_SET(getSock(), &wset);
|
_mutex.unlock();
|
||||||
|
return -1;
|
||||||
int activity = select(getSock() + 1, &rset, &wset, 0, 0);
|
|
||||||
if (activity > 0)
|
|
||||||
{
|
|
||||||
if ((FD_ISSET(getSock(),&rset) && !writeBlockedOnRead)
|
|
||||||
|| (readBlockedOnWrite && FD_ISSET(getSock(), &wset)))
|
|
||||||
{
|
|
||||||
goto loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg));
|
|
||||||
WRITELOG("TLSStack::recv() select %s\n", errmsg);
|
|
||||||
_busy = false;
|
|
||||||
_mutex.unlock();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TCPStack::recv(buf, len);
|
}
|
||||||
|
|
||||||
|
void Network::close(void)
|
||||||
|
{
|
||||||
|
if (_secureFlg)
|
||||||
|
{
|
||||||
|
_sslValid = false;
|
||||||
|
SSL_free(_ssl);
|
||||||
|
_ssl = 0;
|
||||||
|
}
|
||||||
|
TCPStack::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Network::isValid()
|
bool Network::isValid()
|
||||||
{
|
{
|
||||||
if (!_secureFlg)
|
if (_secureFlg)
|
||||||
|
{
|
||||||
|
if (_sslValid && !_busy)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return TCPStack::isValid();
|
return TCPStack::isValid();
|
||||||
}
|
}
|
||||||
if (_ssl)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,12 +616,11 @@ void Network::disconnect()
|
|||||||
{
|
{
|
||||||
SSL_shutdown(_ssl);
|
SSL_shutdown(_ssl);
|
||||||
_ssl = 0;
|
_ssl = 0;
|
||||||
TCPStack::close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TCPStack::close();
|
|
||||||
}
|
}
|
||||||
|
_sslValid = false;
|
||||||
|
_busy = false;
|
||||||
|
TCPStack::close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Network::getSock()
|
int Network::getSock()
|
||||||
@@ -546,18 +628,6 @@ int Network::getSock()
|
|||||||
return TCPStack::getSock();
|
return TCPStack::getSock();
|
||||||
}
|
}
|
||||||
|
|
||||||
SSL* Network::getSSL()
|
|
||||||
{
|
|
||||||
if (_secureFlg)
|
|
||||||
{
|
|
||||||
return _ssl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Network::isSecure()
|
bool Network::isSecure()
|
||||||
{
|
{
|
||||||
return _secureFlg;
|
return _secureFlg;
|
||||||
|
|||||||
@@ -71,26 +71,27 @@ public:
|
|||||||
Network(bool secure);
|
Network(bool secure);
|
||||||
virtual ~Network();
|
virtual ~Network();
|
||||||
|
|
||||||
bool connect(const char* host, const char* service);
|
bool connect(const char* host, const char* port, const char* caPath, const char* caFile, const char* sert, const char* prvkey);
|
||||||
void disconnect();
|
bool connect(const char* host, const char* port);
|
||||||
int send(const uint8_t* buf, uint16_t length);
|
void disconnect(void);
|
||||||
int recv(uint8_t* buf, uint16_t len);
|
void close(void);
|
||||||
|
int send(const uint8_t* buf, uint16_t length);
|
||||||
|
int recv(uint8_t* buf, uint16_t len);
|
||||||
|
|
||||||
bool isValid();
|
bool isValid(void);
|
||||||
bool isSecure();
|
bool isSecure(void);
|
||||||
int getSock();
|
int getSock(void);
|
||||||
SSL* getSSL();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static SSL_CTX* _ctx;
|
static SSL_CTX* _ctx;
|
||||||
static int _numOfInstance;
|
static int _numOfInstance;
|
||||||
static SSL_SESSION* _session;
|
|
||||||
|
|
||||||
|
SSL_SESSION* _session;
|
||||||
SSL* _ssl;
|
SSL* _ssl;
|
||||||
bool _secureFlg;
|
bool _secureFlg;
|
||||||
bool _disconReq;
|
|
||||||
Mutex _mutex;
|
Mutex _mutex;
|
||||||
bool _busy;
|
bool _busy;
|
||||||
|
bool _sslValid;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NETWORK_H_ */
|
#endif /* NETWORK_H_ */
|
||||||
|
|||||||
@@ -502,7 +502,7 @@ bool Thread::equals(pthread_t *t1, pthread_t *t2)
|
|||||||
|
|
||||||
int Thread::start(void)
|
int Thread::start(void)
|
||||||
{
|
{
|
||||||
Runnable *runnable = this;
|
Runnable* runnable = this;
|
||||||
return pthread_create(&_threadID, 0, _run, runnable);
|
return pthread_create(&_threadID, 0, _run, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +511,7 @@ void Thread::stopProcess(void)
|
|||||||
_stopProcessEvent->post();
|
_stopProcessEvent->post();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::testThreadCancel(void)
|
void Thread::cancel(void)
|
||||||
{
|
{
|
||||||
pthread_testcancel();
|
pthread_cancel(_threadID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
#include "MQTTSNGWDefines.h"
|
||||||
|
|
||||||
namespace MQTTSNGW
|
namespace MQTTSNGW
|
||||||
{
|
{
|
||||||
@@ -131,7 +132,7 @@ public:
|
|||||||
static bool equals(pthread_t*, pthread_t*);
|
static bool equals(pthread_t*, pthread_t*);
|
||||||
virtual void initialize(int argc, char** argv);
|
virtual void initialize(int argc, char** argv);
|
||||||
void stopProcess(void);
|
void stopProcess(void);
|
||||||
void testThreadCancel(void);
|
void cancel(void);
|
||||||
private:
|
private:
|
||||||
pthread_t _threadID;
|
pthread_t _threadID;
|
||||||
Semaphore* _stopProcessEvent;
|
Semaphore* _stopProcessEvent;
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ const char* SensorNetwork::getDescription(void)
|
|||||||
return _description.c_str();
|
return _description.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SensorNetAddress* SensorNetwork::getSenderAddress(void)
|
||||||
|
{
|
||||||
|
return &_clientAddr;
|
||||||
|
}
|
||||||
|
|
||||||
/*=========================================
|
/*=========================================
|
||||||
Class udpStack
|
Class udpStack
|
||||||
=========================================*/
|
=========================================*/
|
||||||
|
|||||||
@@ -99,11 +99,7 @@ public:
|
|||||||
int read(uint8_t* buf, uint16_t bufLen);
|
int read(uint8_t* buf, uint16_t bufLen);
|
||||||
int initialize(void);
|
int initialize(void);
|
||||||
const char* getDescription(void);
|
const char* getDescription(void);
|
||||||
SensorNetAddress* getSenderAddress(void)
|
SensorNetAddress* getSenderAddress(void);
|
||||||
{
|
|
||||||
return &_clientAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SensorNetAddress _clientAddr; // Sender's address. not gateway's one.
|
SensorNetAddress _clientAddr; // Sender's address. not gateway's one.
|
||||||
|
|||||||
@@ -14,15 +14,16 @@
|
|||||||
* Tomoaki Yamaguchi - initial API and implementation
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
**************************************************************************************/
|
**************************************************************************************/
|
||||||
|
|
||||||
#include "SensorNetwork.h"
|
|
||||||
#include "MQTTSNGWProcess.h"
|
|
||||||
#include "Threading.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "SensorNetwork.h"
|
||||||
|
#include "MQTTSNGWProcess.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace MQTTSNGW;
|
using namespace MQTTSNGW;
|
||||||
@@ -32,8 +33,8 @@ using namespace MQTTSNGW;
|
|||||||
============================================*/
|
============================================*/
|
||||||
SensorNetAddress::SensorNetAddress()
|
SensorNetAddress::SensorNetAddress()
|
||||||
{
|
{
|
||||||
memset(_address64, 0, sizeof(_address64));
|
memset(_address64, 0, 8);
|
||||||
memset(_address16, 0, sizeof(_address16));
|
memset(_address16, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorNetAddress::~SensorNetAddress()
|
SensorNetAddress::~SensorNetAddress()
|
||||||
@@ -109,20 +110,40 @@ int SensorNetwork::initialize(void)
|
|||||||
{
|
{
|
||||||
char param[MQTTSNGW_PARAM_MAX];
|
char param[MQTTSNGW_PARAM_MAX];
|
||||||
uint16_t baudrate = 9600;
|
uint16_t baudrate = 9600;
|
||||||
|
uint8_t apimode = 2;
|
||||||
|
|
||||||
|
if (theProcess->getParam("ApiMode", param) == 0)
|
||||||
|
{
|
||||||
|
apimode = (uint8_t)atoi(param);
|
||||||
|
}
|
||||||
|
setApiMode(apimode);
|
||||||
|
_description = "API mode ";
|
||||||
|
sprintf(param, "%d", apimode);
|
||||||
|
_description += param;
|
||||||
|
|
||||||
if (theProcess->getParam("Baudrate", param) == 0)
|
if (theProcess->getParam("Baudrate", param) == 0)
|
||||||
{
|
{
|
||||||
baudrate = (uint16_t)atoi(param);
|
baudrate = (uint16_t)atoi(param);
|
||||||
}
|
}
|
||||||
|
_description += ", Baudrate ";
|
||||||
|
sprintf(param ,"%d", baudrate);
|
||||||
|
_description += param;
|
||||||
|
|
||||||
theProcess->getParam("SerialDevice", param);
|
theProcess->getParam("SerialDevice", param);
|
||||||
|
_description += ", SerialDevice ";
|
||||||
|
_description += param;
|
||||||
|
|
||||||
return XBee::open(param, baudrate);
|
return XBee::open(param, baudrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* SensorNetwork::getType(void)
|
const char* SensorNetwork::getDescription(void)
|
||||||
{
|
{
|
||||||
return "XBee";
|
return _description.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
SensorNetAddress* SensorNetwork::getSenderAddress(void)
|
||||||
|
{
|
||||||
|
return &_clientAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*===========================================
|
/*===========================================
|
||||||
@@ -131,8 +152,10 @@ const char* SensorNetwork::getType(void)
|
|||||||
XBee::XBee(){
|
XBee::XBee(){
|
||||||
_serialPort = new SerialPort();
|
_serialPort = new SerialPort();
|
||||||
_respCd = 0;
|
_respCd = 0;
|
||||||
|
_respId = 0;
|
||||||
_dataLen = 0;
|
_dataLen = 0;
|
||||||
_frameId = 0;
|
_frameId = 0;
|
||||||
|
_apiMode = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
XBee::~XBee(){
|
XBee::~XBee(){
|
||||||
@@ -333,7 +356,7 @@ int XBee::send(const uint8_t* payload, uint8_t pLen, SensorNetAddress* addr){
|
|||||||
|
|
||||||
void XBee::send(uint8_t c)
|
void XBee::send(uint8_t c)
|
||||||
{
|
{
|
||||||
if(c == START_BYTE || c == ESCAPE || c == XON || c == XOFF){
|
if(_apiMode == 2 && (c == START_BYTE || c == ESCAPE || c == XON || c == XOFF)){
|
||||||
_serialPort->send(ESCAPE);
|
_serialPort->send(ESCAPE);
|
||||||
_serialPort->send(c ^ 0x20);
|
_serialPort->send(c ^ 0x20);
|
||||||
}else{
|
}else{
|
||||||
@@ -345,7 +368,7 @@ int XBee::recv(uint8_t* buf)
|
|||||||
{
|
{
|
||||||
if (_serialPort->recv(buf) )
|
if (_serialPort->recv(buf) )
|
||||||
{
|
{
|
||||||
if ( *buf == ESCAPE)
|
if ( *buf == ESCAPE && _apiMode == 2 )
|
||||||
{
|
{
|
||||||
_serialPort->recv(buf);
|
_serialPort->recv(buf);
|
||||||
*buf = 0x20 ^ *buf;
|
*buf = 0x20 ^ *buf;
|
||||||
@@ -355,6 +378,11 @@ int XBee::recv(uint8_t* buf)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XBee::setApiMode(uint8_t mode)
|
||||||
|
{
|
||||||
|
_apiMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
/*=========================================
|
/*=========================================
|
||||||
Class SerialPort
|
Class SerialPort
|
||||||
=========================================*/
|
=========================================*/
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ public:
|
|||||||
int unicast(const uint8_t* buf, uint16_t length, SensorNetAddress* sendToAddr);
|
int unicast(const uint8_t* buf, uint16_t length, SensorNetAddress* sendToAddr);
|
||||||
int broadcast(const uint8_t* buf, uint16_t length);
|
int broadcast(const uint8_t* buf, uint16_t length);
|
||||||
int recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr);
|
int recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr);
|
||||||
|
void setApiMode(uint8_t mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int readApiFrame(uint8_t* recvData);
|
int readApiFrame(uint8_t* recvData);
|
||||||
@@ -105,10 +106,10 @@ private:
|
|||||||
Mutex _meutex;
|
Mutex _meutex;
|
||||||
SerialPort* _serialPort;
|
SerialPort* _serialPort;
|
||||||
uint8_t _frameId;
|
uint8_t _frameId;
|
||||||
|
|
||||||
uint8_t _respCd;
|
uint8_t _respCd;
|
||||||
uint8_t _respId;
|
uint8_t _respId;
|
||||||
uint8_t _dataLen;
|
uint8_t _dataLen;
|
||||||
|
uint8_t _apiMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*===========================================
|
/*===========================================
|
||||||
@@ -124,16 +125,12 @@ public:
|
|||||||
int broadcast(const uint8_t* payload, uint16_t payloadLength);
|
int broadcast(const uint8_t* payload, uint16_t payloadLength);
|
||||||
int read(uint8_t* buf, uint16_t bufLen);
|
int read(uint8_t* buf, uint16_t bufLen);
|
||||||
int initialize(void);
|
int initialize(void);
|
||||||
const char* getType(void);
|
const char* getDescription(void);
|
||||||
|
SensorNetAddress* getSenderAddress(void);
|
||||||
SensorNetAddress* getSenderAddress(void)
|
|
||||||
{
|
|
||||||
return &_clientAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SensorNetAddress _clientAddr; // Sender's address. not gateway's one.
|
SensorNetAddress _clientAddr; // Sender's address. not gateway's one.
|
||||||
|
string _description;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,22 +24,18 @@ using namespace MQTTSNGW;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Gateway Process
|
* Gateway Process
|
||||||
*
|
|
||||||
* Certificate file "/etc/ssl/certs"
|
|
||||||
* This is defined in MQTTSNGWDefines.h
|
|
||||||
*/
|
*/
|
||||||
Gateway* gateway = new Gateway();
|
Gateway* gw = new Gateway();
|
||||||
PacketHandleTask* t0 = new PacketHandleTask(gateway);
|
PacketHandleTask task1(gw);
|
||||||
ClientRecvTask* t1 = new ClientRecvTask(gateway);
|
ClientRecvTask task2(gw);
|
||||||
ClientSendTask* t2 = new ClientSendTask(gateway);
|
ClientSendTask task3(gw);
|
||||||
BrokerRecvTask* t3 = new BrokerRecvTask(gateway);
|
BrokerRecvTask task4(gw);
|
||||||
BrokerSendTask* t4 = new BrokerSendTask(gateway);
|
BrokerSendTask task5(gw);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
gateway->initialize(argc, argv);
|
gw->initialize(argc, argv);
|
||||||
gateway->run();
|
gw->run();
|
||||||
delete gateway;
|
delete gw;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
151
MQTTSNGateway/src/tests/TestProcessFramework.cpp
Normal file
151
MQTTSNGateway/src/tests/TestProcessFramework.cpp
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <cassert>
|
||||||
|
#include "TestProcessFramework.h"
|
||||||
|
#include "MQTTSNGWProcess.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
#define ARGV "./testPFW"
|
||||||
|
#define CONFDIR "./"
|
||||||
|
#define CONF "gateway.conf"
|
||||||
|
|
||||||
|
const char* currentDateTime(void);
|
||||||
|
|
||||||
|
TestProcessFramework::TestProcessFramework()
|
||||||
|
{
|
||||||
|
theMultiTaskProcess = this;
|
||||||
|
theProcess = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TestProcessFramework::~TestProcessFramework()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestProcessFramework::initialize(int argc, char** argv)
|
||||||
|
{
|
||||||
|
MultiTaskProcess::initialize(argc, argv);
|
||||||
|
assert(0 == strcmp(CONFDIR, getConfigDirName()->c_str()));
|
||||||
|
assert(0 == strcmp(CONF, getConfigFileName()->c_str()));
|
||||||
|
resetRingBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestProcessFramework::run(void)
|
||||||
|
{
|
||||||
|
char value[256];
|
||||||
|
int* v = 0;
|
||||||
|
int i = 0;
|
||||||
|
Timer tm;
|
||||||
|
TestQue que;
|
||||||
|
|
||||||
|
assert(1 == getArgc() || 3 == getArgc() );
|
||||||
|
assert(0 == strcmp(ARGV, *getArgv()));
|
||||||
|
getParam("BrokerName", value);
|
||||||
|
assert(0 == strcmp("iot.eclipse.org", value));
|
||||||
|
|
||||||
|
for ( i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
putLog("Test RingBuffer %d ", 1234567890);
|
||||||
|
}
|
||||||
|
putLog("\n\nRingBuffer Test complieted. Enter CTRL+C\n");
|
||||||
|
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
v = new int(i);
|
||||||
|
que.post(v);
|
||||||
|
}
|
||||||
|
assert( 10 == que.size());
|
||||||
|
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
assert(i == *que.front());
|
||||||
|
int* p = que.front();
|
||||||
|
if ( p )
|
||||||
|
{
|
||||||
|
assert(i == *p);
|
||||||
|
que.pop();
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(0 == que.front());
|
||||||
|
assert(0 == que.size());
|
||||||
|
|
||||||
|
que.setMaxSize(5);
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
v = new int(i);
|
||||||
|
que.post(v);
|
||||||
|
assert( 5 >= que.size());
|
||||||
|
}
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
int* p = que.front();
|
||||||
|
if ( p )
|
||||||
|
{
|
||||||
|
que.pop();
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s Timer start\n", currentDateTime());
|
||||||
|
tm.start(1000);
|
||||||
|
while (!tm.isTimeup());
|
||||||
|
printf("%s Timer 1sec\n", currentDateTime());
|
||||||
|
|
||||||
|
tm.start();
|
||||||
|
while (!tm.isTimeup(1000));
|
||||||
|
printf("%s Timer 1sec\n", currentDateTime());
|
||||||
|
|
||||||
|
MultiTaskProcess::run();
|
||||||
|
printf("ProcessFramework test complited.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TestQue::TestQue()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TestQue::~TestQue()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int* TestQue::front(void)
|
||||||
|
{
|
||||||
|
return _que.front();
|
||||||
|
}
|
||||||
|
void TestQue::pop(void)
|
||||||
|
{
|
||||||
|
_que.pop();
|
||||||
|
}
|
||||||
|
int TestQue::size(void)
|
||||||
|
{
|
||||||
|
return _que.size();
|
||||||
|
}
|
||||||
|
void TestQue::setMaxSize(int maxsize)
|
||||||
|
{
|
||||||
|
_que.setMaxSize(maxsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQue::post(int* val)
|
||||||
|
{
|
||||||
|
_que.post(val);
|
||||||
|
}
|
||||||
50
MQTTSNGateway/src/tests/TestProcessFramework.h
Normal file
50
MQTTSNGateway/src/tests/TestProcessFramework.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#ifndef TESTPROCESSFRAMEWORK_H_
|
||||||
|
#define TESTPROCESSFRAMEWORK_H_
|
||||||
|
|
||||||
|
#include "MQTTSNGWProcess.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace MQTTSNGW
|
||||||
|
{
|
||||||
|
class TestProcessFramework: public MultiTaskProcess{
|
||||||
|
public:
|
||||||
|
TestProcessFramework();
|
||||||
|
~TestProcessFramework();
|
||||||
|
virtual void initialize(int argc, char** argv);
|
||||||
|
void run(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestQue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestQue();
|
||||||
|
~TestQue();
|
||||||
|
void post(int*);
|
||||||
|
int* front(void);
|
||||||
|
void pop(void);
|
||||||
|
int size(void);
|
||||||
|
void setMaxSize(int maxsize);
|
||||||
|
private:
|
||||||
|
Que<int> _que;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TESTPROCESSFRAMEWORK_H_ */
|
||||||
49
MQTTSNGateway/src/tests/TestTask.cpp
Normal file
49
MQTTSNGateway/src/tests/TestTask.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "TestTask.h"
|
||||||
|
#include "Threading.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
TestTask::TestTask(TestProcessFramework* proc)
|
||||||
|
{
|
||||||
|
proc->attach((Thread*)this);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestTask::~TestTask()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestTask::initialize(int argc, char** argv)
|
||||||
|
{
|
||||||
|
printf("Task initialize complite.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestTask::run(void)
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
printf("Task is running. Enter CTRL+C \n");
|
||||||
|
if (theProcess->checkSignal() == SIGINT)
|
||||||
|
{
|
||||||
|
throw Exception("Terminated by CTL-C");
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
MQTTSNGateway/src/tests/TestTask.h
Normal file
42
MQTTSNGateway/src/tests/TestTask.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#ifndef TESTTASK_H_
|
||||||
|
#define TESTTASK_H_
|
||||||
|
|
||||||
|
#include "Threading.h"
|
||||||
|
#include "TestProcessFramework.h"
|
||||||
|
|
||||||
|
namespace MQTTSNGW
|
||||||
|
{
|
||||||
|
|
||||||
|
class TestTask: public Thread
|
||||||
|
{
|
||||||
|
MAGIC_WORD_FOR_THREAD;
|
||||||
|
;
|
||||||
|
public:
|
||||||
|
TestTask(TestProcessFramework* proc);
|
||||||
|
~TestTask();
|
||||||
|
void initialize(int argc, char** argv);
|
||||||
|
void run(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* TESTTASK_H_ */
|
||||||
31
MQTTSNGateway/src/tests/mainTestProcessFramework.cpp
Normal file
31
MQTTSNGateway/src/tests/mainTestProcessFramework.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#include "TestProcessFramework.h"
|
||||||
|
#include "TestTask.h"
|
||||||
|
|
||||||
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
TestProcessFramework* proc = new TestProcessFramework();
|
||||||
|
TestTask* task = new TestTask(proc);
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
proc->initialize(argc, argv);
|
||||||
|
proc->run();
|
||||||
|
delete proc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
43
Makefile
43
Makefile
@@ -4,6 +4,9 @@ APPL := mainGateway
|
|||||||
LPROGNAME := MQTT-SNLogmonitor
|
LPROGNAME := MQTT-SNLogmonitor
|
||||||
LAPPL := mainLogmonitor
|
LAPPL := mainLogmonitor
|
||||||
|
|
||||||
|
TESTPROGNAME := testPFW
|
||||||
|
TESTAPPL := mainTestProcessFramework
|
||||||
|
|
||||||
CONFIG := MQTTSNGateway/gateway.conf
|
CONFIG := MQTTSNGateway/gateway.conf
|
||||||
CLIENTS := MQTTSNGateway/clients.conf
|
CLIENTS := MQTTSNGateway/clients.conf
|
||||||
|
|
||||||
@@ -12,6 +15,7 @@ SUBDIR := MQTTSNPacket/src
|
|||||||
|
|
||||||
OS := linux
|
OS := linux
|
||||||
SENSORNET := udp
|
SENSORNET := udp
|
||||||
|
TEST := tests
|
||||||
|
|
||||||
CPPSRCS := \
|
CPPSRCS := \
|
||||||
$(SRCDIR)/MQTTGWConnectionHandler.cpp \
|
$(SRCDIR)/MQTTGWConnectionHandler.cpp \
|
||||||
@@ -34,7 +38,10 @@ $(SRCDIR)/MQTTSNGWSubscribeHandler.cpp \
|
|||||||
$(SRCDIR)/$(OS)/$(SENSORNET)/SensorNetwork.cpp \
|
$(SRCDIR)/$(OS)/$(SENSORNET)/SensorNetwork.cpp \
|
||||||
$(SRCDIR)/$(OS)/Timer.cpp \
|
$(SRCDIR)/$(OS)/Timer.cpp \
|
||||||
$(SRCDIR)/$(OS)/Network.cpp \
|
$(SRCDIR)/$(OS)/Network.cpp \
|
||||||
$(SRCDIR)/$(OS)/Threading.cpp
|
$(SRCDIR)/$(OS)/Threading.cpp \
|
||||||
|
$(SRCDIR)/$(TEST)/TestProcessFramework.cpp \
|
||||||
|
$(SRCDIR)/$(TEST)/TestTask.cpp
|
||||||
|
|
||||||
|
|
||||||
CSRCS := $(SUBDIR)/MQTTSNConnectClient.c \
|
CSRCS := $(SUBDIR)/MQTTSNConnectClient.c \
|
||||||
$(SUBDIR)/MQTTSNConnectServer.c \
|
$(SUBDIR)/MQTTSNConnectServer.c \
|
||||||
@@ -51,13 +58,14 @@ $(SUBDIR)/MQTTSNUnsubscribeServer.c
|
|||||||
CXX := g++
|
CXX := g++
|
||||||
CPPFLAGS +=
|
CPPFLAGS +=
|
||||||
|
|
||||||
INCLUDES += -IMQTTSNGateway/src \
|
INCLUDES += -I$(SRCDIR) \
|
||||||
-IMQTTSNGateway/src/$(OS) \
|
-I$(SRCDIR)/$(OS) \
|
||||||
-IMQTTSNGateway/src/$(OS)/$(SENSORNET) \
|
-I$(SRCDIR)/$(OS)/$(SENSORNET) \
|
||||||
-IMQTTSNPacket/src
|
-I$(SUBDIR) \
|
||||||
|
-I$(SRCDIR)/$(TEST)
|
||||||
|
|
||||||
DEFS :=
|
DEFS :=
|
||||||
LIBS +=
|
LIBS += -L/usr/local/lib
|
||||||
LDFLAGS :=
|
LDFLAGS :=
|
||||||
CXXFLAGS := -Wall -O3 -std=c++11
|
CXXFLAGS := -Wall -O3 -std=c++11
|
||||||
LDADD := -lpthread -lssl -lcrypto
|
LDADD := -lpthread -lssl -lcrypto
|
||||||
@@ -65,17 +73,22 @@ OUTDIR := Build
|
|||||||
|
|
||||||
PROG := $(OUTDIR)/$(PROGNAME)
|
PROG := $(OUTDIR)/$(PROGNAME)
|
||||||
LPROG := $(OUTDIR)/$(LPROGNAME)
|
LPROG := $(OUTDIR)/$(LPROGNAME)
|
||||||
|
TPROG := $(OUTDIR)/$(TESTPROGNAME)
|
||||||
|
|
||||||
OBJS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.o)
|
OBJS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.o)
|
||||||
OBJS += $(CSRCS:%.c=$(OUTDIR)/%.o)
|
OBJS += $(CSRCS:%.c=$(OUTDIR)/%.o)
|
||||||
DEPS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.d)
|
DEPS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.d)
|
||||||
DEPS += $(CSRCS:%.c=$(OUTDIR)/%.d)
|
DEPS += $(CSRCS:%.c=$(OUTDIR)/%.d)
|
||||||
|
|
||||||
.PHONY: install clean
|
.PHONY: install clean exectest
|
||||||
|
|
||||||
all: $(PROG) $(LPROG)
|
all: $(PROG) $(LPROG) $(TPROG)
|
||||||
|
|
||||||
monitor: $(LPROG)
|
monitor: $(LPROG)
|
||||||
|
|
||||||
|
test: $(TPROG) $(LPROG) exectest
|
||||||
|
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
||||||
$(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(APPL).o
|
$(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(APPL).o
|
||||||
@@ -84,6 +97,10 @@ $(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(APPL).o
|
|||||||
$(LPROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(LAPPL).o
|
$(LPROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(LAPPL).o
|
||||||
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) $(LDADD)
|
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) $(LDADD)
|
||||||
|
|
||||||
|
$(TPROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(TEST)/$(TESTAPPL).o
|
||||||
|
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) $(LDADD)
|
||||||
|
|
||||||
|
|
||||||
$(OUTDIR)/$(SRCDIR)/%.o:$(SRCDIR)/%.cpp
|
$(OUTDIR)/$(SRCDIR)/%.o:$(SRCDIR)/%.cpp
|
||||||
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
@@ -92,6 +109,10 @@ $(OUTDIR)/$(SRCDIR)/$(APPL).o:$(SRCDIR)/$(APPL).cpp
|
|||||||
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
|
|
||||||
|
$(OUTDIR)/$(SRCDIR)/$(TEST)/$(TESTAPPL).o:$(SRCDIR)/$(TEST)/$(TESTAPPL).cpp
|
||||||
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
|
|
||||||
$(OUTDIR)/$(SRCDIR)/$(LAPPL).o:$(SRCDIR)/$(LAPPL).cpp
|
$(OUTDIR)/$(SRCDIR)/$(LAPPL).o:$(SRCDIR)/$(LAPPL).cpp
|
||||||
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
@@ -108,5 +129,9 @@ install:
|
|||||||
cp -pf $(LPROG) ../
|
cp -pf $(LPROG) ../
|
||||||
cp -pf $(CONFIG) ../
|
cp -pf $(CONFIG) ../
|
||||||
cp -pf $(CLIENTS) ../
|
cp -pf $(CLIENTS) ../
|
||||||
|
|
||||||
|
exectest:
|
||||||
|
cp -pf $(CONFIG) $(OUTDIR)
|
||||||
|
cd $(OUTDIR); ./$(TESTPROGNAME) -f ./gateway.conf
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user