Skip to content

Commit

Permalink
[CC101] receive function works as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Feb 3, 2025
1 parent 634d54f commit 6a59468
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 6 deletions.
2 changes: 1 addition & 1 deletion software/data/Aircrafts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<br>

Expand Down
212 changes: 207 additions & 5 deletions software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down

1 comment on commit 6a59468

@lyusupov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

Please sign in to comment.