📄 canopen_8cpp-source.html
字号:
<a name="l00280"></a>00280 hashMutex.<a class="code" href="classMutex.html#a2">Lock</a>();<a name="l00281"></a>00281 <a name="l00282"></a>00282 r = *searchHash( frame.<a class="code" href="structCanFrame.html#o1">id</a> );<a name="l00283"></a>00283 <span class="keywordflow">if</span>( r )<a name="l00284"></a>00284 r-><a class="code" href="classReceiver.html#a5">NewFrame</a>(frame);<a name="l00285"></a>00285 <a name="l00286"></a>00286 hashMutex.<a class="code" href="classMutex.html#a3">Unlock</a>();<a name="l00287"></a>00287 }<a name="l00288"></a>00288 }<a name="l00289"></a>00289 <a name="l00290"></a>00290 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00291"></a>00291 <span class="comment">/**</span><a name="l00292"></a>00292 <span class="comment">Default constructor for CanOpenSettings object.</span><a name="l00293"></a>00293 <span class="comment">This constructor simply sets all the settings to their default values.</span><a name="l00294"></a>00294 <span class="comment">*/</span><a name="l00295"></a>00295 <span class="comment">/***************************************************************************/</span><a name="l00296"></a><a class="code" href="classCanOpenSettings.html#a0">00296</a> <a class="code" href="classCanOpenSettings.html#a0">CanOpenSettings::CanOpenSettings</a>( <span class="keywordtype">void</span> )<a name="l00297"></a>00297 {<a name="l00298"></a>00298 <a class="code" href="classCanOpenSettings.html#o0">readThreadPriority</a> = 9;<a name="l00299"></a>00299 }<a name="l00300"></a>00300 <a name="l00301"></a>00301 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00302"></a>00302 <span class="comment">/**</span><a name="l00303"></a>00303 <span class="comment">Default constructor for a CANopen receiver object.</span><a name="l00304"></a>00304 <span class="comment">*/</span><a name="l00305"></a>00305 <span class="comment">/***************************************************************************/</span><a name="l00306"></a><a class="code" href="classReceiver.html#a0">00306</a> <a class="code" href="classReceiver.html#a0">Receiver::Receiver</a>( <span class="keywordtype">void</span> )<a name="l00307"></a>00307 {<a name="l00308"></a>00308 <span class="comment">// Whenever the receiver is disabled, we self reference with the </span><a name="l00309"></a>00309 <span class="comment">// next pointer. This is a quick way to identify an enabled receiver</span><a name="l00310"></a>00310 next = <span class="keyword">this</span>;<a name="l00311"></a>00311 <a class="code" href="classReceiver.html#p0">co</a> = 0;<a name="l00312"></a>00312 }<a name="l00313"></a>00313 <a name="l00314"></a>00314 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00315"></a>00315 <span class="comment">/**</span><a name="l00316"></a>00316 <span class="comment">Initialize a new CANopen receiver. After construction, the receiver will </span><a name="l00317"></a>00317 <span class="comment">be disabled. Call Enable() to allow messages to be received.</span><a name="l00318"></a>00318 <span class="comment">@param canOpen Reference to the CANopen network object that this receiver</span><a name="l00319"></a>00319 <span class="comment"> is associated with.</span><a name="l00320"></a>00320 <span class="comment">@param id COB ID of the receive message</span><a name="l00321"></a>00321 <span class="comment">*/</span><a name="l00322"></a>00322 <span class="comment">/***************************************************************************/</span><a name="l00323"></a><a class="code" href="classReceiver.html#a1">00323</a> <a class="code" href="classReceiver.html#a0">Receiver::Receiver</a>( <a class="code" href="classCanOpen.html">CanOpen</a> &canOpen, <a class="code" href="CML__Utils_8h.html#a10">uint32</a> <span class="keywordtype">id</span> )<a name="l00324"></a>00324 {<a name="l00325"></a>00325 next = <span class="keyword">this</span>;<a name="l00326"></a>00326 <a class="code" href="classReceiver.html#p0">co</a> = 0;<a name="l00327"></a>00327 <a class="code" href="classReceiver.html#a3">Init</a>( canOpen, <span class="keywordtype">id</span> );<a name="l00328"></a>00328 }<a name="l00329"></a>00329 <a name="l00330"></a>00330 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00331"></a>00331 <span class="comment">/**</span><a name="l00332"></a>00332 <span class="comment">Destructor for CANopen receiver objects. This destructor ensures that the</span><a name="l00333"></a>00333 <span class="comment">receiver is disabled before it is destroyed.</span><a name="l00334"></a>00334 <span class="comment">*/</span><a name="l00335"></a>00335 <span class="comment">/***************************************************************************/</span><a name="l00336"></a><a class="code" href="classReceiver.html#a2">00336</a> <a class="code" href="classReceiver.html#a2">Receiver::~Receiver</a>()<a name="l00337"></a>00337 {<a name="l00338"></a>00338 <a class="code" href="classReceiver.html#a4">UnInit</a>();<a name="l00339"></a>00339 }<a name="l00340"></a>00340 <a name="l00341"></a>00341 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00342"></a>00342 <span class="comment">/**</span><a name="l00343"></a>00343 <span class="comment">Initialize the CANopen receiver object. This function should be called </span><a name="l00344"></a>00344 <span class="comment">before the receiver is used in any way. It can only be called once.</span><a name="l00345"></a>00345 <span class="comment">@param canOpen Reference to the CANopen network object that this receiver</span><a name="l00346"></a>00346 <span class="comment"> is associated with.</span><a name="l00347"></a>00347 <span class="comment">@param id COB ID of the receive message</span><a name="l00348"></a>00348 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00349"></a>00349 <span class="comment">*/</span><a name="l00350"></a>00350 <span class="comment">/***************************************************************************/</span><a name="l00351"></a><a class="code" href="classReceiver.html#a3">00351</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classReceiver.html#a3">Receiver::Init</a>( <a class="code" href="classCanOpen.html">CanOpen</a> &canOpen, <a class="code" href="CML__Utils_8h.html#a10">uint32</a> <span class="keywordtype">id</span> )<a name="l00352"></a>00352 {<a name="l00353"></a>00353 <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *err = <a class="code" href="classCanInterface.html#e0">CanInterface::ChkID</a>( <span class="keywordtype">id</span> );<a name="l00354"></a>00354 <span class="keywordflow">if</span>( err ) <span class="keywordflow">return</span> err;<a name="l00355"></a>00355 <a name="l00356"></a>00356 <a class="code" href="classReceiver.html#a8">DisableReceiver</a>();<a name="l00357"></a>00357 <a name="l00358"></a>00358 this-><span class="keywordtype">id</span> = id;<a name="l00359"></a>00359 <a class="code" href="classReceiver.html#p0">co</a> = &canOpen;<a name="l00360"></a>00360 <span class="keywordflow">return</span> 0;<a name="l00361"></a>00361 }<a name="l00362"></a>00362 <a name="l00363"></a>00363 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00364"></a>00364 <span class="comment">/**</span><a name="l00365"></a>00365 <span class="comment">Un-initialize a CANopen receiver. This returns the receiver object to it's</span><a name="l00366"></a>00366 <span class="comment">uninitialized state.</span><a name="l00367"></a>00367 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00368"></a>00368 <span class="comment">*/</span><a name="l00369"></a>00369 <span class="comment">/***************************************************************************/</span><a name="l00370"></a><a class="code" href="classReceiver.html#a4">00370</a> <span class="keyword">const</span> <a class="code" href="classError.html">Error</a> *<a class="code" href="classReceiver.html#a4">Receiver::UnInit</a>( <span class="keywordtype">void</span> )<a name="l00371"></a>00371 {<a name="l00372"></a>00372 <a class="code" href="classReceiver.html#a8">DisableReceiver</a>();<a name="l00373"></a>00373 <a class="code" href="classReceiver.html#p0">co</a> = 0;<a name="l00374"></a>00374 <span class="keywordflow">return</span> 0;<a name="l00375"></a>00375 }<a name="l00376"></a>00376 <a name="l00377"></a>00377 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00378"></a>00378 <span class="comment">/**</span><a name="l00379"></a>00379 <span class="comment">Process a new received CAN bus frame. This virtual function is called by</span><a name="l00380"></a>00380 <span class="comment">the CANopen read thread every time a CAN frame is received over the network</span><a name="l00381"></a>00381 <span class="comment">with an ID matching the receivers ID if the receiver is enabled. </span><a name="l00382"></a>00382 <span class="comment"></span><a name="l00383"></a>00383 <span class="comment">Note that this function is called from the CANopen receive thread. No other</span><a name="l00384"></a>00384 <span class="comment">receive frames will be processed until this function returns.</span><a name="l00385"></a>00385 <span class="comment"></span><a name="l00386"></a>00386 <span class="comment">Also note that the map object used to associate message IDs with receive objects</span><a name="l00387"></a>00387 <span class="comment">is locked when this function is called. The locking is required to prevent a </span><a name="l00388"></a>00388 <span class="comment">race condition that could occur when a receive object is disabled and it's </span><a name="l00389"></a>00389 <span class="comment">memory is deallocated. Since the map is locked, it's illegal to Enable() or</span><a name="l00390"></a>00390 <span class="comment">Disable() any receive object from within this function.</span><a name="l00391"></a>00391 <span class="comment"></span><a name="l00392"></a>00392 <span class="comment">@param frame The CAN frame to be processed. Note that the memory holding the</span><a name="l00393"></a>00393 <span class="comment"> frame structure may be reused after the call returns. If the frame </span><a name="l00394"></a>00394 <span class="comment"> contents are to be used after the return the a copy of the frame should</span><a name="l00395"></a>00395 <span class="comment"> be made. </span><a name="l00396"></a>00396 <span class="comment"> </span><a name="l00397"></a>00397 <span class="comment">@return non-zero if the frame was handled, zero if the frame type was unknown.</span><a name="l00398"></a>00398 <span class="comment">*/</span><a name="l00399"></a>00399 <span class="comment">/***************************************************************************/</span><a name="l00400"></a><a class="code" href="classReceiver.html#a5">00400</a> <span class="keywordtype">int</span> <a class="code" href="classReceiver.html#a5">Receiver::NewFrame</a>( <a class="code" href="structCanFrame.html">CanFrame</a> &frame )<a name="l00401"></a>00401 {<a name="l00402"></a>00402 <span class="keywordflow">return</span> 0;<a name="l00403"></a>00403 }<a name="l00404"></a>00404 <a name="l00405"></a>00405 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00406"></a>00406 <span class="comment">/**</span><a name="l00407"></a>00407 <span class="comment">Return the receive COB ID associated with this CANopen message receiver.</span><a name="l00408"></a>00408 <span class="comment">@return The receive COB ID.</span><a name="l00409"></a>00409 <span class="comment">*/</span><a name="l00410"></a>00410 <span class="comment">/***************************************************************************/</span><a name="l00411"></a><a class="code" href="classReceiver.html#a6">00411</a> <a class="code" href="CML__Utils_8h.html#a10">uint32</a> <a class="code" href="classReceiver.html#a6">Receiver::getRecvID</a>( <span class="keywordtype">void</span> )<a name="l00412"></a>00412 {<a name="l00413"></a>00413 <span class="keywordflow">return</span> id;<a name="l00414"></a>00414 }<a name="l00415"></a>00415 <a name="l00416"></a>00416 <span class="comment">/***************************************************************************/</span><span class="comment"></span><a name="l00417"></a>00417 <span class="comment">/**</span><a name="l00418"></a>00418 <span class="comment">Enable reception of this message type. Once enabled, any messages received</span><a name="l00419"></a>00419 <span class="comment">over the CANopen network of this type will be passed to the Receiver</span><a name="l00420"></a>00420 <span class="comment">using the member function NewFrame.</span><a name="l00421"></a>00421 <span class="comment">@return A pointer to an error object, or NULL on success.</span><a name="l00422"></a>00422 <span class="comment">*/</span><a name="l00423"></a>00423 <span class="comment">/***************************************************************************/</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -