SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
position.cpp
Go to the documentation of this file.
1#include "position.h"
2
3#include "ArduinoJson.h"
4
5namespace sensesp {
6
7void convertFromJson(JsonVariantConst src, Position &dst) {
8 dst.longitude = src["longitude"].as<double>();
9 dst.latitude = src["latitude"].as<double>();
10
11 if (src["altitude"].is<float>()) {
12 dst.altitude = src["altitude"].as<float>();
13 }
14}
15
16void convertFromJson(JsonVariantConst src, ENUVector &dst) {
17 dst.east = src["east"].as<float>();
18 dst.north = src["north"].as<float>();
19
20 if (src["up"].is<float>()) {
21 dst.up = src["up"].as<float>();
22 }
23}
24
25void convertFromJson(JsonVariantConst src, AttitudeVector &dst) {
26 dst.roll = src["roll"].as<float>();
27 dst.pitch = src["pitch"].as<float>();
28 dst.yaw = src["yaw"].as<float>();
29}
30
31bool canConvertFromJson(JsonVariantConst src, const Position & /*position*/) {
32 return src["latitude"].is<double>() && src["longitude"].is<double>();
33}
34
35bool canConvertFromJson(JsonVariantConst src, const ENUVector & /*enu*/) {
36 return src["east"].is<double>() && src["north"].is<double>();
37}
38
39bool canConvertFromJson(JsonVariantConst src,
40 const AttitudeVector & /*attitude*/) {
41 return src["roll"].is<float>() && src["pitch"].is<float>() &&
42 src["yaw"].is<float>();
43}
44
45void convertToJson(const Position &src, JsonVariant dst) {
46 JsonObject obj = dst.to<JsonObject>();
47 obj["latitude"] = src.latitude;
48 obj["longitude"] = src.longitude;
49
51 obj["altitude"] = src.altitude;
52 }
53}
54
55void convertToJson(const ENUVector &src, JsonVariant dst) {
56 JsonObject obj = dst.to<JsonObject>();
57 obj["east"] = src.east;
58 obj["north"] = src.north;
59
60 if (src.up != kPositionInvalidAltitude) {
61 obj["up"] = src.up;
62 }
63}
64
65void convertToJson(const AttitudeVector &src, JsonVariant dst) {
66 JsonObject obj = dst.to<JsonObject>();
67 obj["roll"] = src.roll;
68 obj["pitch"] = src.pitch;
69 obj["yaw"] = src.yaw;
70}
71
72} // namespace sensesp
void convertToJson(const Nullable< T > &src, JsonVariant dst)
Definition nullable.h:67
bool canConvertFromJson(JsonVariantConst src, const Position &)
Tells ArduinoJson whether the given JSON is a Position or not.
Definition position.cpp:31
constexpr float kPositionInvalidAltitude
Definition position.h:11
void convertFromJson(JsonVariantConst src, Nullable< T > &dst)
Definition nullable.h:58
Container for attitude data.
Definition position.h:54
Container for local tangent plane coordinates.
Definition position.h:38
Position data container.
Definition position.h:20