aboutsummaryrefslogtreecommitdiffstats
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);
	}
}
; <h2 id="detail-of-bindings">Detail of bindings</h2> <h3 id="hello-world">Hello World</h3> <p>A sample Hello World binding for demonstration and learning purposes.</p> <p>This binding provides a few unauthenticated requests, all beginning with &quot;ping&quot;, to demonstrate basic binder capabilities.</p> <p><strong>Verbs</strong>:</p> <ul> <li><em>ping:</em> returns a success response</li> <li><em>pingfail:</em> returns a failure response</li> <li><em>pingnull:</em> returns a success response, with an empty JSON response field</li> <li><em>pingbug:</em> does a memory violation (intercepted by the binder)</li> <li><em>pingJson:</em> returns a success response, with a complex JSON response field</li> <li><em>pingevent:</em> broadcasts a global event</li> </ul> <p><br /></p> <h3 id="authentication">Authentication</h3> <p>An sample Authentication binding for demonstration purposes.</p> <p>This binding provides a few requests to demonstrate the binder's token-based security mechanism.</p> <p>Calling &quot;<em>connect</em>&quot; with a security token will initiate a session, calling &quot;<em>refresh</em>&quot; will issue a new token and invalidate the previous one, calling &quot;<em>logout</em>&quot; will invalidate all tokens and close the session.</p> <p><strong>Verbs</strong>:</p> <ul> <li><em>ping:</em> returns a success response</li> <li><em>connect:</em> creates a session and returns a new token</li> <li><em>refresh:</em> returns a new token</li> <li><em>check:</em> verifies the passed token is valid</li> <li><em>logout:</em> closes the session</li> </ul> <p><br /></p> <h3 id="tic-tac-toe">Tic Tac Toe</h3> <p>A sample Tic Tac Toe game binding.</p> <p>This binding provides an interactive Tic Tac Toe game where the binder returns the grid as a JSON response.</p> <p><strong>Verbs</strong>:</p> <ul> <li><em>new:</em> starts a new game</li> <li><em>play:</em> asks the server to play</li> <li><em>move:</em> gives a client move</li> <li><em>board:</em> gets the current board state, as a JSON structure</li> <li><em>level</em>: sets the server level</li> <li><em>join</em>: joins an existing board</li> <li><em>undo</em>: undo the last move</li> <li><em>wait</em>: wait for a move</li> </ul> <p><br /></p> <h3 id="audio">Audio</h3> <p>A sample Audio binding with 2 backends:</p> <ul> <li>ALSA (mandatory)</li> <li>PulseAudio (optional)</li> </ul> <p>This binding is able to initialize a specific soundcard, define volume levels, channels (mono/stereo...), mute sound, and play a 22,050 Hz PCM stream.</p> <p><strong>Verbs</strong>:</p> <ul> <li><em>ping:</em> returns a success response</li> <li><em>init:</em> initializes backend, on the &quot;default&quot; sound card</li> <li><em>volume:</em> gets or sets volume, in % (0-100)</li> <li><em>channels:</em> gets or sets channels count (1-8)</li> <li><em>mute:</em> gets or sets the mute status (on-off)</li> <li><em>play</em>: gets or sets the playing status (on-off)</li> </ul> <p><em>(if PulseAudio development libraries are not found at build time, only ALSA will be available)</em></p> <p><em>(if a PulseAudio server is not found at runtime, the binding will dynamically fall back to ALSA)</em></p> <p><em>(a specifc backend can be forced by using this syntax before running afb-daemon : <strong>$ export AFB_AUDIO_OUTPUT=Alsa</strong>)</em></p> <p><br /></p> <h3 id="radio">Radio</h3> <p>A sample AM/FM Radio binding with 1 backend:</p> <ul> <li>RTLSDR - Realtek RTL2832U dongles (mandatory)</li> </ul> <p>This binding is able to initialize specific RTL2832U dongles, switch between AM/FM modes, define frequency, mute sound, and play sound (if combining with the <strong>audio</strong> binding).</p> <p><strong>Verbs</strong>:</p> <ul> <li><em>ping:</em> returns a success response</li> <li><em>init:</em> initializes backend, looking for plugged-in devices</li> <li><em>power:</em> sets device power status (on-off)</li> <li><em>mode:</em> sets device reception mode (AM-FM)</li> <li><em>freq:</em> sets device frequency (in Hz)</li> <li><em>mute</em>: sets device mute status (on-off)</li> <li><em>play</em>: sets device playing status (on-off)</li> </ul> <p><em>(if rtlsdr development libraries are not found at build time, this binding will not be built)</em></p> <p><br /></p> <h3 id="media">Media</h3> <p>A sample Media Server binding with 1 backend:</p> <ul> <li>Rygel</li> </ul> <p>This binding is able to detect a local Rygel UPnP media server, list audio files, select an audio file for playback, play/pause/seek in this file, upload an audio file to the server.</p> <p><strong>Verbs</strong>:</p> <ul> <li><em>ping:</em> returns a success response</li> <li><em>init:</em> initializes backend, looking for an active local UPnP server</li> <li><em>list:</em> returns list of audio files, as a JSON structure</li> <li><em>select:</em> select an audio files, by index number (001-...)</li> <li><em>play:</em> plays the currently selected audio file</li> <li><em>stop:</em> stops the currently selected audio file</li> <li><em>pause:</em> pauses the currently selected audio file</li> <li><em>seek:</em> seeks in the currently selected audio file, in seconds</li> <li><em>upload:</em> uploads an audio file, with a POST request</li> </ul> <p><em>(if GUPnP/GSSDP development libraries are not fund at build time, this binding will not be built)</em></p> <p><br /></p> <hr /> <p><br /></p> <p>Sample command-line applications: <em>afb-client-demo</em> (built by default)</p> <p>Sample HTML5 applications: **test/*.html<strong>, </strong><a href="https://gerrit.automotivelinux.org/gerrit/gitweb?p=src/app-framework-demo.git;a=tree">afb-client</a><strong>, </strong><a href="https://github.com/iotbzh/afb-radio">afb-radio</a>**</p> <p>Sample Qt/QML applications: <em>test/token-websock.qml</em></p> </body> </html>