11 #include "CommandDownload.h" |
11 #include "CommandDownload.h" |
12 |
12 |
13 /*****************************************************************************/ |
13 /*****************************************************************************/ |
14 |
14 |
15 CommandDownload::CommandDownload(): |
15 CommandDownload::CommandDownload(): |
16 SdoCommand("download", "Write an Sdo entry to a slave.") |
16 SdoCommand("download", "Write an SDO entry to a slave.") |
17 { |
17 { |
18 } |
18 } |
19 |
19 |
20 /*****************************************************************************/ |
20 /*****************************************************************************/ |
21 |
21 |
27 << endl |
27 << endl |
28 << getBriefDescription() << endl |
28 << getBriefDescription() << endl |
29 << endl |
29 << endl |
30 << "This command requires a single slave to be selected." << endl |
30 << "This command requires a single slave to be selected." << endl |
31 << endl |
31 << endl |
32 << "The data type of the Sdo entry is taken from the Sdo" << endl |
32 << "The data type of the SDO entry is taken from the SDO" << endl |
33 << "dictionary by default. It can be overridden with the" << endl |
33 << "dictionary by default. It can be overridden with the" << endl |
34 << "--type option. If the slave does not support the Sdo" << endl |
34 << "--type option. If the slave does not support the SDO" << endl |
35 << "information service or the Sdo is not in the dictionary," << endl |
35 << "information service or the SDO is not in the dictionary," << endl |
36 << "the --type option is mandatory." << endl |
36 << "the --type option is mandatory." << endl |
37 << endl |
37 << endl |
38 << "These are the valid Sdo entry data types:" << endl |
38 << "These are the valid SDO entry data types:" << endl |
39 << " int8, int16, int32, uint8, uint16, uint32, string." << endl |
39 << " int8, int16, int32, uint8, uint16, uint32, string." << endl |
40 << endl |
40 << endl |
41 << "Arguments:" << endl |
41 << "Arguments:" << endl |
42 << " INDEX is the Sdo index and must be an unsigned" << endl |
42 << " INDEX is the SDO index and must be an unsigned" << endl |
43 << " 16 bit number." << endl |
43 << " 16 bit number." << endl |
44 << " SUBINDEX is the Sdo entry subindex and must be an" << endl |
44 << " SUBINDEX is the SDO entry subindex and must be an" << endl |
45 << " unsigned 8 bit number." << endl |
45 << " unsigned 8 bit number." << endl |
46 << " VALUE is the value to download and must correspond" << endl |
46 << " VALUE is the value to download and must correspond" << endl |
47 << " to the Sdo entry datatype (see above)." << endl |
47 << " to the SDO entry datatype (see above)." << endl |
48 << endl |
48 << endl |
49 << "Command-specific options:" << endl |
49 << "Command-specific options:" << endl |
50 << " --alias -a <alias>" << endl |
50 << " --alias -a <alias>" << endl |
51 << " --position -p <pos> Slave selection. See the help of" << endl |
51 << " --position -p <pos> Slave selection. See the help of" << endl |
52 << " the 'slaves' command." << endl |
52 << " the 'slaves' command." << endl |
53 << " --type -t <type> Sdo entry data type (see above)." << endl |
53 << " --type -t <type> SDO entry data type (see above)." << endl |
54 << endl |
54 << endl |
55 << numericInfo(); |
55 << numericInfo(); |
56 |
56 |
57 return str.str(); |
57 return str.str(); |
58 } |
58 } |
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 >> number; |
87 >> number; |
88 if (strSubIndex.fail() || number > 0xff) { |
88 if (strSubIndex.fail() || number > 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 = number; |
92 data.sdo_entry_subindex = number; |
93 |
93 |
94 m.open(MasterDevice::ReadWrite); |
94 m.open(MasterDevice::ReadWrite); |
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 } |
205 |
205 |
206 try { |
206 try { |
207 m.sdoDownload(&data); |
207 m.sdoDownload(&data); |
208 } catch (MasterDeviceSdoAbortException &e) { |
208 } catch (MasterDeviceSdoAbortException &e) { |
209 delete [] data.data; |
209 delete [] data.data; |
210 err << "Sdo transfer aborted with code 0x" |
210 err << "SDO transfer aborted with code 0x" |
211 << setfill('0') << hex << setw(8) << e.abortCode |
211 << setfill('0') << hex << setw(8) << e.abortCode |
212 << ": " << abortText(e.abortCode); |
212 << ": " << abortText(e.abortCode); |
213 throwCommandException(err); |
213 throwCommandException(err); |
214 } catch(MasterDeviceException &e) { |
214 } catch(MasterDeviceException &e) { |
215 delete [] data.data; |
215 delete [] data.data; |