semf
canhardware.h
Go to the documentation of this file.
1
10#ifndef SEMF_COMMUNICATION_CANHARDWARE_H_
11#define SEMF_COMMUNICATION_CANHARDWARE_H_
12
15
16namespace semf
17{
24{
25public:
29 enum class ErrorCode : uint8_t
30 {
31 Write_IsBusy = 0,
32 Write_DataIsNullptr,
33 Write_DataSizeIsZero,
34 Read_DataIsNullptr,
35 Read_DataSizeIsZero,
36 Request_IsBusy
37 };
38
39 virtual ~CanHardware() = default;
40
48 void write(const uint8_t data[], size_t dataSize) override;
57 void read(uint8_t buffer[], size_t bufferSize) override;
62 bool isBusyReading() const override;
63 bool isBusyWriting() const override;
68 void request() override;
69
70protected:
78 void setBusyWriting(bool isBusy);
85 virtual void setReadBuffer(uint8_t buffer[], size_t bufferSize) = 0;
91 virtual void writeHardware(const uint8_t data[], size_t dataSize) = 0;
93 virtual void requestHardware() = 0;
95 void onDataWritten();
97 void onDataAvailable();
103 void onError(Error thrown);
105 void onDataRequested();
106
107private:
109 bool m_isBusyWriting = false;
111 static constexpr Error::ClassID kSemfClassId = Error::ClassID::CanHardware;
112};
113} /* namespace semf */
114#endif /* SEMF_COMMUNICATION_CANHARDWARE_H_ */
Interface for using CAN.
Definition: canhardware.h:24
void write(const uint8_t data[], size_t dataSize) override
For writing data, dataWritten signal will be emitted after successful write.
Definition: canhardware.cpp:15
void onError(Error thrown)
Is called if an error occurred by hardware read or write access. Will emit error signal.
Definition: canhardware.cpp:99
ErrorCode
Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring...
Definition: canhardware.h:30
virtual ~CanHardware()=default
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 dat...
Definition: canhardware.cpp:41
bool isBusyWriting() const override
Communication hardware is busy writing at the moment.
Definition: canhardware.cpp:63
virtual void requestHardware()=0
virtual void setReadBuffer(uint8_t buffer[], size_t bufferSize)=0
Sets the read buffer for having the possibility to handle the received data.
virtual void writeHardware(const uint8_t data[], size_t dataSize)=0
Hardware will write data.
bool isBusyReading() const override
Communication hardware is busy reading at the moment.
Definition: canhardware.cpp:58
void setBusyWriting(bool isBusy)
Sets the busy flag for writing.
Definition: canhardware.cpp:81
void request() override
Definition: canhardware.cpp:68
Interface for CAN specific functionalities, which are not solved in a generic way in CommunicationHar...
Definition: can.h:25
This interface standardized the read and write interface for asynchronous hardware,...
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
Definition: error.h:22
ClassID
Semf class IDs.
Definition: error.h:28