tool/DataTypeHandler.cpp
author Florian Pose <fp@igh-essen.com>
Fri, 03 Mar 2017 17:08:39 +0100
changeset 2678 f5ffd1875da1
parent 2621 a26dee45c467
permissions -rw-r--r--
Clear unused ports; use arrows for next slaves.
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
2411
01370d59233d Malformed hg keywords.
Florian Pose <fp@igh-essen.com>
parents: 2388
diff changeset
     3
 *  $Id$
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
    30
#define DEBUG 0
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
    31
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
    32
#if DEBUG
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
    33
#include <iostream>
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
    34
#endif
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
    35
2621
a26dee45c467 Fix for strings containing spaces.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2589
diff changeset
    36
#include <string.h>
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <iomanip>
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <sstream>
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
using namespace std;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "DataTypeHandler.h"
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "ecrt.h"
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
DataTypeHandler::DataTypeHandler()
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
{
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
}
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
/****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
const DataTypeHandler::DataType *DataTypeHandler::findDataType(
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        const string &str
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        )
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
{
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    const DataType *d;
2188
08f547145c91 Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 2148
diff changeset
    58
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    for (d = dataTypes; d->name; d++)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        if (str == d->name)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
            return d;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    return NULL; // FIXME exception
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
}
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
/****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    68
string DataTypeHandler::typeInfo()
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    69
{
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    70
	stringstream s;
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    71
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    72
	s
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    73
		<< "These are valid data types to use with" << endl
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    74
		<< "the --type option:" << endl
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
    75
		<< "  bool," << endl
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
    76
		<< "  int8, int16, int32, int64," << endl
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
    77
		<< "  uint8, uint16, uint32, uint64," << endl
2148
289c42960b04 Minor: Added missing comma.
Florian Pose <fp@igh-essen.com>
parents: 1893
diff changeset
    78
		<< "  float, double," << endl
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
    79
		<< "  string, octet_string, unicode_string." << endl
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
    80
        << "For sign-and-magnitude coding, use the following types:" << endl
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
    81
        << "  sm8, sm16, sm32, sm64" << endl;
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    82
	return s.str();
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    83
}
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    84
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    85
/****************************************************************************/
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    86
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
const DataTypeHandler::DataType *DataTypeHandler::findDataType(uint16_t code)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
{
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    const DataType *d;
2188
08f547145c91 Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 2148
diff changeset
    90
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    for (d = dataTypes; d->name; d++)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
        if (code == d->code)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
            return d;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    return NULL;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
}
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
/****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
size_t DataTypeHandler::interpretAsType(
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        const DataType *type,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
        const string &source,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        void *target,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        size_t targetSize
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        )
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2411
diff changeset
   106
{
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    stringstream str;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    size_t dataSize = type->byteSize;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
2621
a26dee45c467 Fix for strings containing spaces.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2589
diff changeset
   110
    memset(target, 0, targetSize);
a26dee45c467 Fix for strings containing spaces.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2589
diff changeset
   111
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   112
#if DEBUG
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   113
	cerr << __func__ << "(targetSize=" << targetSize << ")" << endl;
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   114
#endif
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   115
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    str << source;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    str >> resetiosflags(ios::basefield); // guess base from prefix
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    str.exceptions(ios::failbit);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   120
#if DEBUG
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   121
	cerr << "code=" << type->code << endl;
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   122
#endif
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   123
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    switch (type->code) {
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   125
        case 0x0001: // bool
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   126
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   127
                int16_t val; // uint8_t is interpreted as char
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   128
                str >> val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   129
                if (val > 1 || val < 0)
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   130
                    throw ios::failure("Value out of range");
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   131
                *(uint8_t *) target = val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   132
                break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   133
            }
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        case 0x0002: // int8
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
                int16_t val; // uint8_t is interpreted as char
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
                str >> val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
                if (val > 127 || val < -128)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
                    throw ios::failure("Value out of range");
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
                *(uint8_t *) target = val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
                break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
        case 0x0003: // int16
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
                int16_t val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
                str >> val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
                *(int16_t *) target = cpu_to_le16(val);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
                break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
        case 0x0004: // int32
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
                int32_t val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
                str >> val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
                *(int32_t *) target = cpu_to_le32(val);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
                break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
        case 0x0005: // uint8
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
                uint16_t val; // uint8_t is interpreted as char
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
                str >> val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
                if (val > 0xff)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
                    throw ios::failure("Value out of range");
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
                *(uint8_t *) target = val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
                break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
        case 0x0006: // uint16
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
                uint16_t val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
                str >> val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
                *(uint16_t *) target = cpu_to_le16(val);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
                break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        case 0x0007: // uint32
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
                uint32_t val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
                str >> val;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
                *(uint32_t *) target = cpu_to_le32(val);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
                break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
            }
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   180
        case 0x0008: // float
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   181
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   182
                float val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   183
                str >> val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   184
                *(uint32_t *) target =
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   185
					cpu_to_le32(*(uint32_t *) (void *) &val);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   186
                break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   187
            }
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
        case 0x0009: // string
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
        case 0x000a: // octet_string
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   190
        case 0x000b: // unicode_string
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
            dataSize = str.str().size();
2388
7fc286c8e72b Fixed 'String too large' error in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2188
diff changeset
   192
            if (dataSize > targetSize) {
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
                stringstream err;
2388
7fc286c8e72b Fixed 'String too large' error in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2188
diff changeset
   194
                err << "String too large ("
7fc286c8e72b Fixed 'String too large' error in command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2188
diff changeset
   195
                    << dataSize << " > " << targetSize << ")";
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
                throw SizeException(err.str());
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
            }
2621
a26dee45c467 Fix for strings containing spaces.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2589
diff changeset
   198
            str.read((char *) target, dataSize);
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
            break;
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   200
        case 0x0011: // double
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   201
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   202
                double val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   203
                str >> val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   204
                *(uint64_t *) target =
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   205
					cpu_to_le64(*(uint64_t *) (void *) &val);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   206
                break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   207
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   208
            break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   209
        case 0x0015: // int64
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   210
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   211
                int64_t val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   212
                str >> val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   213
                *(int64_t *) target = cpu_to_le64(val);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   214
                break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   215
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   216
            break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   217
        case 0x001b: // uint64
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   218
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   219
                uint64_t val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   220
                str >> val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   221
                *(uint64_t *) target = cpu_to_le64(val);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   222
                break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   223
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   224
            break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   225
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   226
        case 0x0010: // int24
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   227
        case 0x0012: // int40
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   228
        case 0x0013: // int48
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   229
        case 0x0014: // int56
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   230
        case 0x0016: // uint24
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   231
        case 0x0018: // uint40
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   232
        case 0x0019: // uint48
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   233
        case 0x001a: // uint56
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   234
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   235
                stringstream err;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   236
                err << "Non-native integer type " << type->name
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   237
					<< " is not yet implemented.";
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   238
                throw runtime_error(err.str());
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   239
            }
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   241
        case 0xfffb: // sm8
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   242
        case 0xfffc: // sm16
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   243
        case 0xfffd: // sm32
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   244
        case 0xfffe: // sm64
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   245
            {
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   246
                stringstream err;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   247
                err << "Sign-and-magitude types not yet"
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   248
                    " implemented for input direction.";
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   249
                throw runtime_error(err.str());
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   250
            }
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   251
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
        default:
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
                stringstream err;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
                err << "Unknown data type 0x" << hex << type->code;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
                throw runtime_error(err.str());
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
    }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   260
#if DEBUG
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   261
	printRawData(cerr, (const uint8_t *) target, dataSize);
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   262
#endif
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   263
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    return dataSize;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
}
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
/****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
void DataTypeHandler::outputData(
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
        ostream &o,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
        const DataType *type,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
        void *data,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
        size_t dataSize
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
        )
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2411
diff changeset
   275
{
1893
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   276
    uint16_t typeCode;
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   277
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   278
    if (type) {
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   279
        if (type->byteSize && dataSize != type->byteSize) {
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   280
            stringstream err;
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   281
            err << "Data type mismatch. Expected " << type->name
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   282
                << " with " << type->byteSize << " byte, but got "
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   283
                << dataSize << " byte.";
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   284
            throw SizeException(err.str());
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   285
        }
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   286
        typeCode = type->code;
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   287
    } else {
9a136c0c30a2 Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents: 1888
diff changeset
   288
        typeCode = 0xffff; // raw data
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
    }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
    o << setfill('0');
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
2188
08f547145c91 Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 2148
diff changeset
   293
    switch (typeCode) {
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   294
        case 0x0001: // bool
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
                int val = (int) *(int8_t *) data;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
                o << "0x" << hex << setw(2) << val
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
                    << " " << dec << val << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
            break;
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   301
        case 0x0002: // int8
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   302
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   303
                int val = (int) *(int8_t *) data;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   304
                o << "0x" << hex << setw(2) << val
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   305
                    << " " << dec << val << endl;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   306
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   307
            break;
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
        case 0x0003: // int16
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
                int16_t val = le16_to_cpup(data);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
                o << "0x" << hex << setw(4) << val
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
                    << " " << dec << val << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
            break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
        case 0x0004: // int32
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
                int32_t val = le32_to_cpup(data);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
                o << "0x" << hex << setw(8) << val
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
                    << " " << dec << val << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
            break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
        case 0x0005: // uint8
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
                unsigned int val = (unsigned int) *(uint8_t *) data;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
                o << "0x" << hex << setw(2) << val
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
                    << " " << dec << val << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
            break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
        case 0x0006: // uint16
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
                uint16_t val = le16_to_cpup(data);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
                o << "0x" << hex << setw(4) << val
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
                    << " " << dec << val << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
            break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
        case 0x0007: // uint32
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
            {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
                uint32_t val = le32_to_cpup(data);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
                o << "0x" << hex << setw(8) << val
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
                    << " " << dec << val << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
            }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
            break;
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   343
        case 0x0008: // float
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   344
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   345
                uint32_t val = le32_to_cpup(data);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   346
				float fval = *(float *) (void *) &val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   347
                o << fval << endl;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   348
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   349
            break;
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
        case 0x0009: // string
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
            o << string((const char *) data, dataSize) << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
            break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
        case 0x000a: // octet_string
1875
01d31e749ee2 Omit newline on octet_string output.
Florian Pose <fp@igh-essen.com>
parents: 1871
diff changeset
   354
            o << string((const char *) data, dataSize) << flush;
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
            break;
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   356
        case 0x000b: // unicode_string
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   357
			// FIXME encoding
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   358
            o << string((const char *) data, dataSize) << endl;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   359
            break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   360
        case 0x0011: // double
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   361
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   362
                uint64_t val = le64_to_cpup(data);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   363
				double fval = *(double *) (void *) &val;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   364
                o << fval << endl;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   365
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   366
            break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   367
        case 0x0015: // int64
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   368
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   369
                int64_t val = le64_to_cpup(data);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   370
                o << "0x" << hex << setw(16) << val
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   371
                    << " " << dec << val << endl;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   372
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   373
            break;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   374
        case 0x001b: // uint64
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   375
            {
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   376
                uint64_t val = le64_to_cpup(data);
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   377
                o << "0x" << hex << setw(16) << val
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   378
                    << " " << dec << val << endl;
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   379
            }
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   380
            break;
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   381
        case 0xfffb: // sm8
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   382
            {
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   383
                int8_t val = *(uint8_t *) data;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   384
                int8_t smval = val < 0 ? (val & 0x7f) * -1 : val;
2188
08f547145c91 Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 2148
diff changeset
   385
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   386
                o << "0x" << hex << setw(2) << (int) val
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   387
                    << " " << dec << (int) smval << endl;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   388
            }
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   389
            break;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   390
        case 0xfffc: // sm16
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   391
            {
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   392
                int16_t val = le16_to_cpup(data);
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   393
                int16_t smval = val < 0 ? (val & 0x7fff) * -1 : val;
2188
08f547145c91 Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 2148
diff changeset
   394
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   395
                o << "0x" << hex << setw(4) << val
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   396
                    << " " << dec << smval << endl;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   397
            }
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   398
            break;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   399
        case 0xfffd: // sm32
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   400
            {
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   401
                int32_t val = le32_to_cpup(data);
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   402
                int32_t smval = val < 0 ? (val & 0x7fffffffUL) * -1 : val;
2188
08f547145c91 Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 2148
diff changeset
   403
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   404
                o << "0x" << hex << setw(8) << val
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   405
                    << " " << dec << smval << endl;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   406
            }
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   407
            break;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   408
        case 0xfffe: // sm64
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   409
            {
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   410
                int64_t val = le64_to_cpup(data);
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   411
                int64_t smval =
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   412
                    val < 0 ? (val & 0x7fffffffffffffffULL) * -1 : val;
2188
08f547145c91 Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 2148
diff changeset
   413
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   414
                o << "0x" << hex << setw(16) << val
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   415
                    << " " << dec << smval << endl;
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   416
            }
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   417
            break;
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   418
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
        default:
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
            printRawData(o, (const uint8_t *) data, dataSize); // FIXME
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
            break;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
    }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   423
}
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
/****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
void DataTypeHandler::printRawData(
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
        ostream &o,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
        const uint8_t *data,
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
        size_t size
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
        )
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
{
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
    o << hex << setfill('0');
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
    while (size--) {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
        o << "0x" << setw(2) << (unsigned int) *data++;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
        if (size)
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   437
            o << " ";
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   438
    }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
    o << endl;
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   440
}
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   441
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
/****************************************************************************/
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
const DataTypeHandler::DataType DataTypeHandler::dataTypes[] = {
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   445
    {"bool",           0x0001, 1},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   446
    {"int8",           0x0002, 1},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   447
    {"int16",          0x0003, 2},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   448
    {"int32",          0x0004, 4},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   449
    {"uint8",          0x0005, 1},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   450
    {"uint16",         0x0006, 2},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   451
    {"uint32",         0x0007, 4},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   452
    {"float",          0x0008, 4},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   453
    {"string",         0x0009, 0}, // a. k. a. visible_string
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   454
    {"octet_string",   0x000a, 0},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   455
    {"unicode_string", 0x000b, 0},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   456
	// ... not implemented yet
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   457
    {"int24",          0x0010, 3},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   458
    {"double",         0x0011, 8},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   459
    {"int40",          0x0012, 5},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   460
    {"int48",          0x0013, 6},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   461
    {"int56",          0x0014, 7},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   462
    {"int64",          0x0015, 8},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   463
    {"uint24",         0x0016, 3},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   464
	// reserved        0x0017
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   465
    {"uint40",         0x0018, 5},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   466
    {"uint48",         0x0019, 6},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   467
    {"uint56",         0x001a, 7},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   468
    {"uint64",         0x001b, 8},
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   469
	// reserved        0x001c-0x001f
1888
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   470
    {"sm8",            0xfffb, 1}, // sign-and-magnitude coding
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   471
    {"sm16",           0xfffc, 2}, // sign-and-magnitude coding
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   472
    {"sm32",           0xfffd, 4}, // sign-and-magnitude coding
02aedba35b94 Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents: 1875
diff changeset
   473
    {"sm64",           0xfffe, 8}, // sign-and-magnitude coding
1871
04ea48971eed Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1868
diff changeset
   474
    {"raw",            0xffff, 0},
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   475
    {}
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   476
};
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   477
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   478
/*****************************************************************************/