⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdo_8cpp-source.html

📁 美国COPLEY驱动器,程序开发工具之一.
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00352"></a>00352    <span class="keywordflow">if</span>( !err ) err = WaitForTransfer( size );<a name="l00353"></a>00353 <a name="l00354"></a>00354    mutex.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00355"></a>00355    <span class="keywordflow">return</span> err;<a name="l00356"></a>00356 }<a name="l00357"></a>00357 <a name="l00358"></a>00358 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00359"></a>00359 <span class="comment">/**</span><a name="l00360"></a>00360 <span class="comment">Upload data using this SDO.  The value of the object is uploaded from the</span><a name="l00361"></a>00361 <span class="comment">object dictionary of a node on the CANopen network using this SDO.  The </span><a name="l00362"></a>00362 <span class="comment">results of the upload are stored in the passed buffer.</span><a name="l00363"></a>00363 <span class="comment"></span><a name="l00364"></a>00364 <span class="comment">@param index The index of the object to be uploaded.</span><a name="l00365"></a>00365 <span class="comment">@param sub The sub-index of the object to be uploaded.</span><a name="l00366"></a>00366 <span class="comment">@param size On entry, this gives the maximum number of bytes of data to </span><a name="l00367"></a>00367 <span class="comment">       be uploaded.  On successful return, it gives the actual number of</span><a name="l00368"></a>00368 <span class="comment">       bytes received.</span><a name="l00369"></a>00369 <span class="comment">@param data A character array which will store the uploaded data.</span><a name="l00370"></a>00370 <span class="comment">@return A valid CANopen error object.</span><a name="l00371"></a>00371 <span class="comment">*/</span><a name="l00372"></a>00372 <span class="comment">/***************************************************************************/</span><a name="l00373"></a><a class="code" href="classSDO.html#a5">00373</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classSDO.html#a5">SDO::Upload</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> &amp;size, <a class="code" href="CML__Utils_8h.html#a2">byte</a> *data )<a name="l00374"></a>00374 {<a name="l00375"></a>00375    <a class="code" href="structCanFrame.html">CanFrame</a> frame;<a name="l00376"></a>00376    <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err;<a name="l00377"></a>00377 <a name="l00378"></a>00378    <span class="comment">// Use a block upload if it makes sense to do so</span><a name="l00379"></a>00379    <span class="keywordflow">if</span>( <a class="code" href="classSDO.html#o0">blkUpldOK</a> &amp;&amp; size &gt;= <a class="code" href="CML__SDO_8h.html#a30">SDO_BLK_UPLD_THRESHOLD</a> )<a name="l00380"></a>00380       <span class="keywordflow">return</span> <a class="code" href="classSDO.html#a7">BlockUpld</a>( index, sub, size, data );<a name="l00381"></a>00381 <a name="l00382"></a>00382    <span class="comment">// Make sure the SDO has been initialized</span><a name="l00383"></a>00383    <span class="keywordflow">if</span>( !<a class="code" href="classReceiver.html#p0">co</a> ) <span class="keywordflow">return</span> &amp;<a class="code" href="classCanOpenError.html#s8">CanOpenError::NotInitialized</a>;<a name="l00384"></a>00384 <a name="l00385"></a>00385    mutex.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00386"></a>00386 <a name="l00387"></a>00387    <span class="keywordflow">if</span>( state != <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a> )<a name="l00388"></a>00388       err = &amp;<a class="code" href="classCanOpenError.html#s2">CanOpenError::SDO_Busy</a>;<a name="l00389"></a>00389 <a name="l00390"></a>00390    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( size &lt;= 0 )<a name="l00391"></a>00391       err = &amp;<a class="code" href="classCanOpenError.html#s1">CanOpenError::BadParam</a>;<a name="l00392"></a>00392 <a name="l00393"></a>00393    <span class="keywordflow">else</span><a name="l00394"></a>00394    {<a name="l00395"></a>00395       <span class="comment">// send an "Initiate SDO upload" message.</span><a name="l00396"></a>00396       frame.<a class="code" href="structCanFrame.html#o1">id</a> = xmitID;<a name="l00397"></a>00397       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="l00398"></a>00398       frame.<a class="code" href="structCanFrame.html#o2">length</a> = 8;<a name="l00399"></a>00399 <a name="l00400"></a>00400       frame.<a class="code" href="structCanFrame.html#o3">data</a>[0] = 0x40;<a name="l00401"></a>00401 <a name="l00402"></a>00402       <span class="comment">// Copy the object multiplexor to the frame</span><a name="l00403"></a>00403       <span class="comment">// and also make a local copy.</span><a name="l00404"></a>00404       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="l00405"></a>00405       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&gt;&gt;8);<a name="l00406"></a>00406       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="l00407"></a>00407 <a name="l00408"></a>00408       <span class="comment">// Clear out the reserved bytes</span><a name="l00409"></a>00409       <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i=4; i&lt;8; i++ )<a name="l00410"></a>00410     frame.<a class="code" href="structCanFrame.html#o3">data</a>[i] = 0;<a name="l00411"></a>00411 <a name="l00412"></a>00412       remain = size;<a name="l00413"></a>00413 <a name="l00414"></a>00414       <span class="comment">// Keep a pointer to the data buffer and reset the toggle bit</span><a name="l00415"></a>00415       dataPtr = data;<a name="l00416"></a>00416       toggle = 0;<a name="l00417"></a>00417 <a name="l00418"></a>00418       state = <a class="code" href="SDO_8cpp.html#a4">SDO_STATE_SENT_UPLD_INIT</a>;<a name="l00419"></a>00419       err = <a class="code" href="classReceiver.html#p0">co</a>-&gt;<a class="code" href="classCanOpen.html#a5">Xmit</a>( frame, timeout );<a name="l00420"></a>00420       <span class="keywordflow">if</span>( err ) state = <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a>;<a name="l00421"></a>00421    }<a name="l00422"></a>00422 <a name="l00423"></a>00423    <span class="comment">// If the upload was started successfully, sit waiting for the</span><a name="l00424"></a>00424    <span class="comment">// state to change to one that indicates success or failure.</span><a name="l00425"></a>00425    <span class="keywordflow">if</span>( !err ) err = WaitForTransfer( size );<a name="l00426"></a>00426    mutex.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00427"></a>00427    <span class="keywordflow">return</span> err;<a name="l00428"></a>00428 }<a name="l00429"></a>00429 <a name="l00430"></a>00430 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00431"></a>00431 <span class="comment">/**</span><a name="l00432"></a>00432 <span class="comment">Upload data using this SDO.  This function uses a block upload protocol</span><a name="l00433"></a>00433 <span class="comment">which makes sending large blocks of data more efficient.  The specified</span><a name="l00434"></a>00434 <span class="comment">object is upload from the CANopen node's object dictionary and stored in    </span><a name="l00435"></a>00435 <span class="comment">the array passed to this function.</span><a name="l00436"></a>00436 <span class="comment"> </span><a name="l00437"></a>00437 <span class="comment">@param index The index of the object to be uploaded.</span><a name="l00438"></a>00438 <span class="comment">@param sub The sub-index of the object to be uploaded.</span><a name="l00439"></a>00439 <span class="comment">@param size On entry, this should be the maximum number of bytes</span><a name="l00440"></a>00440 <span class="comment">       to upload, on successful return, this is the number of bytes</span><a name="l00441"></a>00441 <span class="comment">       actually received.</span><a name="l00442"></a>00442 <span class="comment">@param data A character array which will store the uploaded data.</span><a name="l00443"></a>00443 <span class="comment">@return A valid CANopen error object.</span><a name="l00444"></a>00444 <span class="comment">*/</span><a name="l00445"></a>00445 <span class="comment">/***************************************************************************/</span><a name="l00446"></a><a class="code" href="classSDO.html#a7">00446</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classSDO.html#a7">SDO::BlockUpld</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> &amp;size, <a class="code" href="CML__Utils_8h.html#a2">byte</a> *data )<a name="l00447"></a>00447 {<a name="l00448"></a>00448    <a class="code" href="structCanFrame.html">CanFrame</a> frame;<a name="l00449"></a>00449    <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err;<a name="l00450"></a>00450 <a name="l00451"></a>00451    <span class="comment">// Make sure the SDO has been initialized</span><a name="l00452"></a>00452    <span class="keywordflow">if</span>( !<a class="code" href="classReceiver.html#p0">co</a> ) <span class="keywordflow">return</span> &amp;<a class="code" href="classCanOpenError.html#s8">CanOpenError::NotInitialized</a>;<a name="l00453"></a>00453 <a name="l00454"></a>00454    mutex.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00455"></a>00455 <a name="l00456"></a>00456    <span class="keywordflow">if</span>( state != <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a> )<a name="l00457"></a>00457       err = &amp;<a class="code" href="classCanOpenError.html#s2">CanOpenError::SDO_Busy</a>;<a name="l00458"></a>00458 <a name="l00459"></a>00459    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( size &lt;= 0 )<a name="l00460"></a>00460       err = &amp;<a class="code" href="classCanOpenError.html#s1">CanOpenError::BadParam</a>;<a name="l00461"></a>00461 <a name="l00462"></a>00462    <span class="keywordflow">else</span><a name="l00463"></a>00463    {<a name="l00464"></a>00464       <span class="comment">// send an "Initiate block upload" message.</span><a name="l00465"></a>00465       frame.<a class="code" href="structCanFrame.html#o1">id</a> = xmitID;<a name="l00466"></a>00466       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="l00467"></a>00467       frame.<a class="code" href="structCanFrame.html#o2">length</a> = 8;<a name="l00468"></a>00468 <a name="l00469"></a>00469       <span class="comment">// BUG: I don't support CRC checking at the moment</span><a name="l00470"></a>00470       frame.<a class="code" href="structCanFrame.html#o3">data</a>[0] = 0xA0;<a name="l00471"></a>00471 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -