From e580cca85cb88a8424a4ca91664d2c6120f14339 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 14 Dec 2023 03:04:29 +0100 Subject: [PATCH] fix iio and hidraw reads --- dev_in.c | 8 ++++---- dev_out.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dev_in.c b/dev_in.c index d81aa3f..ddbc784 100644 --- a/dev_in.c +++ b/dev_in.c @@ -458,7 +458,7 @@ void* dev_in_thread_func(void *ptr) { // TODO: handle_leds() } } else { - fprintf(stderr, "Error reading from out_message_pipe_fd: got %zu bytes, expected %zu butes\n", out_message_pipe_read_res, sizeof(out_message_t)); + fprintf(stderr, "Error reading from out_message_pipe_fd: got %zu bytes, expected %zu bytes\n", out_message_pipe_read_res, sizeof(out_message_t)); // in case of an error reschedule to socket for reconnection if (dev_in_data->communication.type == ipc_client_socket) { @@ -506,15 +506,15 @@ void* dev_in_thread_func(void *ptr) { controller_msg_count = dev_in_data->input_dev_decl->dev[i]->map.ev_input_map_fn(&coll, &controller_msg[0], controller_msg_avail, dev_in_data->input_dev_decl->dev[i]->user_data); } else if (devices[i].type == DEV_IN_TYPE_IIO) { controller_msg_count = map_message_from_iio(&devices[i].dev.iio, &controller_msg[0], controller_msg_avail); - if (controller_msg_count != 0) { - fprintf(stderr, "Error in performing operations for device %zd: %d -- Will reconnect to the device\n", i, controller_msg_count); + if (controller_msg_count < 0) { + fprintf(stderr, "Error in reading iio buffer for device %zd: %d -- Will reconnect to the device\n", i, controller_msg_count); iio_close_device(&devices[i].dev.iio); devices[i].type = DEV_IN_TYPE_NONE; continue; } } else if (devices[i].type == DEV_IN_TYPE_HIDRAW) { controller_msg_count = dev_in_data->input_dev_decl->dev[i]->map.hidraw_input_map_fn(dev_hidraw_get_fd(devices[i].dev.hidraw.hidrawdev), &controller_msg[0], controller_msg_avail, dev_in_data->input_dev_decl->dev[i]->user_data); - if (controller_msg_count != 0) { + if (controller_msg_count < 0) { fprintf(stderr, "Error in performing operations for device %zd: %d -- Will reconnect to the device\n", i, controller_msg_count); hidraw_close_device(&devices[i].dev.hidraw); devices[i].type = DEV_IN_TYPE_NONE; diff --git a/dev_out.c b/dev_out.c index dcf1f9e..75901d8 100644 --- a/dev_out.c +++ b/dev_out.c @@ -358,7 +358,7 @@ void *dev_out_thread_func(void *ptr) { if (in_message_pipe_read_res == sizeof(in_message_t)) { handle_incoming_message(&incoming_message, &dev_out_data->dev_stats); } else { - fprintf(stderr, "Error reading from in_message_pipe_fd: got %zu bytes, expected %zu butes\n", in_message_pipe_read_res, sizeof(in_message_t)); + fprintf(stderr, "Error reading from in_message_pipe_fd: got %zu bytes, expected %zu bytes\n", in_message_pipe_read_res, sizeof(in_message_t)); } } } else if (dev_out_data->communication.type == ipc_server_sockets) { @@ -371,7 +371,7 @@ void *dev_out_thread_func(void *ptr) { if (in_message_pipe_read_res == sizeof(in_message_t)) { handle_incoming_message(&incoming_message, &dev_out_data->dev_stats); } else { - fprintf(stderr, "Error reading from socket number %d: got %zu bytes, expected %zu butes\n", i, in_message_pipe_read_res, sizeof(in_message_t)); + fprintf(stderr, "Error reading from socket number %d: got %zu bytes, expected %zu bytes\n", i, in_message_pipe_read_res, sizeof(in_message_t)); close(dev_out_data->communication.endpoint.ssocket.clients[i]); dev_out_data->communication.endpoint.ssocket.clients[i] = -1; }