SensESP 3.4.0
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
9StaticSemaphore_t SKListener::semaphore_buffer_;
10SemaphoreHandle_t SKListener::semaphore_ =
11 xSemaphoreCreateRecursiveMutexStatic(&SKListener::semaphore_buffer_);
12
13SKListener::SKListener(const String &sk_path, int listen_delay,
14 const String &config_path)
15 : FileSystemSaveable(config_path),
17 listen_delay{listen_delay} {
18 listeners_.push_back(this);
19 this->load();
20}
21
22bool SKListener::take_semaphore(uint64_t timeout_ms) {
23 if (timeout_ms == 0) {
24 return xSemaphoreTakeRecursive(semaphore_, portMAX_DELAY) == pdTRUE;
25 } else {
26 return xSemaphoreTakeRecursive(semaphore_, timeout_ms) == pdTRUE;
27 }
28}
29
30void SKListener::release_semaphore() { xSemaphoreGiveRecursive(semaphore_); }
31
32bool SKListener::to_json(JsonObject &root) {
33 root["sk_path"] = this->get_sk_path();
34 return true;
35}
36
37bool SKListener::from_json(const JsonObject &config) {
38 if (!config["sk_path"].is<String>()) {
39 return false;
40 }
41 this->set_sk_path(config["sk_path"].as<String>());
42 return true;
43}
44
45void SKListener::set_sk_path(const String &path) { sk_path = path; }
46
47const String ConfigSchema(const SKListener &obj) {
48 return R"({"type":"object","properties":{"listen_delay":{"title":"Listen delay","type":"number","description":"The time, in milliseconds, between each read of the input"}} })";
49}
50
51} // namespace sensesp
virtual bool load() override
Load and populate the object from a persistent storage.
Definition saveable.cpp:8
FileSystemSaveable(const String &config_path)
Definition saveable.h:63
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)