Skip to content

Commit

Permalink
Update the packet submission logic
Browse files Browse the repository at this point in the history
Packet submission logic is updated to provide a lower channel update
latency.
  • Loading branch information
dkorkmazturk committed Oct 1, 2023
1 parent d21542a commit b223f95
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
44 changes: 25 additions & 19 deletions src/src/rx-serial/SerialSatellite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,35 @@ uint32_t SerialSatellite::sendRCFrame(bool frameAvailable, uint32_t *channelData
}
sendPackets = true;

uint16_t outgoingPacket[SATELLITE_CHANNEL_DATA_LENGTH];
for (uint8_t ii = 0; ii < SATELLITE_CHANNEL_DATA_LENGTH; ++ii)
uint16_t outgoingPacket[SATELLITE_CHANNELS_PER_PACKET];

// Our bandwidth is limited, so try to send updates only for the channels
// with new values to reduce the channel update latency. Updates are
// checked in round-robin fashion to make sure that the channels do not
// starve.
for (uint8_t channelCount = 0, packetDataCount = 0;
(channelCount < SATELLITE_MAX_CHANNELS) && (packetDataCount < SATELLITE_CHANNELS_PER_PACKET);
++channelCount)
{
// These channels are sent in every packet
if (ii < SATELLITE_FIRST_RR_CHANNEL)
// If the channel data is updated, add it to the packet. Or, if the
// space remaining in the packet is equal to the number of remaining
// channels to be checked for updates, just fill the packet with the
// remaining channels no matter if they have updates or not because we
// need to send exactly 7 channel data in every packet.
if ((prevChannelData[roundRobinIndex] != channelData[roundRobinIndex]) ||
((SATELLITE_CHANNELS_PER_PACKET - packetDataCount) == (SATELLITE_MAX_CHANNELS - channelCount)))
{
outgoingPacket[ii] = crsfToSatellite(channelData[ii],
CRSF_TO_SATELLITE_CH_MAP[ii],
satelliteSystem);
prevChannelData[roundRobinIndex] = channelData[roundRobinIndex];
outgoingPacket[packetDataCount++] =
crsfToSatellite(channelData[roundRobinIndex],
CRSF_TO_SATELLITE_CH_MAP[roundRobinIndex],
satelliteSystem);
}
// Round-robin channels
else

++roundRobinIndex;
if (roundRobinIndex >= SATELLITE_MAX_CHANNELS)
{
outgoingPacket[ii] = crsfToSatellite(channelData[rr],
CRSF_TO_SATELLITE_CH_MAP[rr],
satelliteSystem);

// Update the round-robin index
++rr;
if (rr >= SATELLITE_NUM_CHANNELS)
{
rr = SATELLITE_FIRST_RR_CHANNEL;
}
roundRobinIndex = 0;
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/src/rx-serial/SerialSatellite.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class SerialSatellite : public SerialIO
uint32_t sendRCFrame(bool frameAvailable, uint32_t *channelData) override;

private:
static constexpr uint16_t SATELLITE_NUM_CHANNELS = 12;
static constexpr uint8_t SATELLITE_FIRST_RR_CHANNEL = 4;
static constexpr uint8_t SATELLITE_CHANNEL_DATA_LENGTH = 7;
static constexpr uint16_t SATELLITE_MAX_CHANNELS = 12;
static constexpr uint8_t SATELLITE_CHANNELS_PER_PACKET = 7;

void processBytes(uint8_t *bytes, uint16_t size) override{};

uint32_t prevChannelData[SATELLITE_CHANNELS_PER_PACKET] = {0};

uint8_t fadeCount{0};
uint8_t rr{SATELLITE_FIRST_RR_CHANNEL};
uint8_t roundRobinIndex{0};
bool sendPackets{false};
};

0 comments on commit b223f95

Please sign in to comment.