diff options
Diffstat (limited to 'rpc_client_serial.c')
-rw-r--r-- | rpc_client_serial.c | 56 |
1 files changed, 4 insertions, 52 deletions
diff --git a/rpc_client_serial.c b/rpc_client_serial.c index 5194793..ec53e05 100644 --- a/rpc_client_serial.c +++ b/rpc_client_serial.c @@ -47,70 +47,22 @@ #define DEVICE "/dev/ttyUSB0" #define SPEED B115200 -static int fd = -1; - hal_error_t hal_rpc_client_transport_init(void) { - struct termios tty; - - fd = open(DEVICE, O_RDWR | O_NOCTTY | O_SYNC); - if (fd == -1) - return perror("open"), HAL_ERROR_RPC_TRANSPORT; - - if (tcgetattr (fd, &tty) != 0) - return perror("tcgetattr"), HAL_ERROR_RPC_TRANSPORT; - - cfsetospeed (&tty, SPEED); - cfsetispeed (&tty, SPEED); - - tty.c_cflag &= ~CSIZE; - tty.c_cflag |= (CS8 | CLOCAL | CREAD); - - tty.c_iflag = 0; - tty.c_oflag = 0; - tty.c_lflag = 0; - - tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 0; - - if (tcsetattr (fd, TCSANOW, &tty) != 0) - return perror("tcsetattr"), HAL_ERROR_RPC_TRANSPORT; - - return HAL_OK; + return hal_serial_init(DEVICE, SPEED); } hal_error_t hal_rpc_client_transport_close(void) { - int ret = close(fd); - fd = -1; - if (ret != 0) - return perror("close"), HAL_ERROR_RPC_TRANSPORT; - return HAL_OK; + return hal_serial_close(); } hal_error_t hal_rpc_send(const uint8_t * const buf, const size_t len) { - if (hal_slip_send(buf, len) == -1) - return HAL_ERROR_RPC_TRANSPORT; - return HAL_OK; + return hal_slip_send(buf, len); } hal_error_t hal_rpc_recv(uint8_t * const buf, size_t * const len) { - int ret; - - if ((ret = hal_slip_recv(buf, *len)) == -1) - return HAL_ERROR_RPC_TRANSPORT; - *len = ret; - return HAL_OK; -} - -int hal_slip_send_char(const uint8_t c) -{ - return write(fd, &c, 1); -} - -int hal_slip_recv_char(uint8_t * const c) -{ - return read(fd, c, 1); + return hal_slip_recv(buf, *len); } |