1 /** 2 * @file dm_private.h 3 * @brief 数据模型模块内部头文件 4 * @date 2020-01-20 5 * 6 * @copyright Copyright (C) 2015-2020 Alibaba Group Holding Limited 7 * 8 */ 9 10 #ifndef __DM_PRIVATE_H__ 11 #define __DM_PRIVATE_H__ 12 13 #if defined(__cplusplus) 14 extern "C" { 15 #endif 16 17 #include "core_stdinc.h" 18 #include "core_string.h" 19 #include "core_log.h" 20 #include "core_diag.h" 21 #include "core_global.h" 22 #include "core_mqtt.h" 23 24 #include "aiot_sysdep_api.h" 25 #include "aiot_state_api.h" 26 #include "aiot_mqtt_api.h" 27 #include "aiot_dm_api.h" 28 29 /* 模块内部名 */ 30 #define DATA_MODEL_MODULE_NAME "dm" 31 32 /* ALINK请求的JSON格式 */ 33 #define ALINK_REQUEST_FMT "{\"id\":\"%s\",\"version\":\"1.0\",\"params\":%s,\"sys\":{\"ack\":%s}}" 34 /* ALINK应答的JSON格式 */ 35 #define ALINK_RESPONSE_FMT "{\"id\":\"%s\",\"code\":%s,\"data\":%s}" 36 #define ALINK_JSON_KEY_ID "id" 37 #define ALINK_JSON_KEY_CODE "code" 38 #define ALINK_JSON_KEY_PARAMS "params" 39 #define ALINK_JSON_KEY_DATA "data" 40 #define ALINK_JSON_KEY_MESSAGE "message" 41 42 /* 诊断消息类型 */ 43 #define DM_DIAG_MSG_TYPE_REQ (0x00) 44 #define DM_DIAG_MSG_TYPE_RSP (0x01) 45 46 #define DM_FREE(ptr) do {if (ptr) {dm_handle->sysdep->core_sysdep_free(ptr); ptr = NULL;}} while (0) 47 48 /* data-model模块的上下文结构体定义 */ 49 typedef struct { 50 aiot_sysdep_portfile_t *sysdep; 51 void *mqtt_handle; 52 53 aiot_dm_recv_handler_t recv_handler; 54 void *userdata; 55 uint8_t post_reply; 56 } dm_handle_t; 57 58 /* data-model内部发送函数原型定义 */ 59 typedef int32_t (*dm_msg_send_func_t)(dm_handle_t *handle, const char *topic, const aiot_dm_msg_t *msg); 60 61 /* 包含上行topic和对应处理函数的结构体定义 */ 62 typedef struct { 63 char *topic; 64 dm_msg_send_func_t func; 65 } dm_send_topic_map_t; 66 67 /* 包含下行topic和对应处理函数的结构体定义 */ 68 typedef struct { 69 char *topic; 70 aiot_mqtt_recv_handler_t func; 71 } dm_recv_topic_map_t; 72 73 #if defined(__cplusplus) 74 } 75 #endif 76 77 #endif /* #ifndef __DM_PRIVATE_H__ */ 78 79