SensESP 3.6.1-alpha
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
3#include <algorithm>
4
6
7namespace sensesp {
8
9std::vector<SKListener *> SKListener::listeners_;
10
11StaticSemaphore_t SKListener::semaphore_buffer_;
12SemaphoreHandle_t SKListener::semaphore_ =
13 xSemaphoreCreateRecursiveMutexStatic(&SKListener::semaphore_buffer_);
14
15SKListener::SKListener(const String &sk_path, int listen_delay,
16 const String &config_path)
17 : FileSystemSaveable(config_path),
18 sk_path{sk_path},
19 listen_delay{listen_delay} {
20 listeners_.push_back(this);
21 this->load();
22}
23
26 listeners_.erase(std::remove(listeners_.begin(), listeners_.end(), this),
27 listeners_.end());
29}
30
33 listeners_.clear();
35}
36
37bool SKListener::take_semaphore(uint64_t timeout_ms) {
38 if (timeout_ms == 0) {
39 return xSemaphoreTakeRecursive(semaphore_, portMAX_DELAY) == pdTRUE;
40 } else {
41 return xSemaphoreTakeRecursive(semaphore_, timeout_ms) == pdTRUE;
42 }
43}
44
45void SKListener::release_semaphore() { xSemaphoreGiveRecursive(semaphore_); }
46
47bool SKListener::to_json(JsonObject &root) {
48 root["sk_path"] = this->get_sk_path();
49 return true;
50}
51
52bool SKListener::from_json(const JsonObject &config) {
53 if (!config["sk_path"].is<String>()) {
54 return false;
55 }
56 this->set_sk_path(config["sk_path"].as<String>());
57 return true;
58}
59
60void SKListener::set_sk_path(const String &path) { sk_path = path; }
61
62const String ConfigSchema(const SKListener &obj) {
63 return R"({"type":"object","properties":{"listen_delay":{"title":"Listen delay","type":"number","description":"The time, in milliseconds, between each read of the input"}} })";
64}
65
66} // 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="")
static void clear_registry()
const String ConfigSchema(const SmartSwitchController &obj)