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 mbed-os-example-mbed5-blinky by
MQTTPacket.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 MQTTPACKET_H_ 00018 #define MQTTPACKET_H_ 00019 00020 #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ 00021 extern "C" { 00022 #endif 00023 00024 enum errors 00025 { 00026 MQTTPACKET_BUFFER_TOO_SHORT = -2, 00027 MQTTPACKET_READ_ERROR = -1, 00028 MQTTPACKET_READ_COMPLETE, 00029 }; 00030 00031 enum msgTypes 00032 { 00033 CONNECT = 1, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, 00034 PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, 00035 PINGREQ, PINGRESP, DISCONNECT 00036 }; 00037 00038 /** 00039 * Bitfields for the MQTT header byte. 00040 */ 00041 typedef union 00042 { 00043 unsigned char byte; /**< the whole byte */ 00044 #if defined(REVERSED) 00045 struct 00046 { 00047 unsigned int type : 4; /**< message type nibble */ 00048 unsigned int dup : 1; /**< DUP flag bit */ 00049 unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ 00050 unsigned int retain : 1; /**< retained flag bit */ 00051 } bits; 00052 #else 00053 struct 00054 { 00055 unsigned int retain : 1; /**< retained flag bit */ 00056 unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ 00057 unsigned int dup : 1; /**< DUP flag bit */ 00058 unsigned int type : 4; /**< message type nibble */ 00059 } bits; 00060 #endif 00061 } MQTTHeader; 00062 00063 typedef struct 00064 { 00065 int len; 00066 char* data; 00067 } MQTTLenString; 00068 00069 typedef struct 00070 { 00071 char* cstring; 00072 MQTTLenString lenstring; 00073 } MQTTString; 00074 00075 #define MQTTString_initializer {NULL, {0, NULL}} 00076 00077 int MQTTstrlen(MQTTString mqttstring); 00078 00079 #include "MQTTConnect.h" 00080 #include "MQTTPublish.h" 00081 #include "MQTTSubscribe.h" 00082 #include "MQTTUnsubscribe.h" 00083 00084 int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char type, unsigned char dup, unsigned short packetid); 00085 int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen); 00086 00087 int MQTTPacket_len(int rem_len); 00088 int MQTTPacket_equals(MQTTString* a, char* b); 00089 00090 int MQTTPacket_encode(unsigned char* buf, int length); 00091 int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value); 00092 int MQTTPacket_decodeBuf(unsigned char* buf, int* value); 00093 00094 int readInt(unsigned char** pptr); 00095 char readChar(unsigned char** pptr); 00096 void writeChar(unsigned char** pptr, char c); 00097 void writeInt(unsigned char** pptr, int anInt); 00098 int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata); 00099 void writeCString(unsigned char** pptr, const char* string); 00100 void writeMQTTString(unsigned char** pptr, MQTTString mqttstring); 00101 00102 int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); 00103 00104 char* MQTTPacket_toString(char* strbuf, int strbuflen, unsigned char* buf, int buflen); 00105 00106 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ 00107 } 00108 #endif 00109 00110 00111 #endif /* MQTTPACKET_H_ */
Generated on Wed Jul 13 2022 21:16:17 by
