Updated formatting with astyle -A14 -S

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
This commit is contained in:
A.M. Rowsell 2019-03-04 12:58:17 -05:00
commit 7c5dfae57b
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9
7 changed files with 651 additions and 638 deletions

87
mqtt.h
View file

@ -20,7 +20,7 @@
#include "espconn.h"
#include "os_type.h"
//#define DEBUG 1 /**< This define enables or disables serial debug output in most places */
#define DEBUG 1 /**< This define enables or disables serial debug output in most places */
/**
* @typedef
@ -28,22 +28,21 @@
*
* This enum was taken from the NodeMCU mqtt headers. Credit is given to "zeroday" of nodemcu.com. This enum gives us both easily readable names for each message type, but also the correct value for each type. These are used in mqttSend() to construct the correct packet type.
*/
typedef enum mqtt_message_enum
{
MQTT_MSG_TYPE_CONNECT = 1,
MQTT_MSG_TYPE_CONNACK = 2,
MQTT_MSG_TYPE_PUBLISH = 3,
MQTT_MSG_TYPE_PUBACK = 4,
MQTT_MSG_TYPE_PUBREC = 5,
MQTT_MSG_TYPE_PUBREL = 6,
MQTT_MSG_TYPE_PUBCOMP = 7,
MQTT_MSG_TYPE_SUBSCRIBE = 8,
MQTT_MSG_TYPE_SUBACK = 9,
MQTT_MSG_TYPE_UNSUBSCRIBE = 10,
MQTT_MSG_TYPE_UNSUBACK = 11,
MQTT_MSG_TYPE_PINGREQ = 12,
MQTT_MSG_TYPE_PINGRESP = 13,
MQTT_MSG_TYPE_DISCONNECT = 14
typedef enum mqtt_message_enum {
MQTT_MSG_TYPE_CONNECT = 1,
MQTT_MSG_TYPE_CONNACK = 2,
MQTT_MSG_TYPE_PUBLISH = 3,
MQTT_MSG_TYPE_PUBACK = 4,
MQTT_MSG_TYPE_PUBREC = 5,
MQTT_MSG_TYPE_PUBREL = 6,
MQTT_MSG_TYPE_PUBCOMP = 7,
MQTT_MSG_TYPE_SUBSCRIBE = 8,
MQTT_MSG_TYPE_SUBACK = 9,
MQTT_MSG_TYPE_UNSUBSCRIBE = 10,
MQTT_MSG_TYPE_UNSUBACK = 11,
MQTT_MSG_TYPE_PINGREQ = 12,
MQTT_MSG_TYPE_PINGRESP = 13,
MQTT_MSG_TYPE_DISCONNECT = 14
} mqtt_message_type;
/**
@ -53,14 +52,14 @@ typedef enum mqtt_message_enum
* This structure contains pointers to the three main parts of an MQTT packet: the fixed header, the variable header, and the payload. Not all message types contain a variable header or payload, but *all* message types have a fixed header.
*/
typedef struct {
uint8_t *fixedHeader; /**< The pointer to the fixed header bytes */
uint32_t fixedHeader_len; /**< The length of the fixed header */
uint8_t *varHeader; /**< The pointer to the variable header bytes */
uint32_t varHeader_len; /**< The length of the variable header */
uint8_t *payload; /**< The pointer to the payload bytes */
uint32_t payload_len; /**< The length of the payload */
uint32_t length; /**< The full length of the packet */
mqtt_message_type msgType; /**< What message type this packet contains */
uint8_t *fixedHeader; /**< The pointer to the fixed header bytes */
uint32_t fixedHeader_len; /**< The length of the fixed header */
uint8_t *varHeader; /**< The pointer to the variable header bytes */
uint32_t varHeader_len; /**< The length of the variable header */
uint8_t *payload; /**< The pointer to the payload bytes */
uint32_t payload_len; /**< The length of the payload */
uint32_t length; /**< The full length of the packet */
mqtt_message_type msgType; /**< What message type this packet contains */
} mqtt_packet_t;
/**
@ -68,24 +67,24 @@ typedef struct {
* Structure that contains all the information to establish and maintain a TCP-based MQTT connection to the broker
*/
typedef struct {
uint8_t ip[4]; /**< An array containing the four bytes of the IP address of the broker */
uint32_t port; /**< The port the broker is listening on */
uint32_t localPort; /**< The local port returned by the ESP8266 function espconn_port() */
uint8_t *client_id; /**< Pointer to the client ID string */
uint32_t client_id_len; /**< Length of the client ID string */
uint8_t *topic_name; /**< Pointer to the topic name string */
uint32_t topic_name_len; /**< Length of the topic name string */
uint8_t qos_level; /**< QOS level of the MQTT connection (always 0, not currently used) */
uint8_t *username; /**< Pointer to the username string, for brokers which require authentication */
uint32_t username_len; /**< The length of the username string */
uint8_t *password; /**< Pointer to the password string, for brokers which require password authentication */
uint32_t password_len; /**< The length of the password string */
char validConnection; /**< Boolean value which indicates whether or not the TCP connection is established, set in tcpConnect() */
struct espconn *activeConnection; /**< A pointer to the espconn structure containing details of the TCP connection */
void *userData; /**< Used to pass data to the PUBLISH function */
// Add pointers to user callback functions
void (*publish_cb)(void *arg); /**< Pointer to user callback function for publish */
void (*connack_cb)(void *arg); /**< Pointer to user callback function for connack */
uint8_t ip[4]; /**< An array containing the four bytes of the IP address of the broker */
uint32_t port; /**< The port the broker is listening on */
uint32_t localPort; /**< The local port returned by the ESP8266 function espconn_port() */
uint8_t *client_id; /**< Pointer to the client ID string */
uint32_t client_id_len; /**< Length of the client ID string */
uint8_t *topic_name; /**< Pointer to the topic name string */
uint32_t topic_name_len; /**< Length of the topic name string */
uint8_t qos_level; /**< QOS level of the MQTT connection (always 0, not currently used) */
uint8_t *username; /**< Pointer to the username string, for brokers which require authentication */
uint32_t username_len; /**< The length of the username string */
uint8_t *password; /**< Pointer to the password string, for brokers which require password authentication */
uint32_t password_len; /**< The length of the password string */
char validConnection; /**< Boolean value which indicates whether or not the TCP connection is established, set in tcpConnect() */
struct espconn *activeConnection; /**< A pointer to the espconn structure containing details of the TCP connection */
void *userData; /**< Used to pass data to the PUBLISH function */
// Add pointers to user callback functions
void (*publish_cb)(void *arg); /**< Pointer to user callback function for publish */
void (*connack_cb)(void *arg); /**< Pointer to user callback function for connack */
} mqtt_session_t;
/**
@ -135,7 +134,7 @@ uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength);
* @param session a pointer to the active mqtt_session_t
* @param data a pointer to the data to be published; only applied to MQTT_MSG_TYPE_PUBLISH
* @param len the length of the above data
* @param msgType the type of message to be send, one of the mqtt_message_type
* @param msgType the type of message to be sent, one of the mqtt_message_type
* @return -1 in case of error, 0 otherwise
*/
uint8_t ICACHE_FLASH_ATTR mqttSend(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType);