author | Florian Pose <fp@igh-essen.com> |
Mon, 23 Jul 2012 16:20:40 +0200 | |
branch | stable-1.5 |
changeset 2407 | 35223d2e6e72 |
parent 2375 | ac3db27d60e0 |
child 2421 | bc2d4bf9cbe5 |
permissions | -rw-r--r-- |
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 |
* |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
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 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
#include <iomanip> |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
#include <sstream> |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
using namespace std; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
|
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
#include "DataTypeHandler.h" |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
|
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
#include "ecrt.h" |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
|
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 |
DataTypeHandler::DataTypeHandler() |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
{ |
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 |
const DataTypeHandler::DataType *DataTypeHandler::findDataType( |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
const string &str |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
) |
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 |
const DataType *d; |
2191
54cda823743a
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
57 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
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
|
59 |
if (str == d->name) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
return d; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
|
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
return NULL; // FIXME exception |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
} |
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 |
|
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
|
67 |
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
|
68 |
{ |
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 |
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
|
70 |
|
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 |
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
|
72 |
<< "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
|
73 |
<< "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
|
74 |
<< " 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
|
75 |
<< " 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
|
76 |
<< " uint8, uint16, uint32, uint64," << endl |
2122
23414e7559de
Minor: Added missing comma.
Florian Pose <fp@igh-essen.com>
parents:
1893
diff
changeset
|
77 |
<< " float, double," << endl |
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
78 |
<< " string, octet_string, unicode_string." << endl |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
79 |
<< "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
|
80 |
<< " 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
|
81 |
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
|
82 |
} |
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 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
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
|
87 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
const DataType *d; |
2191
54cda823743a
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
89 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
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
|
91 |
if (code == d->code) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
return d; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
|
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
return NULL; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
} |
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 |
size_t DataTypeHandler::interpretAsType( |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
const DataType *type, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
const string &source, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
void *target, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
size_t targetSize |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
stringstream str; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
size_t dataSize = type->byteSize; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
|
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
109 |
#if DEBUG |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
110 |
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
|
111 |
#endif |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
112 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
str << source; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
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
|
115 |
str.exceptions(ios::failbit); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
|
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
117 |
#if DEBUG |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
118 |
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
|
119 |
#endif |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
120 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
*(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
|
129 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
130 |
} |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
case 0x0002: // int8 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
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
|
134 |
str >> val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
if (val > 127 || val < -128) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
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
|
137 |
*(uint8_t *) target = val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
case 0x0003: // int16 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
int16_t val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
str >> val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
*(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
|
145 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
case 0x0004: // int32 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
int32_t val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
str >> val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
*(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
|
152 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
case 0x0005: // uint8 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
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
|
157 |
str >> val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
if (val > 0xff) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
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
|
160 |
*(uint8_t *) target = val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
case 0x0006: // uint16 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
uint16_t val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
str >> val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
*(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
|
168 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
case 0x0007: // uint32 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
171 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
uint32_t val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
str >> val; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
*(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
|
175 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
} |
1871
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
177 |
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
|
178 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
*(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
|
182 |
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
|
183 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
184 |
} |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
185 |
case 0x0009: // string |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
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
|
187 |
case 0x000b: // unicode_string |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
dataSize = str.str().size(); |
2375
ac3db27d60e0
Fixed 'String too large' error in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
2191
diff
changeset
|
189 |
if (dataSize > targetSize) { |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
stringstream err; |
2375
ac3db27d60e0
Fixed 'String too large' error in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
2191
diff
changeset
|
191 |
err << "String too large (" |
ac3db27d60e0
Fixed 'String too large' error in command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
2191
diff
changeset
|
192 |
<< dataSize << " > " << targetSize << ")"; |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
throw SizeException(err.str()); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
str >> (char *) target; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
*(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
|
202 |
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
|
203 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
204 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
205 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
206 |
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
|
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 |
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
|
209 |
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
|
210 |
*(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
|
211 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
212 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
213 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
214 |
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
|
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 |
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
|
217 |
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
|
218 |
*(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
|
219 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
220 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
221 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
222 |
|
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
<< " 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
|
235 |
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
|
236 |
} |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
237 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
238 |
case 0xfffb: // sm8 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
239 |
case 0xfffc: // sm16 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
240 |
case 0xfffd: // sm32 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
241 |
case 0xfffe: // sm64 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
242 |
{ |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
243 |
stringstream err; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
244 |
err << "Sign-and-magitude types not yet" |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
245 |
" implemented for input direction."; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
246 |
throw runtime_error(err.str()); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
247 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
248 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
249 |
default: |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
250 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
251 |
stringstream err; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
252 |
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
|
253 |
throw runtime_error(err.str()); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
254 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
255 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
256 |
|
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
257 |
#if DEBUG |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
258 |
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
|
259 |
#endif |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
260 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
261 |
return dataSize; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
262 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
263 |
|
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
264 |
/****************************************************************************/ |
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 |
void DataTypeHandler::outputData( |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
267 |
ostream &o, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
268 |
const DataType *type, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
269 |
void *data, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
270 |
size_t dataSize |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
271 |
) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
272 |
{ |
1893
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
273 |
uint16_t typeCode; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
274 |
|
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
275 |
if (type) { |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
276 |
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
|
277 |
stringstream err; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
278 |
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
|
279 |
<< " 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
|
280 |
<< dataSize << " byte."; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
281 |
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
|
282 |
} |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
283 |
typeCode = type->code; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
284 |
} else { |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
285 |
typeCode = 0xffff; // raw data |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
286 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
287 |
|
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
288 |
o << setfill('0'); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
289 |
|
2191
54cda823743a
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
290 |
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
|
291 |
case 0x0001: // bool |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
292 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
<< " " << dec << val << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
296 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
<< " " << 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
|
303 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
304 |
break; |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
305 |
case 0x0003: // int16 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
306 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
307 |
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
|
308 |
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
|
309 |
<< " " << dec << val << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
310 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
311 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
312 |
case 0x0004: // int32 |
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 |
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
|
315 |
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
|
316 |
<< " " << dec << val << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
317 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
318 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
319 |
case 0x0005: // uint8 |
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 |
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
|
322 |
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
|
323 |
<< " " << dec << val << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
324 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
325 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
326 |
case 0x0006: // uint16 |
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 |
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
|
329 |
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
|
330 |
<< " " << dec << val << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
331 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
332 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
333 |
case 0x0007: // uint32 |
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 |
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
|
336 |
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
|
337 |
<< " " << dec << val << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
338 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
339 |
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
|
340 |
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
|
341 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
346 |
break; |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
347 |
case 0x0009: // string |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
348 |
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
|
349 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
350 |
case 0x000a: // octet_string |
1875
01d31e749ee2
Omit newline on octet_string output.
Florian Pose <fp@igh-essen.com>
parents:
1871
diff
changeset
|
351 |
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
|
352 |
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
|
353 |
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
|
354 |
// 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
|
355 |
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
|
356 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
357 |
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
|
358 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
359 |
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
|
360 |
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
|
361 |
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
|
362 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
363 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
364 |
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
|
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 |
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
|
367 |
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
|
368 |
<< " " << 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
|
369 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
370 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
371 |
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
|
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 |
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
|
374 |
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
|
375 |
<< " " << 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
|
376 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
377 |
break; |
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
378 |
case 0xfffb: // sm8 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
379 |
{ |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
380 |
int8_t val = *(uint8_t *) data; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
381 |
int8_t smval = val < 0 ? (val & 0x7f) * -1 : val; |
2191
54cda823743a
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
382 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
383 |
o << "0x" << hex << setw(2) << (int) val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
384 |
<< " " << dec << (int) smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
385 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
386 |
break; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
387 |
case 0xfffc: // sm16 |
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 |
int16_t val = le16_to_cpup(data); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
390 |
int16_t smval = val < 0 ? (val & 0x7fff) * -1 : val; |
2191
54cda823743a
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
391 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
392 |
o << "0x" << hex << setw(4) << val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
393 |
<< " " << dec << smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
394 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
395 |
break; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
396 |
case 0xfffd: // sm32 |
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 |
int32_t val = le32_to_cpup(data); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
399 |
int32_t smval = val < 0 ? (val & 0x7fffffffUL) * -1 : val; |
2191
54cda823743a
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
400 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
401 |
o << "0x" << hex << setw(8) << val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
402 |
<< " " << dec << smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
403 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
404 |
break; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
405 |
case 0xfffe: // sm64 |
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 |
int64_t val = le64_to_cpup(data); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
408 |
int64_t smval = |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
409 |
val < 0 ? (val & 0x7fffffffffffffffULL) * -1 : val; |
2191
54cda823743a
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
410 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
411 |
o << "0x" << hex << setw(16) << val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
412 |
<< " " << dec << smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
413 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
414 |
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
|
415 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
416 |
default: |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
417 |
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
|
418 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
419 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
420 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
421 |
|
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 |
void DataTypeHandler::printRawData( |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
425 |
ostream &o, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
426 |
const uint8_t *data, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
427 |
size_t size |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
428 |
) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
429 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
430 |
o << hex << setfill('0'); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
431 |
while (size--) { |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
432 |
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
|
433 |
if (size) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
434 |
o << " "; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
435 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
436 |
o << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
437 |
} |
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 |
/****************************************************************************/ |
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 |
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
|
442 |
{"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
|
443 |
{"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
|
444 |
{"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
|
445 |
{"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
|
446 |
{"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
|
447 |
{"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
|
448 |
{"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
|
449 |
{"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
|
450 |
{"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
|
451 |
{"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
|
452 |
{"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
|
453 |
// ... 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
|
454 |
{"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
|
455 |
{"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
|
456 |
{"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
|
457 |
{"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
|
458 |
{"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
|
459 |
{"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
|
460 |
{"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
|
461 |
// 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
|
462 |
{"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
|
463 |
{"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
|
464 |
{"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
|
465 |
{"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
|
466 |
// reserved 0x001c-0x001f |
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
467 |
{"sm8", 0xfffb, 1}, // sign-and-magnitude coding |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
468 |
{"sm16", 0xfffc, 2}, // sign-and-magnitude coding |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
469 |
{"sm32", 0xfffd, 4}, // sign-and-magnitude coding |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
470 |
{"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
|
471 |
{"raw", 0xffff, 0}, |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
472 |
{} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
473 |
}; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
474 |
|
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
475 |
/*****************************************************************************/ |