SensESP 3.0.1
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)
8 : display_name_{display_name},
9 units_{units},
10 description_{description},
11 short_name_{short_name},
12 timeout_{timeout} {}
13
14void SKMetadata::add_entry(const String& sk_path, JsonArray& meta) {
15 JsonObject json = meta.add<JsonObject>();
16 json["path"] = sk_path;
17 JsonObject val = json["value"].to<JsonObject>();
18
19 if (!this->display_name_.isEmpty()) {
20 val["displayName"] = this->display_name_;
21 }
22
23 if (!this->units_.isEmpty()) {
24 val["units"] = this->units_;
25 }
26
27 if (!this->description_.isEmpty()) {
28 val["description"] = this->description_;
29 }
30
31 if (!this->short_name_.isEmpty()) {
32 val["shortName"] = this->short_name_;
33 }
34
35 if (this->timeout_ >= 0.0) {
36 val["timeout"] = this->timeout_;
37 }
38}
39
40} // namespace sensesp
virtual void add_entry(const String &sk_path, JsonArray &meta)
SKMetadata()
Default constructor creates a blank Metadata structure.