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

Fix frame decoding #224

Merged
merged 21 commits into from
Nov 4, 2018
Merged

Fix frame decoding #224

merged 21 commits into from
Nov 4, 2018

Conversation

ebroecker
Copy link
Owner

this is NOT ready for merge, but in a PR the could be better done.

this fixes wrong decoding frames  (#119)

BUT this is only proof of concept, further cleanup is needed (encoding, multiplex support, dismiss old code ...)
@altendky altendky changed the title Fix frame decoding [WIP] Fix frame decoding Oct 26, 2018
@ebroecker
Copy link
Owner Author

@altendky
your unpack code worked out out the box ...

Now I tried to use your pack code also, but stumbled over some magic code:
https://github.com/altendky/st/blob/c75f436f503adcb4708131a65b059c8062484ae5/epyqlib/canneo.py#L136-L147
I am not sure what happens here, maybe you could give me a hint?
Thanks in advance

@altendky
Copy link
Collaborator

Let's start with a vague overview... I'm just rereading the code since I really don't remember this stuff.

Keep in mind that I wanted to allow for overlapped signals and mixed big and little endian as well. Unpacking overlapped signals... Whatever. A single bit from the bus might end up in multiple signals, no conflict. Packing though, you may have to prioritize one over another, or report a conflict (this code prioritizes I think which is probably a bad choice).

I think the first two lines take the bits calculated from little endian signals and 'turn them around' to align with the big endian bits.

bitstring = iterates over the little and big bits together. The next() picks the first non-None from the choices of the little endian bit, the big endian bit, and the default '0'.

The return line groups the bits into groups of 8, joins each group to an eight character string, creates an integer from the base-2 string, and creates a bytes object from that iterable of integers.

Maybe?

@codecov-io
Copy link

codecov-io commented Oct 30, 2018

Codecov Report

Merging #224 into development will increase coverage by 5.19%.
The diff coverage is 90.07%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #224      +/-   ##
===============================================
+ Coverage        17.48%   22.68%   +5.19%     
===============================================
  Files               25       27       +2     
  Lines             5960     6168     +208     
  Branches          1604     1609       +5     
===============================================
+ Hits              1042     1399     +357     
+ Misses            4852     4660     -192     
- Partials            66      109      +43
Impacted Files Coverage Δ
src/canmatrix/tests/test_frame_decoding.py 100% <100%> (ø)
src/canmatrix/tests/test_canmatrix.py 100% <100%> (ø) ⬆️
src/canmatrix/tests/test_frame_encoding.py 84.31% <84.31%> (ø)
src/canmatrix/canmatrix.py 54.54% <89.28%> (+10.22%) ⬆️
src/canmatrix/sym.py 36.72% <0%> (+3.47%) ⬆️
src/canmatrix/formats.py 49.45% <0%> (+9.89%) ⬆️
src/canmatrix/dbc.py 15.33% <0%> (+12.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0cc1073...3d5f6f9. Read the comment docs.

add float decoding tests
add mux decoding tests

fix py2 compatibility
Copy link
Collaborator

@altendky altendky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would break the test down into five separate tests. At least three: integers, floats, and multiplexed.

src/canmatrix/dbc.py Outdated Show resolved Hide resolved
src/canmatrix/dbc.py Outdated Show resolved Hide resolved
src/canmatrix/tests/test_frame_decoding.py Outdated Show resolved Hide resolved
remove not needed python version checking
Encoding tests still failing.
guess: something with sign seems to be wrong

TODO: check if test data is correct
@altendky
Copy link
Collaborator

I'm not sure at the moment but we should be able to monitor for unrun tests (like would happen with matching names) via coverage of the tests.

@@ -400,7 +400,7 @@ def pack_bitstring(self, length, is_float, value, signed):
signed=signed)
b = '{:0{}b}'.format(int.from_bytes(b, byteorder='big'),
length)
bitstring = b[:length]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@altendky
seems I found a bug. At least now my tests seem to produce correct data.
This was your code, maybe you should have a look to your code also...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh... I wonder how I haven't had issues. It seems to show up for signed values (I forget big endian or little or...). Anyways, thanks for pointing that out. As a double check I made up #235 to recreate it 'in my world' of .sym files.

@ebroecker
Copy link
Owner Author

@altendky
this PR is getting close to done - in my eyes.
One open thing is to kick out bitstruct of the requirements, but the code should work now as expected...

Could you do another review?

Thanks

@ebroecker ebroecker changed the title [WIP] Fix frame decoding Fix frame decoding Nov 2, 2018
Copy link
Collaborator

@altendky altendky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty... I'll try to finish up the rest tomorrow. Thanks for all this, of course.

src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/canmatrix.py Show resolved Hide resolved
Copy link
Collaborator

@altendky altendky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alrighty... i'll probably have to either take a pass three later or reserve the right to think that followup changes might be good. Probably better to do the latter, if at all. i don't like dragging out pr's forever...

src/canmatrix/canmatrix.py Show resolved Hide resolved
src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
src/canmatrix/tests/test_frame_decoding.py Show resolved Hide resolved
altendky and others added 3 commits November 3, 2018 17:47
Co-Authored-By: ebroecker <eduard.broecker@gmail.com>
Co-Authored-By: ebroecker <eduard.broecker@gmail.com>
* Add .sym based test

* fixup for py2
@ebroecker ebroecker merged commit eb6c2ed into development Nov 4, 2018
@ebroecker ebroecker deleted the fixFrameDecoding branch November 4, 2018 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants