6#include "ArduinoJson.h"
13 : max_buffer_size{max_buffer_size}, meta_sent_{false} {
14 semaphore_ = xSemaphoreCreateRecursiveMutex();
21 if (timeout_ms == 0) {
22 return xSemaphoreTakeRecursive(semaphore_, portMAX_DELAY) == pdTRUE;
24 return xSemaphoreTakeRecursive(semaphore_, timeout_ms) == pdTRUE;
32 if (get_buffer_size() >= max_buffer_size) {
35 buffer.push_front(val);
41 if (sk_source->get_sk_path() !=
"") {
42 sk_source->attach([sk_source,
this]() {
45 sk_source->as_signalk_json(doc);
46 serializeJson(doc, output);
55 bool available = buffer.size() > 0;
63 JsonDocument json_doc;
66 JsonArray updates = json_doc[
"updates"].to<JsonArray>();
69 this->add_metadata(updates);
72 JsonObject current = updates.add<JsonObject>();
73 JsonObject source = current[
"source"].to<JsonObject>();
75 JsonArray values = current[
"values"].to<JsonArray>();
78 while (!buffer.empty()) {
79 values.add(serialized(buffer.back()));
84 serializeJson(json_doc, output);
86 ESP_LOGD(__FILENAME__,
"delta: %s", output.c_str());
89void SKDeltaQueue::add_metadata(JsonArray updates) {
90 JsonObject new_entry = updates.add<JsonObject>();
91 JsonArray meta = new_entry[
"meta"].to<JsonArray>();
93 sk_source->add_metadata(meta);
SKDeltaQueue(unsigned int max_buffer_size=20)
void get_delta(String &output)
bool take_semaphore(uint64_t timeout_ms=0)
void append(const String &val)
static const std::vector< SKEmitter * > & get_sources()
static String get_hostname()
Get the current hostname.
std::shared_ptr< reactesp::EventLoop > event_loop()