author | Florian Pose <fp@igh-essen.com> |
Fri, 03 Mar 2017 13:50:49 +0100 | |
branch | stable-1.5 |
changeset 2667 | 0d7936701e60 |
parent 2124 | c4afc5fede19 |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
3 |
* $Id$ |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
4 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
6 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
8 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
11 |
* published by the Free Software Foundation. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
12 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
16 |
* Public License for more details. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
17 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
21 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1334
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1142 | 27 |
* |
28 |
****************************************************************************/ |
|
29 |
||
30 |
#include <iostream> |
|
31 |
#include <iomanip> |
|
32 |
using namespace std; |
|
33 |
||
34 |
#include "CommandDownload.h" |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
35 |
#include "MasterDevice.h" |
1142 | 36 |
|
37 |
/*****************************************************************************/ |
|
38 |
||
39 |
CommandDownload::CommandDownload(): |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
40 |
SdoCommand("download", "Write an SDO entry to a slave.") |
1142 | 41 |
{ |
42 |
} |
|
43 |
||
44 |
/*****************************************************************************/ |
|
45 |
||
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
46 |
string CommandDownload::helpString(const string &binaryBaseName) const |
1142 | 47 |
{ |
48 |
stringstream str; |
|
49 |
||
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
50 |
str << binaryBaseName << " " << getName() |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
51 |
<< " [OPTIONS] <INDEX> <SUBINDEX> <VALUE>" << endl |
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
52 |
<< " [OPTIONS] <INDEX> <VALUE>" << endl |
1804 | 53 |
<< endl |
54 |
<< getBriefDescription() << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
55 |
<< endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
56 |
<< "This command requires a single slave to be selected." << endl |
1804 | 57 |
<< endl |
58 |
<< "The data type of the SDO entry is taken from the SDO" << endl |
|
59 |
<< "dictionary by default. It can be overridden with the" << endl |
|
60 |
<< "--type option. If the slave does not support the SDO" << endl |
|
61 |
<< "information service or the SDO is not in the dictionary," << endl |
|
62 |
<< "the --type option is mandatory." << endl |
|
63 |
<< endl |
|
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
64 |
<< "The second call (without <SUBINDEX>) uses the complete" << endl |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
65 |
<< "access method." << endl |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
66 |
<< endl |
1868
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1835
diff
changeset
|
67 |
<< typeInfo() |
1804 | 68 |
<< endl |
69 |
<< "Arguments:" << endl |
|
70 |
<< " INDEX is the SDO index and must be an unsigned" << endl |
|
71 |
<< " 16 bit number." << endl |
|
72 |
<< " SUBINDEX is the SDO entry subindex and must be an" << endl |
|
73 |
<< " unsigned 8 bit number." << endl |
|
74 |
<< " VALUE is the value to download and must correspond" << endl |
|
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
75 |
<< " to the SDO entry datatype (see above). Use" << endl |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
76 |
<< " '-' to read from standard input." << endl |
1804 | 77 |
<< endl |
78 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
79 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
80 |
<< " --position -p <pos> Slave selection. See the help of" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1155
diff
changeset
|
81 |
<< " the 'slaves' command." << endl |
1804 | 82 |
<< " --type -t <type> SDO entry data type (see above)." << endl |
83 |
<< endl |
|
84 |
<< numericInfo(); |
|
85 |
||
86 |
return str.str(); |
|
1142 | 87 |
} |
88 |
||
89 |
/****************************************************************************/ |
|
90 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
91 |
void CommandDownload::execute(const StringVector &args) |
1142 | 92 |
{ |
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
93 |
stringstream strIndex, err; |
1142 | 94 |
ec_ioctl_slave_sdo_download_t data; |
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
95 |
unsigned int valueIndex; |
1184
75cd6681eb08
Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
96 |
const DataType *dataType = NULL; |
1151 | 97 |
SlaveList slaves; |
1142 | 98 |
|
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
99 |
if (args.size() != 2 && args.size() != 3) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
100 |
err << "'" << getName() << "' takes 2 or 3 arguments!"; |
1142 | 101 |
throwInvalidUsageException(err); |
102 |
} |
|
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
103 |
data.complete_access = args.size() == 2; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
104 |
valueIndex = data.complete_access ? 1 : 2; |
1142 | 105 |
|
106 |
strIndex << args[0]; |
|
107 |
strIndex |
|
108 |
>> resetiosflags(ios::basefield) // guess base from prefix |
|
109 |
>> data.sdo_index; |
|
110 |
if (strIndex.fail()) { |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
111 |
err << "Invalid SDO index '" << args[0] << "'!"; |
1142 | 112 |
throwInvalidUsageException(err); |
113 |
} |
|
114 |
||
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
115 |
if (data.complete_access) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
116 |
data.sdo_entry_subindex = 0; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
117 |
} else { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
118 |
stringstream strSubIndex; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
119 |
unsigned int number; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
120 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
121 |
strSubIndex << args[1]; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
122 |
strSubIndex |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
123 |
>> resetiosflags(ios::basefield) // guess base from prefix |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
124 |
>> number; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
125 |
if (strSubIndex.fail() || number > 0xff) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
126 |
err << "Invalid SDO subindex '" << args[1] << "'!"; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
127 |
throwInvalidUsageException(err); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
128 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
129 |
data.sdo_entry_subindex = number; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
130 |
} |
1142 | 131 |
|
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
132 |
MasterDevice m(getSingleMasterIndex()); |
1151 | 133 |
m.open(MasterDevice::ReadWrite); |
134 |
slaves = selectedSlaves(m); |
|
135 |
if (slaves.size() != 1) { |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
136 |
throwSingleSlaveRequired(slaves.size()); |
1151 | 137 |
} |
138 |
data.slave_position = slaves.front().position; |
|
139 |
||
1166 | 140 |
if (!getDataType().empty()) { // data type specified |
141 |
if (!(dataType = findDataType(getDataType()))) { |
|
142 |
err << "Invalid data type '" << getDataType() << "'!"; |
|
1142 | 143 |
throwInvalidUsageException(err); |
144 |
} |
|
145 |
} else { // no data type specified: fetch from dictionary |
|
146 |
ec_ioctl_slave_sdo_entry_t entry; |
|
147 |
||
148 |
try { |
|
1151 | 149 |
m.getSdoEntry(&entry, data.slave_position, |
1142 | 150 |
data.sdo_index, data.sdo_entry_subindex); |
151 |
} catch (MasterDeviceException &e) { |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
152 |
err << "Failed to determine SDO entry data type. " |
1142 | 153 |
<< "Please specify --type."; |
154 |
throwCommandException(err); |
|
155 |
} |
|
156 |
if (!(dataType = findDataType(entry.data_type))) { |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
157 |
err << "PDO entry has unknown data type 0x" |
1142 | 158 |
<< hex << setfill('0') << setw(4) << entry.data_type << "!" |
159 |
<< " Please specify --type."; |
|
160 |
throwCommandException(err); |
|
161 |
} |
|
162 |
} |
|
163 |
||
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
164 |
if (args[valueIndex] == "-") { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
165 |
ostringstream tmp; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
166 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
167 |
tmp << cin.rdbuf(); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
168 |
string const &contents = tmp.str(); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
169 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
170 |
if (!contents.size()) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
171 |
err << "Invalid data size " << contents.size() << "! " |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
172 |
<< "Must be non-zero."; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
173 |
throwCommandException(err); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
174 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
175 |
data.data_size = contents.size(); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
176 |
data.data = new uint8_t[data.data_size + 1]; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
177 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
178 |
try { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
179 |
data.data_size = interpretAsType( |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
180 |
dataType, contents, data.data, data.data_size); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
181 |
} catch (SizeException &e) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
182 |
delete [] data.data; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
183 |
throwCommandException(e.what()); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
184 |
} catch (ios::failure &e) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
185 |
delete [] data.data; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
186 |
err << "Invalid value argument '" << args[2] |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
187 |
<< "' for type '" << dataType->name << "'!"; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
188 |
throwInvalidUsageException(err); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
189 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
190 |
|
1142 | 191 |
} else { |
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
192 |
if (dataType->byteSize) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
193 |
data.data_size = dataType->byteSize; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
194 |
} else { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
195 |
data.data_size = DefaultBufferSize; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
196 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
197 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
198 |
data.data = new uint8_t[data.data_size + 1]; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
199 |
|
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
200 |
try { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
201 |
data.data_size = interpretAsType( |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
202 |
dataType, args[valueIndex], data.data, data.data_size); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
203 |
} catch (SizeException &e) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
204 |
delete [] data.data; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
205 |
throwCommandException(e.what()); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
206 |
} catch (ios::failure &e) { |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
207 |
delete [] data.data; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
208 |
err << "Invalid value argument '" << args[2] |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
209 |
<< "' for type '" << dataType->name << "'!"; |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
210 |
throwInvalidUsageException(err); |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
211 |
} |
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
212 |
} |
1142 | 213 |
|
214 |
try { |
|
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
215 |
data.data_size = interpretAsType( |
2124
c4afc5fede19
Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
216 |
dataType, args[valueIndex], data.data, data.data_size); |
1835
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
217 |
} catch (SizeException &e) { |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
218 |
delete [] data.data; |
20748e9d2238
Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
219 |
throwCommandException(e.what()); |
1142 | 220 |
} catch (ios::failure &e) { |
221 |
delete [] data.data; |
|
222 |
err << "Invalid value argument '" << args[2] |
|
223 |
<< "' for type '" << dataType->name << "'!"; |
|
224 |
throwInvalidUsageException(err); |
|
225 |
} |
|
226 |
||
1804 | 227 |
try { |
1151 | 228 |
m.sdoDownload(&data); |
1804 | 229 |
} catch (MasterDeviceSdoAbortException &e) { |
1184
75cd6681eb08
Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
230 |
delete [] data.data; |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
231 |
err << "SDO transfer aborted with code 0x" |
1184
75cd6681eb08
Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
232 |
<< setfill('0') << hex << setw(8) << e.abortCode |
75cd6681eb08
Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
233 |
<< ": " << abortText(e.abortCode); |
75cd6681eb08
Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents:
1166
diff
changeset
|
234 |
throwCommandException(err); |
1804 | 235 |
} catch(MasterDeviceException &e) { |
1142 | 236 |
delete [] data.data; |
237 |
throw e; |
|
238 |
} |
|
239 |
||
240 |
delete [] data.data; |
|
241 |
} |
|
242 |
||
243 |
/*****************************************************************************/ |