semf
semf::CanHardware Class Referenceabstract

Interface for using CAN. More...

#include <canhardware.h>

Inheritance diagram for semf::CanHardware:
Inheritance graph
Collaboration diagram for semf::CanHardware:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Write_IsBusy = 0 , Write_DataIsNullptr , Write_DataSizeIsZero , Read_DataIsNullptr ,
  Read_DataSizeIsZero , Request_IsBusy
}
 Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring). More...
 
- Public Types inherited from semf::CommunicationHardware
enum class  Type { SynchronousMaster = 1 , SynchronousSlave , Asynchronous }
 
enum class  Frame : uint8_t { First = 0x01 , Next = 0x08 , Last = 0x10 , FirstAndLast = 0x11 }
 

Public Member Functions

virtual ~CanHardware ()=default
 
void write (const uint8_t data[], size_t dataSize) override
 For writing data, dataWritten signal will be emitted after successful write. More...
 
void read (uint8_t buffer[], size_t bufferSize) override
 For setting the read buffer. This has be done for getting a dataAvailable signal for handling the data. More...
 
bool isBusyReading () const override
 Communication hardware is busy reading at the moment. More...
 
bool isBusyWriting () const override
 Communication hardware is busy writing at the moment. More...
 
void request () override
 
- Public Member Functions inherited from semf::Can
virtual ~Can ()=default
 
virtual void request ()=0
 
virtual uint32_t messageId () const =0
 Returns the message ID for reading data. Use this function after reading the data via read-function. More...
 
virtual void setMessageId (uint32_t id)=0
 Sets the message ID for writing data. Use this function before writing the data via write-function. More...
 
virtual void setFrequency (uint32_t hz)=0
 Sets the speed. More...
 
virtual void setFilter (uint32_t filterBank, uint32_t messageId, uint32_t messageIdMask)=0
 Sets a message hardware receive filter. More...
 
- Public Member Functions inherited from semf::CommunicationHardwareAsynchronous
virtual ~CommunicationHardwareAsynchronous ()=default
 
Type type () const override
 Returns the hardware type. More...
 
void setFrame (Frame frame) final
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::CommunicationHardware
virtual ~CommunicationHardware ()=default
 
virtual void init ()=0
 
virtual void deinit ()=0
 
virtual Type type () const =0
 Returns the hardware type. More...
 
virtual void setFrame (Frame frame)=0
 Sets the selected usage of start and stop condition. More...
 
- Public Member Functions inherited from semf::app::Communication
virtual ~Communication ()=default
 
virtual void write (const uint8_t data[], size_t dataSize)=0
 For writing data, dataWritten signal will be emitted after successful write. More...
 
virtual void read (uint8_t buffer[], size_t bufferSize)=0
 For reading data, dataAvailable signal will be emitted after successful read. More...
 
virtual void stopRead ()=0
 
virtual void stopWrite ()=0
 
virtual bool isBusyReading () const =0
 Communication hardware is busy reading at the moment. More...
 
virtual bool isBusyWriting () const =0
 Communication hardware is busy writing at the moment. More...
 

Protected Member Functions

void setBusyWriting (bool isBusy)
 Sets the busy flag for writing. More...
 
virtual void setReadBuffer (uint8_t buffer[], size_t bufferSize)=0
 Sets the read buffer for having the possibility to handle the received data. More...
 
virtual void writeHardware (const uint8_t data[], size_t dataSize)=0
 Hardware will write data. More...
 
virtual void requestHardware ()=0
 
void onDataWritten ()
 
void onDataAvailable ()
 
void onError (Error thrown)
 Is called if an error occurred by hardware read or write access. Will emit error signal. More...
 
void onDataRequested ()
 

Additional Inherited Members

- Public Attributes inherited from semf::Can
Signal dataRequested
 
- Public Attributes inherited from semf::app::Communication
Signal dataWritten
 
Signal dataAvailable
 
Signal writeStopped
 
Signal readStopped
 
Signal< Errorerror
 

Detailed Description

Interface for using CAN.

Note
For Can read() function will only register the receive buffer and allow handling the received data.

Definition at line 23 of file canhardware.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::CanHardware::ErrorCode : uint8_t
strong

Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring).

Enumerator
Write_IsBusy 
Write_DataIsNullptr 
Write_DataSizeIsZero 
Read_DataIsNullptr 
Read_DataSizeIsZero 
Request_IsBusy 

Definition at line 29 of file canhardware.h.

