-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcanhacker.h
94 lines (69 loc) · 2 KB
/
canhacker.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
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
#pragma once
#include <cstdint>
#include "Can/Can.h"
#include "Buffer.h"
class CanHacker
{
public:
CanHacker() {}
// вызывается из main'а
bool processCmd();
bool processPackets();
// вызывается из прерывания CAN
void packetReceived(Can::Channel channel, const Can::Pkt & packet);
bool gateEnabled(Can::Channel sourceCh, uint32_t pktId) const
{
return canSettings[sourceCh].gate &&
canSettings[sourceCh].gateFilter != pktId;
}
private:
void parse();
int parseDecimal(const char * str, uint32_t len);
int parseHex(const char * str, uint32_t len);
void makeHex(char * buf, uint32_t value, uint32_t bufLen);
void makeHex2(char * buf, uint32_t value); // make byte
uint8_t makeHex(uint32_t value); // make half-byte
void testPin(); // debug function
bool canSpeed(Can::Channel channel, char baudrate);
bool canOpen(Can::Channel channel, bool silent);
bool canClose(Can::Channel channel);
bool canGate(Can::Channel channel, bool enable);
bool canGateBlock(uint8_t channel);
bool canSend(Can::Channel channel, bool id29bit);
bool canSetFilter(bool mask);
struct {
bool open = false;
bool silent = false;
bool gate = false;
uint32_t gateFilter = -1;
uint32_t baudrate = 0;
struct {
uint32_t id;
uint32_t mask;
} filters[15] = {};
} canSettings[2];
struct TCanPktExt : Can::Pkt {
TCanPktExt() {}
TCanPktExt(const Can::Pkt& pkt, uint32_t timestamp=0):
Can::Pkt(pkt), timestamp(timestamp) {}
uint32_t timestamp;
};
CircularBuffer<TCanPktExt, 32> canPkt[2];
static const Can::Filter canFilterEverything[];
struct {
char data[32];
uint32_t idx = 0;
void push(char b) {
if (b < '0' || b > 'z') return;
data[idx++] = b;
idx %= sizeof(data);
}
bool complete(char b) const {
if (idx < 1) return false;
return (b == '\r') || (b == '\n');
}
} cmd;
};
#if PROTOCOL == PROTOCOL_LAWICEL
extern CanHacker canHacker;
#endif