【mbed OS5対応バージョン】データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/
Dependents: mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn
MQTT/MQTTPacket/MQTTPacket.h@13:61e0cc093180, 2018-03-26 (annotated)
- Committer:
- jksoft
- Date:
- Mon Mar 26 04:49:20 2018 +0000
- Revision:
- 13:61e0cc093180
- Parent:
- 0:0a2f634d3324
???????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:0a2f634d3324 | 1 | /******************************************************************************* |
jksoft | 0:0a2f634d3324 | 2 | * Copyright (c) 2014 IBM Corp. |
jksoft | 0:0a2f634d3324 | 3 | * |
jksoft | 0:0a2f634d3324 | 4 | * All rights reserved. This program and the accompanying materials |
jksoft | 0:0a2f634d3324 | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
jksoft | 0:0a2f634d3324 | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
jksoft | 0:0a2f634d3324 | 7 | * |
jksoft | 0:0a2f634d3324 | 8 | * The Eclipse Public License is available at |
jksoft | 0:0a2f634d3324 | 9 | * http://www.eclipse.org/legal/epl-v10.html |
jksoft | 0:0a2f634d3324 | 10 | * and the Eclipse Distribution License is available at |
jksoft | 0:0a2f634d3324 | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
jksoft | 0:0a2f634d3324 | 12 | * |
jksoft | 0:0a2f634d3324 | 13 | * Contributors: |
jksoft | 0:0a2f634d3324 | 14 | * Ian Craggs - initial API and implementation and/or initial documentation |
jksoft | 0:0a2f634d3324 | 15 | *******************************************************************************/ |
jksoft | 0:0a2f634d3324 | 16 | |
jksoft | 0:0a2f634d3324 | 17 | #ifndef MQTTPACKET_H_ |
jksoft | 0:0a2f634d3324 | 18 | #define MQTTPACKET_H_ |
jksoft | 0:0a2f634d3324 | 19 | |
jksoft | 0:0a2f634d3324 | 20 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */ |
jksoft | 0:0a2f634d3324 | 21 | extern "C" { |
jksoft | 0:0a2f634d3324 | 22 | #endif |
jksoft | 0:0a2f634d3324 | 23 | |
jksoft | 0:0a2f634d3324 | 24 | enum errors |
jksoft | 0:0a2f634d3324 | 25 | { |
jksoft | 0:0a2f634d3324 | 26 | MQTTPACKET_BUFFER_TOO_SHORT = -2, |
jksoft | 0:0a2f634d3324 | 27 | MQTTPACKET_READ_ERROR = -1, |
jksoft | 0:0a2f634d3324 | 28 | MQTTPACKET_READ_COMPLETE, |
jksoft | 0:0a2f634d3324 | 29 | }; |
jksoft | 0:0a2f634d3324 | 30 | |
jksoft | 0:0a2f634d3324 | 31 | enum msgTypes |
jksoft | 0:0a2f634d3324 | 32 | { |
jksoft | 0:0a2f634d3324 | 33 | CONNECT = 1, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, |
jksoft | 0:0a2f634d3324 | 34 | PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, |
jksoft | 0:0a2f634d3324 | 35 | PINGREQ, PINGRESP, DISCONNECT |
jksoft | 0:0a2f634d3324 | 36 | }; |
jksoft | 0:0a2f634d3324 | 37 | |
jksoft | 0:0a2f634d3324 | 38 | /** |
jksoft | 0:0a2f634d3324 | 39 | * Bitfields for the MQTT header byte. |
jksoft | 0:0a2f634d3324 | 40 | */ |
jksoft | 0:0a2f634d3324 | 41 | typedef union |
jksoft | 0:0a2f634d3324 | 42 | { |
jksoft | 0:0a2f634d3324 | 43 | unsigned char byte; /**< the whole byte */ |
jksoft | 0:0a2f634d3324 | 44 | #if defined(REVERSED) |
jksoft | 0:0a2f634d3324 | 45 | struct |
jksoft | 0:0a2f634d3324 | 46 | { |
jksoft | 0:0a2f634d3324 | 47 | unsigned int type : 4; /**< message type nibble */ |
jksoft | 0:0a2f634d3324 | 48 | unsigned int dup : 1; /**< DUP flag bit */ |
jksoft | 0:0a2f634d3324 | 49 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ |
jksoft | 0:0a2f634d3324 | 50 | unsigned int retain : 1; /**< retained flag bit */ |
jksoft | 0:0a2f634d3324 | 51 | } bits; |
jksoft | 0:0a2f634d3324 | 52 | #else |
jksoft | 0:0a2f634d3324 | 53 | struct |
jksoft | 0:0a2f634d3324 | 54 | { |
jksoft | 0:0a2f634d3324 | 55 | unsigned int retain : 1; /**< retained flag bit */ |
jksoft | 0:0a2f634d3324 | 56 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */ |
jksoft | 0:0a2f634d3324 | 57 | unsigned int dup : 1; /**< DUP flag bit */ |
jksoft | 0:0a2f634d3324 | 58 | unsigned int type : 4; /**< message type nibble */ |
jksoft | 0:0a2f634d3324 | 59 | } bits; |
jksoft | 0:0a2f634d3324 | 60 | #endif |
jksoft | 0:0a2f634d3324 | 61 | } MQTTHeader; |
jksoft | 0:0a2f634d3324 | 62 | |
jksoft | 0:0a2f634d3324 | 63 | typedef struct |
jksoft | 0:0a2f634d3324 | 64 | { |
jksoft | 0:0a2f634d3324 | 65 | int len; |
jksoft | 0:0a2f634d3324 | 66 | char* data; |
jksoft | 0:0a2f634d3324 | 67 | } MQTTLenString; |
jksoft | 0:0a2f634d3324 | 68 | |
jksoft | 0:0a2f634d3324 | 69 | typedef struct |
jksoft | 0:0a2f634d3324 | 70 | { |
jksoft | 0:0a2f634d3324 | 71 | char* cstring; |
jksoft | 0:0a2f634d3324 | 72 | MQTTLenString lenstring; |
jksoft | 0:0a2f634d3324 | 73 | } MQTTString; |
jksoft | 0:0a2f634d3324 | 74 | |
jksoft | 0:0a2f634d3324 | 75 | #define MQTTString_initializer {NULL, {0, NULL}} |
jksoft | 0:0a2f634d3324 | 76 | |
jksoft | 0:0a2f634d3324 | 77 | int MQTTstrlen(MQTTString mqttstring); |
jksoft | 0:0a2f634d3324 | 78 | |
jksoft | 0:0a2f634d3324 | 79 | #include "MQTTConnect.h" |
jksoft | 0:0a2f634d3324 | 80 | #include "MQTTPublish.h" |
jksoft | 0:0a2f634d3324 | 81 | #include "MQTTSubscribe.h" |
jksoft | 0:0a2f634d3324 | 82 | #include "MQTTUnsubscribe.h" |
jksoft | 0:0a2f634d3324 | 83 | |
jksoft | 0:0a2f634d3324 | 84 | int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char type, unsigned char dup, unsigned short packetid); |
jksoft | 0:0a2f634d3324 | 85 | int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen); |
jksoft | 0:0a2f634d3324 | 86 | |
jksoft | 0:0a2f634d3324 | 87 | int MQTTPacket_len(int rem_len); |
jksoft | 0:0a2f634d3324 | 88 | int MQTTPacket_equals(MQTTString* a, char* b); |
jksoft | 0:0a2f634d3324 | 89 | |
jksoft | 0:0a2f634d3324 | 90 | int MQTTPacket_encode(unsigned char* buf, int length); |
jksoft | 0:0a2f634d3324 | 91 | int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value); |
jksoft | 0:0a2f634d3324 | 92 | int MQTTPacket_decodeBuf(unsigned char* buf, int* value); |
jksoft | 0:0a2f634d3324 | 93 | |
jksoft | 0:0a2f634d3324 | 94 | int readInt(unsigned char** pptr); |
jksoft | 0:0a2f634d3324 | 95 | char readChar(unsigned char** pptr); |
jksoft | 0:0a2f634d3324 | 96 | void writeChar(unsigned char** pptr, char c); |
jksoft | 0:0a2f634d3324 | 97 | void writeInt(unsigned char** pptr, int anInt); |
jksoft | 0:0a2f634d3324 | 98 | int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata); |
jksoft | 0:0a2f634d3324 | 99 | void writeCString(unsigned char** pptr, const char* string); |
jksoft | 0:0a2f634d3324 | 100 | void writeMQTTString(unsigned char** pptr, MQTTString mqttstring); |
jksoft | 0:0a2f634d3324 | 101 | |
jksoft | 0:0a2f634d3324 | 102 | int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); |
jksoft | 0:0a2f634d3324 | 103 | |
jksoft | 0:0a2f634d3324 | 104 | char* MQTTPacket_toString(char* strbuf, int strbuflen, unsigned char* buf, int buflen); |
jksoft | 0:0a2f634d3324 | 105 | |
jksoft | 0:0a2f634d3324 | 106 | #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ |
jksoft | 0:0a2f634d3324 | 107 | } |
jksoft | 0:0a2f634d3324 | 108 | #endif |
jksoft | 0:0a2f634d3324 | 109 | |
jksoft | 0:0a2f634d3324 | 110 | |
jksoft | 0:0a2f634d3324 | 111 | #endif /* MQTTPACKET_H_ */ |