-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessage.cpp
More file actions
71 lines (58 loc) · 1.35 KB
/
message.cpp
File metadata and controls
71 lines (58 loc) · 1.35 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
/*
* message.cpp
*
* Created on: 04.10.2013
* Author: downtimes
* Modified : 05.21.2020
* Author: Yunjin
*/
#include "message.hpp"
#include <istream>
#include <limits>
#include <algorithm>
std::istream& operator>>(std::istream& in, Message& msg) {
std::string preamble;
in >> preamble;
//Check if we are actually reading a Message otherwise fail the stream
if (preamble != "BO_") {
in.setstate(std::ios_base::failbit);
return in;
}
//Parse the message ID
in >> msg.id;
//Parse the name of the Message
std::string name;
in >> name;
msg.name = name.substr(0, name.length() - 1);
//Parse the Messages length
in >> msg.dlc;
//Parse the sender;
in >> msg.from;
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
//As long as there is a Signal, parse the Signal
while(in) {
Signal sig;
in >> sig;
if (in) {
msg.signals.push_back(sig);
}
}
in.clear();
return in;
}
std::set<std::string> Message::getTo() const {
std::set<std::string> collection;
for (auto sig : signals) {
auto toList = sig.getTo();
collection.insert(toList.begin(), toList.end());
}
return collection;
}
std::unordered_map<std::string, double> Message::decode(uint64_t payload) {
std::unordered_map<std::string, double> frame;
for (auto sig : signals)
{
frame.insert({sig.getName(), sig.getValue(payload)});
}
return frame;
}