CARMA C++
carma::canbus::JanzMessage Class Reference

This class encapsulate a Janz CAN message. More...

#include <carma/canbus/JanzMessage.h>

Public Types

enum  messageTypeType { STANDARD = 0, EXTENDED = 1 }
 Message type definition. More...
 

Public Member Functions

void disableTxRetry ()
 Set retry mode for message. More...
 
void enableEcho ()
 Echo this message. More...
 
carma::canbus::busIdType getBusId () const
 Get CAN bus Id. More...
 
std::vector
< carma::canbus::byteType
getData () const
 Get the data as a vector of bytes (raw). More...
 
carma::canbus::idType getId () const
 Get CAN message id. More...
 
carma::canbus::JanzMessage::messageTypeType getMessageType () const
 Get message type. More...
 
carma::canbus::portType getPort () const
 Get port number. More...
 
carma::canbus::FastMessage getRawMessage () const
 Return the underlying drivers raw message. More...
 
double getRxMjd () const
 Return the Rx MJD time. More...
 
bool isSimulated () const
 Return simulated flag. More...
 
 JanzMessage (JanzMessage::messageTypeType msgType=EXTENDED)
 Default constructor. More...
 
 JanzMessage (carma::canbus::idType id, carma::canbus::busIdType busId)
 Create an extended message with specified id and busId. More...
 
 JanzMessage (carma::canbus::idType id, const std::vector< carma::canbus::byteType > &data, carma::canbus::busIdType busId)
 Create an extended message with the specified ids and data. More...
 
 JanzMessage (carma::canbus::FastMessage, carma::canbus::busIdType busId)
 Create a message from a Janz FastMessage. More...
 
 JanzMessage (const carma::canbus::Message &message)
 Create a JanzMessage from a Message. More...
 
 JanzMessage (const JanzMessage &other)
 Copy constructor. More...
 
bool operator!= (const JanzMessage &other) const
 Check for inequality. More...
 
JanzMessageoperator= (const JanzMessage &other)
 Assignment operator. More...
 
bool operator== (const JanzMessage &other) const
 Check for equality. More...
 
void setBusId (carma::canbus::busIdType busId)
 Set bus Id. More...
 
void setData (const std::vector< carma::canbus::byteType > &data)
 Set the data. More...
 
void setId (carma::canbus::idType id)
 Set CAN message id. More...
 
void setPort (carma::canbus::portType port)
 Set port number. More...
 
void setRxMjd (double mjd)
 Set the rxMjd time. More...
 
void setSimFlag (bool sim)
 Set the simulated flag. More...
 

Detailed Description

This class encapsulate a Janz CAN message.

A CAN message consists of a 29 bit message Id and up to 8 bytes of raw data. This class wraps the CAN message structure defined for the Janz drivers which contains the actual bytes. Since this class may be used to post/send messages to multiple CANbusses controlled by multiple processes on a single linux host, it was necessary to define the concept of a busId which uniquely identifies which bus a message was read from or will be posted to. BusIds are generally assigned by the master class and are assured to be unique by deriving the busId number from the CAN device filename (e.g. /dev/dpm_00 = busId 0 whereas /dev/dpm_f0 = busId 31). Any user of this class must be careful to use the proper logic to assure that the BusId of a message exists and is being controlled by a CAN Master. This is generally handled by making sure you set the BusId of a tx msg to the same as a message received from the node you wish to communicate with (i.e. txMsg.setBusId(rxMsg.getBusId)). If this is not possible, but the device name is accessible, one can use the carma::canbus::extractBusId() routine, or the busId canbus::ALL_BUSSES. If a Message is addressed to a bus that doesn't exist an exception will be thrown when trying to post that message. The 29 bit CAN id itself is represented via a typedef carma::canbus::idType (a 4 byte unsigned integer), and the data is represented as a vector<carma::canbus::byteType>, where byteType is an unsigned one-byte character.

Definition at line 56 of file JanzMessage.h.

Member Enumeration Documentation

Message type definition.

Yes you will wonder 'messageTypeType?' - In CANbus parlance there are two message Types STANDARD and EXTENDED - this is a typedef to describe the CAN Message Type thus messageTypeType.

Definition at line 65 of file JanzMessage.h.

Constructor & Destructor Documentation

carma::canbus::JanzMessage::JanzMessage ( JanzMessage::messageTypeType  msgType = EXTENDED)

Default constructor.

Creates a Message with an id of 0 (all bits 0), busId 0, and no data.

carma::canbus::JanzMessage::JanzMessage ( carma::canbus::idType  id,
carma::canbus::busIdType  busId 
)

Create an extended message with specified id and busId.

Exceptions
CAN::Errorif the id is illegal (more than 29 bits).
carma::canbus::JanzMessage::JanzMessage ( carma::canbus::idType  id,
const std::vector< carma::canbus::byteType > &  data,
carma::canbus::busIdType  busId 
)

