CARMA C++
|
#include <carma/canbus/JanzCanIo.h>
Public Types | |
typedef ::std::vector < ::std::pair< ::std::string, bool > > | NameTermPairVec |
Public Member Functions | |
void | clearReadQueue () |
Clear the read message queue. More... | |
void | echoAll (bool enable) |
Echo all messages posted to the canbus back through the read interface. More... | |
BusStatusMap | getBusStatus () const |
Get bus status for all busses. More... | |
carma::canbus::Message | getMessage () |
Retrieve a CAN message. More... | |
JanzCanIo () | |
Default constructor - for emulation only. More... | |
JanzCanIo (const char *deviceName, bool terminate) | |
Constructor for JanzCanIo object with single device. More... | |
JanzCanIo (const char *dev0, bool term0, const char *dev1, bool term1) | |
Constructor for JanzCanIo object controlling dual devices. More... | |
JanzCanIo (const NameTermPairVec &nameTermPairs) | |
Constructor for JanzCanIo object controlling an arbitrary number of CAN devices. More... | |
void | postMessage (const carma::canbus::Message &msg, carma::canbus::txPriorityType prio=carma::canbus::NORMAL) |
Post a CAN message. More... | |
void | queueMessage (const Message &msg) |
Place a carma::canbus::Message in the shared msg queue. More... | |
void | setTimestampEchoLatency (int tsLatency, busIdType busId) |
Set the timestamp echo latency for the specified bus. More... | |
virtual | ~JanzCanIo () |
Destructor for JanzCanIo object. More... | |
![]() | |
virtual | ~CanIo () |
Virtual destructor. More... | |
JanzCanIo class.
Performs all input and output with Janz CAN cards using Janz character driver. This driver is obsolete with the introduction of the Janz socketcan framework driver which is implemented in canbus::SocketCanIo.
The JanzCanIo class is meant for use with Janz VMOD-ICAN single port can modules. However, it can be used as well with CAN-PCI2 (Single device - dual port) cards although only Port 0 on the card will be accessible.
JanzCanIo can be used in several ways.
JanzCanIo can be used to control a single or multiple VMOD-ICAN devices with a single JanzCanIo object. This is reflected in the below single and double device constructors. In these cases, all CAN Messages are read from their respective devices, assigned a BusId (see below) and placed into a shared message queue for retrieval using the JanzCanIo::getMessage routine.
JanzCanIo may also be used with the below described default constructor for emulation. In this case, JanzCanIo will open /dev/null instead of a specified CAN device. All writes will be posted to /dev/null and reads will in general block forever. The single caveat to this is that a simulated Message object may be placed into the shared message queue using the JanzCanIo::queueMessage method. In this case, reads (i.e. getMessage) will return with the simulated message as if it had come directly from the CANbus.
BusId. It is important that any user of carma::canbus classes understand the concept of a BusId. The BusId is a unique Id assigned to each CANbus being controlled by JanzCanIo classes. The uniqueness of the Id is assured not only within a process but also within the context of any process on the linux host machine. This is accomplished by deriving the busId from the device filename. The most important thing to remember regarding BusIds is that any program logic that uses JanzCanIo to postMessages to a CANbus must set the busId correctly on the carma::canbus::Message object being posted. This is most easily done by setting the busId of a message to be posted to the same busId of a message already received from the device or node one wishes to talk to (e.g. txMsg.setBusId(rxMsg.getBusId)). If this isn't possible then the carma::canbus::extractBusId routine can be used to determine the busId from the filename or, the constant busId carma::canbus::ALL_BUSSES can be used to send the message to all busses. See carma::canbus::Message for more information.
Definition at line 79 of file JanzCanIo.h.
carma::canbus::JanzCanIo::JanzCanIo | ( | ) |
Default constructor - for emulation only.
This constructor is intended for use when no Janz hardware exists and the user wishes to emulate JanzCanIo. This is accomplished by opening /dev/null. Reads will block until a JanzCanIo derivative queues messages explicitly whereas writes will write to /dev/null.
carma::util::ErrorException | for a variety of situations. Several different exceptions can be thrown during construction. All exceptions are either util::ErrorException or canbus derivatives thereof. Catching util::ErrorException by reference and calling util::ErrorException.what() on it will reveal the full details. |
carma::canbus::JanzCanIo::JanzCanIo | ( | const char * | deviceName, |
bool | terminate | ||
) |
Constructor for JanzCanIo object with single device.
This constructor initializes a JanzCanIo object for use with a single VMOD-ICAN device.
deviceName,: | The name of the CAN device (e.g. /dev/dpm_00). |
terminate | Flag to control setting of onboard bus termination resistor. Set true if card is connected to the beginning or end of a CANbus (the last or first node). |
carma::util::ErrorException | for a variety of situations. Several different exceptions can be thrown during construction. All exceptions are either util::ErrorException or canbus derivatives thereof. Catching util::ErrorException by reference and calling util::ErrorException.what() on it will reveal the full details. |
carma::canbus::JanzCanIo::JanzCanIo | ( | const char * | dev0, |
bool | term0, | ||
const char * | dev1, | ||
bool | term1 | ||
) |
Constructor for JanzCanIo object controlling dual devices.
This constructor intializes a JanzCanIo object for use with two VMOD-ICAN devices.
dev0 | The name of the first CAN device to open (e.g. /dev/dpm_00) |
term0 | Flag to control setting of onboard bus termination resistor. Set true if card is connected to the beginning or end of a CAN bus. |
dev1 | The name of the second CAN device (e.g./dev/dpm_01) |
term1 | Termination flag (see term0 above). |
carma::util::ErrorException | for a variety of situations. Several different exceptions can be thrown during construction. All exceptions are either util::ErrorException or canbus derivatives thereof. Catching util::ErrorException by reference and calling util::ErrorException.what() on it will reveal the full details. |
carma::canbus::JanzCanIo::JanzCanIo | ( | const NameTermPairVec & | nameTermPairs | ) |
Constructor for JanzCanIo object controlling an arbitrary number of CAN devices.
Vector | of pairs containing dev name and bus termination. |
|
virtual |
Destructor for JanzCanIo object.
|
virtual |
Clear the read message queue.
Clear all messages waiting for retrieval in the internal message queue. This is useful for bus resets and should be done when the hardware is in a reset state and hence known not to be transmitting.
Reimplemented from carma::canbus::CanIo.
|
virtual |
Echo all messages posted to the canbus back through the read interface.
Typically, the ability to echo a posted message is set on the carma::canbus::Message object. However, often during debugging it is useful to echo every written message back through the read interface. This enables sent messages to be verified via canOverIp and DirectCan. This method enables echoing on all messages posted to the CANbus.
Reimplemented from carma::canbus::CanIo.
|
virtual |
Get bus status for all busses.
Reimplemented from carma::canbus::CanIo.
|
virtual |
Retrieve a CAN message.
This routine retrieves a message from the shared CAN message queue. When a message is received, it is retrieved from it's respective device and placed into a shared canbus::Message queue. This routine blocks until a message is available. If the JanzCanIo object is using the default constructor for emulation, this method blocks forever, or until a message is explicitly placed into the queue using JanzCanIo::queueMessage.
carma::canbus::PthreadFailException | on condition timeout error. Unrecoverable. |
Implements carma::canbus::CanIo.
|
virtual |
Post a CAN message.
This routine sends a carma::canbus::Message to a single or multiple CANbusses. The bus which the message will be posted to must be specified in the Message object using the Message::setBusId method. If a user wishes to send the message to all busses controlled by JanzCanIo, use the carma::canbus::ALL_BUSSES constant. If no modules are on a bus to receive a message, messages will remain in onboard buffers until a module is connected to accept them. If this onboard buffer fills up, postMessage will throw an exception.
msg | carma::canbus::Message object. |
prio | carma::canbus::txPriorityType of message. |
carma::canbus::TxBufferFullException | if unable to post message due to a full transmit buffer. This is likely due to a disconnected bus. Message is dropped. |
carma::util::ErrorException | for a variety of other unrecoverable problems. This error generally signals a programming error, or a misconfigured system. |
Implements carma::canbus::CanOutput.
|
virtual |
Place a carma::canbus::Message in the shared msg queue.
This method is provided so that a simulator in an inherited class may place 'CAN' Messages into the queue as if they had been received from the CANbus. Subsequently, any blocks on JanzCanIo::getMessage will return with the queued message.
msg | carma::canbus::Message object to queue. |
Reimplemented from carma::canbus::CanIo.
|
virtual |
Set the timestamp echo latency for the specified bus.
The timestamp echo latency is the time elapsed from the creation of the timestamp to the time it is read back from the read interface (timestamp messages are echoed).
Reimplemented from carma::canbus::CanIo.