Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/fc/logger_service/BUILD
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__",
],
)
93 changes: 93 additions & 0 deletions apps/fc/logger_service/data_type.cpp
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";
}
Comment on lines +19 to +23
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";
}


std::string Data_t::get_header() {
return kCsvHeader;
}
Comment on lines +25 to +27
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;
}


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();
}
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();
}


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
56 changes: 56 additions & 0 deletions apps/fc/logger_service/data_type.hpp
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
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

#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_
23 changes: 23 additions & 0 deletions apps/fc/logger_service/service/BUILD
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",
],
)
70 changes: 70 additions & 0 deletions apps/fc/logger_service/service/logger_builder.hpp
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_
54 changes: 54 additions & 0 deletions apps/fc/logger_service/service/logger_did.hpp
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_
Loading
Loading