lib/voe_handler.c
branchstable-1.5
changeset 2433 3bdd7a747fae
parent 2432 f4313f5aba88
child 2479 b7f84bebd965
--- a/lib/voe_handler.c	Thu Sep 20 09:20:51 2012 +0200
+++ b/lib/voe_handler.c	Thu Sep 20 15:28:25 2012 +0200
@@ -2,7 +2,7 @@
  *
  *  $Id$
  *
- *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
+ *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
  *
  *  This file is part of the IgH EtherCAT master userspace library.
  *
@@ -35,15 +35,13 @@
 /*****************************************************************************/
 
 #include <stdlib.h>
-#include <sys/ioctl.h>
 #include <stdio.h>
-#include <errno.h>
 #include <string.h>
 
+#include "ioctl.h"
 #include "voe_handler.h"
 #include "slave_config.h"
 #include "master.h"
-#include "master/ioctl.h"
 
 /*****************************************************************************/
 
@@ -60,16 +58,17 @@
         uint16_t vendor_type)
 {
     ec_ioctl_voe_t data;
+    int ret;
 
     data.config_index = voe->config->index;
     data.voe_index = voe->index;
     data.vendor_id = &vendor_id;
     data.vendor_type = &vendor_type;
 
-    if (ioctl(voe->config->master->fd,
-                EC_IOCTL_VOE_SEND_HEADER, &data) == -1) {
+    ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_SEND_HEADER, &data);
+    if (EC_IOCTL_IS_ERROR(ret)) {
         fprintf(stderr, "Failed to set VoE send header: %s\n",
-                strerror(errno));
+                strerror(EC_IOCTL_ERRNO(ret)));
     }
 }
 
@@ -79,16 +78,17 @@
         uint32_t *vendor_id, uint16_t *vendor_type)
 {
     ec_ioctl_voe_t data;
+    int ret;
 
     data.config_index = voe->config->index;
     data.voe_index = voe->index;
     data.vendor_id = vendor_id;
     data.vendor_type = vendor_type;
 
-    if (ioctl(voe->config->master->fd,
-                EC_IOCTL_VOE_REC_HEADER, &data) == -1) {
+    ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_REC_HEADER, &data);
+    if (EC_IOCTL_IS_ERROR(ret)) {
         fprintf(stderr, "Failed to get received VoE header: %s\n",
-                strerror(errno));
+                strerror(EC_IOCTL_ERRNO(ret)));
     }
 }
 
@@ -111,13 +111,15 @@
 void ecrt_voe_handler_read(ec_voe_handler_t *voe)
 {
     ec_ioctl_voe_t data;
-
-    data.config_index = voe->config->index;
-    data.voe_index = voe->index;
-
-    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ, &data) == -1) {
+    int ret;
+
+    data.config_index = voe->config->index;
+    data.voe_index = voe->index;
+
+    ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ, &data);
+    if (EC_IOCTL_IS_ERROR(ret)) {
         fprintf(stderr, "Failed to initiate VoE reading: %s\n",
-                strerror(errno));
+                strerror(EC_IOCTL_ERRNO(ret)));
     }
 }
 
@@ -126,14 +128,15 @@
 void ecrt_voe_handler_read_nosync(ec_voe_handler_t *voe)
 {
     ec_ioctl_voe_t data;
-
-    data.config_index = voe->config->index;
-    data.voe_index = voe->index;
-
-    if (ioctl(voe->config->master->fd,
-                EC_IOCTL_VOE_READ_NOSYNC, &data) == -1) {
+    int ret;
+
+    data.config_index = voe->config->index;
+    data.voe_index = voe->index;
+
+    ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ_NOSYNC, &data);
+    if (EC_IOCTL_IS_ERROR(ret)) {
         fprintf(stderr, "Failed to initiate VoE reading: %s\n",
-                strerror(errno));
+                strerror(EC_IOCTL_ERRNO(ret)));
     }
 }
 
@@ -142,15 +145,17 @@
 void ecrt_voe_handler_write(ec_voe_handler_t *voe, size_t size)
 {
     ec_ioctl_voe_t data;
+    int ret;
 
     data.config_index = voe->config->index;
     data.voe_index = voe->index;
     data.size = size;
     data.data = voe->data;
 
-    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_WRITE, &data) == -1) {
+    ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_WRITE, &data);
+    if (EC_IOCTL_IS_ERROR(ret)) {
         fprintf(stderr, "Failed to initiate VoE writing: %s\n",
-                strerror(errno));
+                strerror(EC_IOCTL_ERRNO(ret)));
     }
 }
 
@@ -159,13 +164,15 @@
 ec_request_state_t ecrt_voe_handler_execute(ec_voe_handler_t *voe)
 {
     ec_ioctl_voe_t data;
-
-    data.config_index = voe->config->index;
-    data.voe_index = voe->index;
-
-    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_EXEC, &data) == -1) {
+    int ret;
+
+    data.config_index = voe->config->index;
+    data.voe_index = voe->index;
+
+    ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_EXEC, &data);
+    if (EC_IOCTL_IS_ERROR(ret)) {
         fprintf(stderr, "Failed to execute VoE handler: %s\n",
-                strerror(errno));
+                strerror(EC_IOCTL_ERRNO(ret)));
         return EC_REQUEST_ERROR;
     }
 
@@ -178,8 +185,10 @@
 
         data.data = voe->data;
 
-        if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_DATA, &data) == -1) {
-            fprintf(stderr, "Failed to get VoE data: %s\n", strerror(errno));
+        ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_DATA, &data);
+        if (EC_IOCTL_IS_ERROR(ret)) {
+            fprintf(stderr, "Failed to get VoE data: %s\n",
+                    strerror(EC_IOCTL_ERRNO(ret)));
             return EC_REQUEST_ERROR;
         }
         voe->data_size = data.size;