CARMA C++
carma::canbus Namespace Reference

This namespace contains all canbus library related code. More...

Classes

struct  busStatusStruct
 Bus Status type. More...
 
class  CanDio
 Class to control the CARMA specialized Janz CAN/DIO card. More...
 
class  CanIo
 CanIo interface. More...
 
class  CanOutput
 CanOutput interface. More...
 
class  Device
 Abstract base class for all CAN Bus devices. More...
 
class  DeviceNames
 Completely static class to retrieve string names of CAN devices based on API Id. More...
 
class  Dio
 Dio abstract base class. More...
 
class  DirectCan
 The DirectCan class is intended for use as a way to access the CANbus from multiple separate processes in conjunction with a process implementing the DO model. More...
 
class  GpioDio
 GpioDio class for use with gpio framework. More...
 
class  InetCan
 InetCan class. More...
 
class  JanzCanIo
 JanzCanIo class. More...
 
class  JanzDio
 Dio class for use with Janz char driver. More...
 
class  JanzMessage
 This class encapsulate a Janz CAN message. More...
 
class  Master
 Carma Canbus Master class. More...
 
class  MasterOfNone
 Carma CAN MasterOfNone class. More...
 
class  Message
 Class to encapsulate a CAN message. More...
 
class  SocketCan
 Implements the CanIo interface using the socketcan framework. More...
 

Typedefs

typedef unsigned short apiType
 Carma API id type. More...
 
typedef unsigned short boardType
 Carma Board Type id type. More...
 
typedef unsigned short busIdType
 Carma Bus Id type. More...
 
typedef enum
carma::canbus::busStateEnum 
busStateType
 Bus State type. More...
 
typedef std::map< busIdType,
busStatusType
BusStatusMap
 Map to hold bus status for multiple busses. More...
 
typedef struct
carma::canbus::busStatusStruct 
busStatusType
 Bus Status type. More...
 
typedef unsigned char BYTE_t
 
typedef unsigned char byteType
 Base raw CAN byte. More...
 
typedef ::std::vector
< ::carma::canbus::byteType
DataVector
 Alias for CAN data. More...
 
typedef enum
carma::canbus::deviceStateEnum 
deviceStateType
 
typedef unsigned int idType
 Type for full 29 bit CAN id. More...
 
typedef unsigned int keyType
 Unique key identifier for each device. More...
 
typedef enum
carma::canbus::modeTypeEnum 
modeType
 Mode type. More...
 
typedef ::std::map
< ::carma::canbus::msgType,::std::string > 
MsgBriefMap
 Alias for message descriptions keyed by message id. More...
 
typedef ::std::map
< ::carma::canbus::msgType,::std::string > 
MsgIdInfoMap
 Alias for an ::std::map containing a string description of a message id, keyed by the described carma::canbus::msgType message id. More...
 
typedef unsigned short msgType
 Carma Message id type. More...
 
typedef unsigned short nodeType
 Carma Node Type id type. More...
 
typedef unsigned short portType
 Port id type for multi-port boards. More...
 
typedef unsigned short serialNumberType
 Carma Serial Number type. More...
 

Enumerations

enum  busStateEnum { NO_ERRORS = 0, ERROR_ACTIVE = 1, ERROR_PASSIVE = 2, BUS_OFF = 3 }
 Bus State type. More...
 
enum  deviceStateEnum { OFFLINE, STARTING, ONLINE, SIMULATED }
 Device state type enumeration. More...
 
enum  modeTypeEnum { ENGINEERING = 1, APPLICATION = 0 }
 Mode type. More...
 
enum  txPriorityType { HIGH = 1, NORMAL = 2, LOW = 3 }
 CAN Tx priority type. More...
 

Functions

timespec calculateTimeToNextHalfSec ()
 Calculate the time to the next half second boundary. More...
 
timespec calculateTimeToNextSlowBoundary ()
 Calculate the time to the next five second boundary. More...
 
idType createEngId (bool host, boardType board, serialNumberType serialNumber, msgType mid)
 Produce a CAN message from a board type and serial number (engineering message). More...
 
idType createId (bool host, apiType api, nodeType node, msgType mid)
 Create a CAN id from api, node and mid. More...
 
double dataToDouble (std::vector< byteType > &data)
 Convert data vector to IEEE double. More...
 
float dataToFloat (std::vector< byteType > &data)
 Convert data vector to IEEE float. More...
 
long dataToLong (std::vector< byteType > &data)
 Convert data vector to signed long integer. More...
 
short dataToShort (std::vector< byteType > &data)
 Convert data vector to signed short integer. More...
 
