Closed nuts4coffee closed 1 year ago
In your examples you're providing scalar (float) values when encoding array signals, in the standard the initial value provided to array type signals must be an integer array and all the examples there point to this limitation.
Do you have a productive example of scalars encoded/decoded into array signals? Is this something that's allowed in ISO 17987 or SAE J2602?
In the example, the initial value is an integer array: [0, 0, 2]
. The scalar values are the physical value.
I think this one can better demo the issue. If I encode a frame with default values, I cannot decode it back.
def test_encode_array():
signal = LinSignal('BattCurr', 24, [0, 0, 2])
encoding_type = LinSignalEncodingType(
"BattCurrCoding",
[PhysicalValue(0, 182272, 0.00390625, -512, "A")]
)
signal.encoding_type = encoding_type
frame = LinUnconditionalFrame(0x20, "LinStatus", 3, {0: signal})
encoded = frame.encode({}) # encoded = bytearray(b'\x00\x00\x02')
frame.decode(encoded) # Error
If you do provide a value in the encode step you would also encounter errors because the PhysicalValue
encoder cannot encode list types. So even a line like this encoded = frame.encode({"BattCurr": [0, 1, 2]})
will lead to an exception.
I'd be hesitant to merge #120 since we don't have an example LDF for it, the standard doesn't mention anything about arrays being encoded into scalars, only ASCII and BCD converter examples are available. There's a slight hint at it in the NCF example.
I'll check the ISO standard tomorrow to see if there's anything in there that would confirm this use case. If it does I would prefer the approach where support for array signals is done in the value converters, rather than the frame encoding algorithm.
The ISO standard that I read didn't mention anything new regarding array signals. If this is something you know exists in your LDF files then we can add support but as previously mentioned it should done in the converter that way we won't introduce any breaking changes.
Thank you for pushing back. I realize my original implementation is quite wrong. I've proposed a new solution, please review and let me know if this one is ok.
Describe the bug Unable to encode/decode frame with signal of list type.
Signal in LDF file:
To Reproduce Steps to reproduce the behavior:
The issue can be reproduced from running the following 2 unit tests.
Expected behavior Encode/decode should work without errors.
Stacktrace/Code If applicable, add stacktrace or code segments to help explain your problem.
Environment:
Additional context Add any other context about the problem here.