RedfishSensor: Configurable polling intervall

Add ability to re-configure RedfishServer polling interval through
EntityManager .json file

Tested: on gbcm. Added "PollRateMS": 500 to RedfishServer
entity and verified new polling interval takes place.
Platforms-Affected: Only platforms with satellite BMCs
Google-Bug-Id: 384995794
Fusion2:
https://fusion2.corp.google.com/7af764ef-7966-3913-84d5-edebdca5f776
https://fusion2.corp.google.com/4dd13dd3-cfbc-38fc-b090-8acbe06a8bb2
https://fusion2.corp.google.com/cac6bf5f-75f3-3567-bf1f-e7b9d529fc47
https://fusion2.corp.google.com/0ccf9424-bbab-3d73-9b28-cf056b7f1674
Change-Id: I6c2b460dcb1d8bd191263b6a10e35b9c4b7416e2
Signed-off-by: Eyal Ron <eyalron@google.com>
(cherry picked from commit 75c37b9cd4d4f86b93c20addbd93ef3e5bda4611)
diff --git a/recipes-phosphor/sensors/dbus-sensors/0105-RedfishSensor-Configurable-polling-intervall.patch b/recipes-phosphor/sensors/dbus-sensors/0105-RedfishSensor-Configurable-polling-intervall.patch
new file mode 100644
index 0000000..e1d952c
--- /dev/null
+++ b/recipes-phosphor/sensors/dbus-sensors/0105-RedfishSensor-Configurable-polling-intervall.patch
@@ -0,0 +1,116 @@
+From b57e5d09a09e5a6c0fb3cc8d6a617c7a51b240d1 Mon Sep 17 00:00:00 2001
+From: Eyal Ron <eyalron@google.com>
+Date: Thu, 30 Jan 2025 00:56:48 +0000
+Subject: [PATCH] RedfishSensor: Configurable polling intervall
+
+Add ability to re-configure RedfishServer polling interval through
+EntityManager .json file
+
+Patch Tracking Bug: b/384995794
+Upstream info: Not upstreamed yet
+Upstream-Status: Pending
+Justification: This change is dependent on the below patch
+0104-RedfishSensor-Port-feature-and-other-cleanups.patch
+
+Signed-off-by: Eyal Ron <eyalron@google.com>
+---
+ src/RedfishSensor.cpp     |  4 ++--
+ src/RedfishSensor.hpp     |  1 +
+ src/RedfishSensorMain.cpp | 12 +++++++++++-
+ 3 files changed, 14 insertions(+), 3 deletions(-)
+
+diff --git a/src/RedfishSensor.cpp b/src/RedfishSensor.cpp
+index ee6e48b..b2f08d4 100644
+--- a/src/RedfishSensor.cpp
++++ b/src/RedfishSensor.cpp
+@@ -13,7 +13,6 @@
+ 
+ static constexpr bool debug = false;
+ 
+-static constexpr int pollIntervalTimeMs = 1000;
+ static constexpr int staleSensorTimeMs = 4000;
+ 
+ const RedfishUnit& RedfishUnitLookup::lookup(const std::string& name) const
+@@ -337,6 +336,7 @@ void RedfishServer::startTimer()
+     pollTimer.emplace(*ioContext);
+     std::chrono::steady_clock::time_point when =
+         std::chrono::steady_clock::now();
++
+     when += std::chrono::milliseconds(pollIntervalTimeMs);
+ 
+     auto weakThis = weak_from_this();
+@@ -348,7 +348,7 @@ void RedfishServer::startTimer()
+ 
+     if constexpr (debug)
+     {
+-        std::cerr << "Server " << configName << " timer ready\n";
++        std::cerr << "Server " << configName << " pollInterval " << pollIntervalTimeMs << "ms. timer ready\n";
+     }
+ }
+ 
+diff --git a/src/RedfishSensor.hpp b/src/RedfishSensor.hpp
+index 4c9fb02..7a6c996 100644
+--- a/src/RedfishSensor.hpp
++++ b/src/RedfishSensor.hpp
+@@ -182,6 +182,7 @@ class RedfishServer : public std::enable_shared_from_this<RedfishServer>
+     std::string user;
+     std::string password;
+     int port = 0;
++    int pollIntervalTimeMs = 0;
+ 
+     int readingsReaped = 0;
+     int readingsReports = 0;
+diff --git a/src/RedfishSensorMain.cpp b/src/RedfishSensorMain.cpp
+index 2d219aa..9a7b294 100644
+--- a/src/RedfishSensorMain.cpp
++++ b/src/RedfishSensorMain.cpp
+@@ -19,6 +19,9 @@ static constexpr auto defaultProtocol = "http";
+ // Default port number will be looked up dynamically by protocol
+ static constexpr int defaultPort = -1;
+ 
++// Default polling interval in milli-seconds
++static constexpr int defaultPollIntervalTimeMs = 1000;
++
+ static constexpr auto sensorTypes{std::to_array<const char*>(
+     {"RedfishSensor", "RedfishChassis", "RedfishServer"})};
+ 
+@@ -459,6 +462,7 @@ void createSensorsCallback(
+             std::string serverHost;
+             std::string serverProtocol = defaultProtocol;
+             auto serverPort = static_cast<double>(defaultPort);
++            auto pollIntervalTimeMs = static_cast<double>(defaultPollIntervalTimeMs);
+ 
+             // Host is only mandatory parameter
+             if (!fillConfigString(baseConfigMap, interfacePath, "Host", true,
+@@ -480,6 +484,11 @@ void createSensorsCallback(
+             }
+ 
+             // FUTURE: Parse additional optional parameters
++            if (!fillConfigNumber(baseConfigMap, interfacePath, "PollRateMS", false,
++                                  pollIntervalTimeMs))
++            {
++                continue;
++            }
+ 
+             auto newServer = std::make_shared<RedfishServer>();
+ 
+@@ -488,6 +497,7 @@ void createSensorsCallback(
+             newServer->host = serverHost;
+             newServer->protocol = serverProtocol;
+             newServer->port = static_cast<int>(serverPort);
++            newServer->pollIntervalTimeMs = static_cast<int>(pollIntervalTimeMs);
+ 
+             // FUTURE: Provide additional optional parameters
+ 
+@@ -497,7 +507,7 @@ void createSensorsCallback(
+             {
+                 std::cerr << "Added server " << sensorName << ": host "
+                           << serverHost << ", protocol " << serverProtocol
+-                          << ", port " << serverPort << "\n";
++                          << ", port " << serverPort << ", pollIntervalMs " << pollIntervalTimeMs << "\n";
+             }
+             continue;
+         }
+-- 
+2.48.1.362.g079036d154-goog
+
diff --git a/recipes-phosphor/sensors/dbus-sensors_%.bbappend b/recipes-phosphor/sensors/dbus-sensors_%.bbappend
index 5152601..33be576 100644
--- a/recipes-phosphor/sensors/dbus-sensors_%.bbappend
+++ b/recipes-phosphor/sensors/dbus-sensors_%.bbappend
@@ -13,6 +13,7 @@
   file://0102-RedfishSensor-Network-error-handling-teardown.patch \
   file://0103-RedfishSensor-Intentionally-drop-reported-stale.patch \
   file://0104-RedfishSensor-Port-feature-and-other-cleanups.patch \
+  file://0105-RedfishSensor-Configurable-polling-intervall.patch \
   file://0010-dbus-sensors-Creating-association-between-inventory-.patch \
   file://0001-intrusionsensor-Add-Assosication-interfaces-for-cabl.patch \
   file://0001-adcsensor-Add-optional-battery-status-interface.patch \