-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsds011_protocol.h
49 lines (38 loc) · 1022 Bytes
/
sds011_protocol.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
#ifndef SDS011_PROTOCOL_H
#define SDS011_PROTOCOL_H
#include <stdbool.h>
#include <stdint.h>
// parsing state
typedef enum {
HEAD = 0,
COMMAND,
DATA,
CHECK,
TAIL
} EState;
class SDS011Protocol {
private:
EState _state;
uint8_t _buf[32];
int _idx;
int _len;
uint8_t _sum;
public:
SDS011Protocol();
bool process_rx(uint8_t b, uint8_t rsp_id);
/**
* Creates a command byte array from command data.
* @param buf the destination buffer
* @param cmd_len the length of the command data
* @param cmd_data the command data to be copied
* @return the actual size of the command byte array created
*/
int build_tx(uint8_t *buf, uint8_t cmd, size_t cmd_len, const uint8_t *cmd_data);
/**
* Copies response data.
* @param rsp the response data buffer, should be at least 6 bytes
* @return the actual size of the response data buffer
*/
size_t get_data(uint8_t *rsp);
};
#endif /* SDS011_PROTOCOL_H */