From ac602b5cb39369324ef4f549b883bef4dad829ea Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 16 Apr 2024 13:09:54 +0300 Subject: [PATCH] Breaking change: rename WSClient to SKWSClient --- .../controllers/system_status_controller.h | 4 +- src/sensesp/signalk/signalk_delta_queue.h | 2 +- .../signalk_ws_client.cpp} | 58 +++++++++---------- .../signalk_ws_client.h} | 12 ++-- src/sensesp/system/led_blinker.h | 6 +- src/sensesp/system/system_status_led.h | 4 +- src/sensesp_app.cpp | 2 +- src/sensesp_app.h | 6 +- 8 files changed, 47 insertions(+), 47 deletions(-) rename src/sensesp/{net/ws_client.cpp => signalk/signalk_ws_client.cpp} (93%) rename src/sensesp/{net/ws_client.h => signalk/signalk_ws_client.h} (94%) diff --git a/src/sensesp/controllers/system_status_controller.h b/src/sensesp/controllers/system_status_controller.h index fbaca419e..944f027ca 100644 --- a/src/sensesp/controllers/system_status_controller.h +++ b/src/sensesp/controllers/system_status_controller.h @@ -2,7 +2,7 @@ #define _SYSTEM_STATUS_CONTROLLER_H_ #include "sensesp/net/networking.h" -#include "sensesp/net/ws_client.h" +#include "sensesp/signalk/signalk_ws_client.h" #include "sensesp/system/valueproducer.h" namespace sensesp { @@ -35,7 +35,7 @@ class SystemStatusController : public ValueConsumer, virtual void set(WiFiState new_value, uint8_t input_channel = 0) override; /// ValueConsumer interface for ValueConsumer - /// (WSClient object state updates) + /// (SKWSClient object state updates) virtual void set(WSConnectionState new_value, uint8_t input_channel = 0) override; diff --git a/src/sensesp/signalk/signalk_delta_queue.h b/src/sensesp/signalk/signalk_delta_queue.h index 0c6f993b8..91664303e 100644 --- a/src/sensesp/signalk/signalk_delta_queue.h +++ b/src/sensesp/signalk/signalk_delta_queue.h @@ -11,7 +11,7 @@ namespace sensesp { * @brief Signal K delta queue * * This class implements a Signal K delta queue. There should be a unique queue - * for each possible output channel (WSClient, NMEA 2000 messages, + * for each possible output channel (SKWSClient, NMEA 2000 messages, * carrier pigeons). */ class SKDeltaQueue { diff --git a/src/sensesp/net/ws_client.cpp b/src/sensesp/signalk/signalk_ws_client.cpp similarity index 93% rename from src/sensesp/net/ws_client.cpp rename to src/sensesp/signalk/signalk_ws_client.cpp index 506f43d69..9690d78d9 100644 --- a/src/sensesp/net/ws_client.cpp +++ b/src/sensesp/signalk/signalk_ws_client.cpp @@ -1,4 +1,4 @@ -#include "ws_client.h" +#include "signalk_ws_client.h" #include #include @@ -18,7 +18,7 @@ namespace sensesp { constexpr int ws_client_task_stack_size = 8192; -WSClient* ws_client; +SKWSClient* ws_client; static const char* kRequestPermission = "readwrite"; @@ -74,17 +74,17 @@ static void websocket_event_handler(void* handler_args, esp_event_base_t base, } } -WSClient::WSClient(String config_path, SKDeltaQueue* sk_delta_queue, +SKWSClient::SKWSClient(String config_path, SKDeltaQueue* sk_delta_queue, String server_address, uint16_t server_port, bool use_mdns) : Configurable{config_path, "/System/Signal K Settings", 200}, sk_delta_queue_{sk_delta_queue}, conf_server_address_{server_address}, conf_server_port_{server_port}, use_mdns_{use_mdns} { - // a WSClient object observes its own connection_state_ member + // a SKWSClient object observes its own connection_state_ member // and simply passes through any notification it emits. As a result, // whenever the value of connection_state_ is updated, observers of the - // WSClient object get automatically notified. + // SKWSClient object get automatically notified. this->connection_state_.attach( [this]() { this->emit(this->connection_state_.get()); }); @@ -100,14 +100,14 @@ WSClient::WSClient(String config_path, SKDeltaQueue* sk_delta_queue, delta_tx_tick_producer_.connect_to(&delta_tx_count_producer_); ReactESP::app->onDelay(0, [this]() { - debugD("Starting WSClient"); - xTaskCreate(ExecuteWebSocketTask, "WSClient", ws_client_task_stack_size, + debugD("Starting SKWSClient"); + xTaskCreate(ExecuteWebSocketTask, "SKWSClient", ws_client_task_stack_size, this, 1, NULL); MDNS.addService("signalk-sensesp", "tcp", 80); }); } -void WSClient::connect_loop() { +void SKWSClient::connect_loop() { if (this->get_connection_state() == WSConnectionState::kWSDisconnected) { this->connect(); } @@ -119,7 +119,7 @@ void WSClient::connect_loop() { * This method is called in the websocket task context. * */ -void WSClient::on_disconnected() { +void SKWSClient::on_disconnected() { if (this->get_connection_state() == WSConnectionState::kWSConnecting && server_detected_ && !token_test_success_) { // Going from connecting directly to disconnect when we @@ -139,7 +139,7 @@ void WSClient::on_disconnected() { * Called in the websocket task context. * */ -void WSClient::on_error() { +void SKWSClient::on_error() { this->set_connection_state(WSConnectionState::kWSDisconnected); debugW("Websocket client error."); } @@ -149,7 +149,7 @@ void WSClient::on_error() { * * Called in the websocket task context. */ -void WSClient::on_connected() { +void SKWSClient::on_connected() { this->set_connection_state(WSConnectionState::kWSConnected); this->sk_delta_queue_->reset_meta_send(); debugI("Subscribing to Signal K listeners..."); @@ -162,7 +162,7 @@ void WSClient::on_connected() { * Called in the websocket task context. * */ -void WSClient::subscribe_listeners() { +void SKWSClient::subscribe_listeners() { bool output_available = false; JsonDocument subscription; subscription["context"] = "vessels.self"; @@ -206,7 +206,7 @@ void WSClient::subscribe_listeners() { * * @param payload */ -void WSClient::on_receive_delta(uint8_t* payload) { +void SKWSClient::on_receive_delta(uint8_t* payload) { #ifdef SIGNALK_PRINT_RCV_DELTA debugD("Websocket payload received: %s", (char*)payload); #endif @@ -240,7 +240,7 @@ void WSClient::on_receive_delta(uint8_t* payload) { * * @param message */ -void WSClient::on_receive_updates(JsonDocument& message) { +void SKWSClient::on_receive_updates(JsonDocument& message) { // Process updates from subscriptions... JsonArray updates = message["updates"]; @@ -269,7 +269,7 @@ void WSClient::on_receive_updates(JsonDocument& message) { * This method is called in the main task context. * */ -void WSClient::process_received_updates() { +void SKWSClient::process_received_updates() { SKListener::take_semaphore(); const std::vector& listeners = SKListener::get_listeners(); @@ -310,7 +310,7 @@ void WSClient::process_received_updates() { * * @param message */ -void WSClient::on_receive_put(JsonDocument& message) { +void SKWSClient::on_receive_put(JsonDocument& message) { // Process PUT requests... JsonArray puts = message["put"]; size_t response_count = 0; @@ -359,14 +359,14 @@ void WSClient::on_receive_put(JsonDocument& message) { * * @param payload */ -void WSClient::sendTXT(String& payload) { +void SKWSClient::sendTXT(String& payload) { if (get_connection_state() == WSConnectionState::kWSConnected) { esp_websocket_client_send_text(this->client_, payload.c_str(), payload.length(), portMAX_DELAY); } } -bool WSClient::get_mdns_service(String& server_address, uint16_t& server_port) { +bool SKWSClient::get_mdns_service(String& server_address, uint16_t& server_port) { // get IP address using an mDNS query int n = MDNS.queryService("signalk-ws", "tcp"); if (n == 0) { @@ -380,7 +380,7 @@ bool WSClient::get_mdns_service(String& server_address, uint16_t& server_port) { } } -void WSClient::connect() { +void SKWSClient::connect() { if (get_connection_state() != WSConnectionState::kWSDisconnected) { return; } @@ -437,7 +437,7 @@ void WSClient::connect() { this->test_token(this->server_address_, this->server_port_); } -void WSClient::test_token(const String server_address, +void SKWSClient::test_token(const String server_address, const uint16_t server_port) { // FIXME: implement async HTTP client! HTTPClient http; @@ -479,7 +479,7 @@ void WSClient::test_token(const String server_address, } } -void WSClient::send_access_request(const String server_address, +void SKWSClient::send_access_request(const String server_address, const uint16_t server_port) { debugD("Preparing a new access request"); if (client_id_ == "") { @@ -539,7 +539,7 @@ void WSClient::send_access_request(const String server_address, this->poll_access_request(server_address, server_port, this->polling_href_); } -void WSClient::poll_access_request(const String server_address, +void SKWSClient::poll_access_request(const String server_address, const uint16_t server_port, const String href) { debugD("Polling SK Server for authentication token"); @@ -606,7 +606,7 @@ void WSClient::poll_access_request(const String server_address, } } -void WSClient::connect_ws(const String host, const uint16_t port) { +void SKWSClient::connect_ws(const String host, const uint16_t port) { String path = "/signalk/v1/stream?subscribe=none"; set_connection_state(WSConnectionState::kWSConnecting); @@ -640,18 +640,18 @@ void WSClient::connect_ws(const String host, const uint16_t port) { debugD("Websocket client started."); } -bool WSClient::is_connected() { +bool SKWSClient::is_connected() { return get_connection_state() == WSConnectionState::kWSConnected; } -void WSClient::restart() { +void SKWSClient::restart() { if (get_connection_state() == WSConnectionState::kWSConnected) { esp_websocket_client_close(this->client_, portMAX_DELAY); set_connection_state(WSConnectionState::kWSDisconnected); } } -void WSClient::send_delta() { +void SKWSClient::send_delta() { String output; if (get_connection_state() == WSConnectionState::kWSConnected) { if (sk_delta_queue_->data_available()) { @@ -664,7 +664,7 @@ void WSClient::send_delta() { } } -void WSClient::get_configuration(JsonObject& root) { +void SKWSClient::get_configuration(JsonObject& root) { root["sk_address"] = this->conf_server_address_; root["sk_port"] = this->conf_server_port_; root["use_mdns"] = this->use_mdns_; @@ -674,7 +674,7 @@ void WSClient::get_configuration(JsonObject& root) { root["polling_href"] = this->polling_href_; } -bool WSClient::set_configuration(const JsonObject& config) { +bool SKWSClient::set_configuration(const JsonObject& config) { if (config.containsKey("sk_address")) { this->conf_server_address_ = config["sk_address"].as(); } @@ -702,7 +702,7 @@ bool WSClient::set_configuration(const JsonObject& config) { * * @return String */ -String WSClient::get_connection_status() { +String SKWSClient::get_connection_status() { auto state = get_connection_state(); switch (state) { case WSConnectionState::kWSAuthorizing: diff --git a/src/sensesp/net/ws_client.h b/src/sensesp/signalk/signalk_ws_client.h similarity index 94% rename from src/sensesp/net/ws_client.h rename to src/sensesp/signalk/signalk_ws_client.h index a75e31b4f..9947fb65d 100644 --- a/src/sensesp/net/ws_client.h +++ b/src/sensesp/signalk/signalk_ws_client.h @@ -1,5 +1,5 @@ -#ifndef _ws_client_H_ -#define _ws_client_H_ +#ifndef SENSESP_SRC_SENSESP_SIGNALK_SIGNALK_WS_CLIENT_H_ +#define SENSESP_SRC_SENSESP_SIGNALK_SIGNALK_WS_CLIENT_H_ #include #include @@ -30,13 +30,13 @@ enum class WSConnectionState { * @brief The websocket connection to the Signal K server. * @see SensESPApp */ -class WSClient : public Configurable, +class SKWSClient : public Configurable, public ValueProducer { public: ///////////////////////////////////////////////////////// // main task methods - WSClient(String config_path, SKDeltaQueue* sk_delta_queue, + SKWSClient(String config_path, SKDeltaQueue* sk_delta_queue, String server_address, uint16_t server_port, bool use_mdns = true); const String get_server_address() const { return server_address_; } @@ -65,7 +65,7 @@ class WSClient : public Configurable, String get_connection_status(); ///////////////////////////////////////////////////////// - // WSClient task methods + // SKWSClient task methods void on_disconnected(); void on_error(); @@ -143,7 +143,7 @@ class WSClient : public Configurable, void process_received_updates(); ///////////////////////////////////////////////////////// - // WSClient task methods + // SKWSClient task methods void connect_loop(); void test_token(const String host, const uint16_t port); diff --git a/src/sensesp/system/led_blinker.h b/src/sensesp/system/led_blinker.h index 71b9116bd..b7dd4112e 100644 --- a/src/sensesp/system/led_blinker.h +++ b/src/sensesp/system/led_blinker.h @@ -1,9 +1,9 @@ -#ifndef _led_blinker_H_ -#define _led_blinker_H_ +#ifndef SENSESP_SRC_SENSESP_SYSTEM_LED_BLINKER_H_ +#define SENSESP_SRC_SENSESP_SYSTEM_LED_BLINKER_H_ #include -#include "sensesp/net/ws_client.h" +#include "sensesp/signalk/signalk_ws_client.h" namespace sensesp { diff --git a/src/sensesp/system/system_status_led.h b/src/sensesp/system/system_status_led.h index 4bf167b2e..7830cec07 100644 --- a/src/sensesp/system/system_status_led.h +++ b/src/sensesp/system/system_status_led.h @@ -1,5 +1,5 @@ -#ifndef _LED_CONTROLLER_H_ -#define _LED_CONTROLLER_H_ +#ifndef SENSESP_SRC_SENSESP_SYSTEM_SYSTEM_STATUS_LED_H_ +#define SENSESP_SRC_SENSESP_SYSTEM_SYSTEM_STATUS_LED_H_ #include "lambda_consumer.h" #include "led_blinker.h" diff --git a/src/sensesp_app.cpp b/src/sensesp_app.cpp index 753148708..1f961be75 100644 --- a/src/sensesp_app.cpp +++ b/src/sensesp_app.cpp @@ -55,7 +55,7 @@ void SensESPApp::setup() { // create the websocket client bool use_mdns = sk_server_address_ == ""; this->ws_client_ = - new WSClient("/System/Signal K Settings", sk_delta_queue_, + new SKWSClient("/System/Signal K Settings", sk_delta_queue_, sk_server_address_, sk_server_port_, use_mdns); // connect the system status controller diff --git a/src/sensesp_app.h b/src/sensesp_app.h index 6997476f8..16e5d2793 100644 --- a/src/sensesp_app.h +++ b/src/sensesp_app.h @@ -19,7 +19,7 @@ #include "sensesp/net/web/base_command_handler.h" #include "sensesp/net/web/config_handler.h" #include "sensesp/net/web/static_file_handler.h" -#include "sensesp/net/ws_client.h" +#include "sensesp/signalk/signalk_ws_client.h" #include "sensesp/sensesp_version.h" #include "sensesp/sensors/sensor.h" #include "sensesp/signalk/signalk_delta_queue.h" @@ -60,7 +60,7 @@ class SensESPApp : public SensESPBaseApp { return &(this->system_status_controller_); } Networking* get_networking() { return this->networking_; } - WSClient* get_ws_client() { return this->ws_client_; } + SKWSClient* get_ws_client() { return this->ws_client_; } protected: /** @@ -135,7 +135,7 @@ class SensESPApp : public SensESPBaseApp { Networking* networking_ = NULL; OTA* ota_; SKDeltaQueue* sk_delta_queue_; - WSClient* ws_client_; + SKWSClient* ws_client_; UIOutput* sensesp_version_ui_output_ = new UIOutput( "SenseESP version", kSensESPVersion, "Software", 1900);