12 #include "byteorder.h" |
12 #include "byteorder.h" |
13 |
13 |
14 /*****************************************************************************/ |
14 /*****************************************************************************/ |
15 |
15 |
16 CommandDownload::CommandDownload(): |
16 CommandDownload::CommandDownload(): |
17 SdoCommand("download", "Write an Sdo entry to a slave.") |
17 SdoCommand("download", "Write an SDO entry to 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 << " VALUE is the value to download and must correspond" << endl |
47 << " VALUE is the value to download and must correspond" << endl |
48 << " to the Sdo entry datatype (see above)." << endl |
48 << " to the SDO entry datatype (see above)." << endl |
49 << endl |
49 << endl |
50 << "Command-specific options:" << endl |
50 << "Command-specific options:" << endl |
51 << " --alias -a <alias>" << endl |
51 << " --alias -a <alias>" << endl |
52 << " --position -p <pos> Slave selection. See the help of" << endl |
52 << " --position -p <pos> Slave selection. See the help of" << endl |
53 << " the 'slaves' command." << endl |
53 << " the 'slaves' command." << endl |
54 << " --type -t <type> Sdo entry data type (see above)." << endl |
54 << " --type -t <type> SDO entry data type (see above)." << endl |
55 << endl |
55 << endl |
56 << numericInfo(); |
56 << numericInfo(); |
57 |
57 |
58 return str.str(); |
58 return str.str(); |
59 } |
59 } |
76 strIndex << args[0]; |
76 strIndex << args[0]; |
77 strIndex |
77 strIndex |
78 >> resetiosflags(ios::basefield) // guess base from prefix |
78 >> resetiosflags(ios::basefield) // guess base from prefix |
79 >> data.sdo_index; |
79 >> data.sdo_index; |
80 if (strIndex.fail()) { |
80 if (strIndex.fail()) { |
81 err << "Invalid Sdo index '" << args[0] << "'!"; |
81 err << "Invalid SDO index '" << args[0] << "'!"; |
82 throwInvalidUsageException(err); |
82 throwInvalidUsageException(err); |
83 } |
83 } |
84 |
84 |
85 strSubIndex << args[1]; |
85 strSubIndex << args[1]; |
86 strSubIndex |
86 strSubIndex |
87 >> resetiosflags(ios::basefield) // guess base from prefix |
87 >> resetiosflags(ios::basefield) // guess base from prefix |
88 >> number; |
88 >> number; |
89 if (strSubIndex.fail() || number > 0xff) { |
89 if (strSubIndex.fail() || number > 0xff) { |
90 err << "Invalid Sdo subindex '" << args[1] << "'!"; |
90 err << "Invalid SDO subindex '" << args[1] << "'!"; |
91 throwInvalidUsageException(err); |
91 throwInvalidUsageException(err); |
92 } |
92 } |
93 data.sdo_entry_subindex = number; |
93 data.sdo_entry_subindex = number; |
94 |
94 |
95 m.open(MasterDevice::ReadWrite); |
95 m.open(MasterDevice::ReadWrite); |
109 |
109 |
110 try { |
110 try { |
111 m.getSdoEntry(&entry, data.slave_position, |
111 m.getSdoEntry(&entry, data.slave_position, |
112 data.sdo_index, data.sdo_entry_subindex); |
112 data.sdo_index, data.sdo_entry_subindex); |
113 } catch (MasterDeviceException &e) { |
113 } catch (MasterDeviceException &e) { |
114 err << "Failed to determine Sdo entry data type. " |
114 err << "Failed to determine SDO entry data type. " |
115 << "Please specify --type."; |
115 << "Please specify --type."; |
116 throwCommandException(err); |
116 throwCommandException(err); |
117 } |
117 } |
118 if (!(dataType = findDataType(entry.data_type))) { |
118 if (!(dataType = findDataType(entry.data_type))) { |
119 err << "Pdo entry has unknown data type 0x" |
119 err << "PDO entry has unknown data type 0x" |
120 << hex << setfill('0') << setw(4) << entry.data_type << "!" |
120 << hex << setfill('0') << setw(4) << entry.data_type << "!" |
121 << " Please specify --type."; |
121 << " Please specify --type."; |
122 throwCommandException(err); |
122 throwCommandException(err); |
123 } |
123 } |
124 } |
124 } |
206 |
206 |
207 try { |
207 try { |
208 m.sdoDownload(&data); |
208 m.sdoDownload(&data); |
209 } catch (MasterDeviceSdoAbortException &e) { |
209 } catch (MasterDeviceSdoAbortException &e) { |
210 delete [] data.data; |
210 delete [] data.data; |
211 err << "Sdo transfer aborted with code 0x" |
211 err << "SDO transfer aborted with code 0x" |
212 << setfill('0') << hex << setw(8) << e.abortCode |
212 << setfill('0') << hex << setw(8) << e.abortCode |
213 << ": " << abortText(e.abortCode); |
213 << ": " << abortText(e.abortCode); |
214 throwCommandException(err); |
214 throwCommandException(err); |
215 } catch(MasterDeviceException &e) { |
215 } catch(MasterDeviceException &e) { |
216 delete [] data.data; |
216 delete [] data.data; |