Renamed phy_ commands to reg_.
authorFlorian Pose <fp@igh-essen.com>
Wed, 08 Apr 2009 12:48:59 +0000
changeset 1388 3c886ec376f5
parent 1387 57020c731092
child 1389 5b392b22a2da
Renamed phy_ commands to reg_.
TODO
master/cdev.c
master/fsm_master.c
master/fsm_master.h
master/ioctl.h
master/master.c
master/master.h
tool/CommandPhyRead.cpp
tool/CommandPhyRead.h
tool/CommandPhyWrite.cpp
tool/CommandPhyWrite.h
tool/CommandRegRead.cpp
tool/CommandRegRead.h
tool/CommandRegWrite.cpp
tool/CommandRegWrite.h
tool/Makefile.am
tool/MasterDevice.cpp
tool/MasterDevice.h
tool/main.cpp
--- a/TODO	Wed Apr 08 12:10:01 2009 +0000
+++ b/TODO	Wed Apr 08 12:48:59 2009 +0000
@@ -24,7 +24,6 @@
 * Test File access over EtherCAT (FoE) reading.
 * Distributed clocks.
 * Implement ecrt_master_slave() in kernel space.
-* Rename phy-commands to register commands.
 * Check for ioctl() interface version.
 * Improve application-triggered SDO transfers by moving the statemachine into
   the SDO handlers.
--- a/master/cdev.c	Wed Apr 08 12:10:01 2009 +0000
+++ b/master/cdev.c	Wed Apr 08 12:48:59 2009 +0000
@@ -1041,17 +1041,17 @@
 
 /*****************************************************************************/
 
