@@ -65,29 +65,35 @@ uint32_t SerialSatellite::sendRCFrame(bool frameAvailable, uint32_t *channelData
65
65
}
66
66
sendPackets = true ;
67
67
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)
70
77
{
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)))
73
85
{
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);
77
91
}
78
- // Round-robin channels
79
- else
92
+
93
+ ++roundRobinIndex;
94
+ if (roundRobinIndex >= SATELLITE_MAX_CHANNELS)
80
95
{
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 ;
91
97
}
92
98
}
93
99
0 commit comments