Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTSNGWPacket.h Source File

MQTTSNGWPacket.h

00001 /**************************************************************************************
00002  * Copyright (c) 2016, Tomoaki Yamaguchi
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
00015  **************************************************************************************/
00016 #ifndef MQTTSNGWPACKET_H_
00017 #define MQTTSNGWPACKET_H_
00018 
00019 #include "MQTTSNGWDefines.h"
00020 #include "MQTTSNPacket.h"
00021 #include "SensorNetwork.h"
00022 
00023 namespace MQTTSNGW
00024 {
00025 
00026 class MQTTSNPacket
00027 {
00028 public:
00029     MQTTSNPacket(void);
00030     MQTTSNPacket(MQTTSNPacket &packet);
00031     ~MQTTSNPacket(void);
00032     int unicast(SensorNetwork* network, SensorNetAddress* sendTo);
00033     int broadcast(SensorNetwork* network);
00034     int recv(SensorNetwork* network);
00035     int serialize(uint8_t* buf);
00036     int desirialize(unsigned char* buf, unsigned short len);
00037     int getType(void);
00038     unsigned char* getPacketData(void);
00039     int getPacketLength(void);
00040     const char* getName();
00041 
00042                                                     int setConnect(void);   // Debug
00043     int setADVERTISE(uint8_t gatewayid, uint16_t duration);
00044     int setGWINFO(uint8_t gatewayId);
00045     int setCONNACK(uint8_t returnCode);
00046     int setWILLTOPICREQ(void);
00047     int setWILLMSGREQ(void);
00048     int setREGISTER(uint16_t topicId, uint16_t msgId, MQTTSNString* TopicName);
00049     int setREGACK(uint16_t topicId, uint16_t msgId, uint8_t returnCode);
00050     int setPUBLISH(uint8_t dup, int qos, uint8_t retained, uint16_t msgId,
00051             MQTTSN_topicid topic, uint8_t* payload, uint16_t payloadlen);
00052     int setPUBACK(uint16_t topicId, uint16_t msgId, uint8_t returnCode);
00053     int setPUBREC(uint16_t msgId);
00054     int setPUBREL(uint16_t msgId);
00055     int setPUBCOMP(uint16_t msgId);
00056     int setSUBACK(int qos, uint16_t topicId, uint16_t msgId, uint8_t returnCode);
00057     int setUNSUBACK(uint16_t msgId);
00058     int setPINGRESP(void);
00059     int setDISCONNECT(uint16_t duration);
00060     int setWILLTOPICRESP(uint8_t returnCode);
00061     int setWILLMSGRESP(uint8_t returnCode);
00062 
00063     int setCONNECT(MQTTSNPacket_connectData* options);
00064     int setPINGREQ(MQTTSNString* clientId);
00065 
00066     int getSERCHGW(uint8_t* radius);
00067     int getCONNECT(MQTTSNPacket_connectData* option);
00068     int getCONNACK(uint8_t* returnCode);
00069     int getWILLTOPIC(int* willQoS, uint8_t* willRetain, MQTTSNString* willTopic);
00070     int getWILLMSG(MQTTSNString* willmsg);
00071     int getREGISTER(uint16_t* topicId, uint16_t* msgId, MQTTSNString* topicName);
00072     int getREGACK(uint16_t* topicId, uint16_t* msgId, uint8_t* returnCode);
00073     int getPUBLISH(uint8_t* dup, int* qos, uint8_t* retained, uint16_t* msgId,
00074             MQTTSN_topicid* topic, unsigned char** payload, int* payloadlen);
00075     int getPUBACK(uint16_t* topicId, uint16_t* msgId, uint8_t* returnCode);
00076     int getACK(uint16_t* msgId);
00077     int getSUBSCRIBE(uint8_t* dup, int* qos, uint16_t* msgId, MQTTSN_topicid* topicFilter);
00078     int getUNSUBSCRIBE(uint16_t* msgId, MQTTSN_topicid* topicFilter);
00079     int getPINGREQ(void);
00080     int getDISCONNECT(uint16_t* duration);
00081     int getWILLTOPICUPD(uint8_t* willQoS, uint8_t* willRetain, MQTTSNString* willTopic);
00082     int getWILLMSGUPD(MQTTSNString* willMsg);
00083 
00084     bool isAccepted(void);
00085     bool isDuplicate(void);
00086     bool isQoSMinusPUBLISH(void);
00087     char* getMsgId(char* buf);
00088     int getMsgId(void);
00089     void setMsgId(uint16_t msgId);
00090     char* print(char* buf);
00091 
00092 private:
00093     unsigned char* _buf;    // Ptr to a packet data
00094     int            _bufLen; // length of the packet data
00095 };
00096 
00097 }
00098 #endif /* MQTTSNGWPACKET_H_ */