Ensured there is sufficient time to send a telemetry frame
This commit is contained in:
parent
5d9c22e823
commit
3c5dd1604e
|
@ -41,7 +41,8 @@
|
||||||
|
|
||||||
#include "telemetry/telemetry.h"
|
#include "telemetry/telemetry.h"
|
||||||
|
|
||||||
#define CRSF_TIME_NEEDED_PER_FRAME_US 1500 //!! this needs checking
|
#define CRSF_TIME_NEEDED_PER_FRAME_US 1000
|
||||||
|
#define CRSF_TIME_BETWEEN_FRAMES_US 4000 // a frame is sent by the transmitter every 4 milliseconds
|
||||||
|
|
||||||
#define CRSF_DIGITAL_CHANNEL_MIN 172
|
#define CRSF_DIGITAL_CHANNEL_MIN 172
|
||||||
#define CRSF_DIGITAL_CHANNEL_MAX 1811
|
#define CRSF_DIGITAL_CHANNEL_MAX 1811
|
||||||
|
@ -72,6 +73,8 @@ static uint8_t telemetryBufLen = 0;
|
||||||
* Assume a max payload of 32 bytes (needs confirming with TBS), so max frame size of 36 bytes
|
* Assume a max payload of 32 bytes (needs confirming with TBS), so max frame size of 36 bytes
|
||||||
* A 36 byte frame can be transmitted in 771 microseconds.
|
* A 36 byte frame can be transmitted in 771 microseconds.
|
||||||
*
|
*
|
||||||
|
* CRSF_TIME_NEEDED_PER_FRAME_US is set conservatively at 1000 microseconds
|
||||||
|
*
|
||||||
* Every frame has the structure:
|
* Every frame has the structure:
|
||||||
* <Device address> <Frame length> < Type> <Payload> < CRC>
|
* <Device address> <Frame length> < Type> <Payload> < CRC>
|
||||||
*
|
*
|
||||||
|
@ -204,10 +207,11 @@ void crsfRxSendTelemetryData(void)
|
||||||
{
|
{
|
||||||
// if there is telemetry data to write
|
// if there is telemetry data to write
|
||||||
if (telemetryBufLen > 0) {
|
if (telemetryBufLen > 0) {
|
||||||
// check that we are not currently receiving data
|
// check that we are not currently receiving data (ie in the middle of an RX frame)
|
||||||
const uint32_t now = micros();
|
// and that there is time to send the telemetry frame before the next RX frame arrives
|
||||||
if (now > crsfFrameStartAt + CRSF_TIME_NEEDED_PER_FRAME_US) {
|
const uint32_t timeSinceStartOfFrame = micros() - crsfFrameStartAt;
|
||||||
// any incoming frames will be complete, so it is OK to write to shared serial port
|
if ((timeSinceStartOfFrame > CRSF_TIME_NEEDED_PER_FRAME_US)
|
||||||
|
&& (timeSinceStartOfFrame < CRSF_TIME_BETWEEN_FRAMES_US - CRSF_TIME_NEEDED_PER_FRAME_US)) {
|
||||||
serialWriteBuf(serialPort, telemetryBuf, telemetryBufLen);
|
serialWriteBuf(serialPort, telemetryBuf, telemetryBufLen);
|
||||||
telemetryBufLen = 0; // reset telemetry buffer
|
telemetryBufLen = 0; // reset telemetry buffer
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue