CAN programming interface environment
Version 3.10
Loading...
Searching...
No Matches
QCanNetwork Class Reference

Detailed Description

This class represents a CAN network with a unique bit-rate. It supports one physical CAN interface (see class QCanInterface), which can be attached during run-time to the CAN network and a limited number of virtual CAN interfaces (sockets).

Sockets

Clients can connect to a QCanNetwork via the QCanSocket class, either via a local socket or a WebSocket. The maximum number of available sockets is defined by QCAN_LOCAL_SOCKET_MAX and QCAN_WEB_SOCKET_MAX. It is only possible to connect to a network when it is enabled (see setNetworkEnabled() and isNetworkEnabled()).

CAN Interface

A physical CAN interface is attached to the network using the addInterface() function. It is started by calling startInterface(), which configures the actual bit-rate settings.

A physical CAN interface is stopped by calling stopInterface(), it can be removed from the network by calling removeInterface().


#include <qcan_network.hpp>

Inherits QObject.

Signals

void addLogMessage (const QCan::CAN_Channel_e &ubChannelR, const QString &clMessageR, const QCan::LogLevel_e &teLogLevelR=QCan::eLOG_LEVEL_WARN)
 
void showCanFrames (const QCan::CAN_Channel_e &ubChannelR, const uint32_t &ulFrameTotalR)
 
void showErrFrames (const QCan::CAN_Channel_e &ubChannelR, const uint32_t &ulFrameTotalR)
 
void showInterfaceState (const QCan::CAN_Channel_e &ubChannelR, const QCanInterface::ConnectionState_e &teConnectionStateR)
 
void showLoad (const QCan::CAN_Channel_e &ubChannelR, const uint8_t &ubLoadR, const uint32_t &ulMsgPerSecR)
 

Public Member Functions

 QCanNetwork (QObject *pclParentV=nullptr)
 
bool addInterface (QCanInterface *pclCanIfV)
 
void attachWebSocket (QWebSocket *pclSocketV, const enum SocketType_e teSocketTypeV=eSOCKET_TYPE_CAN_FRAME)
 
int32_t nominalBitrate (void) const
 
QString nominalBitrateString (void) const
 
int32_t dataBitrate (void) const
 
QString dataBitrateString (void) const
 
uint32_t frameCount (void) const
 
uint32_t frameCountError (void) const
 
bool hasErrorFrameSupport (void) const
 
bool hasFlexibleDataSupport (void) const
 
bool hasListenOnlySupport (void) const
 
bool isErrorFrameEnabled (void) const
 
bool isFlexibleDataEnabled (void) const
 
bool isListenOnlyEnabled (void) const
 
bool isNetworkEnabled (void) const
 
void removeInterface (void)
 
void setBitrate (const int32_t slNomBitRateV, const int32_t slDatBitRateV=QCan::eCAN_BITRATE_NONE)
 
void setErrorFrameEnabled (const bool btEnableV=true)
 
void setFlexibleDataEnabled (const bool btEnableV=true)
 
void setInterfaceConfiguration (void)
 
void setNetworkEnabled (const bool btEnableV=true)
 
bool startInterface (void)
 
bool stopInterface (void)
 
QCan::CAN_State_e state (void) const
 

Constructor & Destructor Documentation

◆ QCanNetwork()

QCanNetwork::QCanNetwork ( QObject * pclParentV = nullptr)
Parameters
[in]pclParentVPointer to QObject parent class

Create new CAN network with unique channel number.

Member Function Documentation

◆ addInterface()

bool QCanNetwork::addInterface ( QCanInterface * pclCanIfV)
Parameters
[in]pclCanIfVPointer to CAN interface class
Returns
true if CAN interface added successfully
See also
removeInterface()

The function adds a physical CAN interface to the CAN network. Each CAN network supports only one physical CAN interface. The CAN interface is removed from the network by calling the removeInterface() method. The parameter pclCanIfV is a pointer to an instance of a QCanInterface class.

The function returns true if the CAN interface is added, otherwise it will return false.

◆ addLogMessage

void QCanNetwork::addLogMessage ( const QCan::CAN_Channel_e & ubChannelR,
const QString & clMessageR,
const QCan::LogLevel_e & teLogLevelR = QCan::eLOG_LEVEL_WARN )
signal
Parameters
[in]ubChannelRCAN channel
[in]clMessageRLogging message
[in]teLogLevelRLogging level