unsigned char dataToUbyte (std::vector< byteType > &data)
 Convert data vector to unsigned byte. More...
 
unsigned long dataToUlong (std::vector< byteType > &data)
 Convert data vector to unsigned long integer. More...
 
unsigned short dataToUshort (std::vector< byteType > &data)
 Convert data vector to unsigned short integer. More...
 
void doubleToData (std::vector< byteType > &data, double value)
 Convert a IEEE 754-1990 double float (8 bytes) into raw CAN bytes. More...
 
busIdType extractBusId (std::string filename)
 Extract the busId from a string containing the device filename. More...
 
void floatToData (std::vector< byteType > &data, float value)
 Convert a IEEE 754-1990 float (4 bytes) into raw CAN bytes. More...
 
void fromEngId (boardType &bt, serialNumberType &sn, msgType &mid, idType engId)
 Convert a raw CAN id to board type, serial number and mid. More...
 
void fromId (apiType &api, nodeType &node, msgType &mid, idType id)
 Convert a raw CAN id to api code, node location and mid. More...
 
modeType getMode (idType id)
 Extract the address mode from a 29 bit can id. More...
 
bool isToHost (idType id)
 Extract the host bit from a 29 bit CAN id. More...
 
 MAKE_DERIVED_ERROR_EXCEPTION (SystemException)
 
 MAKE_DERIVED_ERROR_EXCEPTION (TxBufferFullException)
 
 MAKE_DERIVED_ERROR_EXCEPTION (BadDataSizeException)
 
 MAKE_DERIVED_ERROR_EXCEPTION (BadParameterException)
 
 MAKE_DERIVED_ERROR_EXCEPTION (BufferOverflowException)
 
 MAKE_DERIVED_ERROR_EXCEPTION (JanzFailException)
 
 MAKE_DERIVED_ERROR_EXCEPTION (PthreadFailException)
 
void padWithZeros (std::vector< byteType > &data)
 Pad an input vector with up to 8 bytes of zeros. More...
 
void sLongToData (std::vector< byteType > &data, long value)
 Convert a signed long integer (4 bytes) into raw CAN bytes. More...
 
void sShortToData (std::vector< byteType > &data, short value)
 Convert a signed short integer (2 bytes) into raw CAN bytes. More...
 
void uByteToData (std::vector< byteType > &data, unsigned char value)
 Convert a unsigned char into raw CAN bytes. More...
 
void uLongToData (std::vector< byteType > &data, unsigned long value)
 Convert an unsigned long integer (4 bytes) into raw CAN bytes. More...
 
void uShortToData (std::vector< byteType > &data, unsigned short value)
 Convert an unsigned short integer (2 bytes) into raw CAN bytes. More...
 
int validateModulbusNo (int modulbusNo)
 Validate a modulbusNo. More...
 
int validateSlotNo (int slotNo)
 Validate slot number for CANbus slot. More...
 

Variables

const busIdType ALL_BUSSES = 0xffff
 Specifies that a message should be sent to ALL_BUSSES. More...
 
const std::string CAN_INPUT_IPQ = "/can-input.ipq"
 
const std::string CAN_OUTPUT_IPQ = "/can-output.ipq"
 
const apiType DUMMY_PKT_API = 0xFF
 Dummy packet api. More...
 
const msgType DUMMY_PKT_MID = 0x3FF
 Dummy packet message id. More...
 
const long IPQ_BUFFER_SIZE = 150000
 DirectCan IPQ buffer sizes. More...
 
const int NANOSECS_PER_SEC = 1000000000
 
const bool TO_HOST = true
 Constant for bool host parameter of createId indicating that the message is to be addressed to the linux host. More...
 
const bool TO_NODES = false
 Constant for bool host parameter of createId indicating that the message is to be addressed to the can nodes on the bus. More...
 

Detailed Description

This namespace contains all canbus library related code.

Typedef Documentation

typedef unsigned short carma::canbus::apiType

Carma API id type.

Definition at line 64 of file Types.h.

typedef unsigned short carma::canbus::boardType

Carma Board Type id type.

Definition at line 65 of file Types.h.

typedef unsigned short carma::canbus::busIdType

Carma Bus Id type.

Definition at line 70 of file Types.h.

Bus State type.

The Bus states are standard CAN bus states which are defined by the number of rx or tx errors recorded by the CAN controller.

Map to hold bus status for multiple busses.

Definition at line 153 of file Types.h.

Bus Status type.

Bus status contains variables useful for determining the health of the bus. They are maintained by CanIo

See Also
carma::canbus::CanIo
typedef unsigned char carma::canbus::byteType

