diff --git a/crossbow/config.h b/crossbow/config.h index 3e1a467..9706f06 100644 --- a/crossbow/config.h +++ b/crossbow/config.h @@ -13,8 +13,8 @@ * DEVICE_MODE_TX * DEVICE_MODE_RX */ -#define DEVICE_MODE_TX -// #define DEVICE_MODE_RX +// #define DEVICE_MODE_TX +#define DEVICE_MODE_RX // #define FEATURE_TX_OLED // #define FORCE_TX_WITHOUT_INPUT diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index 4dd5840..6bc9d68 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -124,6 +124,9 @@ void onQspSuccess(QspConfiguration_t *qsp, TxDeviceState_t *txDeviceState, RxDev //If recide received a valid frame, that means it can start to talk qsp->canTransmit = true; + radioState->rssi = getRadioRssi(); + radioState->snr = getRadioSnr(); + /* * RX module hops to next channel after frame has been received */ @@ -405,9 +408,6 @@ void loop(void) qspDecodeIncomingFrame(&qsp, tmpBuffer[i], &rxDeviceState, &txDeviceState, &radioState); } - radioState.rssi = getRadioRssi(); - radioState.snr = getRadioSnr(); - //After reading, flush radio buffer, we have no need for whatever might be over there LoRa.sleep(); LoRa.receive(); @@ -474,9 +474,6 @@ void loop(void) #endif #ifdef DEVICE_MODE_RX - - //FIXME here we are missing the whole procedure for jumping to next channel when frame was not recived - /* * This routine updates RX device state and updates one of radio channels with RSSI value */ @@ -486,7 +483,7 @@ void loop(void) uint8_t output = constrain(radioState.rssi - 40, 0, 100); - rxDeviceState.channels[RSSI_CHANNEL - 1] = (output * 10) + 1000; + rxDeviceState.indicatedRssi = (output * 10) + 1000; if (qsp.deviceState == DEVICE_STATE_FAILSAFE) { digitalWrite(LED_BUILTIN, HIGH); } else { @@ -525,6 +522,8 @@ void loop(void) } if (currentMillis > sbusTime) { + rxDeviceState.channels[RSSI_CHANNEL - 1] = rxDeviceState.indicatedRssi; + sbusPreparePacket(sbusPacket, rxDeviceState.channels, false, (qsp.deviceState == DEVICE_STATE_FAILSAFE)); Serial1.write(sbusPacket, SBUS_PACKET_LENGTH); sbusTime = currentMillis + SBUS_UPDATE_RATE; @@ -532,6 +531,8 @@ void loop(void) if (qsp.lastFrameReceivedAt[QSP_FRAME_RC_DATA] + RX_FAILSAFE_DELAY < currentMillis) { qsp.deviceState = DEVICE_STATE_FAILSAFE; + rxDeviceState.indicatedRssi = 0; + radioState.rssi = 0; } else { qsp.deviceState = DEVICE_STATE_OK; } diff --git a/crossbow/variables.h b/crossbow/variables.h index fa13dd6..b1c25bc 100644 --- a/crossbow/variables.h +++ b/crossbow/variables.h @@ -126,6 +126,7 @@ struct RxDeviceState_t { uint8_t a2Voltage = 0; uint8_t flags = 0; int16_t channels[16] = {}; + int16_t indicatedRssi = 0; }; struct QspConfiguration_t {