This signal is emitted by the CAN network to inform the application about status changes or error conditions.

◆ attachWebSocket()

void QCanNetwork::attachWebSocket ( QWebSocket * pclSocketV,
const enum SocketType_e teSocketTypeV = eSOCKET_TYPE_CAN_FRAME )
Parameters
[in]pclSocketVPointer to WebSocket
[in]teSocketTypeVWebSocket type

This function attaches a WebSocket to the CAN network. The WebSocket can either be used to exchange CAN frames or to retrieve and alter the CAN network settings. The WebSocket type is defined by the parameter teSocketTypeV.

◆ dataBitrate()

int32_t QCanNetwork::dataBitrate ( void ) const
inline
Returns
Bit rate value for data bit-timing
See also
setBitrate()

This function returns the data bit rate of the CAN network. For Classic CAN, the return value is always CANpie::eCAN_BITRATE_NONE. For CAN FD the return value defines the bit rate for the data phase.

If no bit rate is configured, the function will return QCan::eCAN_BITRATE_NONE.

◆ dataBitrateString()

QString QCanNetwork::dataBitrateString ( void ) const
Returns
Bit rate value for data bit-timing

This function returns the data bit rate of the CAN network as a QString.

If no bit rate is configured, the function will return "None".

◆ frameCount()

uint32_t QCanNetwork::frameCount ( void ) const
inline
Returns
Number of CAN frames

This function returns the actual number of CAN frames that have been transmitted via the network.

◆ frameCountError()

uint32_t QCanNetwork::frameCountError ( void ) const
inline
Returns
Number of Error frames

This function returns the actual number of error frames that have been transmitted via the network.

◆ hasErrorFrameSupport()

bool QCanNetwork::hasErrorFrameSupport ( void ) const
Returns
true if error frames are supported
See also
isErrorFrameEnabled()

This function returns true if the attached CAN interface supports the evaluation of error frames, otherwise it returns false.

◆ hasFlexibleDataSupport()

bool QCanNetwork::hasFlexibleDataSupport ( void ) const
Returns
true if CAN FD is supported
See also
isFlexibleDataEnabled()

This function returns true if the attached CAN interface supports CAN FD frames, otherwise it returns false.

◆ hasListenOnlySupport()

bool QCanNetwork::hasListenOnlySupport ( void ) const
Returns
true if listen-only is supported
See also
isListenOnlyEnabled()

This function returns true if the attached CAN interface supports listen-only mode, otherwise it returns false.

◆ isErrorFrameEnabled()

bool QCanNetwork::isErrorFrameEnabled ( void ) const
inline
Returns
true if handling of error frames is enabled
See also
setErrorFrameEnabled()

This function returns true if handling of error frames is enabled, otherwise it returns false.

◆ isFlexibleDataEnabled()

bool QCanNetwork::isFlexibleDataEnabled ( void ) const
inline
Returns
true if CAN FD is enabled
See also
setFlexibleDataEnabled()

This function returns true if CAN FD mode is enabled, otherwise it returns false.

◆ isListenOnlyEnabled()

bool QCanNetwork::isListenOnlyEnabled ( void ) const
inline
Returns
true if listen-only is enabled
See also
setListenOnlyEnabled()

This function returns true if listen-only mode is enabled, otherwise it returns false.

◆ isNetworkEnabled()

bool QCanNetwork::isNetworkEnabled ( void ) const
inline
Returns
true if network is enabled
See also
setNetworkEnabled()

This function returns true if the network is enabled, otherwise it returns false.

◆ nominalBitrate()

int32_t QCanNetwork::nominalBitrate ( void ) const
inline
Returns
Bit rate value for nominal bit-timing
See also
setBitrate()

This function returns the nominal bit rate of the CAN network. For Classic CAN, the return value defines the bit rate for the complete frame. For CAN FD the return value defines the bit rate for the arbitration phase.

If no bit rate is configured, the function will return QCan::eCAN_BITRATE_NONE.

◆ nominalBitrateString()

QString QCanNetwork::nominalBitrateString ( void ) const
Returns
Bit rate value for nominal bit-timing

This function returns the nominal bit rate of the CAN network as a QString object.

If no bit-rate is configured, the function will return "None".

◆ removeInterface()

