VMX-pi C++ HAL Library for Raspberry Pi
VMX-pi Robotics Controller & Vision/Motion Processor
Classes | 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  CANBusBitrate { CAN_BUS_BITRATE_1MBPS, CAN_BUS_BITRATE_500KBPS, CAN_BUS_BITRATE_250KBPS }
 
enum  VMXCANMode {
  VMXCAN_OFF, VMXCAN_CONFIG, VMXCAN_NORMAL, VMXCAN_LISTEN,
  VMXCAN_LOOPBACK
}
 Enumeration of VMX CAN operational modes. More...
 

Public Member Functions

void DisplayMasksAndFilters ()
 Diagnostic message which prints the current CAN Protocol Controller's Mask and filters.
 
bool SendMessage (VMXCANMessage &msg, int32_t periodMs, VMXErrorCode *errcode)
 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)
 Opens a new CAN receive stream. More...
 
bool ReadReceiveStream (VMXCANReceiveStreamHandle streamHandle, VMXCANTimestampedMessage *messages, uint32_t messagesToRead, uint32_t &messagesRead, VMXErrorCode *errcode)
 Reads CAN messages which were recently received by the receive stream. More...
 
bool CloseReceiveStream (VMXCANReceiveStreamHandle streamHandle, VMXErrorCode *errcode)
 Closes a previously-opened CAN Receive Stream, and releases any HW Filter Resources, if any. More...
 
bool GetCANBUSStatus (VMXCANBusStatus &bus_status, VMXErrorCode *errcode)
 Retrieve the current CAN Bus status and statistics. More...
 
bool Reset (VMXErrorCode *errcode)
 Reset the VMX CAN Transceiver and Protocol Controller. More...
 
bool ResetBusBitrate (VMXCAN::CANBusBitrate can_bus_bitrate, VMXErrorCode *errcode)
 
bool FlushTxFIFO (VMXErrorCode *errcode)
 Empty the VMX CAN transmit buffer. More...
 
bool FlushRxFIFO (VMXErrorCode *errcode)
 Empty the VMX CAN receive buffer. More...
 
bool SetMode (VMXCANMode mode, VMXErrorCode *errcode)
 Set the VMX CAN Protocol Transceiver/Protocol Controller Mode: More...
 
bool GetMode (VMXCANMode &current_mode, VMXErrorCode *errcode)
 Retreieve the current VMX CAN Transceiver/Controller mode. More...
 
bool ClearErrors (VMXErrorCode *errcode)
 If any VMX CAN errors are reported by the firmware, they are cleared. More...
 
bool RetrieveAllCANData (uint64_t sys_timestamp, VMXErrorCode *errcode)
 Retrieve the recently-received CAN Bus messages from the VMX CAN receivequeue. More...
 
bool EnableReceiveStreamBlackboard (VMXCANReceiveStreamHandle streamHandle, bool enable, VMXErrorCode *errcode)
 
bool IsReceveStreamBlackboardEnabled (VMXCANReceiveStreamHandle streamHandle, bool &enabled, VMXErrorCode *errcode)
 
bool GetBlackboardEntry (VMXCANReceiveStreamHandle streamid, uint32_t messageID, VMXCANTimestampedMessage &msg, uint64_t &sys_timestamp, bool &already_retrieved, VMXErrorCode *errcode)
 

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)

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 
)

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)

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)

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 
)

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 
)

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 
)

Opens a new CAN receive stream.

Parameters
session_handleA handle to the newly-created stream
messageIDThe CAN message ID to receive messages from. If standard (11-bit) IDs are to be acquired, the VMXCAN_IS_FRAME_11BIT bit must be set; if this bit is not set, only extended (29-bit) IDs will be acquired.
messageMaskThe CAN message mask to receive messages from. If standard (11-bit) IDs are to be acquired the VMXCAN_IS_FRAME_11BIT bit must be set; if this bit is not set, only extended (29-bit) IDs will be acquired.
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 
)

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)

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 ( uint64_t  sys_timestamp,
VMXErrorCode *  errcode 
)

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 
)

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

The message is placed into a Fifo and transmitted as soon as possible.

This function is re-entrant and thus may be called from multiple contexts.

Parameters
msgThe message to be transmitted at the ID specified within the message. Note that unless the periodMs parameter is negative, the data bytes and length in the message must be valid.
periodMsIf >= 0, the message is set immediately. Additionally, if greater than zero, the message (and its data) is periodically retransmitted after this number of milliseconds. If zero, the message is only transmitted once. If less than zero, any previously-requested periodic message retranmsittal for this CAN ID will be cancelled.
[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 
)

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: