Other Parts Discussed in Thread: CC1312R, CC1101,
1. 参考DN504 FEC Implementation 我们将源数据(0x01 0x02 0x03 0x04 0x05)进行FEC编码,得到:4C F0 30 10 C8 7C C3 23 40 34 7C E3;
2. 参考DN507 FEC Decoding 对上述编码数据进行解码,得到结果是:0x01 0x02 0x73 0x04 0x05, 与源数据不一致!
// NUMBER_OF_BYTES_AFTER_DECODING should be given the length of the payload + CRC (CRC is optional) #define NUMBER_OF_BYTES_AFTER_DECODING 5 #define NUMBER_OF_BYTES_BEFORE_DECODING (4 * ((NUMBER_OF_BYTES_AFTER_DECODING / 2) + 1)) /******************************************************************************* * @fn: * @brief: * @para: * @return: ******************************************************************************/ void ReadRxFifo(uint8_t* rxBuf, uint16_t startAddr, uint16_t readLen) { // 01 02 03 04 05 const uint8_t rxRawData[] = { // 0x4C, 0xF0, 0x30, 0x10, // 0xC8, 0x7C, 0xC3, 0x23, // 0x40, 0x34, 0x7C, 0xE3, // }; uint8_t iX; for (iX = 0; iX < readLen; iX++) { if (startAddr + iX >= sizeof(rxRawData)) { break; } rxBuf[iX] = rxRawData[startAddr + iX]; } } /******************************************************************************* * @fn: * @brief: * @para: * @return: ******************************************************************************/ void main(void) { unsigned short checksum; unsigned short nBytes; unsigned char *pDecData = rxPacket; // Destination for decoded data uint16_t total = 0; // Init MCU and Radio while (1) { // while (!packetReceived) // ; // Wait for packet to be received (64 bytes in the RXFIFO) // packetReceived = 0; memset(rxPacket, 0, sizeof(rxPacket)); pDecData = rxPacket; // Perform de-interleaving and decoding (both done in the same function) fecDecode(NULL, NULL, 0); // The function needs to be called with a NULL pointer for // initialization before every packet to decode nBytes = NUMBER_OF_BYTES_AFTER_DECODING; total = 0; while (nBytes > 0) { unsigned short nBytesOut; // readRxFifo(RF_RXFIFO, rxBuffer, 4); // Read 4 bytes from the RXFIFO and store them in rxBuffer ReadRxFifo(rxBuffer, total, 4); nBytesOut = fecDecode(pDecData, rxBuffer, nBytes); total += 4; nBytes -= nBytesOut; pDecData += nBytesOut; } // 运行到此处,rxPacket的内容是:01 02 73 04 05 (十六进制) // Perform CRC check (Optional) { unsigned short i; nBytes = NUMBER_OF_BYTES_AFTER_DECODING; checksum = 0xFFFF; // Init value for CRC calculation for (i = 0; i < nBytes; i++) checksum = calcCRC(rxPacket[i], checksum); if (!checksum) { // Do something to indicate that the CRC is OK } } } }