VMX-pi C++ HAL Library for Raspberry Pi
VMX-pi Robotics Controller & Vision/Motion Processor
Public Types | Public Member Functions | Friends | List of all members
VMXCAN Class Reference

The VMXCAN class provides a hardware-abstraction of the VMX-pi CAN functionality. More...

#include <VMXCAN.h>

Public Types

enum  VMXCANMode {
  VMXCAN_OFF, VMXCAN_CONFIG, VMXCAN_NORMAL, VMXCAN_LISTEN,
  VMXCAN_LOOPBACK
}
 Enumeration of VMX CAN operational modes. More...
 

Public Member Functions

bool SendMessage (VMXCANMessage &msg, int32_t periodMs, VMXErrorCode *errcode=0)
 Enqueues the CAN message for transmission onto the CAN bus to which the VMX device is currently connected. More...
 
bool OpenReceiveStream (VMXCANReceiveStreamHandle &streamHandle, uint32_t messageID, uint32_t messageMask, uint32_t maxMessages, VMXErrorCode *errcode=0)
 Opens a new CAN receive stream. More...
 
bool ReadReceiveStream (VMXCANReceiveStreamHandle streamHandle, VMXCANTimestampedMessage *messages, uint32_t messagesToRead, uint32_t &messagesRead, VMXErrorCode *errcode=0)
 Reads CAN messages which were recently received by the receive stream. More...
 
bool CloseReceiveStream (VMXCANReceiveStreamHandle streamHandle, VMXErrorCode *errcode=0)
 Closes a previously-opened CAN Receive Stream, and releases any HW Filter Resources, if any. More...
 
bool GetCANBUSStatus (VMXCANBusStatus &bus_status, VMXErrorCode *errcode=0)
 Retrieve the current CAN Bus status and statistics. More...
 
bool Reset (VMXErrorCode *errcode=0)
 Reset the VMX CAN Transceiver and Protocol Controller. More...
 
bool FlushTxFIFO (VMXErrorCode *errcode=0)
 Empty the VMX CAN transmit buffer. More...
 
bool FlushRxFIFO (VMXErrorCode *errcode=0)
 Empty the VMX CAN receive buffer. More...
 
bool SetMode (VMXCANMode mode, VMXErrorCode *errcode=0)
 Set the VMX CAN Protocol Transceiver/Protocol Controller Mode: More...
 
bool GetMode (VMXCANMode &mode, VMXErrorCode *errcode=0)
 Retreieve the current VMX CAN Transceiver/Controller mode. More...
 
bool ClearErrors (VMXErrorCode *errcode=0)
 If any VMX CAN errors are reported by the firmware, they are cleared. More...
 
bool RetrieveAllCANData (VMXErrorCode *errcode=0)
 Retrieve the recently-received CAN Bus messages from the VMX CAN receivequeue. More...
 
void DisplayMasksAndFilters ()
 Diagnostic message which prints the current CAN Protocol Controller's Mask and filters.
 

Friends

class VMXPi
 

Detailed Description

The VMXCAN class provides a hardware-abstraction of the VMX-pi CAN functionality.

Member Enumeration Documentation

◆ VMXCANMode

Enumeration of VMX CAN operational modes.

Enumerator
VMXCAN_OFF 

Places the CAN Transceiver/Controller into a sleep state, which may be automatically woken from if CAN Bus activity is later detected.

VMXCAN_CONFIG 

Places the CAN Controller into configuration mode, during which the Receive Masks/ Fiters may be modified.

VMXCAN_NORMAL 

Places the CAN Controller into normal mode, where it may transmit messages onto the CAN Bus, and may receive messages from the CAN Bus.

All Receive Masks/Filters which have previously been configured are active and will be used to filter the reception of transmitted messages.

VMXCAN_LISTEN 

Places the CAN Controller into a listen-only mode where it passively listens to the CAN Bus.

Note that all Receive Masks/Filters which have previously been configured will be ignored during this mode.

VMXCAN_LOOPBACK 

Places the CAN Controller into a mode where transmitted messages are looped back internally to the Receive circuitry.

During this mode, the Transceiver is completely disconnected from the CAN Bus. Note that during this mode, all Receive Masks/Filters which have previously been configured are active and will be used to filter the reception of transmitted messages.

Member Function Documentation

◆ ClearErrors()

bool VMXCAN::ClearErrors ( VMXErrorCode *  errcode = 0)

If any VMX CAN errors are reported by the firmware, they are cleared.

All VMX CAN errors are transient ~except~ the HW RX Overflow condition. If this condition exists, this method will clear it.

Parameters
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if any CAN errors were cleared. If false, the error code will be returned via the errcode parameter.

◆ CloseReceiveStream()

bool VMXCAN::CloseReceiveStream ( VMXCANReceiveStreamHandle  streamid,
VMXErrorCode *  errcode = 0 
)

Closes a previously-opened CAN Receive Stream, and releases any HW Filter Resources, if any.

Parameters
streamidHandle of VMXCANReceiveStream to close
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the CAN Receive stream was closed. If false, the error code will be returned via the errcode parameter.

