Paul Paterson / CanPipe Featured

Dependents:   CanPipe_Example

Embed: (wiki syntax)

« Back to documentation index

CanPipe Class Reference

CanPipe Class Reference

A stack on top of mbed CAN class to handle complex filtered callbacks. More...

#include <CanPipe.h>

Public Types

enum  CanPipeResult
 

Enumeration for method return values.

More...
enum  FilterMode
 

Enumeration for how filters should be handled.

More...

Public Member Functions

 CanPipe (CAN *p_can, FilterMode filter_mode=kFilterAuto)
 Creates message handler linked with the CAN device.
int RegisterFilter (unsigned int id, unsigned int mask, CANFormat format=CANAny, int handle=0)
 Assigns a filter to apply to CAN messages.
int RegisterCallback (CanMessageCallback callback, int handle)
 Assigns a callback to apply to CAN messages associated with a given filter.
void PostMessage (CANMessage msg)
 Stage a message to be written to the bus.
int HandleMessages ()
 Passes all received messages through the software-filters, if any, and writes any messages that have been posted.

Detailed Description

A stack on top of mbed CAN class to handle complex filtered callbacks.

Definition at line 15 of file CanPipe.h.


Member Enumeration Documentation

Enumeration for method return values.

Definition at line 21 of file CanPipe.h.

enum FilterMode

Enumeration for how filters should be handled.

Definition at line 29 of file CanPipe.h.


Constructor & Destructor Documentation

CanPipe ( CAN *  p_can,
FilterMode  filter_mode = kFilterAuto 
)

Creates message handler linked with the CAN device.

Parameters:
p_canreference to CAN device
filter_modehardware or software filtering only (Optional)

Example:

 #include "mbed.h"
 #include "CanPipe.h"

 Ticker ticker;
 DigitalOut led1(LED1);

 CAN m_can(P0_11, P0_31);
 CanPipe m_can_pipe(&m_can);

 char counter = 0;

 void send() {
     led1 = !led1;
     m_can_pipe.PostMessage(CANMessage(1337, &counter, 1));
 }

 int callback1(CANMessage &msg) { return CanPipe::kOkay; }
 int callback2(CANMessage &msg) { return CanPipe::kOkay; }
 int callback3(CANMessage &msg) { return CanPipe::kOkay; }

 int main() {
     int handle;

     handle = m_can_pipe.RegisterFilter(0x200, 0x780);
     m_can_pipe.RegisterCallback(callback1, handle);

     handle = m_can_pipe.RegisterFilter(0x281, 0);
     m_can_pipe.RegisterCallback(callback2, handle);
     m_can_pipe.RegisterCallback(callback3, handle);

     ticker.attach(send, 1);

     while (1) {
         __WFI(); //sleep();
         m_can_pipe.HandleMessages();
     }
 }

Definition at line 4 of file CanPipe.cpp.


Member Function Documentation

int HandleMessages ( void   )

Passes all received messages through the software-filters, if any, and writes any messages that have been posted.

Returns:
Boolean 1 if a message was handled (post or receive). 0 otherwise.

Definition at line 89 of file CanPipe.cpp.

void PostMessage ( CANMessage  msg )

Stage a message to be written to the bus.

Parameters:
msgmessage to write

Definition at line 85 of file CanPipe.cpp.

int RegisterCallback ( CanMessageCallback  callback,
int  handle 
)

Assigns a callback to apply to CAN messages associated with a given filter.

Parameters:
callback29 bit identifier to base filter on
handleFilter handle to associate with this callback (Optional)

Member functions can be added using the right callback Constructor

 canopen_class.RegisterCallback(
         CanMessageCallback(&object_instance, &ObjectClass::HandleMessage),
         handle);

Definition at line 53 of file CanPipe.cpp.

int RegisterFilter ( unsigned int  id,
unsigned int  mask,
CANFormat  format = CANAny,
int  handle = 0 
)

Assigns a filter to apply to CAN messages.

Parameters:
id29 bit identifier to base filter on
maskBit mask applied to the id
formatCAN message format (Default CANAny)
handleNumber to associate with message when passing this filter (Optional)

Can create software filters if device fails to create filters in hardware

Definition at line 12 of file CanPipe.cpp.