summaryrefslogtreecommitdiffstats
path: root/src/openxc/can_message.cpp
blob: d42d1efa742ecd2304b51b03763c43fffdc2e2ed (plain)
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
#include "can_message.hpp"

namespace openxc
{
	std::string can_message::bus() const
	{
		return bus_;
	}
	
	bool can_message::bit_numbering_inverted() const
	{
		return bit_numbering_inverted_;
	}
	
	const std::map<std::string, signal>& can_message::signals() const
	{
		return signals_;
	}
	
	std::string can_message::name() const
	{
		return name_;
	}
	
	std::vector<std::string> can_message::handlers() const
	{
		return handlers_;
	}
	
	bool can_message::enabled() const
	{
		return enabled_;
	}
	
	std::uint32_t can_message::max_frequency() const
	{
		return max_frequency_;
	}
	
	std::uint32_t can_message::max_signal_frequency() const
	{
		return max_signal_frequency_;
	}
	
	bool can_message::force_send_changed() const
	{
		return force_send_changed_;
	}
	
	bool can_message::force_send_changed_signals() const
	{
		return force_send_changed_;
	}
	
	void can_message::from_json(const nlohmann::json& j)
	{
		bus_ = j.count("bus") ? j["bus"].get<std::string>() : "";
		bit_numbering_inverted_ = j.count("bit_numbering_inverted") ? j["bit_numbering_inverted"].get<bool>() : false;
		signals_= j.count("signals") ? j["signals"].get<std::map<std::string, signal>>() : std::map<std::string, signal>();
		name_ = j.count("name") ? j["name"].get<std::string>() : "";
		handlers_ = j.count("handlers") ? j["handlers"].get<std::vector<std::string>>() : std::vector<std::string>();
		enabled_ = j.count("enabled") ? j["enabled"].get<bool>() : true;
		max_frequency_ = j.count("max_frequency") ? j["max_frequency"].get<std::uint32_t>() : 0;
		max_signal_frequency_ = j.count("max_signal_frequency") ? j["max_signal_frequency"].get<std::uint32_t>() : 0;
		force_send_changed_ = j.count("force_send_changed") ? j["force_send_changed"].get<bool>() : true;
		force_send_changed_signals_ = j.count("force_send_changed_signals") ? j["force_send_changed_signals"].get<bool>() : false;
	}
	
	std::uint32_t can_message::get_signals_count() const
	{
		return signals_.size();
	}

	nlohmann::json can_message::to_json() const
	{
		nlohmann::json j;
		j["bus"] = bus_;
		j["bit_numbering_inverted"] = bit_numbering_inverted_;
		j["signals"] = signals_;
		j["name"] = name_;
		j["handlers"] = handlers_;
		j["enabled"] = enabled_;
		j["max_frequency"] = max_frequency_;
		j["max_signal_frequency"] = max_signal_frequency_;
		j["force_send_changed"] = force_send_changed_;
		j["force_send_changed_signals"] = force_send_changed_signals_;
		return j;
	}

	void to_json(nlohmann::json& j, const can_message& p)
	{
		j = p.to_json();
	}

	void from_json(const nlohmann::json& j, can_message& p)
	{
		p.from_json(j);
	}
}