-
Notifications
You must be signed in to change notification settings - Fork 659
ISSUE-538: Added user defined CAN speed selection, by setting SJW, BR… #539
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
Conversation
…P, TSEG2, TSEG1 with the bitrate argument
Codecov Report
@@ Coverage Diff @@
## develop #539 +/- ##
===========================================
- Coverage 64% 63.96% -0.04%
===========================================
Files 63 63
Lines 5700 5703 +3
===========================================
Hits 3648 3648
- Misses 2052 2055 +3 |
|
But thank you for the contribution! Where did you find the information about the custom bitrate? We might just link it in the parameter documentation of |
|
Hello felixdivo, |
|
Okay, nice to see that Wiki! It would probably be nice to link it somewhere. |
|
@felixdivo sorry I overwrote some of the changes you made because the main develop branch was extended to CAN-FD could you redo the merge you did before. |
|
No sorry, only you can commit to your own branch. I think you should undo the rebase and apply b96a54f on top of a rebase from the GUI in GitLab or a new clean rebase done from CLI. Something seemed to have gone wrong. |
|
And also by now I forgot what I changed. ^^ |
bhass1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed change doesn't seem to actually work. TPCANHandle(bitrate) isn't the proper interface.
It should be TPCANBaudrate(BTR0BTR1), and BTR0BTR1 needs to be calculated with an external tool which makes the current usage difficult for an ordinary user passing in arguments from the command line (i.e. simple 500000 does not translate directly to the proper BTR0BTR1 value for 500KBaud).
can/interfaces/pcan/pcan.py
Outdated
| if not user_bit: | ||
| pcan_bitrate = pcan_bitrate_objs.get(bitrate, PCAN_BAUD_500K) | ||
| else: | ||
| pcan_bitrate = TPCANHandle(bitrate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't clear how this actually works. Where are the SJW, BRP, TSEG1, and TSEG2 set? Does TPCANHandle(bitrate) handle arbitrary bitrates?
I don't see this interface in the Python PCANBasic API docs: https://www.peak-system.com/produktcd/Develop/PC%20interfaces/Windows/PCAN-Basic%20API/Include/PCANBasic.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its just a type definition:
TPCANHandle = c_ushort # Represents a PCAN hardware channel handle
But you are right I should use the :
TPCANBaudrate = c_ushort # Represents a PCAN Baud rate register value
"(i.e. simple 500000 does not translate directly to the proper BTR0BTR1 value for 500KBaud)"
In this case it does because we look the default values (most used) up in a dictionary
line 55: pcan_bitrate_objs
In the docstring I describe it quite well I think:
This argument can also be used for a user defined CAN-speed (e.g.: 0x0012 for 1.33 MHz)
For details on how to write a user speed register (SJW, TSEG 1/2, BRP) see:
http://www.bittiming.can-wiki.info (NXP SJA1000)
Please tell me what I could add for better understandability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I see is that bitrate is an integer representation of the bitrate (e.g. 500000). If user_bit is set, then line 97 becomes pcan_bitrate = TPCANHandle(500000) but in the dictionary, for 500K bitrate, pcan_bitrate = TPCANBaudrate(0x1C) #or TPCANBaudrate(28). They both can't be right.
The same issue comes up for the written example in the docstring. I'd expect bitrate to be 1330000 for 1.33M bitrate.
So the definition of what bitrate represents changes if user_bit = True or user_bit = False, and I don't think it's a good idea to do that.
Perhaps it would be better to define a new configuration type or calculate the register value of BTR0BTR1 within this method based on bitrate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this solved? Once it is, I'd merge this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still discussing in Issue #538
|
@felixdivo |
…dated branch for the pull request
|
I don't know how to do this, maybe @hardbyte has other rights? But maybe it's not possible since you applied changes on top of it. |
|
@bhass1 are you happy to sign off on this? I'd like to hold off merging until I see your approving review. I'm going to start getting develop ready for the |
I don't like the user-interface - it muddles the meaning of |
|
The next release will now be 4.0. It will be some weeks until we release it, since there are quite a few major changes, like dropping support for all Python versions below 3.6 and reworking how exceptions are used. Take your time. |
|
+1 for the separation of bitrate and btr0 btr1. |
|
See #615 |
|
#615 is now merged. |
|
Closing since this is superseeded by #625. Please reopen if necessary. |
…P, TSEG2, TSEG1 with the bitrate argument
Closes #538.