1200
|
1 |
/*****************************************************************************
|
|
2 |
*
|
|
3 |
* $Id$
|
|
4 |
*
|
|
5 |
****************************************************************************/
|
|
6 |
|
|
7 |
#include <iostream>
|
|
8 |
#include <iomanip>
|
|
9 |
using namespace std;
|
|
10 |
|
|
11 |
#include "CommandPhyRead.h"
|
|
12 |
|
|
13 |
/*****************************************************************************/
|
|
14 |
|
|
15 |
CommandPhyRead::CommandPhyRead():
|
|
16 |
Command("phy_read", "Output a slave's physical memory contents.")
|
|
17 |
{
|
|
18 |
}
|
|
19 |
|
|
20 |
/*****************************************************************************/
|
|
21 |
|
|
22 |
string CommandPhyRead::helpString() const
|
|
23 |
{
|
|
24 |
stringstream str;
|
|
25 |
|
|
26 |
str << getName() << " [OPTIONS] <OFFSET> <LENGTH>" << endl
|
|
27 |
<< endl
|
|
28 |
<< getBriefDescription() << endl
|
|
29 |
<< endl
|
|
30 |
<< "This command requires a single slave to be selected." << endl
|
|
31 |
<< endl
|
|
32 |
<< "Arguments:" << endl
|
|
33 |
<< " OFFSET is the physical memory address. Must" << endl
|
|
34 |
<< " be an unsigned 16 bit number." << endl
|
|
35 |
<< " LENGTH is the number of bytes to read and must also be" << endl
|
|
36 |
<< " an unsigned 16 bit number. OFFSET plus LENGTH" << endl
|
|
37 |
<< " may not exceed 64k." << endl
|
|
38 |
<< endl
|
|
39 |
<< "Command-specific options:" << endl
|
|
40 |
<< " --alias -a <alias>" << endl
|
|
41 |
<< " --position -p <pos> Slave selection. See the help of" << endl
|
|
42 |
<< " the 'slaves' command." << endl
|
|
43 |
<< endl
|
|
44 |
<< numericInfo();
|
|
45 |
|
|
46 |
return str.str();
|
|
47 |
}
|
|
48 |
|
|
49 |
/****************************************************************************/
|
|
50 |
|
|
51 |
void CommandPhyRead::execute(MasterDevice &m, const StringVector &args)
|
|
52 |
{
|
|
53 |
SlaveList slaves;
|
|
54 |
ec_ioctl_slave_phy_t data;
|
|
55 |
stringstream strOffset, strLength, err;
|
|
56 |
uint16_t i;
|
|
57 |
|
|
58 |
if (args.size() != 2) {
|
|
59 |
err << "'" << getName() << "' takes two arguments!";
|
|
60 |
throwInvalidUsageException(err);
|
|
61 |
}
|
|
62 |
|
|
63 |
strOffset << args[0];
|
|
64 |
strOffset
|
|
65 |
>> resetiosflags(ios::basefield) // guess base from prefix
|
|
66 |
>> data.offset;
|
|
67 |
if (strOffset.fail()) {
|
|
68 |
err << "Invalid offset '" << args[0] << "'!";
|
|
69 |
throwInvalidUsageException(err);
|
|
70 |
}
|
|
71 |
|
|
72 |
strLength << args[1];
|
|
73 |
strLength
|
|
74 |
>> resetiosflags(ios::basefield) // guess base from prefix
|
|
75 |
>> data.length;
|
|
76 |
if (strLength.fail()) {
|
|
77 |
err << "Invalid length '" << args[1] << "'!";
|
|
78 |
throwInvalidUsageException(err);
|
|
79 |
}
|
|
80 |
|
|
81 |
if (!data.length) {
|
|
82 |
return;
|
|
83 |
}
|
|
84 |
|
|
85 |
if ((uint32_t) data.offset + data.length > 0xffff) {
|
|
86 |
err << "Offset and length exceeding 64k!";
|
|
87 |
throwInvalidUsageException(err);
|
|
88 |
}
|
|
89 |
|
|
90 |
m.open(MasterDevice::Read);
|
|
91 |
slaves = selectedSlaves(m);
|
|
92 |
|
|
93 |
if (slaves.size() != 1) {
|
|
94 |
throwSingleSlaveRequired(slaves.size());
|
|
95 |
}
|
|
96 |
data.slave_position = slaves.front().position;
|
|
97 |
|
|
98 |
data.data = new uint8_t[data.length];
|
|
99 |
|
|
100 |
try {
|
|
101 |
m.readPhy(&data);
|
|
102 |
} catch (MasterDeviceException &e) {
|
|
103 |
delete [] data.data;
|
|
104 |
throw e;
|
|
105 |
}
|
|
106 |
|
|
107 |
for (i = 0; i < data.length; i++) {
|
|
108 |
cout << data.data[i];
|
|
109 |
}
|
|
110 |
|
|
111 |
delete [] data.data;
|
|
112 |
}
|
|
113 |
|
|
114 |
/*****************************************************************************/
|