semf
uarthardware.h
Go to the documentation of this file.
1
10#ifndef SEMF_COMMUNICATION_UARTHARDWARE_H_
11#define SEMF_COMMUNICATION_UARTHARDWARE_H_
12
15
16namespace semf
17{
22{
23public:
27 enum class ErrorCode : uint8_t
28 {
29 Write_IsBusy = 0,
30 Write_DataIsNullptr,
31 Write_DataSizeIsZero,
32 Read_IsBusy,
33 Read_BufferIsNullptr,
34 Read_BufferSizeIsZero
35 };
36
37 virtual ~UartHardware() = default;
38
45 void write(const uint8_t data[], size_t dataSize) override;
52 void read(uint8_t buffer[], size_t bufferSize) override;
53 bool isBusyReading() const override;
54 bool isBusyWriting() const override;
55
56protected:
64 void setBusyReading(bool isBusy);
72 void setBusyWriting(bool isBusy);
78 virtual void writeHardware(const uint8_t data[], size_t dataSize) = 0;
84 virtual void readHardware(uint8_t buffer[], size_t bufferSize) = 0;
86 void onDataWritten();
88 void onDataAvailable();
94 void onError(Error thrown);
95
96private:
98 bool m_isBusyReading = false;
100 bool m_isBusyWriting = false;
102 static constexpr Error::ClassID kSemfClassId = Error::ClassID::UartHardware;
103};
104} /* namespace semf */
105#endif /* SEMF_COMMUNICATION_UARTHARDWARE_H_ */
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
Class for using UART hardware.
Definition: uarthardware.h:22
ErrorCode
Error codes for this class. Error ID identify a unique error() / onError call (excluding transferring...
Definition: uarthardware.h:28
void setBusyReading(bool isBusy)
Sets the busy flag for reading.
void onError(Error thrown)
Is called if an error occurred by hardware read or write access. Will throw error signal.
virtual void readHardware(uint8_t buffer[], size_t bufferSize)=0
Hardware will read data in interrupt mode.
virtual ~UartHardware()=default
void write(const uint8_t data[], size_t dataSize) override
For writing data, dataWritten signal will be emitted after successful write.
void setBusyWriting(bool isBusy)
Sets the busy flag for writing.
bool isBusyReading() const override
Communication hardware is busy reading at the moment.
void read(uint8_t buffer[], size_t bufferSize) override
For reading data, dataAvailable signal will be emitted after successful read.
virtual void writeHardware(const uint8_t data[], size_t dataSize)=0
Hardware will write data in interrupt mode.
bool isBusyWriting() const override
Communication hardware is busy writing at the moment.
Interface for UART specific functionalities, which are not solved in a generic way in CommunicationHa...
Definition: uart.h:25