12 #include "byteorder.h" |
12 #include "byteorder.h" |
13 |
13 |
14 /*****************************************************************************/ |
14 /*****************************************************************************/ |
15 |
15 |
16 CommandUpload::CommandUpload(): |
16 CommandUpload::CommandUpload(): |
17 SdoCommand("upload", "Read an Sdo entry from a slave.") |
17 SdoCommand("upload", "Read an SDO entry from a slave.") |
18 { |
18 { |
19 } |
19 } |
20 |
20 |
21 /*****************************************************************************/ |
21 /*****************************************************************************/ |
22 |
22 |
28 << endl |
28 << endl |
29 << getBriefDescription() << endl |
29 << getBriefDescription() << endl |
30 << endl |
30 << endl |
31 << "This command requires a single slave to be selected." << endl |
31 << "This command requires a single slave to be selected." << endl |
32 << endl |
32 << endl |
33 << "The data type of the Sdo entry is taken from the Sdo" << endl |
33 << "The data type of the SDO entry is taken from the SDO" << endl |
34 << "dictionary by default. It can be overridden with the" << endl |
34 << "dictionary by default. It can be overridden with the" << endl |
35 << "--type option. If the slave does not support the Sdo" << endl |
35 << "--type option. If the slave does not support the SDO" << endl |
36 << "information service or the Sdo is not in the dictionary," << endl |
36 << "information service or the SDO is not in the dictionary," << endl |
37 << "the --type option is mandatory." << endl |
37 << "the --type option is mandatory." << endl |
38 << endl |
38 << endl |
39 << "These are the valid Sdo entry data types:" << endl |
39 << "These are the valid SDO entry data types:" << endl |
40 << " int8, int16, int32, uint8, uint16, uint32, string." << endl |
40 << " int8, int16, int32, uint8, uint16, uint32, string." << endl |
41 << endl |
41 << endl |
42 << "Arguments:" << endl |
42 << "Arguments:" << endl |
43 << " INDEX is the Sdo index and must be an unsigned" << endl |
43 << " INDEX is the SDO index and must be an unsigned" << endl |
44 << " 16 bit number." << endl |
44 << " 16 bit number." << endl |
45 << " SUBINDEX is the Sdo entry subindex and must be an" << endl |
45 << " SUBINDEX is the SDO entry subindex and must be an" << endl |
46 << " unsigned 8 bit number." << endl |
46 << " unsigned 8 bit number." << endl |
47 << endl |
47 << endl |
48 << "Command-specific options:" << endl |
48 << "Command-specific options:" << endl |
49 << " --alias -a <alias>" << endl |
49 << " --alias -a <alias>" << endl |
50 << " --position -p <pos> Slave selection. See the help of" << endl |
50 << " --position -p <pos> Slave selection. See the help of" << endl |
51 << " the 'slaves' command." << endl |
51 << " the 'slaves' command." << endl |
52 << " --type -t <type> Sdo entry data type (see above)." << endl |
52 << " --type -t <type> SDO entry data type (see above)." << endl |
53 << endl |
53 << endl |
54 << numericInfo(); |
54 << numericInfo(); |
55 |
55 |
56 return str.str(); |
56 return str.str(); |
57 } |
57 } |
75 strIndex << args[0]; |
75 strIndex << args[0]; |
76 strIndex |
76 strIndex |
77 >> resetiosflags(ios::basefield) // guess base from prefix |
77 >> resetiosflags(ios::basefield) // guess base from prefix |
78 >> data.sdo_index; |
78 >> data.sdo_index; |
79 if (strIndex.fail()) { |
79 if (strIndex.fail()) { |
80 err << "Invalid Sdo index '" << args[0] << "'!"; |
80 err << "Invalid SDO index '" << args[0] << "'!"; |
81 throwInvalidUsageException(err); |
81 throwInvalidUsageException(err); |
82 } |
82 } |
83 |
83 |
84 strSubIndex << args[1]; |
84 strSubIndex << args[1]; |
85 strSubIndex |
85 strSubIndex |
86 >> resetiosflags(ios::basefield) // guess base from prefix |
86 >> resetiosflags(ios::basefield) // guess base from prefix |
87 >> uval; |
87 >> uval; |
88 if (strSubIndex.fail() || uval > 0xff) { |
88 if (strSubIndex.fail() || uval > 0xff) { |
89 err << "Invalid Sdo subindex '" << args[1] << "'!"; |
89 err << "Invalid SDO subindex '" << args[1] << "'!"; |
90 throwInvalidUsageException(err); |
90 throwInvalidUsageException(err); |
91 } |
91 } |
92 data.sdo_entry_subindex = uval; |
92 data.sdo_entry_subindex = uval; |
93 |
93 |
94 m.open(MasterDevice::Read); |
94 m.open(MasterDevice::Read); |
108 |
108 |
109 try { |
109 try { |
110 m.getSdoEntry(&entry, data.slave_position, |
110 m.getSdoEntry(&entry, data.slave_position, |
111 data.sdo_index, data.sdo_entry_subindex); |
111 data.sdo_index, data.sdo_entry_subindex); |
112 } catch (MasterDeviceException &e) { |
112 } catch (MasterDeviceException &e) { |
113 err << "Failed to determine Sdo entry data type. " |
113 err << "Failed to determine SDO entry data type. " |
114 << "Please specify --type."; |
114 << "Please specify --type."; |
115 throwCommandException(err); |
115 throwCommandException(err); |
116 } |
116 } |
117 if (!(dataType = findDataType(entry.data_type))) { |
117 if (!(dataType = findDataType(entry.data_type))) { |
118 err << "Pdo entry has unknown data type 0x" |
118 err << "PDO entry has unknown data type 0x" |
119 << hex << setfill('0') << setw(4) << entry.data_type << "!" |
119 << hex << setfill('0') << setw(4) << entry.data_type << "!" |
120 << " Please specify --type."; |
120 << " Please specify --type."; |
121 throwCommandException(err); |
121 throwCommandException(err); |
122 } |
122 } |
123 } |
123 } |
132 |
132 |
133 try { |
133 try { |
134 m.sdoUpload(&data); |
134 m.sdoUpload(&data); |
135 } catch (MasterDeviceSdoAbortException &e) { |
135 } catch (MasterDeviceSdoAbortException &e) { |
136 delete [] data.target; |
136 delete [] data.target; |
137 err << "Sdo transfer aborted with code 0x" |
137 err << "SDO transfer aborted with code 0x" |
138 << setfill('0') << hex << setw(8) << e.abortCode |
138 << setfill('0') << hex << setw(8) << e.abortCode |
139 << ": " << abortText(e.abortCode); |
139 << ": " << abortText(e.abortCode); |
140 throwCommandException(err); |
140 throwCommandException(err); |
141 } catch (MasterDeviceException &e) { |
141 } catch (MasterDeviceException &e) { |
142 delete [] data.target; |
142 delete [] data.target; |