Skip to content
Draft
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
1 change: 1 addition & 0 deletions deployment/cpu/ec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cpu_def(
etcs = [
"diag_config.json",
"logger_config.json",
"ntp_config.json",
],
platform_etcs = [
"//deployment/cpu/ec:sm_config",
Expand Down
5 changes: 5 additions & 0 deletions deployment/cpu/ec/ntp_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ip": "192.168.10.51",
"ntp_class": 4,
"T_hb_ms": 1000
}
1 change: 1 addition & 0 deletions deployment/cpu/fc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cpu_def(
etcs = [
"diag_config.json",
"logger_config.json",
"ntp_config.json",
],
platform_etcs = [
"//deployment/cpu/fc:sm_config",
Expand Down
5 changes: 5 additions & 0 deletions deployment/cpu/fc/ntp_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ip": "192.168.10.52",
"ntp_class": 3,
"T_hb_ms": 1000
}
14 changes: 14 additions & 0 deletions mw/timestamp_mw/ntp/config/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cc_library(
name = "ntp_config_manager",
srcs = [
"config_manager.cpp",
],
hdrs = [
"config_manager.hpp",
],
deps = [
"//core/json:simba_json",
"@srp_platform//ara/log",
],
visibility = ["//visibility:public"],
)
56 changes: 56 additions & 0 deletions mw/timestamp_mw/ntp/config/config_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @file config_manager.hpp
* @brief Loads device configuration
* @author Wiktor Müller (wiktor.muller8@gmail.com)
* @version 0.1
* @date 2026-05-02
*
* @copyright Copyright (c) 2025
*
*/

#include "mw/timestamp_mw/ntp/config/config_manager.hpp"
#include "core/json/json_parser.h"
#include "ara/log/log.h"

namespace srp {
namespace tinyNTP {
namespace {
static constexpr auto kDefault_ip = "127.0.0.1";
static constexpr auto kDefault_device_class = 7;
static constexpr auto kDefault_announce_interval = 1000;
} // namespace

NtpConfig ConfigManager::LoadConfig(const std::string& filepath) {
NtpConfig config;
// Podstawowe dane do fallbacku
config.ip = "127.0.0.1";
config.ntp_class = 7;
config.t_hb_ms = 1000;

auto parser_opt = srp::core::json::JsonParser::Parser(filepath);
if (!parser_opt.has_value()) {
ara::log::LogError() << "Cannot open or parse config file: " << filepath
<< ". Using fallback values.";
return config;
}
const auto& parser = parser_opt.value();

auto ip = parser.GetString("ip");
config.ip = ip.value_or(kDefault_ip);

auto ntp_class = parser.GetNumber<uint8_t>("ntp_class");
config.ntp_class = ntp_class.value_or(kDefault_device_class);
if (config.ntp_class > 7) {
ara::log::LogWarn() << "Config ntp_class > 7. Using fallback class 7.";
config.ntp_class = kDefault_device_class;
}

auto t_hb_ms = parser.GetNumber<uint32_t>("T_hb_ms");
config.t_hb_ms = t_hb_ms.value_or(kDefault_announce_interval);

return config;
}

} // namespace tinyNTP
} // namespace srp
43 changes: 43 additions & 0 deletions mw/timestamp_mw/ntp/config/config_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @file config_manager.hpp
* @brief Loads device configuration
* @author Wiktor Müller (wiktor.muller8@gmail.com)
* @version 0.1
* @date 2026-05-02
*
* @copyright Copyright (c) 2025
*
*/

#ifndef MW_TIMESTAMP_MW_NTP_CONFIG_CONFIG_MANAGER_HPP_
#define MW_TIMESTAMP_MW_NTP_CONFIG_CONFIG_MANAGER_HPP_

#include <string>
#include <cstdint>

namespace srp {
namespace tinyNTP {

constexpr auto kConfig_file_path = "/srp/opt/cpu_srp/ntp_config.json";

struct NtpConfig {
std::string ip;
uint8_t ntp_class;
uint32_t t_hb_ms;
};

class ConfigManager {
public:
/**
* @brief Wczytuje konfiguracje z pliku JSON
*
* @param filepath Ścieżka do pliku konfiguracyjnego
* @return NtpConfig Struktura z wczytanymi parametrami
*/
static NtpConfig LoadConfig(const std::string& filepath = kConfig_file_path);
};

} // namespace tinyNTP
} // namespace srp

#endif // MW_TIMESTAMP_MW_NTP_CONFIG_CONFIG_MANAGER_HPP_
5 changes: 4 additions & 1 deletion mw/timestamp_mw/ntp/controller/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ load("@srp_platform//tools/model_generator/ara:data_structure_generator.bzl", "d
cc_library(
name = "ntp_controller",
deps = [
"//communication-core/sockets:socket_tcp",
"//communication-core/sockets:socket_udp",
"//communication-core/sockets:socket_udp_multicast",
"//core/json:simba_json",
"//core/timestamp:timestamp_controller",
"//mw/timestamp_mw/ntp/controller:ntp_com_data",
"//mw/timestamp_mw/ntp/config:ntp_config_manager",
"//mw/timestamp_mw/ntp/discovery:ntp_discovery",
],
srcs = ["ntp_controller.cpp"],
hdrs = ["ntp_controller.hpp"],
Expand Down
Loading