📄 sdo_8cpp-source.html
字号:
<a name="l00232"></a>00232 <span class="comment"></span><a name="l00233"></a>00233 <span class="comment">@param index The index of the object in the object dictionary</span><a name="l00234"></a>00234 <span class="comment">@param sub The sub-index of the object in the object dictionary</span><a name="l00235"></a>00235 <span class="comment">@param data A null terminated string to be downloaded.</span><a name="l00236"></a>00236 <span class="comment">@return A valid CANopen error code.</span><a name="l00237"></a>00237 <span class="comment">*/</span><a name="l00238"></a>00238 <span class="comment">/***************************************************************************/</span><a name="l00239"></a><a class="code" href="classSDO.html#a14">00239</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classSDO.html#a14">SDO::DnldString</a>( <a class="code" href="CML__Utils_8h.html#a7">int16</a> index, <a class="code" href="CML__Utils_8h.html#a7">int16</a> sub, <span class="keywordtype">char</span> *data )<a name="l00240"></a>00240 {<a name="l00241"></a>00241 <span class="comment">// Find the string length</span><a name="l00242"></a>00242 <a class="code" href="CML__Utils_8h.html#a9">int32</a> i;<a name="l00243"></a>00243 <span class="keywordflow">for</span>( i=0; data[i]; i++ );<a name="l00244"></a>00244 <a name="l00245"></a>00245 <span class="keywordflow">return</span> <a class="code" href="classSDO.html#a4">Download</a>( index, sub, i, data );<a name="l00246"></a>00246 }<a name="l00247"></a>00247 <a name="l00248"></a>00248 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00249"></a>00249 <span class="comment">/**</span><a name="l00250"></a>00250 <span class="comment">Upload a visible string type from the SDO. The only difference between</span><a name="l00251"></a>00251 <span class="comment">this function and the lower level Upload function is that this function</span><a name="l00252"></a>00252 <span class="comment">guarantees that there will be a zero character at the end of the string.</span><a name="l00253"></a>00253 <span class="comment"></span><a name="l00254"></a>00254 <span class="comment">@param index The index of the object in the object dictionary</span><a name="l00255"></a>00255 <span class="comment">@param sub The sub-index of the object in the object dictionary</span><a name="l00256"></a>00256 <span class="comment">@param len Holds the size of the buffer on entry, and the</span><a name="l00257"></a>00257 <span class="comment"> length of the downloaded data on return.</span><a name="l00258"></a>00258 <span class="comment">@param data The uploaded string will be returned here.</span><a name="l00259"></a>00259 <span class="comment">@return A valid CANopen error code.</span><a name="l00260"></a>00260 <span class="comment">*/</span><a name="l00261"></a>00261 <span class="comment">/***************************************************************************/</span><a name="l00262"></a><a class="code" href="classSDO.html#a15">00262</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classSDO.html#a15">SDO::UpldString</a>( <a class="code" href="CML__Utils_8h.html#a7">int16</a> index, <a class="code" href="CML__Utils_8h.html#a7">int16</a> sub, <a class="code" href="CML__Utils_8h.html#a9">int32</a> &len, <span class="keywordtype">char</span> *data )<a name="l00263"></a>00263 {<a name="l00264"></a>00264 len--;<a name="l00265"></a>00265 <a name="l00266"></a>00266 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err = <a class="code" href="classSDO.html#a5">Upload</a>( index, sub, len, data );<a name="l00267"></a>00267 <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> err;<a name="l00268"></a>00268 <a name="l00269"></a>00269 data[len] = 0;<a name="l00270"></a>00270 <span class="keywordflow">return</span> 0;<a name="l00271"></a>00271 }<a name="l00272"></a>00272 <a name="l00273"></a>00273 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00274"></a>00274 <span class="comment">/**</span><a name="l00275"></a>00275 <span class="comment">Download data using this SDO. The passed array of data is downloaded to the</span><a name="l00276"></a>00276 <span class="comment">object dictionary of a node on the CANopen network using this SDO.</span><a name="l00277"></a>00277 <span class="comment">@param index The index of the object to be downloaded.</span><a name="l00278"></a>00278 <span class="comment">@param sub The sub-index of the object to be downloaded.</span><a name="l00279"></a>00279 <span class="comment">@param size The number of bytes of data to be downloaded</span><a name="l00280"></a>00280 <span class="comment">@param data A character array holding the data to be downloaded.</span><a name="l00281"></a>00281 <span class="comment">@return A valid CANopen error object.</span><a name="l00282"></a>00282 <span class="comment">*/</span><a name="l00283"></a>00283 <span class="comment">/***************************************************************************/</span><a name="l00284"></a><a class="code" href="classSDO.html#a4">00284</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classSDO.html#a4">SDO::Download</a>( <a class="code" href="CML__Utils_8h.html#a7">int16</a> index, <a class="code" href="CML__Utils_8h.html#a7">int16</a> sub, <a class="code" href="CML__Utils_8h.html#a9">int32</a> size, <a class="code" href="CML__Utils_8h.html#a2">byte</a> *data )<a name="l00285"></a>00285 {<a name="l00286"></a>00286 <a class="code" href="structCanFrame.html">CanFrame</a> frame;<a name="l00287"></a>00287 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err;<a name="l00288"></a>00288 <a name="l00289"></a>00289 <span class="comment">// Use a block download if it makes sense to do so</span><a name="l00290"></a>00290 <span class="keywordflow">if</span>( <a class="code" href="classSDO.html#o1">blkDnldOK</a> && size >= <a class="code" href="CML__SDO_8h.html#a29">SDO_BLK_DNLD_THRESHOLD</a> )<a name="l00291"></a>00291 <span class="keywordflow">return</span> <a class="code" href="classSDO.html#a6">BlockDnld</a>( index, sub, size, data );<a name="l00292"></a>00292 <a name="l00293"></a>00293 <span class="comment">// Make sure the SDO has been initialized</span><a name="l00294"></a>00294 <span class="keywordflow">if</span>( !<a class="code" href="classReceiver.html#p0">co</a> ) <span class="keywordflow">return</span> &<a class="code" href="classCanOpenError.html#s8">CanOpenError::NotInitialized</a>;<a name="l00295"></a>00295 <a name="l00296"></a>00296 mutex.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00297"></a>00297 <a name="l00298"></a>00298 <span class="keywordflow">if</span>( state != <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a> )<a name="l00299"></a>00299 err = &<a class="code" href="classCanOpenError.html#s2">CanOpenError::SDO_Busy</a>;<a name="l00300"></a>00300 <a name="l00301"></a>00301 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( size <= 0 )<a name="l00302"></a>00302 err = &<a class="code" href="classCanOpenError.html#s1">CanOpenError::BadParam</a>;<a name="l00303"></a>00303 <a name="l00304"></a>00304 <span class="keywordflow">else</span><a name="l00305"></a>00305 {<a name="l00306"></a>00306 <span class="comment">// send an "Initiate SDO download" message.</span><a name="l00307"></a>00307 frame.<a class="code" href="structCanFrame.html#o1">id</a> = xmitID;<a name="l00308"></a>00308 frame.<a class="code" href="structCanFrame.html#o0">type</a> = <a class="code" href="CML__Can_8h.html#a3a0">CAN_FRAME_DATA</a>;<a name="l00309"></a>00309 frame.<a class="code" href="structCanFrame.html#o2">length</a> = 8;<a name="l00310"></a>00310 <a name="l00311"></a>00311 <span class="comment">// Copy the object multiplexor to the frame</span><a name="l00312"></a>00312 <span class="comment">// and also make a local copy.</span><a name="l00313"></a>00313 frame.<a class="code" href="structCanFrame.html#o3">data</a>[1] = mplex[0] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(index);<a name="l00314"></a>00314 frame.<a class="code" href="structCanFrame.html#o3">data</a>[2] = mplex[1] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(index>>8);<a name="l00315"></a>00315 frame.<a class="code" href="structCanFrame.html#o3">data</a>[3] = mplex[2] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(sub);<a name="l00316"></a>00316 <a name="l00317"></a>00317 <span class="comment">// If the data size is <= 4 bytes, then send an expedited download</span><a name="l00318"></a>00318 <span class="keywordflow">if</span>( size <= 4 )<a name="l00319"></a>00319 {<a name="l00320"></a>00320 frame.<a class="code" href="structCanFrame.html#o3">data</a>[0] = 0x23 | ((4-size)<<2);<a name="l00321"></a>00321 <a name="l00322"></a>00322 <a class="code" href="CML__Utils_8h.html#a9">int32</a> i;<a name="l00323"></a>00323 <span class="keywordflow">for</span>( i=0; i<size; i++ ) frame.<a class="code" href="structCanFrame.html#o3">data</a>[i+4] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(data[i]);<a name="l00324"></a>00324 <span class="keywordflow">for</span>( ; i<4; i++ ) frame.<a class="code" href="structCanFrame.html#o3">data</a>[i+4] = 0;<a name="l00325"></a>00325 <a name="l00326"></a>00326 remain = 0;<a name="l00327"></a>00327 }<a name="l00328"></a>00328 <a name="l00329"></a>00329 <span class="comment">// Otherwise, send a normal init</span><a name="l00330"></a>00330 <span class="keywordflow">else</span><a name="l00331"></a>00331 {<a name="l00332"></a>00332 frame.<a class="code" href="structCanFrame.html#o3">data</a>[0] = 0x21;<a name="l00333"></a>00333 frame.<a class="code" href="structCanFrame.html#o3">data</a>[4] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(size);<a name="l00334"></a>00334 frame.<a class="code" href="structCanFrame.html#o3">data</a>[5] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(size>>8);<a name="l00335"></a>00335 frame.<a class="code" href="structCanFrame.html#o3">data</a>[6] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(size>>16);<a name="l00336"></a>00336 frame.<a class="code" href="structCanFrame.html#o3">data</a>[7] = <a class="code" href="CML__Utils_8h.html#a0">ByteCast</a>(size>>24);<a name="l00337"></a>00337 <a name="l00338"></a>00338 remain = size;<a name="l00339"></a>00339 }<a name="l00340"></a>00340 <a name="l00341"></a>00341 <span class="comment">// Keep a pointer to the data buffer and reset the toggle bit</span><a name="l00342"></a>00342 dataPtr = data;<a name="l00343"></a>00343 toggle = 0;<a name="l00344"></a>00344 <a name="l00345"></a>00345 state = <a class="code" href="SDO_8cpp.html#a2">SDO_STATE_SENT_DNLD_INIT</a>;<a name="l00346"></a>00346 err = <a class="code" href="classReceiver.html#p0">co</a>-><a class="code" href="classCanOpen.html#a5">Xmit</a>( frame, timeout );<a name="l00347"></a>00347 <span class="keywordflow">if</span>( err ) state = <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a>;<a name="l00348"></a>00348 }<a name="l00349"></a>00349 <a name="l00350"></a>00350 <span class="comment">// If the download was started successfully, sit waiting for the</span><a name="l00351"></a>00351 <span class="comment">// state to change to one that indicates success or failure.</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -