45 string CommandRegRead::helpString() const |
45 string CommandRegRead::helpString() const |
46 { |
46 { |
47 stringstream str; |
47 stringstream str; |
48 |
48 |
49 str << getName() << " [OPTIONS] <OFFSET> [LENGTH]" << endl |
49 str << getName() << " [OPTIONS] <OFFSET> [LENGTH]" << endl |
50 << endl |
50 << endl |
51 << getBriefDescription() << endl |
51 << getBriefDescription() << endl |
52 << endl |
52 << endl |
53 << "This command requires a single slave to be selected." << endl |
53 << "This command requires a single slave to be selected." << endl |
54 << endl |
54 << endl |
55 << "Arguments:" << endl |
55 << "Arguments:" << endl |
56 << " OFFSET is the register address. Must" << endl |
56 << " OFFSET is the register address. Must" << endl |
57 << " be an unsigned 16 bit number." << endl |
57 << " be an unsigned 16 bit number." << endl |
58 << " LENGTH is the number of bytes to read and must also be" << 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 |
59 << " an unsigned 16 bit number. OFFSET plus LENGTH" << endl |
63 << endl |
63 << endl |
64 << "These are the valid data types:" << endl |
64 << "These are the valid data types:" << endl |
65 << " int8, int16, int32, int64, uint8, uint16, uint32," << endl |
65 << " int8, int16, int32, int64, uint8, uint16, uint32," << endl |
66 << " uint64, string, raw." << endl |
66 << " uint64, string, raw." << endl |
67 << endl |
67 << endl |
68 << "Command-specific options:" << endl |
68 << "Command-specific options:" << endl |
69 << " --alias -a <alias>" << endl |
69 << " --alias -a <alias>" << endl |
70 << " --position -p <pos> Slave selection. See the help of" << endl |
70 << " --position -p <pos> Slave selection. See the help of" << endl |
71 << " the 'slaves' command." << endl |
71 << " the 'slaves' command." << endl |
72 << " --type -t <type> Data type (see above)." << endl |
72 << " --type -t <type> Data type (see above)." << endl |
73 << endl |
73 << endl |
74 << numericInfo(); |
74 << numericInfo(); |
75 |
75 |
76 return str.str(); |
76 return str.str(); |
77 } |
77 } |
78 |
78 |
79 /****************************************************************************/ |
79 /****************************************************************************/ |
80 |
80 |
81 void CommandRegRead::execute(MasterDevice &m, const StringVector &args) |
81 void CommandRegRead::execute(MasterDevice &m, const StringVector &args) |
149 } |
149 } |
150 data.slave_position = slaves.front().position; |
150 data.slave_position = slaves.front().position; |
151 |
151 |
152 data.data = new uint8_t[data.length]; |
152 data.data = new uint8_t[data.length]; |
153 |
153 |
154 try { |
154 try { |
155 m.readReg(&data); |
155 m.readReg(&data); |
156 } catch (MasterDeviceException &e) { |
156 } catch (MasterDeviceException &e) { |
157 delete [] data.data; |
157 delete [] data.data; |
158 throw e; |
158 throw e; |
159 } |
159 } |
160 |
160 |
161 cout << setfill('0'); |
161 cout << setfill('0'); |
162 if (!dataType || string(dataType->name) == "string") { |
162 if (!dataType || string(dataType->name) == "string") { |
163 uint16_t i; |
163 uint16_t i; |
164 for (i = 0; i < data.length; i++) { |
164 for (i = 0; i < data.length; i++) { |