Skip to content

Remove redundant initial state check in LC_SampleAPs #114

@igorluppi

Description

@igorluppi

Summary

The initial state validation in LC_SampleAPs prevents sampling any action points whenever the first (start) AP is in PERMOFF or NOT_USED state. Since LC_SampleSingleAP() already skips non‑operational APs, this extra check is unnecessary and leads to unexpected behavior when sampling a range that happens to begin with a disabled AP.

Background

  • Function: LC_SampleAPs(uint16 StartIndex, uint16 EndIndex)

  • Current behavior:

    CurrentAPState = LC_OperData.ARTPtr[StartIndex].CurrentState;
    
    if ((CurrentAPState != LC_ACTION_NOT_USED) && (CurrentAPState != LC_APSTATE_PERMOFF))
    {
        for (TableIndex = StartIndex; TableIndex <= EndIndex; TableIndex++)
        {
            LC_SampleSingleAP(TableIndex);
        }
    }
    else
    {
        CFE_EVS_SendEvent(..., "Sample AP error, invalid current AP state: AP = %d, State = %d", StartIndex, CurrentAPState);
    }
    return;
  • Redundancy: Inside LC_SampleSingleAP() there is already a check for PERMOFF/invalid states and it simply returns without sampling non‑operational APs (see LC_SampleSingleAP at line 94–95`).

Problem

  1. Unintended all‑or‑nothing behavior
    If StartIndex refers to an AP that is permanently off or unused, none of the APs in the [StartIndex…EndIndex] range will be sampled—even if the rest are active.
  2. Duplicate logic
    The per‑AP validity check is already handled in LC_SampleSingleAP(), so rejecting the entire batch upfront is unnecessary and inconsistent.

Proposed Change

  1. Remove the initial state check at the top of LC_SampleAPs.
  2. Always iterate from StartIndex to EndIndex, calling LC_SampleSingleAP(TableIndex) for each.
  3. Rely on the existing checks inside LC_SampleSingleAP() to skip invalid APs and emit error events on a per‑AP basis.

Before:

if ((CurrentAPState != LC_ACTION_NOT_USED) && (CurrentAPState != LC_APSTATE_PERMOFF))
{
    for (TableIndex = StartIndex; TableIndex <= EndIndex; TableIndex++)
    {
        LC_SampleSingleAP(TableIndex);
    }
}
else
{
    CFE_EVS_SendEvent(…);
}

After:

for (TableIndex = StartIndex; TableIndex <= EndIndex; TableIndex++)
{
    LC_SampleSingleAP(TableIndex);
}

Impact

  • Positive:
    • Ensures that all valid APs in the requested range are sampled, regardless of the state of the first AP.
    • Simplifies the code by removing redundant validation logic.
  • Neutral:
    • Error reporting remains the same—LC_SampleSingleAP() will emit an event for each invalid AP.

References

  • Initial check in LC_SampleAPs:
    if ((CurrentAPState != LC_ACTION_NOT_USED) && (CurrentAPState != LC_APSTATE_PERMOFF))
  • Per‑AP validation in LC_SampleSingleAP:
    if ((CurrentAPState == LC_APSTATE_ACTIVE) || (CurrentAPState == LC_APSTATE_PASSIVE))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions