You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
7.2 KiB
C

/*****************************************************************************
* 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
*
* <h2><center>&copy; COPYRIGHT(c) 2021 LandPower</center></h2>
*
* 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 <semaphore.h>
#include <termios.h>
#include <unistd.h>
#include "common.h"
1 week ago
#include "pd_main.h"
/* Define --------------------------------------------------------------------*/
#define DAU_ETH_SLOTS_SUM 4
#define RS485_SLOTS 2
#define DAU_BUF_SIZE 1536
/* Exported types ------------------------------------------------------------*/
typedef int32_t (*dau_recv_cb)(uint8_t, char*, uint16_t);
typedef int32_t (*dau_send_cb)(uint8_t, uint8_t, void*);
1 week ago
typedef void (*dau_data_free_cb)(uint8_t);
/* 命令类型. */
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_ADD = 1,
DAU_SEND_RESET = 2,
DAU_SEND_INFO_SET = 4,
DAU_SEND_INFO_GET = 5,
DAU_SEND_HEARTBEAT = 7,
DAU_SEND_CFG_SET = 8,
DAU_SEND_CFG_GET = 9,
DAU_SEND_PORT_SET = 10,
DAU_SEND_PORT_GET = 11,
DAU_SEND_PRPS_GET = 12,
DAU_SEND_PRPS = 14,
DAU_SEND_MAX
};
/* 发送数据消息 */
typedef struct
{
uint32_t type;
1 week ago
uint8_t slot;
uint8_t reserve[3];
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;
1 week ago
uint16_t beat_cnt;
} 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 收包处理函数
1 week ago
dau_data_free_cb free_cb; // 内存释放函数
int32_t fifo_send; // 发包 fifo
void *private_data;
} dau_t;
/* Exported macro ------------------------------------------------------------*/
/* 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);
1 week ago
extern int32_t dau_msg_send(uint32_t type, uint8_t slot, void *data);
extern int32_t dau_msg_send_cmd(uint32_t type, uint8_t slot, void *data);
#endif
#endif
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****/