-
Notifications
You must be signed in to change notification settings - Fork 1
/
SerialCan.hpp
64 lines (50 loc) · 1.34 KB
/
SerialCan.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
#include <iostream>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <thread>
#define BUFFER_SIZE 128
//masks for the 6th byte
#define EXTENTED_MASK 0b100
#define REMOTE_MASK 0b10
class SerialCan
{
public:
friend SerialCan *createSerialCom(std::string path,
speed_t baudRate);
bool startReadThd();
bool stopReadThd();
bool sendCanMsg(uint32_t id,
bool extended,
bool remote,
uint8_t numBytes,
const uint8_t data[]);
~SerialCan();
private:
SerialCan(int fd, termios tty);
void receiveCB(uint32_t id,
bool extended,
bool remote,
uint8_t numBytes,
const uint8_t data[]);
void readThdFunc();
bool sendStr(const char *word);
bool waitWord(const char *word, size_t waitNumChar);
const int fd;
termios tty;
//queue related
unsigned char buf[BUFFER_SIZE];
unsigned int startPos = 0;
unsigned int endPos = 0;
bool foundAT = false;
unsigned int ATseekPos = 0;
unsigned int EOLseekPos = 0;
std::thread *readThd;
volatile bool shouldRead = false;
};
SerialCan *createSerialCom(std::string path,
speed_t baudRate = B115200);