-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add logger service for flight computer #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4956ca
feat: dd logger service for flight computer
KrzysKond 6ea364c
feat: add forgotten deployment files
KrzysKond 7a4cb2e
fix: remove include chrono
KrzysKond 4c8c07d
update SD
KrzysKond b3b877d
feat: add svc over UDP
KrzysKond 15951c5
fix
Mateusz-Krajewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| cc_library( | ||
| name = "logger_data_type_lib", | ||
| srcs = ["data_type.cpp"], | ||
| hdrs = ["data_type.hpp"], | ||
| visibility = [ | ||
| "//apps/fc/logger_service:__subpackages__", | ||
| "//apps/fc/logger_service/tests:__subpackages__", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,93 @@ | ||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * @file data_type.cpp | ||||||||||||||||||||||||||||||||||||||
| * @author Krzysztof Kondracki (kondracki.christopher@gmail.com) | ||||||||||||||||||||||||||||||||||||||
| * @brief | ||||||||||||||||||||||||||||||||||||||
| * @version 0.1 | ||||||||||||||||||||||||||||||||||||||
| * @date 2026-04-13 | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @copyright Copyright (c) 2026 | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| #include "apps/fc/logger_service/data_type.hpp" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #include <iomanip> | ||||||||||||||||||||||||||||||||||||||
| #include <sstream> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| namespace srp { | ||||||||||||||||||||||||||||||||||||||
| namespace logger { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| namespace { | ||||||||||||||||||||||||||||||||||||||
| constexpr auto kCsvHeader = | ||||||||||||||||||||||||||||||||||||||
| "TIMESTAMP;BOARD_TEMP1;BOARD_TEMP2;BOARD_TEMP3;BME_TEMP;BME_HUMIDITY;" | ||||||||||||||||||||||||||||||||||||||
| "BME_ALTITUDE;CPU_USAGE;MEM_USAGE;DISK_UTILIZATION"; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| std::string Data_t::get_header() { | ||||||||||||||||||||||||||||||||||||||
| return kCsvHeader; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+27
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| std::string Data_t::to_string(const std::string& timestamp) { | ||||||||||||||||||||||||||||||||||||||
| std::stringstream res; | ||||||||||||||||||||||||||||||||||||||
| res << std::fixed << std::setprecision(2); | ||||||||||||||||||||||||||||||||||||||
| res << timestamp << ";"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| std::shared_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| res << board_temp1_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << board_temp2_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << board_temp3_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << bme_temp_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << bme_humidity_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << bme_altitude_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << cpu_usage_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << mem_usage_ << ";"; | ||||||||||||||||||||||||||||||||||||||
| res << disk_utilization_; | ||||||||||||||||||||||||||||||||||||||
| return res.str(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetBoardTemp1(const tempType& temp) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| board_temp1_ = temp; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetBoardTemp2(const tempType& temp) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| board_temp2_ = temp; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetBoardTemp3(const tempType& temp) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| board_temp3_ = temp; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetBmeTemp(const bmeType& value) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| bme_temp_ = value; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetBmeHumidity(const bmeType& value) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| bme_humidity_ = value; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetBmeAltitude(const bmeType& value) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| bme_altitude_ = value; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetCpuUsage(const systemStatType& value) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| cpu_usage_ = value; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetMemUsage(const systemStatType& value) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| mem_usage_ = value; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| void Data_t::SetDiskUtilization(const systemStatType& value) { | ||||||||||||||||||||||||||||||||||||||
| std::unique_lock<std::shared_mutex> lock(mutex_); | ||||||||||||||||||||||||||||||||||||||
| disk_utilization_ = value; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } // namespace logger | ||||||||||||||||||||||||||||||||||||||
| } // namespace srp | ||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||
| /** | ||||
| * @file data_type.hpp | ||||
| * @author Krzysztof Kondracki (kondracki.christopher@gmail.com) | ||||
| * @brief | ||||
| * @version 0.1 | ||||
| * @date 2026-04-13 | ||||
| * | ||||
| * @copyright Copyright (c) 2026 | ||||
| * | ||||
| */ | ||||
| #ifndef APPS_FC_LOGGER_SERVICE_DATA_TYPE_HPP_ | ||||
| #define APPS_FC_LOGGER_SERVICE_DATA_TYPE_HPP_ | ||||
|
|
||||
| #include <cstdint> | ||||
| #include <mutex> // NOLINT | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| #include <shared_mutex> | ||||
| #include <string> | ||||
|
|
||||
| namespace srp { | ||||
| namespace logger { | ||||
|
|
||||
| class Data_t { | ||||
| private: | ||||
| using tempType = int16_t; | ||||
| using bmeType = float; | ||||
| using systemStatType = float; | ||||
|
|
||||
| std::shared_mutex mutex_; | ||||
| tempType board_temp1_{0}; | ||||
| tempType board_temp2_{0}; | ||||
| tempType board_temp3_{0}; | ||||
| bmeType bme_temp_{0.0F}; | ||||
| bmeType bme_humidity_{0.0F}; | ||||
| bmeType bme_altitude_{0.0F}; | ||||
| systemStatType cpu_usage_{0.0F}; | ||||
| systemStatType mem_usage_{0.0F}; | ||||
| systemStatType disk_utilization_{0.0F}; | ||||
|
|
||||
| public: | ||||
| std::string get_header(); | ||||
| std::string to_string(const std::string& timestamp); | ||||
| void SetBoardTemp1(const tempType& temp); | ||||
| void SetBoardTemp2(const tempType& temp); | ||||
| void SetBoardTemp3(const tempType& temp); | ||||
| void SetBmeTemp(const bmeType& value); | ||||
| void SetBmeHumidity(const bmeType& value); | ||||
| void SetBmeAltitude(const bmeType& value); | ||||
| void SetCpuUsage(const systemStatType& value); | ||||
| void SetMemUsage(const systemStatType& value); | ||||
| void SetDiskUtilization(const systemStatType& value); | ||||
| }; | ||||
|
|
||||
| } // namespace logger | ||||
| } // namespace srp | ||||
|
|
||||
| #endif // APPS_FC_LOGGER_SERVICE_DATA_TYPE_HPP_ | ||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| cc_binary( | ||
| name = "logger_service_fc", | ||
| srcs = [ | ||
| "logger_builder.hpp", | ||
| "logger_did.hpp", | ||
| "logger_service.cpp", | ||
| "logger_service.hpp", | ||
| "main.cpp", | ||
| "service.hpp", | ||
| ], | ||
| visibility = ["//deployment:__subpackages__"], | ||
| deps = [ | ||
| "@srp_platform//ara/exec:adaptive_application_lib", | ||
| "//apps/fc/logger_service:logger_data_type_lib", | ||
| "//core/common:condition_lib", | ||
| "//core/csvdriver", | ||
| "//core/time:sys_time_change_lib", | ||
| "//core/timestamp:timestamp_controller", | ||
| "//deployment/apps/fc/logger_service:ara", | ||
| "//deployment/apps/fc/logger_service:someip_lib", | ||
| "@srp_platform//ara/diag:uds_lib", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /** | ||
| * @file logger_builder.hpp | ||
| * @author Krzysztof Kondracki (kondracki.christopher@gmail.com) | ||
| * @brief | ||
| * @version 0.1 | ||
| * @date 2026-04-19 | ||
| * | ||
| * @copyright Copyright (c) 2026 | ||
| * | ||
| */ | ||
| #ifndef APPS_FC_LOGGER_SERVICE_SERVICE_LOGGER_BUILDER_HPP_ | ||
| #define APPS_FC_LOGGER_SERVICE_SERVICE_LOGGER_BUILDER_HPP_ | ||
|
|
||
| #include <cstdint> | ||
| #include <functional> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <utility> | ||
|
|
||
| #include "apps/fc/logger_service/service/logger_did.hpp" | ||
| #include "apps/fc/logger_service/service/service.hpp" | ||
|
|
||
| namespace srp { | ||
| namespace logger { | ||
|
|
||
| class Builder { | ||
| private: | ||
| std::unique_ptr<FileLoggerDID> logger_did_; | ||
| std::unique_ptr<apps::MyFcFileLoggerAppSkeleton> service_ipc_; | ||
| std::unique_ptr<apps::MyFcFileLoggerAppSkeleton> service_udp_; | ||
| std::function<void(std::uint8_t)> callback_; | ||
|
|
||
| public: | ||
| explicit Builder(std::function<void(std::uint8_t)> callback_handler) | ||
| : callback_(std::move(callback_handler)) {} | ||
|
|
||
| Builder& SetLoggerDID(const ara::core::InstanceSpecifier& specifier) { | ||
| logger_did_ = std::make_unique<FileLoggerDID>(specifier, callback_); | ||
| return *this; | ||
| } | ||
|
|
||
| Builder& SetLoggerIPC(const std::string& instance) { | ||
| service_ipc_ = std::make_unique<apps::MyFcFileLoggerAppSkeleton>( | ||
| ara::core::InstanceSpecifier{instance}, | ||
| callback_); | ||
| return *this; | ||
| } | ||
|
|
||
| Builder& SetLoggerUDP(const std::string& instance) { | ||
| service_udp_ = std::make_unique<apps::MyFcFileLoggerAppSkeleton>( | ||
| ara::core::InstanceSpecifier{instance}, | ||
| callback_); | ||
| return *this; | ||
| } | ||
|
|
||
| struct Result { | ||
| std::unique_ptr<FileLoggerDID> logger_did; | ||
| std::unique_ptr<apps::MyFcFileLoggerAppSkeleton> service_ipc; | ||
| std::unique_ptr<apps::MyFcFileLoggerAppSkeleton> service_udp; | ||
| }; | ||
|
|
||
| Result Build() { | ||
| return {std::move(logger_did_), std::move(service_ipc_), std::move(service_udp_)}; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace logger | ||
| } // namespace srp | ||
|
|
||
| #endif // APPS_FC_LOGGER_SERVICE_SERVICE_LOGGER_BUILDER_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * @file logger_did.hpp | ||
| * @author Krzysztof Kondracki (kondracki.christopher@gmail.com) | ||
| * @brief | ||
| * @version 0.1 | ||
| * @date 2026-04-19 | ||
| * | ||
| * @copyright Copyright (c) 2026 | ||
| * | ||
| */ | ||
| #ifndef APPS_FC_LOGGER_SERVICE_SERVICE_LOGGER_DID_HPP_ | ||
| #define APPS_FC_LOGGER_SERVICE_SERVICE_LOGGER_DID_HPP_ | ||
|
|
||
| #include <cstdint> | ||
| #include <functional> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "ara/diag/generic_data_identifier.h" | ||
| #include "ara/diag/uds_error_domain.h" | ||
|
|
||
| namespace srp { | ||
| namespace logger { | ||
|
|
||
| using DidSaveThreadHandler = std::function<void(std::uint8_t status)>; | ||
|
|
||
| class FileLoggerDID : public ara::diag::GenericDiD { | ||
| private: | ||
| DidSaveThreadHandler handler_; | ||
|
|
||
| ara::core::Result<ara::diag::OperationOutput> Read() noexcept override { | ||
| return ara::diag::MakeErrorCode( | ||
| ara::diag::UdsDiagErrc::kSubFunctionNotSupported); | ||
| } | ||
|
|
||
| ara::core::Result<void> Write(const std::vector<std::uint8_t>& payload) noexcept override { | ||
| if (payload.size() != 1U) { | ||
| return ara::diag::MakeErrorCode( | ||
| ara::diag::UdsDiagErrc::kInvalidMessageLengthFormat); | ||
| } | ||
|
|
||
| handler_(payload[0]); | ||
| return {}; | ||
| } | ||
|
|
||
| public: | ||
| FileLoggerDID(const ara::core::InstanceSpecifier& instance, DidSaveThreadHandler handler) | ||
| : ara::diag::GenericDiD{instance}, handler_(std::move(handler)) {} | ||
| }; | ||
|
|
||
| } // namespace logger | ||
| } // namespace srp | ||
|
|
||
| #endif // APPS_FC_LOGGER_SERVICE_SERVICE_LOGGER_DID_HPP_ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.