Base raw CAN byte.

Definition at line 61 of file Types.h.

Alias for CAN data.

Definition at line 72 of file Types.h.

typedef unsigned int carma::canbus::idType

Type for full 29 bit CAN id.

Definition at line 60 of file Types.h.

typedef unsigned int carma::canbus::keyType

Unique key identifier for each device.

Definition at line 68 of file Types.h.

Mode type.

The mode type is extracted from the CAN id. It is a single bit and designates how the application should interpret the 29 bit CAN id.

typedef ::std::map< ::carma::canbus::msgType, ::std::string > carma::canbus::MsgBriefMap

Alias for message descriptions keyed by message id.

Definition at line 74 of file Types.h.

typedef ::std::map< ::carma::canbus::msgType, ::std::string > carma::canbus::MsgIdInfoMap

Alias for an ::std::map containing a string description of a message id, keyed by the described carma::canbus::msgType message id.

Definition at line 30 of file Device.h.

typedef unsigned short carma::canbus::msgType

Carma Message id type.

Definition at line 69 of file Types.h.

typedef unsigned short carma::canbus::nodeType

Carma Node Type id type.

Definition at line 66 of file Types.h.

typedef unsigned short carma::canbus::portType

Port id type for multi-port boards.

Definition at line 62 of file Types.h.

typedef unsigned short carma::canbus::serialNumberType

Carma Serial Number type.

Definition at line 67 of file Types.h.

Enumeration Type Documentation

Bus State type.

The Bus states are standard CAN bus states which are defined by the number of rx or tx errors recorded by the CAN controller.

Enumerator
NO_ERRORS 

Rx and tx error count = 0.

ERROR_ACTIVE 

Rx and tx error count < 127.

ERROR_PASSIVE 

Rx and tx error count < 255.

BUS_OFF 

Rx and tx error count = 255.

Definition at line 110 of file Types.h.

Device state type enumeration.

Defines the various states of a CAN device.

Enumerator
OFFLINE 

Monitor packets are not being received from the module.

STARTING 

The module has sent out a single slow monitor packet to identify itself.

The module should begin sending normal blanking frame packets after about five seconds.

ONLINE 

Host is receiving CAN messages on a half second time scale.

SIMULATED 

Host is simulating the receipt of monitor packets for this module.

Definition at line 183 of file Types.h.

Mode type.

The mode type is extracted from the CAN id. It is a single bit and designates how the application should interpret the 29 bit CAN id.

Enumerator
ENGINEERING 

Decode CAN Id in serial num, board type form.

APPLICATION 

Decode CAN id in API, Node form.

Definition at line 99 of file Types.h.

CAN Tx priority type.

CAN messages are sent via prioritized queues.

Definition at line 194 of file Types.h.

Function Documentation

timespec carma::canbus::calculateTimeToNextHalfSec ( )

Calculate the time to the next half second boundary.

This routine calculates the amount of time necessary to sleep until the next half second boundary as determined by absolute time.

Returns
timespec containing amount of time to sleep until next half second boundary.
timespec carma::canbus::calculateTimeToNextSlowBoundary ( )

Calculate the time to the next five second boundary.

This routine calculates the amount of time necessary to sleep until the next five second boundary as determined by absolute time.

Returns
timespec containing amount of time to sleep until next five second boundary.
idType carma::canbus::createEngId ( bool  host,
boardType  board,
serialNumberType  serialNumber,
msgType  mid 
)

Produce a CAN message from a board type and serial number (engineering message).

Parameters
hostsend to host.
boardthe board id being addressed.
serialNumberof board being addressed.
midmessage id.
Returns
29 bit CAN id.
idType carma::canbus::createId ( bool  host,
apiType  api,
nodeType  node,
msgType  mid 
)

Create a CAN id from api, node and mid.

Creates an application message from the api, node and message id addressed to either the host or nodes.

Parameters
hostaddressed to host or nodes.
apiid.
nodemessage node location id.
midof message.
double carma::canbus::dataToDouble ( std::vector< byteType > &  data)

Convert data vector to IEEE double.

This routine interprets the first 8 bytes of a vector of raw CAN data as an IEEE double floating point value. It then extracts, converts and returns the double.

Parameters
datais the vector to extract the double from.
Returns
double.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is < than 8 bytes.
float carma::canbus::dataToFloat ( std::vector< byteType > &  data)

Convert data vector to IEEE float.

This routine interprets the first 4 bytes of a vector of raw CAN data as an IEEE floating point value. It then extracts, converts and returns the float.

