SensESP 3.3.0
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
signalk_metadata.cpp
Go to the documentation of this file.
1#include "signalk_metadata.h"
2
3namespace sensesp {
4
5SKMetadata::SKMetadata(const String& units, const String& display_name,
6 const String& description, const String& short_name,
7 float timeout, bool supports_put)
8 : display_name_{display_name},
9 units_{units},
10 description_{description},
11 short_name_{short_name},
12 timeout_{timeout},
13 supports_put_{supports_put} {}
14
15void SKMetadata::add_entry(const String& sk_path, JsonArray& meta) {
16 JsonObject json = meta.add<JsonObject>();
17 json["path"] = sk_path;
18 JsonObject val = json["value"].to<JsonObject>();
19
20 if (!this->display_name_.isEmpty()) {
21 val["displayName"] = this->display_name_;
22 }
23
24 if (!this->units_.isEmpty()) {
25 val["units"] = this->units_;
26 }
27
28 if (!this->description_.isEmpty()) {
29 val["description"] = this->description_;
30 }
31
32 if (!this->short_name_.isEmpty()) {
33 val["shortName"] = this->short_name_;
34 }
35
36 if (this->timeout_ >= 0.0) {
37 val["timeout"] = this->timeout_;
38 }
39
40 if (this->supports_put_) {
41 val["supportsPut"] = this->supports_put_;
42 }
43}
44
45} // namespace sensesp
virtual void add_entry(const String &sk_path, JsonArray &meta)
SKMetadata()
Default constructor creates a blank Metadata structure.