/***************************************************************************** * file include/ca_mqtt.h * author YuLiang * version 1.0.0 * date 07-Dec-2023 * brief This file provides all the headers of the MQTT functions. ****************************************************************************** * Attention * *

© COPYRIGHT(c) 2023 LandPower

* * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of LandPower nor the names of its contributors may be used to * endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ******************************************************************************/ #ifndef __CA_MQTT_H__ #define __CA_MQTT_H__ #ifdef CFG_DEV_TYPE_LAND_CA /* Includes ------------------------------------------------------------------*/ #include "ca_collect.h" #include "cmd.h" #include "MQTTAsync.h" /* Define --------------------------------------------------------------------*/ #define CA_MQTT_FIFO "CA_MQTT_FIFO" #define NODE_NUM (1) #define TOPIC_WILL "offline/will" //遗嘱主题 #define QOS 1 #define DEVICE_MODEL "SD_JK_LD_FBDMX"// //#define DEVICE_MODEL "DL_WHLD_HL" #define MANUFACTURERID "WHLD" #define DEVICE_CODE "03MW00000000001" #define DEVICE_POINT_A "03MCD00000000001" #define DEVICE_POINT_B "03MCD00000000002" #define DEVICE_POINT_C "03MCD00000000003" /* Exported types ------------------------------------------------------------*/ /* MQTT 状态结构体 */ typedef struct { bool is_connect; // 是否连接 uint8_t login_err_cnt; // 4G 网络连接成功的情况下, 登录失败次数 } ca_mqtt_state_t; /* fifo 消息结构体 */ typedef struct { uint32_t type; // 类型 void *data; // 数据 } ca_mqtt_msg_t; typedef struct { char node_id[32]; char device_id[32]; } node_info_t; /* 全局控制结构体 */ typedef struct { int32_t fifo_id; // fifo id ca_mqtt_dev_info_t info; // MQTT 信息 ca_mqtt_state_t state; // MQTT 状态 MQTTAsync client; node_info_t node[NODE_NUM]; // 测点信息 } ca_mqtt_ctrl_t; /* Exported macro ------------------------------------------------------------*/ /* Extern global variables ---------------------------------------------------*/ /* Extern functions ----------------------------------------------------------*/ extern int32_t ca_mqtt_init(void); extern int32_t ca_mqtt_init_after(void); extern int32_t ca_mqtt_data_report(ca_coll_dev_data_t *data); extern ca_mqtt_state_t* ca_mqtt_state_get(void); extern void ca_mqtt_state_show(void); extern void _ca_mqtt_query_device_info(); extern int _ca_mqtt_gen_topic(char *topic, char *id, char *cmd); extern void _ca_mqtt_json_ground_current(ca_coll_dev_data_t *data, char *outmsg, int idx); extern int _ca_mqtt_data_report_child_device(ca_coll_dev_data_t *data, char *device_id, int idx); extern int _ca_mqtt_update_device_status(char *device_id); extern int _ca_mqtt_add_sub_device(node_info_t *node_info); #endif #endif /************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/