-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMobaBus_CAN.h
71 lines (51 loc) · 1.71 KB
/
MobaBus_CAN.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
/**
MobaBus Can Interface
© 2021, Markus Mair. All rights reserved.
This file is part of the MobaBus Project
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __MobaBus_CAN__
#define __MobaBus_CAN__
#include "MobaBus_Interface.h"
#include <mcp_can.h>
#include <SPI.h>
extern volatile bool MM_CANIntReq;
void MM_CANInt(void);
class MobaBus_CAN : public MobaBus_Interface {
private:
uint8_t _csPin = 0;
/**
* Interrupt pin to be used
*/
uint8_t _intPin = 0;
/**
* CAN Bus Speed
*/
uint8_t _speed = 0;
/**
* CAN Crystal Frequency
*/
uint8_t _clockspd = 0;
MCP_CAN _interface;
/**
* Error code of the last action - 0 = no error
*/
uint8_t lastErr = 0;
public:
MobaBus_CAN(uint8_t cs, uint8_t speed, uint8_t clockspd, uint8_t interrupt);
bool begin();
bool Send(MobaDevType type, uint16_t target, uint8_t port, MobaCmd cmd, uint8_t len, uint8_t *data);
bool Receive(MobaBus_Packet &pkg);
uint32_t CanAddrAssemble(MobaDevType type, uint16_t target, uint8_t port, MobaCmd cmd);
MobaBus_Meta CanAddrParse(uint32_t canAddr);
};
#endif