diff --git a/MQTTSNGateway/Makefile b/MQTTSNGateway/Makefile index 4015b85..1fd2233 100644 --- a/MQTTSNGateway/Makefile +++ b/MQTTSNGateway/Makefile @@ -18,6 +18,9 @@ OS := linux SENSORNET := udp TEST := tests +INSTALL_DIR=../../ +CONFIG_DIR=../../ + CPPSRCS := \ $(SRCDIR)/MQTTGWConnectionHandler.cpp \ $(SRCDIR)/MQTTGWPacket.cpp \ @@ -143,11 +146,11 @@ clean: rm -rf $(OUTDIR) install: - cp -pf $(PROG) ../../ - cp -pf $(LPROG) ../../ - cp -pf $(CONFIG) ../../ - cp -pf $(CLIENTS) ../../ - cp -pf $(PREDEFTOPIC) ../../ + cp -pf $(PROG) $(INSTALL_DIR) + cp -pf $(LPROG) $(INSTALL_DIR) + cp -pf $(CONFIG) $(CONFIG_DIR) + cp -pf $(CLIENTS) $(CONFIG_DIR) + cp -pf $(PREDEFTOPIC) $(CONFIG_DIR) exectest: diff --git a/MQTTSNGateway/README.md b/MQTTSNGateway/README.md index e04ffa6..108511e 100644 --- a/MQTTSNGateway/README.md +++ b/MQTTSNGateway/README.md @@ -8,7 +8,11 @@ $ make $ make install $ make clean ```` -MQTT-SNGateway, MQTT-SNLogmonitor and param.conf are copied into ../ directory. +MQTT-SNGateway, MQTT-SNLogmonitor and *.conf files are copied into ../ directory. +If you want to install the gateway into specific directories, enter a command line as follows: +```` +$ make install INSTALL_DIR=/path/to/your_directory CONFIG_DIR=/path/to/your_directory +```` ### **step2. Execute the Gateway.** diff --git a/MQTTSNGateway/src/MQTTGWPacket.h b/MQTTSNGateway/src/MQTTGWPacket.h index bc35d97..3a4829e 100644 --- a/MQTTSNGateway/src/MQTTGWPacket.h +++ b/MQTTSNGateway/src/MQTTGWPacket.h @@ -116,6 +116,7 @@ typedef struct unsigned char version; /**< MQTT version number */ } Connect; +#define MQTTPacket_Connect_Initializer {{0}, 0, nullptr, nullptr, nullptr, nullptr, 0, 0} #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 } #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \ MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } @@ -173,6 +174,7 @@ typedef struct int payloadlen; /**< payload length */ } Publish; +#define MQTTPacket_Publish_Initializer {{0}, nullptr, 0, 0, nullptr, 0} /** * Data for one of the ack packets. diff --git a/MQTTSNGateway/src/MQTTSNGWBrokerRecvTask.cpp b/MQTTSNGateway/src/MQTTSNGWBrokerRecvTask.cpp index 01f6fb1..0f180c9 100644 --- a/MQTTSNGateway/src/MQTTSNGWBrokerRecvTask.cpp +++ b/MQTTSNGateway/src/MQTTSNGWBrokerRecvTask.cpp @@ -104,7 +104,7 @@ void BrokerRecvTask::run(void) { client = _gateway->getClientList()->getClient(0); - while (client > 0) + while ( client ) { _light->blueLight(false); if (client->getNetwork()->isValid()) diff --git a/MQTTSNGateway/src/MQTTSNGWClient.cpp b/MQTTSNGateway/src/MQTTSNGWClient.cpp index f524d0b..11c5520 100644 --- a/MQTTSNGateway/src/MQTTSNGWClient.cpp +++ b/MQTTSNGateway/src/MQTTSNGWClient.cpp @@ -44,7 +44,7 @@ Client::Client(bool secure) _clientId = nullptr; _willTopic = nullptr; _willMsg = nullptr; - _connectData = {0, 0, 0, 0, 0, 0, 0}; + _connectData = MQTTPacket_Connect_Initializer; _network = new Network(secure); _secureNetwork = secure; _sensorNetype = true; diff --git a/MQTTSNGateway/src/MQTTSNGWConnectionHandler.h b/MQTTSNGateway/src/MQTTSNGWConnectionHandler.h index adf92d4..6af6113 100644 --- a/MQTTSNGateway/src/MQTTSNGWConnectionHandler.h +++ b/MQTTSNGateway/src/MQTTSNGWConnectionHandler.h @@ -39,7 +39,6 @@ public: private: void sendStoredPublish(Client* client); - char _pbuf[MQTTSNGW_MAX_PACKET_SIZE * 3]; Gateway* _gateway; }; diff --git a/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp b/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp index 53bbb43..dd01c50 100644 --- a/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp +++ b/MQTTSNGateway/src/MQTTSNGWPublishHandler.cpp @@ -44,7 +44,7 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket* uint8_t* payload; MQTTSN_topicid topicid; int payloadlen; - Publish pub = {0, 0, 0, 0, 0, 0}; + Publish pub = MQTTPacket_Publish_Initializer; char shortTopic[2]; diff --git a/MQTTSNGateway/src/MQTTSNGWTopic.cpp b/MQTTSNGateway/src/MQTTSNGWTopic.cpp index 7777a2c..5be2278 100644 --- a/MQTTSNGateway/src/MQTTSNGWTopic.cpp +++ b/MQTTSNGateway/src/MQTTSNGWTopic.cpp @@ -443,7 +443,7 @@ TopicIdMapElement* TopicIdMap::add(uint16_t msgId, uint16_t topicId, MQTTSN_topi { return 0; } - if ( getElement(msgId) > 0 ) + if ( getElement(msgId) ) { erase(msgId); } diff --git a/MQTTSNGateway/src/MQTTSNGateway.cpp b/MQTTSNGateway/src/MQTTSNGateway.cpp index 25ab87f..46d4281 100644 --- a/MQTTSNGateway/src/MQTTSNGateway.cpp +++ b/MQTTSNGateway/src/MQTTSNGateway.cpp @@ -191,11 +191,6 @@ void Gateway::initialize(int argc, char** argv) _params.keepAlive = atoi(param); } - if (_params.keepAlive > 65536) - { - throw Exception("Gateway::initialize: KeepAliveTime is grater than 65536 Secs"); - } - if (getParam("LoginID", param) == 0) { _params.loginId = strdup(param); diff --git a/MQTTSNPacket/src/MQTTSNPacket.c b/MQTTSNPacket/src/MQTTSNPacket.c index 03928b1..a788b78 100644 --- a/MQTTSNPacket/src/MQTTSNPacket.c +++ b/MQTTSNPacket/src/MQTTSNPacket.c @@ -274,4 +274,20 @@ exit: return rc; } +int MQTTSNPacket_read_nb(unsigned char* buf, int buflen) +{ + int rc = MQTTSNPACKET_READ_ERROR; + int len = buflen; /* the length of the whole packet including length field */ + int lenlen = 0; + int datalen = 0; + + /* 2. read the length. This is variable in itself */ + lenlen = MQTTSNPacket_decode(buf, len, &datalen); + if (datalen != len) + goto exit; /* there was an error */ + + rc = buf[lenlen]; /* return the packet type */ +exit: + return rc; +} diff --git a/MQTTSNPacket/src/MQTTSNPacket.h b/MQTTSNPacket/src/MQTTSNPacket.h index ebde5b3..3d9b296 100644 --- a/MQTTSNPacket/src/MQTTSNPacket.h +++ b/MQTTSNPacket/src/MQTTSNPacket.h @@ -143,6 +143,8 @@ void writeCString(unsigned char** pptr, char* string); void writeMQTTSNString(unsigned char** pptr, MQTTSNString mqttstring); int MQTTSNPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); +int MQTTSNPacket_read_nb(unsigned char* buf, int buflen); + #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ }