Skip to content

Enhance energy model - #201

Open
dinayuil wants to merge 17 commits into
signetlabdei:developfrom
dinayuil:enhance-energy-model
Open

Enhance energy model#201
dinayuil wants to merge 17 commits into
signetlabdei:developfrom
dinayuil:enhance-energy-model

Conversation

@dinayuil

Copy link
Copy Markdown

This pull request fixes issue #200

Proposed Changes

  • Add an OFF PHY state
  • Set a depletion call back to switch off (like Wifi module)
  • Auto schedule to switch off based on the remaining energy (like Wifi module)
  • Add a test for energy depletion
  • Some refactoring for getting current value of a state

@dinayuil
dinayuil force-pushed the enhance-energy-model branch from 2bde98c to 1832f9a Compare October 13, 2025 22:33
@dinayuil

This comment was marked as resolved.

@nondetalle
nondetalle self-requested a review October 17, 2025 11:20
@nondetalle

Copy link
Copy Markdown
Collaborator

Hi, thank you for the contribution. I like the general idea this PR, I'll get to reviewing it as soon as I have addressed the previous PRs in the backlog.

I merged the latest changes and I have hidden your comment with test results: we have a CI pipeline to take care of that without polluting the PR msg history. In the meantime you can update this PR by fixing eventual errors detected by the CI pipeline.

@dinayuil

Copy link
Copy Markdown
Author

Merged code with recent changes from @maribu

@codecov

codecov Bot commented Oct 21, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.99174% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.60%. Comparing base (0c073e7) to head (fe730d1).

Files with missing lines Patch % Lines
model/lora-radio-energy-model.cc 77.50% 9 Missing ⚠️
model/end-device-lora-phy.cc 0.00% 8 Missing ⚠️
model/class-a-end-device-lorawan-mac.cc 0.00% 4 Missing ⚠️
model/simple-end-device-lora-phy.cc 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #201      +/-   ##
===========================================
+ Coverage    84.47%   84.60%   +0.13%     
===========================================
  Files           67       68       +1     
  Lines         7016     7115      +99     
===========================================
+ Hits          5927     6020      +93     
- Misses        1089     1095       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…g ScheduleSwitchToOff inside HandleEnergyChanged to avoid nested calls
@dinayuil

Copy link
Copy Markdown
Author

I find one problem but not sure how to deal with it:
If the radio is in RX or TX, and the energy source depletes, we want to change the radio to OFF state. However, before switch, we also need to stop the RX or TX events.
A work-around might be add a Tag info marking the packet being incomplete.

I put a TODO comment in SwitchToOff function. Please let me know if you have ideas.

@dinayuil

dinayuil commented Oct 29, 2025

Copy link
Copy Markdown
Author

Removed the 'Auto schedule to switch off based on remaining energy' feature.

Reason: Encountered floating-point comparison issues when reaching to 0 energy, which could lead to an assert failure due to subtle inaccuracies.

This removal should not affect normal use cases because the BasicEnergySource class already includes a minimum energy threshold parameter (default value: 0.1×initialEnergy). Therefore, during normal simulation runs, the energy level will not typically reach a value close enough to zero to trigger the assert issue, and the simulation will stop safely beforehand.

@nondetalle

nondetalle commented Mar 2, 2026

Copy link
Copy Markdown
Collaborator

Hello. I have considered merging this for the upcoming release but I see some problems in how the MAC layer may manage the OFF state (not your fault, they come from modeling choices of the previous developers). For example, in reality RX windows are actually managed by the PHY layer in a mode called RXSINGLE (as opposed to RXCONTINUOUS). Also the whole device should shut down (the APP and MAC too) when the battery dies. So in order to integrate and merge this, I started working on restructuring the PHY state model to actually reflect hardware modes. Unfortunately it is somewhat of a big change, so due to the current limited time I have to work on it I have decided to postpone this goal for next realease.

@dinayuil

dinayuil commented Mar 2, 2026

Copy link
Copy Markdown
Author

Thanks for the detailed explanation. No problem. I’ll stay available if you need any help with this PR.

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