Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2019-07-13 16:38:12 +09:00
parent 18885668cf
commit 93e297c6d3
6 changed files with 39 additions and 25 deletions

View File

@@ -133,7 +133,7 @@
<sourceEntries> <sourceEntries>
<entry excluding="MQTTSNGateway/src/linux/udp|MQTTSNGateway/GatewayTester|MQTTSNClient|MQTTSNGateway/src/MQTTSNGWProxy.cpp|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src/tests|MQTTSNGateway/src/tests/mainTestProcessFramework.cpp|ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/> <entry excluding="MQTTSNGateway/src/linux/udp6|MQTTSNGateway/GatewayTester|MQTTSNClient|MQTTSNGateway/src/MQTTSNGWProxy.cpp|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src/tests|MQTTSNGateway/src/tests/mainTestProcessFramework.cpp|ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries> </sourceEntries>
@@ -277,7 +277,7 @@
<entry excluding="MQTTSNGWProxy.cpp|mainLogmonitor.cpp|tests|tests/mainTestProcessFramework.cpp|linux|linux/udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src"/> <entry excluding="MQTTSNGWProxy.cpp|mainLogmonitor.cpp|tests|tests/mainTestProcessFramework.cpp|linux|linux/udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src"/>
<entry excluding="udp|xbee" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src/linux"/> <entry excluding="udp6|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"/>

View File

@@ -138,7 +138,7 @@ void publishTopic1(void)
PUBLISH(topic1,(uint8_t*)payload, strlen(payload), QoS0); PUBLISH(topic1,(uint8_t*)payload, strlen(payload), QoS0);
} }
void subscribeTopic2(void) void subscribeTopic10(void)
{ {
SUBSCRIBE(10, on_Topic02, QoS1); SUBSCRIBE(10, on_Topic02, QoS1);
} }
@@ -190,7 +190,7 @@ TEST_LIST = {// e.g. TEST( Label, Test),
TEST("Step0:Subscribe predef topic1", subscribePredefTopic1), TEST("Step0:Subscribe predef topic1", subscribePredefTopic1),
TEST("Step1:Publish topic1", publishTopic1), TEST("Step1:Publish topic1", publishTopic1),
TEST("Step2:Publish topic2", publishTopic2), TEST("Step2:Publish topic2", publishTopic2),
TEST("Step3:Subscribe topic2", subscribeTopic2), TEST("Step3:Subscribe PreDefined topic10. ID is not defined.", subscribeTopic10),
TEST("Step4:Publish topic2", publishTopic2), TEST("Step4:Publish topic2", publishTopic2),
TEST("Step5:Unsubscribe topic2", unsubscribe), TEST("Step5:Unsubscribe topic2", unsubscribe),
TEST("Step6:Publish topic2", publishTopic2), TEST("Step6:Publish topic2", publishTopic2),

View File

@@ -1,5 +1,5 @@
#************************************************************************** #**************************************************************************
# Copyright (c) 2016-2018, Tomoaki Yamaguchi # Copyright (c) 2016-2019, Tomoaki Yamaguchi
# #
# All rights reserved. This program and the accompanying materials # All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0 # are made available under the terms of the Eclipse Public License v1.0
@@ -14,7 +14,7 @@
# config file of MQTT-SN Gateway # config file of MQTT-SN Gateway
# #
BrokerName=iot.eclipse.org BrokerName=mqtt.eclipse.org
BrokerPortNo=1883 BrokerPortNo=1883
BrokerSecurePortNo=8883 BrokerSecurePortNo=8883
@@ -50,6 +50,12 @@ GatewayPortNo=10000
MulticastIP=225.1.1.1 MulticastIP=225.1.1.1
MulticastPortNo=1883 MulticastPortNo=1883
# UDP6
GatewayUDP6Bind=FFFF:FFFE::1
GatewayUDP6Port=10000
GatewayUDP6Broadcast=FF02::1
GatewayUDP6If=wpan0
# XBee # XBee
Baudrate=38400 Baudrate=38400
SerialDevice=/dev/ttyUSB0 SerialDevice=/dev/ttyUSB0

View File

@@ -416,9 +416,9 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicName, uint16_t topicId, bool aggregate) Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicName, uint16_t topicId, bool aggregate)
{ {
if ( clientId->cstring == common_topic ) if ( strcmp(clientId->cstring, common_topic) == 0 )
{ {
_gateway->getTopics()->add((const char*)topicName.c_str(), topicId); theGateway->getTopics()->add((const char*)topicName.c_str(), topicId);
return 0; return 0;
} }
else else

View File

@@ -18,6 +18,7 @@
#include "MQTTSNGateway.h" #include "MQTTSNGateway.h"
#include "MQTTSNGWEncapsulatedPacket.h" #include "MQTTSNGWEncapsulatedPacket.h"
#include "MQTTSNGWQoSm1Proxy.h" #include "MQTTSNGWQoSm1Proxy.h"
#include <errno.h>
using namespace MQTTSNGW; using namespace MQTTSNGW;
using namespace std; using namespace std;
@@ -75,8 +76,8 @@ void ClientSendTask::run()
if ( rc < 0 ) if ( rc < 0 )
{ {
WRITELOG("%s ClientSendTask can't send a packet to the client %s%s.\n", WRITELOG("%s ClientSendTask can't send a packet to the client %s. Error=%d%s\n",
ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), ERRMSG_FOOTER); ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), errno, ERRMSG_FOOTER);
} }
delete ev; delete ev;
} }

View File

@@ -60,25 +60,22 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPack
{ {
topic = client->getTopics()->getTopicById(&topicFilter); topic = client->getTopics()->getTopicById(&topicFilter);
if ( !topic )
if ( topic )
{
topicId = topic->getTopicId();
subscribe = new MQTTGWPacket();
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
}
else
{ {
topic = _gateway->getTopics()->getTopicById(&topicFilter); topic = _gateway->getTopics()->getTopicById(&topicFilter);
if ( !topic ) if ( topic )
{ {
topic = client->getTopics()->add(topic->getTopicName()->c_str(), topic->getTopicId()); topic = client->getTopics()->add(topic->getTopicName()->c_str(), topic->getTopicId());
} }
else else
{ {
goto RespExit; goto RespExit;
} }
} }
topicId = topic->getTopicId();
subscribe = new MQTTGWPacket();
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
} }
else if (topicFilter.type == MQTTSN_TOPIC_TYPE_NORMAL) else if (topicFilter.type == MQTTSN_TOPIC_TYPE_NORMAL)
{ {
@@ -148,7 +145,6 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa
return nullptr; return nullptr;
} }
Topic* topic = client->getTopics()->getTopicById(&topicFilter);
if (topicFilter.type == MQTTSN_TOPIC_TYPE_SHORT) if (topicFilter.type == MQTTSN_TOPIC_TYPE_SHORT)
{ {
@@ -161,6 +157,17 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa
} }
else else
{ {
Topic* topic = nullptr;
if (topicFilter.type == MQTTSN_TOPIC_TYPE_PREDEFINED)
{
topic = client->getTopics()->getTopicById(&topicFilter);
}
else
{
topic = client->getTopics()->getTopicByName(&topicFilter);
}
if ( topic == nullptr ) if ( topic == nullptr )
{ {
MQTTSNPacket* sUnsuback = new MQTTSNPacket(); MQTTSNPacket* sUnsuback = new MQTTSNPacket();