mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-15 08:26:51 +01:00
upgrade and bugfix for a test
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -133,7 +133,7 @@
|
|||||||
|
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
|
|
||||||
<entry excluding="MQTTSNGateway/src/linux/udp6|MQTTSNGateway/src/linux/loralink|MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples|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" kind="sourcePath" name=""/>
|
<entry excluding="MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/ClientSub|MQTTSNGateway/GatewayTester/samples/ClientPub|MQTTSNGateway/src/linux/udp6|MQTTSNGateway/src/linux/loralink|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" kind="sourcePath" name=""/>
|
||||||
|
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
|
|
||||||
@@ -273,7 +273,7 @@
|
|||||||
|
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
|
|
||||||
<entry excluding="MQTTSNGateway/src/tests/mainTestProcess.cpp|MQTTSNGateway/src/linux|MQTTSNPacket/src|MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples|MQTTSNClient|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|ClientPubQoS-1" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
|
<entry excluding="MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/ClientSub|MQTTSNGateway/GatewayTester/samples/ClientPub|MQTTSNGateway/src/tests/mainTestProcess.cpp|MQTTSNGateway/src/linux|MQTTSNPacket/src|MQTTSNClient|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|ClientPubQoS-1" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
|
||||||
|
|
||||||
<entry excluding="udp6|xbee|loralink" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
<entry excluding="udp6|xbee|loralink" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
||||||
|
|
||||||
|
|||||||
@@ -51,25 +51,25 @@ extern LScreen* theScreen;
|
|||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* UDP Configuration (theNetcon)
|
* UDP Configuration (theNetcon)
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
UDPCONF = {
|
UDPCONF =
|
||||||
"GatewayTestClient", // ClientId
|
{ "GatewayTestClient", // ClientId
|
||||||
{225,1,1,1}, // Multicast group IP
|
{ 225, 1, 1, 1 }, // Multicast group IP
|
||||||
1883, // Multicast group Port
|
1883, // Multicast group Port
|
||||||
20020, // Local PortNo
|
20020, // Local PortNo
|
||||||
};
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* Client Configuration (theMqcon)
|
* Client Configuration (theMqcon)
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
MQTTSNCONF = {
|
MQTTSNCONF =
|
||||||
60, //KeepAlive [seconds]
|
{ 60, //KeepAlive [seconds]
|
||||||
true, //Clean session
|
true, //Clean session
|
||||||
300, //Sleep duration [seconds]
|
300, //Sleep duration [seconds]
|
||||||
"", //WillTopic
|
"", //WillTopic
|
||||||
"", //WillMessage
|
"", //WillMessage
|
||||||
0, //WillQos
|
0, //WillQos
|
||||||
false //WillRetain
|
false //WillRetain
|
||||||
};
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* Define Topics
|
* Define Topics
|
||||||
@@ -83,32 +83,31 @@ const char* topic52 = "ty4tw/topic5/2";
|
|||||||
const char* topic53 = "ty4tw/topic5/3";
|
const char* topic53 = "ty4tw/topic5/3";
|
||||||
const char* topic50 = "ty4tw/topic5/+";
|
const char* topic50 = "ty4tw/topic5/+";
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* Callback routines for Subscribed Topics
|
* Callback routines for Subscribed Topics
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
int on_Topic01(uint8_t* pload, uint16_t ploadlen)
|
int on_Topic01(uint8_t* pload, uint16_t ploadlen)
|
||||||
{
|
{
|
||||||
DISPLAY("\n\nTopic1 recv.\n");
|
DISPLAY("\n\nTopic1 recv.\n");
|
||||||
char c = pload[ploadlen-1];
|
char c = pload[ploadlen - 1];
|
||||||
pload[ploadlen-1]= 0; // set null terminator
|
pload[ploadlen - 1] = 0; // set null terminator
|
||||||
DISPLAY("Payload -->%s%c<--\n\n",pload, c);
|
DISPLAY("Payload -->%s%c<--\n\n", pload, c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int on_Topic02(uint8_t* pload, uint16_t ploadlen)
|
int on_Topic02(uint8_t* pload, uint16_t ploadlen)
|
||||||
{
|
{
|
||||||
DISPLAY("\n\nTopic2 recv.\n");
|
DISPLAY("\n\nTopic2 recv.\n");
|
||||||
pload[ploadlen-1]= 0; // set null terminator
|
pload[ploadlen - 1] = 0; // set null terminator
|
||||||
DISPLAY("Payload -->%s <--\n\n",pload);
|
DISPLAY("Payload -->%s <--\n\n", pload);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int on_Topic03(uint8_t* pload, uint16_t ploadlen)
|
int on_Topic03(uint8_t* pload, uint16_t ploadlen)
|
||||||
{
|
{
|
||||||
DISPLAY("\n\nNew callback recv Topic3\n");
|
DISPLAY("\n\nNew callback recv Topic3\n");
|
||||||
pload[ploadlen-1]= 0; // set null terminator
|
pload[ploadlen - 1] = 0; // set null terminator
|
||||||
DISPLAY("Payload -->%s <--\n\n",pload);
|
DISPLAY("Payload -->%s <--\n\n", pload);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,26 +115,26 @@ int on_Topic03(uint8_t* pload, uint16_t ploadlen)
|
|||||||
* A Link list of Callback routines and Topics
|
* A Link list of Callback routines and Topics
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
SUBSCRIBE_LIST = {// e.g. SUB(TopicType, topicName, TopicId, callback, QoSx),
|
SUBSCRIBE_LIST =
|
||||||
SUB(MQTTSN_TOPIC_TYPE_NORMAL, topic1, 0, on_Topic01, QoS1),
|
{ // e.g. SUB(TopicType, topicName, TopicId, callback, QoSx),
|
||||||
SUB(MQTTSN_TOPIC_TYPE_NORMAL, topic2, 0, on_Topic02, QoS1),
|
SUB(MQTTSN_TOPIC_TYPE_NORMAL, topic1, 0, on_Topic01, QoS1),
|
||||||
END_OF_SUBSCRIBE_LIST
|
SUB(MQTTSN_TOPIC_TYPE_NORMAL, topic2, 0, on_Topic02, QoS1),
|
||||||
};
|
END_OF_SUBSCRIBE_LIST
|
||||||
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* Test functions
|
* Test functions
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
void subscribePredefTopic1(void)
|
void subscribePredefTopic1(void)
|
||||||
{
|
{
|
||||||
SUBSCRIBE(1, on_Topic03, QoS1);
|
SUBSCRIBE(1, on_Topic03, QoS1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishTopic1(void)
|
void publishTopic1(void)
|
||||||
{
|
{
|
||||||
char payload[300];
|
char payload[300];
|
||||||
sprintf(payload, "publish \"ty4tw/Topic1\" \n");
|
sprintf(payload, "publish \"ty4tw/Topic1\" \n");
|
||||||
PUBLISH(topic1,(uint8_t*)payload, strlen(payload), QoS0);
|
PUBLISH(topic1, (uint8_t* )payload, strlen(payload), QoS0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subscribeTopic10(void)
|
void subscribeTopic10(void)
|
||||||
@@ -147,11 +146,9 @@ void publishTopic2(void)
|
|||||||
{
|
{
|
||||||
char payload[300];
|
char payload[300];
|
||||||
sprintf(payload, "publish \"ty4tw/topic2\" \n");
|
sprintf(payload, "publish \"ty4tw/topic2\" \n");
|
||||||
PUBLISH(topic2,(uint8_t*)payload, strlen(payload), QoS1);
|
PUBLISH(topic2, (uint8_t* )payload, strlen(payload), QoS1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void unsubscribe(void)
|
void unsubscribe(void)
|
||||||
{
|
{
|
||||||
UNSUBSCRIBE(topic2);
|
UNSUBSCRIBE(topic2);
|
||||||
@@ -167,7 +164,7 @@ void test3(void)
|
|||||||
char payload[300];
|
char payload[300];
|
||||||
sprintf(payload, "TEST3 ");
|
sprintf(payload, "TEST3 ");
|
||||||
uint8_t qos = 0;
|
uint8_t qos = 0;
|
||||||
PUBLISH(topic2,(uint8_t*)payload, strlen(payload), qos);
|
PUBLISH(topic2, (uint8_t* )payload, strlen(payload), qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void disconnect(void)
|
void disconnect(void)
|
||||||
@@ -180,48 +177,71 @@ void asleep(void)
|
|||||||
DISCONNECT(theMqcon.sleepDuration);
|
DISCONNECT(theMqcon.sleepDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onconnect(void)
|
||||||
|
{
|
||||||
|
ONCONNECT();
|
||||||
|
}
|
||||||
|
|
||||||
|
void connect(void)
|
||||||
|
{
|
||||||
|
CONNECT();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DisableAutoPingreq(void)
|
||||||
|
{
|
||||||
|
SetAutoPingReqMode(false);
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* A List of Test functions is valid in case of
|
* A List of Test functions is valid in case of
|
||||||
* line 23 of LMqttsnClientApp.h is commented out.
|
* line 23 of LMqttsnClientApp.h is commented out.
|
||||||
* //#define CLIENT_MODE
|
* //#define CLIENT_MODE
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
TEST_LIST = {// e.g. TEST( Label, Test),
|
TEST_LIST =
|
||||||
TEST("Step0:Subscribe predef topic1", subscribePredefTopic1),
|
{ // e.g. TEST( Label, Test),
|
||||||
TEST("Step1:Publish topic1", publishTopic1),
|
TEST("Step0:Connect", connect),
|
||||||
TEST("Step2:Publish topic2", publishTopic2),
|
TEST("Step1:Subscribe list", onconnect),
|
||||||
TEST("Step3:Subscribe PreDefined topic10. ID is not defined.", subscribeTopic10),
|
TEST("Step2:Subscribe predef topic1", subscribePredefTopic1),
|
||||||
TEST("Step4:Publish topic2", publishTopic2),
|
TEST("Step3:Publish topic1", publishTopic1),
|
||||||
TEST("Step5:Unsubscribe topic2", unsubscribe),
|
TEST("Step4:Publish topic2", publishTopic2),
|
||||||
TEST("Step6:Publish topic2", publishTopic2),
|
TEST("Step5:Subscribe PreDefined topic10. ID is not defined.", subscribeTopic10),
|
||||||
TEST("Step7:subscribe again", subscribechangeCallback),
|
TEST("Step6:Publish topic2", publishTopic2),
|
||||||
TEST("Step8:Publish topic2", publishTopic2),
|
TEST("Step7:Unsubscribe topic2", unsubscribe),
|
||||||
TEST("Step9:Sleep ", asleep),
|
TEST("Step8:Publish topic2", publishTopic2),
|
||||||
TEST("Step10:Publish topic1", publishTopic1),
|
TEST("Step9:subscribe again", subscribechangeCallback),
|
||||||
TEST("Step11:Disconnect", disconnect),
|
TEST("Step10:Publish topic2", publishTopic2),
|
||||||
END_OF_TEST_LIST
|
TEST("Step11:Sleep ", asleep),
|
||||||
};
|
TEST("Step12:Publish topic1", publishTopic1),
|
||||||
|
TEST("Step13:Disconnect", disconnect),
|
||||||
|
TEST("Step14:Publish topic2", publishTopic1),
|
||||||
|
TEST("Step15:Connect", connect),
|
||||||
|
TEST("Step16:Publish topic2", publishTopic2),
|
||||||
|
TEST("Step17:Auto Pingreq mode off", DisableAutoPingreq),
|
||||||
|
TEST("Step18:Publish topic2", publishTopic1),
|
||||||
|
TEST("Step19:Disconnect", disconnect),
|
||||||
|
END_OF_TEST_LIST
|
||||||
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* List of tasks is valid in case of line23 of
|
* List of tasks is valid in case of line23 of
|
||||||
* LMqttsnClientApp.h is uncommented.
|
* LMqttsnClientApp.h is uncommented.
|
||||||
* #define CLIENT_MODE
|
* #define CLIENT_MODE
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
TASK_LIST = {// e.g. TASK( task, executing duration in second),
|
TASK_LIST =
|
||||||
TASK(publishTopic1, 4), // publishTopic1() is executed every 4 seconds
|
{ // e.g. TASK( task, executing duration in second),
|
||||||
TASK(publishTopic2, 7), // publishTopic2() is executed every 7 seconds
|
TASK(publishTopic1, 4),// publishTopic1() is executed every 4 seconds
|
||||||
END_OF_TASK_LIST
|
TASK(publishTopic2, 7),// publishTopic2() is executed every 7 seconds
|
||||||
};
|
END_OF_TASK_LIST
|
||||||
|
};
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* Initialize function
|
* Initialize function
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
SetForwarderMode(false);
|
SetForwarderMode(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***************** END OF PROGRAM ********************/
|
/***************** END OF PROGRAM ********************/
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ LGwProxy::LGwProxy()
|
|||||||
_initialized = 0;
|
_initialized = 0;
|
||||||
_isForwarderMode = false;
|
_isForwarderMode = false;
|
||||||
_isQoSMinus1Mode = false;
|
_isQoSMinus1Mode = false;
|
||||||
|
_isPingReqMode = true;
|
||||||
|
_isAutoConnectMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LGwProxy::~LGwProxy()
|
LGwProxy::~LGwProxy()
|
||||||
@@ -231,9 +233,12 @@ int LGwProxy::getConnectResponce(void)
|
|||||||
|
|
||||||
void LGwProxy::reconnect(void)
|
void LGwProxy::reconnect(void)
|
||||||
{
|
{
|
||||||
D_MQTTLOG("...Gateway reconnect\r\n");
|
if (_isAutoConnectMode)
|
||||||
_status = GW_DISCONNECTED;
|
{
|
||||||
connect();
|
D_MQTTLOG("...Gateway reconnect\r\n");
|
||||||
|
_status = GW_DISCONNECTED;
|
||||||
|
connect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LGwProxy::disconnect(uint16_t secs)
|
void LGwProxy::disconnect(uint16_t secs)
|
||||||
@@ -395,7 +400,7 @@ int LGwProxy::getMessage(void)
|
|||||||
}
|
}
|
||||||
else if (_mqttsnMsg[0] == MQTTSN_TYPE_DISCONNECT)
|
else if (_mqttsnMsg[0] == MQTTSN_TYPE_DISCONNECT)
|
||||||
{
|
{
|
||||||
_status = GW_LOST;
|
_status = GW_DISCONNECTED;
|
||||||
_gwAliveTimer.stop();
|
_gwAliveTimer.stop();
|
||||||
_keepAliveTimer.stop();
|
_keepAliveTimer.stop();
|
||||||
}
|
}
|
||||||
@@ -586,7 +591,7 @@ uint16_t LGwProxy::getNextMsgId(void)
|
|||||||
|
|
||||||
void LGwProxy::checkPingReq(void)
|
void LGwProxy::checkPingReq(void)
|
||||||
{
|
{
|
||||||
if ( _isQoSMinus1Mode )
|
if (_isQoSMinus1Mode || _isPingReqMode == false)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -671,3 +676,18 @@ void LGwProxy::setQoSMinus1Mode(bool valid)
|
|||||||
{
|
{
|
||||||
_isQoSMinus1Mode = valid;
|
_isQoSMinus1Mode = valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LGwProxy::setPingReqMode(bool valid)
|
||||||
|
{
|
||||||
|
_isPingReqMode = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LGwProxy::setAutoConnectMode(bool valid)
|
||||||
|
{
|
||||||
|
_isAutoConnectMode = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t LGwProxy::getStatus(void)
|
||||||
|
{
|
||||||
|
return _status;
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ public:
|
|||||||
void setAdvertiseDuration(uint16_t duration);
|
void setAdvertiseDuration(uint16_t duration);
|
||||||
void setForwarderMode(bool valid);
|
void setForwarderMode(bool valid);
|
||||||
void setQoSMinus1Mode(bool valid);
|
void setQoSMinus1Mode(bool valid);
|
||||||
|
void setPingReqMode(bool valid);
|
||||||
|
void setAutoConnectMode(bool valid);
|
||||||
void reconnect(void);
|
void reconnect(void);
|
||||||
int writeMsg(const uint8_t* msg);
|
int writeMsg(const uint8_t* msg);
|
||||||
void setPingReqTimer(void);
|
void setPingReqTimer(void);
|
||||||
@@ -74,6 +76,7 @@ public:
|
|||||||
LTopicTable* getTopicTable(void);
|
LTopicTable* getTopicTable(void);
|
||||||
LRegisterManager* getRegisterManager(void);
|
LRegisterManager* getRegisterManager(void);
|
||||||
const char* getClientId(void);
|
const char* getClientId(void);
|
||||||
|
uint8_t getStatus(void);
|
||||||
private:
|
private:
|
||||||
int readMsg(void);
|
int readMsg(void);
|
||||||
void writeGwMsg(void);
|
void writeGwMsg(void);
|
||||||
@@ -111,6 +114,8 @@ private:
|
|||||||
uint16_t _tWake;
|
uint16_t _tWake;
|
||||||
bool _isForwarderMode;
|
bool _isForwarderMode;
|
||||||
bool _isQoSMinus1Mode;
|
bool _isQoSMinus1Mode;
|
||||||
|
bool _isPingReqMode;
|
||||||
|
bool _isAutoConnectMode;
|
||||||
char _msg[MQTTSN_MAX_MSG_LENGTH + 1];
|
char _msg[MQTTSN_MAX_MSG_LENGTH + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
theClient->setAutoConnectMode(false);
|
||||||
|
theClient->getPublishManager()->setAutoConnectMode(false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
@@ -98,7 +100,7 @@ int main(int argc, char** argv)
|
|||||||
======================================*/
|
======================================*/
|
||||||
LMqttsnClient::LMqttsnClient()
|
LMqttsnClient::LMqttsnClient()
|
||||||
{
|
{
|
||||||
|
_isAutoConnect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LMqttsnClient::~LMqttsnClient()
|
LMqttsnClient::~LMqttsnClient()
|
||||||
@@ -205,10 +207,20 @@ void LMqttsnClient::disconnect(uint16_t sleepInSecs)
|
|||||||
|
|
||||||
void LMqttsnClient::run()
|
void LMqttsnClient::run()
|
||||||
{
|
{
|
||||||
_gwProxy.connect();
|
if (_isAutoConnect)
|
||||||
|
{
|
||||||
|
_gwProxy.connect();
|
||||||
|
}
|
||||||
_taskMgr.run();
|
_taskMgr.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LMqttsnClient::setAutoConnectMode(uint8_t flg)
|
||||||
|
{
|
||||||
|
_isAutoConnect = flg;
|
||||||
|
_pubMgr.setAutoConnectMode(flg);
|
||||||
|
_gwProxy.setAutoConnectMode(flg);
|
||||||
|
}
|
||||||
|
|
||||||
void LMqttsnClient::setSleepMode(uint32_t duration)
|
void LMqttsnClient::setSleepMode(uint32_t duration)
|
||||||
{
|
{
|
||||||
// ToDo: set WDT and sleep mode
|
// ToDo: set WDT and sleep mode
|
||||||
@@ -227,7 +239,10 @@ void LMqttsnClient::setSleepDuration(uint32_t duration)
|
|||||||
|
|
||||||
void LMqttsnClient::onConnect(void)
|
void LMqttsnClient::onConnect(void)
|
||||||
{
|
{
|
||||||
|
if (_isAutoConnect)
|
||||||
|
{
|
||||||
_subMgr.onConnect();
|
_subMgr.onConnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* LMqttsnClient::getClientId(void)
|
const char* LMqttsnClient::getClientId(void)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public:
|
|||||||
void addTask(bool test);
|
void addTask(bool test);
|
||||||
void setSleepDuration(uint32_t duration);
|
void setSleepDuration(uint32_t duration);
|
||||||
void setSleepMode(uint32_t duration);
|
void setSleepMode(uint32_t duration);
|
||||||
|
void setAutoConnectMode(uint8_t flg);
|
||||||
void sleep(void);
|
void sleep(void);
|
||||||
const char* getClientId(void);
|
const char* getClientId(void);
|
||||||
uint16_t getTopicId(const char* topicName);
|
uint16_t getTopicId(const char* topicName);
|
||||||
@@ -78,6 +79,7 @@ private:
|
|||||||
LSubscribeManager _subMgr;
|
LSubscribeManager _subMgr;
|
||||||
LGwProxy _gwProxy;
|
LGwProxy _gwProxy;
|
||||||
uint32_t _sleepDuration;
|
uint32_t _sleepDuration;
|
||||||
|
uint8_t _isAutoConnect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ typedef enum
|
|||||||
#define SUBSCRIBE(...) theClient->subscribe(__VA_ARGS__)
|
#define SUBSCRIBE(...) theClient->subscribe(__VA_ARGS__)
|
||||||
#define UNSUBSCRIBE(...) theClient->unsubscribe(__VA_ARGS__)
|
#define UNSUBSCRIBE(...) theClient->unsubscribe(__VA_ARGS__)
|
||||||
#define DISCONNECT(...) theClient->disconnect(__VA_ARGS__)
|
#define DISCONNECT(...) theClient->disconnect(__VA_ARGS__)
|
||||||
|
#define ONCONNECT() theClient->getSubscribeManager()->onConnect()
|
||||||
|
|
||||||
#define TASK_LIST TaskList theTaskList[]
|
#define TASK_LIST TaskList theTaskList[]
|
||||||
#define TASK(...) {__VA_ARGS__, 0, 0}
|
#define TASK(...) {__VA_ARGS__, 0, 0}
|
||||||
@@ -104,8 +105,11 @@ typedef enum
|
|||||||
#define END_OF_SUBSCRIBE_LIST {MQTTSN_TOPIC_TYPE_NORMAL,0,0,0, 0}
|
#define END_OF_SUBSCRIBE_LIST {MQTTSN_TOPIC_TYPE_NORMAL,0,0,0, 0}
|
||||||
#define UDPCONF LUdpConfig theNetcon
|
#define UDPCONF LUdpConfig theNetcon
|
||||||
#define MQTTSNCONF LMqttsnConfig theMqcon
|
#define MQTTSNCONF LMqttsnConfig theMqcon
|
||||||
|
|
||||||
#define SetForwarderMode(...) theClient->getGwProxy()->setForwarderMode(__VA_ARGS__)
|
#define SetForwarderMode(...) theClient->getGwProxy()->setForwarderMode(__VA_ARGS__)
|
||||||
#define SetQoSMinus1Mode(...) theClient->getGwProxy()->setQoSMinus1Mode(__VA_ARGS__)
|
#define SetQoSMinus1Mode(...) theClient->getGwProxy()->setQoSMinus1Mode(__VA_ARGS__)
|
||||||
|
#define SetAutoConnectMode(...) theClient->setAutoConnectMode(__VA_ARGS__)
|
||||||
|
#define SetAutoPingReqMode(...) theClient->getGwProxy()->setPingReqMode(__VA_ARGS__)
|
||||||
|
|
||||||
#ifdef CLIENT_MODE
|
#ifdef CLIENT_MODE
|
||||||
#define DISPLAY(...)
|
#define DISPLAY(...)
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ LPublishManager::LPublishManager()
|
|||||||
_last = 0;
|
_last = 0;
|
||||||
_elmCnt = 0;
|
_elmCnt = 0;
|
||||||
_publishedFlg = SAVE_TASK_INDEX;
|
_publishedFlg = SAVE_TASK_INDEX;
|
||||||
|
_autoConnectFlg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPublishManager::~LPublishManager()
|
LPublishManager::~LPublishManager()
|
||||||
@@ -115,7 +116,10 @@ void LPublishManager::sendPublish(PubElement* elm)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
theClient->getGwProxy()->connect();
|
if (_autoConnectFlg)
|
||||||
|
{
|
||||||
|
theClient->getGwProxy()->connect();
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t msg[MQTTSN_MAX_MSG_LENGTH + 1];
|
uint8_t msg[MQTTSN_MAX_MSG_LENGTH + 1];
|
||||||
uint8_t org = 0;
|
uint8_t org = 0;
|
||||||
@@ -310,6 +314,11 @@ void LPublishManager::checkTimeout(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LPublishManager::setAutoConnectMode(bool flg)
|
||||||
|
{
|
||||||
|
_autoConnectFlg = flg;
|
||||||
|
}
|
||||||
|
|
||||||
PubElement* LPublishManager::getElement(uint16_t msgId)
|
PubElement* LPublishManager::getElement(uint16_t msgId)
|
||||||
{
|
{
|
||||||
PubElement* elm = _first;
|
PubElement* elm = _first;
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public:
|
|||||||
void sendSuspend(const char* topicName, uint16_t topicId, uint8_t topicType);
|
void sendSuspend(const char* topicName, uint16_t topicId, uint8_t topicType);
|
||||||
bool isDone(void);
|
bool isDone(void);
|
||||||
bool isMaxFlight(void);
|
bool isMaxFlight(void);
|
||||||
|
void setAutoConnectMode(bool);
|
||||||
private:
|
private:
|
||||||
PubElement* getElement(uint16_t msgId);
|
PubElement* getElement(uint16_t msgId);
|
||||||
PubElement* getElement(const char* topicName);
|
PubElement* getElement(const char* topicName);
|
||||||
@@ -84,7 +85,8 @@ private:
|
|||||||
PubElement* _last;
|
PubElement* _last;
|
||||||
uint8_t _elmCnt;
|
uint8_t _elmCnt;
|
||||||
uint8_t _publishedFlg;
|
uint8_t _publishedFlg;
|
||||||
|
uint8_t _autoConnectFlg;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* tomyAsyncClient */
|
} /* tomyAsyncClient */
|
||||||
#endif /* PUBLISHMANAGER_H_ */
|
#endif /* PUBLISHMANAGER_H_ */
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ void LSubscribeManager::send(SubElement* elm)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t msg[MQTTSN_MAX_MSG_LENGTH + 1];
|
uint8_t msg[MQTTSN_MAX_MSG_LENGTH + 1];
|
||||||
if (elm->topicType == MQTTSN_TOPIC_TYPE_PREDEFINED)
|
if (elm->topicType == MQTTSN_TOPIC_TYPE_PREDEFINED)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void BrokerRecvTask::run(void)
|
|||||||
{
|
{
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
MQTTGWPacket* packet = nullptr;
|
MQTTGWPacket* packet = nullptr;
|
||||||
int rc;
|
int rc;
|
||||||
Event* ev = nullptr;
|
Event* ev = nullptr;
|
||||||
fd_set rset;
|
fd_set rset;
|
||||||
fd_set wset;
|
fd_set wset;
|
||||||
@@ -100,6 +100,7 @@ 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(0);
|
client = _gateway->getClientList()->getClient(0);
|
||||||
@@ -134,17 +135,26 @@ void BrokerRecvTask::run(void)
|
|||||||
{
|
{
|
||||||
if (rc == 0) // Disconnected
|
if (rc == 0) // Disconnected
|
||||||
{
|
{
|
||||||
|
WRITELOG(
|
||||||
|
"%s BrokerRecvTask %s is disconnected by the broker.%s\n",
|
||||||
|
ERRMSG_HEADER,
|
||||||
|
client->getClientId(),
|
||||||
|
ERRMSG_FOOTER);
|
||||||
|
client->getNetwork()->close();
|
||||||
|
client->disconnected();
|
||||||
|
|
||||||
|
/*
|
||||||
client->getNetwork()->close();
|
client->getNetwork()->close();
|
||||||
delete packet;
|
delete packet;
|
||||||
|
|
||||||
/* delete client when the client is not authorized & session is clean */
|
|
||||||
_gateway->getClientList()->erase(client);
|
|
||||||
|
|
||||||
if (client)
|
if (client)
|
||||||
{
|
{
|
||||||
client = client->getNextClient();
|
client = client->getNextClient();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (rc == -1)
|
else if (rc == -1)
|
||||||
{
|
{
|
||||||
@@ -165,7 +175,7 @@ void BrokerRecvTask::run(void)
|
|||||||
else if (rc == -3)
|
else if (rc == -3)
|
||||||
{
|
{
|
||||||
WRITELOG(
|
WRITELOG(
|
||||||
"%s BrokerRecvTask can't get memories for the packet %s%s\n",
|
"%s BrokerRecvTask can't allocate memories for the packet %s%s\n",
|
||||||
ERRMSG_HEADER,
|
ERRMSG_HEADER,
|
||||||
client->getClientId(),
|
client->getClientId(),
|
||||||
ERRMSG_FOOTER);
|
ERRMSG_FOOTER);
|
||||||
@@ -173,22 +183,26 @@ void BrokerRecvTask::run(void)
|
|||||||
|
|
||||||
delete packet;
|
delete packet;
|
||||||
|
|
||||||
if ((rc == -1 || rc == -2)
|
if ((rc == -1 || rc == -2)
|
||||||
&& (client->isActive()
|
&& (client->isActive()
|
||||||
|| client->isSleep()
|
|| client->isSleep()
|
||||||
|| client->isAwake()))
|
|| client->isAwake()))
|
||||||
{
|
{
|
||||||
/* disconnect the client */
|
/* disconnect the client */
|
||||||
|
/*
|
||||||
packet = new MQTTGWPacket();
|
packet = new MQTTGWPacket();
|
||||||
packet->setHeader(DISCONNECT);
|
packet->setHeader(DISCONNECT);
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setBrokerRecvEvent(client, packet);
|
ev->setBrokerRecvEvent(client, packet);
|
||||||
_gateway->getPacketEventQue()->post(ev);
|
_gateway->getPacketEventQue()->post(ev);
|
||||||
|
*/
|
||||||
|
client->getNetwork()->close();
|
||||||
|
client->disconnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nextClient: client = client->getNextClient();
|
nextClient: client = client->getNextClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ char* currentDateTime(void);
|
|||||||
=====================================*/
|
=====================================*/
|
||||||
ClientRecvTask::ClientRecvTask(Gateway* gateway)
|
ClientRecvTask::ClientRecvTask(Gateway* gateway)
|
||||||
{
|
{
|
||||||
_gateway = gateway;
|
_gateway = gateway;
|
||||||
_gateway->attach((Thread*) this);
|
_gateway->attach((Thread*) this);
|
||||||
_sensorNetwork = _gateway->getSensorNetwork();
|
_sensorNetwork = _gateway->getSensorNetwork();
|
||||||
setTaskName("ClientRecvTask");
|
setTaskName("ClientRecvTask");
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientRecvTask::~ClientRecvTask()
|
ClientRecvTask::~ClientRecvTask()
|
||||||
@@ -45,7 +45,7 @@ ClientRecvTask::~ClientRecvTask()
|
|||||||
*/
|
*/
|
||||||
void ClientRecvTask::initialize(int argc, char** argv)
|
void ClientRecvTask::initialize(int argc, char** argv)
|
||||||
{
|
{
|
||||||
_sensorNetwork->initialize();
|
_sensorNetwork->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -55,287 +55,307 @@ void ClientRecvTask::initialize(int argc, char** argv)
|
|||||||
*/
|
*/
|
||||||
void ClientRecvTask::run()
|
void ClientRecvTask::run()
|
||||||
{
|
{
|
||||||
Event* ev = nullptr;
|
Event* ev = nullptr;
|
||||||
AdapterManager* adpMgr = _gateway->getAdapterManager();
|
AdapterManager* adpMgr = _gateway->getAdapterManager();
|
||||||
QoSm1Proxy* qosm1Proxy = adpMgr->getQoSm1Proxy();
|
QoSm1Proxy* qosm1Proxy = adpMgr->getQoSm1Proxy();
|
||||||
int clientType =
|
int clientType =
|
||||||
adpMgr->isAggregaterActive() ? AGGREGATER_TYPE : TRANSPEARENT_TYPE;
|
adpMgr->isAggregaterActive() ? AGGREGATER_TYPE : TRANSPEARENT_TYPE;
|
||||||
ClientList* clientList = _gateway->getClientList();
|
ClientList* clientList = _gateway->getClientList();
|
||||||
EventQue* packetEventQue = _gateway->getPacketEventQue();
|
EventQue* packetEventQue = _gateway->getPacketEventQue();
|
||||||
|
EventQue* clientsendQue = _gateway->getClientSendQue();
|
||||||
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Client* client = nullptr;
|
Client* client = nullptr;
|
||||||
Forwarder* fwd = nullptr;
|
Forwarder* fwd = nullptr;
|
||||||
WirelessNodeId nodeId;
|
WirelessNodeId nodeId;
|
||||||
|
|
||||||
MQTTSNPacket* packet = new MQTTSNPacket();
|
MQTTSNPacket* packet = new MQTTSNPacket();
|
||||||
int packetLen = packet->recv(_sensorNetwork);
|
int packetLen = packet->recv(_sensorNetwork);
|
||||||
|
|
||||||
if (CHK_SIGINT)
|
if (CHK_SIGINT)
|
||||||
{
|
{
|
||||||
WRITELOG("%s %s stopped.\n", currentDateTime(), getTaskName());
|
WRITELOG("%s %s stopped.\n", currentDateTime(), getTaskName());
|
||||||
delete packet;
|
delete packet;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packetLen < 2)
|
if (packetLen < 2)
|
||||||
{
|
{
|
||||||
delete packet;
|
delete packet;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet->getType() <= MQTTSN_ADVERTISE
|
if (packet->getType() <= MQTTSN_ADVERTISE
|
||||||
|| packet->getType() == MQTTSN_GWINFO)
|
|| packet->getType() == MQTTSN_GWINFO)
|
||||||
{
|
{
|
||||||
delete packet;
|
delete packet;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet->getType() == MQTTSN_SEARCHGW)
|
if (packet->getType() == MQTTSN_SEARCHGW)
|
||||||
{
|
{
|
||||||
/* write log and post Event */
|
/* write log and post Event */
|
||||||
log(0, packet, 0);
|
log(0, packet, 0);
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setBrodcastEvent(packet);
|
ev->setBrodcastEvent(packet);
|
||||||
packetEventQue->post(ev);
|
packetEventQue->post(ev);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorNetAddress* senderAddr =
|
SensorNetAddress* senderAddr =
|
||||||
_gateway->getSensorNetwork()->getSenderAddress();
|
_gateway->getSensorNetwork()->getSenderAddress();
|
||||||
|
|
||||||
if (packet->getType() == MQTTSN_ENCAPSULATED)
|
if (packet->getType() == MQTTSN_ENCAPSULATED)
|
||||||
{
|
{
|
||||||
fwd =
|
fwd =
|
||||||
_gateway->getAdapterManager()->getForwarderList()->getForwarder(
|
_gateway->getAdapterManager()->getForwarderList()->getForwarder(
|
||||||
senderAddr);
|
senderAddr);
|
||||||
|
|
||||||
if (fwd != nullptr)
|
if (fwd != nullptr)
|
||||||
{
|
{
|
||||||
MQTTSNString fwdName = MQTTSNString_initializer;
|
MQTTSNString fwdName = MQTTSNString_initializer;
|
||||||
fwdName.cstring = const_cast<char *>(fwd->getName());
|
fwdName.cstring = const_cast<char *>(fwd->getName());
|
||||||
log(0, packet, &fwdName);
|
log(0, packet, &fwdName);
|
||||||
|
|
||||||
/* get the packet from the encapsulation message */
|
/* get the packet from the encapsulation message */
|
||||||
MQTTSNGWEncapsulatedPacket encap;
|
MQTTSNGWEncapsulatedPacket encap;
|
||||||
encap.desirialize(packet->getPacketData(),
|
encap.desirialize(packet->getPacketData(),
|
||||||
packet->getPacketLength());
|
packet->getPacketLength());
|
||||||
nodeId.setId(encap.getWirelessNodeId());
|
nodeId.setId(encap.getWirelessNodeId());
|
||||||
client = fwd->getClient(&nodeId);
|
client = fwd->getClient(&nodeId);
|
||||||
packet = encap.getMQTTSNPacket();
|
packet = encap.getMQTTSNPacket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Check the client belonging to QoS-1Proxy ? */
|
/* Check the client belonging to QoS-1Proxy ? */
|
||||||
|
|
||||||
if (qosm1Proxy->isActive())
|
if (qosm1Proxy->isActive())
|
||||||
{
|
{
|
||||||
const char* clientName = qosm1Proxy->getClientId(senderAddr);
|
const char* clientName = qosm1Proxy->getClientId(senderAddr);
|
||||||
|
|
||||||
if (clientName != nullptr)
|
if (clientName != nullptr)
|
||||||
{
|
{
|
||||||
client = qosm1Proxy->getClient();
|
client = qosm1Proxy->getClient();
|
||||||
|
|
||||||
if (!packet->isQoSMinusPUBLISH())
|
if (!packet->isQoSMinusPUBLISH())
|
||||||
{
|
{
|
||||||
log(clientName, packet);
|
log(clientName, packet);
|
||||||
WRITELOG(
|
WRITELOG(
|
||||||
"%s %s %s can send only PUBLISH with QoS-1.%s\n",
|
"%s %s %s can send only PUBLISH with QoS-1.%s\n",
|
||||||
ERRMSG_HEADER, clientName,
|
ERRMSG_HEADER, clientName,
|
||||||
senderAddr->sprint(buf), ERRMSG_FOOTER);
|
senderAddr->sprint(buf), ERRMSG_FOOTER);
|
||||||
delete packet;
|
delete packet;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client == nullptr)
|
if (client == nullptr)
|
||||||
{
|
{
|
||||||
client = _gateway->getClientList()->getClient(senderAddr);
|
client = _gateway->getClientList()->getClient(senderAddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client != nullptr)
|
if (client != nullptr)
|
||||||
{
|
{
|
||||||
/* write log and post Event */
|
log(client, packet, 0);
|
||||||
log(client, packet, 0);
|
|
||||||
ev = new Event();
|
|
||||||
ev->setClientRecvEvent(client, packet);
|
|
||||||
packetEventQue->post(ev);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* new client */
|
|
||||||
if (packet->getType() == MQTTSN_CONNECT)
|
|
||||||
{
|
|
||||||
MQTTSNPacket_connectData data;
|
|
||||||
memset(&data, 0, sizeof(MQTTSNPacket_connectData));
|
|
||||||
if (!packet->getCONNECT(&data))
|
|
||||||
{
|
|
||||||
log(0, packet, &data.clientID);
|
|
||||||
WRITELOG("%s CONNECT message form %s is incorrect.%s\n",
|
|
||||||
ERRMSG_HEADER, senderAddr->sprint(buf),
|
|
||||||
ERRMSG_FOOTER);
|
|
||||||
delete packet;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
client = clientList->getClient(&data.clientID);
|
if (client->isDisconnect() && packet->getType() != MQTTSN_CONNECT)
|
||||||
|
{
|
||||||
|
WRITELOG(
|
||||||
|
"%s MQTTSNGWClientRecvTask %s is not connecting.%s\n",
|
||||||
|
ERRMSG_HEADER,
|
||||||
|
client->getClientId(), ERRMSG_FOOTER);
|
||||||
|
|
||||||
if (fwd != nullptr)
|
/* send DISCONNECT to the client, if it is not connected */
|
||||||
{
|
MQTTSNPacket* snPacket = new MQTTSNPacket();
|
||||||
if (client == nullptr)
|
snPacket->setDISCONNECT(0);
|
||||||
{
|
ev = new Event();
|
||||||
/* create a new client */
|
ev->setClientSendEvent(client, snPacket);
|
||||||
client = clientList->createClient(0, &data.clientID,
|
clientsendQue->post(ev);
|
||||||
clientType);
|
delete packet;
|
||||||
}
|
continue;
|
||||||
/* Add to a forwarded client list of forwarder. */
|
}
|
||||||
fwd->addClient(client, &nodeId);
|
else
|
||||||
}
|
{
|
||||||
else
|
ev = new Event();
|
||||||
{
|
ev->setClientRecvEvent(client, packet);
|
||||||
if (client)
|
packetEventQue->post(ev);
|
||||||
{
|
}
|
||||||
/* Authentication is not required */
|
}
|
||||||
if (_gateway->getGWParams()->clientAuthentication
|
else
|
||||||
== false)
|
{
|
||||||
{
|
/* new client */
|
||||||
client->setClientAddress(senderAddr);
|
if (packet->getType() == MQTTSN_CONNECT)
|
||||||
}
|
{
|
||||||
}
|
MQTTSNPacket_connectData data;
|
||||||
else
|
memset(&data, 0, sizeof(MQTTSNPacket_connectData));
|
||||||
{
|
if (!packet->getCONNECT(&data))
|
||||||
/* create a new client */
|
{
|
||||||
client = clientList->createClient(senderAddr,
|
log(0, packet, &data.clientID);
|
||||||
&data.clientID, clientType);
|
WRITELOG("%s CONNECT message form %s is incorrect.%s\n",
|
||||||
}
|
ERRMSG_HEADER, senderAddr->sprint(buf),
|
||||||
}
|
ERRMSG_FOOTER);
|
||||||
|
delete packet;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
log(client, packet, &data.clientID);
|
client = clientList->getClient(&data.clientID);
|
||||||
|
|
||||||
if (client == nullptr)
|
if (fwd != nullptr)
|
||||||
{
|
{
|
||||||
WRITELOG(
|
if (client == nullptr)
|
||||||
"%s Client(%s) was rejected. CONNECT message has been discarded.%s\n",
|
{
|
||||||
ERRMSG_HEADER, senderAddr->sprint(buf),
|
/* create a new client */
|
||||||
ERRMSG_FOOTER);
|
client = clientList->createClient(0, &data.clientID,
|
||||||
delete packet;
|
clientType);
|
||||||
continue;
|
}
|
||||||
}
|
/* Add to a forwarded client list of forwarder. */
|
||||||
|
fwd->addClient(client, &nodeId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (client)
|
||||||
|
{
|
||||||
|
/* Authentication is not required */
|
||||||
|
if (_gateway->getGWParams()->clientAuthentication
|
||||||
|
== false)
|
||||||
|
{
|
||||||
|
client->setClientAddress(senderAddr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* create a new client */
|
||||||
|
client = clientList->createClient(senderAddr,
|
||||||
|
&data.clientID, clientType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* post Client RecvEvent */
|
log(client, packet, &data.clientID);
|
||||||
ev = new Event();
|
|
||||||
ev->setClientRecvEvent(client, packet);
|
if (client == nullptr)
|
||||||
packetEventQue->post(ev);
|
{
|
||||||
}
|
WRITELOG(
|
||||||
else
|
"%s Client(%s) was rejected. CONNECT message has been discarded.%s\n",
|
||||||
{
|
ERRMSG_HEADER, senderAddr->sprint(buf),
|
||||||
log(client, packet, 0);
|
ERRMSG_FOOTER);
|
||||||
if (packet->getType() == MQTTSN_ENCAPSULATED)
|
delete packet;
|
||||||
{
|
continue;
|
||||||
WRITELOG(
|
}
|
||||||
"%s MQTTSNGWClientRecvTask Forwarder(%s) is not declared by ClientList file. message has been discarded.%s\n",
|
|
||||||
ERRMSG_HEADER,
|
/* post Client RecvEvent */
|
||||||
_sensorNetwork->getSenderAddress()->sprint(buf),
|
ev = new Event();
|
||||||
ERRMSG_FOOTER);
|
ev->setClientRecvEvent(client, packet);
|
||||||
}
|
packetEventQue->post(ev);
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
WRITELOG(
|
{
|
||||||
"%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n",
|
log(client, packet, 0);
|
||||||
ERRMSG_HEADER, senderAddr->sprint(buf),
|
if (packet->getType() == MQTTSN_ENCAPSULATED)
|
||||||
ERRMSG_FOOTER);
|
{
|
||||||
}
|
WRITELOG(
|
||||||
delete packet;
|
"%s MQTTSNGWClientRecvTask Forwarder(%s) is not declared by ClientList file. message has been discarded.%s\n",
|
||||||
}
|
ERRMSG_HEADER,
|
||||||
}
|
_sensorNetwork->getSenderAddress()->sprint(buf),
|
||||||
}
|
ERRMSG_FOOTER);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WRITELOG(
|
||||||
|
"%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n",
|
||||||
|
ERRMSG_HEADER,
|
||||||
|
senderAddr->sprint(buf), ERRMSG_FOOTER);
|
||||||
|
}
|
||||||
|
delete packet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientRecvTask::log(Client* client, MQTTSNPacket* packet, MQTTSNString* id)
|
void ClientRecvTask::log(Client* client, MQTTSNPacket* packet, MQTTSNString* id)
|
||||||
{
|
{
|
||||||
const char* clientId;
|
const char* clientId;
|
||||||
char cstr[MAX_CLIENTID_LENGTH + 1];
|
char cstr[MAX_CLIENTID_LENGTH + 1];
|
||||||
|
|
||||||
if (id)
|
if (id)
|
||||||
{
|
{
|
||||||
if (id->cstring)
|
if (id->cstring)
|
||||||
{
|
{
|
||||||
strncpy(cstr, id->cstring, strlen(id->cstring));
|
strncpy(cstr, id->cstring, strlen(id->cstring));
|
||||||
clientId = cstr;
|
clientId = cstr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset((void*) cstr, 0, id->lenstring.len + 1);
|
memset((void*) cstr, 0, id->lenstring.len + 1);
|
||||||
strncpy(cstr, id->lenstring.data, id->lenstring.len);
|
strncpy(cstr, id->lenstring.data, id->lenstring.len);
|
||||||
clientId = cstr;
|
clientId = cstr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (client)
|
else if (client)
|
||||||
{
|
{
|
||||||
clientId = client->getClientId();
|
clientId = client->getClientId();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clientId = UNKNOWNCL;
|
clientId = UNKNOWNCL;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(clientId, packet);
|
log(clientId, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientRecvTask::log(const char* clientId, MQTTSNPacket* packet)
|
void ClientRecvTask::log(const char* clientId, MQTTSNPacket* packet)
|
||||||
{
|
{
|
||||||
char pbuf[ SIZE_OF_LOG_PACKET * 3 + 1];
|
char pbuf[ SIZE_OF_LOG_PACKET * 3 + 1];
|
||||||
char msgId[6];
|
char msgId[6];
|
||||||
|
|
||||||
switch (packet->getType())
|
switch (packet->getType())
|
||||||
{
|
{
|
||||||
case MQTTSN_SEARCHGW:
|
case MQTTSN_SEARCHGW:
|
||||||
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(),
|
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(),
|
||||||
LEFTARROW, CLIENT, packet->print(pbuf));
|
LEFTARROW, CLIENT, packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
case MQTTSN_CONNECT:
|
case MQTTSN_CONNECT:
|
||||||
case MQTTSN_PINGREQ:
|
case MQTTSN_PINGREQ:
|
||||||
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(),
|
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(),
|
||||||
LEFTARROW, clientId, packet->print(pbuf));
|
LEFTARROW, clientId, packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
case MQTTSN_DISCONNECT:
|
case MQTTSN_DISCONNECT:
|
||||||
case MQTTSN_WILLTOPICUPD:
|
case MQTTSN_WILLTOPICUPD:
|
||||||
case MQTTSN_WILLMSGUPD:
|
case MQTTSN_WILLMSGUPD:
|
||||||
case MQTTSN_WILLTOPIC:
|
case MQTTSN_WILLTOPIC:
|
||||||
case MQTTSN_WILLMSG:
|
case MQTTSN_WILLMSG:
|
||||||
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW,
|
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW,
|
||||||
clientId, packet->print(pbuf));
|
clientId, packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
case MQTTSN_PUBLISH:
|
case MQTTSN_PUBLISH:
|
||||||
case MQTTSN_REGISTER:
|
case MQTTSN_REGISTER:
|
||||||
case MQTTSN_SUBSCRIBE:
|
case MQTTSN_SUBSCRIBE:
|
||||||
case MQTTSN_UNSUBSCRIBE:
|
case MQTTSN_UNSUBSCRIBE:
|
||||||
WRITELOG(FORMAT_G_MSGID_G_G_NL, currentDateTime(), packet->getName(),
|
WRITELOG(FORMAT_G_MSGID_G_G_NL, currentDateTime(), packet->getName(),
|
||||||
packet->getMsgId(msgId), LEFTARROW, clientId,
|
packet->getMsgId(msgId), LEFTARROW, clientId,
|
||||||
packet->print(pbuf));
|
packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
case MQTTSN_REGACK:
|
case MQTTSN_REGACK:
|
||||||
case MQTTSN_PUBACK:
|
case MQTTSN_PUBACK:
|
||||||
case MQTTSN_PUBREC:
|
case MQTTSN_PUBREC:
|
||||||
case MQTTSN_PUBREL:
|
case MQTTSN_PUBREL:
|
||||||
case MQTTSN_PUBCOMP:
|
case MQTTSN_PUBCOMP:
|
||||||
WRITELOG(FORMAT_G_MSGID_G_G, currentDateTime(), packet->getName(),
|
WRITELOG(FORMAT_G_MSGID_G_G, currentDateTime(), packet->getName(),
|
||||||
packet->getMsgId(msgId), LEFTARROW, clientId,
|
packet->getMsgId(msgId), LEFTARROW, clientId,
|
||||||
packet->print(pbuf));
|
packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
case MQTTSN_ENCAPSULATED:
|
case MQTTSN_ENCAPSULATED:
|
||||||
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW,
|
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW,
|
||||||
clientId, packet->print(pbuf));
|
clientId, packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WRITELOG(FORMAT_W_NL, currentDateTime(), packet->getName(), LEFTARROW,
|
WRITELOG(FORMAT_W_NL, currentDateTime(), packet->getName(), LEFTARROW,
|
||||||
clientId, packet->print(pbuf));
|
clientId, packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,12 +121,14 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client,
|
|||||||
{
|
{
|
||||||
pub.topic = (char*) topic->getTopicName()->data();
|
pub.topic = (char*) topic->getTopicName()->data();
|
||||||
pub.topiclen = topic->getTopicName()->length();
|
pub.topiclen = topic->getTopicName()->length();
|
||||||
|
topicid.data.long_.name = pub.topic;
|
||||||
|
topicid.data.long_.len = pub.topiclen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Save a msgId & a TopicId pare for PUBACK */
|
/* Save a msgId & a TopicId pare for PUBACK */
|
||||||
if (msgId && qos > 0 && qos < 3)
|
if (msgId && qos > 0 && qos < 3)
|
||||||
{
|
{
|
||||||
client->setWaitedPubTopicId(msgId, topicid.data.id, &topicid);
|
client->setWaitedPubTopicId(msgId, topicid.data.id, &topicid);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub.payload = (char*) payload;
|
pub.payload = (char*) payload;
|
||||||
|
|||||||
Reference in New Issue
Block a user