Skip to content

[IO][canutils]: use common CAN interface names in generated logfile #1271

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

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

hartkopp
Copy link
Collaborator

@hartkopp hartkopp commented Mar 2, 2022

CAN interfaces in canutils logfiles are usually named 'can0', 'can32' or
'vcan8'. This allows to split logfiles just by performing 'grep' or to
rename CAN interfaces easily with 'sed'.

The current implementation of the canutils log file writer just provides
channel numbers for CAN interfaces. This patch adds the string 'can' to
the channel number to make it look like a usual canutils logfiles that can
be preprocessed as described above.

Signed-off-by: Oliver Hartkopp [email protected]

@@ -161,7 +161,7 @@ def on_message_received(self, msg):

channel = msg.channel if msg.channel is not None else self.channel

framestr = "(%f) %s" % (timestamp, channel)
framestr = "(%f) can%s" % (timestamp, channel)
Copy link
Collaborator

Choose a reason for hiding this comment

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

msg.channel might can be a string like "can0". You'd get "cancan0" here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point!
Unfortunately I'm not really familiar with Python, but would it make sense to add some isdigit() vodoo to catch the case that we are only dealing with numbers and add "can" only in these cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you could use

if isinstance(channel, int):
    ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @zariiii9003 ,
I looked at the docs and also at some code - but I don't have Python knowledge that goes beyond my original patch :-/
Would you mind to provide a patch/PR that adds "can" before the channel only when channel is a simple number?
Thanks!

Copy link
Owner

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Big thanks!

@codecov
Copy link

codecov bot commented Mar 5, 2022

Codecov Report

Merging #1271 (56fb131) into develop (4d9b32c) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1271      +/-   ##
===========================================
- Coverage    66.02%   66.01%   -0.01%     
===========================================
  Files           86       86              
  Lines         8912     8914       +2     
===========================================
+ Hits          5884     5885       +1     
- Misses        3028     3029       +1     

CAN interfaces in canutils logfiles are usually named 'can0', 'can32' or
'vcan8'. This allows to split logfiles just by performing 'grep' or to
rename CAN interfaces easily with 'sed'.

The current implementation of the canutils log file writer just provides
channel numbers for CAN interfaces. This patch adds the string 'can' to
the channel number to make it look like a usual canutils logfiles that can
be preprocessed as described above.

The string 'can' is added when the provided CAN channel is only a number.

Author: Brian Thorne <[email protected]>
Suggested-by: Oliver Hartkopp <[email protected]>
Tested-by: Oliver Hartkopp <[email protected]>
@hardbyte hardbyte merged commit ebae360 into hardbyte:develop Mar 9, 2022
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