summaryrefslogtreecommitdiffstats
path: root/CAN-config-generator/src/openxc/diagnostic_message.cpp
blob: 3881abef70b4ef7581e21377d49657cea9ffad46 (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
#include "diagnostic_message.hpp"

namespace openxc
{
	std::string diagnostic_message::bus() const
	{
		return bus_;
	}
	
	std::uint32_t diagnostic_message::id() const
	{
		return id_;
	}
	
	std::uint32_t diagnostic_message::mode() const
	{
		return mode_;
	}
	
	float diagnostic_message::frequency() const
	{
		return frequency_;
	}
	
	std::uint32_t diagnostic_message::pid() const
	{
		return pid_;
	}
	
	std::string diagnostic_message::name() const
	{
		return name_;
	}
	
	std::string diagnostic_message::decoder() const
	{
		return decoder_;
	}
	
	std::string diagnostic_message::callback() const
	{
		return callback_;
	}
	
	void diagnostic_message::from_json(const nlohmann::json& j)
	{
		bus_ = j.count("bus") ? j["bus"].get<std::string>() : "";
		id_ = j.count("id") ? j["id"].get<std::uint32_t>() : 0;
		mode_ = j.count("mode") ? j["mode"].get<std::uint32_t>() : 1;
		frequency_ = j.count("frequency") ? j["frequency"].get<float>() : 0;
		pid_ = j.count("pid") ? j["pid"].get<std::uint32_t>() : 0;
		name_ = j.count("name") ? j["name"].get<std::string>() : "";
		decoder_ = j.count("decoder") ? j["decoder"].get<std::string>() : "";
		callback_ = j.count("callback") ? j["callback"].get<std::string>() : "";
	}

	nlohmann::json diagnostic_message::to_json() const
	{
		nlohmann::json j;
		j["bus"] = bus_;
		j["id"] = id_;
		j["mode"] = mode_;
		j["frequency"] = frequency_;
		j["pid"] = pid_;
		j["name"] = name_;
		j["decoder"] = decoder_;
		j["callback"] = callback_;
		return j;
	}

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

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