Skip to content
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

Improve handling of NamedSignalValue #31

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
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