Parameters
datais the vector to extract the float from.
Returns
float.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is < than 4 bytes.
long carma::canbus::dataToLong ( std::vector< byteType > &  data)

Convert data vector to signed long integer.

This routine interprets the first 4 bytes of a vector of raw CAN data as an signed long integer in network byte order. It then extracts, converts and returns the signed int.

Parameters
datais the vector to extract the signed long from.
Returns
signed long.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is < than 4 bytes.
short carma::canbus::dataToShort ( std::vector< byteType > &  data)

Convert data vector to signed short integer.

This routine interprets the first 2 bytes of a vector of raw CAN data as an signed short integer in network byte order. It then extracts, converts and returns the signed int.

Parameters
datais the vector to extract the signed short from.
Returns
unsigned long.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is < than 2 bytes.
unsigned char carma::canbus::dataToUbyte ( std::vector< byteType > &  data)

Convert data vector to unsigned byte.

This routine interprets the first byte of a vector of raw CAN data as an unsigned byte and returns the byte.

Parameters
datais the vector to extract the unsigned byte from.
Returns
unsigned byte.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is empty.
unsigned long carma::canbus::dataToUlong ( std::vector< byteType > &  data)

Convert data vector to unsigned long integer.

This routine interprets the first 4 bytes of a vector of raw CAN data as an unsigned long integer in network byte order. It then extracts, converts and returns the unsigned int.

Parameters
datais the vector to extract the unsigned long from.
Returns
unsigned long.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is < than 4 bytes.
unsigned short carma::canbus::dataToUshort ( std::vector< byteType > &  data)

Convert data vector to unsigned short integer.

This routine interprets the first 2 bytes of a vector of raw CAN data as an unsigned short integer in network byte order. It then extracts, converts and returns the unsigned int.

Parameters
datais the vector to extract the unsigned short from.
Returns
unsigned short.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is < than 2 bytes.
void carma::canbus::doubleToData ( std::vector< byteType > &  data,
double  value 
)

Convert a IEEE 754-1990 double float (8 bytes) into raw CAN bytes.

This routine takes an input double float value and adds it to the input vector of raw CAN bytes in network byte order. This enables one to build a full CAN data packet by consecutively calling the appropriate typeToData routine.

Parameters
datais the vector to append the data to.
valueis the double to append to the data.
Exceptions
carma::canbus::BadDataSizeExceptionif resulting vector is > than 8 bytes.
busIdType carma::canbus::extractBusId ( std::string  filename)

Extract the busId from a string containing the device filename.

In order to maintain unique busIds on a multiprocess multi canbus system, I use the can device filename to determine the bus Id.

Exceptions
carma::canbus::BadParameterExceptionif input filename is invalid.
void carma::canbus::floatToData ( std::vector< byteType > &  data,
float  value 
)

Convert a IEEE 754-1990 float (4 bytes) into raw CAN bytes.

This routine takes an input floating point value and adds it to the input vector of raw CAN bytes in network byte order. This enables one to build a full CAN data packet by consecutively calling the appropriate typeToData routine.

Parameters
datais the vector to append the data to.
valueis the float to append to the data.
Exceptions
carma::canbus::BadDataSizeExceptionif resulting vector is > than 8 bytes.
void carma::canbus::fromEngId ( boardType &  bt,
serialNumberType &  sn,
msgType &  mid,
idType  engId 
)

Convert a raw CAN id to board type, serial number and mid.

Parameters
btboard type id.
snserial number id.
midmessage id.
engIdfull Engineering CAN message id.
void carma::canbus::fromId ( apiType &  api,
nodeType &  node,
msgType &  mid,
idType  id 
)

Convert a raw CAN id to api code, node location and mid.

Parameters
apiapi id.
nodenode id.
midmessage id.
idfull CAN message id.
modeType carma::canbus::getMode ( idType  id)

Extract the address mode from a 29 bit can id.

Parameters
id29 bit CAN address.
Returns
address mode ENGINEERING or APPLICATION.
bool carma::canbus::isToHost ( idType  id)

Extract the host bit from a 29 bit CAN id.

Parameters
id29 bit CAN address.
Returns
host bit (true = message addressed to host).
void carma::canbus::padWithZeros ( std::vector< byteType > &  data)

Pad an input vector with up to 8 bytes of zeros.

This routine takes the input data, calculates it's size and fills the remaining space with up to 8 bytes of '0's. For example a single byte data vector, after being input to this routine, will contain the original data and 7 '0's.

Parameters
datareference to vector to be stuffed with '0's.
Exceptions
carma::canbus::BadDataSizeExceptionif data vector is > than 8 bytes.
void carma::canbus::sLongToData ( std::vector< byteType > &  data,
long  value 
)

