From c6fbdc0cb81cacfe5da6d2c7e7732e6e8822f955 Mon Sep 17 00:00:00 2001 From: Henry Wurzburg Date: Sun, 24 Apr 2022 07:12:03 -0500 Subject: [PATCH] AP_Relay:Prevent operation for sim-on-hardware,add logs Co-authored-by: Iampete1 --- libraries/AP_Relay/AP_Relay.cpp | 13 +++++++++++++ libraries/AP_Relay/AP_Relay.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/libraries/AP_Relay/AP_Relay.cpp b/libraries/AP_Relay/AP_Relay.cpp index 577d22ed81..578ab4fdf5 100644 --- a/libraries/AP_Relay/AP_Relay.cpp +++ b/libraries/AP_Relay/AP_Relay.cpp @@ -7,6 +7,7 @@ #include #include "AP_Relay.h" +#include #if CONFIG_HAL_BOARD == HAL_BOARD_SITL #define RELAY1_PIN_DEFAULT 13 @@ -140,6 +141,18 @@ void AP_Relay::set(const uint8_t instance, const bool value) if (_pin[instance] == -1) { return; } + const uint32_t now = AP_HAL::millis(); + _pin_states = value ? _pin_states | (1U< 10)) { + AP::logger().Write("RELY", "TimeUS,State", "s-", "F-", "QB", + AP_HAL::micros64(), + _pin_states); + _last_log_ms = now; + _last_logged_pin_states = _pin_states; + } +#if AP_SIM_ENABLED && (CONFIG_HAL_BOARD != HAL_BOARD_SITL) + return; +#endif hal.gpio->pinMode(_pin[instance], HAL_GPIO_OUTPUT); hal.gpio->write(_pin[instance], value); } diff --git a/libraries/AP_Relay/AP_Relay.h b/libraries/AP_Relay/AP_Relay.h index a13748d9d5..9a7dcdf389 100644 --- a/libraries/AP_Relay/AP_Relay.h +++ b/libraries/AP_Relay/AP_Relay.h @@ -50,6 +50,9 @@ private: AP_Int8 _pin[AP_RELAY_NUM_RELAYS]; AP_Int8 _default; + uint8_t _pin_states; + uint8_t _last_logged_pin_states; + uint32_t _last_log_ms; void set(uint8_t instance, bool value); };