/*
 * @Author: ybzhou yibo.zhou@lnxall.com
 * @Date: 2025-01-31 22:43:11
 * @LastEditors: ybzhou yibo.zhou@lnxall.com
 * @LastEditTime: 2025-02-03 09:48:43
 * @FilePath: /proto_forward/src/ydt1363.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __YDT1363_H__
#define __YDT1363_H__

#include <stdint.h>

typedef struct ydt1363_hd_t ydt1363_hd_t;
typedef struct ydt1363_if
{
    int (*connect)(ydt1363_hd_t *hd);
    int (*tx)(ydt1363_hd_t *hd, const void *buff, uint32_t len);
    int (*rx)(ydt1363_hd_t *hd, void *buff, uint32_t max_len);
    int (*flush)(ydt1363_hd_t *hd);
    int (*dis_connect)(ydt1363_hd_t *hd);
    int (*free)(ydt1363_hd_t *hd);
} ydt1363_if;

struct ydt1363_hd_t
{
    char name[32];
    int fd;
    int error_recovery;
    ydt1363_if *if_funs;
    void *data;
    uint32_t read_time_out;
    uint32_t interval;
};


//
ydt1363_hd_t *new_ydt1363_uart(char *dev, int baud, uint8_t data_bit, uint8_t stop_bit, char parity);
int ydt1363_set_name(ydt1363_hd_t *hd, char *new_name);
int ydt1363_connect(ydt1363_hd_t *hd);
int ydt1363_dis_connect(ydt1363_hd_t *hd);
int ydt1363_free(ydt1363_hd_t *hd);
int ydt1363_set_time(ydt1363_hd_t *hd, uint32_t timeout_ms, uint32_t interval);
int ydt1363_read(ydt1363_hd_t *hd, void *tx_buff, int tx_buff_len, void *rx_buff, int rx_buff_len);
int ydt1363_write(ydt1363_hd_t *hd, void *tx_buff, int tx_buff_len, void *rx_buff, int rx_buff_len);
#endif

