tool/CommandRegRead.cpp
author Matthias Luescher <ch1010472@ch10lt140>
Thu, 17 Dec 2009 17:21:03 +0100
changeset 1603 8e528f806dc5
parent 1431 70e891465da1
child 1804 742607c464c4
permissions -rw-r--r--
fix build for recent kernel versions (tested with 2.6.31)
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
     3
 *  $Id$
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
     4
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
     6
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
     8
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    11
 *  published by the Free Software Foundation.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    12
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    16
 *  Public License for more details.
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    17
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    21
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <iostream>
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <iomanip>
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
using namespace std;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1387
diff changeset
    34
#include "CommandRegRead.h"
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1387
diff changeset
    38
CommandRegRead::CommandRegRead():
1389
5b392b22a2da reg_write with data types.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    39
    CommandReg("reg_read", "Output a slave's register contents.")
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1387
diff changeset
    45
string CommandRegRead::helpString() const
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    stringstream str;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    49
    str << getName() << " [OPTIONS] <OFFSET> [LENGTH]" << endl
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    	<< endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
    	<< getBriefDescription() << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
    	<< endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << "This command requires a single slave to be selected." << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
    	<< endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << "Arguments:" << endl
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1387
diff changeset
    56
        << "  OFFSET is the register address. Must" << endl
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        << "         be an unsigned 16 bit number." << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        << "  LENGTH is the number of bytes to read and must also be" << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << "         an unsigned 16 bit number. OFFSET plus LENGTH" << endl
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    60
        << "         may not exceed 64k. The length is ignored (and" << endl
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    61
        << "         can be omitted), if a selected data type" << endl
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    62
        << "         implies a length." << endl
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    63
        << endl
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    64
        << "These are the valid data types:" << endl
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    65
        << "  int8, int16, int32, int64, uint8, uint16, uint32," << endl
1389
5b392b22a2da reg_write with data types.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    66
        << "  uint64, string, raw." << endl
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
        << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    	<< "Command-specific options:" << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
        << "  --alias    -a <alias>" << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
        << "  --position -p <pos>    Slave selection. See the help of" << endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
        << "                         the 'slaves' command." << endl
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    72
        << "  --type     -t <type>   Data type (see above)." << endl
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    	<< endl
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
		<< numericInfo();
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
	return str.str();
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
/****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1387
diff changeset
    81
void CommandRegRead::execute(MasterDevice &m, const StringVector &args)
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    SlaveList slaves;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1387
diff changeset
    84
    ec_ioctl_slave_reg_t data;
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    85
    stringstream strOffset, err;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    86
    const DataType *dataType = NULL;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    87
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    88
    if (args.size() < 1 || args.size() > 2) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    89
        err << "'" << getName() << "' takes one or two arguments!";
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        throwInvalidUsageException(err);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    strOffset << args[0];
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    strOffset
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
        >> resetiosflags(ios::basefield) // guess base from prefix
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
        >> data.offset;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    if (strOffset.fail()) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        err << "Invalid offset '" << args[0] << "'!";
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        throwInvalidUsageException(err);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   102
    if (args.size() > 1) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   103
        stringstream strLength;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   104
        strLength << args[1];
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   105
        strLength
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   106
            >> resetiosflags(ios::basefield) // guess base from prefix
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   107
            >> data.length;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   108
        if (strLength.fail()) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   109
            err << "Invalid length '" << args[1] << "'!";
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   110
            throwInvalidUsageException(err);
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   111
        }
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   112
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   113
        if (!data.length) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   114
            err << "Length may not be zero!";
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   115
            throwInvalidUsageException(err);
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   116
        }
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   117
    } else { // no length argument given
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   118
        data.length = 0;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   119
    }
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   120
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   121
    if (!getDataType().empty()) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   122
        if (!(dataType = findDataType(getDataType()))) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   123
            err << "Invalid data type '" << getDataType() << "'!";
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   124
            throwInvalidUsageException(err);
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   125
        }
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   126
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   127
        if (dataType->byteSize) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   128
            // override length argument
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   129
            data.length = dataType->byteSize;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   130
        }
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    if (!data.length) {
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   134
        err << "The length argument is mandatory, if no datatype is " << endl
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   135
            << "specified, or the datatype does not imply a length!";
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   136
        throwInvalidUsageException(err);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    if ((uint32_t) data.offset + data.length > 0xffff) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        err << "Offset and length exceeding 64k!";
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        throwInvalidUsageException(err);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    m.open(MasterDevice::Read);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    slaves = selectedSlaves(m);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    if (slaves.size() != 1) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        throwSingleSlaveRequired(slaves.size());
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    data.slave_position = slaves.front().position;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    data.data = new uint8_t[data.length];
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
	try {
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1387
diff changeset
   155
		m.readReg(&data);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
	} catch (MasterDeviceException &e) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
        delete [] data.data;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
		throw e;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
	}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   161
    cout << setfill('0');
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   162
    if (!dataType || string(dataType->name) == "string") {
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   163
        uint16_t i;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   164
        for (i = 0; i < data.length; i++) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   165
            cout << data.data[i];
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   166
        }
1389
5b392b22a2da reg_write with data types.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   167
        if (dataType)
5b392b22a2da reg_write with data types.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   168
            cout << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   169
    } else if (string(dataType->name) == "int8") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   170
        int val = (int) *data.data;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   171
        cout << "0x" << hex << setw(2) << val << " " << dec << val << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   172
    } else if (string(dataType->name) == "int16") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   173
        int16_t val = le16_to_cpup(data.data);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   174
        cout << "0x" << hex << setw(4) << val << " " << dec << val << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   175
    } else if (string(dataType->name) == "int32") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   176
        int32_t val = le32_to_cpup(data.data);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   177
        cout << "0x" << hex << setw(8) << val << " " << dec << val << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   178
    } else if (string(dataType->name) == "int64") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   179
        int64_t val = le64_to_cpup(data.data);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   180
        cout << "0x" << hex << setw(16) << val << " " << dec << val << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   181
    } else if (string(dataType->name) == "uint8") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   182
        unsigned int val = (unsigned int) *data.data;
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   183
        cout << "0x" << hex << setw(2) << val << " " << dec << val << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   184
    } else if (string(dataType->name) == "uint16") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   185
        uint16_t val = le16_to_cpup(data.data);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   186
        cout << "0x" << hex << setw(4) << val << " " << dec << val << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   187
    } else if (string(dataType->name) == "uint32") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   188
        uint32_t val = le32_to_cpup(data.data);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   189
        cout << "0x" << hex << setw(8) << val << " " << dec << val << endl;
1431
70e891465da1 Fixed const char * comparison.
Florian Pose <fp@igh-essen.com>
parents: 1393
diff changeset
   190
    } else if (string(dataType->name) == "uint64") {
1393
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   191
        uint64_t val = le64_to_cpup(data.data);
979a7b26036d Output (fixed-size) hex value before decimal value.
Florian Pose <fp@igh-essen.com>
parents: 1391
diff changeset
   192
        cout << "0x" << hex << setw(16) << val << " " << dec << val << endl;
1389
5b392b22a2da reg_write with data types.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   193
    } else { // raw
1387
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   194
        uint8_t *d = data.data;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   195
        unsigned int size = data.length;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   196
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   197
        cout << hex << setfill('0');
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   198
        while (size--) {
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   199
            cout << "0x" << setw(2) << (unsigned int) *d++;
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   200
            if (size)
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   201
                cout << " ";
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   202
        }
57020c731092 Data types for phy_read.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   203
        cout << endl;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    delete [] data.data;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
/*****************************************************************************/