forked from wirenboard/wb-mqtt-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport.h
39 lines (31 loc) · 1.2 KB
/
port.h
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
#pragma once
#include "definitions.h"
#include <chrono>
#include <functional>
class TPort: public std::enable_shared_from_this<TPort> {
public:
using TFrameCompletePred = std::function<bool(uint8_t* buf, int size)>;
TPort() = default;
TPort(const TPort &) = delete;
TPort& operator=(const TPort &) = delete;
virtual ~TPort() = default;
virtual void CycleBegin() {}
virtual void CycleEnd(bool ok) {}
virtual void Open() = 0;
virtual void Close() = 0;
virtual bool IsOpen() const = 0;
virtual void CheckPortOpen() const = 0;
virtual void WriteBytes(const uint8_t * buf, int count) = 0;
virtual uint8_t ReadByte() = 0;
virtual int ReadFrame(
uint8_t* buf, int count,
const std::chrono::microseconds& timeout = std::chrono::microseconds(-1),
TFrameCompletePred frame_complete = 0) = 0;
virtual void SkipNoise() = 0;
virtual void SetDebug(bool debug) = 0;
virtual bool Debug() const = 0;
virtual void Sleep(const std::chrono::microseconds& us) = 0;
virtual bool Wait(const PBinarySemaphore & semaphore, const TTimePoint & until) = 0;
virtual TTimePoint CurrentTime() const = 0;
};
using PPort = std::shared_ptr<TPort>;