question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decoding an encoded message returns different values

See original GitHub issue

I’ve tried decoding an encoded message in both Cantools 28.6.0 and 22.0.1, and I’m seeing the same behavior where one signal’s value is lost somehow.

>>> msg.decode(msg.encode({ 'signal1': -250.0, 'signal2': -250.0, 'signal3': 1, 'signal4': 2, 'signal5': 3, 'signal6': 4, 'signal7': 0 }))
{'signal1': -250.0, 'signal2': -250.0, 'signal3': 1, 'signal4': 0, 'signal5': 3, 'signal6': 4, 'signal7': 0}

I noticed that https://github.com/eerimoq/cantools/blob/master/tests/test_database.py contains quite a few instances of checking whether the decoded message matches the original message passed through something equivalent to msg.decode(msg.encode(msg_payload)), so I’m unsure where the issue lies. All of my signals in this CAN message are big-endian, and I also noticed this weird inconsistency when printing the start and length values for my signals in this message:

>>> sorted([(sig.start, sig.length) for sig in msg.signals], key=lambda sig: sig[0])
[(6, 15), (22, 15), (35, 4), (39, 4), (41, 2), (55, 8), (59, 3)]

Some of the signals seem to overlap for some reason. Am I misunderstanding how the signals are laid out in this particular message?

I took a look at the message dump, which looks fine however: https://pastebin.com/0UufZbuj

Please let me know if more information is necessary.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
ilanbialacommented, Aug 1, 2018

This is a partial dump of that message actually:

           7   6   5   4   3   2   1   0
         +---+---+---+---+---+---+---+---+
       0 |   |<--------------------------|
         +---+---+---+---+---+---+---+---+
       1 |------------------------------x|
         +---+---+---+---+---+---+---+---+
                                       +-- signal1

So it makes sense how 0x34BC is directly in the message actually. Thanks for the clarifications!

0reactions
ilanbialacommented, Aug 1, 2018

You’re right the encoding and decoding issue is actually a result of the signal value not matching the scale.

Is this the correct way to encode 0x34BC starting at bit 6 then?

Big endian signal value 0x34BC with start bit 6 and length 15 (C=LSB, 3=MSB):

Byte:       0        1        2        3
       +--------+--------+--------+--- - -
       |11010010|111100  |        |        
       +--------+--------+--------+--- - -
Bit:    7      0 15     8 23    16 31

If that is, there are actually only 14 bits that can fit starting at bit 6, right?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is encoding and decoding? - TechTarget
Encoding and decoding in Java is a method of representing data in a different format to efficiently transfer information through a network or...
Read more >
Decode Ways - LeetCode
To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above...
Read more >
3. Communications Process: Encoding and Decoding
Encoding is the process of turning thoughts into communication. The encoder uses a 'medium' to send the message — a phone call, email,...
Read more >
Decode the string encoded with the given algorithm
Given a decoded string str which was decoded with the following encoding algorithm: Write down the middle character of the string then ...
Read more >
Message Encode Decode in Python with Tkinter - DataFlair
Message encoding and decoding is the process to first convert the original text to the random and meaningless text called ciphertext. This process...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found