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

[DBC to FIBEX] Fix BASE-DATA-TYPE for some signals #805

Merged
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
15 changes: 6 additions & 9 deletions src/canmatrix/formats/fibex.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,35 +131,34 @@ def get_multiplexing_parts_infos(signals, frame_name, start_pos=-1, end_pos=-1,

def get_base_data_type(bit_length, is_signed=False):
# type: (int, bool) -> str
if bit_length == 8:
if bit_length > 0 and bit_length <= 8:
if is_signed:
return "A_INT8"

elif not is_signed:
return "A_UINT8"

elif bit_length == 16:
elif bit_length > 8 and bit_length <= 16:
if is_signed:
return "A_INT16"

elif not is_signed:
return "A_UINT16"

elif bit_length == 32:
elif bit_length > 16 and bit_length <= 32:
if is_signed:
return "A_INT32"

elif not is_signed:
return "A_UINT32"

elif bit_length == 64:
elif bit_length > 32 and bit_length <= 64:
if is_signed:
return "A_INT64"

elif not is_signed:
return "A_UINT64"


class Fe:
def __init__(self, filename):
self.tree = lxml.etree.parse(filename)
Expand Down Expand Up @@ -788,10 +787,8 @@ def dump(db, f, **options):
"Coding for " +
signal_id)

coded = create_sub_element_ho(coding, "CODED-TYPE")
# find smallest predefined type size able of holding signal size
byte_size = (signal.size + 8 - 1) / 8
base_data_type = get_base_data_type(byte_size * 8, signal.is_signed)
coded = create_sub_element_ho(coding, "CODED-TYPE")
base_data_type = get_base_data_type(signal.size, signal.is_signed)
if base_data_type is not None:
coded.set(ns_ho + "BASE-DATA-TYPE", base_data_type)
coded.set("CATEGORY", "STANDARD-LENGTH-TYPE")
Expand Down
Loading