Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MQTTPacket by
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 *******************************************************************************/ 00016 00017 #ifndef MQTTCONNECT_H_ 00018 #define MQTTCONNECT_H_ 00019 00020 typedef union 00021 { 00022 unsigned char all; /**< all connect flags */ 00023 #if defined(REVERSED) 00024 struct 00025 { 00026 unsigned int username : 1; /**< 3.1 user name */ 00027 unsigned int password : 1; /**< 3.1 password */ 00028 unsigned int willRetain : 1; /**< will retain setting */ 00029 unsigned int willQoS : 2; /**< will QoS value */ 00030 unsigned int will : 1; /**< will flag */ 00031 unsigned int cleansession : 1; /**< clean session flag */ 00032 unsigned int : 1; /**< unused */ 00033 } bits; 00034 #else 00035 struct 00036 { 00037 unsigned int : 1; /**< unused */ 00038 unsigned int cleansession : 1; /**< cleansession flag */ 00039 unsigned int will : 1; /**< will flag */ 00040 unsigned int willQoS : 2; /**< will QoS value */ 00041 unsigned int willRetain : 1; /**< will retain setting */ 00042 unsigned int password : 1; /**< 3.1 password */ 00043 unsigned int username : 1; /**< 3.1 user name */ 00044 } bits; 00045 #endif 00046 } MQTTConnectFlags; /**< connect flags byte */ 00047 00048 00049 00050 /** 00051 * Defines the MQTT "Last Will and Testament" (LWT) settings for 00052 * the connect packet. 00053 */ 00054 typedef struct 00055 { 00056 /** The eyecatcher for this structure. must be MQTW. */ 00057 char struct_id[4]; 00058 /** The version number of this structure. Must be 0 */ 00059 int struct_version; 00060 /** The LWT topic to which the LWT message will be published. */ 00061 MQTTString topicName; 00062 /** The LWT payload. */ 00063 MQTTString message; 00064 /** 00065 * The retained flag for the LWT message (see MQTTAsync_message.retained). 00066 */ 00067 unsigned char retained; 00068 /** 00069 * The quality of service setting for the LWT message (see 00070 * MQTTAsync_message.qos and @ref qos). 00071 */ 00072 char qos; 00073 } MQTTPacket_willOptions; 00074 00075 00076 #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 } 00077 00078 00079 typedef struct 00080 { 00081 /** The eyecatcher for this structure. must be MQTC. */ 00082 char struct_id[4]; 00083 /** The version number of this structure. Must be 0 */ 00084 int struct_version; 00085 /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1 00086 */ 00087 unsigned char MQTTVersion; 00088 MQTTString clientID; 00089 unsigned short keepAliveInterval; 00090 unsigned char cleansession; 00091 unsigned char willFlag; 00092 MQTTPacket_willOptions will; 00093 MQTTString username; 00094 MQTTString password; 00095 } MQTTPacket_connectData; 00096 00097 typedef union 00098 { 00099 unsigned char all; /**< all connack flags */ 00100 #if defined(REVERSED) 00101 struct 00102 { 00103 unsigned int sessionpresent : 1; /**< session present flag */ 00104 unsigned int : y; /**< unused */ 00105 } bits; 00106 #else 00107 struct 00108 { 00109 unsigned int : 7; /**< unused */ 00110 unsigned int sessionpresent : 1; /**< session present flag */ 00111 } bits; 00112 #endif 00113 } MQTTConnackFlags; /**< connack flags byte */ 00114 00115 #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \ 00116 MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } 00117 00118 int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options); 00119 int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len); 00120 00121 int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent); 00122 int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen); 00123 00124 int MQTTSerialize_disconnect(unsigned char* buf, int buflen); 00125 int MQTTSerialize_pingreq(unsigned char* buf, int buflen); 00126 00127 #endif /* MQTTCONNECT_H_ */
Generated on Tue Jul 12 2022 19:26:03 by
1.7.2
