-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBBBSerial.h
57 lines (43 loc) · 1.3 KB
/
BBBSerial.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
/*
* BBBSerial.h
*
* Created on: Oct 7, 2013
* Author: michaeldarling
*/
#ifndef BBBSERIAL_H_
#define BBBSERIAL_H_
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#include <assert.h>
#include <time.h>
#include <vector>
#define BBBSERIAL_BAUD B38400
typedef unsigned char uint8_t;
class BBBSerial{
private:
int fd; // file handle
int rd; // read character count
unsigned int read_timeout; // timeout on read
// header message, initial checksum, payload length
uint8_t hdr[4], chk_hdr, payload_len;
public:
BBBSerial();
~BBBSerial();
bool readBytes(uint8_t&);
void writeBytes(const uint8_t&);
int writeData(const std::vector<double>&); // Pass a vector of state info
int checkRequest();
// TODO:
// Need to Send Header Message: 'D' 'A' 'T' 'A'
// Send PAYLOAD length as a byte
// Typecast payload to single-precision floats (probably save as a float data[6] type array)
// Use assert(sizeof(float) == 4) to make sure that a float is 4 bytes
// Use a union to be able to access payload as an array of floats or an array of uint8_t.
// Compute a checksum by doing a bitwise OR (^) on all bytes before the checksum in sequence.
// Append all bytes in order and send across serial
};
#endif /* BBBSERIAL_H_ */