author | Florian Pose <fp@igh-essen.com> |
Tue, 12 Feb 2013 15:30:34 +0100 | |
branch | stable-1.5 |
changeset 2521 | 3d68bb0047a1 |
parent 1968 | 4f682084c643 |
permissions | -rw-r--r-- |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/***************************************************************************** |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* published by the Free Software Foundation. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* Public License for more details. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* --- |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
#include <iostream> |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
31 |
#include <iomanip> |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
using namespace std; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
#include "CommandSoeWrite.h" |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
#include "MasterDevice.h" |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
/*****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
CommandSoeWrite::CommandSoeWrite(): |
1966
23c638a81fe7
Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents:
1953
diff
changeset
|
40 |
Command("soe_write", "Write an SoE IDN to a slave.") |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
{ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
/*****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
|
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
46 |
string CommandSoeWrite::helpString(const string &binaryBaseName) const |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
{ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
stringstream str; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
|
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
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:
1966
diff
changeset
|
51 |
<< " [OPTIONS] <IDN> <VALUE>" << endl |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
52 |
<< binaryBaseName << " " << getName() |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
53 |
<< " [OPTIONS] <DRIVE> <IDN> <VALUE>" << endl |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
<< endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
<< getBriefDescription() << endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
<< endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
<< "This command requires a single slave to be selected." << endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
<< endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
<< "Arguments:" << endl |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
60 |
<< " DRIVE is the drive number (0 - 7). If omitted, 0 is assumed." |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
61 |
<< endl |
1868
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
62 |
<< " IDN is the IDN and must be either an unsigned" << endl |
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
63 |
<< " 16 bit number acc. to IEC 61800-7-204:" << endl |
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
64 |
<< " Bit 15: (0) Standard data, (1) Product data" << endl |
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
65 |
<< " Bit 14 - 12: Parameter set (0 - 7)" << endl |
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
66 |
<< " Bit 11 - 0: Data block number" << endl |
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
67 |
<< " or a string like 'P-0-150'." << endl |
1872
23d4e121faaf
Improved SoE command help.
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
68 |
<< " VALUE is the value to write (see below)." << endl |
1868
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
69 |
<< endl |
1872
23d4e121faaf
Improved SoE command help.
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
70 |
<< "The VALUE argument is interpreted as the given data type" << endl |
23d4e121faaf
Improved SoE command help.
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
71 |
<< "(--type is mandatory) and written to the selected slave." << endl |
23d4e121faaf
Improved SoE command help.
Florian Pose <fp@igh-essen.com>
parents:
1870
diff
changeset
|
72 |
<< endl |
1868
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
73 |
<< typeInfo() |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
<< endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
<< "Command-specific options:" << endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
<< " --alias -a <alias>" << endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
<< " --position -p <pos> Slave selection. See the help of" << endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
<< " the 'slaves' command." << endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
<< " --type -t <type> Data type (see above)." << endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
<< endl |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
<< numericInfo(); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
return str.str(); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
/****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
void CommandSoeWrite::execute(const StringVector &args) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
{ |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
90 |
stringstream err; |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
const DataType *dataType = NULL; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
ec_ioctl_slave_soe_write_t ioctl; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
SlaveList slaves; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
size_t memSize; |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
95 |
int driveArgIndex = -1, idnArgIndex = -1, valueArgIndex = -1; |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
|
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
97 |
if (args.size() == 2) { |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
98 |
idnArgIndex = 0; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
99 |
valueArgIndex = 1; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
100 |
} else if (args.size() == 3) { |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
101 |
driveArgIndex = 0; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
102 |
idnArgIndex = 1; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
103 |
valueArgIndex = 2; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
104 |
} else { |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
105 |
err << "'" << getName() << "' takes eiter 2 or 3 arguments!"; |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
throwInvalidUsageException(err); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
|
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
109 |
if (driveArgIndex >= 0) { |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
110 |
stringstream str; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
111 |
unsigned int number; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
112 |
str << args[driveArgIndex]; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
113 |
str |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
114 |
>> resetiosflags(ios::basefield) // guess base from prefix |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
115 |
>> number; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
116 |
if (str.fail() || number > 7) { |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
117 |
err << "Invalid drive number '" << args[driveArgIndex] << "'!"; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
118 |
throwInvalidUsageException(err); |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
119 |
} |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
120 |
ioctl.drive_no = number; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
121 |
} else { |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
122 |
ioctl.drive_no = 0; |
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
123 |
} |
1953
968a531e5a89
Always set drive_no to zero in ethercat tool (TBC).
Florian Pose <fp@igh-essen.com>
parents:
1877
diff
changeset
|
124 |
|
1868
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
125 |
try { |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
126 |
ioctl.idn = parseIdn(args[idnArgIndex]); |
1868
489ea0becd74
Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents:
1867
diff
changeset
|
127 |
} catch (runtime_error &e) { |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
128 |
err << "Invalid IDN '" << args[idnArgIndex] << "': " << e.what(); |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
throwInvalidUsageException(err); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
|
1870
0cee1fb7f0fd
Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
132 |
MasterDevice m(getSingleMasterIndex()); |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
m.open(MasterDevice::ReadWrite); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
slaves = selectedSlaves(m); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
if (slaves.size() != 1) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
throwSingleSlaveRequired(slaves.size()); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
ioctl.slave_position = slaves.front().position; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
if (!getDataType().empty()) { // data type specified |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
if (!(dataType = findDataType(getDataType()))) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
err << "Invalid data type '" << getDataType() << "'!"; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
throwInvalidUsageException(err); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
} else { // no data type specified |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
err << "Please specify a data type."; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
throwInvalidUsageException(err); // FIXME read from stream |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
if (dataType->byteSize) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
memSize = dataType->byteSize; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
} else { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
// guess string type size |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
154 |
memSize = args[valueArgIndex].size() + 1; |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
if (!memSize) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
err << "Empty argument not allowed."; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
throwInvalidUsageException(err); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
|
1867
fec951a0a654
Fixed string argument for soe_write.
Florian Pose <fp@igh-essen.com>
parents:
1837
diff
changeset
|
161 |
ioctl.data = new uint8_t[memSize]; |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
try { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
ioctl.data_size = interpretAsType( |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
165 |
dataType, args[valueArgIndex], ioctl.data, memSize); |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
} catch (SizeException &e) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
delete [] ioctl.data; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
throwCommandException(e.what()); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
} catch (ios::failure &e) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
delete [] ioctl.data; |
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1966
diff
changeset
|
171 |
err << "Invalid value argument '" << args[valueArgIndex] |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
<< "' for type '" << dataType->name << "'!"; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
throwInvalidUsageException(err); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
try { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
m.writeSoe(&ioctl); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
} catch (MasterDeviceSoeException &e) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
delete [] ioctl.data; |
1877
7b77000f9764
Included list of common SoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1872
diff
changeset
|
180 |
err << "SoE write command failed with code " << errorMsg(e.errorCode); |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
throwCommandException(err); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
} catch (MasterDeviceException &e) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
183 |
delete [] ioctl.data; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
184 |
throw e; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
185 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
delete [] ioctl.data; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
/*****************************************************************************/ |