Skip to content

Commit

Permalink
Improve handling of NamedSignalValue and add 4.2
Browse files Browse the repository at this point in the history
Fixes #30

Signed-off-by: Erik Jaegervall <erik.jaegervall@se.bosch.com>
  • Loading branch information
erikbosch authored and SebastianSchildt committed Sep 26, 2024
1 parent 9dc39dc commit dec1e05
Show file tree
Hide file tree
Showing 3 changed files with 10,268 additions and 2 deletions.
24 changes: 22 additions & 2 deletions dbcfeederlib/dbc2vssmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import json
import logging
import sys
import cantools

from dataclasses import dataclass
from typing import Any, Dict, List, Set, Optional, KeysView
Expand Down Expand Up @@ -139,8 +140,27 @@ def transform_value(self, value: Any) -> Any:
"""
vss_value = None
if self.transform is None:
log.debug("No mapping to VSS %s, using raw value %s", self.vss_name, value)
vss_value = value
if isinstance(value, cantools.database.can.signal.NamedSignalValue):
# We try to be "smart" when doing implicit mapping for NamedSignalValues like
# VAL_ 599 DI_uiSpeedUnits 1 "DI_SPEED_KPH" 0 "DI_SPEED_MPH" ;
if self.datatype == "string":
# Use string representation if VSS type is string
vss_value = value.name
log.debug("Using string value %s for %s", vss_value, self.vss_name)
else:
# In all other cases try with numeric value
vss_value = value.value
log.debug("Using numeric value %s for %s",
vss_value, self.vss_name)
elif isinstance(value, (int, float)):
vss_value = value
log.debug("Using int/float value %s for %s", vss_value, self.vss_name)
else:
vss_value = value
# It is not expected to end up here, if we find a use-case we should better handle that
# type exactly. That is the reason we use "info" here, to give better visibility.
log.info("Using raw value %s of type %s for %s", vss_value, type(vss_value), self.vss_name)

else:
if "mapping" in self.transform:
tmp = self.transform["mapping"]
Expand Down
Loading

0 comments on commit dec1e05

Please sign in to comment.