Convert a signed long integer (4 bytes) into raw CAN bytes.

This routine takes an input signed long integer value and adds it to the input vector of raw CAN bytes in network byte order. This enables one to build a full CAN data packet by consecutively calling the appropriate typeToData routine.

Parameters
datais the vector to append the data to.
valueis the signed long int to append to data.
Exceptions
carma::canbus::BadDataSizeExceptionif resulting vector is > than 8 bytes.
void carma::canbus::sShortToData ( std::vector< byteType > &  data,
short  value 
)

Convert a signed short integer (2 bytes) into raw CAN bytes.

This routine takes an input signed short integer value and adds it to the input vector of raw CAN bytes in network byte order. This enables one to build a full CAN data packet by consecutively calling the appropriate typeToData routine.

Parameters
datais the vector to append the data to.
valueis the signed short int to append to data.
Exceptions
carma::canbus::BadDataSizeExceptionif resulting vector is > than 8 bytes.
void carma::canbus::uByteToData ( std::vector< byteType > &  data,
unsigned char  value 
)

Convert a unsigned char into raw CAN bytes.

This routine takes an input unsigned char value and adds it to the input vector of raw CAN bytes. This enbables one to build a full CAN data packet by consecutively calling the appropriate typeToData routine.

Parameters
datais a reference to a vector which the data will be appended to.
datais the vector to append the data to.
valueis the unsigned char to be appended to data.
Exceptions
carma::canbus::BadDataSizeExceptionif resulting vector is > than 8 bytes.
void carma::canbus::uLongToData ( std::vector< byteType > &  data,
unsigned long  value 
)

Convert an unsigned long integer (4 bytes) into raw CAN bytes.

This routine takes an input unsigned long integer value and adds it to the input vector of raw CAN bytes in network byte order. This enables one to build a full CAN data packet by consecutively calling the appropriate typeToData routine.

Parameters
datais the vector to append the data to.
valueis the unsigned long int to append to data.
Exceptions
carma::canbus::BadDataSizeExceptionif resulting vector is > than 8 bytes.
void carma::canbus::uShortToData ( std::vector< byteType > &  data,
unsigned short  value 
)

Convert an unsigned short integer (2 bytes) into raw CAN bytes.

This routine takes an input unsigned short integer value and adds it to the input vector of raw CAN bytes in network byte order. This enables one to build a full CAN data packet by consecutively calling the appropriate typeToData routine.

Parameters
datais the vector to append the data to.
valueis the unsigned short int to append to data.
Exceptions
carma::canbus::BadDataSizeExceptionif resulting vector is > than 8 bytes.
int carma::canbus::validateModulbusNo ( int  modulbusNo)

Validate a modulbusNo.

The janz modulbus hardware has a hex switch to designate the modulbus id of the board. This routine, checks to make sure that a modulbusNo is within the range of 0x00 to 0x0f.

Parameters
modulbusNoto validate.
Returns
modulbusNo if validated.
Exceptions
carma::canbus::BadParameterExceptionif invalid modulbusNo.
int carma::canbus::validateSlotNo ( int  slotNo)

Validate slot number for CANbus slot.

The specialized janz CANDio card contains CANbus cards in modulbus slots 0 and 1 only. This routine checks to make sure that a input slot number is within that range and throws an exception otherwise.

Parameters
slotNoto validate.
Returns
slotNo if valid.
Exceptions
carma::canbus::BadParameterExceptionif invalid slotNo.

Variable Documentation

const busIdType carma::canbus::ALL_BUSSES = 0xffff

Specifies that a message should be sent to ALL_BUSSES.

Definition at line 91 of file Types.h.

const apiType carma::canbus::DUMMY_PKT_API = 0xFF

Dummy packet api.

This api id is reserved for dummy messages.

Definition at line 80 of file Types.h.

const msgType carma::canbus::DUMMY_PKT_MID = 0x3FF

Dummy packet message id.

This message id is reserved for dummy messages.

Definition at line 86 of file Types.h.

const long carma::canbus::IPQ_BUFFER_SIZE = 150000

DirectCan IPQ buffer sizes.

Definition at line 213 of file Types.h.

const bool carma::canbus::TO_HOST = true

Constant for bool host parameter of createId indicating that the message is to be addressed to the linux host.

Definition at line 45 of file Utilities.h.

const bool carma::canbus::TO_NODES = false

Constant for bool host parameter of createId indicating that the message is to be addressed to the can nodes on the bus.

Definition at line 51 of file Utilities.h.