V.06 11/3

Dependencies:   FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts

Fork of ATT_AWS_IoT_demo by attiot

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTConnect.h Source File

MQTTConnect.h

00001 /*******************************************************************************
00002  * Copyright (c) 2014 IBM Corp.
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  *    Ian Craggs - initial API and implementation and/or initial documentation
00015  *    Xiang Rong - 442039 Add makefile to Embedded C client
00016  *******************************************************************************/
00017 
00018 #ifndef MQTTCONNECT_H_
00019 #define MQTTCONNECT_H_
00020 
00021 #if !defined(DLLImport)
00022   #define DLLImport 
00023 #endif
00024 #if !defined(DLLExport)
00025   #define DLLExport
00026 #endif
00027 
00028 
00029 typedef union {
00030     uint8_t all;    /**< all connect flags */
00031 #if defined(REVERSED)
00032     struct
00033     {
00034         unsigned int username : 1;          /**< 3.1 user name */
00035         unsigned int password : 1;          /**< 3.1 password */
00036         unsigned int willRetain : 1;        /**< will retain setting */
00037         unsigned int willQoS : 2;               /**< will QoS value */
00038         unsigned int will : 1;              /**< will flag */
00039         unsigned int cleansession : 1;    /**< clean session flag */
00040         unsigned int : 1;                 /**< unused */
00041     } bits;
00042 #else
00043     struct
00044     {
00045         unsigned int : 1;                           /**< unused */
00046         unsigned int cleansession : 1;    /**< cleansession flag */
00047         unsigned int will : 1;              /**< will flag */
00048         unsigned int willQoS : 2;               /**< will QoS value */
00049         unsigned int willRetain : 1;        /**< will retain setting */
00050         unsigned int password : 1;          /**< 3.1 password */
00051         unsigned int username : 1;          /**< 3.1 user name */
00052     } bits;
00053 #endif
00054 } MQTTConnectFlags; /**< connect flags byte */
00055 
00056 
00057 
00058 /**
00059  * Defines the MQTT "Last Will and Testament" (LWT) settings for
00060  * the connect packet.
00061  */
00062 typedef struct {
00063     /** The eyecatcher for this structure.  must be MQTW. */
00064     char struct_id[4];
00065     /** The version number of this structure.  Must be 0 */
00066     uint8_t struct_version;
00067     /** The LWT topic to which the LWT message will be published. */
00068     MQTTString topicName;
00069     /** The LWT payload. */
00070     MQTTString message;
00071     /**
00072       * The retained flag for the LWT message (see MQTTAsync_message.retained).
00073       */
00074     uint8_t retained;
00075     /**
00076       * The quality of service setting for the LWT message (see
00077       * MQTTAsync_message.qos and @ref qos).
00078       */
00079     QoS qos;
00080 } MQTTPacket_willOptions;
00081 
00082 
00083 #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, (QoS)0 }
00084 
00085 typedef struct {
00086     /** The eyecatcher for this structure.  must be MQTC. */
00087     char struct_id[4];
00088     /** The version number of this structure.  Must be 0 */
00089     uint8_t struct_version;
00090     /** Version of MQTT to be used.  3 = 3.1 4 = 3.1.1
00091       */
00092     uint8_t MQTTVersion;
00093     MQTTString clientID;
00094     uint16_t keepAliveInterval;
00095     uint8_t cleansession;
00096     uint8_t willFlag;
00097     MQTTPacket_willOptions will;
00098     MQTTString username;
00099     MQTTString password;
00100 } MQTTPacket_connectData;
00101 
00102 typedef union
00103 {
00104     uint8_t all;    /**< all connack flags */
00105 #if defined(REVERSED)
00106     struct
00107     {
00108         unsigned int sessionpresent : 1;    /**< session present flag */
00109         unsigned int : 7;                 /**< unused */
00110     } bits;
00111 #else
00112     struct
00113     {
00114         unsigned int : 7;                   /**< unused */
00115         unsigned int sessionpresent : 1;    /**< session present flag */
00116     } bits;
00117 #endif
00118 } MQTTConnackFlags; /**< connack flags byte */
00119 
00120 typedef enum {
00121     CONNACK_CONNECTION_ACCEPTED = 0,
00122     CONANCK_UNACCEPTABLE_PROTOCOL_VERSION_ERROR = 1,
00123     CONNACK_IDENTIFIER_REJECTED_ERROR = 2,
00124     CONNACK_SERVER_UNAVAILABLE_ERROR = 3,
00125     CONNACK_BAD_USERDATA_ERROR = 4,
00126     CONNACK_NOT_AUTHORIZED_ERROR = 5
00127 }MQTTConnackReturnCodes;
00128 
00129 #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
00130         MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }
00131 
00132 DLLExport MQTTReturnCode MQTTSerialize_connect(unsigned char *buf, size_t buflen,
00133                                     MQTTPacket_connectData *options,
00134                                     uint32_t *serialized_len);
00135 
00136 DLLExport MQTTReturnCode MQTTDeserialize_connack(unsigned char *sessionPresent,
00137                                                  MQTTReturnCode *connack_rc,
00138                                                  unsigned char *buf, size_t buflen);
00139 
00140 DLLExport MQTTReturnCode MQTTSerialize_disconnect(unsigned char *buf, size_t buflen,
00141                                    uint32_t *serialized_length);
00142 
00143 DLLExport MQTTReturnCode MQTTSerialize_pingreq(unsigned char *buf, size_t buflen,
00144                                                uint32_t *serialized_length);
00145 
00146 #endif /* MQTTCONNECT_H_ */
00147 
00148