This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcLib.hpp
149 lines (125 loc) · 4.98 KB
/
rcLib.hpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @file lib.hpp
* @author Paul Nykiel
* @version 1.2.1
*/
#ifndef _RC_LIB_PACKAGE_
#define _RC_LIB_PACKAGE_
extern "C" {
#include "RadioControlProtocolC/rc_lib.h"
}
namespace rcLib{
class Package{
public:
/**
* Default constructor, should only be used when reading a package
*/
Package();
/**
* Constructor to use when creating a new package
* @param channelCount The number of channels used
* @param resolution The resolution (steps) of each channel.
*/
Package(uint16_t resolution, uint8_t channelCount);
/**
* Read in the next byte for the package
* @param data a byte containing package information
* @return a boolean, true when the package is finished
*/
bool decode(uint8_t data);
/**
* Convert the package into a serialised byte-array for sending
* @return a byte array containing the package
*/
uint8_t encode();
/**
* Read the data which should get transmitted
* @return a pointer to the data, the length is returned by the encode function.
*/
[[nodiscard]] const uint8_t* getEncodedData() const;
/**
* Set the value of one channel. The values get ignored if they are
* not in the valid range.
* @param channel the number of the channel starting from 0
* @param data the value of the channel
*/
void setChannel(uint8_t channel, uint16_t data);
/**
* Get the data of one channel
* @param channel the number (starting at 0) of the channel
* @return the value of the channel
*/
[[nodiscard]] uint16_t getChannel(uint8_t channel) const;
/**
* Read the amount of channels transmitted by the sender
* @return the number of channels
*/
[[nodiscard]] uint16_t getChannelCount() const;
/**
* Get the resolution (steps) of each channel
* @return The resolution as a uint16_t
*/
[[nodiscard]] uint16_t getResolution() const;
/**
* Get the id of the original sender of the package
* @return a uint8_t containing the id
*/
[[nodiscard]] uint8_t getDeviceId() const;
/**
* Set the id of the original sender, this function should only be called if the deviceId != transmitterId.
* This is the case if you want to simulate packages.
* @param deviceId
*/
void setDeviceId(uint8_t deviceId);
/**
* Check if the calculated checksum equals the checksum of the package.
* @return a boolean whether the checksum is correct
*/
[[nodiscard]] uint8_t isChecksumCorrect() const;
/**
* Read whether the message is a mesh message
* @return a boolean wheter the message is a mesh message
*/
[[nodiscard]] uint8_t isMesh() const;
/**
* Set the properties of the package if it is a mesh package
* @param enabled a boolean whether the message should be mesh message
* @param routingLength the maximum amount of nodes one package can traverse
*/
void setMeshProperties(uint8_t enabled = false,
uint8_t routingLength = 8);
/**
* Checks whether the message has already been forwarded
* @return true if routingLength is larger 0 and the message is a mesh message
*/
[[nodiscard]] uint8_t needsForwarding() const;
/**
* Counts the current node as traversed node by decrementing
* the routing Length
*/
void countNode();
/**
* @return A boolean wheter the message is a discover message
*/
[[nodiscard]] uint8_t isDiscoverMessage() const;
/**
* @return A boolean wheter the message is a discover response
*/
[[nodiscard]] uint8_t isDiscoverResponse() const;
/**
* Sets the package as a discover message
*/
void setDiscoverMessage();
/**
* Creates an discover response to send back.
* @param responses all received responses
* @param len the length of responses
*/
void makeDiscoverResponse(Package responses[], uint8_t len);
static void setTransmitterId(uint8_t transmitterId);
static uint8_t getTransmitterId();
protected:
rc_lib_package_t pkg;
};
}
#endif