-/** Read a slave's physical memory.
- */
-int ec_cdev_ioctl_slave_phy_read(
+/** Read a slave's registers.
+ */
+int ec_cdev_ioctl_slave_reg_read(
         ec_master_t *master, /**< EtherCAT master. */
         unsigned long arg /**< ioctl() argument. */
         )
 {
-    ec_ioctl_slave_phy_t data;
+    ec_ioctl_slave_reg_t data;
     ec_slave_t *slave;
     uint8_t *contents;
-    ec_phy_request_t request;
+    ec_reg_request_t request;
 
     if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
@@ -1061,7 +1061,7 @@
         return 0;
 
     if (!(contents = kmalloc(data.length, GFP_KERNEL))) {
-        EC_ERR("Failed to allocate %u bytes for phy data.\n", data.length);
+        EC_ERR("Failed to allocate %u bytes for register data.\n", data.length);
         return -ENOMEM;
     }
 
@@ -1075,7 +1075,7 @@
         return -EINVAL;
     }
 
-    // init phy request
+    // init register request
     INIT_LIST_HEAD(&request.list);
     request.slave = slave;
     request.dir = EC_DIR_INPUT;
@@ -1085,12 +1085,12 @@
     request.state = EC_INT_REQUEST_QUEUED;
 
     // schedule request.
-    list_add_tail(&request.list, &master->phy_requests);
+    list_add_tail(&request.list, &master->reg_requests);
 
     up(&master->master_sem);
 
     // wait for processing through FSM
-    if (wait_event_interruptible(master->phy_queue,
+    if (wait_event_interruptible(master->reg_queue,
                 request.state != EC_INT_REQUEST_QUEUED)) {
         // interrupted by signal
         down(&master->master_sem);
@@ -1105,7 +1105,7 @@
     }
 
     // wait until master FSM has finished processing
-    wait_event(master->phy_queue, request.state != EC_INT_REQUEST_BUSY);
+    wait_event(master->reg_queue, request.state != EC_INT_REQUEST_BUSY);
 
     if (request.state == EC_INT_REQUEST_SUCCESS) {
         if (copy_to_user((void __user *) data.data, contents, data.length))
@@ -1118,17 +1118,17 @@
 
 /*****************************************************************************/
 
-/** Write a slave's physical memory.
- */
-int ec_cdev_ioctl_slave_phy_write(
+/** Write a slave's registers.
+ */
+int ec_cdev_ioctl_slave_reg_write(
         ec_master_t *master, /**< EtherCAT master. */
         unsigned long arg /**< ioctl() argument. */
         )
 {
-    ec_ioctl_slave_phy_t data;
+    ec_ioctl_slave_reg_t data;
     ec_slave_t *slave;
     uint8_t *contents;
-    ec_phy_request_t request;
+    ec_reg_request_t request;
 
     if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
@@ -1138,7 +1138,7 @@
         return 0;
 
     if (!(contents = kmalloc(data.length, GFP_KERNEL))) {
-        EC_ERR("Failed to allocate %u bytes for phy data.\n", data.length);
+        EC_ERR("Failed to allocate %u bytes for register data.\n", data.length);
         return -ENOMEM;
     }
 
@@ -1158,7 +1158,7 @@
         return -EINVAL;
     }
 
-    // init phy request
+    // init register request
     INIT_LIST_HEAD(&request.list);
     request.slave = slave;
     request.dir = EC_DIR_OUTPUT;
@@ -1168,12 +1168,12 @@
     request.state = EC_INT_REQUEST_QUEUED;
 
     // schedule request.
-    list_add_tail(&request.list, &master->phy_requests);
+    list_add_tail(&request.list, &master->reg_requests);
 
     up(&master->master_sem);
 
     // wait for processing through FSM
-    if (wait_event_interruptible(master->phy_queue,
+    if (wait_event_interruptible(master->reg_queue,
                 request.state != EC_INT_REQUEST_QUEUED)) {
         // interrupted by signal
         down(&master->master_sem);
@@ -1188,7 +1188,7 @@
     }
 
     // wait until master FSM has finished processing
-    wait_event(master->phy_queue, request.state != EC_INT_REQUEST_BUSY);
+    wait_event(master->reg_queue, request.state != EC_INT_REQUEST_BUSY);
 
     kfree(contents);
 
@@ -2981,12 +2981,12 @@
             if (!(filp->f_mode & FMODE_WRITE))
                 return -EPERM;
             return ec_cdev_ioctl_slave_sii_write(master, arg);
-        case EC_IOCTL_SLAVE_PHY_READ:
-            return ec_cdev_ioctl_slave_phy_read(master, arg);
-        case EC_IOCTL_SLAVE_PHY_WRITE:
+        case EC_IOCTL_SLAVE_REG_READ:
+            return ec_cdev_ioctl_slave_reg_read(master, arg);
+        case EC_IOCTL_SLAVE_REG_WRITE:
             if (!(filp->f_mode & FMODE_WRITE))
                 return -EPERM;
-            return ec_cdev_ioctl_slave_phy_write(master, arg);
+            return ec_cdev_ioctl_slave_reg_write(master, arg);
         case EC_IOCTL_SLAVE_FOE_READ:
             return ec_cdev_ioctl_slave_foe_read(master, arg);
         case EC_IOCTL_SLAVE_FOE_WRITE:
--- a/master/fsm_master.c	Wed Apr 08 12:10:01 2009 +0000
+++ b/master/fsm_master.c	Wed Apr 08 12:48:59 2009 +0000
@@ -56,7 +56,7 @@
 void ec_fsm_master_state_write_sii(ec_fsm_master_t *);
 void ec_fsm_master_state_sdo_dictionary(ec_fsm_master_t *);
 void ec_fsm_master_state_sdo_request(ec_fsm_master_t *);
-void ec_fsm_master_state_phy_request(ec_fsm_master_t *);
+void ec_fsm_master_state_reg_request(ec_fsm_master_t *);
 void ec_fsm_master_state_foe_request(ec_fsm_master_t *);
 
 /*****************************************************************************/
@@ -327,29 +327,29 @@
 
 /*****************************************************************************/
 
-/** Check for pending phy requests and process one.
+/** Check for pending register requests and process one.
  * 
- * \return non-zero, if a phy request is processed.
- */
-int ec_fsm_master_action_process_phy(
-        ec_fsm_master_t *fsm /**< Master state machine. */
-        )
-{
-    ec_master_t *master = fsm->master;
-    ec_phy_request_t *request;
+ * \return non-zero, if a register request is processed.
+ */
+int ec_fsm_master_action_process_register(
+        ec_fsm_master_t *fsm /**< Master state machine. */
+        )
+{
+    ec_master_t *master = fsm->master;
+    ec_reg_request_t *request;
 
     // search the first request to be processed
-    while (!list_empty(&master->phy_requests)) {
+    while (!list_empty(&master->reg_requests)) {
 
         // get first request
-        request = list_entry(master->phy_requests.next,
-                ec_phy_request_t, list);
+        request = list_entry(master->reg_requests.next,
+                ec_reg_request_t, list);
         list_del_init(&request->list); // dequeue
         request->state = EC_INT_REQUEST_BUSY;
 
         // found pending request; process it!
         if (master->debug_level)
-            EC_DBG("Processing phy request for slave %u, "
+            EC_DBG("Processing register request for slave %u, "
                     "offset 0x%04x, length %u...\n",
                     request->slave->ring_position,
                     request->offset, request->length);
@@ -359,11 +359,11 @@
                     "datagram size (%u)!\n", request->length,
                     fsm->datagram->mem_size);
             request->state = EC_INT_REQUEST_FAILURE;
-            wake_up(&master->phy_queue);
+            wake_up(&master->reg_queue);
             continue;
         }
 
-        fsm->phy_request = request;
+        fsm->reg_request = request;
 
         if (request->dir == EC_DIR_INPUT) {
             ec_datagram_fprd(fsm->datagram, request->slave->station_address,
@@ -375,7 +375,7 @@
             memcpy(fsm->datagram->data, request->data, request->length);
         }
         fsm->retries = EC_FSM_RETRIES;
-        fsm->state = ec_fsm_master_state_phy_request;
+        fsm->state = ec_fsm_master_state_reg_request;
         return 1;
     }
 
@@ -568,9 +568,9 @@
     if (ec_fsm_master_action_process_sii(fsm))
         return; // SII write request found
 
-    // check for pending phy requests.
-    if (ec_fsm_master_action_process_phy(fsm))
-        return; // phy request processing
+    // check for pending register requests.
+    if (ec_fsm_master_action_process_register(fsm))
+        return; // register request processing
 
     ec_fsm_master_restart(fsm);
 }
@@ -1014,21 +1014,21 @@
 
 /*****************************************************************************/
 
-/** Master state: PHY.
- */
-void ec_fsm_master_state_phy_request(
+/** Master state: REG REQUEST.
+ */
+void ec_fsm_master_state_reg_request(
         ec_fsm_master_t *fsm /**< Master state machine. */
         )
 {
     ec_master_t *master = fsm->master;
     ec_datagram_t *datagram = fsm->datagram;
-    ec_phy_request_t *request = fsm->phy_request;
+    ec_reg_request_t *request = fsm->reg_request;
 
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
-        EC_ERR("Failed to receive phy request datagram (state %u).\n",
+        EC_ERR("Failed to receive register request datagram (state %u).\n",
                 datagram->state);
         request->state = EC_INT_REQUEST_FAILURE;
-        wake_up(&master->phy_queue);
+        wake_up(&master->reg_queue);
         ec_fsm_master_restart(fsm);
         return;
     }
@@ -1039,10 +1039,10 @@
                 kfree(request->data);
             request->data = kmalloc(request->length, GFP_KERNEL);
             if (!request->data) {
-                EC_ERR("Failed to allocate %u bytes of memory for phy request.\n",
-                        request->length);
+                EC_ERR("Failed to allocate %u bytes of memory for"
+                        " register data.\n", request->length);
                 request->state = EC_INT_REQUEST_FAILURE;
-                wake_up(&master->phy_queue);
+                wake_up(&master->reg_queue);
                 ec_fsm_master_restart(fsm);
                 return;
             }
@@ -1054,10 +1054,10 @@
         request->state = EC_INT_REQUEST_FAILURE;
     }
 
-    wake_up(&master->phy_queue);
-
-    // check for another PHY request
-    if (ec_fsm_master_action_process_phy(fsm))
+    wake_up(&master->reg_queue);
+
+    // check for another register request
+    if (ec_fsm_master_action_process_register(fsm))
         return; // processing another request
 
     ec_fsm_master_restart(fsm);
--- a/master/fsm_master.h	Wed Apr 08 12:10:01 2009 +0000
+++ b/master/fsm_master.h	Wed Apr 08 12:48:59 2009 +0000
@@ -61,17 +61,17 @@
 
 /*****************************************************************************/
 
-/** Physical memory request.
+/** Register request.
  */
 typedef struct {
     struct list_head list; /**< List head. */
     ec_slave_t *slave; /**< EtherCAT slave. */
     ec_direction_t dir; /**< Direction. */
-    uint16_t offset; /**< Physical memory offset. */
+    uint16_t offset; /**< Register address. */
     size_t length; /**< Number of bytes. */
     uint8_t *data; /**< Data to write / memory for read data. */
     ec_internal_request_state_t state; /**< State of the request. */
-} ec_phy_request_t;
+} ec_reg_request_t;
 
 /*****************************************************************************/
 
@@ -114,7 +114,7 @@
     ec_sii_write_request_t *sii_request; /**< SII write request */
     off_t sii_index; /**< index to SII write request data */
     ec_sdo_request_t *sdo_request; /**< SDO request to process. */
-    ec_phy_request_t *phy_request; /**< Physical memory request to process. */
+    ec_reg_request_t *reg_request; /**< Register request to process. */
     ec_foe_request_t *foe_request; /**< FoE request to process. */
     off_t foe_index; /**< index to FoE write request data */
 
--- a/master/ioctl.h	Wed Apr 08 12:10:01 2009 +0000
+++ b/master/ioctl.h	Wed Apr 08 12:48:59 2009 +0000
@@ -69,8 +69,8 @@
 #define EC_IOCTL_SLAVE_SDO_DOWNLOAD   EC_IOWR(0x0d, ec_ioctl_slave_sdo_download_t)
 #define EC_IOCTL_SLAVE_SII_READ       EC_IOWR(0x0e, ec_ioctl_slave_sii_t)
 #define EC_IOCTL_SLAVE_SII_WRITE       EC_IOW(0x0f, ec_ioctl_slave_sii_t)
-#define EC_IOCTL_SLAVE_PHY_READ       EC_IOWR(0x10, ec_ioctl_slave_phy_t)
-#define EC_IOCTL_SLAVE_PHY_WRITE       EC_IOW(0x11, ec_ioctl_slave_phy_t)
+#define EC_IOCTL_SLAVE_REG_READ       EC_IOWR(0x10, ec_ioctl_slave_reg_t)
+#define EC_IOCTL_SLAVE_REG_WRITE       EC_IOW(0x11, ec_ioctl_slave_reg_t)
 #define EC_IOCTL_SLAVE_FOE_READ       EC_IOWR(0x12, ec_ioctl_slave_foe_t)
 #define EC_IOCTL_SLAVE_FOE_WRITE       EC_IOW(0x13, ec_ioctl_slave_foe_t)
 #define EC_IOCTL_CONFIG               EC_IOWR(0x14, ec_ioctl_config_t)
@@ -340,7 +340,7 @@
     uint16_t offset;
     uint16_t length;
     uint8_t *data;
-} ec_ioctl_slave_phy_t;
+} ec_ioctl_slave_reg_t;
 
 /*****************************************************************************/
 
--- a/master/master.c	Wed Apr 08 12:10:01 2009 +0000
+++ b/master/master.c	Wed Apr 08 12:48:59 2009 +0000
@@ -170,8 +170,8 @@
     INIT_LIST_HEAD(&master->slave_sdo_requests);
     init_waitqueue_head(&master->sdo_queue);
 
-    INIT_LIST_HEAD(&master->phy_requests);
-    init_waitqueue_head(&master->phy_queue);
+    INIT_LIST_HEAD(&master->reg_requests);
+    init_waitqueue_head(&master->reg_queue);
 
     INIT_LIST_HEAD(&master->foe_requests);
     init_waitqueue_head(&master->foe_queue);
--- a/master/master.h	Wed Apr 08 12:10:01 2009 +0000
+++ b/master/master.h	Wed Apr 08 12:48:59 2009 +0000
@@ -166,8 +166,8 @@
     wait_queue_head_t sdo_queue; /**< Wait queue for SDO access requests
                                    from user space. */
 
-    struct list_head phy_requests; /**< Physical memory requests. */
-    wait_queue_head_t phy_queue; /**< Wait queue for phy requests. */
+    struct list_head reg_requests; /**< Register requests. */
+    wait_queue_head_t reg_queue; /**< Wait queue for register requests. */
 
     struct list_head foe_requests; /**< FoE write requests. */
     wait_queue_head_t foe_queue; /**< Wait queue for FoE
--- a/tool/CommandPhyRead.cpp	Wed Apr 08 12:10:01 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,241 +0,0 @@
-/*****************************************************************************
- *
- *  $Id$
- *
- *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
- *
- *  This file is part of the IgH EtherCAT Master.
- *
- *  The IgH EtherCAT Master is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License version 2, as
- *  published by the Free Software Foundation.
- *
- *  The IgH EtherCAT Master 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 General
- *  Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with the IgH EtherCAT Master; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- *  ---
- *
- *  The license mentioned above concerns the source code only. Using the
- *  EtherCAT technology and brand is only permitted in compliance with the
- *  industrial property and similar rights of Beckhoff Automation GmbH.
- *
- ****************************************************************************/
-
-#include <iostream>
-#include <iomanip>
-using namespace std;
-
-#include "CommandPhyRead.h"
-
-/*****************************************************************************/
-
-CommandPhyRead::CommandPhyRead():
-    Command("phy_read", "Output a slave's physical memory contents.")
-{
-}
-
-/*****************************************************************************/
-
-string CommandPhyRead::helpString() const
-{
-    stringstream str;
-
-    str << getName() << " [OPTIONS] <OFFSET> [LENGTH]" << endl
-    	<< endl
-    	<< getBriefDescription() << endl
-    	<< endl
-        << "This command requires a single slave to be selected." << endl
-    	<< endl
-        << "Arguments:" << endl
-        << "  OFFSET is the physical memory address. Must" << endl
-        << "         be an unsigned 16 bit number." << endl
-        << "  LENGTH is the number of bytes to read and must also be" << endl
-        << "         an unsigned 16 bit number. OFFSET plus LENGTH" << endl
-        << "         may not exceed 64k. The length is ignored (and" << endl
-        << "         can be omitted), if a selected data type" << endl
-        << "         implies a length." << endl
-        << endl
-        << "These are the valid data types:" << endl
-        << "  int8, int16, int32, int64, uint8, uint16, uint32," << endl
-        << "  uint64, string, octet_string, raw." << endl
-        << endl
-    	<< "Command-specific options:" << endl
-        << "  --alias    -a <alias>" << endl
-        << "  --position -p <pos>    Slave selection. See the help of" << endl
-        << "                         the 'slaves' command." << endl
-        << "  --type     -t <type>   Data type (see above)." << endl
-    	<< endl
-		<< numericInfo();
-
-	return str.str();
-}
-
-/****************************************************************************/
-
-void CommandPhyRead::execute(MasterDevice &m, const StringVector &args)
-{
-    SlaveList slaves;
-    ec_ioctl_slave_phy_t data;
-    stringstream strOffset, err;
-    const DataType *dataType = NULL;
-
-    if (args.size() < 1 || args.size() > 2) {
-        err << "'" << getName() << "' takes one or two arguments!";
-        throwInvalidUsageException(err);
-    }
-
-    strOffset << args[0];
-    strOffset
-        >> resetiosflags(ios::basefield) // guess base from prefix
-        >> data.offset;
-    if (strOffset.fail()) {
-        err << "Invalid offset '" << args[0] << "'!";
-        throwInvalidUsageException(err);
-    }
-
-    if (args.size() > 1) {
-        stringstream strLength;
-        strLength << args[1];
-        strLength
-            >> resetiosflags(ios::basefield) // guess base from prefix
-            >> data.length;
-        if (strLength.fail()) {
-            err << "Invalid length '" << args[1] << "'!";
-            throwInvalidUsageException(err);
-        }
-
-        if (!data.length) {
-            err << "Length may not be zero!";
-            throwInvalidUsageException(err);
-        }
-    } else { // no length argument given
-        data.length = 0;
-    }
-
-    if (!getDataType().empty()) {
-        if (!(dataType = findDataType(getDataType()))) {
-            err << "Invalid data type '" << getDataType() << "'!";
-            throwInvalidUsageException(err);
-        }
-
-        if (dataType->byteSize) {
-            // override length argument
-            data.length = dataType->byteSize;
-        }
-    }
-
-    if (!data.length) {
-        err << "The length argument is mandatory, if no datatype is " << endl
-            << "specified, or the datatype does not imply a length!";
-        throwInvalidUsageException(err);
-    }
-
-    if ((uint32_t) data.offset + data.length > 0xffff) {
-        err << "Offset and length exceeding 64k!";
-        throwInvalidUsageException(err);
-    }
-    
-    m.open(MasterDevice::Read);
-    slaves = selectedSlaves(m);
-
-    if (slaves.size() != 1) {
-        throwSingleSlaveRequired(slaves.size());
-    }
-    data.slave_position = slaves.front().position;
-
-    data.data = new uint8_t[data.length];
-
-	try {
-		m.readPhy(&data);
-	} catch (MasterDeviceException &e) {
-        delete [] data.data;
-		throw e;
-	}
-
-    cout << setfill('0');
-    if (!dataType ||
-            dataType->name == "string" ||
-            dataType->name == "octet_string") {
-        uint16_t i;
-        for (i = 0; i < data.length; i++) {
-            cout << data.data[i];
-        }
-    } else if (dataType->name == "int8") {
-        int sval = *(int8_t *) data.data;
-        cout << sval << " 0x" << hex << setw(2) << sval << endl;
-    } else if (dataType->name == "int16") {
-        int sval = le16_to_cpup(data.data);
-        cout << sval << " 0x" << hex << setw(4) << sval << endl;
-    } else if (dataType->name == "int32") {
-        int sval = le32_to_cpup(data.data);
-        cout << sval << " 0x" << hex << setw(8) << sval << endl;
-    } else if (dataType->name == "int64") {
-        long long int sval = le64_to_cpup(data.data);
-        cout << sval << " 0x" << hex << setw(16) << sval << endl;
-    } else if (dataType->name == "uint8") {
-        unsigned int uval = (unsigned int) *(uint8_t *) data.data;
-        cout << uval << " 0x" << hex << setw(2) << uval << endl;
-    } else if (dataType->name == "uint16") {
-        unsigned int uval = le16_to_cpup(data.data);
-        cout << uval << " 0x" << hex << setw(4) << uval << endl;
-    } else if (dataType->name == "uint32") {
-        unsigned int uval = le32_to_cpup(data.data);
-        cout << uval << " 0x" << hex << setw(8) << uval << endl;
-    } else if (dataType->name == "uint64") {
-        long long unsigned int uval = le32_to_cpup(data.data);
-        cout << uval << " 0x" << hex << setw(8) << uval << endl;
-    } else {
-        uint8_t *d = data.data;
-        unsigned int size = data.length;
-
-        cout << hex << setfill('0');
-        while (size--) {
-            cout << "0x" << setw(2) << (unsigned int) *d++;
-            if (size)
-                cout << " ";
-        }
-        cout << endl;
-    }
-
-    delete [] data.data;
-}
-
-/****************************************************************************/
-
-const CommandPhyRead::DataType *CommandPhyRead::findDataType(
-        const string &str
-        )
-{
-    const DataType *d;
-    
-    for (d = dataTypes; d->name; d++)
-        if (str == d->name)
-            return d;
-
-    return NULL;
-}
-
-/****************************************************************************/
-
-const CommandPhyRead::DataType CommandPhyRead::dataTypes[] = {
-    {"int8",         1},
-    {"int16",        2},
-    {"int32",        4},
-    {"int64",        8},
-    {"uint8",        1},
-    {"uint16",       2},
-    {"uint32",       4},
-    {"uint64",       8},
-    {"string",       0},
-    {"octet_string", 0},
-    {"raw",          0},
-    {}
-};
-
-/*****************************************************************************/
--- a/tool/CommandPhyRead.h	Wed Apr 08 12:10:01 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/*****************************************************************************
- *
- *  $Id$
- *
- *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
- *
- *  This file is part of the IgH EtherCAT Master.
- *
- *  The IgH EtherCAT Master is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License version 2, as
- *  published by the Free Software Foundation.
- *
- *  The IgH EtherCAT Master 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 General
- *  Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with the IgH EtherCAT Master; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- *  ---
- *
- *  The license mentioned above concerns the source code only. Using the
- *  EtherCAT technology and brand is only permitted in compliance with the
- *  industrial property and similar rights of Beckhoff Automation GmbH.
- *
- ****************************************************************************/
-
-#ifndef __COMMANDPHYREAD_H__
-#define __COMMANDPHYREAD_H__
-
-#include "Command.h"
-
-/****************************************************************************/
-
-class CommandPhyRead:
-    public Command
-{
-    public:
-        CommandPhyRead();
-
-        string helpString() const;
-        void execute(MasterDevice &, const StringVector &);
-
-    private:
-        struct DataType {
-            const char *name;
-            unsigned int byteSize;
-        };
-        static const DataType dataTypes[];
-        static const DataType *findDataType(const string &);
-};
-
-/****************************************************************************/
-
-#endif
--- a/tool/CommandPhyWrite.cpp	Wed Apr 08 12:10:01 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,170 +0,0 @@
-/*****************************************************************************
- *
- *  $Id$
- *
- *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
- *
- *  This file is part of the IgH EtherCAT Master.
- *
- *  The IgH EtherCAT Master is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License version 2, as
- *  published by the Free Software Foundation.
- *
- *  The IgH EtherCAT Master 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 General
- *  Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with the IgH EtherCAT Master; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- *  ---
- *
- *  The license mentioned above concerns the source code only. Using the
- *  EtherCAT technology and brand is only permitted in compliance with the
- *  industrial property and similar rights of Beckhoff Automation GmbH.
- *
- ****************************************************************************/
-
-#include <iostream>
-#include <iomanip>
-#include <fstream>
-using namespace std;
-
-#include "CommandPhyWrite.h"
-#include "sii_crc.h"
-
-/*****************************************************************************/
-
-CommandPhyWrite::CommandPhyWrite():
-    Command("phy_write", "Write data to a slave's physical memory.")
-{
-}
-
-/*****************************************************************************/
-
-string CommandPhyWrite::helpString() const
-{
-    stringstream str;
-
-    str << getName() << " [OPTIONS] <OFFSET> <FILENAME>" << endl
-        << endl 
-        << getBriefDescription() << endl
-        << endl
-        << "This command requires a single slave to be selected." << endl
-    	<< endl
-        << "Arguments:" << endl
-        << "  OFFSET   must be the physical memory offset to start." << endl
-        << "  FILENAME must be a path to a file with data to write." << endl
-        << "           If it is '-', data are read from stdin." << endl
-        << endl
-        << "Command-specific options:" << endl
-        << "  --alias    -a <alias>" << endl
-        << "  --position -p <pos>    Slave selection. See the help of" << endl
-        << "                         the 'slaves' command." << endl
-        << endl
-        << numericInfo();
-
-    return str.str();
-}
-
-/****************************************************************************/
-
-void CommandPhyWrite::execute(MasterDevice &m, const StringVector &args)
-{
-    stringstream strOffset, err;
-    ec_ioctl_slave_phy_t data;
-    ifstream file;
-    SlaveList slaves;
-
-    if (args.size() != 2) {
-        err << "'" << getName() << "' takes exactly two arguments!";
-        throwInvalidUsageException(err);
-    }
-    
-    strOffset << args[0];
-    strOffset
-        >> resetiosflags(ios::basefield) // guess base from prefix
-        >> data.offset;
-    if (strOffset.fail()) {
-        err << "Invalid offset '" << args[0] << "'!";
-        throwInvalidUsageException(err);
-    }
-
-    if (args[1] == "-") {
-        loadPhyData(&data, cin);
-    } else {
-        file.open(args[1].c_str(), ifstream::in | ifstream::binary);
-        if (file.fail()) {
-            err << "Failed to open '" << args[0] << "'!";
-            throwCommandException(err);
-        }
-        loadPhyData(&data, file);
-        file.close();
-    }
-
-    if ((uint32_t) data.offset + data.length > 0xffff) {
-        err << "Offset and length exceeding 64k!";
-        delete [] data.data;
-        throwInvalidUsageException(err);
-    }
-
-    try {
-        m.open(MasterDevice::ReadWrite);
-    } catch (MasterDeviceException &e) {
-        delete [] data.data;
-        throw e;
-    }
-
-    slaves = selectedSlaves(m);
-    if (slaves.size() != 1) {
-        delete [] data.data;
-        throwSingleSlaveRequired(slaves.size());
-    }
-    data.slave_position = slaves.front().position;
-
-    // send data to master
-    try {
-        m.writePhy(&data);
-    } catch (MasterDeviceException &e) {
-        delete [] data.data;
-        throw e;
-    }
-
-    if (getVerbosity() == Verbose) {
-        cerr << "Physical memory writing finished." << endl;
-    }
-
-    delete [] data.data;
-}
-
-/*****************************************************************************/
-
-void CommandPhyWrite::loadPhyData(
-        ec_ioctl_slave_phy_t *data,
-        const istream &in
-        )
-{
-    stringstream err;
-    ostringstream tmp;
-
-    tmp << in.rdbuf();
-    string const &contents = tmp.str();
-
-    if (getVerbosity() == Verbose) {
-        cerr << "Read " << contents.size() << " bytes of data." << endl;
-    }
-
-    if (contents.size() > 0xffff) {
-        err << "Invalid data size " << contents.size() << "!";
-        throwInvalidUsageException(err);
-    }
-    data->length = contents.size();
-
-    // allocate buffer and read file into buffer
-    data->data = new uint8_t[data->length];
-    contents.copy((char *) data->data, contents.size());
-}
-
-/*****************************************************************************/
--- a/tool/CommandPhyWrite.h	Wed Apr 08 12:10:01 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*****************************************************************************
- *
- *  $Id$
- *
- *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
- *
- *  This file is part of the IgH EtherCAT Master.
- *
- *  The IgH EtherCAT Master is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License version 2, as
- *  published by the Free Software Foundation.
- *
- *  The IgH EtherCAT Master 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 General
- *  Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with the IgH EtherCAT Master; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- *  ---
- *
- *  The license mentioned above concerns the source code only. Using the
- *  EtherCAT technology and brand is only permitted in compliance with the
- *  industrial property and similar rights of Beckhoff Automation GmbH.
- *
- ****************************************************************************/
-
-#ifndef __COMMANDPHYWRITE_H__
-#define __COMMANDPHYWRITE_H__
-
-#include "Command.h"
-
-/****************************************************************************/
-
-class CommandPhyWrite:
-    public Command
-{
-    public:
-        CommandPhyWrite();
-
-        string helpString() const;
-        void execute(MasterDevice &, const StringVector &);
-
-    private:
-        void loadPhyData(ec_ioctl_slave_phy_t *, const istream &);
-};
-
-/****************************************************************************/
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandRegRead.cpp	Wed Apr 08 12:48:59 2009 +0000
@@ -0,0 +1,241 @@
+/*****************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License version 2, as
+ *  published by the Free Software Foundation.
+ *
+ *  The IgH EtherCAT Master 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 General
+ *  Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  ---
+ *
+ *  The license mentioned above concerns the source code only. Using the
+ *  EtherCAT technology and brand is only permitted in compliance with the
+ *  industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ ****************************************************************************/
+
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+#include "CommandRegRead.h"
+
+/*****************************************************************************/
+
+CommandRegRead::CommandRegRead():
+    Command("reg_read", "Output a slave's register contents.")
+{
+}
+
+/*****************************************************************************/
+
+string CommandRegRead::helpString() const
+{
+    stringstream str;
+
+    str << getName() << " [OPTIONS] <OFFSET> [LENGTH]" << endl
+    	<< endl
+    	<< getBriefDescription() << endl
+    	<< endl
+        << "This command requires a single slave to be selected." << endl
+    	<< endl
+        << "Arguments:" << endl
+        << "  OFFSET is the register address. Must" << endl
+        << "         be an unsigned 16 bit number." << endl
+        << "  LENGTH is the number of bytes to read and must also be" << endl
+        << "         an unsigned 16 bit number. OFFSET plus LENGTH" << endl
+        << "         may not exceed 64k. The length is ignored (and" << endl
+        << "         can be omitted), if a selected data type" << endl
+        << "         implies a length." << endl
+        << endl
+        << "These are the valid data types:" << endl
+        << "  int8, int16, int32, int64, uint8, uint16, uint32," << endl
+        << "  uint64, string, octet_string, raw." << endl
+        << endl
+    	<< "Command-specific options:" << endl
+        << "  --alias    -a <alias>" << endl
+        << "  --position -p <pos>    Slave selection. See the help of" << endl
+        << "                         the 'slaves' command." << endl
+        << "  --type     -t <type>   Data type (see above)." << endl
+    	<< endl
+		<< numericInfo();
+
+	return str.str();
+}
+
+/****************************************************************************/
+
+void CommandRegRead::execute(MasterDevice &m, const StringVector &args)
+{
+    SlaveList slaves;
+    ec_ioctl_slave_reg_t data;
+    stringstream strOffset, err;
+    const DataType *dataType = NULL;
+
+    if (args.size() < 1 || args.size() > 2) {
+        err << "'" << getName() << "' takes one or two arguments!";
+        throwInvalidUsageException(err);
+    }
+
+    strOffset << args[0];
+    strOffset
+        >> resetiosflags(ios::basefield) // guess base from prefix
+        >> data.offset;
+    if (strOffset.fail()) {
+        err << "Invalid offset '" << args[0] << "'!";
+        throwInvalidUsageException(err);
+    }
+
+    if (args.size() > 1) {
+        stringstream strLength;
+        strLength << args[1];
+        strLength
+            >> resetiosflags(ios::basefield) // guess base from prefix
+            >> data.length;
+        if (strLength.fail()) {
+            err << "Invalid length '" << args[1] << "'!";
+            throwInvalidUsageException(err);
+        }
+
+        if (!data.length) {
+            err << "Length may not be zero!";
+            throwInvalidUsageException(err);
+        }
+    } else { // no length argument given
+        data.length = 0;
+    }
+
+    if (!getDataType().empty()) {
+        if (!(dataType = findDataType(getDataType()))) {
+            err << "Invalid data type '" << getDataType() << "'!";
+            throwInvalidUsageException(err);
+        }
+
+        if (dataType->byteSize) {
+            // override length argument
+            data.length = dataType->byteSize;
+        }
+    }
+
+    if (!data.length) {
+        err << "The length argument is mandatory, if no datatype is " << endl
+            << "specified, or the datatype does not imply a length!";
+        throwInvalidUsageException(err);
+    }
+
+    if ((uint32_t) data.offset + data.length > 0xffff) {
+        err << "Offset and length exceeding 64k!";
+        throwInvalidUsageException(err);
+    }
+    
+    m.open(MasterDevice::Read);
+    slaves = selectedSlaves(m);
+
+    if (slaves.size() != 1) {
+        throwSingleSlaveRequired(slaves.size());
+    }
+    data.slave_position = slaves.front().position;
+
+    data.data = new uint8_t[data.length];
+
+	try {
+		m.readReg(&data);
+	} catch (MasterDeviceException &e) {
+        delete [] data.data;
+		throw e;
+	}
+
+    cout << setfill('0');
+    if (!dataType ||
+            dataType->name == "string" ||
+            dataType->name == "octet_string") {
+        uint16_t i;
+        for (i = 0; i < data.length; i++) {
+            cout << data.data[i];
+        }
+    } else if (dataType->name == "int8") {
+        int sval = *(int8_t *) data.data;
+        cout << sval << " 0x" << hex << setw(2) << sval << endl;
+    } else if (dataType->name == "int16") {
+        int sval = le16_to_cpup(data.data);
+        cout << sval << " 0x" << hex << setw(4) << sval << endl;
+    } else if (dataType->name == "int32") {
+        int sval = le32_to_cpup(data.data);
+        cout << sval << " 0x" << hex << setw(8) << sval << endl;
+    } else if (dataType->name == "int64") {
+        long long int sval = le64_to_cpup(data.data);
+        cout << sval << " 0x" << hex << setw(16) << sval << endl;
+    } else if (dataType->name == "uint8") {
+        unsigned int uval = (unsigned int) *(uint8_t *) data.data;
+        cout << uval << " 0x" << hex << setw(2) << uval << endl;
+    } else if (dataType->name == "uint16") {
+        unsigned int uval = le16_to_cpup(data.data);
+        cout << uval << " 0x" << hex << setw(4) << uval << endl;
+    } else if (dataType->name == "uint32") {
+        unsigned int uval = le32_to_cpup(data.data);
+        cout << uval << " 0x" << hex << setw(8) << uval << endl;
+    } else if (dataType->name == "uint64") {
+        long long unsigned int uval = le32_to_cpup(data.data);
+        cout << uval << " 0x" << hex << setw(8) << uval << endl;
+    } else {
+        uint8_t *d = data.data;
+        unsigned int size = data.length;
+
+        cout << hex << setfill('0');
+        while (size--) {
+            cout << "0x" << setw(2) << (unsigned int) *d++;
+            if (size)
+                cout << " ";
+        }
+        cout << endl;
+    }
+
+    delete [] data.data;
+}
+
+/****************************************************************************/
+
+const CommandRegRead::DataType *CommandRegRead::findDataType(
+        const string &str
+        )
+{
+    const DataType *d;
+    
+    for (d = dataTypes; d->name; d++)
+        if (str == d->name)
+            return d;
+
+    return NULL;
+}
+
+/****************************************************************************/
+
+const CommandRegRead::DataType CommandRegRead::dataTypes[] = {
+    {"int8",         1},
+    {"int16",        2},
+    {"int32",        4},
+    {"int64",        8},
+    {"uint8",        1},
+    {"uint16",       2},
+    {"uint32",       4},
+    {"uint64",       8},
+    {"string",       0},
+    {"octet_string", 0},
+    {"raw",          0},
+    {}
+};
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandRegRead.h	Wed Apr 08 12:48:59 2009 +0000
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License version 2, as
+ *  published by the Free Software Foundation.
+ *
+ *  The IgH EtherCAT Master 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 General
+ *  Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  ---
+ *
+ *  The license mentioned above concerns the source code only. Using the
+ *  EtherCAT technology and brand is only permitted in compliance with the
+ *  industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ ****************************************************************************/
+
+#ifndef __COMMANDREGREAD_H__
+#define __COMMANDREGREAD_H__
+
+#include "Command.h"
+
+/****************************************************************************/
+
+class CommandRegRead:
+    public Command
+{
+    public:
+        CommandRegRead();
+
+        string helpString() const;
+        void execute(MasterDevice &, const StringVector &);
+
+    private:
+        struct DataType {
+            const char *name;
+            unsigned int byteSize;
+        };
+        static const DataType dataTypes[];
+        static const DataType *findDataType(const string &);
+};
+
+/****************************************************************************/
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandRegWrite.cpp	Wed Apr 08 12:48:59 2009 +0000
@@ -0,0 +1,170 @@
+/*****************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License version 2, as
+ *  published by the Free Software Foundation.
+ *
+ *  The IgH EtherCAT Master 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 General
+ *  Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  ---
+ *
+ *  The license mentioned above concerns the source code only. Using the
+ *  EtherCAT technology and brand is only permitted in compliance with the
+ *  industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ ****************************************************************************/
+
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+using namespace std;
+
+#include "CommandRegWrite.h"
+#include "sii_crc.h"
+
+/*****************************************************************************/
+
+CommandRegWrite::CommandRegWrite():
+    Command("reg_write", "Write data to a slave's registers.")
+{
+}
+
+/*****************************************************************************/
+
+string CommandRegWrite::helpString() const
+{
+    stringstream str;
+
+    str << getName() << " [OPTIONS] <OFFSET> <FILENAME>" << endl
+        << endl 
+        << getBriefDescription() << endl
+        << endl
+        << "This command requires a single slave to be selected." << endl
+    	<< endl
+        << "Arguments:" << endl
+        << "  OFFSET   must be the register address." << endl
+        << "  FILENAME must be a path to a file with data to write." << endl
+        << "           If it is '-', data are read from stdin." << endl
+        << endl
+        << "Command-specific options:" << endl
+        << "  --alias    -a <alias>" << endl
+        << "  --position -p <pos>    Slave selection. See the help of" << endl
+        << "                         the 'slaves' command." << endl
+        << endl
+        << numericInfo();
+
+    return str.str();
+}
+
+/****************************************************************************/
+
+void CommandRegWrite::execute(MasterDevice &m, const StringVector &args)
+{
+    stringstream strOffset, err;
+    ec_ioctl_slave_reg_t data;
+    ifstream file;
+    SlaveList slaves;
+
+    if (args.size() != 2) {
+        err << "'" << getName() << "' takes exactly two arguments!";
+        throwInvalidUsageException(err);
+    }
+    
+    strOffset << args[0];
+    strOffset
+        >> resetiosflags(ios::basefield) // guess base from prefix
+        >> data.offset;
+    if (strOffset.fail()) {
+        err << "Invalid offset '" << args[0] << "'!";
+        throwInvalidUsageException(err);
+    }
+
+    if (args[1] == "-") {
+        loadRegData(&data, cin);
+    } else {
+        file.open(args[1].c_str(), ifstream::in | ifstream::binary);
+        if (file.fail()) {
+            err << "Failed to open '" << args[0] << "'!";
+            throwCommandException(err);
+        }
+        loadRegData(&data, file);
+        file.close();
+    }
+
+    if ((uint32_t) data.offset + data.length > 0xffff) {
+        err << "Offset and length exceeding 64k!";
+        delete [] data.data;
+        throwInvalidUsageException(err);
+    }
+
+    try {
+        m.open(MasterDevice::ReadWrite);
+    } catch (MasterDeviceException &e) {
+        delete [] data.data;
+        throw e;
+    }
+
+    slaves = selectedSlaves(m);
+    if (slaves.size() != 1) {
+        delete [] data.data;
+        throwSingleSlaveRequired(slaves.size());
+    }
+    data.slave_position = slaves.front().position;
+
+    // send data to master
+    try {
+        m.writeReg(&data);
+    } catch (MasterDeviceException &e) {
+        delete [] data.data;
+        throw e;
+    }
+
+    if (getVerbosity() == Verbose) {
+        cerr << "Register writing finished." << endl;
+    }
+
+    delete [] data.data;
+}
+
+/*****************************************************************************/
+
+void CommandRegWrite::loadRegData(
+        ec_ioctl_slave_reg_t *data,
+        const istream &in
+        )
+{
+    stringstream err;
+    ostringstream tmp;
+
+    tmp << in.rdbuf();
+    string const &contents = tmp.str();
+
+    if (getVerbosity() == Verbose) {
+        cerr << "Read " << contents.size() << " bytes of data." << endl;
+    }
+
+    if (contents.size() > 0xffff) {
+        err << "Invalid data size " << contents.size() << "!";
+        throwInvalidUsageException(err);
+    }
+    data->length = contents.size();
+
+    // allocate buffer and read file into buffer
+    data->data = new uint8_t[data->length];
+    contents.copy((char *) data->data, contents.size());
+}
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool/CommandRegWrite.h	Wed Apr 08 12:48:59 2009 +0000
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License version 2, as
+ *  published by the Free Software Foundation.
+ *
+ *  The IgH EtherCAT Master 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 General
+ *  Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  ---
+ *
+ *  The license mentioned above concerns the source code only. Using the
+ *  EtherCAT technology and brand is only permitted in compliance with the
+ *  industrial property and similar rights of Beckhoff Automation GmbH.
+ *
+ ****************************************************************************/
+
+#ifndef __COMMANDREGWRITE_H__
+#define __COMMANDREGWRITE_H__
+
+#include "Command.h"
+
+/****************************************************************************/
+
+class CommandRegWrite:
+    public Command
+{
+    public:
+        CommandRegWrite();
+
+        string helpString() const;
+        void execute(MasterDevice &, const StringVector &);
+
+    private:
+        void loadRegData(ec_ioctl_slave_reg_t *, const istream &);
+};
+
+/****************************************************************************/
+
+#endif
--- a/tool/Makefile.am	Wed Apr 08 12:10:01 2009 +0000
+++ b/tool/Makefile.am	Wed Apr 08 12:48:59 2009 +0000
@@ -45,8 +45,8 @@
 	CommandFoeWrite.cpp \
 	CommandMaster.cpp \
 	CommandPdos.cpp \
-	CommandPhyRead.cpp \
-	CommandPhyWrite.cpp \
+	CommandRegRead.cpp \
+	CommandRegWrite.cpp \
 	CommandSdos.cpp \
 	CommandSiiRead.cpp \
 	CommandSiiWrite.cpp \
@@ -73,8 +73,8 @@
 	CommandFoeWrite.h \
 	CommandMaster.h \
 	CommandPdos.h \
-	CommandPhyRead.h \
-	CommandPhyWrite.h \
+	CommandRegRead.h \
+	CommandRegWrite.h \
 	CommandSdos.h \
 	CommandSiiRead.h \
 	CommandSiiWrite.h \
--- a/tool/MasterDevice.cpp	Wed Apr 08 12:10:01 2009 +0000
+++ b/tool/MasterDevice.cpp	Wed Apr 08 12:48:59 2009 +0000
@@ -369,26 +369,26 @@
 
 /****************************************************************************/
 
-void MasterDevice::readPhy(
-        ec_ioctl_slave_phy_t *data
-        )
-{
-    if (ioctl(fd, EC_IOCTL_SLAVE_PHY_READ, data) < 0) {
-        stringstream err;
-        err << "Failed to read physical memory: " << strerror(errno);
-        throw MasterDeviceException(err);
-    }
-}
-
-/****************************************************************************/
-
-void MasterDevice::writePhy(
-        ec_ioctl_slave_phy_t *data
-        )
-{
-    if (ioctl(fd, EC_IOCTL_SLAVE_PHY_WRITE, data) < 0) {
-        stringstream err;
-        err << "Failed to write physical memory: " << strerror(errno);
+void MasterDevice::readReg(
+        ec_ioctl_slave_reg_t *data
+        )
+{
+    if (ioctl(fd, EC_IOCTL_SLAVE_REG_READ, data) < 0) {
+        stringstream err;
+        err << "Failed to read register: " << strerror(errno);
+        throw MasterDeviceException(err);
+    }
+}
+
+/****************************************************************************/
+
+void MasterDevice::writeReg(
+        ec_ioctl_slave_reg_t *data
+        )
+{
+    if (ioctl(fd, EC_IOCTL_SLAVE_REG_WRITE, data) < 0) {
+        stringstream err;
+        err << "Failed to write register: " << strerror(errno);
         throw MasterDeviceException(err);
     }
 }
--- a/tool/MasterDevice.h	Wed Apr 08 12:10:01 2009 +0000
+++ b/tool/MasterDevice.h	Wed Apr 08 12:48:59 2009 +0000
@@ -109,8 +109,8 @@
         void getSdoEntry(ec_ioctl_slave_sdo_entry_t *, uint16_t, int, uint8_t);
         void readSii(ec_ioctl_slave_sii_t *);
         void writeSii(ec_ioctl_slave_sii_t *);
-        void readPhy(ec_ioctl_slave_phy_t *);
-        void writePhy(ec_ioctl_slave_phy_t *);
+        void readReg(ec_ioctl_slave_reg_t *);
+        void writeReg(ec_ioctl_slave_reg_t *);
 		void setDebug(unsigned int);
 		void sdoDownload(ec_ioctl_slave_sdo_download_t *);
 		void sdoUpload(ec_ioctl_slave_sdo_upload_t *);
--- a/tool/main.cpp	Wed Apr 08 12:10:01 2009 +0000
+++ b/tool/main.cpp	Wed Apr 08 12:48:59 2009 +0000
@@ -45,8 +45,8 @@
 #include "CommandFoeWrite.h"
 #include "CommandMaster.h"
 #include "CommandPdos.h"
-#include "CommandPhyRead.h"
-#include "CommandPhyWrite.h"
+#include "CommandRegRead.h"
+#include "CommandRegWrite.h"
 #include "CommandSdos.h"
 #include "CommandSiiRead.h"
 #include "CommandSiiWrite.h"
@@ -299,8 +299,8 @@
     commandList.push_back(new CommandFoeWrite());
     commandList.push_back(new CommandMaster());
     commandList.push_back(new CommandPdos());
-    commandList.push_back(new CommandPhyRead());
-    commandList.push_back(new CommandPhyWrite());
+    commandList.push_back(new CommandRegRead());
+    commandList.push_back(new CommandRegWrite());
     commandList.push_back(new CommandSdos());
     commandList.push_back(new CommandSiiRead());
     commandList.push_back(new CommandSiiWrite());