Skip to content

Commit

Permalink
control flag indicating bms is present, timeout
Browse files Browse the repository at this point in the history
Set control flag to 1 if a BMS is present, so user interface can
enable/disable functionality.

add timeout so that a lost BMS eventually causes relay signals to
operate.
  • Loading branch information
izak committed Feb 5, 2021
1 parent 08fdcbf commit 19f1f96
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions delegates/dvcc.py
Expand Up @@ -20,6 +20,7 @@
# message, so the update rate could be increased. For now, keep this at 3 and
# above.
ADJUST = 3
BMS_TIMEOUT = 60

VEBUS_FIRMWARE_REQUIRED = 0x422
VEDIRECT_FIRMWARE_REQUIRED = 0x129
Expand Down Expand Up @@ -610,6 +611,7 @@ def __init__(self, sc):
self._vecan_services = []
self._timer = None
self._tickcount = ADJUST
self._bmscount = BMS_TIMEOUT

def get_input(self):
return [
Expand Down Expand Up @@ -668,6 +670,7 @@ def set_sources(self, dbusmonitor, settings, dbusservice):
self._dbusservice.add_path('/Control/EffectiveChargeVoltage', value=None)
self._dbusservice.add_path('/Control/BmsParameters', value=0)
self._dbusservice.add_path('/Control/MaxChargeCurrent', value=0)
self._dbusservice.add_path('/Control/BmsPresent', value=0)
self._dbusservice.add_path('/Control/Dvcc', value=1)
self._dbusservice.add_path('/Debug/BatteryOperationalLimits/SolarVoltageOffset', value=0, writeable=True)
self._dbusservice.add_path('/Debug/BatteryOperationalLimits/VebusVoltageOffset', value=0, writeable=True)
Expand Down Expand Up @@ -736,13 +739,21 @@ def bms(self):
return None

def _on_timer(self):
from delegates import RelayState
bol_support = self.has_dvcc
bms_service = self.bms

# Toggle relays if so configured. Do this early because we want
# this to work even if DVCC is off.
if bms_service is not None:
from delegates import RelayState
if bms_service is None:
self._bmscount = max(self._bmscount - 1, 0)
if not self._bmscount:
self._dbusservice['/Control/BmsPresent'] = 0
RelayState.instance.set_function(RelayState.FUNCTION_BMS_STOPCHARGE, 1)
RelayState.instance.set_function(RelayState.FUNCTION_BMS_STOPDISCHARGE, 1)
else:
self._bmscount = BMS_TIMEOUT
self._dbusservice['/Control/BmsPresent'] = 1
RelayState.instance.set_function(
RelayState.FUNCTION_BMS_STOPCHARGE, int(bms_service.maxchargecurrent == 0))
RelayState.instance.set_function(
Expand Down

0 comments on commit 19f1f96

Please sign in to comment.