Skip to content

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

Merged
hardbyte merged 1 commit into
hardbyte:developfrom
hartkopp:develop
Mar 9, 2022
Merged

[IO][canutils]: use common CAN interface names in generated logfile#1271
hardbyte merged 1 commit into
hardbyte:developfrom
hartkopp:develop

Conversation

@hartkopp

@hartkopp hartkopp commented Mar 2, 2022

Copy link
Copy Markdown
Collaborator

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 socketcan@hartkopp.net

Comment thread can/io/canutils.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
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

codecov Bot commented Mar 5, 2022

Copy link
Copy Markdown

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 <brian@hardbyte.nz>
Suggested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
@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