ME910 support
Dependents: 5_Dragonfly_Cayenne_Sprint_IKS01A1
Fork of Cayenne-MQTT-mbed-MTSAS by
src/MQTTCommon/MQTTPacket.h@22:0dbabcc6e7b2, 2017-01-25 (annotated)
- Committer:
- jburhenn
- Date:
- Wed Jan 25 10:34:16 2017 -0700
- Branch:
- feature/multivalue
- Revision:
- 22:0dbabcc6e7b2
- Parent:
- 0:09ef59d2d0f7
Added support for multi-value arrays and size_t data type modifications from the Cayenne-MQTT-C library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jburhenn | 0:09ef59d2d0f7 | 1 | /******************************************************************************* |
jburhenn | 0:09ef59d2d0f7 | 2 | * Copyright (c) 2014 IBM Corp. |
jburhenn | 0:09ef59d2d0f7 | 3 | * |
jburhenn | 0:09ef59d2d0f7 | 4 | * All rights reserved. This program and the accompanying materials |
jburhenn | 0:09ef59d2d0f7 | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
jburhenn | 0:09ef59d2d0f7 | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
jburhenn | 0:09ef59d2d0f7 | 7 | * |
jburhenn | 0:09ef59d2d0f7 | 8 | * The Eclipse Public License is available at |
jburhenn | 0:09ef59d2d0f7 | 9 | * http://www.eclipse.org/legal/epl-v10.html |
jburhenn | 0:09ef59d2d0f7 | 10 | * and the Eclipse Distribution License is available at |
jburhenn | 0:09ef59d2d0f7 | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
jburhenn | 0:09ef59d2d0f7 | 12 | * |
jburhenn | 0:09ef59d2d0f7 | 13 | * Contributors: |
jburhenn | 0:09ef59d2d0f7 | 14 | * Ian Craggs - initial API and implementation and/or initial documentation |
jburhenn | 0:09ef59d2d0f7 | 15 | * Xiang Rong - 442039 Add makefile to Embedded C client |
jburhenn | 0:09ef59d2d0f7 | 16 | *******************************************************************************/ |
jburhenn | 0:09ef59d2d0f7 | 17 | |
jburhenn | 0:09ef59d2d0f7 | 18 | #ifndef MQTTPACKET_H_ |
jburhenn | 0:09ef59d2d0f7 | 19 | #define MQTTPACKET_H_ |
jburhenn | 0:09ef59d2d0f7 | 20 | |
jburhenn | 22:0dbabcc6e7b2 | 21 | #include <stddef.h> |
jburhenn | 22:0dbabcc6e7b2 | 22 | |
jburhenn | 0:09ef59d2d0f7 | 23 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ |
jburhenn | 0:09ef59d2d0f7 | 24 | extern "C" { |
jburhenn | 0:09ef59d2d0f7 | 25 | #endif |
jburhenn | 0:09ef59d2d0f7 | 26 | |
jburhenn | 0:09ef59d2d0f7 | 27 | #if defined(WIN32_DLL) || defined(WIN64_DLL) |
jburhenn | 0:09ef59d2d0f7 | 28 | #define DLLImport __declspec(dllimport) |
jburhenn | 0:09ef59d2d0f7 | 29 | #define DLLExport __declspec(dllexport) |
jburhenn | 0:09ef59d2d0f7 | 30 | #elif defined(LINUX_SO) |
jburhenn | 0:09ef59d2d0f7 | 31 | #define DLLImport extern |
jburhenn | 0:09ef59d2d0f7 | 32 | #define DLLExport __attribute__ ((visibility ("default"))) |
jburhenn | 0:09ef59d2d0f7 | 33 | #else |
jburhenn | 0:09ef59d2d0f7 | 34 | #define DLLImport |
jburhenn | 0:09ef59d2d0f7 | 35 | #define DLLExport |
jburhenn | 0:09ef59d2d0f7 | 36 | #endif |
jburhenn | 0:09ef59d2d0f7 | 37 | |
jburhenn | 0:09ef59d2d0f7 | 38 | enum errors |
jburhenn | 0:09ef59d2d0f7 | 39 | { |
jburhenn | 0:09ef59d2d0f7 | 40 | MQTTPACKET_BUFFER_TOO_SHORT = -2, |
jburhenn | 0:09ef59d2d0f7 | 41 | MQTTPACKET_READ_ERROR = -1, |
jburhenn | 0:09ef59d2d0f7 | 42 | MQTTPACKET_READ_COMPLETE |
jburhenn | 0:09ef59d2d0f7 | 43 | }; |
jburhenn | 0:09ef59d2d0f7 | 44 | |
jburhenn | 0:09ef59d2d0f7 | 45 | enum msgTypes |
jburhenn | 0:09ef59d2d0f7 | 46 | { |
jburhenn | 0:09ef59d2d0f7 | 47 | CONNECT_MSG = 1, CONNACK_MSG, PUBLISH_MSG, PUBACK_MSG, PUBREC_MSG, PUBREL_MSG, |
jburhenn | 0:09ef59d2d0f7 | 48 | PUBCOMP_MSG, SUBSCRIBE_MSG, SUBACK_MSG, UNSUBSCRIBE_MSG, UNSUBACK_MSG, |
jburhenn | 0:09ef59d2d0f7 | 49 | PINGREQ_MSG, PINGRESP_MSG, DISCONNECT_MSG |
jburhenn | 0:09ef59d2d0f7 | 50 | }; |
jburhenn | 0:09ef59d2d0f7 | 51 | |
jburhenn | 0:09ef59d2d0f7 | 52 | /** |
jburhenn | 0:09ef59d2d0f7 | 53 | * Bitfields for the MQTT header byte. |
jburhenn | 0:09ef59d2d0f7 | 54 | */ |
jburhenn | 0:09ef59d2d0f7 | 55 | typedef union |
jburhenn | 0:09ef59d2d0f7 | 56 | { |
jburhenn | 0:09ef59d2d0f7 | 57 | unsigned char byte; /**< the whole byte */ |
jburhenn | 0:09ef59d2d0f7 | 58 | #if defined(REVERSED) |
jburhenn | 0:09ef59d2d0f7 | 59 | struct |
jburhenn | 0:09ef59d2d0f7 | 60 | { |
jburhenn | 0:09ef59d2d0f7 | 61 | unsigned int type : 4; /**< message type nibble */ |
jburhenn | 0:09ef59d2d0f7 | 62 | unsigned int dup : 1; /**< DUP flag bit */ |
jburhenn | 0:09ef59d2d0f7 | 63 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ |
jburhenn | 0:09ef59d2d0f7 | 64 | unsigned int retain : 1; /**< retained flag bit */ |
jburhenn | 0:09ef59d2d0f7 | 65 | } bits; |
jburhenn | 0:09ef59d2d0f7 | 66 | #else |
jburhenn | 0:09ef59d2d0f7 | 67 | struct |
jburhenn | 0:09ef59d2d0f7 | 68 | { |
jburhenn | 0:09ef59d2d0f7 | 69 | unsigned int retain : 1; /**< retained flag bit */ |
jburhenn | 0:09ef59d2d0f7 | 70 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ |
jburhenn | 0:09ef59d2d0f7 | 71 | unsigned int dup : 1; /**< DUP flag bit */ |
jburhenn | 0:09ef59d2d0f7 | 72 | unsigned int type : 4; /**< message type nibble */ |
jburhenn | 0:09ef59d2d0f7 | 73 | } bits; |
jburhenn | 0:09ef59d2d0f7 | 74 | #endif |
jburhenn | 0:09ef59d2d0f7 | 75 | } MQTTHeader; |
jburhenn | 0:09ef59d2d0f7 | 76 | |
jburhenn | 0:09ef59d2d0f7 | 77 | typedef struct |
jburhenn | 0:09ef59d2d0f7 | 78 | { |
jburhenn | 22:0dbabcc6e7b2 | 79 | size_t len; |
jburhenn | 0:09ef59d2d0f7 | 80 | char* data; |
jburhenn | 0:09ef59d2d0f7 | 81 | } MQTTLenString; |
jburhenn | 0:09ef59d2d0f7 | 82 | |
jburhenn | 0:09ef59d2d0f7 | 83 | typedef struct |
jburhenn | 0:09ef59d2d0f7 | 84 | { |
jburhenn | 0:09ef59d2d0f7 | 85 | char* cstring; |
jburhenn | 0:09ef59d2d0f7 | 86 | MQTTLenString lenstring; |
jburhenn | 0:09ef59d2d0f7 | 87 | } MQTTString; |
jburhenn | 0:09ef59d2d0f7 | 88 | |
jburhenn | 0:09ef59d2d0f7 | 89 | #define MQTTString_initializer {NULL, {0, NULL}} |
jburhenn | 0:09ef59d2d0f7 | 90 | |
jburhenn | 22:0dbabcc6e7b2 | 91 | size_t MQTTstrlen(MQTTString mqttstring); |
jburhenn | 0:09ef59d2d0f7 | 92 | |
jburhenn | 0:09ef59d2d0f7 | 93 | #include "MQTTConnect.h" |
jburhenn | 0:09ef59d2d0f7 | 94 | #include "MQTTPublish.h" |
jburhenn | 0:09ef59d2d0f7 | 95 | #include "MQTTSubscribe.h" |
jburhenn | 0:09ef59d2d0f7 | 96 | #include "MQTTUnsubscribe.h" |
jburhenn | 0:09ef59d2d0f7 | 97 | |
jburhenn | 22:0dbabcc6e7b2 | 98 | int MQTTSerialize_ack(unsigned char* buf, size_t buflen, unsigned char type, unsigned char dup, unsigned short packetid); |
jburhenn | 22:0dbabcc6e7b2 | 99 | int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, size_t buflen); |
jburhenn | 0:09ef59d2d0f7 | 100 | |
jburhenn | 22:0dbabcc6e7b2 | 101 | size_t MQTTPacket_len(size_t rem_len); |
jburhenn | 0:09ef59d2d0f7 | 102 | int MQTTPacket_equals(MQTTString* a, char* b); |
jburhenn | 0:09ef59d2d0f7 | 103 | |
jburhenn | 22:0dbabcc6e7b2 | 104 | int MQTTPacket_encode(unsigned char* buf, size_t length); |
jburhenn | 0:09ef59d2d0f7 | 105 | int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value); |
jburhenn | 0:09ef59d2d0f7 | 106 | int MQTTPacket_decodeBuf(unsigned char* buf, int* value); |
jburhenn | 0:09ef59d2d0f7 | 107 | |
jburhenn | 0:09ef59d2d0f7 | 108 | int readInt(unsigned char** pptr); |
jburhenn | 0:09ef59d2d0f7 | 109 | char readChar(unsigned char** pptr); |
jburhenn | 0:09ef59d2d0f7 | 110 | void writeChar(unsigned char** pptr, char c); |
jburhenn | 0:09ef59d2d0f7 | 111 | void writeInt(unsigned char** pptr, int anInt); |
jburhenn | 0:09ef59d2d0f7 | 112 | int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata); |
jburhenn | 0:09ef59d2d0f7 | 113 | void writeCString(unsigned char** pptr, const char* string); |
jburhenn | 0:09ef59d2d0f7 | 114 | void writeMQTTString(unsigned char** pptr, MQTTString mqttstring); |
jburhenn | 0:09ef59d2d0f7 | 115 | |
jburhenn | 0:09ef59d2d0f7 | 116 | DLLExport int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); |
jburhenn | 0:09ef59d2d0f7 | 117 | |
jburhenn | 0:09ef59d2d0f7 | 118 | typedef struct { |
jburhenn | 0:09ef59d2d0f7 | 119 | int (*getfn)(void *, unsigned char*, int); /* must return -1 for error, 0 for call again, or the number of bytes read */ |
jburhenn | 0:09ef59d2d0f7 | 120 | void *sck; /* pointer to whatever the system may use to identify the transport */ |
jburhenn | 0:09ef59d2d0f7 | 121 | int multiplier; |
jburhenn | 0:09ef59d2d0f7 | 122 | int rem_len; |
jburhenn | 0:09ef59d2d0f7 | 123 | int len; |
jburhenn | 0:09ef59d2d0f7 | 124 | char state; |
jburhenn | 0:09ef59d2d0f7 | 125 | }MQTTTransport; |
jburhenn | 0:09ef59d2d0f7 | 126 | |
jburhenn | 0:09ef59d2d0f7 | 127 | int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp); |
jburhenn | 0:09ef59d2d0f7 | 128 | |
jburhenn | 0:09ef59d2d0f7 | 129 | #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ |
jburhenn | 0:09ef59d2d0f7 | 130 | } |
jburhenn | 0:09ef59d2d0f7 | 131 | #endif |
jburhenn | 0:09ef59d2d0f7 | 132 | |
jburhenn | 0:09ef59d2d0f7 | 133 | |
jburhenn | 0:09ef59d2d0f7 | 134 | #endif /* MQTTPACKET_H_ */ |