forked from gary/ems
2
0
Fork 0
sun_ems/ems_c/driver/drv_tcp_client.h

69 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*****************************************************************************
* @copyright 2024-2024, . POWER SUPPLY CO., LTD.
* @file drv_tcp.h
* @brief 驱动文件
* @author Gary
* @date 2024/09/03
* @remark 初修订
*****************************************************************************/
#ifndef DRY_TCP_H_
#define DRY_TCP_H_
#include <stdint.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <sys/select.h>
#include "drv_comm.h"
#include <stdio.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "kit_log.h"
#include "kit_data.h"
#include "bsp_rtdb.h"
// tcp client驱动结构体
typedef struct
{
int socket_fd; // socket fd
uint8_t netId; // NET口对应序号
uint16_t uId; // 设备序号
char ip[MAX_TCP_IP_LEN]; // ip地址
conn_status_e status; // 连接状态 0离线 1在线
uint32_t port; // 端口号
uint16_t timeout; // 超时时间(milisecond)
uint16_t count; // 超时次数
uint32_t send_len; // 发送报文的长度
uint32_t recv_len; // 接收报文的长度
uint8_t send_buf[MAX_TCP_LEN]; // 发送报文缓存
uint8_t recv_buf[MAX_TCP_LEN]; // 接收报文缓存
} tcp_client_lib_t;
/*****************************************************************************
* @brief 打开tcp驱动
* @param[in] p_tcp: tcp驱动结构体指针
* @return 0-成功 1-失败
*****************************************************************************/
int drvTcpOpen(tcp_client_lib_t *p_tcp);
/*****************************************************************************
* @brief 关闭tcp驱动
* @param[in] p_tcp: tcp驱动结构体指针
* @return 0-成功 1-失败
*****************************************************************************/
int drvTcpClose(tcp_client_lib_t *p_tcp);
/*****************************************************************************
* @brief tcp驱动发送
* @param[in] p_tcp: tcp驱动结构体指针
* @return 0-成功 1-失败
*****************************************************************************/
int drvTcpSend(tcp_client_lib_t *p_tcp);
/*****************************************************************************
* @brief tcp驱动接收
* @param[in] p_tcp: tcp驱动结构体指针
* @return 0-成功 1-失败
*****************************************************************************/
int drvTcpRecv(tcp_client_lib_t *p_tcp);
#endif