-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcomm_unittest_helper.h
More file actions
44 lines (32 loc) · 1.15 KB
/
Copy pathcomm_unittest_helper.h
File metadata and controls
44 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "gen.h"
#if IS_POSIX
#include "ArduinoJson.h"
#endif
#include "comm.h"
class bus;
class comm_unittest_helper: public comm
{
private:
bool connected { false };
std::vector<uint8_t> data_rx;
std::vector<uint8_t> data_tx;
public:
comm_unittest_helper() {
}
virtual ~comm_unittest_helper() {
}
virtual bool begin() override { return true; }
#if IS_POSIX
virtual JsonDocument serialize() const override {
}
#endif
virtual std::string get_identifier() const override { return "unittest helper"; }
void set_connected(const bool state) { connected = state; }
virtual bool is_connected() override { return connected; }
void set_data(const std::vector<uint8_t> & data_in) { data_rx = data_in; }
virtual bool has_data() override { return data_rx.empty() == false; }
virtual uint8_t get_byte() override { auto rc = data_rx.front(); data_rx.erase(data_rx.begin()); return rc; }
virtual void send_data(const uint8_t *const in, const size_t n) override { data_tx = std::vector<uint8_t>(in, in + n); }
std::vector<uint8_t> get_tx_data() { auto rc = data_tx; data_tx.clear(); return rc; }
};