Skip to content

If parsed data has shortened, overwrite end of line with spaces#1201

Merged
felixdivo merged 2 commits into
hardbyte:developfrom
simonkerscher:canviewer/spaces_over_old_parsed_data
Feb 8, 2022
Merged

If parsed data has shortened, overwrite end of line with spaces#1201
felixdivo merged 2 commits into
hardbyte:developfrom
simonkerscher:canviewer/spaces_over_old_parsed_data

Conversation

@simonkerscher
Copy link
Copy Markdown
Contributor

@simonkerscher simonkerscher commented Dec 23, 2021

If parsed data has shortened, overwrite end of line with spaces

This bug could easily be replicated by running:
python can_viewer.py -c vcan0 -i socketcan -d "123:>BB"
In another terminal send:
cansend vcan0 123#FFFF
Followed by:
cansend vcan0 123#0001

@simonkerscher simonkerscher force-pushed the canviewer/spaces_over_old_parsed_data branch from 51b204c to 0196bdc Compare December 23, 2021 17:11
@pkess
Copy link
Copy Markdown
Contributor

pkess commented Dec 26, 2021

Hello @simonkerscher i saw your pull request and tried to reproduce it. But unfortunatelly i did not saw a real bug with the current develop branch. Can you explain what is your fault?

The line cansend vcan0 123#0 does not work in my terminal as the data bytes are not complete. I can either use cansend vcan0 123#00 or cansend vcan0 123# while running python3 -m can.viewer -i socketcan -c vcan0 in an other terminal and the output seems correct

@simonkerscher simonkerscher force-pushed the canviewer/spaces_over_old_parsed_data branch 3 times, most recently from f624897 to 9f08a80 Compare January 4, 2022 07:51
@simonkerscher
Copy link
Copy Markdown
Contributor Author

Hi @pkess . Apologies for the unclear instructions. I have amended my commit message and quoted code blocks to make sure commands don't get edited by Github directly.

Thes bug could easily be replicated by running:
python can_viewer.py -c vcan0 -i socketcan -d "123:>BB"
In another terminal send:
cansend vcan0 123#FFFF
Followed by:
cansend vcan0 123#0001

Currently, the output is:
2 0.976789 0.976789 0x123 2 00 01 0 1 255
while I would expect:
2 1.509172 1.509172 0x123 2 00 01 0 1

@pkess
Copy link
Copy Markdown
Contributor

pkess commented Jan 4, 2022

Ok, now i was able to reproduce this. But wouldn't it be easier to always write spaces until end of line than remember the old line length? Maybe @hardbyte or @felixdivo can add some comment here

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 4, 2022

Codecov Report

Merging #1201 (f610f54) into develop (e7a2b04) will increase coverage by 0.23%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1201      +/-   ##
===========================================
+ Coverage    65.65%   65.89%   +0.23%     
===========================================
  Files           86       86              
  Lines         8846     8875      +29     
===========================================
+ Hits          5808     5848      +40     
+ Misses        3038     3027      -11     

This bug could easily be replicated by running:
  `python can_viewer.py -c vcan0 -i socketcan -d "123:>BB"`
In another terminal send:
  `cansend vcan0 123#FFFF`
Followed by:
  `cansend vcan0 123#0001`
@simonkerscher simonkerscher force-pushed the canviewer/spaces_over_old_parsed_data branch from 9f08a80 to bbecf66 Compare January 4, 2022 13:27
@simonkerscher
Copy link
Copy Markdown
Contributor Author

Ok, now i was able to reproduce this. But wouldn't it be easier to always write spaces until end of line than remember the old line length? Maybe @hardbyte or @felixdivo can add some comment here

As this is the last field, I guess we could write spaces until the end of the line. I was trying to follow the approach used for a shortened message in lines 210-217, only overwriting spaces that had changed.

                # Clear the old data bytes when the length of the new message is shorter
                if msg.dlc < self.ids[key]["msg"].dlc:
                    self.draw_line(
                        self.ids[key]["row"],
                        # Start drawing at the last byte that is not in the new message
                        52 + msg.dlc * 3,
                        # Draw spaces where the old bytes were drawn
                        " " * ((self.ids[key]["msg"].dlc - msg.dlc) * 3 - 1),
                    )

@zariiii9003
Copy link
Copy Markdown
Collaborator

Thes bug could easily be replicated by running: python can_viewer.py -c vcan0 -i socketcan -d "123:>BB" In another terminal send: cansend vcan0 123#FFFF Followed by: cansend vcan0 123#0001

Currently, the output is: 2 0.976789 0.976789 0x123 2 00 01 0 1 255 while I would expect: 2 1.509172 1.509172 0x123 2 00 01 0 1

I think you are looking in the wrong place. Why is there a 255 in your output? It should be hexadecimal FF, right?

@simonkerscher
Copy link
Copy Markdown
Contributor Author

simonkerscher commented Jan 11, 2022

Thes bug could easily be replicated by running: python can_viewer.py -c vcan0 -i socketcan -d "123:>BB" In another terminal send: cansend vcan0 123#FFFF Followed by: cansend vcan0 123#0001
Currently, the output is: 2 0.976789 0.976789 0x123 2 00 01 0 1 255 while I would expect: 2 1.509172 1.509172 0x123 2 00 01 0 1

I think you are looking in the wrong place. Why is there a 255 in your output? It should be hexadecimal FF, right?

No, the 255 is from decoding the previous value, e.g.

0x123 2 FF FF 255 255
|     | |  |  |   decoded second byte
|     | |  |  decoded first byte
|     | |  second byte
|     | first byte
     message length
node ID

Sending both messages in order, we get

...0x123 2 FF FF 255 255 # Decoding 123#FFFF
...0x123 2 00 01 0 1     # Correctly decoding 123#0001
...0x123 2 00 01 0 1 255 # Overwriting line 1 with line 2, without overwriting trailing characters. This is the current wrong behaviour.

Comment thread can/viewer.py Outdated
self.ids[key]["previous_values_string_length"] = len(values_string)

if len(values_string) < previousLength:
values_string += " " * (previousLength - len(values_string))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
values_string += " " * (previousLength - len(values_string))
values_string += " " * (self.x- len(values_string))

Wouldn't it be easier to fill all available space? Then you don't have to keep track of line length.
I didn't test this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have included this suggestion, but have kept saving the length of the values_string to enable testing this behaviour.

@felixdivo felixdivo added the bug label Feb 6, 2022
@felixdivo felixdivo added this to the 4.0.0 Release milestone Feb 6, 2022
@felixdivo
Copy link
Copy Markdown
Collaborator

@zariiii9003 Can we merge this?

@felixdivo felixdivo merged commit 1142299 into hardbyte:develop Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants