#ifndef _INCLUDE_LWMQTT_MAIN_H_ #define _INCLUDE_LWMQTT_MAIN_H_ #include "os_types_api.h" #include "iot_pkt_api.h" #include "lwmqtt.h" #define LWMQTT_HTON_L(x) ((((x) >> 24) & 0x0000FF) |(((x) >> 8) & 0x0000FF00)\ | (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000)) #define LWMQTT_HTON_S(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00)) #define LWMQTT_DEBUG(x) do {\ iot_cus_printf x;\ } while(0) /* Indicate the source of message where from. */ #define LWMQTT_SOURCE_ETH 0 /* message from ETH port. */ #define LWMQTT_SOURCE_PLC 1 /* message from PLC port. */ /* TODO : Do we need a mid ? */ #define LWMQTT_MID 0 #define LWMQTT_MIN(x, y) ((x) > (y) ? (y) : (x)) /* Type of funciotn that sends raw data to lowlayer */ typedef uint8_t(*data_send_to_lowlayer)(uint8_t *buf, uint16_t buf_len); /** * @brief lwmqtt_message_public() - Public a MQTT message to server. * @param t: Topic of MQTT message. * @param m: Message data of MQTT message. */ void lwmqtt_message_public(lwmqtt_string_t *t, lwmqtt_message_t *m); /** * @brief lwmqtt_register_fn_message_to_ge() - Register a function that puts MQTT raw data to GE layer. * @param fn: Pointer of function to register. Reference to typedef data_send_to_lowlayer. */ void lwmqtt_register_fn_message_to_ge(void *fn); /** * @brief lwmqtt_message_received_from_ge() - Handle the MQTT raw data post from GE layer. * @return: ERR_OK -- Process the message successfully. * @return: ERR_FAIL -- Error occurs when process this message. */ uint32_t lwmqtt_message_received_from_ge(iot_pkt_t *p_pkt_frame); /** * @brief lwmqtt_message_send_to_lowlayer_ge() - Send a GE-MQTT message to GE port to the remote devices. * @param fn: Pointer of function to register. Reference to typedef data_send_to_lowlayer. */ void lwmqtt_message_send_to_lowlayer_ge(uint8_t *mq_str, uint16_t str_len); /** * @brief lwmqtt_lwip_init() - Initialize whole mqtt module. * @return: ERR_OK -- Initialize the mqtt successfully. * @return: ERR_FAIL -- Error occurs when initialize mqtt. */ uint32_t lwmqtt_lwip_init(void); #endif