From 382b09a1644c391f019aa64e295968163049389b Mon Sep 17 00:00:00 2001 From: Mateusz Krajewski Date: Tue, 27 May 2025 15:46:43 +0200 Subject: [PATCH 1/6] fix rocket state --- .gitignore | 2 +- apps/fc/main_service/mainService.cpp | 2 +- apps/fc/main_service/rocketController.cpp | 19 ++----------------- apps/fc/main_service/rocket_state.h | 16 +++++++--------- apps/fc/main_service/service.hpp | 14 ++++---------- 5 files changed, 15 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index 23428c2a..64852bec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ bazel-* .vscode MODULE.bazel.lock -coverage-report \ No newline at end of file +coverage-report diff --git a/apps/fc/main_service/mainService.cpp b/apps/fc/main_service/mainService.cpp index 7063333a..a85a18c1 100644 --- a/apps/fc/main_service/mainService.cpp +++ b/apps/fc/main_service/mainService.cpp @@ -23,10 +23,10 @@ namespace service { namespace { constexpr auto kService_ipc_name = "srp/apps/MainService/MainService_ipc"; constexpr auto kService_udp_name = "srp/apps/RecoveryService/MainService_udp"; -using RocketState_t = apps::RocketState_t; const auto kMain_loop_delay_ms = 10; const auto kSend_event_time = 1000; } +using RocketState_t = apps::RocketState_t; MainService::MainService() {} diff --git a/apps/fc/main_service/rocketController.cpp b/apps/fc/main_service/rocketController.cpp index 94fabe95..6dcd98c5 100644 --- a/apps/fc/main_service/rocketController.cpp +++ b/apps/fc/main_service/rocketController.cpp @@ -32,11 +32,6 @@ void RocketController::Loop() { break; case RocketState_t::DISARM: break; - case RocketState_t::TANK: - if (last_state_ != RocketState_t::TANK) { - ActivateTankActuators(); - } - break; case RocketState_t::ARM: if (last_state_ != RocketState_t::ARM) { ArmRocket(); @@ -81,27 +76,17 @@ void RocketController::Loop() { // TODO(simba) open all actuator and disable power on actuator } break; - case RocketState_t::ABORD: + case RocketState_t::ABORT: // TODO(simba) open vent valve // TODO(simba) disable all actuator power break; - case RocketState_t::LOST_CONN: { - // NOW UNUSED - // if (last_state_ != RocketState_t::LOST_CONN) { - // LossConnSeq(); - // } - break; } -} -last_state_ = now_state; + last_state_ = now_state; } core::ErrorCode RocketController::InitializeCompleted() { return core::ErrorCode::kOk; } -core::ErrorCode RocketController::ActivateTankActuators() { - return core::ErrorCode::kOk; -} core::ErrorCode RocketController::ArmRocket() { // enable power on all stages return core::ErrorCode::kOk; diff --git a/apps/fc/main_service/rocket_state.h b/apps/fc/main_service/rocket_state.h index 15e25c89..432d92be 100644 --- a/apps/fc/main_service/rocket_state.h +++ b/apps/fc/main_service/rocket_state.h @@ -22,15 +22,13 @@ static std::shared_ptr rocket_state = nullptr; enum RocketState_t { INIT = 0, DISARM = 1, - TANK = 2, - ARM = 3, - CUTDOWN = 4, - CUTDOWN_END = 5, - FLIGHT = 6, - FALL = 7, - LANDED = 8, - ABORD = 50, - LOST_CONN = 52 + ARM = 2, + CUTDOWN = 3, + CUTDOWN_END = 4, + FLIGHT = 5, + FALL = 6, + LANDED = 7, + ABORT = 50, }; class RocketState { diff --git a/apps/fc/main_service/service.hpp b/apps/fc/main_service/service.hpp index 674ed566..f6d37bd1 100644 --- a/apps/fc/main_service/service.hpp +++ b/apps/fc/main_service/service.hpp @@ -20,15 +20,13 @@ namespace srp { namespace apps { static const std::unordered_map> allowed_transitions{ {RocketState_t::INIT, {RocketState_t::DISARM}}, - {RocketState_t::DISARM, {RocketState_t::TANK, RocketState_t::ABORD}}, - {RocketState_t::TANK, {RocketState_t::ARM, RocketState_t::ABORD}}, - {RocketState_t::ARM, {RocketState_t::CUTDOWN, RocketState_t::ABORD}}, - {RocketState_t::CUTDOWN, {RocketState_t::CUTDOWN_END, RocketState_t::ABORD}}, + {RocketState_t::DISARM, {RocketState_t::ARM, RocketState_t::ABORT}}, + {RocketState_t::ARM, {RocketState_t::CUTDOWN, RocketState_t::ABORT}}, + {RocketState_t::CUTDOWN, {RocketState_t::CUTDOWN_END, RocketState_t::ABORT}}, {RocketState_t::CUTDOWN_END, {RocketState_t::FLIGHT}}, {RocketState_t::FLIGHT, {RocketState_t::FALL}}, {RocketState_t::FALL, {RocketState_t::LANDED}}, - {RocketState_t::ABORD, {RocketState_t::DISARM}}, - {RocketState_t::LOST_CONN, {RocketState_t::DISARM}}, + {RocketState_t::ABORT, {RocketState_t::DISARM}} }; class MyMainServiceSkeleton: public MainServiceSkeleton { private: @@ -38,10 +36,6 @@ class MyMainServiceSkeleton: public MainServiceSkeleton { ara::log::LogWarn() << "CUTDOWN_END from CUTDOWN:This change needs to be called automatically by mainService, not from someip!"; } - if (req_state == RocketState_t::DISARM && actual_state == RocketState_t::LOST_CONN) { - ara::log::LogWarn() << - "DISARM from LOST_CONN: This change needs to be called automatically by mainService, not from someip!"; - } if (req_state == RocketState_t::DISARM && actual_state == RocketState_t::INIT) { ara::log::LogWarn() << "DISARM from INIT: This change needs to be called automatically by mainService, not from someip!"; From e38fdf9ceddfcbcdd67645f8cf2a2ced3d301393 Mon Sep 17 00:00:00 2001 From: Mateusz Krajewski Date: Tue, 27 May 2025 16:05:54 +0200 Subject: [PATCH 2/6] fix UT --- apps/fc/gps_service/gps_app.cpp | 7 +++--- apps/fc/gps_service/ut/BUILD | 1 + apps/fc/gps_service/ut/gps_app_test.cc | 3 +++ apps/fc/radio_service/ut/BUILD | 26 +++++++++++----------- apps/fc/radio_service/ut/radio_app_test.cc | 1 + core/timestamp/mock_timestamp_driver.h | 1 + core/timestamp/ut/timestamp_driver_test.cc | 8 +++---- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/apps/fc/gps_service/gps_app.cpp b/apps/fc/gps_service/gps_app.cpp index ea6a4b2c..99a6ff46 100644 --- a/apps/fc/gps_service/gps_app.cpp +++ b/apps/fc/gps_service/gps_app.cpp @@ -44,10 +44,9 @@ std::optional GPSApp::ParseGPSData(const std::vector& return std::nullopt; } auto someip_data = GetSomeIPData(res.value()); - // TODO(matikrajek42@gmail.com) uncoment afer basn advice - // ara::log::LogDebug() << "GPS latitude: " << someip_data.latitude - // << ", longtitude: " << someip_data.longitude << ",height(M):" - // << res.value().height << "satelite_nr: " << res.value().satellite_nr; + ara::log::LogDebug() << "GPS latitude: " << someip_data.latitude + << ", longtitude: " << someip_data.longitude << ",height(M):" + << res.value().height << "satelite_nr: " << res.value().satellite_nr; return someip_data; } diff --git a/apps/fc/gps_service/ut/BUILD b/apps/fc/gps_service/ut/BUILD index f42062a6..773c39da 100644 --- a/apps/fc/gps_service/ut/BUILD +++ b/apps/fc/gps_service/ut/BUILD @@ -8,5 +8,6 @@ cc_test( "@com_google_googletest//:gtest_main", "//apps/fc/gps_service:gps_app_lib", "//core/uart:mock_uart", + "@srp_platform//ara/log", ], ) \ No newline at end of file diff --git a/apps/fc/gps_service/ut/gps_app_test.cc b/apps/fc/gps_service/ut/gps_app_test.cc index f84eb37f..1d9cf5be 100644 --- a/apps/fc/gps_service/ut/gps_app_test.cc +++ b/apps/fc/gps_service/ut/gps_app_test.cc @@ -12,6 +12,7 @@ #include #include "apps/fc/gps_service/gps_app.hpp" #include "core/uart/mock_uart_driver.hpp" +#include "ara/log/log.h" using ::testing::Return; @@ -107,6 +108,7 @@ TEST(GPSAppTest2, ParseGPSData_ZeroSatellites_ReturnsNullopt) { } TEST(GPSAppTest2, ParseGPSData) { + ara::log::LoggingMenager::Create("123", ara::log::LogMode::kConsole); std::string str = "$GNGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"; std::vector vec(str.begin(), str.end()); auto res = srp::apps::GPSApp::ParseGPSData(vec); @@ -115,6 +117,7 @@ TEST(GPSAppTest2, ParseGPSData) { EXPECT_NEAR(res.value().longitude, 1131.000, 0.001); } TEST(GPSAppTest2, ParseGPSData2) { + ara::log::LoggingMenager::Create("123", ara::log::LogMode::kConsole); std::string str = "$GNGGA,123519,4807.038,S,01131.000,W,1,08,0.9,545.4,M,46.9,M,,*47"; std::vector vec(str.begin(), str.end()); auto res = srp::apps::GPSApp::ParseGPSData(vec); diff --git a/apps/fc/radio_service/ut/BUILD b/apps/fc/radio_service/ut/BUILD index e81f530b..7a18a067 100644 --- a/apps/fc/radio_service/ut/BUILD +++ b/apps/fc/radio_service/ut/BUILD @@ -1,16 +1,16 @@ -# cc_test( -# name = "radio_app_test", -# srcs = [ -# "radio_app_test.cc" -# ], -# visibility = ["//visibility:public"], -# deps = [ -# "@com_google_googletest//:gtest_main", -# "//apps/fc/radio_service:radio_app_lib", -# "//core/uart:mock_uart", -# "//core/timestamp:mock_timestamp_controller", -# ], -# ) +cc_test( + name = "radio_app_test", + srcs = [ + "radio_app_test.cc" + ], + visibility = ["//visibility:public"], + deps = [ + "@com_google_googletest//:gtest_main", + "//apps/fc/radio_service:radio_app_lib", + "//core/uart:mock_uart", + "//core/timestamp:mock_timestamp_controller", + ], +) cc_test( name = "event_data_test", diff --git a/apps/fc/radio_service/ut/radio_app_test.cc b/apps/fc/radio_service/ut/radio_app_test.cc index 1dc4791b..714b8488 100644 --- a/apps/fc/radio_service/ut/radio_app_test.cc +++ b/apps/fc/radio_service/ut/radio_app_test.cc @@ -17,6 +17,7 @@ using ::testing::_; using ::testing::Invoke; TEST(RADIOAPPTEST, InitializeTestNoUart) { + ara::log::LoggingMenager::Create("123", ara::log::LogMode::kConsole); const std::map map; srp::apps::RadioApp app; EXPECT_EQ(app.Initialize(map), 1); diff --git a/core/timestamp/mock_timestamp_driver.h b/core/timestamp/mock_timestamp_driver.h index 364be5a5..a0c12747 100644 --- a/core/timestamp/mock_timestamp_driver.h +++ b/core/timestamp/mock_timestamp_driver.h @@ -19,6 +19,7 @@ class MockTimestampController : public srp::core::timestamp::ITimestampControlle public: MOCK_METHOD(std::optional, GetNewTimeStamp, (), (override)); MOCK_METHOD(bool, Init, (), (override)); + MOCK_METHOD(int64_t, GetDeltaTime, (const int64_t now, const int64_t previous), (override)); }; class MockTimestampMaster : public srp::core::timestamp::ITimestampMaster { diff --git a/core/timestamp/ut/timestamp_driver_test.cc b/core/timestamp/ut/timestamp_driver_test.cc index cd743d71..5ba8a7bd 100644 --- a/core/timestamp/ut/timestamp_driver_test.cc +++ b/core/timestamp/ut/timestamp_driver_test.cc @@ -18,7 +18,7 @@ namespace srp { namespace core { namespace timestamp { -constexpr auto KBasicCorrection = 50; +constexpr auto KBasicCorrection = 0.1; class TimestampMasterTest : public ::testing::Test { protected: TimestampMaster master; @@ -38,9 +38,9 @@ TEST_F(TimestampMasterTest, GetNewTimeStampReturnsElapsedTime) { std::this_thread::sleep_for(std::chrono::milliseconds(K3)); int64_t timestamp3 = master.GetNewTimeStamp(); - EXPECT_NEAR(timestamp, K1, KBasicCorrection); - EXPECT_NEAR(timestamp2, K1 + K2, KBasicCorrection); - EXPECT_NEAR(timestamp3, K1 + K2 + K3, 3 * KBasicCorrection); + EXPECT_NEAR(timestamp, K1, K1 * KBasicCorrection); + EXPECT_NEAR(timestamp2, K1 + K2, (K1 + K2) * KBasicCorrection); + EXPECT_NEAR(timestamp3, K1 + K2 + K3, (K1 + K2 + K3) * KBasicCorrection); } TEST_F(TimestampMasterTest, CorrectStartPointAdjustsStartTime) { From cc27e098183f73767230626ad678f6b7e74443e7 Mon Sep 17 00:00:00 2001 From: Mateusz Krajewski Date: Tue, 27 May 2025 16:42:05 +0200 Subject: [PATCH 3/6] add error to gps msg receiver and add modifiable uart timeout --- apps/fc/gps_service/gps_app.cpp | 25 ++++++++++++++++++++++++- apps/fc/gps_service/gps_app.hpp | 7 +++++-- apps/fc/gps_service/ut/BUILD | 2 +- core/pd-33x/rs485/ut/rs485_test.cc | 12 ++++++------ core/uart/Iuart_driver.hpp | 2 +- core/uart/mock_uart_driver.hpp | 2 +- core/uart/uart_driver.cpp | 11 ++++++++++- core/uart/uart_driver.hpp | 2 +- 8 files changed, 49 insertions(+), 14 deletions(-) diff --git a/apps/fc/gps_service/gps_app.cpp b/apps/fc/gps_service/gps_app.cpp index 99a6ff46..dea04f8c 100644 --- a/apps/fc/gps_service/gps_app.cpp +++ b/apps/fc/gps_service/gps_app.cpp @@ -20,6 +20,8 @@ namespace { constexpr auto kService_udp_instance = "srp/apps/GPSApp/GPSService_udp"; constexpr auto KGPS_UART_path = "/dev/ttyS1"; constexpr auto KGPS_UART_baudrate = B230400; + constexpr uint16_t KGps_expected_interval = 1000; + constexpr auto kGps_freq_tolerance = 100; } GPSDataStructure GPSApp::GetSomeIPData(const core::GPS_DATA_T& data) { @@ -50,14 +52,34 @@ std::optional GPSApp::ParseGPSData(const std::vector& return someip_data; } +float GPSApp::GetFreq(const int64_t delta) const { + return static_cast(1.0f / static_cast(delta) * 1000); +} + int GPSApp::Run(const std::stop_token& token) { while (!token.stop_requested()) { + auto now = std::chrono::high_resolution_clock::now(); + auto delta = std::chrono::duration_cast(now - last_frame).count(); + if (delta > KGps_expected_interval + kGps_freq_tolerance) { + ara::log::LogWarn() << "Missing GPS frame"; + } + auto data = uart_->Read(); if (!data.has_value()) { continue; } auto res = ParseGPSData(data.value()); if (res.has_value()) { + auto now = std::chrono::high_resolution_clock::now(); + auto delta = std::chrono::duration_cast(now - last_frame).count(); + if (std::abs(delta - KGps_expected_interval) > kGps_freq_tolerance) { + ara::log::LogWarn() << "GPS frequency deviation detected: interval = " << std::to_string(delta) << " ms"; + } + + double freq_hz = GetFreq(delta); + ara::log::LogDebug() << "GPS data freq: " << std::to_string(freq_hz) << " Hz"; + + last_frame = now; service_ipc->GPSStatusEvent.Update(res.value()); service_udp->GPSStatusEvent.Update(res.value()); } @@ -75,7 +97,7 @@ int GPSApp::Initialize(const std::map(); Init(std::move(uart_d)); } - if (!this->uart_->Open(KGPS_UART_path, KGPS_UART_baudrate)) { + if (!this->uart_->Open(KGPS_UART_path, KGPS_UART_baudrate, 1)) { return 1; } service_ipc = std::make_unique(service_ipc_instance); @@ -83,6 +105,7 @@ int GPSApp::Initialize(const std::mapStartOffer(); service_udp->StartOffer(); ara::log::LogInfo() << "End initialization"; + last_frame = std::chrono::high_resolution_clock::now(); return 0; } diff --git a/apps/fc/gps_service/gps_app.hpp b/apps/fc/gps_service/gps_app.hpp index 32fba4bd..1267a302 100644 --- a/apps/fc/gps_service/gps_app.hpp +++ b/apps/fc/gps_service/gps_app.hpp @@ -17,6 +17,7 @@ #include #include #include // NOLINT +#include // NOLINT #include "ara/exec/adaptive_application.h" #include "srp/apps/GPSServiceSkeleton.h" @@ -35,6 +36,10 @@ class GPSApp final : public ara::exec::AdaptiveApplication { std::unique_ptr service_udp; std::unique_ptr uart_; + std::chrono::high_resolution_clock::time_point last_frame; + + float GetFreq(const int64_t delta) const; + public: static std::optional ParseGPSData(const std::vector& data); void Init(std::unique_ptr uart); @@ -52,8 +57,6 @@ class GPSApp final : public ara::exec::AdaptiveApplication { */ int Initialize(const std::map parms) override; - - public: ~GPSApp(); GPSApp(); }; diff --git a/apps/fc/gps_service/ut/BUILD b/apps/fc/gps_service/ut/BUILD index 773c39da..adffd53a 100644 --- a/apps/fc/gps_service/ut/BUILD +++ b/apps/fc/gps_service/ut/BUILD @@ -10,4 +10,4 @@ cc_test( "//core/uart:mock_uart", "@srp_platform//ara/log", ], -) \ No newline at end of file +) diff --git a/core/pd-33x/rs485/ut/rs485_test.cc b/core/pd-33x/rs485/ut/rs485_test.cc index b02257af..463db934 100644 --- a/core/pd-33x/rs485/ut/rs485_test.cc +++ b/core/pd-33x/rs485/ut/rs485_test.cc @@ -24,7 +24,7 @@ TEST(RS485Test, InitSuccess) { auto uart_mock = std::make_unique(); auto gpio_mock = std::make_unique(); - EXPECT_CALL(*uart_mock, Open(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*uart_mock, Open(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*uart_mock, Close()).Times(1); EXPECT_TRUE(rs485.Init(config, std::move(uart_mock), std::move(gpio_mock))); @@ -36,7 +36,7 @@ TEST(RS485Test, InitFailure) { auto uart_mock = std::make_unique(); auto gpio_mock = std::make_unique(); - EXPECT_CALL(*uart_mock, Open(_, _)).WillOnce(Return(false)); + EXPECT_CALL(*uart_mock, Open(_, _, _)).WillOnce(Return(false)); EXPECT_CALL(*uart_mock, Close()).Times(1); EXPECT_FALSE(rs485.Init(config, std::move(uart_mock), std::move(gpio_mock))); @@ -51,7 +51,7 @@ TEST(RS485Test, WriteReadSuccess) { auto uart_mock = std::make_unique(); auto gpio_mock = std::make_unique(); - EXPECT_CALL(*uart_mock, Open(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*uart_mock, Open(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*gpio_mock, SetPinValue(1, 1)).WillOnce(Return(srp::core::ErrorCode::kOk)); EXPECT_CALL(*uart_mock, Write(data)).WillOnce(Return(srp::core::ErrorCode::kOk)); EXPECT_CALL(*gpio_mock, SetPinValue(1, 0)).WillOnce(Return(srp::core::ErrorCode::kOk)); @@ -73,7 +73,7 @@ TEST(RS485Test, WriteReadFail1) { auto uart_mock = std::make_unique(); auto gpio_mock = std::make_unique(); - EXPECT_CALL(*uart_mock, Open(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*uart_mock, Open(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*gpio_mock, SetPinValue(1, 1)).WillOnce(Return(srp::core::ErrorCode::kNotDefine)); EXPECT_CALL(*uart_mock, Close()).Times(1); @@ -91,7 +91,7 @@ TEST(RS485Test, WriteReadFail2) { auto uart_mock = std::make_unique(); auto gpio_mock = std::make_unique(); - EXPECT_CALL(*uart_mock, Open(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*uart_mock, Open(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*gpio_mock, SetPinValue(1, 1)).WillOnce(Return(srp::core::ErrorCode::kOk)); EXPECT_CALL(*uart_mock, Write(data)).WillOnce(Return(srp::core::ErrorCode::kNotDefine)); EXPECT_CALL(*uart_mock, Close()).Times(1); @@ -109,7 +109,7 @@ TEST(RS485Test, WriteReadFail3) { auto uart_mock = std::make_unique(); auto gpio_mock = std::make_unique(); - EXPECT_CALL(*uart_mock, Open(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*uart_mock, Open(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*gpio_mock, SetPinValue(1, 1)).WillOnce(Return(srp::core::ErrorCode::kOk)); EXPECT_CALL(*uart_mock, Write(data)).WillOnce(Return(srp::core::ErrorCode::kOk)); EXPECT_CALL(*gpio_mock, SetPinValue(1, 0)).WillOnce(Return(srp::core::ErrorCode::kNotDefine)); diff --git a/core/uart/Iuart_driver.hpp b/core/uart/Iuart_driver.hpp index 5fd45375..d4500a66 100644 --- a/core/uart/Iuart_driver.hpp +++ b/core/uart/Iuart_driver.hpp @@ -23,7 +23,7 @@ namespace uart { class IUartDriver { public: - virtual bool Open(const std::string& portName, const uint32_t& baudrate = B9600) = 0; + virtual bool Open(const std::string& portName, const uint32_t& baudrate = B9600, const uint8_t timeout = 10) = 0; virtual std::optional> Read(const uint16_t size = 0) = 0; virtual void Close() = 0; virtual core::ErrorCode Write(const std::vector& data) = 0; diff --git a/core/uart/mock_uart_driver.hpp b/core/uart/mock_uart_driver.hpp index 9c9ad0c9..8ea6a13e 100644 --- a/core/uart/mock_uart_driver.hpp +++ b/core/uart/mock_uart_driver.hpp @@ -18,7 +18,7 @@ class MockUartDriver : public srp::core::uart::IUartDriver { public: - MOCK_METHOD(bool, Open, (const std::string& portName, const uint32_t& baudrate), (override)); + MOCK_METHOD(bool, Open, (const std::string& portName, const uint32_t& baudrate, const uint8_t timeout), (override)); MOCK_METHOD(std::optional>, Read, (const uint16_t size), (override)); MOCK_METHOD(void, Close, (), (override)); MOCK_METHOD(srp::core::ErrorCode, Write, (const std::vector& data), (override)); diff --git a/core/uart/uart_driver.cpp b/core/uart/uart_driver.cpp index f7e77aac..4677b44e 100644 --- a/core/uart/uart_driver.cpp +++ b/core/uart/uart_driver.cpp @@ -34,7 +34,16 @@ core::ErrorCode UartDriver::Write(const std::vector& data) { return core::ErrorCode::kOk; } -bool UartDriver::Open(const std::string& portName, const uint32_t& baudrate) { +/** + * @brief + * + * @param portName + * @param baudrate + * @param timeout // value in deciseconds + * @return true + * @return false + */ +bool UartDriver::Open(const std::string& portName, const uint32_t& baudrate, const uint8_t timeout) { serial_port = open(portName.c_str(), O_RDWR | O_NOCTTY); if (serial_port == -1) { return false; diff --git a/core/uart/uart_driver.hpp b/core/uart/uart_driver.hpp index 6fce7fd5..b68b49cc 100644 --- a/core/uart/uart_driver.hpp +++ b/core/uart/uart_driver.hpp @@ -27,7 +27,7 @@ class UartDriver: public IUartDriver { int serial_port; public: - bool Open(const std::string& portName, const uint32_t& baudrate = B9600) override; + bool Open(const std::string& portName, const uint32_t& baudrate = B9600, const uint8_t timeout = 10) override; std::optional> Read(const uint16_t size = 0) override; core::ErrorCode Write(const std::vector& data) override; void Close() override; From 332ceeb45548799f996bda75e268abb65b1dbfa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20=C5=9Anieg?= Date: Tue, 27 May 2025 17:29:52 +0200 Subject: [PATCH 4/6] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 64852bec..ed3fcdbd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bazel-* .vscode MODULE.bazel.lock coverage-report + From 82f6bc021b298b160426650a6a45615603f357c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20=C5=9Anieg?= Date: Tue, 27 May 2025 17:57:14 +0200 Subject: [PATCH 5/6] Update uart_driver.cpp --- core/uart/uart_driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/uart/uart_driver.cpp b/core/uart/uart_driver.cpp index 4677b44e..1217f09d 100644 --- a/core/uart/uart_driver.cpp +++ b/core/uart/uart_driver.cpp @@ -35,7 +35,7 @@ core::ErrorCode UartDriver::Write(const std::vector& data) { } /** - * @brief + * @brief geswrgewrg * * @param portName * @param baudrate From 46af43eafc53cd74d3a7e52a191f647d341de7fe Mon Sep 17 00:00:00 2001 From: Mateusz Krajewski Date: Tue, 27 May 2025 19:30:46 +0200 Subject: [PATCH 6/6] fix to many logs issue, remove libdoip submodule --- .gitmodules | 3 --- apps/fc/gps_service/gps_app.cpp | 28 ++++++++++++++-------------- apps/fc/gps_service/gps_app.hpp | 2 +- libdoip | 1 - 4 files changed, 15 insertions(+), 19 deletions(-) delete mode 160000 libdoip diff --git a/.gitmodules b/.gitmodules index 33981723..cd65c9e4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,3 @@ [submodule "third_party/python/someipy"] path = third_party/python/someipy url = git@github.com:Simba-Avionic/someipy.git -[submodule "libdoip"] - path = libdoip - url = https://github.com/Simba-Avionic/libdoip diff --git a/apps/fc/gps_service/gps_app.cpp b/apps/fc/gps_service/gps_app.cpp index dea04f8c..6b0fa76d 100644 --- a/apps/fc/gps_service/gps_app.cpp +++ b/apps/fc/gps_service/gps_app.cpp @@ -52,16 +52,19 @@ std::optional GPSApp::ParseGPSData(const std::vector& return someip_data; } -float GPSApp::GetFreq(const int64_t delta) const { - return static_cast(1.0f / static_cast(delta) * 1000); +int64_t GPSApp::GetTimeDelata() const { + auto now = std::chrono::high_resolution_clock::now(); + return std::chrono::duration_cast(now - last_frame).count(); } int GPSApp::Run(const std::stop_token& token) { + uint32_t warn_num = 0; while (!token.stop_requested()) { - auto now = std::chrono::high_resolution_clock::now(); - auto delta = std::chrono::duration_cast(now - last_frame).count(); - if (delta > KGps_expected_interval + kGps_freq_tolerance) { - ara::log::LogWarn() << "Missing GPS frame"; + if (GetTimeDelata() > KGps_expected_interval + kGps_freq_tolerance) { + if (warn_num < 1) { + ara::log::LogWarn() << "Missing GPS frame"; + } + warn_num +=1; } auto data = uart_->Read(); @@ -70,16 +73,13 @@ int GPSApp::Run(const std::stop_token& token) { } auto res = ParseGPSData(data.value()); if (res.has_value()) { - auto now = std::chrono::high_resolution_clock::now(); - auto delta = std::chrono::duration_cast(now - last_frame).count(); + auto delta = GetTimeDelata(); if (std::abs(delta - KGps_expected_interval) > kGps_freq_tolerance) { ara::log::LogWarn() << "GPS frequency deviation detected: interval = " << std::to_string(delta) << " ms"; } - - double freq_hz = GetFreq(delta); - ara::log::LogDebug() << "GPS data freq: " << std::to_string(freq_hz) << " Hz"; - - last_frame = now; + ara::log::LogDebug() << "GPS frequency deviation detected: interval = " << std::to_string(delta) << " ms"; + warn_num = 0; + last_frame = std::chrono::high_resolution_clock::now(); service_ipc->GPSStatusEvent.Update(res.value()); service_udp->GPSStatusEvent.Update(res.value()); } @@ -104,7 +104,7 @@ int GPSApp::Initialize(const std::map(service_udp_instance); service_ipc->StartOffer(); service_udp->StartOffer(); - ara::log::LogInfo() << "End initialization"; + ara::log::LogDebug() << "End initialization"; last_frame = std::chrono::high_resolution_clock::now(); return 0; } diff --git a/apps/fc/gps_service/gps_app.hpp b/apps/fc/gps_service/gps_app.hpp index 1267a302..3a0e7bcf 100644 --- a/apps/fc/gps_service/gps_app.hpp +++ b/apps/fc/gps_service/gps_app.hpp @@ -38,7 +38,7 @@ class GPSApp final : public ara::exec::AdaptiveApplication { std::chrono::high_resolution_clock::time_point last_frame; - float GetFreq(const int64_t delta) const; + int64_t GetTimeDelata() const; public: static std::optional ParseGPSData(const std::vector& data); diff --git a/libdoip b/libdoip deleted file mode 160000 index 88921494..00000000 --- a/libdoip +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 889214942e326026b02176330da887cbf6d851e6