Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Ignore signal values that are out of the defined range
Browse files Browse the repository at this point in the history
The message definition database may contain signals for which a
minimum and/or maximum value has been defined. In particular,
j1939 uses "special" out-of-range values to indicate that a signal
is not available (at the moment). These "special" values should not
be published to the Databroker.

The CanReader has been altered to ignore signal values from CAN
messages which do not match the defined min/max values.
  • Loading branch information
sophokles73 committed Oct 23, 2023
1 parent 6863fe2 commit 16d7aa4
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 218 deletions.
20 changes: 20 additions & 0 deletions dbc2val/dbcfeederlib/canreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from abc import ABC, abstractmethod

import cantools.database # type: ignore

from dbcfeederlib.canplayer import CANplayer
from dbcfeederlib.dbc2vssmapper import Mapper, VSSObservation
from typing import Any, Dict, Optional
Expand Down Expand Up @@ -89,7 +91,25 @@ def _process_can_message(self, frame_id: int, data: Any):
log.debug("Decoded message: %s", str(decode))
rx_time = time.time()
for signal_name, raw_value in decode.items(): # type: ignore
signal: cantools.database.Signal = message_def.get_signal_by_name(signal_name)
if isinstance(raw_value, (int, float)):
# filter out signals with values out of defined range
# which is usually because the signal's value is unavailable
# (represented as e.g. "all bits set")
if signal.minimum is not None and raw_value < signal.minimum:
log.debug(
"discarding out-of-range value [signal: %s, min: %s, value: %s]",
signal_name, signal.minimum, raw_value
)
continue
if signal.maximum is not None and raw_value > signal.maximum:
log.debug(
"discarding out-of-range value [signal: %s, max: %s, value: %s]",
signal_name, signal.maximum, raw_value
)
continue
for signal_mapping in self._mapper.get_dbc2vss_mappings(signal_name):

if signal_mapping.time_condition_fulfilled(rx_time):
log.debug(
"Queueing %s, triggered by %s, raw value %s",
Expand Down
33 changes: 0 additions & 33 deletions dbc2val/test/test_readers/j1939.kcd

This file was deleted.

28 changes: 0 additions & 28 deletions dbc2val/test/test_readers/simple_mapping.json

This file was deleted.

46 changes: 0 additions & 46 deletions dbc2val/test/test_readers/simple_mapping.vspec

This file was deleted.

33 changes: 0 additions & 33 deletions dbc2val/test/test_readers/standard_can.kcd

This file was deleted.

Loading

0 comments on commit 16d7aa4

Please sign in to comment.