Skip to content

Some small fixes and improvements extracted from PR1238#1565

Open
fschrempf wants to merge 5 commits intomeshcore-dev:devfrom
fschrempf:pr1238-extracted-fixups-and-improvements
Open

Some small fixes and improvements extracted from PR1238#1565
fschrempf wants to merge 5 commits intomeshcore-dev:devfrom
fschrempf:pr1238-extracted-fixups-and-improvements

Conversation

@fschrempf
Copy link
Contributor

@fschrempf fschrempf commented Feb 1, 2026

While working on #1238 I discovered a bug I had a hard time understanding the logic of the state handling in RadioLibWrappers.cpp. Therefore this PR improves the readability of that part and a few other things which can be reviewed and merged separately.

  • Fix subtle bug in RadioLibWrappers.cpp state machine
  • Improve readability of state machine macros in in RadioLibWrappers.cpp
  • Enable reset pin for RAK4631
  • Repeater: improve hasPendingWork() which is used to decide when the system is idle and can enter powersaving mode
  • Repeater: use constexpr values for powersaving timings instead of inline literals

#define STATE_IDLE 0
#define STATE_RX 1
#define STATE_TX_WAIT 3
#define STATE_TX_WAIT 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't follow what this is supposed to fix?

Copy link
Contributor Author

@fschrempf fschrempf Feb 2, 2026

Choose a reason for hiding this comment

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

Did you see the commit message?

STATE_TX_WAIT is meant to be a single bit but is defined as two bits,
therefore overlapping with STATE_RX. This causes incorrect results
when the code uses the bits to handle the state machine.

Unless I'm getting it all wrong (which totally could be the case) you meant to use the STATE_* defines as single-bit masks for the static volatile uint8_t state variable. But 3 is not a single bit but two bits. Therefore currently if state is set to STATE_TX_WAIT, then state & STATE_RX will return true, which seems unexpected and looks wrong to me.

I don't now if this has any negative impact with the current implementation, but it certainly caused problems with the code I was working at here: a6ce03d.

And anyway, it seems like a good idea to fix this no matter if it is currently causing any issues or not as it has the potential to cause problems in the future.

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 looks like there is no actual impact at the moment, as checks for STATE_RX are currently all done with == to check for STATE_RX exclusively.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Only STATE_INT_READY is intended as a bit mask. The others are enums.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, got it. I still think it is very easy to get wrong the way it is currently written. Please see the updated PR for a suggestion to make it a bit easier to understand.

The STATE_* defines are meant to be used as enumerations, except for
STATE_INT_READY which describes a single bit flag. Improve the name
of the flag to make the difference clearer. While at it also make the
enumeration use a continuous increment without gaps.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
There is no reason to not use the reset pin as the RAK4630/31 module
has it connected internally.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
If the radio driver state machine is not in receive mode, this means
that processing of a packet is still in progress and we are not in an
idle state.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
This makes the code easier to read and allows for easier changing of
the hardcoded values.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
When a CLI command is issued through the serial interface, extend the
timeout for going to sleep to give the user more time for issuing more
commands.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
@fschrempf fschrempf force-pushed the pr1238-extracted-fixups-and-improvements branch from 4400d5b to 07a223e Compare February 5, 2026 19:58
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