-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCANCommClass.cpp
54 lines (40 loc) · 1.23 KB
/
CANCommClass.cpp
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
/**
* @file CANCommClass.cpp
* @author Leonardo Cavagnis
* @brief Source file for the CANCommClass used to initialize and interact with the CAN Bus communication protocol on the Portenta Machine Control board.
*/
/* Includes -----------------------------------------------------------------*/
#include "CANCommClass.h"
#include <pinDefinitions.h>
/* Functions -----------------------------------------------------------------*/
CANCommClass::CANCommClass(PinName can_tx_pin, PinName can_rx_pin, PinName can_stb_pin) :
_can(can_rx_pin, can_tx_pin), _tx{can_tx_pin}, _rx{can_rx_pin}, _stb{can_stb_pin}
{ }
CANCommClass::~CANCommClass()
{ }
bool CANCommClass::begin(CanBitRate can_bitrate) {
pinMode(PinNameToIndex(_stb), OUTPUT);
_enable();
return _can.begin(can_bitrate);
}
int CANCommClass::write(CanMsg const & msg) {
return _can.write(msg);
}
size_t CANCommClass::available() {
return _can.available();
}
CanMsg CANCommClass::read() {
return _can.read();
}
void CANCommClass::end() {
_disable();
_can.end();
}
void CANCommClass::_enable() {
digitalWrite(PinNameToIndex(_stb), LOW);
}
void CANCommClass::_disable() {
digitalWrite(PinNameToIndex(_stb), HIGH);
}
CANCommClass MachineControl_CANComm;
/**** END OF FILE ****/