📄 sdo_8cpp-source.html
字号:
<a name="l00472"></a>00472 <span class="comment">// Copy the object multiplexor to the frame</span><a name="l00473"></a>00473 <span class="comment">// and also make a local copy.</span><a name="l00474"></a>00474 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="l00475"></a>00475 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="l00476"></a>00476 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="l00477"></a>00477 <a name="l00478"></a>00478 <span class="comment">// For now, I use 127 segments/block and allow</span><a name="l00479"></a>00479 <span class="comment">// drop back to normal update if the number of</span><a name="l00480"></a>00480 <span class="comment">// actual bytes is less then my threshold.</span><a name="l00481"></a>00481 blockSize = 127;<a name="l00482"></a>00482 frame.<a class="code" href="structCanFrame.html#o3">data</a>[4] = blockSize;<a name="l00483"></a>00483 frame.<a class="code" href="structCanFrame.html#o3">data</a>[5] = <a class="code" href="CML__SDO_8h.html#a30">SDO_BLK_UPLD_THRESHOLD</a>-1;<a name="l00484"></a>00484 <a name="l00485"></a>00485 <span class="comment">// Clear out the reserved bytes</span><a name="l00486"></a>00486 frame.<a class="code" href="structCanFrame.html#o3">data</a>[6] = 0;<a name="l00487"></a>00487 frame.<a class="code" href="structCanFrame.html#o3">data</a>[7] = 0;<a name="l00488"></a>00488 <a name="l00489"></a>00489 remain = size;<a name="l00490"></a>00490 toggle = 0;<a name="l00491"></a>00491 <a name="l00492"></a>00492 <span class="comment">// Keep a pointer to the data buffer</span><a name="l00493"></a>00493 dataPtr = data;<a name="l00494"></a>00494 <a name="l00495"></a>00495 state = <a class="code" href="SDO_8cpp.html#a6">SDO_STATE_SENT_BUP_INIT</a>;<a name="l00496"></a>00496 err = <a class="code" href="classReceiver.html#p0">co</a>-><a class="code" href="classCanOpen.html#a5">Xmit</a>( frame, timeout );<a name="l00497"></a>00497 <span class="keywordflow">if</span>( err ) state = <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a>;<a name="l00498"></a>00498 }<a name="l00499"></a>00499 <a name="l00500"></a>00500 <span class="keywordflow">if</span>( !err ) err = WaitForTransfer( size );<a name="l00501"></a>00501 mutex.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00502"></a>00502 <span class="keywordflow">return</span> err;<a name="l00503"></a>00503 }<a name="l00504"></a>00504 <a name="l00505"></a>00505 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00506"></a>00506 <span class="comment">/**</span><a name="l00507"></a>00507 <span class="comment">Download data using this SDO. This function uses a block download protocol</span><a name="l00508"></a>00508 <span class="comment">which makes sending large blocks of data more efficient. The data passed</span><a name="l00509"></a>00509 <span class="comment">to this function is downloaded to the object dictionary of the CANopen node</span><a name="l00510"></a>00510 <span class="comment"></span><a name="l00511"></a>00511 <span class="comment">@param index The index of the object to be downloaded.</span><a name="l00512"></a>00512 <span class="comment">@param sub The sub-index of the object to be downloaded.</span><a name="l00513"></a>00513 <span class="comment">@param size The number of bytes of data to be downloaded</span><a name="l00514"></a>00514 <span class="comment">@param data A character array holding the data to be downloaded.</span><a name="l00515"></a>00515 <span class="comment">@return A valid CANopen error object.</span><a name="l00516"></a>00516 <span class="comment">*/</span><a name="l00517"></a>00517 <span class="comment">/***************************************************************************/</span><a name="l00518"></a><a class="code" href="classSDO.html#a6">00518</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classSDO.html#a6">SDO::BlockDnld</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="l00519"></a>00519 {<a name="l00520"></a>00520 <span class="comment">// This isn't supported yet, just return an error</span><a name="l00521"></a>00521 <span class="keywordflow">return</span> &<a class="code" href="classCanOpenError.html#s10">CanOpenError::NotSupported</a>;<a name="l00522"></a>00522 }<a name="l00523"></a>00523 <a name="l00524"></a>00524 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00525"></a>00525 <span class="comment">/**</span><a name="l00526"></a>00526 <span class="comment">Wait for the current SDO transfer to finish. This is an internal function </span><a name="l00527"></a>00527 <span class="comment">used by all the SDO transfer modes (upload, download, block upload, block</span><a name="l00528"></a>00528 <span class="comment">download). It simply waits on the SDO's semaphore until either the SDO</span><a name="l00529"></a>00529 <span class="comment">transfer times out, or finishes either successfully or not.</span><a name="l00530"></a>00530 <span class="comment"></span><a name="l00531"></a>00531 <span class="comment">@param size Used to pass back the size of the transfer.</span><a name="l00532"></a>00532 <span class="comment">@return An error object.</span><a name="l00533"></a>00533 <span class="comment">*/</span><a name="l00534"></a>00534 <span class="comment">/***************************************************************************/</span><a name="l00535"></a>00535 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *SDO::WaitForTransfer( <a class="code" href="CML__Utils_8h.html#a9">int32</a> &size )<a name="l00536"></a>00536 {<a name="l00537"></a>00537 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err;<a name="l00538"></a>00538 <a name="l00539"></a>00539 <span class="keywordflow">while</span>( 1 )<a name="l00540"></a>00540 {<a name="l00541"></a>00541 err = sem.<a class="code" href="classSemaphore.html#a2">Get</a>( timeout );<a name="l00542"></a>00542 <a name="l00543"></a>00543 <span class="keywordflow">if</span>( err || state == <a class="code" href="SDO_8cpp.html#a1">SDO_STATE_DONE</a> )<a name="l00544"></a>00544 <span class="keywordflow">break</span>;<a name="l00545"></a>00545 }<a name="l00546"></a>00546 <a name="l00547"></a>00547 <span class="keywordflow">if</span>( err )<a name="l00548"></a>00548 {<a name="l00549"></a>00549 <span class="keywordflow">if</span>( err == &<a class="code" href="classThreadError.html#s2">ThreadError::Timeout</a> )<a name="l00550"></a>00550 err = &<a class="code" href="classCanOpenError.html#s3">CanOpenError::SDO_Timeout</a>;<a name="l00551"></a>00551 <span class="keywordflow">else</span><a name="l00552"></a>00552 err = &<a class="code" href="classCanOpenError.html#s4">CanOpenError::SDO_Unknown</a>;<a name="l00553"></a>00553 <a name="l00554"></a>00554 SendAbort( <a class="code" href="CML__SDO_8h.html#a1">SDO_ABORT_TIMEOUT</a> );<a name="l00555"></a>00555 }<a name="l00556"></a>00556 <a name="l00557"></a>00557 <span class="keywordflow">else</span><a name="l00558"></a>00558 {<a name="l00559"></a>00559 err = lastErr;<a name="l00560"></a>00560 size = count;<a name="l00561"></a>00561 }<a name="l00562"></a>00562 <a name="l00563"></a>00563 state = <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a>;<a name="l00564"></a>00564 <a name="l00565"></a>00565 <span class="keywordflow">return</span> err;<a name="l00566"></a>00566 }<a name="l00567"></a>00567 <a name="l00568"></a>00568 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00569"></a>00569 <span class="comment">/**</span><a name="l00570"></a>00570 <span class="comment">Process a newly received CAN frame addressed to this SDO object. This</span><a name="l00571"></a>00571 <span class="comment">is called from the CanOpen receive thread when a frame addressed to this</span><a name="l00572"></a>00572 <span class="comment">SDO is received over the network. This frame is processed based on the</span><a name="l00573"></a>00573 <span class="comment">state of the SDO.</span><a name="l00574"></a>00574 <span class="comment">@param frame The frame to be processed</span><a name="l00575"></a>00575 <span class="comment">@return This function always returns 1.</span><a name="l00576"></a>00576 <span class="comment">*/</span><a name="l00577"></a>00577 <span class="comment">/***************************************************************************/</span><a name="l00578"></a><a class="code" href="classSDO.html#a26">00578</a> <span class="keywordtype">int</span> <a class="code" href="classSDO.html#a26">SDO::NewFrame</a>( <a class="code" href="structCanFrame.html">CanFrame</a> &frame )<a name="l00579"></a>00579 {<a name="l00580"></a>00580 <span class="comment">// Ignore messages when idle</span><a name="l00581"></a>00581 <span class="keywordflow">if</span>( state == <a class="code" href="SDO_8cpp.html#a0">SDO_STATE_IDLE</a> )<a name="l00582"></a>00582 <span class="keywordflow">return</span> 1;<a name="l00583"></a>00583 <a name="l00584"></a>00584 <span class="comment">// Ignore remote frames</span><a name="l00585"></a>00585 <span class="keywordflow">if</span>( 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="l00586"></a>00586 <span class="keywordflow">return</span> 1;<a name="l00587"></a>00587 <a name="l00588"></a>00588 <span class="comment">// Pull the server command specifier out of the message.</span><a name="l00589"></a>00
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -