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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#include <sstream>
#include "message_set.hpp"
namespace openxc
{
message_set::message_set()
: name_{""}
, bit_numbering_inverted_{false}
, max_message_frequency_{0}
, raw_can_mode_{can_bus_mode::off}
, parents_{}
, initializers_{}
, loopers_{}
, buses_{}
, messages_{}
, diagnostic_messages_{}
, mappings_{}
, extra_sources_{}
, commands_{}
{
}
std::string message_set::name() const
{
return name_;
}
bool message_set::bit_numbering_inverted() const
{
return bit_numbering_inverted_;
}
std::uint32_t message_set::max_message_frequency() const
{
return max_message_frequency_;
}
can_bus_mode message_set::raw_can_mode() const
{
return raw_can_mode_;
}
const std::vector<std::string>& message_set::parents() const
{
return parents_;
}
const std::vector<std::string>& message_set::initializers() const
{
return initializers_;
}
const std::vector<std::string>& message_set::loopers() const
{
return loopers_;
}
const std::map<std::string, can_bus>& message_set::buses() const
{
return buses_;
}
const std::map<std::string, can_message>& message_set::messages() const
{
return messages_;
}
const std::vector<diagnostic_message>& message_set::diagnostic_messages() const
{
return diagnostic_messages_;
}
const std::vector<mapping>& message_set::mappings() const
{
return mappings_;
}
const std::vector<std::string>& message_set::extra_sources() const
{
return extra_sources_;
}
const std::vector<command>& message_set::commands() const
{
return commands_;
}
std::string message_set::to_initializer() const
{
std::uint32_t signal_count = 0;
for(const auto& m : messages_)
{
signal_count += m.second.get_signals_count();
}
std::stringstream ss;
ss << "{0, "
<< "\"" << name_ << "\", "
<< buses_.size() << ", "
<< messages_.size() << ", "
<< signal_count << ", "
<< commands_.size() << ", "
<< diagnostic_messages_.size() << "}";
return ss.str();
}
void message_set::from_json(const nlohmann::json& j)
{
name_ = j["name"].get<std::string>();
bit_numbering_inverted_ = j.count("bit_numbering_inverted") ? j["bit_numbering_inverted"].get<bool>() : false; // TODO: should be true by default if database-backed.
max_message_frequency_ = j.count("max_message_frequency") ? j["max_message_frequency"].get<std::uint32_t>() : 0;
raw_can_mode_ = j.count("raw_can_mode") ? j["raw_can_mode"].get<can_bus_mode>() : can_bus_mode::off;
parents_ = j.count("parents") ? j["parents"].get<std::vector<std::string>>() : std::vector<std::string>();
initializers_ = j.count("initializers") ? j["initializers"].get<std::vector<std::string>>() : std::vector<std::string>();
loopers_ = j.count("loopers") ? j["loopers"].get<std::vector<std::string>>() : std::vector<std::string>();
buses_ = j.count("buses") ? j["buses"].get<std::map<std::string, can_bus>>() : std::map<std::string, can_bus>();
messages_ = j.count("messages") ? j["messages"].get<std::map<std::string, can_message>>() : std::map<std::string, can_message>();
diagnostic_messages_ = j.count("diagnostic_messages") ? j["diagnostic_messages"].get<std::vector<diagnostic_message>>() : std::vector<diagnostic_message>();
mappings_ = j.count("mappings") ? j["mappings"].get<std::vector<mapping>>() : std::vector<mapping>();
extra_sources_ = j.count("extra_sources") ? j["extra_sources"].get<std::vector<std::string>>() : std::vector<std::string>();
commands_ = j.count("commands") ? j["commands"].get<std::vector<command>>() : std::vector<command>();
}
nlohmann::json message_set::to_json() const
{
nlohmann::json j;
j["name_"] = name_;
j["bit_numbering_inverted"] = bit_numbering_inverted_;
j["max_message_frequency"] = max_message_frequency_;
j["raw_can_mode"] = raw_can_mode_;
j["parents"] = parents_;
j["initializers"] = initializers_;
j["loopers"] = loopers_;
j["buses"] = buses_;
j["messages"] = messages_;
j["diagnostic_messages"] = diagnostic_messages_;
j["mappings"] = mappings_;
j["extra_sources"] = extra_sources_;
j["commands"] = commands_;
return j;
}
void to_json(nlohmann::json& j, const message_set& p)
{
j = p.to_json();
}
void from_json(const nlohmann::json& j, message_set& p)
{
p.from_json(j);
}
}
|