Added ecrt_master_slave().
authorFlorian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 14:39:49 +0000
changeset 1341 32ba7ffb6c7f
parent 1340 3d45edb1b4a1
child 1342 a72b9b370277
Added ecrt_master_slave().
NEWS
TODO
include/ecrt.h
lib/master.c
--- a/NEWS	Mon Jan 26 14:14:17 2009 +0000
+++ b/NEWS	Mon Jan 26 14:39:49 2009 +0000
@@ -22,6 +22,7 @@
 * Implemented the File Access over EtherCAT (FoE) mailbox protocol.
 * Going to the Bootstrap state is now supported by the state machines and the
   command-line tool.
+* Introduced ecrt_master_slave() to get information about a certain slave.
 
 Changes in 1.4.0:
 
--- a/TODO	Mon Jan 26 14:14:17 2009 +0000
+++ b/TODO	Mon Jan 26 14:39:49 2009 +0000
@@ -24,6 +24,7 @@
 * C++ implementation of the library.
 * Distributed clocks.
 * Bus simulator interface.
+* Implement ecrt_master_slave() in kernel space.
 
 Future issues:
 
--- a/include/ecrt.h	Mon Jan 26 14:14:17 2009 +0000
+++ b/include/ecrt.h	Mon Jan 26 14:39:49 2009 +0000
@@ -1,27 +1,27 @@
 /******************************************************************************
  *
- * $Id$
- *
- * Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
- *
- * This file is part of the IgH EtherCAT master userspace library.
- * 
- * The IgH EtherCAT master userspace library is free software; you can
- * redistribute it and/or modify it under the terms of the GNU Lesser General
- * Public License as published by the Free Software Foundation; version 2.1 of
- * the License.
- *
- * The IgH EtherCAT master userspace library is distributed in the hope that
- * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with the IgH EtherCAT master userspace library. If not, see
- * <http://www.gnu.org/licenses/>.
- * 
- * Using the EtherCAT technology and brand is permitted in compliance with the
- * industrial property and similar rights of Beckhoff Automation GmbH.
+ *  $Id$
+ *
+ *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT master userspace library.
+ *  
+ *  The IgH EtherCAT master userspace library is free software; you can
+ *  redistribute it and/or modify it under the terms of the GNU Lesser General
+ *  Public License as published by the Free Software Foundation; version 2.1
+ *  of the License.
+ *
+ *  The IgH EtherCAT master userspace library is distributed in the hope that
+ *  it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with the IgH EtherCAT master userspace library. If not, see
+ *  <http://www.gnu.org/licenses/>.
+ *  
+ *  Using the EtherCAT technology and brand is permitted in compliance with
+ *  the industrial property and similar rights of Beckhoff Automation GmbH.
  *
  *****************************************************************************/
 
@@ -40,6 +40,11 @@
  *
  * - Changed the meaning of the negative return values of
  *   ecrt_slave_config_reg_pdo_entry() and ecrt_slave_config_sdo*().
+ * - Imlemented the Vendor-specific over EtherCAT mailbox protocol. See
+ *   ecrt_slave_config_create_voe_handler().
+ * - Renamed ec_sdo_request_state_t to ec_request_state_t, because it is also
+ *   used by VoE handlers.
+ * - Added ecrt_master_slave() to get information about a certain slave.
  *
  * Changes in Version 1.4:
  *
@@ -134,6 +139,12 @@
  */
 #define EC_MAX_SYNC_MANAGERS 16
 
+/** Maximum string length.
+ *
+ * Used in ec_slave_info_t.
+ */
+#define EC_MAX_STRING_LENGTH 64
+
 /******************************************************************************
  * Data types 
  *****************************************************************************/
@@ -199,6 +210,29 @@
 
 /*****************************************************************************/
 
+/** Slave information.
+ *
+ * This is used as an output parameter of ecrt_master_slave().
+ *
+ * \see ecrt_master_slave().
+ */
+typedef struct {
+    uint16_t position; /**< Offset of the slave in the ring. */
+    uint32_t vendor_id; /**< Vendor-ID stored on the slave. */
+    uint32_t product_code; /**< Product-Code stored on the slave. */
+    uint32_t revision_number; /**< Revision-Number stored on the slave. */
+    uint32_t serial_number; /**< Serial-Number stored on the slave. */
+    uint16_t alias; /**< The slaves alias if not equal to 0. */
+    int16_t current_on_ebus;
+    uint8_t al_state; /**< Current state of the slave. */
+    uint8_t error_flag; /**< Error flag for that slave. */
+    uint8_t sync_count; /**< Number of sync managers. */
+    uint16_t sdo_count; /**< Number of SDO's. */
+    char name[EC_MAX_STRING_LENGTH]; /**< Name of the slave. */
+} ec_slave_info_t;
+
+/*****************************************************************************/
+
 /** Domain working counter interpretation.
  *
  * This is used in ec_domain_state_t.
@@ -433,6 +467,23 @@
         uint32_t product_code /**< Expected product code. */
         );
 
+/** Obtains slave information.
+ *
+ * Tries to find the slave with the given ring position. The obtained
+ * information is stored in a structure. No memory is allocated on the heap in
+ * this function.
+ *
+ * \attention The pointer to this structure must point to a valid variable.
+ *
+ * \return 0 in case of success, else < 0
+ */
+int ecrt_master_slave(
+        ec_master_t *master, /**< EtherCAT master */
+        uint16_t position, /**< Slave position. */
+        ec_slave_info_t *slave_info /**< Structure that will output the
+                                      information */
+        );
+
 /** Finishes the configuration phase and prepares for cyclic operation.
  *
  * This function tells the master that the configuration phase is finished and
--- a/lib/master.c	Mon Jan 26 14:14:17 2009 +0000
+++ b/lib/master.c	Mon Jan 26 14:39:49 2009 +0000
@@ -100,6 +100,38 @@
 
 /*****************************************************************************/
 
+int ecrt_master_slave(ec_master_t *master, uint16_t position,
+        ec_slave_info_t *slave_info)
+{
+    ec_ioctl_slave_t data;
+    int index;
+
+    data.position = position;
+
+    if (ioctl(master->fd, EC_IOCTL_SLAVE, &data) == -1) {
+        fprintf(stderr, "Failed to get slave info: %s\n",
+                strerror(errno));
+        return -1;
+    }
+
+    slave_info->position = data.position;
+    slave_info->vendor_id = data.vendor_id;
+    slave_info->product_code = data.product_code;
+    slave_info->revision_number = data.revision_number;
+    slave_info->serial_number = data.serial_number;
+    slave_info->alias = data.alias;
+    slave_info->current_on_ebus = data.current_on_ebus;
+    slave_info->al_state = data.al_state;
+    slave_info->error_flag = data.error_flag;
+    slave_info->sync_count = data.sync_count;
+    slave_info->sdo_count = data.sdo_count;
+    strncpy(slave_info->name, data.name, EC_IOCTL_STRING_SIZE);
+
+    return 0;
+}
+
+/*****************************************************************************/
+
 int ecrt_master_activate(ec_master_t *master)
 {
     if (ioctl(master->fd, EC_IOCTL_ACTIVATE,