diff --git a/crossbow.ino b/crossbow.ino index 4dec975..eddcb19 100644 --- a/crossbow.ino +++ b/crossbow.ino @@ -288,7 +288,7 @@ void loop(void) * Here we do state handling and similar operations */ #ifdef DEVICE_MODE_RX - if (abs(currentMillis - qsp.lastRcFrameReceived) > RX_FAILSAFE_DELAY) { + if (abs(currentMillis - qsp.lastFrameReceivedAt[QSP_FRAME_RC_DATA]) > RX_FAILSAFE_DELAY) { qsp.deviceState = DEVICE_STATE_FAILSAFE; } else { qsp.deviceState = DEVICE_STATE_OK; diff --git a/qsp.cpp b/qsp.cpp index 5cdf020..2061d8b 100644 --- a/qsp.cpp +++ b/qsp.cpp @@ -194,10 +194,13 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p canTransmit = true; #endif - switch (frameId) - { + //Store the last timestamp when frame was received + if (frameId < QSP_FRAME_COUNT) { + qsp->lastFrameReceivedAt[frameId] = millis(); + } + + switch (frameId) { case QSP_FRAME_RC_DATA: - qsp->lastRcFrameReceived = millis(); qspDecodeRcDataFrame(qsp, ppm); break; diff --git a/variables.h b/variables.h index cd6ce2f..0f6a98f 100644 --- a/variables.h +++ b/variables.h @@ -15,6 +15,10 @@ #define QSP_FRAME_RC_DATA 0x0 #define QSP_FRAME_RX_HEALTH 0x1 +#define QSP_FRAME_GET_RX_CONFIG 0x2 +#define QSP_FRAME_RX_CONFIG 0x3 +#define QSP_FRAME_SET_RX_CONFIG 0x4 +#define QSP_FRAME_COUNT 0x5 #define PIN_LED 13 @@ -48,7 +52,7 @@ struct QspConfiguration_t { uint8_t payload[QSP_PAYLOAD_LENGTH] = {0}; uint8_t payloadLength = 0; uint8_t frameToSend = 0; - uint32_t lastRcFrameReceived = 0; + uint32_t lastFrameReceivedAt[QSP_FRAME_COUNT] = {0}; uint8_t deviceState = DEVICE_STATE_OK; void (* hardwareWriteFunction)(uint8_t, QspConfiguration_t*); }; \ No newline at end of file