mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-17 01:16:52 +01:00
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "LMqttsnClientApp.h"
|
#include "LMqttsnClientApp.h"
|
||||||
#include "LNetworkUdp.h"
|
#include "LNetworkUdp.h"
|
||||||
@@ -92,11 +93,11 @@ private:
|
|||||||
uint8_t _gwId;
|
uint8_t _gwId;
|
||||||
uint16_t _tkeepAlive;
|
uint16_t _tkeepAlive;
|
||||||
uint32_t _tAdv;
|
uint32_t _tAdv;
|
||||||
uint32_t _sendUTC;
|
time_t _sendUTC;
|
||||||
int _retryCount;
|
int _retryCount;
|
||||||
int _connectRetry;
|
int _connectRetry;
|
||||||
uint8_t _status;
|
uint8_t _status;
|
||||||
uint32_t _pingSendUTC;
|
time_t _pingSendUTC;
|
||||||
uint8_t _pingRetryCount;
|
uint8_t _pingRetryCount;
|
||||||
uint8_t _pingStatus;
|
uint8_t _pingStatus;
|
||||||
LRegisterManager _regMgr;
|
LRegisterManager _regMgr;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#ifndef PUBLISHMANAGER_H_
|
#ifndef PUBLISHMANAGER_H_
|
||||||
#define PUBLISHMANAGER_H_
|
#define PUBLISHMANAGER_H_
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
#include "LMqttsnClientApp.h"
|
#include "LMqttsnClientApp.h"
|
||||||
#include "LTimer.h"
|
#include "LTimer.h"
|
||||||
#include "LTopicTable.h"
|
#include "LTopicTable.h"
|
||||||
@@ -42,7 +43,7 @@ typedef struct PubElement{
|
|||||||
const char* topicName;
|
const char* topicName;
|
||||||
uint8_t* payload;
|
uint8_t* payload;
|
||||||
uint16_t payloadlen;
|
uint16_t payloadlen;
|
||||||
uint32_t sendUTC;
|
time_t sendUTC;
|
||||||
int (*callback)(void);
|
int (*callback)(void);
|
||||||
int retryCount;
|
int retryCount;
|
||||||
int taskIndex;
|
int taskIndex;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#ifndef REGISTERQUE_H_
|
#ifndef REGISTERQUE_H_
|
||||||
#define REGISTERQUE_H_
|
#define REGISTERQUE_H_
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
#include "LMqttsnClientApp.h"
|
#include "LMqttsnClientApp.h"
|
||||||
|
|
||||||
namespace linuxAsyncClient {
|
namespace linuxAsyncClient {
|
||||||
@@ -27,7 +28,7 @@ typedef struct RegQueElement{
|
|||||||
const char* topicName;
|
const char* topicName;
|
||||||
uint16_t msgId;
|
uint16_t msgId;
|
||||||
int retryCount;
|
int retryCount;
|
||||||
uint32_t sendUTC;
|
time_t sendUTC;
|
||||||
RegQueElement* prev;
|
RegQueElement* prev;
|
||||||
RegQueElement* next;
|
RegQueElement* next;
|
||||||
}RegQueElement;
|
}RegQueElement;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "LMqttsnClientApp.h"
|
#include "LMqttsnClientApp.h"
|
||||||
#include "LRegisterManager.h"
|
#include "LRegisterManager.h"
|
||||||
@@ -33,7 +34,7 @@ typedef struct SubElement{
|
|||||||
TopicCallback callback;
|
TopicCallback callback;
|
||||||
const char* topicName;
|
const char* topicName;
|
||||||
uint16_t msgId;
|
uint16_t msgId;
|
||||||
uint32_t sendUTC;
|
time_t sendUTC;
|
||||||
uint16_t topicId;
|
uint16_t topicId;
|
||||||
uint8_t msgType;
|
uint8_t msgType;
|
||||||
uint8_t topicType;
|
uint8_t topicType;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "LMqttsnClientApp.h"
|
#include "LMqttsnClientApp.h"
|
||||||
#include "LTimer.h"
|
#include "LTimer.h"
|
||||||
@@ -29,8 +30,8 @@ namespace linuxAsyncClient {
|
|||||||
|
|
||||||
struct TaskList{
|
struct TaskList{
|
||||||
void (*callback)(void);
|
void (*callback)(void);
|
||||||
uint32_t interval;
|
time_t interval;
|
||||||
uint32_t prevTime;
|
time_t prevTime;
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "LMqttsnClientApp.h"
|
#include "LMqttsnClientApp.h"
|
||||||
#include "LTimer.h"
|
#include "LTimer.h"
|
||||||
|
|
||||||
using namespace std;
|
//using namespace std;
|
||||||
using namespace linuxAsyncClient;
|
using namespace linuxAsyncClient;
|
||||||
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#ifndef TIMER_H_
|
#ifndef TIMER_H_
|
||||||
#define TIMER_H_
|
#define TIMER_H_
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "LMqttsnClientApp.h"
|
#include "LMqttsnClientApp.h"
|
||||||
|
|
||||||
|
|||||||
@@ -62,14 +62,16 @@ $(SUBDIR)/MQTTSNUnsubscribeServer.c
|
|||||||
CXX := g++
|
CXX := g++
|
||||||
CPPFLAGS +=
|
CPPFLAGS +=
|
||||||
|
|
||||||
INCLUDES += -I$(SRCDIR) \
|
INCLUDE :=
|
||||||
|
INCLUDES += $(INCLUDE) -I$(SRCDIR) \
|
||||||
-I$(SRCDIR)/$(OS) \
|
-I$(SRCDIR)/$(OS) \
|
||||||
-I$(SRCDIR)/$(OS)/$(SENSORNET) \
|
-I$(SRCDIR)/$(OS)/$(SENSORNET) \
|
||||||
-I$(SUBDIR) \
|
-I$(SUBDIR) \
|
||||||
-I$(SRCDIR)/$(TEST)
|
-I$(SRCDIR)/$(TEST)
|
||||||
|
|
||||||
DEFS :=
|
DEFS :=
|
||||||
LIBS += -L/usr/local/lib
|
LIB :=
|
||||||
|
LIBS += $(LIB) -L/usr/local/lib
|
||||||
LDFLAGS :=
|
LDFLAGS :=
|
||||||
CXXFLAGS := -Wall -O3 -std=c++11
|
CXXFLAGS := -Wall -O3 -std=c++11
|
||||||
LDADD := -lpthread -lssl -lcrypto -lrt
|
LDADD := -lpthread -lssl -lcrypto -lrt
|
||||||
|
|||||||
@@ -500,6 +500,7 @@ char* MQTTGWPacket::getMsgId(char* pbuf)
|
|||||||
{
|
{
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
Publish pub;
|
Publish pub;
|
||||||
|
pub.msgId = 0;
|
||||||
getPUBLISH(&pub);
|
getPUBLISH(&pub);
|
||||||
if ( _header.bits.dup )
|
if ( _header.bits.dup )
|
||||||
{
|
{
|
||||||
@@ -533,8 +534,8 @@ char* MQTTGWPacket::print(char* pbuf)
|
|||||||
char* ptr = pbuf;
|
char* ptr = pbuf;
|
||||||
char** pptr = &pbuf;
|
char** pptr = &pbuf;
|
||||||
int len = getPacketData(packetData);
|
int len = getPacketData(packetData);
|
||||||
|
int size = len > SIZE_OF_LOG_PACKET ? SIZE_OF_LOG_PACKET : len;
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
sprintf(*pptr, " %02X", packetData[i]);
|
sprintf(*pptr, " %02X", packetData[i]);
|
||||||
*pptr += 3;
|
*pptr += 3;
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
|||||||
|
|
||||||
if (id > 0)
|
if (id > 0)
|
||||||
{
|
{
|
||||||
/* create REGACK */
|
/* create REGISTER */
|
||||||
MQTTSNPacket* regPacket = new MQTTSNPacket();
|
MQTTSNPacket* regPacket = new MQTTSNPacket();
|
||||||
|
|
||||||
MQTTSNString topicName;
|
MQTTSNString topicName;
|
||||||
@@ -143,6 +143,7 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
|||||||
(uint8_t) pub.header.bits.retain, (uint16_t) pub.msgId, topicId, (uint8_t*) pub.payload,
|
(uint8_t) pub.header.bits.retain, (uint16_t) pub.msgId, topicId, (uint8_t*) pub.payload,
|
||||||
pub.payloadlen);
|
pub.payloadlen);
|
||||||
client->getWaitREGACKPacketList()->setPacket(snPacket, regackMsgId);
|
client->getWaitREGACKPacketList()->setPacket(snPacket, regackMsgId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -227,6 +227,14 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
|
|||||||
{
|
{
|
||||||
client->setClientId(*clientId);
|
client->setClientId(*clientId);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MQTTSNString dummyId;
|
||||||
|
dummyId.cstring = strdup("");
|
||||||
|
dummyId.lenstring.len = 0;
|
||||||
|
client->setClientId(dummyId);
|
||||||
|
free(dummyId.cstring);
|
||||||
|
}
|
||||||
|
|
||||||
/* add the list */
|
/* add the list */
|
||||||
if ( _firstClient == 0 )
|
if ( _firstClient == 0 )
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ void PacketHandleTask::run()
|
|||||||
_mqttsnPublish->handleRegister(client, snPacket);
|
_mqttsnPublish->handleRegister(client, snPacket);
|
||||||
break;
|
break;
|
||||||
case MQTTSN_REGACK:
|
case MQTTSN_REGACK:
|
||||||
// NOP
|
_mqttsnPublish->handleRegAck(client, snPacket);
|
||||||
break;
|
break;
|
||||||
case MQTTSN_SUBSCRIBE:
|
case MQTTSN_SUBSCRIBE:
|
||||||
_mqttsnSubscribe->handleSubscribe(client, snPacket);
|
_mqttsnSubscribe->handleSubscribe(client, snPacket);
|
||||||
|
|||||||
@@ -245,5 +245,28 @@ void MQTTSNPublishHandler::handleRegister(Client* client, MQTTSNPacket* packet)
|
|||||||
ev->setClientSendEvent(client, regAck);
|
ev->setClientSendEvent(client, regAck);
|
||||||
_gateway->getClientSendQue()->post(ev);
|
_gateway->getClientSendQue()->post(ev);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MQTTSNPublishHandler::handleRegAck( Client* client, MQTTSNPacket* packet)
|
||||||
|
{
|
||||||
|
uint16_t id;
|
||||||
|
uint16_t msgId;
|
||||||
|
uint8_t rc;
|
||||||
|
if ( client->isActive() || client->isAwake())
|
||||||
|
{
|
||||||
|
if ( packet->getREGACK(&id, &msgId, &rc) == 0 )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MQTTSNPacket* regAck = client->getWaitREGACKPacketList()->getPacket(msgId);
|
||||||
|
if ( regAck != 0 )
|
||||||
|
{
|
||||||
|
client->getWaitREGACKPacketList()->erase(msgId);
|
||||||
|
Event* ev = new Event();
|
||||||
|
ev->setClientSendEvent(client, regAck);
|
||||||
|
_gateway->getClientSendQue()->post(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
void handlePuback(Client* client, MQTTSNPacket* packet);
|
void handlePuback(Client* client, MQTTSNPacket* packet);
|
||||||
void handleAck(Client* client, MQTTSNPacket* packet, uint8_t packetType);
|
void handleAck(Client* client, MQTTSNPacket* packet, uint8_t packetType);
|
||||||
void handleRegister(Client* client, MQTTSNPacket* packet);
|
void handleRegister(Client* client, MQTTSNPacket* packet);
|
||||||
|
void handleRegAck( Client* client, MQTTSNPacket* packet);
|
||||||
private:
|
private:
|
||||||
Gateway* _gateway;
|
Gateway* _gateway;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user