author | Florian Pose <fp@igh-essen.com> |
Thu, 19 Mar 2009 08:42:33 +0000 | |
changeset 1372 | 6b45c4c6f56f |
parent 1363 | 11c0b2caa253 |
child 1387 | 57020c731092 |
permissions | -rw-r--r-- |
1200 | 1 |
/***************************************************************************** |
2 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
3 |
* $Id$ |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
4 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
6 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
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:
1200
diff
changeset
|
8 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
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:
1200
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:
1200
diff
changeset
|
11 |
* published by the Free Software Foundation. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
12 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
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:
1200
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:
1200
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:
1200
diff
changeset
|
16 |
* Public License for more details. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
17 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
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:
1200
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:
1200
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:
1200
diff
changeset
|
21 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1200
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:
1200
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:
1200
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1200 | 27 |
* |
28 |
****************************************************************************/ |
|
29 |
||
30 |
#include <iostream> |
|
31 |
#include <iomanip> |
|
32 |
using namespace std; |
|
33 |
||
34 |
#include "CommandPhyRead.h" |
|
35 |
||
36 |
/*****************************************************************************/ |
|
37 |
||
38 |
CommandPhyRead::CommandPhyRead(): |
|
39 |
Command("phy_read", "Output a slave's physical memory contents.") |
|
40 |
{ |
|
41 |
} |
|
42 |
||
43 |
/*****************************************************************************/ |
|
44 |
||
45 |
string CommandPhyRead::helpString() const |
|
46 |
{ |
|
47 |
stringstream str; |
|
48 |
||
49 |
str << getName() << " [OPTIONS] <OFFSET> <LENGTH>" << endl |
|
50 |
<< endl |
|
51 |
<< getBriefDescription() << endl |
|
52 |
<< endl |
|
53 |
<< "This command requires a single slave to be selected." << endl |
|
54 |
<< endl |
|
55 |
<< "Arguments:" << endl |
|
56 |
<< " OFFSET is the physical memory address. Must" << endl |
|
57 |
<< " be an unsigned 16 bit number." << endl |
|
58 |
<< " LENGTH is the number of bytes to read and must also be" << endl |
|
59 |
<< " an unsigned 16 bit number. OFFSET plus LENGTH" << endl |
|
60 |
<< " may not exceed 64k." << endl |
|
61 |
<< endl |
|
62 |
<< "Command-specific options:" << endl |
|
63 |
<< " --alias -a <alias>" << endl |
|
64 |
<< " --position -p <pos> Slave selection. See the help of" << endl |
|
65 |
<< " the 'slaves' command." << endl |
|
66 |
<< endl |
|
67 |
<< numericInfo(); |
|
68 |
||
69 |
return str.str(); |
|
70 |
} |
|
71 |
||
72 |
/****************************************************************************/ |
|
73 |
||
74 |
void CommandPhyRead::execute(MasterDevice &m, const StringVector &args) |
|
75 |
{ |
|
76 |
SlaveList slaves; |
|
77 |
ec_ioctl_slave_phy_t data; |
|
78 |
stringstream strOffset, strLength, err; |
|
79 |
uint16_t i; |
|
80 |
||
81 |
if (args.size() != 2) { |
|
82 |
err << "'" << getName() << "' takes two arguments!"; |
|
83 |
throwInvalidUsageException(err); |
|
84 |
} |
|
85 |
||
86 |
strOffset << args[0]; |
|
87 |
strOffset |
|
88 |
>> resetiosflags(ios::basefield) // guess base from prefix |
|
89 |
>> data.offset; |
|
90 |
if (strOffset.fail()) { |
|
91 |
err << "Invalid offset '" << args[0] << "'!"; |
|
92 |
throwInvalidUsageException(err); |
|
93 |
} |
|
94 |
||
95 |
strLength << args[1]; |
|
96 |
strLength |
|
97 |
>> resetiosflags(ios::basefield) // guess base from prefix |
|
98 |
>> data.length; |
|
99 |
if (strLength.fail()) { |
|
100 |
err << "Invalid length '" << args[1] << "'!"; |
|
101 |
throwInvalidUsageException(err); |
|
102 |
} |
|
103 |
||
104 |
if (!data.length) { |
|
105 |
return; |
|
106 |
} |
|
107 |
||
108 |
if ((uint32_t) data.offset + data.length > 0xffff) { |
|
109 |
err << "Offset and length exceeding 64k!"; |
|
110 |
throwInvalidUsageException(err); |
|
111 |
} |
|
112 |
||
113 |
m.open(MasterDevice::Read); |
|
114 |
slaves = selectedSlaves(m); |
|
115 |
||
116 |
if (slaves.size() != 1) { |
|
117 |
throwSingleSlaveRequired(slaves.size()); |
|
118 |
} |
|
119 |
data.slave_position = slaves.front().position; |
|
120 |
||
121 |
data.data = new uint8_t[data.length]; |
|
122 |
||
123 |
try { |
|
124 |
m.readPhy(&data); |
|
125 |
} catch (MasterDeviceException &e) { |
|
126 |
delete [] data.data; |
|
127 |
throw e; |
|
128 |
} |
|
129 |
||
130 |
for (i = 0; i < data.length; i++) { |
|
131 |
cout << data.data[i]; |
|
132 |
} |
|
133 |
||
134 |
delete [] data.data; |
|
135 |
} |
|
136 |
||
137 |
/*****************************************************************************/ |