From aaf153c6a158fac0433005537494872c04509bde Mon Sep 17 00:00:00 2001 From: Dieter Niklaus Date: Sat, 4 Aug 2018 02:13:35 +0200 Subject: [PATCH] fix: use actual BatteryThresholdConfig, improve tracing --- Battery.cpp | 18 ++++++++++++------ BatteryImpl.cpp | 34 ++++++++++++++++++++++++++++++---- BatteryImpl.h | 5 +++++ BatteryVoltageEvalFsm.cpp | 12 ++++++------ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/Battery.cpp b/Battery.cpp index b8ac8e4..58b4939 100644 --- a/Battery.cpp +++ b/Battery.cpp @@ -38,40 +38,46 @@ void BatteryAdapter::notifyBattVoltageOk() { if (0 != m_trPort) { - TR_PRINTF(m_trPort, DbgTrace_Level::debug, "BatteryAdapter::notifyBattVoltageOk()"); + TR_PRINTF(m_trPort, DbgTrace_Level::info, "BatteryAdapter::notifyBattVoltageOk()"); } + notifyBattStateAnyChange(); } void BatteryAdapter::notifyBattVoltageBelowWarnThreshold() { if (0 != m_trPort) { - TR_PRINTF(m_trPort, DbgTrace_Level::debug, "BatteryAdapter::notifyBattVoltageBelowWarnThreshold()"); + TR_PRINTF(m_trPort, DbgTrace_Level::info, "BatteryAdapter::notifyBattVoltageBelowWarnThreshold()"); } + notifyBattStateAnyChange(); } void BatteryAdapter::notifyBattVoltageBelowStopThreshold() { if (0 != m_trPort) { - TR_PRINTF(m_trPort, DbgTrace_Level::debug, "BatteryAdapter::notifyBattVoltageBelowStopThreshold()"); + TR_PRINTF(m_trPort, DbgTrace_Level::info, "BatteryAdapter::notifyBattVoltageBelowStopThreshold()"); } + notifyBattStateAnyChange(); } void BatteryAdapter::notifyBattVoltageBelowShutdownThreshold() { if (0 != m_trPort) { - TR_PRINTF(m_trPort, DbgTrace_Level::debug, "BatteryAdapter::notifyBattVoltageBelowShutdownThreshold()"); + TR_PRINTF(m_trPort, DbgTrace_Level::info, "BatteryAdapter::notifyBattVoltageBelowShutdownThreshold()"); } + notifyBattStateAnyChange(); } void BatteryAdapter::notifyBattStateAnyChange() { if ((0 != m_trPort) && (0 != m_battery)) { - TR_PRINTF(m_trPort, DbgTrace_Level::info, "BatteryAdapter::notifyBattStateAnyChange(), %d [mV], %s", - m_battery->getBatteryVoltage() * 1000, m_battery->isBattVoltageOk() ? "ok" : "/!\\"); + TR_PRINTF(m_trPort, DbgTrace_Level::notice, "BatteryAdapter::notifyBattStateAnyChange(), %d.%02dV, %s", + static_cast(m_battery->getBatteryVoltage()), + static_cast(m_battery->getBatteryVoltage()*100.0)-static_cast(m_battery->getBatteryVoltage())*100, + m_battery->isBattVoltageOk() ? "ok" : "/!\\"); } } diff --git a/BatteryImpl.cpp b/BatteryImpl.cpp index df587c2..aba2d55 100644 --- a/BatteryImpl.cpp +++ b/BatteryImpl.cpp @@ -67,7 +67,7 @@ BatteryImpl::BatteryImpl(BatteryAdapter* adapter, BatteryThresholdConfig battery , m_evalFsm(new BatteryVoltageEvalFsm(this)) , m_startupTimer(new Timer(new BattStartupTimerAdapter(this), Timer::IS_NON_RECURRING, s_DEFAULT_STARTUP_TIME)) , m_pollTimer(new Timer(new BattPollTimerAdapter(this), Timer::IS_RECURRING)) -, m_trPort(new DbgTrace_Port("batt", DbgTrace_Level::info)) +, m_trPort(new DbgTrace_Port("batt", DbgTrace_Level::notice)) , m_batteryVoltage(0.0) , m_battVoltageSenseFactor(2.0) , m_battWarnThreshd(batteryThresholdConfig.battWarnThreshd) @@ -115,11 +115,17 @@ void BatteryImpl::evaluateStatus() if ((0 != m_adapter) && (0 != m_evalFsm)) { m_batteryVoltage = m_adapter->readRawBattSenseValue() * m_battVoltageSenseFactor * adapter()->getVAdcFullrange() / adapter()->getNAdcFullrange(); - char buf[200]; - sprintf(buf, "evaluateStatus(), rawVal: %d, factor: %d thds, VFull: %dmV, NFull: %d, m_batteryVoltage = %dmV", - m_adapter->readRawBattSenseValue(), static_cast(m_battVoltageSenseFactor*1000), + char buf[250]; + sprintf(buf, "evaluateStatus(), stat: %s, rawVal: %d, factor: %d thds, VFull: %dmV, NFull: %d, Voltage: %dmV", + getCurrentStateName(), m_adapter->readRawBattSenseValue(), static_cast(m_battVoltageSenseFactor*1000), static_cast(adapter()->getVAdcFullrange()*1000), adapter()->getNAdcFullrange(), static_cast(m_batteryVoltage*1000)); TR_PRINTF(m_trPort, DbgTrace_Level::debug, "%s", buf); + if (DbgTrace_Level::debug != m_trPort->getLevel()) + { + TR_PRINTF(m_trPort, DbgTrace_Level::info, "evaluateStatus(), stat: %s, rawVal: %d, m_batteryVoltage: %d.%02dV", + getCurrentStateName(), m_adapter->readRawBattSenseValue(), static_cast(m_batteryVoltage), + static_cast(m_batteryVoltage*100.0)-static_cast(m_batteryVoltage)*100) + } m_evalFsm->evaluateStatus(); } } @@ -199,3 +205,23 @@ DbgTrace_Port* BatteryImpl::trPort() { return m_trPort; } + +float BatteryImpl::battWarnThreshd() +{ + return m_battWarnThreshd; +} + +float BatteryImpl::battStopThrshd() +{ + return m_battStopThrshd; +} + +float BatteryImpl::battShutThrshd() +{ + return m_battShutThrshd; +} + +float BatteryImpl::battHyst() +{ + return m_battHyst; +} diff --git a/BatteryImpl.h b/BatteryImpl.h index 5a7899d..49c42b1 100644 --- a/BatteryImpl.h +++ b/BatteryImpl.h @@ -92,6 +92,11 @@ class BatteryImpl DbgTrace_Port* trPort(); + float battWarnThreshd(); /// Battery Voltage Warn Threshold [V] + float battStopThrshd(); /// Battery Voltage Stop Actors Threshold[V] + float battShutThrshd(); /// Battery Voltage Shutdown Threshold[V] + float battHyst(); /// Battery Voltage Hysteresis around Threshold levels[V] + private: BatteryAdapter* m_adapter; /// Pointer to the currently attached specific BatteryAdapter object BatteryVoltageEvalFsm* m_evalFsm; diff --git a/BatteryVoltageEvalFsm.cpp b/BatteryVoltageEvalFsm.cpp index 84f1886..1632c7f 100644 --- a/BatteryVoltageEvalFsm.cpp +++ b/BatteryVoltageEvalFsm.cpp @@ -95,7 +95,7 @@ bool BatteryVoltageEvalFsm::isGuardWarn() bool isGuard = false; if (0 != m_battImpl) { - isGuard = (Battery::s_BATT_WARN_THRSHD > m_battImpl->getBatteryVoltage()); + isGuard = (m_battImpl->battWarnThreshd() > m_battImpl->getBatteryVoltage()); } return isGuard; } @@ -105,7 +105,7 @@ bool BatteryVoltageEvalFsm::isGuardStop() bool isGuard = false; if (0 != m_battImpl) { - isGuard = (Battery::s_BATT_STOP_THRSHD > m_battImpl->getBatteryVoltage()); + isGuard = (m_battImpl->battStopThrshd() > m_battImpl->getBatteryVoltage()); } return isGuard; } @@ -115,7 +115,7 @@ bool BatteryVoltageEvalFsm::isGuardShut() bool isGuard = false; if (0 != m_battImpl) { - isGuard = (Battery::s_BATT_SHUT_THRSHD> m_battImpl->getBatteryVoltage()); + isGuard = (m_battImpl->battShutThrshd() > m_battImpl->getBatteryVoltage()); } return isGuard; } @@ -125,7 +125,7 @@ bool BatteryVoltageEvalFsm::isGuardWarnPlusHyst() bool isGuard = false; if (0 != m_battImpl) { - isGuard = ((Battery::s_BATT_WARN_THRSHD + Battery::s_BATT_HYST) < m_battImpl->getBatteryVoltage()); + isGuard = ((m_battImpl->battWarnThreshd() + m_battImpl->battHyst()) < m_battImpl->getBatteryVoltage()); } return isGuard; } @@ -135,7 +135,7 @@ bool BatteryVoltageEvalFsm::isGuardStopPlusHyst() bool isGuard = false; if (0 != m_battImpl) { - isGuard = ((Battery::s_BATT_STOP_THRSHD + Battery::s_BATT_HYST) < m_battImpl->getBatteryVoltage()); + isGuard = ((m_battImpl->battStopThrshd() + m_battImpl->battHyst()) < m_battImpl->getBatteryVoltage()); } return isGuard; } @@ -145,7 +145,7 @@ bool BatteryVoltageEvalFsm::isGuardShutPlusHyst() bool isGuard = false; if (0 != m_battImpl) { - isGuard = ((Battery::s_BATT_SHUT_THRSHD + Battery::s_BATT_HYST) < m_battImpl->getBatteryVoltage()); + isGuard = ((m_battImpl->battShutThrshd() + m_battImpl->battHyst()) < m_battImpl->getBatteryVoltage()); } return isGuard; }