/***************************************************************************** * file include/pd_dau.h * author YuLiang * version 1.0.0 * date 03-Feb-2023 * brief This file provides all the headers of the dau functions. ****************************************************************************** * Attention * *

© COPYRIGHT(c) 2021 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 __PD_DAU_H__ #define __PD_DAU_H__ #ifdef CFG_DEV_TYPE_LAND_PD /* Includes ------------------------------------------------------------------*/ #include #include #include #include "pd_main.h" #include "common.h" /* Define --------------------------------------------------------------------*/ #define DAU_ETH_SLOTS_SUM 4 #define RS485_SLOTS 2 #define DAU_BUF_SIZE 1536 #define UHF "UDP_UHF" #define HF "UDP_HF" #define ULTRASONIC "UDP_ULTRASONIC" #define IRONCORE "RS485_IRONCORE" /* Exported types ------------------------------------------------------------*/ typedef int32_t (*dau_recv_cb)(uint8_t, char*, uint16_t); typedef int32_t (*dau_send_cb)(uint8_t, uint8_t, void*); typedef void (*dau_recv_fun_cb)(uint8_t, char*, uint16_t); typedef void (*dau_send_fun_cb)(uint8_t, void*); /* 命令类型. */ enum DAU_CMD_TYPE { DAU_REQUEST = 1, DAU_REPLY = 2, DAU_PRV_REQUEST = 121, DAU_PRV_REPLY = 122 }; /* 共有命令字. */ enum DAU_CMD { DAU_C_CONTACT = 1, DAU_C_ADD_DAU = 2, DAU_C_RESET = 3, DAU_C_UPDATE = 5, DAU_C_DEV_INFO_SET = 6, DAU_C_DEV_INFO_GET = 7, DAU_C_UPDATE_RESULT = 9, DAU_C_HEARTBEAT = 10, DAU_C_MAX }; /* 私有命令字. */ enum DAU_P_CMD { DAU_P_CONFIG_SET = 1, // 设备全局参数设置 DAU_P_CONFIG_GET = 2, // 设备全局参数获取 DAU_P_CONFIG_PORT_SET = 3, // 设备端口参数设置 DAU_P_CONFIG_PORT_GET = 4, // 设备端口参数获取 DAU_P_CONFIG_REAL_WAVE = 5, // 实时波形配置 DAU_P_TREND = 10, DAU_P_REAL_PRPS = 11, DAU_P_EVENT = 12, DAU_P_MAX }; /* 命令类型. */ enum DAU_SEND_TYPE { DAU_SEND_PRPS = 1, DAU_SEND_MAX }; /* 发送数据消息 */ typedef struct { uint32_t type; void *data; } dau_send_msg_t; /* 报文头初始化结构体 */ typedef struct { uint8_t cmd_type; uint8_t cmd; uint16_t pkt_id; char *pkt; uint32_t len; } dau_head_init_t; /* 应答报文 */ typedef struct { uint8_t result; // 应答结果. 0:成功 1:失败 uint8_t reserved[3]; // 保留 } dau_ack_t; /* 报文头 */ typedef struct { uint16_t len; uint8_t dev_type_m; uint8_t dev_type_s; uint32_t dev_id; uint8_t cmd_type; uint8_t cmd; uint16_t pkt_id; uint8_t version; uint8_t reserve1[2]; uint8_t slot; uint32_t sdev_id; uint8_t reserve2[12]; } dau_pkt_head_t; /* 开机联络 */ typedef struct { uint8_t type_m; // 主设备号 uint8_t type_s; // 次设备号 uint8_t reserved1[2]; // 保留 uint32_t dev_id; // 设备ID char hostname[FILE_NAME_LEN]; // 设备名 128byte uint32_t factory_date; // 出厂日期. uint32_t deployment_date; // 部署日期. uint8_t app_version[DEV_VERSION_STR_LEN]; // 软件版本 uint8_t app_compile_time[DEV_VERSION_STR_LEN]; // 软件编译时间 uint8_t hardware_version[DEV_VERSION_STR_LEN]; // 硬件版本 uint8_t FPGA_version[DEV_VERSION_STR_LEN]; // fpga版本 uint32_t ip; // 本机 IP. uint32_t mask; // 本机 MASK. uint32_t gw; // 本机网关 uint8_t mac[MAC_ADDR_LEN]; // MAC地址. uint16_t server_port; // 服务器端口号. uint32_t server_ipv4; // 服务器 IP. uint8_t port[PD_PORT_SUM]; uint8_t port_type[PD_PORT_SUM]; } dau_contact_t; /* DAU 状态结构体 */ typedef struct { uint8_t is_insert:1; uint8_t is_connect:1; } dau_state_t; /* DAU 全局结构体 */ typedef struct { uint8_t slot; // dau slot uint16_t pkt_id; // 发送报文 id int fd; // dau socket fd struct sockaddr_in server; // dau client ip char buf_recv[DAU_BUF_SIZE]; // dau 收包 buf char buf_send[DAU_BUF_SIZE]; // dau 发包 buf dau_contact_t info; // dau 信息 dau_state_t state; // dau 状态 dau_recv_cb recv_cb; // dau 收包处理函数 dau_send_cb send_cb; // dau 收包处理函数 int32_t fifo_send; // 发包 fifo void *private_data; } dau_t; /* Exported macro ------------------------------------------------------------*/ #define SET_BIT(REG, BIT) ((REG) |= (BIT)) #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT)) #define READ_BIT(REG, BIT) ((REG) & (BIT)) #define WRITE_REG(REG, VAL) ((REG) = (VAL)) #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((REG) & (~(CLEARMASK))) | (SETMASK))) #define DAU_REG_PORT_ADDR_GET(port) ((port + 1) << 8) /* Extern global variables ---------------------------------------------------*/ extern dau_t daus[PD_SLOTS_MAX]; /* Extern functions ----------------------------------------------------------*/ extern int32_t dau_handle_init(void); extern int32_t dau_handle_init_after(void); extern void dau_data_send(dau_t *dau, dau_head_init_t *head_data); extern int32_t dau_msg_send_cmd(uint32_t type, void *data); #endif #endif /************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/