upgrade and bugfix for a test

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2021-05-15 18:32:05 +09:00
parent 9c9de103df
commit f079211ea7
13 changed files with 448 additions and 334 deletions

View File

@@ -133,7 +133,7 @@
<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>
@@ -273,7 +273,7 @@
<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"/>

View File

@@ -51,25 +51,25 @@ extern LScreen* theScreen;
/*------------------------------------------------------
* UDP Configuration (theNetcon)
*------------------------------------------------------*/
UDPCONF = {
"GatewayTestClient", // ClientId
{225,1,1,1}, // Multicast group IP
UDPCONF =
{ "GatewayTestClient", // ClientId
{ 225, 1, 1, 1 }, // Multicast group IP
1883, // Multicast group Port
20020, // Local PortNo
};
};
/*------------------------------------------------------
* Client Configuration (theMqcon)
*------------------------------------------------------*/
MQTTSNCONF = {
60, //KeepAlive [seconds]
MQTTSNCONF =
{ 60, //KeepAlive [seconds]
true, //Clean session
300, //Sleep duration [seconds]
"", //WillTopic
"", //WillMessage
0, //WillQos
false //WillRetain
};
};
/*------------------------------------------------------
* Define Topics
@@ -83,32 +83,31 @@ const char* topic52 = "ty4tw/topic5/2";
const char* topic53 = "ty4tw/topic5/3";
const char* topic50 = "ty4tw/topic5/+";
/*------------------------------------------------------
* Callback routines for Subscribed Topics
*------------------------------------------------------*/
int on_Topic01(uint8_t* pload, uint16_t ploadlen)
{
DISPLAY("\n\nTopic1 recv.\n");
char c = pload[ploadlen-1];
pload[ploadlen-1]= 0; // set null terminator
DISPLAY("Payload -->%s%c<--\n\n",pload, c);
char c = pload[ploadlen - 1];
pload[ploadlen - 1] = 0; // set null terminator
DISPLAY("Payload -->%s%c<--\n\n", pload, c);
return 0;
}
int on_Topic02(uint8_t* pload, uint16_t ploadlen)
{
DISPLAY("\n\nTopic2 recv.\n");
pload[ploadlen-1]= 0; // set null terminator
DISPLAY("Payload -->%s <--\n\n",pload);
pload[ploadlen - 1] = 0; // set null terminator
DISPLAY("Payload -->%s <--\n\n", pload);
return 0;
}
int on_Topic03(uint8_t* pload, uint16_t ploadlen)
{
DISPLAY("\n\nNew callback recv Topic3\n");
pload[ploadlen-1]= 0; // set null terminator
DISPLAY("Payload -->%s <--\n\n",pload);
pload[ploadlen - 1] = 0; // set null terminator
DISPLAY("Payload -->%s <--\n\n", pload);
return 0;
}
@@ -116,12 +115,12 @@ int on_Topic03(uint8_t* pload, uint16_t ploadlen)
* A Link list of Callback routines and Topics
*------------------------------------------------------*/
SUBSCRIBE_LIST = {// e.g. SUB(TopicType, topicName, TopicId, callback, QoSx),
SUBSCRIBE_LIST =
{ // e.g. SUB(TopicType, topicName, TopicId, callback, QoSx),
SUB(MQTTSN_TOPIC_TYPE_NORMAL, topic1, 0, on_Topic01, QoS1),
SUB(MQTTSN_TOPIC_TYPE_NORMAL, topic2, 0, on_Topic02, QoS1),
END_OF_SUBSCRIBE_LIST
};
};
/*------------------------------------------------------
* Test functions
@@ -135,7 +134,7 @@ void publishTopic1(void)
{
char payload[300];
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)
@@ -147,11 +146,9 @@ void publishTopic2(void)
{
char payload[300];
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)
{
UNSUBSCRIBE(topic2);
@@ -167,7 +164,7 @@ void test3(void)
char payload[300];
sprintf(payload, "TEST3 ");
uint8_t qos = 0;
PUBLISH(topic2,(uint8_t*)payload, strlen(payload), qos);
PUBLISH(topic2, (uint8_t* )payload, strlen(payload), qos);
}
void disconnect(void)
@@ -180,40 +177,64 @@ void asleep(void)
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
* line 23 of LMqttsnClientApp.h is commented out.
* //#define CLIENT_MODE
*------------------------------------------------------*/
TEST_LIST = {// e.g. TEST( Label, Test),
TEST("Step0:Subscribe predef topic1", subscribePredefTopic1),
TEST("Step1:Publish topic1", publishTopic1),
TEST("Step2:Publish topic2", publishTopic2),
TEST("Step3:Subscribe PreDefined topic10. ID is not defined.", subscribeTopic10),
TEST_LIST =
{ // e.g. TEST( Label, Test),
TEST("Step0:Connect", connect),
TEST("Step1:Subscribe list", onconnect),
TEST("Step2:Subscribe predef topic1", subscribePredefTopic1),
TEST("Step3:Publish topic1", publishTopic1),
TEST("Step4:Publish topic2", publishTopic2),
TEST("Step5:Unsubscribe topic2", unsubscribe),
TEST("Step5:Subscribe PreDefined topic10. ID is not defined.", subscribeTopic10),
TEST("Step6:Publish topic2", publishTopic2),
TEST("Step7:subscribe again", subscribechangeCallback),
TEST("Step7:Unsubscribe topic2", unsubscribe),
TEST("Step8:Publish topic2", publishTopic2),
TEST("Step9:Sleep ", asleep),
TEST("Step10:Publish topic1", publishTopic1),
TEST("Step11:Disconnect", disconnect),
TEST("Step9:subscribe again", subscribechangeCallback),
TEST("Step10:Publish topic2", publishTopic2),
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
* LMqttsnClientApp.h is uncommented.
* #define CLIENT_MODE
*------------------------------------------------------*/
TASK_LIST = {// e.g. TASK( task, executing duration in second),
TASK(publishTopic1, 4), // publishTopic1() is executed every 4 seconds
TASK(publishTopic2, 7), // publishTopic2() is executed every 7 seconds
TASK_LIST =
{ // e.g. TASK( task, executing duration in second),
TASK(publishTopic1, 4),// publishTopic1() is executed every 4 seconds
TASK(publishTopic2, 7),// publishTopic2() is executed every 7 seconds
END_OF_TASK_LIST
};
};
/*------------------------------------------------------
* Initialize function
@@ -223,5 +244,4 @@ void setup(void)
SetForwarderMode(false);
}
/***************** END OF PROGRAM ********************/

View File

@@ -57,6 +57,8 @@ LGwProxy::LGwProxy()
_initialized = 0;
_isForwarderMode = false;
_isQoSMinus1Mode = false;
_isPingReqMode = true;
_isAutoConnectMode = true;
}
LGwProxy::~LGwProxy()
@@ -231,9 +233,12 @@ int LGwProxy::getConnectResponce(void)
void LGwProxy::reconnect(void)
{
if (_isAutoConnectMode)
{
D_MQTTLOG("...Gateway reconnect\r\n");
_status = GW_DISCONNECTED;
connect();
}
}
void LGwProxy::disconnect(uint16_t secs)
@@ -395,7 +400,7 @@ int LGwProxy::getMessage(void)
}
else if (_mqttsnMsg[0] == MQTTSN_TYPE_DISCONNECT)
{
_status = GW_LOST;
_status = GW_DISCONNECTED;
_gwAliveTimer.stop();
_keepAliveTimer.stop();
}
@@ -586,7 +591,7 @@ uint16_t LGwProxy::getNextMsgId(void)
void LGwProxy::checkPingReq(void)
{
if ( _isQoSMinus1Mode )
if (_isQoSMinus1Mode || _isPingReqMode == false)
{
return;
}
@@ -671,3 +676,18 @@ void LGwProxy::setQoSMinus1Mode(bool valid)
{
_isQoSMinus1Mode = valid;
}
void LGwProxy::setPingReqMode(bool valid)
{
_isPingReqMode = valid;
}
void LGwProxy::setAutoConnectMode(bool valid)
{
_isAutoConnectMode = valid;
}
uint8_t LGwProxy::getStatus(void)
{
return _status;
}

View File

@@ -67,6 +67,8 @@ public:
void setAdvertiseDuration(uint16_t duration);
void setForwarderMode(bool valid);
void setQoSMinus1Mode(bool valid);
void setPingReqMode(bool valid);
void setAutoConnectMode(bool valid);
void reconnect(void);
int writeMsg(const uint8_t* msg);
void setPingReqTimer(void);
@@ -74,6 +76,7 @@ public:
LTopicTable* getTopicTable(void);
LRegisterManager* getRegisterManager(void);
const char* getClientId(void);
uint8_t getStatus(void);
private:
int readMsg(void);
void writeGwMsg(void);
@@ -111,6 +114,8 @@ private:
uint16_t _tWake;
bool _isForwarderMode;
bool _isQoSMinus1Mode;
bool _isPingReqMode;
bool _isAutoConnectMode;
char _msg[MQTTSN_MAX_MSG_LENGTH + 1];
};

