/***************************************************************************** * 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 enum { DAU_TYPE_UDP, DAU_TYPE_RS485, DAU_TYPE_NONE } DauType; // 板卡状态枚举 typedef enum { DAU_STATE_DISCONNECTED, DAU_STATE_CONNECTED, DAU_STATE_REGISTERED } DauState; // 通信回调函数类型 //typedef void (*data_recv_callback)(void* priv_data, const void* data, size_t len); //typedef void (*data_send_callback)(void* priv_data, void* data, size_t len); // 板卡私有数据结构 typedef struct { DauType type; union { struct { int sockfd; struct sockaddr_in addr; } udp; struct { int fd; char port[20]; struct termios options; } rs485; } comm; char board_id[32]; void *rx_buffer; size_t buffer_size; uint8_t cmd_type; uint8_t cmd; } dau_private_data_t; // 板卡操作回调函数结构 typedef struct { int (*init)(dau_private_data_t *data, const char *config); int (*receive)(dau_private_data_t *data, void *buf, size_t len); int (*transmit)(dau_private_data_t *data, const void *buf, size_t len); void (*cleanup)(dau_private_data_t *data); } dau_operations_t; // UDP客户端信息 typedef struct { struct sockaddr_in addr; char board_id[32]; } udp_client_data; // RS485设备信息 typedef struct { int fd; // 串口文件描述符 char board_id[32]; uint8_t address; // 从机地址 } rs485_device_data; 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[32]; // 软件版本 uint8_t app_compile_time[32]; // 软件编译时间 uint8_t hardware_version[32]; // 硬件版本 uint8_t FPGA_version[32]; // fpga版本 uint32_t ip; // 本机 IP. uint32_t mask; // 本机 MASK. uint32_t gw; // 本机网关 uint8_t mac[6]; // MAC地址. uint16_t server_port; // 服务器端口号. uint32_t server_ipv4; // 服务器 IP. uint8_t port[8]; uint8_t port_type[8]; } dau_info_t; // 板卡管理器结构 typedef struct { //dau_private_data_t *private_data; dau_operations_t ops; // udp int sockfd; struct sockaddr_in addr; // rs485 int fd; char port[20]; struct termios options; char board_id[32]; void *rx_buffer; size_t buffer_size; uint8_t cmd_type; uint8_t cmd; pthread_t thread_id; int slot; bool occupied; // 槽位占用标志 dau_info_t info; } dau_manager_t; /* DAU 状态结构体 */ typedef struct { uint8_t is_insert:1; uint8_t is_connect:1; } dau_state_t; /* DAU 全局结构体 */ typedef struct { uint8_t slot; DauType type; int fd; char buf_recv[DAU_BUF_SIZE]; DauState stat; void *private_data; dau_info_t info; dau_state_t state; } 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_response(int slot, char *buf, int len); #endif #endif /************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/