mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Merge pull request #5269 from mikeller/fixed_fport_efficiency
Fixed efficiency of FPort protocol.
This commit is contained in:
commit
a8f28b8973
2 changed files with 22 additions and 23 deletions
|
@ -242,6 +242,7 @@ static bool checkChecksum(uint8_t *data, uint8_t length)
|
||||||
static uint8_t fportFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
|
static uint8_t fportFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
{
|
{
|
||||||
static smartPortPayload_t payloadBuffer;
|
static smartPortPayload_t payloadBuffer;
|
||||||
|
static bool hasTelemetryRequest = false;
|
||||||
|
|
||||||
uint8_t result = RX_FRAME_PENDING;
|
uint8_t result = RX_FRAME_PENDING;
|
||||||
|
|
||||||
|
@ -278,18 +279,16 @@ static uint8_t fportFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mspPayload = NULL;
|
|
||||||
switch(frame->data.telemetryData.frameId) {
|
switch(frame->data.telemetryData.frameId) {
|
||||||
case FPORT_FRAME_ID_NULL:
|
case FPORT_FRAME_ID_NULL:
|
||||||
case FPORT_FRAME_ID_DATA: // never used
|
case FPORT_FRAME_ID_DATA: // never used
|
||||||
result = result | RX_FRAME_PROCESSING_REQUIRED;
|
hasTelemetryRequest = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case FPORT_FRAME_ID_READ:
|
case FPORT_FRAME_ID_READ:
|
||||||
case FPORT_FRAME_ID_WRITE: // never used
|
case FPORT_FRAME_ID_WRITE: // never used
|
||||||
memcpy(&payloadBuffer, &frame->data.telemetryData, sizeof(smartPortPayload_t));
|
memcpy(&payloadBuffer, &frame->data.telemetryData, sizeof(smartPortPayload_t));
|
||||||
mspPayload = &payloadBuffer;
|
mspPayload = &payloadBuffer;
|
||||||
result = result | RX_FRAME_PROCESSING_REQUIRED;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -312,6 +311,12 @@ static uint8_t fportFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
rxBufferReadIndex = (rxBufferReadIndex + 1) % NUM_RX_BUFFERS;
|
rxBufferReadIndex = (rxBufferReadIndex + 1) % NUM_RX_BUFFERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((mspPayload || hasTelemetryRequest) && cmpTimeUs(micros(), lastTelemetryFrameReceivedUs) >= FPORT_MIN_TELEMETRY_RESPONSE_DELAY_US) {
|
||||||
|
hasTelemetryRequest = false;
|
||||||
|
|
||||||
|
result = result | RX_FRAME_PROCESSING_REQUIRED;
|
||||||
|
}
|
||||||
|
|
||||||
if (lastRcFrameReceivedMs && ((millis() - lastRcFrameReceivedMs) > FPORT_MAX_TELEMETRY_AGE_MS)) {
|
if (lastRcFrameReceivedMs && ((millis() - lastRcFrameReceivedMs) > FPORT_MAX_TELEMETRY_AGE_MS)) {
|
||||||
setRssiFiltered(0, RSSI_SOURCE_RX_PROTOCOL);
|
setRssiFiltered(0, RSSI_SOURCE_RX_PROTOCOL);
|
||||||
lastRcFrameReceivedMs = 0;
|
lastRcFrameReceivedMs = 0;
|
||||||
|
@ -324,34 +329,28 @@ static bool fportProcessFrame(const rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
{
|
{
|
||||||
UNUSED(rxRuntimeConfig);
|
UNUSED(rxRuntimeConfig);
|
||||||
|
|
||||||
bool processingDone = false;
|
|
||||||
|
|
||||||
#if defined(USE_TELEMETRY_SMARTPORT)
|
#if defined(USE_TELEMETRY_SMARTPORT)
|
||||||
timeUs_t currentTimeUs = micros();
|
timeUs_t currentTimeUs = micros();
|
||||||
if (telemetryEnabled && clearToSend && cmpTimeUs(currentTimeUs, lastTelemetryFrameReceivedUs) >= FPORT_MIN_TELEMETRY_RESPONSE_DELAY_US) {
|
if (cmpTimeUs(currentTimeUs, lastTelemetryFrameReceivedUs) > FPORT_MAX_TELEMETRY_RESPONSE_DELAY_US) {
|
||||||
if (cmpTimeUs(currentTimeUs, lastTelemetryFrameReceivedUs) > FPORT_MAX_TELEMETRY_RESPONSE_DELAY_US) {
|
clearToSend = false;
|
||||||
clearToSend = false;
|
}
|
||||||
}
|
|
||||||
|
if (clearToSend) {
|
||||||
|
DEBUG_SET(DEBUG_FPORT, DEBUG_FPORT_TELEMETRY_DELAY, currentTimeUs - lastTelemetryFrameReceivedUs);
|
||||||
|
|
||||||
|
processSmartPortTelemetry(mspPayload, &clearToSend, NULL);
|
||||||
|
|
||||||
if (clearToSend) {
|
if (clearToSend) {
|
||||||
DEBUG_SET(DEBUG_FPORT, DEBUG_FPORT_TELEMETRY_DELAY, currentTimeUs - lastTelemetryFrameReceivedUs);
|
smartPortWriteFrameFport(&emptySmartPortFrame);
|
||||||
|
|
||||||
processSmartPortTelemetry(mspPayload, &clearToSend, NULL);
|
clearToSend = false;
|
||||||
|
|
||||||
if (clearToSend) {
|
|
||||||
smartPortWriteFrameFport(&emptySmartPortFrame);
|
|
||||||
|
|
||||||
clearToSend = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processingDone = true;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
processingDone = true;
|
mspPayload = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return processingDone;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fportRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
bool fportRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
|
||||||
|
|
|
@ -421,7 +421,7 @@ bool rxUpdateCheck(timeUs_t currentTimeUs, timeDelta_t currentDeltaTime)
|
||||||
rxIsInFailsafeMode = (frameStatus & RX_FRAME_FAILSAFE) != 0;
|
rxIsInFailsafeMode = (frameStatus & RX_FRAME_FAILSAFE) != 0;
|
||||||
rxSignalReceived = !rxIsInFailsafeMode;
|
rxSignalReceived = !rxIsInFailsafeMode;
|
||||||
needRxSignalBefore = currentTimeUs + needRxSignalMaxDelayUs;
|
needRxSignalBefore = currentTimeUs + needRxSignalMaxDelayUs;
|
||||||
} else if (cmpTimeUs(currentTimeUs, rxNextUpdateAtUs) > 0) {
|
} else if (cmpTimeUs(currentTimeUs, rxNextUpdateAtUs) > 0) {
|
||||||
rxDataProcessingRequired = true;
|
rxDataProcessingRequired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue