-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanBus.cpp
More file actions
48 lines (42 loc) · 1.04 KB
/
CanBus.cpp
File metadata and controls
48 lines (42 loc) · 1.04 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
#include "CanBus.h"
#include <iostream>
#include <algorithm>
void CanBus::addCandidateMessage(CommunicationFrame* frame)
{
candidateFrames.push_back(frame);
std::sort(
candidateFrames.begin(),
candidateFrames.end(),
[](CommunicationFrame* a, CommunicationFrame* b) {
return *a < *b;
}
);
}
void CanBus::transmitFrame()
{
if (!candidateFrames.size())
return;
for (auto device : subscribedDevices)
device->receiveFrame(candidateFrames[0]);
framesHistory.push_back(candidateFrames[0]);
candidateFrames.clear();
}
void CanBus::subscribeDevice(NetworkDevice* newDevice)
{
subscribedDevices.push_back(newDevice);
}
void CanBus::unsubscribeDevice(NetworkDevice* device)
{
for (auto it = subscribedDevices.begin(); it != subscribedDevices.end(); ++it)
{
if (*it == device)
{
subscribedDevices.erase(it);
break;
}
}
}
std::vector<CommunicationFrame*> CanBus::getCandidateFrames()
{
return candidateFrames;
}