-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrames.h
executable file
·69 lines (54 loc) · 1.35 KB
/
Frames.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Copyright (c) 2021 Andrew Riachi. All rights reserved.*/
#ifndef FRAMES_H
#define FRAMES_H
#include <Arduino.h>
struct frame
{
// const uint16_t MAX_BUFFER_SIZE = 1550;
static const uint16_t MAX_BUFFER_SIZE{1800};
char buf[MAX_BUFFER_SIZE]; //0x7E will NOT be in the buffer.
uint16_t bytes_recvd;
// frame();
~frame();
frame& operator=(const frame& other);
uint16_t length() const; // the length field of the packet, plus the length of the length field itself, plus 1 byte for checksum
uint16_t frameLength() const;
uint8_t frameType() const;
char* frameData();
uint16_t frameDataLength() const;
uint8_t checksum() const;
void clear();
};
inline uint16_t frame::length() const
{
return frameLength() + 3;
}
inline uint16_t frame::frameLength() const
{
return (bytes_recvd >= 2) ? (buf[1] | (buf[0] << 8)) : 0;
}
inline uint16_t frame::frameDataLength() const
{
return frameLength() - 1;
}
inline uint8_t frame::frameType() const
{
return buf[2];
}
inline char* frame::frameData()
{
return buf+3; // +2 to get past length, +1 to get past frameType
}
inline uint8_t frame::checksum() const
{
return buf[frameLength()];
}
struct userFrame
{
bool operator==(const userFrame& other);
uint8_t frameType;
const char* frameData;
uint16_t frameDataLength;
};
const userFrame NULL_USER_FRAME = {0, nullptr, 0};
#endif