-
Notifications
You must be signed in to change notification settings - Fork 643
interface for changing bitrate #1030
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
Draft
cperkulator
wants to merge
11
commits into
hardbyte:main
Choose a base branch
from
cperkulator:set_baudrate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c2260f3
interface for changing bitrate
2faf400
Format code with black
786525d
making it a property
6a609ef
Format code with black
f8fef99
add init access handling and FD
cperkulator 4d305b2
Format code with black
cperkulator 896b915
shouldn't have made this abstract
cperkulator 48052ae
Format code with black
cperkulator 6d80f4c
only works with python versions greater than 3.3
cperkulator 46365fd
Format code with black
cperkulator 48b8f8c
removing debug info
cperkulator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,7 @@ def __init__( | |
) | ||
self.channels = channel_index | ||
else: | ||
# Is there any better way to raise the error? | ||
# TODO - Is there any better way to raise the error? | ||
raise Exception( | ||
"None of the configured channels could be found on the specified hardware." | ||
) | ||
|
@@ -233,6 +233,8 @@ def __init__( | |
) | ||
|
||
if permission_mask.value == self.mask: | ||
self._init_access = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a huge fan of this flag but I would rather not check for init access everytime. |
||
self._bitrate = bitrate | ||
if fd: | ||
self.canFdConf = xlclass.XLcanFdConf() | ||
if bitrate: | ||
|
@@ -277,6 +279,7 @@ def __init__( | |
) | ||
LOG.info("SetChannelBitrate: baudr.=%u", bitrate) | ||
else: | ||
self._init_access = False | ||
LOG.info("No init access!") | ||
|
||
# Enable/disable TX receipts | ||
|
@@ -515,6 +518,25 @@ def handle_canfd_event(self, event: xlclass.XLcanRxEvent) -> None: | |
def send(self, msg: Message, timeout: typing.Optional[float] = None): | ||
self._send_sequence([msg]) | ||
|
||
@property | ||
def bitrate(self) -> int: | ||
return self._bitrate | ||
|
||
@bitrate.setter | ||
def bitrate(self, bitrate: int) -> None: | ||
if self._init_access: | ||
if self.fd: | ||
self.canFdConf.arbitrationBitRate = bitrate | ||
xldriver.xlCanFdSetConfiguration( | ||
self.port_handle, self.mask, self.canFdConf | ||
) | ||
else: | ||
xldriver.xlCanSetChannelBitrate(self.port_handle, self.mask, bitrate) | ||
self._bitrate = bitrate | ||
LOG.info("SetChannelBitrate: baudr.=%u", bitrate) | ||
else: | ||
LOG.error("No init access!") | ||
|
||
def _send_sequence(self, msgs: typing.Sequence[Message]) -> int: | ||
"""Send messages and return number of successful transmissions.""" | ||
if self.fd: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.