CANpie FD
CAN programming interface environment - Version 3.08
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Modules Pages
Signals | Public Member Functions
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().


Inherits QObject.

Signals

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

Public Member Functions

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

Constructor & Destructor Documentation

◆ QCanNetwork()

QCanNetwork::QCanNetwork ( QObject *  pclParentV = Q_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 CAN_Channel_e ubChannelR,
const QString &  clMessageR,
const LogLevel_e teLogLevelR = 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,
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  )
inline
Returns
Bit-rate value for Data Bit Timing
See also
setBitrate()

This function returns the data bit-rate of the CAN network. For classical 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  )
Returns
Bit-rate value for Data Bit Timing

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

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

◆ frameCount()

uint32_t QCanNetwork::frameCount ( void  )
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  )
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  )
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  )
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  )
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  )
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  )
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  )
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  )
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  )
inline
Returns
Bit-rate value for Nominal Bit Timing
See also
setBitrate()

This function returns the nominal bit-rate of the CAN network. For classical 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  )
Returns
Bit-rate value for Nominal Bit Timing

This function returns the nominal bit-rate of the CAN network as 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 ( int32_t  slNomBitRateV,
int32_t  slDatBitRateV = 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 Classical 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 ( 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 ( 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 ( 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 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 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 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 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()

CAN_State_e QCanNetwork::state ( void  )
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.