SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
signalk_listener.cpp
Go to the documentation of this file.
1#include "signalk_listener.h"
2
4
5namespace sensesp {
6
7std::vector<SKListener *> SKListener::listeners_;
8
9SemaphoreHandle_t SKListener::semaphore_ = xSemaphoreCreateRecursiveMutex();
10
11SKListener::SKListener(const String &sk_path, int listen_delay,
12 const String &config_path)
13 : FileSystemSaveable(config_path),
14 sk_path{sk_path},
15 listen_delay{listen_delay} {
16 listeners_.push_back(this);
17 this->load();
18}
19
20bool SKListener::take_semaphore(uint64_t timeout_ms) {
21 if (timeout_ms == 0) {
22 return xSemaphoreTakeRecursive(semaphore_, portMAX_DELAY) == pdTRUE;
23 } else {
24 return xSemaphoreTakeRecursive(semaphore_, timeout_ms) == pdTRUE;
25 }
26}
27
28void SKListener::release_semaphore() { xSemaphoreGiveRecursive(semaphore_); }
29
30bool SKListener::to_json(JsonObject &root) {
31 root["sk_path"] = this->get_sk_path();
32 return true;
33}
34
35bool SKListener::from_json(const JsonObject &config) {
36 if (!config["sk_path"].is<String>()) {
37 return false;
38 }
39 this->set_sk_path(config["sk_path"].as<String>());
40 return true;
41}
42
43void SKListener::set_sk_path(const String &path) { sk_path = path; }
44
45const String ConfigSchema(const SKListener &obj) {
46 return R"({"type":"object","properties":{"listen_delay":{"title":"Listen delay","type":"number","description":"The time, in milliseconds, between each read of the input"}} })";
47}
48
49} // namespace sensesp
virtual bool load() override
Load and populate the object from a persistent storage.
Definition saveable.cpp:8
An Obervable class that listens for Signal K stream deltas and notifies any observers of value change...
static bool take_semaphore(uint64_t timeout_ms=0)
static void release_semaphore()
SKListener(const String &sk_path, int listen_delay, const String &config_path="")
const String ConfigSchema(const SmartSwitchController &obj)