Skip to content
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

Question: is it okay to not "sleep" on driver.get_message() #5

Open
half2me opened this issue Jul 29, 2024 · 3 comments
Open

Question: is it okay to not "sleep" on driver.get_message() #5

half2me opened this issue Jul 29, 2024 · 3 comments

Comments

@half2me
Copy link
Contributor

half2me commented Jul 29, 2024

In the sample you use a loop:

loop {
  match driver.get_message() {
    Ok(None) => (),
    msg => println!("{:#?}", msg),
  }
}

Just out of curiosity I checked how many times it's actually matching the Ok(None) pattern, and it's up to >4000 times between messages. Is this okay? Are we wasting cycles here or is this a non-issue?

I've had cases where the usb stick freezes up, and I don't get any new messages unless I unplug and plug it back in. I'm trying to find a way to reproduce this and see if I can detect this issue in code and differentiate it from there just being no packets available to capture. This was the first thing I checked, if I could maybe count how many times its hitting this pattern.

@cujomalainey
Copy link
Owner

Yea, that is just a sample code, and outside of demo code it does not make sense indeed. Places where you can get interrupts from the underlying buses (uart, spi. usb) would be better for triggering the checks, but I have not gotten around to actually demoing such code.

Also one challenge with rust is that the model is for the driver to be own the underlying bus, so if the bus triggers an interrupt and calls out to some supporting function, unless that callback is deferred (e.g. through an event queue) you will end up calling back into the driver which causes an ownership issue. Still working on how to avoid that as I am not a rust expert yet and the embedded rust community is still iterating their designs.

@cujomalainey
Copy link
Owner

One other thing I forgot to mention is that @harrychin is looking to add a async support, this will also solve some of the headache here as you can just await a message once its complete.

@half2me
Copy link
Contributor Author

half2me commented Jul 30, 2024

async support would be awesome. Let me know if there is anything I can help to test. My primary use case is just using the RxScanmode to capture as much ant+ data around me as I can and save it to a file.

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

No branches or pull requests

2 participants