BusBricks: /Users/felixschulke/Developement/Arduino/Modbus_RTU/Modbus_RTU/Modbus-RTU/lib/mockArduino/mockArduino.h Source File
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
mockArduino.h
Go to the documentation of this file.
1
25#ifndef MOCK_ARDUINO_H
26#define MOCK_ARDUINO_H
27
28#ifdef ARDUINO
29 #include <Arduino.h>
30#else
31 #include <iostream>
32 #include <string>
33 #include <sstream>
34 #include <chrono>
35 #include <queue>
36 #include <functional>
37
38 #define OUTPUT 1
39 #define INPUT 0
40
45 namespace arduinoMocking {
46
51 typedef std::string String;
52
61 void pinMode(int pin, int mode);
62
69 class MockTime {
70 public:
74 MockTime();
75
81 unsigned long millis() const;
82
88 unsigned long micros() const;
89
90 private:
91 std::chrono::steady_clock::time_point startTime;
92 unsigned long simulatedMillis;
93 unsigned long simulatedMicros;
94 };
95
101 unsigned long millis();
102
108 unsigned long micros();
109
117 public:
121 MockSerial();
122
130 void begin(unsigned long baudrate);
131
137 void print(const std::string& str);
138
144 void print(char c);
145
151 void print(int num);
152
158 void print(unsigned int num);
159
165 void print(long num);
166
172 void print(unsigned long num);
173
179 void print(double num);
180
186 void println(const std::string& str);
187
193 void println(char c);
194
200 void println(int num);
201
207 void println(unsigned int num);
208
214 void println(long num);
215
221 void println(unsigned long num);
222
228 void println(double num);
229
233 void println();
234
240 int available();
241
247 int read();
248
255 size_t write(uint8_t byte);
256
262 void simulateInput();
263
269 void simulateInput(std::string input);
270
271 private:
272 std::queue<uint8_t> inputBuffer;
273 };
274
280
281 } // namespace arduinoMocking
282
283#endif // ARDUINO
284
285#endif // MOCK_ARDUINO_H
Simulates Arduino's Serial class for testing purposes.
Definition mockArduino.h:116
int read()
Reads a byte from the serial input buffer.
Definition mockArduino.cpp:148
void simulateInput()
Simulates user input by adding characters to the input buffer.
Definition mockArduino.cpp:164
void println()
Prints a newline to the serial output.
Definition mockArduino.cpp:139
void print(const std::string &str)
Prints a string to the serial output.
Definition mockArduino.cpp:82
void begin(unsigned long baudrate)
Begins serial communication with the specified baud rate.
Definition mockArduino.cpp:77
size_t write(uint8_t byte)
Writes a byte to the serial output.
Definition mockArduino.cpp:158
MockSerial()
Constructs a MockSerial object.
Definition mockArduino.cpp:73
int available()
Returns the number of bytes available to read from the serial input buffer.
Definition mockArduino.cpp:144
Simulates Arduino's time functions for testing purposes.
Definition mockArduino.h:69
unsigned long millis() const
Returns the simulated time in milliseconds.
Definition mockArduino.cpp:44
MockTime()
Constructs a MockTime object and initializes the start time.
Definition mockArduino.cpp:36
unsigned long micros() const
Returns the simulated time in microseconds.
Definition mockArduino.cpp:51
Provides mock implementations of Arduino framework functions and classes for native builds.
Definition mockArduino.cpp:28
std::string String
Alias for std::string to simulate Arduino's String type.
Definition mockArduino.h:51
unsigned long micros()
Simulates the micros function to get the number of microseconds since the program started.
Definition mockArduino.cpp:68
void pinMode(int pin, int mode)
Simulates the pinMode function for setting pin modes.
Definition mockArduino.cpp:31
MockSerial Serial
Global instance of MockSerial to mimic Arduino's Serial object.
Definition mockArduino.cpp:185
unsigned long millis()
Simulates the millis function to get the number of milliseconds since the program started.
Definition mockArduino.cpp:62