Constructor & Destructor Documentation

◆ ~CanHardware()

virtual semf::CanHardware::~CanHardware ( )
virtualdefault

Member Function Documentation

◆ isBusyReading()

bool semf::CanHardware::isBusyReading ( ) const
overridevirtual

Communication hardware is busy reading at the moment.

Returns
State of the communication hardware.
Attention
Returns always false, is not used here.

Implements semf::app::Communication.

Definition at line 58 of file canhardware.cpp.

◆ isBusyWriting()

bool semf::CanHardware::isBusyWriting ( ) const
overridevirtual

Communication hardware is busy writing at the moment.

Returns
State of the communication hardware.

Implements semf::app::Communication.

Definition at line 63 of file canhardware.cpp.

◆ onDataAvailable()

void semf::CanHardware::onDataAvailable ( )
protected

Is called after data is available in the hardware. Will emit dataAvailable signal.

Definition at line 93 of file canhardware.cpp.

Here is the caller graph for this function:

◆ onDataRequested()

void semf::CanHardware::onDataRequested ( )
protected

Slot for hardware has finished request.

Definition at line 106 of file canhardware.cpp.

Here is the caller graph for this function:

◆ onDataWritten()

void semf::CanHardware::onDataWritten ( )
protected

Is called after data are written by the hardware. Will emit dataWritten signal.

Definition at line 86 of file canhardware.cpp.

Here is the caller graph for this function:

◆ onError()

void semf::CanHardware::onError ( Error  thrown)
protected

Is called if an error occurred by hardware read or write access. Will emit error signal.

Parameters
thrownA thrown error object.

Definition at line 99 of file canhardware.cpp.

Here is the caller graph for this function:

◆ read()

void semf::CanHardware::read ( uint8_t  buffer[],
size_t  bufferSize 
)
overridevirtual

For setting the read buffer. This has be done for getting a dataAvailable signal for handling the data.

Parameters
bufferBuffer to store received bytes in.
bufferSizeSize of receive buffer.
Exceptions
Read_DataIsNullptrIf data is nullptr.
Read_DataSizeIsZeroIf dataSize is zero.

Implements semf::app::Communication.

Definition at line 41 of file canhardware.cpp.

Here is the call graph for this function:

◆ request()

void semf::CanHardware::request ( )
overridevirtual

Sends a CAN request. Message id has to be set first by calling setMessageId().

Exceptions
Request_IsBusyIf this is busy.

Implements semf::Can.

Definition at line 68 of file canhardware.cpp.

Here is the call graph for this function:

◆ requestHardware()

virtual void semf::CanHardware::requestHardware ( )
protectedpure virtual

Hardware will request data on specific id. Id can be set by calling setMessageId().

Implemented in semf::Stm32Can.

Here is the caller graph for this function:

◆ setBusyWriting()

void semf::CanHardware::setBusyWriting ( bool  isBusy)
protected

Sets the busy flag for writing.

Note
in the functions write(), read() busy is set to true. In onDataAvailable(), onDataWritten() and onError() is busy reseted to false.
Parameters
isBusytrue for busy, false for idle.

Definition at line 81 of file canhardware.cpp.

◆ setReadBuffer()

virtual void semf::CanHardware::setReadBuffer ( uint8_t  buffer[],
size_t  bufferSize 
)
protectedpure virtual

Sets the read buffer for having the possibility to handle the received data.

Parameters
bufferBuffer to store received bytes in.
bufferSizeSize of receive buffer.

Implemented in semf::Stm32Can.

Here is the caller graph for this function:

◆ write()

void semf::CanHardware::write ( const uint8_t  data[],
size_t  dataSize 
)
overridevirtual

For writing data, dataWritten signal will be emitted after successful write.

Parameters
dataArray, containing data to write.
dataSizeSize of write data.
Note
Message id has to be set first by calling setMessageId().
Exceptions
Write_IsBusyIf this is busy.
Write_DataIsNullptrIf data is nullptr.
Write_DataSizeIsZeroIf dataSize is zero.

Implements semf::app::Communication.

Definition at line 15 of file canhardware.cpp.

Here is the call graph for this function:

◆ writeHardware()

virtual void semf::CanHardware::writeHardware ( const uint8_t  data[],
size_t  dataSize 
)
protectedpure virtual

Hardware will write data.

Parameters
datadata array
dataSizedata array size

Implemented in semf::Stm32Can.

Here is the caller graph for this function: