Skip to content

Commit f0310f6

Browse files
committed
Update the packet submission logic
Packet submission logic is updated to provide a lower channel update latency.
1 parent 6cb8c2e commit f0310f6

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

src/src/rx-serial/SerialSatellite.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,35 @@ uint32_t SerialSatellite::sendRCFrame(bool frameAvailable, uint32_t *channelData
6565
}
6666
sendPackets = true;
6767

68-
uint16_t outgoingPacket[SATELLITE_CHANNEL_DATA_LENGTH];
69-
for (uint8_t ii = 0; ii < SATELLITE_CHANNEL_DATA_LENGTH; ++ii)
68+
uint16_t outgoingPacket[SATELLITE_CHANNELS_PER_PACKET];
69+
70+
// Our bandwidth is limited, so try to send updates only for the channels
71+
// with new values to reduce the channel update latency. Updates are
72+
// checked in round-robin fashion to make sure that the channels do not
73+
// starve.
74+
for (uint8_t channelCount = 0, packetDataCount = 0;
75+
(channelCount < SATELLITE_MAX_CHANNELS) && (packetDataCount < SATELLITE_CHANNELS_PER_PACKET);
76+
++channelCount)
7077
{
71-
// These channels are sent in every packet
72-
if (ii < SATELLITE_FIRST_RR_CHANNEL)
78+
// If the channel data is updated, add it to the packet. Or, if the
79+
// space remaining in the packet is equal to the number of remaining
80+
// channels to be checked for updates, just fill the packet with the
81+
// remaining channels no matter if they have updates or not because we
82+
// need to send exactly 7 channel data in every packet.
83+
if ((prevChannelData[roundRobinIndex] != channelData[roundRobinIndex]) ||
84+
((SATELLITE_CHANNELS_PER_PACKET - packetDataCount) == (SATELLITE_MAX_CHANNELS - channelCount)))
7385
{
74-
outgoingPacket[ii] = crsfToSatellite(channelData[ii],
75-
CRSF_TO_SATELLITE_CH_MAP[ii],
76-
satelliteSystem);
86+
prevChannelData[roundRobinIndex] = channelData[roundRobinIndex];
87+
outgoingPacket[packetDataCount++] =
88+
crsfToSatellite(channelData[roundRobinIndex],
89+
CRSF_TO_SATELLITE_CH_MAP[roundRobinIndex],
90+
satelliteSystem);
7791
}
78-
// Round-robin channels
79-
else
92+
93+
++roundRobinIndex;
94+
if (roundRobinIndex >= SATELLITE_MAX_CHANNELS)
8095
{
81-
outgoingPacket[ii] = crsfToSatellite(channelData[rr],
82-
CRSF_TO_SATELLITE_CH_MAP[rr],
83-
satelliteSystem);
84-
85-
// Update the round-robin index
86-
++rr;
87-
if (rr >= SATELLITE_NUM_CHANNELS)
88-
{
89-
rr = SATELLITE_FIRST_RR_CHANNEL;
90-
}
96+
roundRobinIndex = 0;
9197
}
9298
}
9399

src/src/rx-serial/SerialSatellite.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ class SerialSatellite : public SerialIO
1313
uint32_t sendRCFrame(bool frameAvailable, uint32_t *channelData) override;
1414

1515
private:
16-
static constexpr uint16_t SATELLITE_NUM_CHANNELS = 12;
17-
static constexpr uint8_t SATELLITE_FIRST_RR_CHANNEL = 4;
18-
static constexpr uint8_t SATELLITE_CHANNEL_DATA_LENGTH = 7;
16+
static constexpr uint16_t SATELLITE_MAX_CHANNELS = 12;
17+
static constexpr uint8_t SATELLITE_CHANNELS_PER_PACKET = 7;
1918

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

21+
uint32_t prevChannelData[SATELLITE_CHANNELS_PER_PACKET] = {0};
22+
2223
uint8_t fadeCount{0};
23-
uint8_t rr{SATELLITE_FIRST_RR_CHANNEL};
24+
uint8_t roundRobinIndex{0};
2425
bool sendPackets{false};
2526
};

0 commit comments

Comments
 (0)