From 12e2bca44104795c3a16d98d13808d2efdb97400 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Thu, 19 Apr 2018 12:49:40 +0200 Subject: [PATCH] Fixed current channel indication and next channel computation --- .vscode/c_cpp_properties.json | 6 ------ crossbow/config.h | 6 +++--- crossbow/crossbow.ino | 4 ++-- crossbow/qsp.cpp | 5 ++--- crossbow/qsp.h | 2 +- crossbow/variables.h | 2 +- 6 files changed, 9 insertions(+), 16 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index fc1a11f..c6842ff 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -11,12 +11,6 @@ "${workspaceRoot}" ] }, - "defines": [ - "SPI_HAS_NOTUSINGINTERRUPT", - "FEATURE_TX_INPUT_SBUS", - "DEVICE_MODE_TX", - "DEVICE_MODE_RX" - ], "intelliSenseMode": "msvc-x64", "cStandard": "c11", "cppStandard": "c++17", diff --git a/crossbow/config.h b/crossbow/config.h index 0b540aa..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 @@ -27,7 +27,7 @@ */ #define FEATURE_TX_INPUT_SBUS -// #define DEBUG_SERIAL +#define DEBUG_SERIAL // #define DEBUG_PING_PONG // #define DEBUG_LED // #define DEBUG_TX_INPUT_ON_OLED diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index 0a6ba41..f3d8fa2 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -103,7 +103,7 @@ uint8_t getPrevChannel(uint8_t channel) { return (RADIO_CHANNEL_COUNT + channel - RADIO_HOP_OFFSET) % RADIO_CHANNEL_COUNT; } -void hopFrequency(RadioState_t *radioState, bool forward, uint8_t fromChannel) { +void hopFrequency(volatile RadioState_t *radioState, bool forward, uint8_t fromChannel) { radioState->channelEntryMillis = millis(); if (forward) { @@ -495,7 +495,7 @@ void loop(void) uint8_t size; LoRa.beginPacket(); //Prepare packet - qspEncodeFrame(&qsp, tmpBuffer, &size); + qspEncodeFrame(&qsp, &radioState, tmpBuffer, &size); //Sent it to radio in one SPI transaction LoRa.write(tmpBuffer, size); LoRa.endPacketAsync(); diff --git a/crossbow/qsp.cpp b/crossbow/qsp.cpp index 2fe7ef0..5106778 100644 --- a/crossbow/qsp.cpp +++ b/crossbow/qsp.cpp @@ -189,7 +189,6 @@ void qspDecodeIncomingFrame( qsp->frameId = (incomingByte >> 4) & 0x0f; payloadLength = qspFrameLengths[qsp->frameId]; receivedChannel = incomingByte & 0x0f; - qsp->protocolState = QSP_STATE_FRAME_TYPE_RECEIVED; } else if (qsp->protocolState == QSP_STATE_FRAME_TYPE_RECEIVED) @@ -228,7 +227,7 @@ void qspDecodeIncomingFrame( /** * Encode frame is corrent format and write to hardware */ -void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size) { +void qspEncodeFrame(QspConfiguration_t *qsp, volatile RadioState_t *radioState, uint8_t buffer[], uint8_t *size) { //Zero CRC qsp->crc = 0; @@ -238,7 +237,7 @@ void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size) { //Write frame type and length // We are no longer sending payload length, so 4 bits are now free for other usages // uint8_t data = qsp->payloadLength & 0x0f; - uint8_t data = 0; + uint8_t data = radioState->channel; data |= (qsp->frameToSend << 4) & 0xf0; qspComputeCrc(qsp, data); buffer[1] = data; diff --git a/crossbow/qsp.h b/crossbow/qsp.h index d9ee307..60eff2a 100644 --- a/crossbow/qsp.h +++ b/crossbow/qsp.h @@ -16,6 +16,6 @@ void qspDecodeIncomingFrame( volatile RadioState_t *radioState ); void qspClearPayload(QspConfiguration_t *qsp); -void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size); +void qspEncodeFrame(QspConfiguration_t *qsp, volatile RadioState_t *radioState, uint8_t buffer[], uint8_t *size); void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros); \ No newline at end of file diff --git a/crossbow/variables.h b/crossbow/variables.h index d8bab73..6481cfa 100644 --- a/crossbow/variables.h +++ b/crossbow/variables.h @@ -90,7 +90,7 @@ enum debugConfigFlags { #define RADIO_FREQUENCY_MAX 870000000 #define RADIO_FREQUENCY_RANGE (RADIO_FREQUENCY_MAX-RADIO_FREQUENCY_MIN) #define RADIO_CHANNEL_WIDTH 250000 -#define RADIO_CHANNEL_COUNT (RADIO_FREQUENCY_RANGE/RADIO_CHANNEL_WIDTH) + 1 // 9 channels in 2MHz range +#define RADIO_CHANNEL_COUNT 9 // 9 channels in 2MHz range (RADIO_FREQUENCY_RANGE/RADIO_CHANNEL_WIDTH) + 1 #define RADIO_HOP_OFFSET 5 struct RadioState_t {