Skip to content

Maybe fix spurious charge abort notifications #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions car/isotp_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def preprocess_fields(self):
new_fields.append(new_field)

self._log.debug("fmt(%s)", fmt)
cmd_data['autopad'] = cmd_data.get('autopad', False)
cmd_data['struct'] = struct.Struct(fmt)
cmd_data['fields'] = new_fields

Expand All @@ -124,6 +125,15 @@ def get_data(self):
raw = self._dongle.send_command_ex(cmd_data['cmd'],
canrx=cmd_data['canrx'],
cantx=cmd_data['cantx'])
# Learn how much to pad a block on first encounter if autopadding is active
if cmd_data['autopad']:
pad = len(raw) - len(cmd_data['struct'].size)
if pad > 0:
fmt = cmd_data['struct'].format
fmt += str(pad) + 'x'
cmd_data['struct'] = struct.Struct(fmt)
cmd_data['autopad'] = False

raw_fields = cmd_data['struct'].unpack(raw)

for field in cmd_data['fields']:
Expand Down
17 changes: 10 additions & 7 deletions evnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def submit_data(self):
last_charging = time()
last_charging_soc = 0
last_evn_settings_poll = 0
is_charging = 0
is_connected = 0
settings = None
soc_notification = ARMED
soc_threshold = self._config.get('soc_threshold', 100)
Expand All @@ -101,7 +103,9 @@ def submit_data(self):
if ((now - last_charging > ABORT_NOTIFICATION_INTERVAL and
charging_start_soc > 0 and 0 < last_charging_soc < soc_threshold and
abort_notification is ARMED) or abort_notification is FAILED):
log.info("Aborted charge detected, send abort notification")
log.info("Aborted charge detected, send abort notification now-last_charging(%i) charging_start_soc(%i) last_charging_soc(%i) soc_threshold(%i) abort_notification(%i)",
now - last_charging, charging_start_soc, last_charging_soc,
soc_threshold, abort_notification)
try:
evn.sendNotification(True)
abort_notification = SENT
Expand Down Expand Up @@ -141,13 +145,16 @@ def submit_data(self):
try:
if (data['SOC_DISPLAY'] is not None or
data['SOC_BMS'] is not None):
evn.setSOC(data['SOC_DISPLAY'], data['SOC_BMS'])

current_soc = data['SOC_DISPLAY'] or data['SOC_BMS']

is_charging = bool(data['charging'])
is_connected = bool(data['normalChargePort'] or data['rapidChargePort'])

if is_charging:
last_charging = now
last_charging_soc = current_soc

evn.setSOC(data['SOC_DISPLAY'], data['SOC_BMS'])
extended_data = {a: round(data[a], EXTENDED_FIELDS[a])
for a in EXTENDED_FIELDS if data[a] is not None}
log.debug(extended_data)
Expand Down Expand Up @@ -193,10 +200,6 @@ def submit_data(self):
log.info("Communication Error: %s", err)
soc_notification = FAILED

if is_charging:
last_charging = now
last_charging_soc = current_soc

except EVNotifyAPI.CommunicationError as err:
log.info("Communication Error: %s", err)

Expand Down