First Commit of MQTT-SN Gateway

Add    new SensorNetwork XBee
Add    a sensor network type in a start message.
Update MQTTSNClient to avoid build warning.
Update WiringPi's functions to my original ones. 
BugFix check msgId before adding waitdTopicId table.
BugFix Process termination procedures
Update print curent time in millseconds.
update move currentDateTime() to linux directory.
Bugfix: blink blue lightiIndicator.
Bugfix: Register returns wrong id.
change a status of the client to Disconnected.
change client status procedure
Update README
BugFix: change Network Disconnect procedures.

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2016-05-13 19:18:47 +09:00
parent 826b2a83b0
commit 64fa07b391
63 changed files with 9206 additions and 1138 deletions

View File

@@ -20,6 +20,7 @@
#include <string.h>
/**
* Determines the length of the MQTT connect packet that would be produced using the supplied connect options.
* @param options the options to be used to build the connect packet
@@ -116,7 +117,7 @@ int MQTTSNSerialize_disconnectLength(int duration)
int len = 0;
FUNC_ENTRY;
len = (duration >= 0) ? 3 : 1;
len = (duration > 0) ? 3 : 1;
FUNC_EXIT_RC(len);
return len;
}
@@ -144,7 +145,7 @@ int MQTTSNSerialize_disconnect(unsigned char* buf, int buflen, int duration)
ptr += MQTTSNPacket_encode(ptr, len); /* write length */
writeChar(&ptr, MQTTSN_DISCONNECT); /* write message type */
if (duration >= 0)
if (duration > 0)
writeInt(&ptr, duration);
rc = ptr - buf;

View File

@@ -56,7 +56,7 @@ int MQTTSNDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retai
*qos = flags.bits.QoS;
*retained = flags.bits.retain;
topic->type = flags.bits.topicIdType;
topic->type = (MQTTSN_topicTypes)flags.bits.topicIdType;
if (topic->type == MQTTSN_TOPIC_TYPE_NORMAL && *qos == 3)
{
/* special arrangement for long topic names in QoS -1 publishes. The length of the topic is in the topicid field */

View File

@@ -19,7 +19,7 @@
#include <string.h>
static char* packet_names[] =
static const char* packet_names[] =
{
"ADVERTISE", "SEARCHGW", "GWINFO", "RESERVED", "CONNECT", "CONNACK",
"WILLTOPICREQ", "WILLTOPIC", "WILLMSGREQ", "WILLMSG", "REGISTER", "REGACK",
@@ -35,7 +35,7 @@ static char* packet_names[] =
* @param code MsgType code
* @return the corresponding packet name
*/
char* MQTTSNPacket_name(int code)
const char* MQTTSNPacket_name(int code)
{
return (code >= 0 && code <= MQTTSN_WILLMSGRESP) ? packet_names[code] : "UNKNOWN";
}
@@ -51,7 +51,6 @@ int MQTTSNPacket_len(int length)
return (length > 255) ? length + 3 : length + 1;
}
/**
* Encodes the MQTT-SN message length
* @param buf the buffer into which the encoded data is written
@@ -95,7 +94,7 @@ int MQTTSNPacket_decode(unsigned char* buf, int buflen, int* value)
if (buf[0] == 1)
{
unsigned char* bufptr = &buf[1];
if (buflen < 3)
if (buflen < MAX_NO_OF_LENGTH_BYTES)
goto exit;
*value = readInt(&bufptr);
len = 3;
@@ -188,7 +187,7 @@ void writeMQTTSNString(unsigned char** pptr, MQTTSNString MQTTSNString)
{
if (MQTTSNString.lenstring.len > 0)
{
memcpy(*pptr, MQTTSNString.lenstring.data, MQTTSNString.lenstring.len);
memcpy(*pptr, (const unsigned char*)MQTTSNString.lenstring.data, MQTTSNString.lenstring.len);
*pptr += MQTTSNString.lenstring.len;
}
else if (MQTTSNString.cstring)

View File

@@ -12,6 +12,7 @@
*
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
* TomoakiiYamaguchi - modify for C++
*******************************************************************************/
#ifndef MQTTSNPACKET_H_
@@ -35,15 +36,15 @@ enum MQTTSN_connackCodes
MQTTSN_RC_ACCEPTED,
MQTTSN_RC_REJECTED_CONGESTED,
MQTTSN_RC_REJECTED_INVALID_TOPIC_ID,
MQTTSN_RC_NOT_SUPPORTED
};
enum MQTTSN_topicTypes
typedef enum
{
MQTTSN_TOPIC_TYPE_NORMAL, /* topic id in publish, topic name in subscribe */
MQTTSN_TOPIC_TYPE_PREDEFINED,
MQTTSN_TOPIC_TYPE_SHORT,
};
}MQTTSN_topicTypes;
enum MQTTSN_msgTypes
{
@@ -60,7 +61,7 @@ enum MQTTSN_msgTypes
typedef struct
{
enum MQTTSN_topicTypes type;
MQTTSN_topicTypes type;
union
{
unsigned short id;
@@ -73,7 +74,6 @@ typedef struct
} data;
} MQTTSN_topicid;
/**
* Bitfields for the MQTT-SN flags byte.
*/
@@ -126,7 +126,7 @@ int MQTTSNstrlen(MQTTSNString mqttsnstring);
#include "MQTTSNUnsubscribe.h"
#include "MQTTSNSearch.h"
char* MQTTSNPacket_name(int ptype);
const char* MQTTSNPacket_name(int ptype);
int MQTTSNPacket_len(int length);
int MQTTSNPacket_encode(unsigned char* buf, int length);

View File

@@ -41,5 +41,6 @@ int MQTTSNSerialize_regack(unsigned char* buf, int buflen, unsigned short topici
unsigned char return_code);
int MQTTSNDeserialize_regack(unsigned short* topicid, unsigned short* packetid, unsigned char* return_code,
unsigned char* buf, int buflen);
int MQTTSNSerialize_pubrel(unsigned char* buf, int buflen, unsigned short packetid);
#endif /* MQTTSNPUBLISH_H_ */

View File

@@ -53,7 +53,7 @@ int MQTTSNDeserialize_subscribe(unsigned char* dup, int* qos, unsigned short* pa
*packetid = readInt(&curdata);
topicFilter->type = flags.bits.topicIdType;
topicFilter->type = (MQTTSN_topicTypes)flags.bits.topicIdType;
if (topicFilter->type == MQTTSN_TOPIC_TYPE_NORMAL)
{

View File

@@ -38,7 +38,7 @@ int MQTTSNDeserialize_unsubscribe(unsigned short* packetid, MQTTSN_topicid* topi
flags.all = readChar(&curdata);
*packetid = readInt(&curdata);
topicFilter->type = flags.bits.topicIdType;
topicFilter->type = (MQTTSN_topicTypes)flags.bits.topicIdType;
if (topicFilter->type == MQTTSN_TOPIC_TYPE_NORMAL)
{
topicFilter->data.long_.len = enddata - curdata;