Skip to content

Commit

Permalink
Improve handling of NamedSignalValue
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 committed Sep 20, 2024
1 parent 9dc39dc commit 0d6b350
Show file tree
Hide file tree
Showing 3 changed files with 10,273 additions and 2 deletions.
22 changes: 20 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,25 @@ 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
log.debug("Using string value for %s", self.vss_name)
vss_value = value.name
else:
# In all other cases try with numeric value
log.debug("Using numeric value for %s, value is %s of type %s",
self.vss_name, value, type(value.value))
vss_value = value.value
elif isinstance(value, (int, float)):
log.debug("Using implicit numeric mapping for %s", self.vss_name)
vss_value = value
else:
log.debug("No implicit mapping to VSS for signal %s of type %s with value %s, ignoring it!",
self.vss_name, type(value), value)

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

0 comments on commit 0d6b350

Please sign in to comment.