1142
|
1 |
/*****************************************************************************
|
|
2 |
*
|
|
3 |
* $Id$
|
|
4 |
*
|
|
5 |
****************************************************************************/
|
|
6 |
|
|
7 |
#include <iostream>
|
|
8 |
using namespace std;
|
|
9 |
|
|
10 |
#include "CommandData.h"
|
|
11 |
|
|
12 |
/*****************************************************************************/
|
|
13 |
|
|
14 |
CommandData::CommandData():
|
|
15 |
Command("data", "Output binary domain process data.")
|
|
16 |
{
|
|
17 |
}
|
|
18 |
|
|
19 |
/*****************************************************************************/
|
|
20 |
|
|
21 |
string CommandData::helpString() const
|
|
22 |
{
|
|
23 |
stringstream str;
|
|
24 |
|
|
25 |
str << getName() << " [OPTIONS]" << endl
|
|
26 |
<< endl
|
|
27 |
<< getBriefDescription() << endl
|
|
28 |
<< endl
|
|
29 |
<< "Command-specific options:" << endl
|
|
30 |
<< " --domain -d <index> Positive numerical domain index, or" << endl
|
|
31 |
<< " 'all' for all domains (default). In" << endl
|
|
32 |
<< " this case, data of all domains are" << endl
|
|
33 |
<< " concatenated." << endl
|
|
34 |
<< endl
|
|
35 |
<< numericInfo();
|
|
36 |
|
|
37 |
return str.str();
|
|
38 |
}
|
|
39 |
|
|
40 |
/****************************************************************************/
|
|
41 |
|
|
42 |
void CommandData::execute(MasterDevice &m, const StringVector &args)
|
|
43 |
{
|
|
44 |
m.open(MasterDevice::Read);
|
|
45 |
|
|
46 |
if (domainIndex == -1) {
|
|
47 |
unsigned int i;
|
|
48 |
ec_ioctl_master_t master;
|
|
49 |
|
|
50 |
m.getMaster(&master);
|
|
51 |
|
|
52 |
for (i = 0; i < master.domain_count; i++) {
|
|
53 |
outputDomainData(m, i);
|
|
54 |
}
|
|
55 |
} else {
|
|
56 |
outputDomainData(m, domainIndex);
|
|
57 |
}
|
|
58 |
}
|
|
59 |
|
|
60 |
/****************************************************************************/
|
|
61 |
|
|
62 |
void CommandData::outputDomainData(MasterDevice &m, unsigned int domainIndex)
|
|
63 |
{
|
|
64 |
ec_ioctl_domain_t domain;
|
|
65 |
ec_ioctl_domain_data_t data;
|
|
66 |
unsigned char *processData;
|
|
67 |
unsigned int i;
|
|
68 |
|
|
69 |
m.getDomain(&domain, domainIndex);
|
|
70 |
|
|
71 |
if (!domain.data_size)
|
|
72 |
return;
|
|
73 |
|
|
74 |
processData = new unsigned char[domain.data_size];
|
|
75 |
|
|
76 |
try {
|
|
77 |
m.getData(&data, domainIndex, domain.data_size, processData);
|
|
78 |
} catch (MasterDeviceException &e) {
|
|
79 |
delete [] processData;
|
|
80 |
throw e;
|
|
81 |
}
|
|
82 |
|
|
83 |
for (i = 0; i < data.data_size; i++)
|
|
84 |
cout << processData[i];
|
|
85 |
cout.flush();
|
|
86 |
|
|
87 |
delete [] processData;
|
|
88 |
}
|
|
89 |
|
|
90 |
/****************************************************************************/
|