Create an extended message with the specified ids and data.

Exceptions
CAN::Errorif the id is illegal or the data contains more than 8 bytes.
carma::canbus::JanzMessage::JanzMessage ( carma::canbus::FastMessage  ,
carma::canbus::busIdType  busId 
)

Create a message from a Janz FastMessage.

carma::canbus::JanzMessage::JanzMessage ( const carma::canbus::Message message)

Create a JanzMessage from a Message.

carma::canbus::JanzMessage::JanzMessage ( const JanzMessage other)

Copy constructor.

Member Function Documentation

void carma::canbus::JanzMessage::disableTxRetry ( )

Set retry mode for message.

The Janz driver allows one to specify if the card should attempt to resend a message upon a transmit failure due to bus-errors or arbitration. By default, the CAN card will continuously try to send a message until either it succeeds or fails due to bus errors triggering the controller to shutdown. However, this isn't always desirable. In particular, we do not want the CAN controller to continuously try to resend a time sync if nobody is there to receive it (i.e. nobody is on the bus or the bus is disconnected from the linux host machine). The reasons for this are twofold. First, the timesyncs will continue to queue up until the controller is able to send them. If this continues long enough, the onboard queue will overflow. Second, when a module is connected to the bus, it will receive all queued timesync messages (which are nearly all bad) which in turn may overload and confuse the XACs timekeeping algorithms. In this case, it is desirable to disable retries using this method. Note also that the timesync message will almost never lose arbitration since it is (almost) the highest priority message in the system. The single caveat to this is the reset message (highest prio) in which case it doesn't matter anyway.

void carma::canbus::JanzMessage::enableEcho ( )

Echo this message.

Set the Echo flag on a message. This will cause the Janz board to echo the message back through the read queue once it has been sent on the bus. For the most part, this is useful for debugging only.

carma::canbus::busIdType carma::canbus::JanzMessage::getBusId ( ) const

Get CAN bus Id.

std::vector<carma::canbus::byteType> carma::canbus::JanzMessage::getData ( ) const

Get the data as a vector of bytes (raw).

carma::canbus::idType carma::canbus::JanzMessage::getId ( ) const

Get CAN message id.

Returns
CAN message id.
carma::canbus::JanzMessage::messageTypeType carma::canbus::JanzMessage::getMessageType ( ) const

Get message type.

CAN messages exist in two flavors: STANDARD (11 bit Id) and EXTENDED (29 bit Id). CARMA will use EXTENDED Ids by default but STANDARD functionality is included for completeness. Note the type must be established at object creation (no set type methods).

carma::canbus::portType carma::canbus::JanzMessage::getPort ( ) const

Get port number.

Only valid on multi-bus modules (E.G. CAN-PCI2), returns 0 on all others.

carma::canbus::FastMessage carma::canbus::JanzMessage::getRawMessage ( ) const

Return the underlying drivers raw message.

Needed so that BusIo can post a message.

double carma::canbus::JanzMessage::getRxMjd ( ) const

Return the Rx MJD time.

bool carma::canbus::JanzMessage::isSimulated ( ) const

Return simulated flag.

This method should be used to determine if the Message was artificially constructed for simulation purposes (i.e. not retrieved from or posted to a CAN bus).

Returns
True if message is simulated, false otherwise.
bool carma::canbus::JanzMessage::operator!= ( const JanzMessage other) const

Check for inequality.

JanzMessage& carma::canbus::JanzMessage::operator= ( const JanzMessage other)

Assignment operator.

bool carma::canbus::JanzMessage::operator== ( const JanzMessage other) const

Check for equality.

void carma::canbus::JanzMessage::setBusId ( carma::canbus::busIdType  busId)

Set bus Id.

void carma::canbus::JanzMessage::setData ( const std::vector< carma::canbus::byteType > &  data)

Set the data.

Exceptions
carma::canbus::BadDataSizeExceptionif the data contains more than 8 bytes.
void carma::canbus::JanzMessage::setId ( carma::canbus::idType  id)

Set CAN message id.

Exceptions
carma::canbus::BadParameterExceptionif id is illegal (more than 29 bits).
void carma::canbus::JanzMessage::setPort ( carma::canbus::portType  port)

Set port number.

Also only for use on multi-bus modules like CAN-PCI2.

Exceptions
carma::canbus::BadParameterExceptionif invalid port.
void carma::canbus::JanzMessage::setRxMjd ( double  mjd)

Set the rxMjd time.

void carma::canbus::JanzMessage::setSimFlag ( bool  sim)

Set the simulated flag.

This flag should be set if the message is being artificially created for simulation purposes (i.e. it isn't actually retrieved from or sent to the CAN bus). For the most part, it is set internally by the canbus::Master class.

Parameters
simTrue if message is simulated, false if not.

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