Skip to content

Commit

Permalink
Enable two slot fifo for all crsf ext frames
Browse files Browse the repository at this point in the history
Change dropping semantics: overwrite oldest message in fifo that is not sent yet
  • Loading branch information
schugabe committed Jul 10, 2024
1 parent e2f5faf commit 0cfc930
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/lib/Telemetry/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void Telemetry::ResetState()
telemetry_state = TELEMETRY_IDLE;
currentTelemetryByte = 0;
currentPayloadIndex = 0;
currentQueueIndex = 0;
receivedPackages = 0;

uint8_t offset = 0;
Expand Down Expand Up @@ -318,25 +319,29 @@ bool Telemetry::AppendTelemetryPackage(uint8_t *package)
else // if no TCP client we just want to forward MSP over the link
#endif
{
// larger msp resonses are sent in two chunks so special handling is needed so both get sent
#if defined(HAS_MSP_VTX) && defined(TARGET_RX)
if (header->type == CRSF_FRAMETYPE_MSP_RESP)
{
#if defined(HAS_MSP_VTX) && defined(TARGET_RX)
mspVtxProcessPacket(package);
}
#endif
// there is already another response stored
if (payloadTypes[targetIndex].updated)
{
// use other slot
targetIndex = payloadTypesCount - 1;
}

// if both slots are taked do not overwrite other data since the first chunk would be lost
if (payloadTypes[targetIndex].updated)
{
targetFound = false;
}
// This code is emulating a two slot FIFO with head dropping
if (currentPayloadIndex == payloadTypesCount - 2 && payloadTypes[currentPayloadIndex].locked)
{
// Sending the first slot, use the second
targetIndex = payloadTypesCount - 1;
}
else if (currentPayloadIndex == payloadTypesCount - 1 && payloadTypes[currentPayloadIndex].locked)
{
// Sending the second slot, use the first
targetIndex = payloadTypesCount - 2;
}
else if (currentQueueIndex == payloadTypesCount - 2 && payloadTypes[currentQueueIndex].updated)
{
// Previous frame saved to the first slot, use the second
targetIndex = payloadTypesCount - 1;
}
currentQueueIndex = targetIndex;
}
}
else
Expand Down
1 change: 1 addition & 0 deletions src/lib/Telemetry/telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Telemetry
telemetry_state_s telemetry_state;
uint8_t currentTelemetryByte;
uint8_t currentPayloadIndex;
uint8_t currentQueueIndex;
volatile crsf_telemetry_package_t *telemetryPackageHead;
uint8_t receivedPackages;
bool callBootloader;
Expand Down

0 comments on commit 0cfc930

Please sign in to comment.