Skip to content

feat: add logger service for flight computer#352

Merged
Mateusz-Krajewski merged 6 commits into
masterfrom
loger-fc
Apr 27, 2026
Merged

feat: add logger service for flight computer#352
Mateusz-Krajewski merged 6 commits into
masterfrom
loger-fc

Conversation

@KrzysKond
Copy link
Copy Markdown
Contributor

@KrzysKond KrzysKond commented Apr 19, 2026

Logger for FC

@KrzysKond KrzysKond self-assigned this Apr 19, 2026
@KrzysKond KrzysKond mentioned this pull request Apr 19, 2026
@Mateusz-Krajewski Mateusz-Krajewski linked an issue Apr 20, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Collaborator

@Mateusz-Krajewski Mateusz-Krajewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wygląda ok, po testach zmienie na Approve

Comment on lines +25 to +27
std::string Data_t::get_header() {
return kCsvHeader;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string Data_t::get_header() {
return kCsvHeader;
}
std::string Data_t::get_header() const noexcept {
return kCsvHeader;
}

Comment on lines +19 to +23
namespace {
constexpr auto kCsvHeader =
"TIMESTAMP;BOARD_TEMP1;BOARD_TEMP2;BOARD_TEMP3;BME_TEMP;BME_HUMIDITY;"
"BME_ALTITUDE;CPU_USAGE;MEM_USAGE;DISK_UTILIZATION";
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <mutex> // NOLINT

Comment on lines +25 to +36
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +66 to +69
logger_did_->Offer();
service_ipc_->StartOffer();
service_udp_->StartOffer();
SomeIpInit();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger_did_->Offer();
service_ipc_->StartOffer();
service_udp_->StartOffer();
SomeIpInit();
SomeIpInit();
logger_did_->Offer();
service_ipc_->StartOffer();
service_udp_->StartOffer();

Comment on lines +136 to +142
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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: mogłeś sobie skrócić kod robiąc metodę SetSystemStat

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment on lines +150 to +175
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());
}
});
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

teoretycznie to samo, metoda SetBoardTemp(const int16_t& value, const TempSensor_e sensor)

Comment on lines +177 to +186
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);
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

});
});

env_service_handler_->newBoardTempEvent_3.Subscribe(1, [this](std::uint8_t /*status*/) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@Mateusz-Krajewski Mateusz-Krajewski merged commit 16fc13a into master Apr 27, 2026
2 checks passed
@Mateusz-Krajewski Mateusz-Krajewski deleted the loger-fc branch April 27, 2026 18:18
Mateusz-Krajewski added a commit that referenced this pull request May 25, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FC Logger App

2 participants