◆ FlushRxFIFO()

bool VMXCAN::FlushRxFIFO ( VMXErrorCode *  errcode = 0)

Empty the VMX CAN receive buffer.

Parameters
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the CAN receive buffer was flushed. If false, the error code will be returned via the errcode parameter.

◆ FlushTxFIFO()

bool VMXCAN::FlushTxFIFO ( VMXErrorCode *  errcode = 0)

Empty the VMX CAN transmit buffer.

Parameters
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the CAN transmit buffer was flushed. If false, the error code will be returned via the errcode parameter.

◆ GetCANBUSStatus()

bool VMXCAN::GetCANBUSStatus ( VMXCANBusStatus bus_status,
VMXErrorCode *  errcode = 0 
)

Retrieve the current CAN Bus status and statistics.

Parameters
[out]bus_statusThe current status/statistics, returned by this method.
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the CAN Bus status was retrieved If false, the error code will be returned via the errcode parameter.

◆ GetMode()

bool VMXCAN::GetMode ( VMXCANMode mode,
VMXErrorCode *  errcode = 0 
)

Retreieve the current VMX CAN Transceiver/Controller mode.

Parameters
[out]modeThe current mode.
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the CAN mode was retrieved. If false, the error code will be returned via the errcode parameter.

◆ OpenReceiveStream()

bool VMXCAN::OpenReceiveStream ( VMXCANReceiveStreamHandle &  session_handle,
uint32_t  messageID,
uint32_t  messageMask,
uint32_t  maxMessages,
VMXErrorCode *  errcode = 0 
)

Opens a new CAN receive stream.

Parameters
session_handleA handle to the newly-created stream
messageIDThe CAN message ID to receive messages from
messageMaskThe CAN message mask to receive messages from
maxMessagesThe maximum number of received messages held within the stream
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the CAN receive stream was created. If false, the error code will be returned via the errcode parameter.

◆ ReadReceiveStream()

bool VMXCAN::ReadReceiveStream ( VMXCANReceiveStreamHandle  streamid,
VMXCANTimestampedMessage messages,
uint32_t  messagesToRead,
uint32_t &  messagesRead,
VMXErrorCode *  errcode = 0 
)

Reads CAN messages which were recently received by the receive stream.

Parameters
streamidHandle to the CAN receive stream to read messages from
[out]messagesBuffer to read received messages into
messagesToReadThe maximum number of messages to read into the memory pointed to by the messages parameter
[out]messagesReadThe actual number of messages read into the memory pointed to by the messages parameter
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if no errors were encountered while reading messages from the stream. If false, the error code will be returned via the errcode parameter.

◆ Reset()

bool VMXCAN::Reset ( VMXErrorCode *  errcode = 0)

Reset the VMX CAN Transceiver and Protocol Controller.

Note this method will block for 10ms after resetting the controller.

Parameters
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the CAN Bus Transceiver/Controller was reset. If false, the error code will be returned via the errcode parameter.

◆ RetrieveAllCANData()

bool VMXCAN::RetrieveAllCANData ( VMXErrorCode *  errcode = 0)

Retrieve the recently-received CAN Bus messages from the VMX CAN receivequeue.

Received messages are place into the receive stream queue whose messageID filter matches each message.

Parameters
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if no errors were encountered while retrieving CAN data. If false, the error code will be returned via the errcode parameter.

◆ SendMessage()

bool VMXCAN::SendMessage ( VMXCANMessage msg,
int32_t  periodMs,
VMXErrorCode *  errcode = 0 
)

Enqueues the CAN message for transmission onto the CAN bus to which the VMX device is currently connected.

Parameters
msgThe message to be transmitted at the ID specified within the message.
periodMsIf non-zero, the message is periodically retransmitted after this number of milliseconds.
[out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
Returns
Returns true if the message succesfully enqueued for transfer. If false, the error code will be returned via the errcode parameter.

◆ SetMode()

bool VMXCAN::SetMode ( VMXCANMode  mode,
VMXErrorCode *  errcode = 0 
)

Set the VMX CAN Protocol Transceiver/Protocol Controller Mode:

  • VMXCAN_OFF: The transceiver is disconnected from the CAN bus, and cannot receive or transmit messages.
  • VMXCAN_CONFIG: The protocol controller is ready to receive configuration changes (to the current hardware receive filters)
  • VMXCAN_NORMAL: The transceiver is connected to the CAN bus, and can receive and transmit messages.
  • VMXCAN_LISTEN: The transceiver is connected to the CAN bus, and can only receive messages. Note that messages will be received even if errors (e.g., CRC errors) are detected. In this mode, a high number of messages can be received; this mode is not recommended for normal use.
  • VMXCAN_LOOPBACK: The transceiver is disconnected from the CAN bus, and the TX signal is connected internally to the RX signal. This mode is useful for debugging/testing CAN protocol-related software.
    Parameters
    modeThe requested CAN mode
    [out]errcodePointer to the VMXErrorCode to be returned in case of error; may be null
    Returns
    Returns true if the CAN mode was changed. If false, the error code will be returned via the errcode parameter.

The documentation for this class was generated from the following files: