From 8c5a5161a145bfd73d52976738834d42a86c55ba Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:42:50 +0100 Subject: [PATCH] Separate method --- app/rpi/common/include/car/system/CarSystem.h | 2 + app/rpi/common/src/car/system/CarSystem.cpp | 48 ++++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/rpi/common/include/car/system/CarSystem.h b/app/rpi/common/include/car/system/CarSystem.h index c5def63e..71150bce 100644 --- a/app/rpi/common/include/car/system/CarSystem.h +++ b/app/rpi/common/include/car/system/CarSystem.h @@ -67,6 +67,8 @@ namespace car::system const std::shared_ptr getPlugin() const { return this->plugin_manager_->getPlugin(); } private: + void sendData(); + std::shared_ptr configuration_; const std::unique_ptr device_manager_; diff --git a/app/rpi/common/src/car/system/CarSystem.cpp b/app/rpi/common/src/car/system/CarSystem.cpp index c4ad45a5..d7cdce3b 100644 --- a/app/rpi/common/src/car/system/CarSystem.cpp +++ b/app/rpi/common/src/car/system/CarSystem.cpp @@ -105,35 +105,39 @@ namespace car::system this->device_manager_->update(); if (this->messaging_system_->isConnected() && this->device_manager_->isRunning()) { - rapidjson::Document output_json; - output_json.SetObject(); + } + this->plugin_manager_->update(); + } - std::string frame_buffer_base64 = base64::to_base64(this->device_manager_->getCameraDevice()->getFrameBuffer()); - auto scan_data = this->device_manager_->getLidarDevice()->getScanData(); + void CarSystem::sendData() + { + rapidjson::Document output_json; + output_json.SetObject(); - rapidjson::Value data_array(rapidjson::kArrayType); + std::string frame_buffer_base64 = base64::to_base64(this->device_manager_->getCameraDevice()->getFrameBuffer()); + auto scan_data = this->device_manager_->getLidarDevice()->getScanData(); - for (const Measure& measure : scan_data) - { - rapidjson::Value measure_object(rapidjson::kObjectType); - measure_object.AddMember("distance", measure.distance, output_json.GetAllocator()); - measure_object.AddMember("angle", measure.angle, output_json.GetAllocator()); - data_array.PushBack(measure_object, output_json.GetAllocator()); - } + rapidjson::Value data_array(rapidjson::kArrayType); - output_json.AddMember("lidar", data_array, output_json.GetAllocator()); + for (const Measure& measure : scan_data) + { + rapidjson::Value measure_object(rapidjson::kObjectType); + measure_object.AddMember("distance", measure.distance, output_json.GetAllocator()); + measure_object.AddMember("angle", measure.angle, output_json.GetAllocator()); + data_array.PushBack(measure_object, output_json.GetAllocator()); + } - output_json.AddMember("frame_buffer", rapidjson::Value().SetString(frame_buffer_base64.c_str(), output_json.GetAllocator()), output_json.GetAllocator()); + output_json.AddMember("lidar", data_array, output_json.GetAllocator()); - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - output_json.Accept(writer); + output_json.AddMember("frame_buffer", rapidjson::Value().SetString(frame_buffer_base64.c_str(), output_json.GetAllocator()), output_json.GetAllocator()); - std::string output_json_string = buffer.GetString(); - spdlog::info("Sending message: {}", output_json_string); - this->messaging_system_->sendMessage(output_json_string); - } - this->plugin_manager_->update(); + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); + output_json.Accept(writer); + + std::string output_json_string = buffer.GetString(); + spdlog::info("Sending message: {}", output_json_string); + this->messaging_system_->sendMessage(output_json_string); } void CarSystem::setConfiguration(std::shared_ptr configuration)