#ifndef __COM_TTYSX_H__
#define __COM_TTYSX_H__

#include "msystem.h"

typedef struct com_ttySx
{
    int fd;
    char devname[256];

    int debug;

    struct termios save_termios;
    struct termios curr_termios;

    pthread_mutex_t mutex;
}com_ttySx_t;

uint32_t com_crc32(uint8_t* buf, int len) ;

int comm_ttySx_reset(com_ttySx_t* dev);

int com_ttySx_init(com_ttySx_t* dev, const char* devname, int baudrate, int databits, int parbits, int stopbits);

int com_ttySx_send(com_ttySx_t* dev, char* txbuff, int txlen);

int com_ttySx_recv(com_ttySx_t* dev, char* rxbuff, int rxsize);

int com_ttySx_flush(com_ttySx_t* dev);

int com_ttySx_recv_with_timeout(com_ttySx_t* dev, char* rxbuff, int max_bytes, int timeout);

int com_ttySx_rs485_enable(com_ttySx_t* dev, int enable);

int com_ttySx_rs485_control(com_ttySx_t* dev, int send);

void com_ttySx_exit(com_ttySx_t* dev);

#endif//__COM_TTYSX_H__
