Skip to content

Commit

Permalink
Separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Apr 12, 2024
1 parent 207b4fd commit 8c5a516
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
2 changes: 2 additions & 0 deletions app/rpi/common/include/car/system/CarSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace car::system
const std::shared_ptr<T> getPlugin() const { return this->plugin_manager_->getPlugin<T>(); }

private:
void sendData();

std::shared_ptr<Configuration> configuration_;

const std::unique_ptr<DeviceManager> device_manager_;
Expand Down
48 changes: 26 additions & 22 deletions app/rpi/common/src/car/system/CarSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rapidjson::StringBuffer> 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<rapidjson::StringBuffer> 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> configuration)
Expand Down

0 comments on commit 8c5a516

Please sign in to comment.