📄 canopen_8cpp-source.html
字号:
<a name="l00424"></a><a class="code" href="classReceiver.html#a7">00424</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classReceiver.html#a7">Receiver::EnableReceiver</a>()<a name="l00425"></a>00425 {<a name="l00426"></a>00426 <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="l00427"></a>00427 <a name="l00428"></a>00428 <span class="keywordflow">return</span> <a class="code" href="classReceiver.html#p0">co</a>-><a class="code" href="classCanOpen.html#d1">EnableReceiver</a>( <span class="keyword">this</span> );<a name="l00429"></a>00429 }<a name="l00430"></a>00430 <a name="l00431"></a>00431 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00432"></a>00432 <span class="comment">/**</span><a name="l00433"></a>00433 <span class="comment">Search a hash table of receiver objects associated with this network.</span><a name="l00434"></a>00434 <span class="comment">The CanOpen object maintains a hash of all enabled receivers on the </span><a name="l00435"></a>00435 <span class="comment">network. Each time a new CAN frame is received, the hash is searched for</span><a name="l00436"></a>00436 <span class="comment">a receiver matching the frame's ID. This function handles the details of</span><a name="l00437"></a>00437 <span class="comment">the search.</span><a name="l00438"></a>00438 <span class="comment"></span><a name="l00439"></a>00439 <span class="comment">This function is also used when adding receivers to the tree. To aid this</span><a name="l00440"></a>00440 <span class="comment">use, it actually returns a pointer to a pointer to the receiver, or to the</span><a name="l00441"></a>00441 <span class="comment">place where the new receiver would be added.</span><a name="l00442"></a>00442 <span class="comment"></span><a name="l00443"></a>00443 <span class="comment">Note, it's assumed that the hash mutex will be locked when this function </span><a name="l00444"></a>00444 <span class="comment">is called.</span><a name="l00445"></a>00445 <span class="comment"></span><a name="l00446"></a>00446 <span class="comment">@param id The CAN message ID of the receiver to be found.</span><a name="l00447"></a>00447 <span class="comment">@return A pointer to a pointer to the receiver, or the location where the</span><a name="l00448"></a>00448 <span class="comment"> receiver should be added if there is none with a matching ID.</span><a name="l00449"></a>00449 <span class="comment">*/</span><a name="l00450"></a>00450 <span class="comment">/***************************************************************************/</span><a name="l00451"></a>00451 <a class="code" href="classReceiver.html">Receiver</a> **CanOpen::searchHash( <a class="code" href="CML__Utils_8h.html#a10">uint32</a> <span class="keywordtype">id</span> )<a name="l00452"></a>00452 {<a name="l00453"></a>00453 <span class="keywordtype">int</span> i = <span class="keywordtype">id</span> % <a class="code" href="CML__Settings_8h.html#a1">CML_HASH_SIZE</a>;<a name="l00454"></a>00454 <a name="l00455"></a>00455 <a class="code" href="classReceiver.html">Receiver</a> **pp = &hash[i];<a name="l00456"></a>00456 <a name="l00457"></a>00457 <span class="keywordflow">while</span>( 1 )<a name="l00458"></a>00458 {<a name="l00459"></a>00459 <span class="keywordflow">if</span>( !*pp )<a name="l00460"></a>00460 <span class="keywordflow">return</span> pp;<a name="l00461"></a>00461 <a name="l00462"></a>00462 <a class="code" href="CML__Utils_8h.html#a10">uint32</a> x = (*pp)->id;<a name="l00463"></a>00463 <a name="l00464"></a>00464 <span class="keywordflow">if</span>( <span class="keywordtype">id</span> == x )<a name="l00465"></a>00465 <span class="keywordflow">return</span> pp;<a name="l00466"></a>00466 <a name="l00467"></a>00467 pp = &( (*pp)->next);<a name="l00468"></a>00468 }<a name="l00469"></a>00469 }<a name="l00470"></a>00470 <a name="l00471"></a>00471 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00472"></a>00472 <span class="comment">/**</span><a name="l00473"></a>00473 <span class="comment">Enable reception handling of the message identified by this Receiver</span><a name="l00474"></a>00474 <span class="comment">object. The receiver is enabled by adding it to a binary tree of </span><a name="l00475"></a>00475 <span class="comment">receiver objects maintained by the CanOpen object.</span><a name="l00476"></a>00476 <span class="comment"></span><a name="l00477"></a>00477 <span class="comment">@param rPtr Pointer to the receiver to add</span><a name="l00478"></a>00478 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00479"></a>00479 <span class="comment">*/</span><a name="l00480"></a>00480 <span class="comment">/***************************************************************************/</span><a name="l00481"></a>00481 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *CanOpen::EnableReceiver( <a class="code" href="classReceiver.html">Receiver</a> *rPtr )<a name="l00482"></a>00482 {<a name="l00483"></a>00483 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err = 0;<a name="l00484"></a>00484 <a name="l00485"></a>00485 hashMutex.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00486"></a>00486 <a name="l00487"></a>00487 <a class="code" href="classReceiver.html">Receiver</a> **pp = searchHash( rPtr-><a class="code" href="classReceiver.html#r0">id</a> );<a name="l00488"></a>00488 <a name="l00489"></a>00489 <span class="keywordflow">if</span>( *pp )<a name="l00490"></a>00490 err = &<a class="code" href="classCanOpenError.html#s14">CanOpenError::RcvrPresent</a>;<a name="l00491"></a>00491 <span class="keywordflow">else</span><a name="l00492"></a>00492 {<a name="l00493"></a>00493 rPtr-><a class="code" href="classReceiver.html#r1">next</a> = 0;<a name="l00494"></a>00494 *pp = rPtr;<a name="l00495"></a>00495 }<a name="l00496"></a>00496 <a name="l00497"></a>00497 hashMutex.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00498"></a>00498 <a name="l00499"></a>00499 <span class="keywordflow">return</span> err;<a name="l00500"></a>00500 }<a name="l00501"></a>00501 <a name="l00502"></a>00502 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00503"></a>00503 <span class="comment">/**</span><a name="l00504"></a>00504 <span class="comment">Disable reception handling of the message identified by this Receiver</span><a name="l00505"></a>00505 <span class="comment">object. Receivers are disabled by removing them from a binary tree of </span><a name="l00506"></a>00506 <span class="comment">receiver objects maintained by the CanOpen object.</span><a name="l00507"></a>00507 <span class="comment"></span><a name="l00508"></a>00508 <span class="comment">@param rPtr A pointer to the receiver to disable.</span><a name="l00509"></a>00509 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00510"></a>00510 <span class="comment">*/</span><a name="l00511"></a>00511 <span class="comment">/***************************************************************************/</span><a name="l00512"></a>00512 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *CanOpen::DisableReceiver( <a class="code" href="classReceiver.html">Receiver</a> *rPtr )<a name="l00513"></a>00513 {<a name="l00514"></a>00514 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err = 0;<a name="l00515"></a>00515 <a name="l00516"></a>00516 hashMutex.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00517"></a>00517 <a name="l00518"></a>00518 <a class="code" href="classReceiver.html">Receiver</a> **pp = searchHash( rPtr-><a class="code" href="classReceiver.html#r0">id</a> );<a name="l00519"></a>00519 <a name="l00520"></a>00520 <span class="keywordflow">if</span>( !*pp )<a name="l00521"></a>00521 err = &<a class="code" href="classCanOpenError.html#s13">CanOpenError::RcvrNotFound</a>;<a name="l00522"></a>00522 <a name="l00523"></a>00523 <span class="keywordflow">else</span><a name="l00524"></a>00524 {<a name="l00525"></a>00525 rPtr = *pp;<a name="l00526"></a>00526 *pp = rPtr-><a class="code" href="classReceiver.html#r1">next</a>;<a name="l00527"></a>00527 <a name="l00528"></a>00528 <span class="comment">// Point the receiver back at itself.</span><a name="l00529"></a>00529 <span class="comment">// This allows the receiver to determine it's disabled.</span><a name="l00530"></a>00530 rPtr-><a class="code" href="classReceiver.html#r1">next</a> = rPtr;<a name="l00531"></a>00531 }<a name="l00532"></a>00532 <a name="l00533"></a>00533 hashMutex.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00534"></a>00534 <span class="keywordflow">return</span> err;<a name="l00535"></a>00535 }<a name="l00536"></a>00536 <a name="l00537"></a>00537 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00538"></a>00538 <span class="comment">/**</span><a name="l00539"></a>00539 <span class="comment">Disable reception of this message type. Any CAN frames received by the</span><a name="l00540"></a>00540 <span class="comment">CANopen object of a disabled message type will be ignored by the CANopen</span><a name="l00541"></a>00541 <span class="comment">object.</span><a name="l00542"></a>00542 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00543"></a>00543 <span class="comment">*/</span><a name="l00544"></a>00544 <span class="comment">/***************************************************************************/</span><a name="l00545"></a><a class="code" href="classReceiver.html#a8">00545</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classReceiver.html#a8">Receiver::DisableReceiver</a>()<a name="l00546"></a>00546 {<a name="l00547"></a>00547 <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="l00548"></a>00548 <a name="l00549"></a>00549 <span class="keywordflow">if</span>( next == this ) <span class="keywordflow">return</span> &<a class="code" href="classCanOpenError.html#s13">CanOpenError::RcvrNotFound</a>;<a name="l00550"></a>00550 <a name="l00551"></a>00551 <span class="keywordflow">return</span> <a class="code" href="classReceiver.html#p0">co</a>-><a class="code" href="classCanOpen.html#d2">DisableReceiver</a>( <span class="keyword">this</span> );<a name="l00552"></a>00552 }<a name="l00553"></a>00553 </pre></div><hr><address style="align: right;"><small>Copley Motion Library, Copyright (c) 2002-2003<a href="http://www.copleycontrols.com"><img src="CCC_logo.gif" alt="Copley Controls Corp." align="middle" border=0 ></a></small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -