feat: add logger service for flight computer#352
Conversation
Mateusz-Krajewski
left a comment
There was a problem hiding this comment.
Wygląda ok, po testach zmienie na Approve
| std::string Data_t::get_header() { | ||
| return kCsvHeader; | ||
| } |
There was a problem hiding this comment.
| std::string Data_t::get_header() { | |
| return kCsvHeader; | |
| } | |
| std::string Data_t::get_header() const noexcept { | |
| return kCsvHeader; | |
| } |
| namespace { | ||
| constexpr auto kCsvHeader = | ||
| "TIMESTAMP;BOARD_TEMP1;BOARD_TEMP2;BOARD_TEMP3;BME_TEMP;BME_HUMIDITY;" | ||
| "BME_ALTITUDE;CPU_USAGE;MEM_USAGE;DISK_UTILIZATION"; | ||
| } |
There was a problem hiding this comment.
| namespace { | |
| constexpr auto kCsvHeader = | |
| "TIMESTAMP;BOARD_TEMP1;BOARD_TEMP2;BOARD_TEMP3;BME_TEMP;BME_HUMIDITY;" | |
| "BME_ALTITUDE;CPU_USAGE;MEM_USAGE;DISK_UTILIZATION"; | |
| } | |
| namespace { | |
| constexpr auto kCsvdecimalPrecision = 2; | |
| constexpr auto kCsvHeader = | |
| "TIMESTAMP;BOARD_TEMP1;BOARD_TEMP2;BOARD_TEMP3;BME_TEMP;BME_HUMIDITY;" | |
| "BME_ALTITUDE;CPU_USAGE;MEM_USAGE;DISK_UTILIZATION"; | |
| } |
| res << mem_usage_ << ";"; | ||
| res << disk_utilization_; | ||
| return res.str(); | ||
| } |
There was a problem hiding this comment.
| } | |
| std::string Data_t::to_string(const std::string& timestamp) const { | |
| std::stringstream res; | |
| res << std::fixed << std::setprecision(kCsvdecimalPrecision); | |
| 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(); | |
| } |
| #define APPS_FC_LOGGER_SERVICE_DATA_TYPE_HPP_ | ||
|
|
||
| #include <cstdint> | ||
| #include <mutex> // NOLINT |
There was a problem hiding this comment.
| #include <mutex> // NOLINT |
| namespace { | ||
| constexpr auto kLoggerFilename = "_fc_log.csv"; | ||
| constexpr auto kLoggerFilenamePrefix = "/home/root/"; | ||
| constexpr std::uint16_t kSaveIntervalMs = 5000; | ||
| constexpr auto kEnvServicePathName = "srp/env/EnvAppFc/envServiceFc_ipc"; | ||
| constexpr auto kUdpServicePathName = "srp/apps/FcFileLoggerApp/logService_udp"; | ||
| constexpr auto kIpcServicePathName = "srp/apps/FcFileLoggerApp/logService_ipc"; | ||
| constexpr auto kSysStatServicePathName = "srp/apps/FcSysStatService/FcSysStatService_ipc"; | ||
| constexpr auto kFileDidPathName = "/srp/apps/FcFileLoggerApp/logger_did"; | ||
| constexpr std::uint8_t kLogsOn = 1; | ||
| constexpr std::uint8_t kLogsOff = 0; | ||
| } // namespace |
There was a problem hiding this comment.
| namespace { | |
| constexpr auto kLoggerFilename = "_fc_log.csv"; | |
| constexpr auto kLoggerFilenamePrefix = "/home/root/"; | |
| constexpr std::uint16_t kSaveIntervalMs = 5000; | |
| constexpr auto kEnvServicePathName = "srp/env/EnvAppFc/envServiceFc_ipc"; | |
| constexpr auto kUdpServicePathName = "srp/apps/FcFileLoggerApp/logService_udp"; | |
| constexpr auto kIpcServicePathName = "srp/apps/FcFileLoggerApp/logService_ipc"; | |
| constexpr auto kSysStatServicePathName = "srp/apps/FcSysStatService/FcSysStatService_ipc"; | |
| constexpr auto kFileDidPathName = "/srp/apps/FcFileLoggerApp/logger_did"; | |
| constexpr std::uint8_t kLogsOn = 1; | |
| constexpr std::uint8_t kLogsOff = 0; | |
| } // namespace | |
| namespace { | |
| constexpr auto kEnvServicePathName = "srp/env/EnvAppFc/envServiceFc_ipc"; | |
| constexpr auto kUdpServicePathName = "srp/apps/FcFileLoggerApp/logService_udp"; | |
| constexpr auto kIpcServicePathName = "srp/apps/FcFileLoggerApp/logService_ipc"; | |
| constexpr auto kSysStatServicePathName = "srp/apps/FcSysStatService/FcSysStatService_ipc"; | |
| constexpr auto kFileDidPathName = "/srp/apps/FcFileLoggerApp/logger_did"; | |
| constexpr std::uint8_t kLogsOn = 1; | |
| constexpr std::uint8_t kLogsOff = 0; | |
| constexpr auto kLoggerFilename = "_fc_log.csv"; | |
| constexpr auto kLoggerFilenamePrefix = "/home/root/"; | |
| constexpr std::uint16_t kSaveIntervalMs = 50; | |
| } // namespace |
| logger_did_->Offer(); | ||
| service_ipc_->StartOffer(); | ||
| service_udp_->StartOffer(); | ||
| SomeIpInit(); |
There was a problem hiding this comment.
| logger_did_->Offer(); | |
| service_ipc_->StartOffer(); | |
| service_udp_->StartOffer(); | |
| SomeIpInit(); | |
| SomeIpInit(); | |
| logger_did_->Offer(); | |
| service_ipc_->StartOffer(); | |
| service_udp_->StartOffer(); |
| auto res = stat_service_handler_->NewSystemUsage.GetNewSamples(); | ||
| if (!res.HasValue()) { | ||
| return; | ||
| } | ||
| data_.SetCpuUsage(res.Value().cpu_usage); | ||
| data_.SetMemUsage(res.Value().mem_usage); | ||
| data_.SetDiskUtilization(res.Value().disk_utilization); |
There was a problem hiding this comment.
note: mogłeś sobie skrócić kod robiąc metodę SetSystemStat
There was a problem hiding this comment.
to wsm istotne jest, bo jak kompilator nie ogarnie to blokujesz mutex 3 razy (co trochę trwa), i miedzy blokowaniami mogą ci się inne eventy wbijac (aczkolwiem nwm czy nie skopiowales tego z loger-ec)
| env_service_handler_->newBoardTempEvent_1.Subscribe(1, [this](std::uint8_t /*status*/) { | ||
| env_service_handler_->newBoardTempEvent_1.SetReceiveHandler([this]() { | ||
| auto res = env_service_handler_->newBoardTempEvent_1.GetNewSamples(); | ||
| if (res.HasValue()) { | ||
| data_.SetBoardTemp1(res.Value()); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| env_service_handler_->newBoardTempEvent_2.Subscribe(1, [this](std::uint8_t /*status*/) { | ||
| env_service_handler_->newBoardTempEvent_2.SetReceiveHandler([this]() { | ||
| auto res = env_service_handler_->newBoardTempEvent_2.GetNewSamples(); | ||
| if (res.HasValue()) { | ||
| data_.SetBoardTemp2(res.Value()); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| env_service_handler_->newBoardTempEvent_3.Subscribe(1, [this](std::uint8_t /*status*/) { | ||
| env_service_handler_->newBoardTempEvent_3.SetReceiveHandler([this]() { | ||
| auto res = env_service_handler_->newBoardTempEvent_3.GetNewSamples(); | ||
| if (res.HasValue()) { | ||
| data_.SetBoardTemp3(res.Value()); | ||
| } | ||
| }); | ||
| }); |
There was a problem hiding this comment.
teoretycznie to samo, metoda SetBoardTemp(const int16_t& value, const TempSensor_e sensor)
| env_service_handler_->newBME280Event.Subscribe(1, [this](std::uint8_t /*status*/) { | ||
| env_service_handler_->newBME280Event.SetReceiveHandler([this]() { | ||
| auto res = env_service_handler_->newBME280Event.GetNewSamples(); | ||
| if (!res.HasValue()) { | ||
| return; | ||
| } | ||
| data_.SetBmeTemp(res.Value().temperature); | ||
| data_.SetBmeHumidity(res.Value().humidity); | ||
| data_.SetBmeAltitude(res.Value().altitude); | ||
| }); |
| }); | ||
| }); | ||
|
|
||
| env_service_handler_->newBoardTempEvent_3.Subscribe(1, [this](std::uint8_t /*status*/) { |
There was a problem hiding this comment.
| env_service_handler_->newBoardTempEvent_3.Subscribe(1, [this](std::uint8_t /*status*/) { | |
| env_service_handler_->newBoardTempEvent_3.Subscribe(1, [this](std::uint8_t status) { |
dlaczego te statusy są zakomentowane? + brak logowania
* feat: dd logger service for flight computer * feat: add forgotten deployment files * fix: remove include chrono * update SD * feat: add svc over UDP * fix --------- Co-authored-by: Mateusz Krajewski <matikrajek42@gmail.com>
Logger for FC