-
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: concrete error type and cached TX address #38
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
For TX address bug, see nRF24/RF24#1028. Field and variable names prefixed with `_` tells the rust linter ("clippy" tool) that unused dead code shall be explicitly ignored. Coming from Arduino, this isn't the case. Arduino lib convention suggests to prefix private members with a `_` for readability.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #38 +/- ##
===========================================
- Coverage 100.00% 99.81% -0.19%
===========================================
Files 22 22
Lines 3154 3194 +40
===========================================
+ Hits 3154 3188 +34
- Misses 0 6 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
impl From<SpiError> for Nrf24Error<SpiError, OutputPinError> { | ||
fn from(value: SpiError) -> Self { | ||
Nrf24Error::Spi(value) | ||
} | ||
} | ||
|
||
impl From<OutputPinError> for Nrf24Error<SpiError, OutputPinError> { | ||
fn from(value: OutputPinError) -> Self { | ||
Nrf24Error::Gpo(value) | ||
} | ||
} |
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.
These implementations cannot be covered with unit tests. Doing so would require changing the test harness to employ qemu, but that seems like overkill since
- the emulated hardware would be infallible under a proper hardware setup
- the qemu instance would need to interact with another qemu instance to emulate wireless transactions. I'm guessing this approach is not a thing we can do currently.
EDIT: This could be resolved upstream in the embedded-hal-mock library.
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.
I opened a couple issues to hopefully resolve this upstream in the mock library we're using for unit tests:
- add
with_error()
for SPITransaction
dbrgn/embedded-hal-mock#128 - use
embedded_hal::digital::ErrorKind
for mocked digital pins dbrgn/embedded-hal-mock#129 (would be considered a breaking change though)
Alternatively, I can fork embedded-hal-mock and tell cargo to pull in my patched fork from git source instead of the original from crates.io. Although, this would incur a tech debt just to satisfy 100% line coverage.
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.
I have a locally stashed patch that will use my fork's patches (in my fork's dev branch). I'm waiting for feedback upstream before committing the patch. Local tests show these lines will be covered with these upstream patches
Too many unrelated changes in this PR. I've broken it up into 3 separate contributions. |
Concrete Error type
Changes the
Esb*
traits to require a new traitRadioErrorType
.rf24-rs/crates/rf24-rs/src/radio/prelude.rs
Line 457 in da36293
In the
RadioErrorType
trait, there is an associatedError
type.rf24-rs/crates/rf24-rs/src/radio/prelude.rs
Lines 15 to 18 in da36293
Then, the
RadioErrorType
trait is implemented for theRF24
struct.rf24-rs/crates/rf24-rs/src/radio/rf24/mod.rs
Lines 59 to 66 in da36293
Subsequent required implementations
The
?
operator used to propagateResult::Err
needed an explicit forwarding mechanism for hardware-related errors, namelyembedded_hal::digital::ErrorKind as OutputPinError
andembedded_hal::spi::ErrorKind as SpiError
.rf24-rs/crates/rf24-rs/src/radio/rf24/mod.rs
Lines 47 to 57 in da36293
This allows automatic categorization of the error encountered using our
Nrf24Error
enum.Advantages
This convoluted approach
Esb*
traits' fallible functions. Previously, each trait had it's own associated error type which didn't bode well for implementing different radio hardware.Cached TX address
For the TX address bug, see nRF24/RF24#1028 (and corresponding solution in nRF24/RF24#1029).
Renamed private fields
Field and variable names prefixed with
_
tells the rust linter ("clippy" tool) that unused dead code shall be explicitly ignored. This does not bode well for static analysis on production code.Coming from Arduino, this isn't the case. Arduino lib convention suggests to prefix private members with a
_
for readability. Many C++ linters don't treat the_
prefix of member/variable/parameter names in any special way (excluding#include
guards).