35 #include "MasterDevice.h" |
35 #include "MasterDevice.h" |
36 |
36 |
37 /*****************************************************************************/ |
37 /*****************************************************************************/ |
38 |
38 |
39 CommandSoeRead::CommandSoeRead(): |
39 CommandSoeRead::CommandSoeRead(): |
40 Command("soe_read", "Read an SoE IDN from a slave.") |
40 SoeCommand("soe_read", "Read an SoE IDN from a slave.") |
41 { |
41 { |
42 } |
42 } |
43 |
43 |
44 /*****************************************************************************/ |
44 /*****************************************************************************/ |
45 |
45 |
46 string CommandSoeRead::helpString() const |
46 string CommandSoeRead::helpString() const |
47 { |
47 { |
48 stringstream str; |
48 stringstream str; |
49 |
49 |
50 str << getName() << " [OPTIONS] <INDEX> <SUBINDEX>" << endl |
50 str << getName() << " [OPTIONS] <IDN>" << endl |
51 << endl |
51 << endl |
52 << getBriefDescription() << endl |
52 << getBriefDescription() << endl |
53 << endl |
53 << endl |
54 << "This command requires a single slave to be selected." << endl |
54 << "This command requires a single slave to be selected." << endl |
55 << endl |
55 << endl |
56 << "Arguments:" << endl |
56 << "Arguments:" << endl |
57 << " IDN is the IDN and must be an unsigned" << endl |
57 << " IDN is the IDN and must be either an unsigned" << endl |
58 << " 16 bit number." << endl |
58 << " 16 bit number acc. to IEC 61800-7-204:" << endl |
|
59 << " Bit 15: (0) Standard data, (1) Product data" << endl |
|
60 << " Bit 14 - 12: Parameter set (0 - 7)" << endl |
|
61 << " Bit 11 - 0: Data block number" << endl |
|
62 << " or a string like 'P-0-150'." << endl |
|
63 << endl |
|
64 << typeInfo() |
59 << endl |
65 << endl |
60 << "Command-specific options:" << endl |
66 << "Command-specific options:" << endl |
61 << " --alias -a <alias>" << endl |
67 << " --alias -a <alias>" << endl |
62 << " --position -p <pos> Slave selection. See the help of" << endl |
68 << " --position -p <pos> Slave selection. See the help of" << endl |
63 << " the 'slaves' command." << endl |
69 << " the 'slaves' command." << endl |
|
70 << " --type -t <type> Data type (see above)." << endl |
64 << endl |
71 << endl |
65 << numericInfo(); |
72 << numericInfo(); |
66 |
73 |
67 return str.str(); |
74 return str.str(); |
68 } |
75 } |
70 /****************************************************************************/ |
77 /****************************************************************************/ |
71 |
78 |
72 void CommandSoeRead::execute(const StringVector &args) |
79 void CommandSoeRead::execute(const StringVector &args) |
73 { |
80 { |
74 SlaveList slaves; |
81 SlaveList slaves; |
75 stringstream err, strIdn; |
82 stringstream err; |
76 const DataType *dataType = NULL; |
83 const DataType *dataType = NULL; |
77 ec_ioctl_slave_soe_read_t ioctl; |
84 ec_ioctl_slave_soe_read_t ioctl; |
78 |
85 |
79 if (args.size() != 1) { |
86 if (args.size() != 1) { |
80 err << "'" << getName() << "' takes one argument!"; |
87 err << "'" << getName() << "' takes one argument!"; |
81 throwInvalidUsageException(err); |
88 throwInvalidUsageException(err); |
82 } |
89 } |
83 |
90 |
84 strIdn << args[0]; |
91 try { |
85 strIdn |
92 ioctl.idn = parseIdn(args[0]); |
86 >> resetiosflags(ios::basefield) // guess base from prefix |
93 } catch (runtime_error &e) { |
87 >> ioctl.idn; |
94 err << "Invalid IDN '" << args[0] << "': " << e.what(); |
88 if (strIdn.fail()) { |
|
89 err << "Invalid IDN '" << args[0] << "'!"; |
|
90 throwInvalidUsageException(err); |
95 throwInvalidUsageException(err); |
91 } |
96 } |
92 |
97 |
93 if (getMasterIndices().size() != 1) { |
98 if (getMasterIndices().size() != 1) { |
94 err << getName() << " requires to select a single master!"; |
99 err << getName() << " requires to select a single master!"; |