#ifndef __CUS_H__
#define __CUS_H__

#include <stdint.h>

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

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


//
custom_hd_t *new_custom_uart(char *dev, int baud, uint8_t data_bit, uint8_t stop_bit, char parity);
int custom_set_name(custom_hd_t *hd, char *new_name);
int custom_connect(custom_hd_t *hd);
int custom_dis_connect(custom_hd_t *hd);
int custom_free(custom_hd_t *hd);
int custom_set_time(custom_hd_t *hd, uint32_t timeout_ms, uint32_t interval);
int custom_read(custom_hd_t *hd, void *tx_buff, int tx_buff_len, void *rx_buff, int rx_buff_len);
int custom_write(custom_hd_t *hd, void *tx_buff, int tx_buff_len, void *rx_buff, int rx_buff_len);
#endif

