#ifndef HY_COMM_H
#define HY_COMM_H
#include <stdint.h>
#include <termios.h>
#include <limits.h>
#define MAX_DATA_LENGTH 246
#define MAX_QUERY_LENGTH 55
#define MAX_RESPONSE_LENGTH 1024
#define MIN_QUERY_SIZE 8
#define MAX_PACKET_SIZE 8
#define TIME_OUT_BEGIN_OF_FRAME 500000
#define TIME_OUT_END_OF_FRAME 500000
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define COMM_TIME_OUT -0x0C
#define PORT_SOCKET_FAILURE -0x0D
#define SELECT_FAILURE -0x0E
#define TOO_MANY_DATAS -0x0F
#define INVALID_CRC -0x10
#define INVALID_EXCEPTION_CODE -0x11
#define FUNCTION_READ 0x01
#define FUNCTION_WRITE 0x02
#define WRITE_CONTROL_DATA 0x03
#define READ_CONTROL_STATUS 0x04
#define WRITE_FREQ_DATA 0x05
#define LOOP_TEST 0x08
#define COMMS_FAILURE 0
#define ILLEGAL_FUNCTION -1
#define ILLEGAL_PARAMETER -2
#define ILLEGAL_DATA_VALUE -3
#define SLAVE_DEVICE_FAILURE -4
#define ACKNOWLEDGE -5
#define SLAVE_DEVICE_BUSY -6
#define NEGATIVE_ACKNOWLEDGE -7
#define MEMORY_PARITY_ERROR -8
#define PORT_FAILURE -11
typedef struct _hycomm_param_t {
char device[PATH_MAX];
int print_errors;
int baud;
char parity[5];
int data_bit;
int stop_bit;
struct termios old_tios;
int fd;
int debug;
} hycomm_param_t;
typedef struct _hycomm_data_t {
unsigned char slave;
unsigned char function;
unsigned char parameter;
int data;
unsigned char ret_length;
unsigned char ret_parameter;
int ret_data;
} hycomm_data_t;
void hycomm_init(hycomm_param_t *hc_param, const char *device,
int baud, const char *parity, int data_bit,
int stop_bit);
void hycomm_close(hycomm_param_t *hc_param);
void hycomm_init_rtu(hycomm_param_t *hc_param, const char *device,
int baud, const char *parity, int data_bit,
int stop_bit);
int hycomm_connect(hycomm_param_t *hc_param);
int hy_comm(hycomm_param_t *hc_param, hycomm_data_t *hc_data);
#endif