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

Introduce desired State for runner #94

Merged
merged 16 commits into from
Jan 4, 2024

Conversation

tarfu
Copy link
Contributor

@tarfu tarfu commented Nov 1, 2023

This PR should introduce a desired state functionality to the runner and state.

@tarfu
Copy link
Contributor Author

tarfu commented Nov 1, 2023

Having Heap would make that a lot more convenient. Probably will have another generic parameter on state for what the maximum number of subscribers there are per desired-state/state, which most likely would be the number of different runners there are, and you need to define when initializing. At least, I don't see a way to make it dynamic without heap.

@MathiasKoch
Copy link
Member

Yeah, we have a strict heapless approach at Blackbird, so at least for us, we will have to work around that 😔

@tarfu
Copy link
Contributor Author

tarfu commented Nov 1, 2023

Yeah, I have the same premise, as it makes it a lot easier to manage ram and not worry about that parts of something leaking heap in some driver.

If you know for sure you only have one, you need to notify the approach already in with the waker like for link_state works nice but unfortunately not really for the possibility of multiple subscribers.

@MathiasKoch
Copy link
Member

I am not sure, I quite understand the issue you are describing?
Could you either elaborate, or give an example?

@tarfu
Copy link
Contributor Author

tarfu commented Nov 3, 2023

What I meant is that the single waker (which is already in the state right now) is nice for the implementation if one party is waiting for a change in the state, but would fight to be the correct waker. Waker registration would overwrite the old waker and wake it, then the old waker would wake and look if it is in the right state and sets itself as the new waker triggering the other waker again and play ping pong. It would work, but would not be really nice for computing resources.

Wasn't in the mood of programming today and worked on a PCB I still have to finish.

@tarfu
Copy link
Contributor Author

tarfu commented Nov 10, 2023

This should see progress again as one of my projects ended and that freed up quite a bit of time.

@MathiasKoch
Copy link
Member

No rush from my end, but nice to hear!
I hope to find some time to chime in, once you have established a working foundation for us to work on :)

@tarfu
Copy link
Contributor Author

tarfu commented Nov 23, 2023

It's still a lot uglier than I hoped for, but at least something to discuss on to get progress.

Copy link
Member

@MathiasKoch MathiasKoch left a comment

Choose a reason for hiding this comment

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

Wouldn't it be possible for us to just define som MAX_STATE_LISTENERS as a const based on either available services for a module, or just a fixed number? I assume the stack usage overhead of e.g. 3 vs 6 is minimal for a PubSub of unit variant enums (1 byte)

src/asynch/state.rs Show resolved Hide resolved
@tarfu
Copy link
Contributor Author

tarfu commented Nov 27, 2023

We could set it as a constant and if it is ever not enough, just increase it would be a lot less generic parameters pain. But if we want then to be able to change it and keep the API, we would then need a feature set for that or something like that.

@MathiasKoch
Copy link
Member

I think, at least for now, it makes sense to just pick a "high-enough" number, to reduce the pain of generics at a rather low stack overhead cost.

@MathiasKoch
Copy link
Member

Other than those comments, I think the current implementation looks good! With a fixed number for MAX_STATE_LISTENERS I also think looks reasonably simple

@MathiasKoch
Copy link
Member

Does it work to set the desired operational state directly to one of the final values, or do you need to do one step at a time as your example?

@tarfu
Copy link
Contributor Author

tarfu commented Nov 27, 2023

I think, at least for now, it makes sense to just pick a "high-enough" number, to reduce the pain of generics at a rather low stack overhead cost.

Would you completely remove the generics, or just set the constant in the asynch/mod.rs and use it in the 2 relevant new()? This would keep them in the state but reduce complexity outside. Or just completely remove it?

Does it work to set the desired operational state directly to one of the final values, or do you need to do one step at a time as your example?

My goal is that you just set what you want, and the runner figures out what the steps are it needs to do. It would be a classic thing for a fall through switch in C 😆 .

@MathiasKoch
Copy link
Member

MathiasKoch commented Nov 28, 2023

Would you completely remove the generics, or just set the constant in the asynch/mod.rs and use it in the 2 relevant new()? This would keep them in the state but reduce complexity outside. Or just completely remove it?

I think I would completely remove it, and just have a single const MAX_STATE_LISTENERS: usize = 5 that is used where the pubsub is mentioned

My goal is that you just set what you want, and the runner figures out what the steps are it needs to do. It would be a classic thing for a fall through switch in C 😆

Awesome! I would expect it to work that way as well

@tarfu
Copy link
Contributor Author

tarfu commented Dec 24, 2023

Might want to think about a backchannel to the user if something went wrong, so the user can react and knows that for example, a state transition went wrong.

@tarfu
Copy link
Contributor Author

tarfu commented Dec 25, 2023

Currently, is_alive is a bit unstable. Not sure why, maybe because it was powered down and something went wrong then.

@tarfu tarfu marked this pull request as ready for review January 2, 2024 08:03
@tarfu
Copy link
Contributor Author

tarfu commented Jan 3, 2024

@MathiasKoch have a look as soon as you got time. This is already a bit bigger as it should be and has stuff not really on topic but needed to be done anyways ...

@MathiasKoch
Copy link
Member

Awesome 👍
Already started looking a bit, but I will take a thorough look soon :)

Cargo.toml Outdated Show resolved Hide resolved

// checks alive status continuiously until it is alive
async fn check_is_alive_loop(&mut self) -> bool {
loop {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm.. Think I would prefer if this had either a retry counter or a timeout..? This seems like something that can get stuck for infinity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should have a timeout in the transition match. Extracted it to be less code in the match.

@MathiasKoch
Copy link
Member

This looks great!
It does have a path dependency on ublox-sockets.. Could we change that to a git dep before merging?

@tarfu
Copy link
Contributor Author

tarfu commented Jan 3, 2024

This looks great!

It does have a path dependency on ublox-sockets.. Could we change that to a git dep before merging?

It is patched in the patch section but sure we can. I think there is also a PR open in ublox-socket for a embassy time bump.

@MathiasKoch
Copy link
Member

This looks great!
It does have a path dependency on ublox-sockets.. Could we change that to a git dep before merging?

It is patched in the patch section but sure we can. I think there is also a PR open in ublox-socket for a embassy time bump.

Ahh, sorry i didn't notice that! Patch section should be okay. I just stubled upon the CI failing due to this..

@MathiasKoch MathiasKoch merged commit 07cd52a into FactbirdHQ:feature/async Jan 4, 2024
2 of 4 checks passed
@MathiasKoch
Copy link
Member

Nice job on this! Can't wait to see a network / data API 😀

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.

2 participants