void QCanNetwork::removeInterface ( void )
See also
addInterface()

Remove a physical CAN interface from the CAN network.

◆ setBitrate()

void QCanNetwork::setBitrate ( const int32_t slNomBitRateV,
const int32_t slDatBitRateV = QCan::eCAN_BITRATE_NONE )
Parameters
[in]slNomBitRateVNominal bit rate value
[in]slDatBitRateVData bit rate value
See also
dataBitrate(), nominalBitrate()

This function sets the bit rate for the CAN network. For Classic CAN, the parameter slNomBitRateV defines the bit rate for the complete frame; the parameter slDatBitRateV is not evaluated in that case. For CAN FD the parameter slNomBitRateV defines the bit rate for the arbitration phase; the parameter slDatBitRateV defines the bit rate for the data phase.

For selection of predefined bit rates the value can be taken from the enumeration CANpie::CAN_Bitrate_e.

◆ setErrorFrameEnabled()

void QCanNetwork::setErrorFrameEnabled ( const bool btEnableV = true)
Parameters
[in]btEnableVEnable / disable error frames
See also
isErrorFrameEnabled()

This function enables the dispatching of CAN error frames if btEnable is true, it is disabled on false.

◆ setFlexibleDataEnabled()

void QCanNetwork::setFlexibleDataEnabled ( const bool btEnableV = true)
Parameters
[in]btEnableVEnable / disable CAN FD mode
See also
isFlexibleDataEnabled()

This function enables the CAN FD mode if btEnable is true, it is disabled on false.

◆ setInterfaceConfiguration()

void QCanNetwork::setInterfaceConfiguration ( void )

Perform a device specific interface configuration. This function is only executed if a CAN interface has been added to the network (refer to addInterface()).

◆ setNetworkEnabled()

void QCanNetwork::setNetworkEnabled ( const bool btEnableV = true)
Parameters
[in]btEnableVEnable / disable network
See also
isNetworkEnabled()

This function enables the dispatching of CAN frames if btEnable is true, it is disabled on false.

◆ showCanFrames

void QCanNetwork::showCanFrames ( const QCan::CAN_Channel_e & ubChannelR,
const uint32_t & ulFrameTotalR )
signal
Parameters
[in]ubChannelRCAN channel
[in]ulFrameTotalRTotal number of frames

This signal is emitted every second. The parameter ulFrameTotalV denotes the total number of CAN frames.

◆ showErrFrames

void QCanNetwork::showErrFrames ( const QCan::CAN_Channel_e & ubChannelR,
const uint32_t & ulFrameTotalR )
signal
Parameters
[in]ubChannelRCAN channel
[in]ulFrameTotalRTotal number of frames

This signal is emitted every second. The parameter ulFrameTotalV denotes the total number of CAN error frames.

◆ showInterfaceState

void QCanNetwork::showInterfaceState ( const QCan::CAN_Channel_e & ubChannelR,
const QCanInterface::ConnectionState_e & teConnectionStateR )
signal
Parameters
[in]ubChannelRCAN channel
[in]teConnectionStateRConnection state of CAN interface

This signal is once upon a connection state change of a physical CAN interface.

◆ showLoad

void QCanNetwork::showLoad ( const QCan::CAN_Channel_e & ubChannelR,
const uint8_t & ubLoadR,
const uint32_t & ulMsgPerSecR )
signal
Parameters
[in]ubChannelRCAN channel
[in]ubLoadRBus load in percent
[in]ulMsgPerSecRMessages per second

This signal is emitted every second. The parameter ubLoadV denotes the bus load in percent (value range 0 .. 100).

◆ startInterface()

bool QCanNetwork::startInterface ( void )
Returns
true if CAN interface is started
See also
addInterface()

The function starts a physical CAN interface. The interface must have been attached to the network using addInterface() in advance.

The function returns true if the CAN interface is started, otherwise it will return false.

◆ state()

QCan::CAN_State_e QCanNetwork::state ( void ) const
inline
Returns
State of CAN network

The function returns the CAN state of the network.

◆ stopInterface()

bool QCanNetwork::stopInterface ( void )
Returns
true if CAN interface is stopped
See also
addInterface()

The function stops a physical CAN interface. The interface must have been attached to the network using addInterface() in advance.

The function returns true if the CAN interface is stopped, otherwise it will return false.