mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-16 08:56:51 +01:00
upgrade and bugfix for a test
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -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)
|
||||
{
|
||||
D_MQTTLOG("...Gateway reconnect\r\n");
|
||||
_status = GW_DISCONNECTED;
|
||||
connect();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
_gwProxy.connect();
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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(...)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
theClient->getGwProxy()->connect();
|
||||
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;
|
||||
|
||||
@@ -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,7 +85,8 @@ private:
|
||||
PubElement* _last;
|
||||
uint8_t _elmCnt;
|
||||
uint8_t _publishedFlg;
|
||||
uint8_t _autoConnectFlg;
|
||||
};
|
||||
|
||||
|
||||
} /* tomyAsyncClient */
|
||||
#endif /* PUBLISHMANAGER_H_ */
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user