From 6a594683ee6d550ccf6adafc1555093fb7e638c2 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Mon, 3 Feb 2025 06:38:25 +0300 Subject: [PATCH] [CC101] receive function works as well --- software/data/Aircrafts/README.md | 2 +- .../SoftRF/src/driver/radio/radiolib.cpp | 212 +++++++++++++++++- 2 files changed, 208 insertions(+), 6 deletions(-) diff --git a/software/data/Aircrafts/README.md b/software/data/Aircrafts/README.md index 921ced8eb..3ba133ae4 100644 --- a/software/data/Aircrafts/README.md +++ b/software/data/Aircrafts/README.md @@ -13,7 +13,7 @@ Follow [**this link**](https://github.com/lyusupov/SoftRF/actions/workflows/adb. The file is located in '**Artifacts**' section. > [!IMPORTANT] -> [Artifact download](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/storing-and-sharing-data-from-a-workflow) only work for GitHub registered users. Read [this ticket](https://github.com/actions/upload-artifact/issues/51) for more details. +> [Artifact download](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/storing-and-sharing-data-from-a-workflow) is only available for registered GitHub users. Read [this ticket](https://github.com/actions/upload-artifact/issues/51) for more details.
diff --git a/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp b/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp index 26f2b93c1..813b1ed79 100644 --- a/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp +++ b/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp @@ -1329,10 +1329,10 @@ static void cc1101_setup() SoC->SPI_begin(); - uint32_t gdo0 = lmic_pins.busy == LMIC_UNUSED_PIN ? - RADIOLIB_NC : lmic_pins.busy; - uint32_t gdo2 = lmic_pins.dio[0] == LMIC_UNUSED_PIN ? - RADIOLIB_NC : lmic_pins.dio[0]; + uint32_t gdo0 = lmic_pins.dio[0] == LMIC_UNUSED_PIN ? + RADIOLIB_NC : lmic_pins.dio[0]; + uint32_t gdo2 = lmic_pins.busy == LMIC_UNUSED_PIN ? + RADIOLIB_NC : lmic_pins.busy; mod = new Module(lmic_pins.nss, gdo0, RADIOLIB_NC, gdo2, RadioSPI); radio_ti = new CC1101(mod); @@ -1563,7 +1563,209 @@ static void cc1101_setup() static bool cc1101_receive() { - return false; + bool success = false; + int state; + + if (settings->power_save & POWER_SAVE_NORECEIVE) { + return success; + } + + if (!cc1101_receive_active) { + + state = radio_ti->startReceive(); + if (state == RADIOLIB_ERR_NONE) { + cc1101_receive_active = true; + } + } + + if (cc1101_receive_complete == true) { + + rxPacket.len = radio_ti->getPacketLength(); + + if (rxPacket.len > 0) { + + if (rxPacket.len > sizeof(rxPacket.payload)) { + rxPacket.len = sizeof(rxPacket.payload); + } + + state = radio_ti->readData(rxPacket.payload, rxPacket.len); + cc1101_receive_active = false; + + if (state == RADIOLIB_ERR_NONE && + !memeqzero(rxPacket.payload, rxPacket.len)) { + + uint8_t i; + + if (rl_protocol->syncword_size > 2) { + for (i=2; i < rl_protocol->syncword_size; i++) { + if (rxPacket.payload[i-2] != rl_protocol->syncword[i]) { +#if 0 + Serial.print("syncword mismatch "); + Serial.print("i="); Serial.print(i); + Serial.print(" p="); Serial.print(rxPacket.payload[i-2], HEX); + Serial.print(" s="); Serial.print(rl_protocol->syncword[i], HEX); + Serial.println(); +#endif + if (i != 2) { + memset(rxPacket.payload, 0, sizeof(rxPacket.payload)); + rxPacket.len = 0; + cc1101_receive_complete = false; + + return success; + } + } + } + + memcpy(rxPacket.payload, + rxPacket.payload + rl_protocol->syncword_size - 2, + rxPacket.len - (rl_protocol->syncword_size - 2)); + } + + size_t size = 0; + uint8_t offset; + + u1_t crc8, pkt_crc8; + u2_t crc16, pkt_crc16; + + RadioLib_DataPacket *rxPacket_ptr = &rxPacket; + + switch (rl_protocol->crc_type) + { + case RF_CHECKSUM_TYPE_GALLAGER: + case RF_CHECKSUM_TYPE_CRC_MODES: + case RF_CHECKSUM_TYPE_NONE: + /* crc16 left not initialized */ + break; + case RF_CHECKSUM_TYPE_CRC8_107: + crc8 = 0x71; /* seed value */ + break; + case RF_CHECKSUM_TYPE_CCITT_0000: + crc16 = 0x0000; /* seed value */ + break; + case RF_CHECKSUM_TYPE_CCITT_FFFF: + default: + crc16 = 0xffff; /* seed value */ + break; + } + + switch (rl_protocol->type) + { + case RF_PROTOCOL_LEGACY: + /* take in account NRF905/FLARM "address" bytes */ + crc16 = update_crc_ccitt(crc16, 0x31); + crc16 = update_crc_ccitt(crc16, 0xFA); + crc16 = update_crc_ccitt(crc16, 0xB6); + break; + case RF_PROTOCOL_P3I: + case RF_PROTOCOL_OGNTP: + case RF_PROTOCOL_ADSL_860: + default: + break; + } + + switch (rl_protocol->type) + { + case RF_PROTOCOL_P3I: + offset = rl_protocol->payload_offset; + for (i = 0; i < rl_protocol->payload_size; i++) + { + update_crc8(&crc8, (u1_t)(rxPacket_ptr->payload[i + offset])); + if (i < sizeof(RxBuffer)) { + RxBuffer[i] = rxPacket_ptr->payload[i + offset] ^ + pgm_read_byte(&whitening_pattern[i]); + } + } + + pkt_crc8 = rxPacket_ptr->payload[i + offset]; + + if (crc8 == pkt_crc8) { + success = true; + } + break; + case RF_PROTOCOL_OGNTP: + case RF_PROTOCOL_ADSL_860: + case RF_PROTOCOL_LEGACY: + default: + offset = 0; + size = rl_protocol->payload_offset + + rl_protocol->payload_size + + rl_protocol->payload_size + + rl_protocol->crc_size + + rl_protocol->crc_size; + if (rxPacket_ptr->len >= (size + offset)) { + uint8_t val1, val2; + for (i = 0; i < size; i++) { + val1 = pgm_read_byte(&ManchesterDecode[rxPacket_ptr->payload[i + offset]]); + i++; + val2 = pgm_read_byte(&ManchesterDecode[rxPacket_ptr->payload[i + offset]]); + if ((i>>1) < sizeof(RxBuffer)) { + RxBuffer[i>>1] = ((val1 & 0x0F) << 4) | (val2 & 0x0F); + + if (i < size - (rl_protocol->crc_size + rl_protocol->crc_size)) { + switch (rl_protocol->crc_type) + { + case RF_CHECKSUM_TYPE_GALLAGER: + case RF_CHECKSUM_TYPE_CRC_MODES: + case RF_CHECKSUM_TYPE_NONE: + break; + case RF_CHECKSUM_TYPE_CCITT_FFFF: + case RF_CHECKSUM_TYPE_CCITT_0000: + default: + crc16 = update_crc_ccitt(crc16, (u1_t)(RxBuffer[i>>1])); + break; + } + } + } + } + + size = size>>1; + + switch (rl_protocol->crc_type) + { + case RF_CHECKSUM_TYPE_GALLAGER: + if (LDPC_Check((uint8_t *) &RxBuffer[0]) == 0) { + success = true; + } + break; + case RF_CHECKSUM_TYPE_CRC_MODES: +#if defined(ENABLE_ADSL) + if (ADSL_Packet::checkPI((uint8_t *) &RxBuffer[0], size) == 0) { + success = true; + } +#endif /* ENABLE_ADSL */ + break; + case RF_CHECKSUM_TYPE_CCITT_FFFF: + case RF_CHECKSUM_TYPE_CCITT_0000: + offset = rl_protocol->payload_offset + rl_protocol->payload_size; + if (offset + 1 < sizeof(RxBuffer)) { + pkt_crc16 = (RxBuffer[offset] << 8 | RxBuffer[offset+1]); + if (crc16 == pkt_crc16) { + + success = true; + } + } + break; + default: + break; + } + } + break; + } + + if (success) { + RF_last_rssi = radio_ti->getRSSI(); + rx_packets_counter++; + } + } + + memset(rxPacket.payload, 0, sizeof(rxPacket.payload)); + rxPacket.len = 0; + } + + cc1101_receive_complete = false; + } + + return success; } static bool cc1101_transmit()