blob: 6a1bf2c4eee8b7c0a2113dcb003d881375ad009e (
plain) (
blame)
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
|
#include <iostream>
#include <fstream>
#include <map>
#include "message.h"
#include "frame.h"
using namespace std;
int main() {
ifstream msgFile("messages.txt");
if (!msgFile.is_open()) {
return 1;
}
map<unsigned int, Message> unfinished_messages;
string line;
unsigned int can_id;
while (getline(msgFile, line)) {
const char* data = line.c_str();
sscanf(data, "%3x", &can_id);
Frame frame(data + 3);
// When the message is split into multiple frames (an FF and then multiple CFs)
if (unfinished_messages.count(can_id)) {
Message& m = unfinished_messages[can_id];
m.receive_frame(frame);
if (!m.expects_more_frames()) {
cout << m << endl;
unfinished_messages.erase(can_id);
}
}
else {
Message m(can_id, frame);
if (m.expects_more_frames())
unfinished_messages.insert({ can_id, m });
else
cout << m << endl;
}
}
}
|