#ifndef _MY_COMM_H_ #define _MY_COMM_H_ #include #ifdef __cplusplus extern "C" { #endif #define COMM_IP_LEN 16 #define COMM_DEV_LEN 256 typedef enum { COMM_TYPE_UNKNOWN, COMM_TYPE_TCP_SERVER, COMM_TYPE_TCP_CLIENT, COMM_TYPE_UDP_SERVER, COMM_TYPE_UDP_CLIENT, COMM_TYPE_UART, }CommType; typedef enum { COMM_DEBUG_OFF, COMM_DEBUG_ON, }CommDebugShow; typedef enum { COMM_STATE_DISCONNECTED, COMM_STATE_CONNECTED, }CommState; typedef enum { COMM_FD_UNKNOWN = 0, COMM_FD_FILE, COMM_FD_SOCKET, COMM_FD_SERIAL, COMM_FD_PIPE, }CommFdType; typedef struct { char local_ip[COMM_IP_LEN]; uint16_t local_port; char remote_ip[COMM_IP_LEN]; uint16_t remote_port; }stru_tcp_para; typedef struct { char local_ip[COMM_IP_LEN]; uint16_t local_port; char remote_ip[COMM_IP_LEN]; uint16_t remote_port; }stru_udp_para; typedef struct { char device[COMM_DEV_LEN]; uint32_t baudrate; uint8_t data_bits; uint8_t stop_bits; uint8_t parity; }stru_uart_para; typedef struct { CommFdType type; union { struct { char local_ip[16]; int local_port; char remote_ip[16]; int remote_port; int protocol; // SOCK_STREAM or SOCK_DGRAM } socket_info; struct { char device[256]; int baud_rate; int data_bits; int stop_bits; char parity[8]; } serial_info; struct { char filename[256]; off_t size; } file_info; }; }stru_comm_fd_info; typedef void (*comm_state_cb)(int id, int socket_fd, CommState state); typedef void (*comm_recv_cb)(int id, int socket_fd, const uint8_t*data, uint16_t len); int comm_create(CommType type, CommDebugShow debug_show, void *p_para); int comm_connect(int id); int comm_disconnect(int id); int comm_send(int id, int fd, const uint8_t *data, uint16_t len); int comm_recv_register(int id, comm_recv_cb cb); int comm_state_register(int id, comm_state_cb cb); int comm_destroy(int id); #ifdef __cplusplus } #endif #endif