View File

@@ -77,6 +77,8 @@ int main(int argc, char** argv)
break;
}
}
theClient->setAutoConnectMode(false);
theClient->getPublishManager()->setAutoConnectMode(false);
#endif
setup();
@@ -98,7 +100,7 @@ int main(int argc, char** argv)
======================================*/
LMqttsnClient::LMqttsnClient()
{
_isAutoConnect = true;
}
LMqttsnClient::~LMqttsnClient()
@@ -205,10 +207,20 @@ void LMqttsnClient::disconnect(uint16_t sleepInSecs)
void LMqttsnClient::run()
{
if (_isAutoConnect)
{
_gwProxy.connect();
}
_taskMgr.run();
}
void LMqttsnClient::setAutoConnectMode(uint8_t flg)
{
_isAutoConnect = flg;
_pubMgr.setAutoConnectMode(flg);
_gwProxy.setAutoConnectMode(flg);
}
void LMqttsnClient::setSleepMode(uint32_t duration)
{
// ToDo: set WDT and sleep mode
@@ -227,7 +239,10 @@ void LMqttsnClient::setSleepDuration(uint32_t duration)
void LMqttsnClient::onConnect(void)
{
if (_isAutoConnect)
{
_subMgr.onConnect();
}
}
const char* LMqttsnClient::getClientId(void)

View File

@@ -63,6 +63,7 @@ public:
void addTask(bool test);
void setSleepDuration(uint32_t duration);
void setSleepMode(uint32_t duration);
void setAutoConnectMode(uint8_t flg);
void sleep(void);
const char* getClientId(void);
uint16_t getTopicId(const char* topicName);
@@ -78,6 +79,7 @@ private:
LSubscribeManager _subMgr;
LGwProxy _gwProxy;
uint32_t _sleepDuration;
uint8_t _isAutoConnect;
};

