From b9f00bdbc5bdfa27ed5d78285e6258b16718614f Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Tue, 26 May 2020 12:41:33 +0200 Subject: [PATCH] Q90C: checksum fix --- Multiprotocol/Multiprotocol.h | 2 +- Multiprotocol/NRF250K_EMU.ino | 10 +--------- Multiprotocol/Q90C_nrf24l01.ino | 17 ++++++++++------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index f2fcb11..d941c1e 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 1 -#define VERSION_PATCH_LEVEL 3 +#define VERSION_PATCH_LEVEL 4 //****************** // Protocols diff --git a/Multiprotocol/NRF250K_EMU.ino b/Multiprotocol/NRF250K_EMU.ino index cb57672..d98695c 100644 --- a/Multiprotocol/NRF250K_EMU.ino +++ b/Multiprotocol/NRF250K_EMU.ino @@ -192,13 +192,6 @@ static void __attribute__((unused)) XN297L_WriteEnhancedPayload(uint8_t* msg, ui static uint8_t pid=0; // address - if (xn297_addr_len < 4) - { - // If address length (which is defined by receive address length) - // is less than 4 the TX address can't fit the preamble, so the last - // byte goes here - buf[last++] = 0x55; - } for (uint8_t i = 0; i < xn297_addr_len; ++i) { buf[last] = xn297_tx_addr[xn297_addr_len-i-1]; @@ -235,9 +228,8 @@ static void __attribute__((unused)) XN297L_WriteEnhancedPayload(uint8_t* msg, ui // crc //if (xn297_crc) { - uint8_t offset = xn297_addr_len < 4 ? 1 : 0; uint16_t crc = 0xb5d2; - for (uint8_t i = offset; i < last; ++i) + for (uint8_t i = 0; i < last; ++i) crc = crc16_update(crc, buf[i], 8); crc = crc16_update(crc, buf[last] & 0xc0, 2); if (xn297_scramble_enabled) diff --git a/Multiprotocol/Q90C_nrf24l01.ino b/Multiprotocol/Q90C_nrf24l01.ino index d6c124f..63858ee 100644 --- a/Multiprotocol/Q90C_nrf24l01.ino +++ b/Multiprotocol/Q90C_nrf24l01.ino @@ -47,13 +47,11 @@ static void __attribute__((unused)) Q90C_send_packet() packet[8] = 0; packet[9] = 0; packet[10] = rx_tx_addr[4]; - packet[11] = 0x3a; // initial checksum value ? } else { XN297L_Hopping(hopping_frequency_no++); // RF Freq - if (hopping_frequency_no >= Q90C_RF_NUM_CHANNELS) - hopping_frequency_no = 0; + hopping_frequency_no %= Q90C_RF_NUM_CHANNELS; packet[0]= convert_channel_8b(THROTTLE); // 0..255 // A,E,R have weird scaling, 0x00-0xff range (unsigned) but center isn't 7f or 80 // rudder ff-7a-00 @@ -83,16 +81,21 @@ static void __attribute__((unused)) Q90C_send_packet() packet[8] = 0x00; // flags: 3 position flight mode (Angle - Horizon - Acro), VTX Toggle HIGH = next vTX frequency packet[9] = 0x00; packet[10] = packet_count++; - packet[11] = 0x9c; // initial checksum value ? } - // checksum + uint8_t sum=0; + // checksum for (uint8_t i = 0; i < Q90C_PACKET_SIZE - 1; i++) - packet[11] += packet[i]; + { + sum += packet[i]; + debug("%02X ", packet[i]); + } + packet[11] = sum ^ (IS_BIND_IN_PROGRESS? 0xc6 : 0xa4); + debugln("%02X",packet[11]); XN297L_SetFreqOffset(); // Set frequency offset - XN297L_WriteEnhancedPayload(packet, Q90C_PACKET_SIZE, 0); XN297L_SetPower(); // Set tx_power + XN297L_WriteEnhancedPayload(packet, Q90C_PACKET_SIZE, 0); } static void __attribute__((unused)) Q90C_initialize_txid()