Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FPort stop one sensor cycle every 3 #3308

Merged
merged 2 commits into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/rx/fport.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define FPORT_MIN_TELEMETRY_RESPONSE_DELAY_US 500
#define FPORT_MAX_TELEMETRY_AGE_MS 500

#define FPORT_TELEMETRY_MAX_CONSECUTIVE_SENSORS 2 // Needed to avoid lost sensors on FPort, see #3198

#define FPORT_FRAME_MARKER 0x7E

Expand Down Expand Up @@ -340,7 +341,17 @@ static bool fportProcessFrame(const rxRuntimeConfig_t *rxRuntimeConfig)
if (clearToSend) {
DEBUG_SET(DEBUG_FPORT, DEBUG_FPORT_TELEMETRY_DELAY, currentTimeUs - lastTelemetryFrameReceivedUs);

processSmartPortTelemetry(mspPayload, &clearToSend, NULL);
uint8_t *consecutiveSensorCount = rxRuntimeConfig->frameData;
if (*consecutiveSensorCount >= FPORT_TELEMETRY_MAX_CONSECUTIVE_SENSORS && !smartPortPayloadContainsMSP(mspPayload)) {
// Stop one cycle to avoid saturating the buffer in the RX, since the
// downstream bandwidth doesn't allow sensor sensors on every cycle.
// We allow MSP frames to run over the resting period, expecting that
// the caller won't flood us with requests.
*consecutiveSensorCount = 0;
} else {
(*consecutiveSensorCount)++;
processSmartPortTelemetry(mspPayload, &clearToSend, NULL);
}

if (clearToSend) {
smartPortWriteFrameFport(&emptySmartPortFrame);
Expand All @@ -358,7 +369,9 @@ static bool fportProcessFrame(const rxRuntimeConfig_t *rxRuntimeConfig)
bool fportRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
{
static uint16_t sbusChannelData[SBUS_MAX_CHANNEL];
static uint8_t consecutiveSensorCount = 0;
rxRuntimeConfig->channelData = sbusChannelData;
rxRuntimeConfig->frameData = &consecutiveSensorCount;
sbusChannelsInit(rxRuntimeConfig);

rxRuntimeConfig->channelCount = SBUS_MAX_CHANNEL;
Expand Down
17 changes: 6 additions & 11 deletions src/main/telemetry/smartport.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include "telemetry/msp_shared.h"

#define SMARTPORT_MIN_TELEMETRY_RESPONSE_DELAY_US 500
#define SMARTPORT_REST_PERIOD 3 // Needed to avoid lost sensors on FPort, see #3198

// these data identifiers are obtained from https://github.com/opentx/opentx/blob/master/radio/src/telemetry/frsky_hub.h
enum
Expand Down Expand Up @@ -138,7 +137,6 @@ enum

static uint8_t telemetryState = TELEMETRY_STATE_UNINITIALIZED;
static uint8_t smartPortIdCnt = 0;
static bool smartPortHasRested = false;

typedef struct smartPortFrame_s {
uint8_t sensorId;
Expand Down Expand Up @@ -233,6 +231,11 @@ void smartPortSendByte(uint8_t c, uint16_t *checksum, serialPort_t *port)
}
}

bool smartPortPayloadContainsMSP(const smartPortPayload_t *payload)
{
return payload && (payload->frameId == FSSP_MSPC_FRAME_SMARTPORT || payload->frameId == FSSP_MSPC_FRAME_FPORT);
}

void smartPortWriteFrameSerial(const smartPortPayload_t *payload, serialPort_t *port, uint16_t checksum)
{
uint8_t *data = (uint8_t *)payload;
Expand Down Expand Up @@ -343,7 +346,7 @@ void processSmartPortTelemetry(smartPortPayload_t *payload, volatile bool *clear
// unless we start receiving other sensors' packets

#if defined(USE_MSP_OVER_TELEMETRY)
if (payload->frameId == FSSP_MSPC_FRAME_SMARTPORT || payload->frameId == FSSP_MSPC_FRAME_FPORT) {
if (smartPortPayloadContainsMSP(payload)) {
// Pass only the payload: skip frameId
uint8_t *frameStart = (uint8_t *)&payload->valueId;
smartPortMspReplyPending = handleMspFrame(frameStart, SMARTPORT_MSP_PAYLOAD_SIZE);
Expand Down Expand Up @@ -380,14 +383,6 @@ void processSmartPortTelemetry(smartPortPayload_t *payload, volatile bool *clear
id = frSkyDataIdTable[smartPortIdCnt];
}
smartPortIdCnt++;
if (smartPortIdCnt % SMARTPORT_REST_PERIOD == 0) {
if (!smartPortHasRested) {
smartPortIdCnt--;
smartPortHasRested = true;
return;
}
smartPortHasRested = false;
}

switch (id) {
case FSSP_DATAID_VFAS :
Expand Down
1 change: 1 addition & 0 deletions src/main/telemetry/smartport.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ smartPortPayload_t *smartPortDataReceive(uint16_t c, bool *clearToSend, smartPor
struct serialPort_s;
void smartPortWriteFrameSerial(const smartPortPayload_t *payload, struct serialPort_s *port, uint16_t checksum);
void smartPortSendByte(uint8_t c, uint16_t *checksum, struct serialPort_s *port);
bool smartPortPayloadContainsMSP(const smartPortPayload_t *payload);