-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathBinaryIO.h
46 lines (35 loc) · 1.37 KB
/
BinaryIO.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
40
41
42
#pragma once
#include "../RegisterIO.h"
#include <Stream.h>
#define MARKER_BYTE 0xA5
// standard buffer size is 64 bytes, to match the FS USB packet transfer size
// the BinaryIO will send the data in chunks of this size, which should greatly
// improve the performance compared to the ASCII version, which will do a lot of
// converting data to ASCII, and then write in many small writes.
#ifndef BINARYIO_BUFFER_SIZE
#define BINARYIO_BUFFER_SIZE 58
#endif
class BinaryIO : public PacketIO {
public:
BinaryIO(Stream& io);
virtual ~BinaryIO();
BinaryIO& operator<<(float value) override;
BinaryIO& operator<<(uint32_t value) override;
BinaryIO& operator<<(uint8_t value) override;
BinaryIO& operator<<(char value) override;
BinaryIO& operator<<(Packet value) override;
BinaryIO& operator<<(Separator value) override;
BinaryIO& operator>>(float& value) override;
BinaryIO& operator>>(uint32_t& value) override;
BinaryIO& operator>>(uint8_t& value) override;
PacketIO& operator>>(Packet& value) override;
bool is_complete() override;
protected:
void _buff(uint8_t* data, uint8_t size);
void _buff(uint8_t data);
void _flush();
Stream& _io;
uint8_t remaining = 0;
uint8_t _pos = 0;
uint8_t _buffer[BINARYIO_BUFFER_SIZE];
};