Skip to content

Conversation

@pkendall64
Copy link
Collaborator

@pkendall64 pkendall64 commented May 26, 2025

This PR is a reimplementation of the slot-based telemetry system using a prioritised FIFO.
It builds on the work done in #3222.

There are a few inherent issues in the slot-based telemetry system.

Issue 1: Only 2 slots for non-sensor based messages

By using a FIFO for the messages we are no longer limited to 2 slots, we can have as many messages in the FIFO as will fit. The current allocation is 2kbytes. Also, the telemetry system can overwrite undelivered entries in the queue for sensor-data messages. i.e. all of the "broadcast" type simple messages.

This should resolve #3196

Issue 2: Prioritise "parameter" messages

The implementation prioritises delivery of the 5 message types used for CRSF configuration:

  • CRSF_FRAMETYPE_DEVICE_PING
  • CRSF_FRAMETYPE_DEVICE_INFO
  • CRSF_FRAMETYPE_PARAMETER_SETTINGS_ENTRY
  • CRSF_FRAMETYPE_PARAMETER_READ
  • CRSF_FRAMETYPE_PARAMETER_WRITE

This ensures that the Lua scripts load in a timely manner, even at 1:8 telemetry ratio. This also has the benefit of being able to remove the special behaviour added in #3222 which paused (dropped) telemetry message for 10 seconds when seeing a DEVICE_INFO message.

resolves #3218

@pkendall64 pkendall64 requested review from CapnBry and mha1 May 26, 2025 19:54
@pkendall64 pkendall64 linked an issue May 26, 2025 that may be closed by this pull request
Copy link
Contributor

@mha1 mha1 left a comment

Choose a reason for hiding this comment

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

Telemetry and the LUA script works fine showing "other devices" and loading the RX settings even under heavy telemetry load with some expected limitations:

All Full-res packet rates in all available Switch Modes and all telemetry ratios,
all packet rates in Hybrid Mode and all telemetry ratios,
all packet rates in Wide Mode and telemetry ratios 1:2, 1:4:

  • RX settings loading times are comparable to pre-3.5.5 firmware versions

All packet rates in Wide Mode and telemetry ratios 1:8 or slower:

  • RX settings loading times are as expected about factor 3 (50Hz about factor 4) slower than compared to pre-3.5.5 firmware version

@CapnBry CapnBry self-assigned this May 28, 2025
Copy link
Member

@CapnBry CapnBry left a comment

Choose a reason for hiding this comment

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

This is working flipping great, amazing refactor with support for a longer queue to support bursts. Most of these are minor things, but we do need to address the webui not loading for me on 8285 RXes (2 resources load and then the web server never responds to rest) but we can maybe tackle that in a separate PR. Here's what I see, and I can push most of these changes.

  • Bug introduced in lua.cpp pushResponseChunk(), should be else nextStatusChunk++;
  • dummy[CRSF_MAX_PACKET_LEN] -> replace messagePayloads.popBytes(dummy, sz); with skip()
  • Remove crsf_telemetry_package_t and member
  • Remove receivedPackages
  • Remove twoslotLastQueueIndex
  • Remove currentPayloadIndex
  • Comment for ACTION_NEXT suggest "continue searching queue for other messages"
  • settingsCount should be member, and probably named prioritizedCount?
  • bit(7) should be a define and use e.g. IS_DEL(sz) SET_DEL(sz) SIZE(sz) etc
  • FIFO<TELEMETRY_FIFO_SIZE> everywhere, typedef it
  • Should comparator_t definition have const as well?
  • messagePayloads[] data is accessed without lock
  • uint16_t messagePosition = 0 -> rename overwritePosition
  • if (whatToDo == ACTION_IGNORE || whatToDo == ACTION_APPEND || whatToDo == ACTION_OVERWRITE) is clearer if it is if (whatToDo != ACTION_NEXT)
  • Add comparitor for CRSF_FRAMETYPE_PARAMETER_SETTINGS_ENTRY to check for duplicates (OVERWRITE)
  • Should AppendTelemetryPackage also check currentPayload? Considering duplicates of PARAMINFO being requested while that value is currently being transmitted. Would require changing signature to use some sort of accessor helper class
  • MicroOptimization: If the first item in the queue is prio, use pop instead of marking deleted. This only triggers at high packet rates so probably doesn't matter?
  • Test for two different deviceinfo
  • Test function that doesn't require popping and requeing everything
int Telemetry::UpdatedPayloadCount()
{
    int retVal = 0;
    unsigned pos = 0;
    while (pos < messagePayloads.size())
    {
        uint8_t sz = messagePayloads[pos];
        if (!(sz & bit(7)))
        {
            retVal++;
        }
        pos += (sz & 0x7F) + 1;
    }
    return retVal;
}
  • Add uint8_t payload[0] to crsf_header_t and use payload[0] instead of ((uint8_t*)newMessage)[CRSF_TELEMETRY_TYPE_INDEX + 1]
  • Move CRSF_FRAMETYPE_OPENTX_SYNC to be in a new enum, subtype?
    • CRSF_FRAMETYPE_RADIO_ID rename to CRSF_FRAMETYPE_HANDSET? (spec lists as Remote Related Frames)
    • CRSF_FRAMETYPE_OPENTX_SYNC go to subcommand rename to CRSF_HANDSET_SUBCMD_TIMING
  • Can we reuse deleted slots to reduce buffer use? Push can also defragment as it goes, merging an adjacent deleted block into one larger deleted block
  • CRSF_AP_CUSTOM_TELEM_STATUS_TEXT is actually a log so both our old and new mechanism isn't great for servicing this message, but that's outside the scope of this PR

@pkendall64 pkendall64 merged commit ce14b1b into ExpressLRS:3.x.x-maintenance Jun 1, 2025
48 checks passed
@pkendall64 pkendall64 deleted the telemetry-redo branch June 1, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

packet rate 150hz problem 3.5.4 and 3.5.5

3 participants