View File

@@ -92,6 +92,7 @@ typedef enum
#define SUBSCRIBE(...) theClient->subscribe(__VA_ARGS__)
#define UNSUBSCRIBE(...) theClient->unsubscribe(__VA_ARGS__)
#define DISCONNECT(...) theClient->disconnect(__VA_ARGS__)
#define ONCONNECT() theClient->getSubscribeManager()->onConnect()
#define TASK_LIST TaskList theTaskList[]
#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 UDPCONF LUdpConfig theNetcon
#define MQTTSNCONF LMqttsnConfig theMqcon
#define SetForwarderMode(...) theClient->getGwProxy()->setForwarderMode(__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
#define DISPLAY(...)

View File

@@ -44,6 +44,7 @@ LPublishManager::LPublishManager()
_last = 0;
_elmCnt = 0;
_publishedFlg = SAVE_TASK_INDEX;
_autoConnectFlg = false;
}
LPublishManager::~LPublishManager()
@@ -115,7 +116,10 @@ void LPublishManager::sendPublish(PubElement* elm)
return;
}
if (_autoConnectFlg)
{
theClient->getGwProxy()->connect();
}
uint8_t msg[MQTTSN_MAX_MSG_LENGTH + 1];
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* elm = _first;

View File

@@ -70,6 +70,7 @@ public:
void sendSuspend(const char* topicName, uint16_t topicId, uint8_t topicType);
bool isDone(void);
bool isMaxFlight(void);
void setAutoConnectMode(bool);
private:
PubElement* getElement(uint16_t msgId);
PubElement* getElement(const char* topicName);
@@ -84,6 +85,7 @@ private:
PubElement* _last;
uint8_t _elmCnt;
uint8_t _publishedFlg;
uint8_t _autoConnectFlg;
};
} /* tomyAsyncClient */

