BusBricks: /Users/felixschulke/Developement/Arduino/Modbus_RTU/Modbus_RTU/Modbus-RTU/lib/Interface/CommInterface.h Source File
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
CommInterface.h
Go to the documentation of this file.
1
25#ifndef COMMINTERFACE_H
26#define COMMINTERFACE_H
27#ifdef ARDUINO
28 #include <Arduino.h> // include Arduino-Library for platformIO-build
29#else
30 #include <mockArduino.h>
31 using namespace arduinoMocking;
32#endif
33
34#include<CharArray.h>
35#include<ErrorState.h>
36
54{
55public:
60 virtual void setup_interface(){};
61
67 virtual void sendNewFrame(CharArray* sendFrame){};
68
75 virtual bool finishedSending(){};
76
82 virtual void getReceivedFrame(CharArray* destFrameBuffer){};
83
90 virtual bool receivedNewFrame(){};
91
97
103};
104
122template<typename interface_type>
124 protected:
126 interface_type* interface;
127
130
133
141 virtual bool send() = 0;
142
143
151 virtual bool receive() = 0;
152
153 public:
160 CommInterface(interface_type* interface, uint32_t baudrate): interface(interface){};
161
168 void sendNewFrame(CharArray* sendFrame){
169 if (sendBuffer == nullptr)
170 {
171 sendBuffer = sendFrame; // set the send-buffer-ptr to the Frame, that has to be sent
172 }
173 };
174
184 return sendBuffer==nullptr;
185 };
186
192 void getReceivedFrame(CharArray* externalRecBuffer){
193 receiveBuffer = externalRecBuffer; // set the receive-buffer-ptr to the destination, the next received Frame should be stored at
194 };
195
204 return receiveBuffer==nullptr;
205 };
206
211 virtual void receiveCycle(){
212 // Receiving
213 if (receive()) {
214 receiveBuffer = nullptr;
215 };
216 };
217
222 virtual void sendCycle(){
223 // Sending
224 if (send()){
225 sendBuffer = nullptr;
226 };
227 };
228};
229#endif // COMMINTERFACE_H
Class for storing char-array (byte-array) together with size. The Array is stored on Heap-memory and ...
Definition CharArray.h:38
Communcation-Interface-Base-Class of the CommInterface template specifies a standardized interface to...
Definition CommInterface.h:54
~CommInterfaceBase()
Destroy the Comm-Interface Base object.
Definition CommInterface.h:102
virtual bool receivedNewFrame()
Check, if a new Frame was received.
Definition CommInterface.h:90
virtual void getReceivedFrame(CharArray *destFrameBuffer)
Define the destination, the next received Frame should be copied to ba a pointer to an empty String-O...
Definition CommInterface.h:82
CommInterfaceBase()
Construct a new Comm Interface Base object.
Definition CommInterface.h:96
virtual bool finishedSending()
Check, if the Frame was sent and the CommInterface is ready to send the next Frame.
Definition CommInterface.h:75
virtual void setup_interface()
Setup the Interface has to be called in Setup-function.
Definition CommInterface.h:60
virtual void sendNewFrame(CharArray *sendFrame)
Add a new Frame to the send-buffer.
Definition CommInterface.h:67
Template for generic communication-interface specifies a standardized interface to use for integratin...
Definition CommInterface.h:123
CommInterface(interface_type *interface, uint32_t baudrate)
Construct a new Comm-Interface object.
Definition CommInterface.h:160
CharArray * sendBuffer
pointer to the next frame to be send, set to nullptr if Frame was sent
Definition CommInterface.h:129
CharArray * receiveBuffer
pointer to CharArray-object, a received frame should be stored at, set to nullptr if Frame was copied...
Definition CommInterface.h:132
void sendNewFrame(CharArray *sendFrame)
Specify the next frame to be sent by the interface, no overwrite, if the sendBuffer is already pointi...
Definition CommInterface.h:168
virtual bool send()=0
Send the frame, sendBuffer is pointing to (has to be done in the derived class)
interface_type * interface
pointer to an instance of the native bus-interface (setup outside of BusBricks)
Definition CommInterface.h:126
virtual bool receive()=0
Receive a Frame (has to be done in the derived class)
virtual void receiveCycle()
Execution of receive-cycle, set the receiveBuffer to nullptr after a new frame was received.
Definition CommInterface.h:211
virtual void sendCycle()
Execution of send-cycle, set the sendBuffer to nullptr, after the frame, sendBuffer was pointing at,...
Definition CommInterface.h:222
bool finishedSending()
Check, if the Frame was sent and the CommInterface is ready to send the next Frame Interface is ready...
Definition CommInterface.h:183
void getReceivedFrame(CharArray *externalRecBuffer)
Define the destination, the next received Frame should be stored at.
Definition CommInterface.h:192
bool receivedNewFrame()
Check, if a new Frame was received and stored at the in getReceivedFrame specified location the inter...
Definition CommInterface.h:203
A class to manage and track error states using error codes.
Definition ErrorState.h:49
Provides mock implementations of Arduino framework functions and classes for native builds.
Definition mockArduino.cpp:28