author | Christoph Mathys <ch1010832@ch10pc602> |
Thu, 04 Nov 2010 09:32:58 +0100 | |
branch | redundancy |
changeset 2313 | 7c5dded8e576 |
parent 2308 | f842ca3436ba |
child 2375 | ac3db27d60e0 |
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; |
2308
f842ca3436ba
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; |
2308
f842ca3436ba
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(); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
if (dataSize >= targetSize) { |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
stringstream err; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
err << "String too large"; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
throw SizeException(err.str()); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
str >> (char *) target; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
198 |
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
|
199 |
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
|
200 |
*(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
|
201 |
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
|
202 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
203 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
204 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
205 |
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
|
206 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
207 |
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
|
208 |
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
|
209 |
*(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
|
210 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
211 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
212 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
213 |
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
|
214 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
215 |
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
|
216 |
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
|
217 |
*(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
|
218 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
219 |
} |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
220 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
221 |
|
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
<< " 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
|
234 |
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
|
235 |
} |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
236 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
237 |
case 0xfffb: // sm8 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
238 |
case 0xfffc: // sm16 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
239 |
case 0xfffd: // sm32 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
240 |
case 0xfffe: // sm64 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
241 |
{ |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
242 |
stringstream err; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
243 |
err << "Sign-and-magitude types not yet" |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
244 |
" implemented for input direction."; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
245 |
throw runtime_error(err.str()); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
246 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
247 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
248 |
default: |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
249 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
250 |
stringstream err; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
251 |
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
|
252 |
throw runtime_error(err.str()); |
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 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
255 |
|
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
256 |
#if DEBUG |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
257 |
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
|
258 |
#endif |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
259 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
260 |
return dataSize; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
261 |
} |
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 |
void DataTypeHandler::outputData( |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
266 |
ostream &o, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
267 |
const DataType *type, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
268 |
void *data, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
269 |
size_t dataSize |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
270 |
) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
271 |
{ |
1893
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
272 |
uint16_t typeCode; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
273 |
|
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
274 |
if (type) { |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
275 |
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
|
276 |
stringstream err; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
277 |
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
|
278 |
<< " 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
|
279 |
<< dataSize << " byte."; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
280 |
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
|
281 |
} |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
282 |
typeCode = type->code; |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
283 |
} else { |
9a136c0c30a2
Fixed segfault in reg_read when no datatype is specified.
Florian Pose <fp@igh-essen.com>
parents:
1888
diff
changeset
|
284 |
typeCode = 0xffff; // raw data |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
285 |
} |
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 |
o << setfill('0'); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
288 |
|
2308
f842ca3436ba
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
289 |
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
|
290 |
case 0x0001: // bool |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
291 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
292 |
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
|
293 |
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
|
294 |
<< " " << dec << val << endl; |
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 |
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
|
297 |
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
|
298 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
299 |
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
|
300 |
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
|
301 |
<< " " << 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
|
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 |
break; |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
304 |
case 0x0003: // int16 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
305 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
<< " " << dec << val << endl; |
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 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
311 |
case 0x0004: // int32 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
312 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
313 |
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
|
314 |
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
|
315 |
<< " " << dec << val << endl; |
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 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
318 |
case 0x0005: // uint8 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
319 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
320 |
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
|
321 |
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
|
322 |
<< " " << dec << val << endl; |
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 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
325 |
case 0x0006: // uint16 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
326 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
327 |
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
|
328 |
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
|
329 |
<< " " << dec << val << endl; |
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 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
332 |
case 0x0007: // uint32 |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
333 |
{ |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
<< " " << dec << val << endl; |
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 |
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
|
339 |
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
|
340 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
341 |
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
|
342 |
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
|
343 |
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
|
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 |
break; |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
346 |
case 0x0009: // string |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
347 |
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
|
348 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
349 |
case 0x000a: // octet_string |
1875
01d31e749ee2
Omit newline on octet_string output.
Florian Pose <fp@igh-essen.com>
parents:
1871
diff
changeset
|
350 |
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
|
351 |
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
|
352 |
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
|
353 |
// 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
|
354 |
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
|
355 |
break; |
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 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
|
357 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
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
|
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 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
363 |
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
|
364 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
365 |
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
|
366 |
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
|
367 |
<< " " << 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
|
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 |
break; |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
370 |
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
|
371 |
{ |
04ea48971eed
Implemented a bunch of CANopen data types for the command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1868
diff
changeset
|
372 |
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
|
373 |
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
|
374 |
<< " " << 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
|
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 |
break; |
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
377 |
case 0xfffb: // sm8 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
378 |
{ |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
379 |
int8_t val = *(uint8_t *) data; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
380 |
int8_t smval = val < 0 ? (val & 0x7f) * -1 : val; |
2308
f842ca3436ba
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
381 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
382 |
o << "0x" << hex << setw(2) << (int) val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
383 |
<< " " << dec << (int) smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
384 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
385 |
break; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
386 |
case 0xfffc: // sm16 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
387 |
{ |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
388 |
int16_t val = le16_to_cpup(data); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
389 |
int16_t smval = val < 0 ? (val & 0x7fff) * -1 : val; |
2308
f842ca3436ba
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
390 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
391 |
o << "0x" << hex << setw(4) << val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
392 |
<< " " << dec << smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
393 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
394 |
break; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
395 |
case 0xfffd: // sm32 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
396 |
{ |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
397 |
int32_t val = le32_to_cpup(data); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
398 |
int32_t smval = val < 0 ? (val & 0x7fffffffUL) * -1 : val; |
2308
f842ca3436ba
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
399 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
400 |
o << "0x" << hex << setw(8) << val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
401 |
<< " " << dec << smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
402 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
403 |
break; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
404 |
case 0xfffe: // sm64 |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
405 |
{ |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
406 |
int64_t val = le64_to_cpup(data); |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
407 |
int64_t smval = |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
408 |
val < 0 ? (val & 0x7fffffffffffffffULL) * -1 : val; |
2308
f842ca3436ba
Fixed possible null pointer dereference in ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
2122
diff
changeset
|
409 |
|
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
410 |
o << "0x" << hex << setw(16) << val |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
411 |
<< " " << dec << smval << endl; |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
412 |
} |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
413 |
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
|
414 |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
415 |
default: |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
416 |
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
|
417 |
break; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
418 |
} |
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 |
void DataTypeHandler::printRawData( |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
424 |
ostream &o, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
425 |
const uint8_t *data, |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
426 |
size_t size |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
427 |
) |
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 |
o << hex << setfill('0'); |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
430 |
while (size--) { |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
431 |
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
|
432 |
if (size) |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
433 |
o << " "; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
434 |
} |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
435 |
o << endl; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
436 |
} |
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 |
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
|
441 |
{"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
|
442 |
{"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
|
443 |
{"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
|
444 |
{"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
|
445 |
{"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
|
446 |
{"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
|
447 |
{"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
|
448 |
{"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
|
449 |
{"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
|
450 |
{"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
|
451 |
{"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
|
452 |
// ... 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
|
453 |
{"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
|
454 |
{"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
|
455 |
{"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
|
456 |
{"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
|
457 |
{"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
|
458 |
{"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
|
459 |
{"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
|
460 |
// 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
|
461 |
{"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
|
462 |
{"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
|
463 |
{"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
|
464 |
{"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
|
465 |
// reserved 0x001c-0x001f |
1888
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
466 |
{"sm8", 0xfffb, 1}, // sign-and-magnitude coding |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
467 |
{"sm16", 0xfffc, 2}, // sign-and-magnitude coding |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
468 |
{"sm32", 0xfffd, 4}, // sign-and-magnitude coding |
02aedba35b94
Implemented sign-and-magnitude integer types.
Florian Pose <fp@igh-essen.com>
parents:
1875
diff
changeset
|
469 |
{"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
|
470 |
{"raw", 0xffff, 0}, |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
471 |
{} |
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 |
/*****************************************************************************/ |