fix: build now succeded. Added logging capabilities also

This commit is contained in:
2026-03-10 17:26:32 +00:00
parent 36093e6c73
commit 5b6f20a70a
3 changed files with 77 additions and 26 deletions

View File

@@ -7,13 +7,32 @@
#include "SysfsRead.hpp"
Producer::Producer(const std::filesystem::path& sysfs_path,
std::function<void(int)> send_fn, RandomFn random_fn
std::function<void(int)> send_fn, RandomFn random_fn,
LogFn log_fn, SleepFn sleep_fn)
: m_reader(sysfs_path),
m_send(std::move(send_fn)),
m_random(std::move(random_fn)),
m_log(std::move(log_fn)),
m_sleep(std::move(sleep_fn))
{
}
std::chrono::milliseconds Producer::compute_delay(SysfsStatus status) const
{
using namespace std::chrono_literals;
auto standard = 1000ms; // example: 1s, must be < 7s
auto hot = 7000ms; // exactly 7s
if (status == SysfsStatus::ErrorTempTooHigh)
{ // when error = temp too high
return hot;
}
else
{
return standard;
}
}
void Producer::start()
{
m_running.store(true);
@@ -28,28 +47,38 @@ void Producer::stop()
m_thread.join();
}
}
void Producer::run_loop()
{
auto status = m_reader.read_status();
switch (status)
while (m_running.load())
{
case SysfsStatus::Enabled:
m_send(m_random());
break;
auto status = m_reader.read_status();
switch (status)
{
case SysfsStatus::Enabled:
m_send(m_random());
if (m_log) m_log("Producer: Enabled");
break;
case SysfsStatus::Unreachable:
// do nothing for now
break;
case SysfsStatus::Unreachable:
// do nothing for now
if (m_log) m_log("Producer: SysfsFile Unreachable");
break;
case SysfsStatus::Empty:
break;
case SysfsStatus::Empty:
if (m_log) m_log("Producer: SysfsFile Empty");
break;
case SysfsStatus::ErrorTempTooHigh:
break;
case SysfsStatus::ErrorTempTooHigh:
if (m_log) m_log("Producer: Error temp too high!!");
break;
case SysfsStatus::UnexpectedValue:
break;
case SysfsStatus::UnexpectedValue:
if (m_log) m_log("Producer: UnexpectedValue");
break;
}
auto delay = compute_delay(status);
m_sleep(delay);
// Thread will end here (for now) stop will join it
}
m_sleep(delay);
// Thread will end here (for now) stop will join it
}