View File

@@ -122,6 +122,7 @@ void LSubscribeManager::send(SubElement* elm)
{
return;
}
uint8_t msg[MQTTSN_MAX_MSG_LENGTH + 1];
if (elm->topicType == MQTTSN_TOPIC_TYPE_PREDEFINED)
{

View File

@@ -100,6 +100,7 @@ void BrokerRecvTask::run(void)
{
/* Check sockets is ready to read */
int activity = select(maxSock + 1, &rset, 0, 0, &timeout);
if (activity > 0)
{
client = _gateway->getClientList()->getClient(0);
@@ -134,17 +135,26 @@ void BrokerRecvTask::run(void)
{
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();
delete packet;
/* delete client when the client is not authorized & session is clean */
_gateway->getClientList()->erase(client);
if (client)
{
client = client->getNextClient();
}
continue;
*/
}
else if (rc == -1)
{
@@ -165,7 +175,7 @@ void BrokerRecvTask::run(void)
else if (rc == -3)
{
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,
client->getClientId(),
ERRMSG_FOOTER);
@@ -179,11 +189,15 @@ void BrokerRecvTask::run(void)
|| client->isAwake()))
{
/* disconnect the client */
/*
packet = new MQTTGWPacket();
packet->setHeader(DISCONNECT);
ev = new Event();
ev->setBrokerRecvEvent(client, packet);
_gateway->getPacketEventQue()->post(ev);
*/
client->getNetwork()->close();
client->disconnected();
}
}
}

View File

@@ -62,6 +62,7 @@ void ClientRecvTask::run()
adpMgr->isAggregaterActive() ? AGGREGATER_TYPE : TRANSPEARENT_TYPE;
ClientList* clientList = _gateway->getClientList();
EventQue* packetEventQue = _gateway->getPacketEventQue();
EventQue* clientsendQue = _gateway->getClientSendQue();
char buf[128];
@@ -161,12 +162,31 @@ void ClientRecvTask::run()
if (client != nullptr)
{
/* write log and post Event */
log(client, packet, 0);
if (client->isDisconnect() && packet->getType() != MQTTSN_CONNECT)
{
WRITELOG(
"%s MQTTSNGWClientRecvTask %s is not connecting.%s\n",
ERRMSG_HEADER,
client->getClientId(), ERRMSG_FOOTER);
/* send DISCONNECT to the client, if it is not connected */
MQTTSNPacket* snPacket = new MQTTSNPacket();
snPacket->setDISCONNECT(0);
ev = new Event();
ev->setClientSendEvent(client, snPacket);
clientsendQue->post(ev);
delete packet;
continue;
}
else
{
ev = new Event();
ev->setClientRecvEvent(client, packet);
packetEventQue->post(ev);
}
}
else
{
/* new client */
@@ -248,8 +268,8 @@ void ClientRecvTask::run()
{
WRITELOG(
"%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n",
ERRMSG_HEADER, senderAddr->sprint(buf),
ERRMSG_FOOTER);
ERRMSG_HEADER,
senderAddr->sprint(buf), ERRMSG_FOOTER);
}
delete packet;
}

View File

@@ -121,6 +121,8 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client,
{
pub.topic = (char*) topic->getTopicName()->data();
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 */