This repository was archived by the owner on Oct 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCanBusPort.cpp
More file actions
76 lines (58 loc) · 1.43 KB
/
Copy pathCanBusPort.cpp
File metadata and controls
76 lines (58 loc) · 1.43 KB
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
#include "CanBusPort.h"
//Constructor vacío (inicializa el can0)
CanBusPort::CanBusPort()
{
Init( "/dev/can0" );
}
//Inicializa todos los puertos que introduzcas
CanBusPort::CanBusPort(string canPort)
{
Init(canPort);
}
//Función para inicializar los puertos
long CanBusPort::Init(string canPort)
{
int val;
portId = open(canPort.c_str(), O_RDWR);
if (portId<0){
err(1, "could not open node '%s'",canPort.c_str());
}
/* Reset the board. Which node is used for this doesn't matter */
if(ioctl(portId,IOC_RESET_BOARD)!=0){
err(1, "could not reset board");
}
/* Set baudrate for both nodes */
val=BITRATE_1000k;
if(ioctl(portId,IOC_SET_BITRATE,&val)!=0){
err(1, "could not set bitrate");
}
/* Start both CAN nodes */
if(ioctl(portId,IOC_START)!=0){
err(1, "IOC_START");
}
return 0;
}
int CanBusPort::getPortId()
{
return portId;
}
long CanBusPort::SetFilter(uint32_t canId, uint32_t mask)
{
cerr << "Not implemented" << endl;
return -1;
}
long CanBusPort::GetMsg(uint32_t &canId, uint8_t *data, uint8_t &size)
{
cerr << "Not implemented" << endl;
return -1;
}
long CanBusPort::PutMsg(const uint32_t &canId, uint8_t * const data, const uint8_t size)
{
cerr << "Not implemented" << endl;
return -1;
}
long CanBusPort::GetNMT(uint8_t * const data, uint8_t &size)
{
cerr << "Not implemented" << endl;
return -1;
}