106 MDC crc fix

This commit is contained in:
wu58430 2023-12-05 20:19:43 +08:00
parent 98ae937059
commit 79e40d98b7
7 changed files with 60 additions and 41 deletions

View file

@ -46,7 +46,7 @@ ENABLE_BLMIN_TMP_OFF := 0
ENABLE_SCAN_RANGES := 1 ENABLE_SCAN_RANGES := 1
ENABLE_MDC1200 := 1 ENABLE_MDC1200 := 1
ENABLE_MDC1200_SHOW_OP_ARG := 0 ENABLE_MDC1200_SHOW_OP_ARG := 0
ENABLE_MDC1200_SIDE_BEEP := 1 ENABLE_MDC1200_SIDE_BEEP := 0
# ---- DEBUGGING ---- # ---- DEBUGGING ----
ENABLE_AM_FIX_SHOW_DATA := 0 ENABLE_AM_FIX_SHOW_DATA := 0
ENABLE_AGC_SHOW_DATA := 0 ENABLE_AGC_SHOW_DATA := 0

View file

@ -85,6 +85,8 @@ void AIRCOPY_StorePacket(void)
g_FSK_Buffer[i + 1] ^= Obfuscation[i % 8]; g_FSK_Buffer[i + 1] ^= Obfuscation[i % 8];
CRC = CRC_Calculate(&g_FSK_Buffer[1], 2 + 64); CRC = CRC_Calculate(&g_FSK_Buffer[1], 2 + 64);
CRC_Init();
if (g_FSK_Buffer[34] == CRC) if (g_FSK_Buffer[34] == CRC)
{ {
const uint16_t *pData; const uint16_t *pData;

View file

@ -13,7 +13,7 @@ const uint8_t mdc1200_sync[5] = {0x07, 0x09, 0x2a, 0x44, 0x6f};
uint8_t mdc1200_sync_suc_xor[sizeof(mdc1200_sync)]; uint8_t mdc1200_sync_suc_xor[sizeof(mdc1200_sync)];
#if 1 #if 0
uint16_t compute_crc(const void *data, const unsigned int data_len) uint16_t compute_crc(const void *data, const unsigned int data_len)
{ // let the CPU's hardware do some work :) { // let the CPU's hardware do some work :)
@ -25,21 +25,24 @@ uint16_t compute_crc(const void *data, const unsigned int data_len)
} }
#elif 1 #elif 1
uint16_t compute_crc( void *data, const unsigned int data_len) { // let the CPU's hardware do some work :)
uint16_t compute_crc(const void *data, const unsigned int data_len) return CRC_Calculate(data, data_len);
{ // using the reverse computation and polynominal avoids having to reverse the bit order during and after }
unsigned int i; //uint16_t compute_crc( void *data, const unsigned int data_len)
const uint8_t *data8 = (const uint8_t *)data; // { // using the reverse computation and polynominal avoids having to reverse the bit order during and after
uint16_t crc = 0; // unsigned int i;
for (i = 0; i < data_len; i++) // uint8_t *data8 = ( uint8_t *)data;
{ // uint16_t crc = 0;
unsigned int k; // for (i = 0; i < data_len; i++)
crc ^= data8[i]; // {
for (k = 8; k > 0; k--) // unsigned int k;
crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1; // crc ^= data8[i];
} // for (k = 8; k > 0; k--)
return crc ^ 0xffff; // crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1;
} // }
// return crc ^ 0xffff;
// }
#else #else
@ -528,7 +531,7 @@ void MDC1200_process_rx(const uint16_t interrupt_bits)
&mdc1200_op, &mdc1200_op,
&mdc1200_arg, &mdc1200_arg,
&mdc1200_unit_id)) { &mdc1200_unit_id)) {
mdc1200_rx_ready_tick_500ms = 2 * 3; // 6 second MDC display time mdc1200_rx_ready_tick_500ms = 2 * 5; // 6 second MDC display time
gUpdateDisplay = true; gUpdateDisplay = true;
} }

View file

@ -516,9 +516,9 @@ bool UART_IsCommandAvailable(void)
// for (int i = 0; i < Size; i++) { // for (int i = 0; i < Size; i++) {
// tmp[i]=UART_Command.Buffer[i]; // tmp[i]=UART_Command.Buffer[i];
// } // }
bool judge=(CRC_Calculate1(UART_Command.Buffer, Size)!= CRC) ? false : true;
return judge;
return (CRC_Calculate(UART_Command.Buffer, Size)!= CRC) ? false : true;
} }
void UART_HandleCommand(void) void UART_HandleCommand(void)

View file

@ -48,28 +48,11 @@ void CRC_InitReverse(void)
CRC_IV = 0; CRC_IV = 0;
} }
#endif #endif
// uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size)
//{
// const uint8_t *pData = (const uint8_t *)pBuffer;
// uint16_t i, Crc;
// UART_Send(pData, Size);
//
// CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_ENABLE;
// UART_Send(pData, Size);
//
// for (i = 0; i < Size; i++) {
// CRC_DATAIN = pData[i];
// }
// Crc = (uint16_t)CRC_DATAOUT;
//
// CRC_CR = (CRC_CR & ~CRC_CR_CRC_EN_MASK) | CRC_CR_CRC_EN_BITS_DISABLE;
//
// return Crc;
//}
#define CRC16_XMODEM_POLY 0x1021 #define CRC16_XMODEM_POLY 0x1021
uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size) { uint16_t CRC_Calculate1( void *pBuffer, uint16_t Size)
const uint8_t *pData = (const uint8_t *)pBuffer; {
uint8_t *pData = ( uint8_t *)pBuffer;
uint16_t crc = 0; // 初始CRC值为0 uint16_t crc = 0; // 初始CRC值为0
while (Size--) { while (Size--) {
@ -85,3 +68,32 @@ uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size) {
return crc; return crc;
} }
uint16_t CRC_Calculate( void *pBuffer, uint16_t Size) {
// uint8_t *pData = ( uint8_t *)pBuffer;
// uint16_t crc = 0; // 初始CRC值为0
//
// while (Size--) {
// crc ^= (*pData++) << 8; // 将数据字节的最高位与CRC异或
// for (uint8_t i = 0; i < 8; i++) {
// if (crc & 0x8000) { // 检查最高位是否为1
// crc = (crc << 1) ^ CRC16_XMODEM_POLY; // 如果最高位为1执行CRC多项式计算
// } else {
// crc = crc << 1; // 如果最高位为0继续左移
// }
// }
// }
//
// return crc;
unsigned int i;
uint8_t *data8 = ( uint8_t *)pBuffer;
uint16_t crc = 0;
for (i = 0; i < Size; i++)
{
unsigned int k;
crc ^= data8[i];
for (k = 8; k > 0; k--)
crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1;
}
return crc ^ 0xffff;
}

View file

@ -20,7 +20,9 @@
#include <stdint.h> #include <stdint.h>
void CRC_Init(void); void CRC_Init(void);
uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size); uint16_t CRC_Calculate( void *pBuffer, uint16_t Size);
uint16_t CRC_Calculate1( void *pBuffer, uint16_t Size);
void CRC_InitReverse(void); void CRC_InitReverse(void);
#endif #endif

View file

@ -4,7 +4,7 @@
#ifdef GIT_HASH #ifdef GIT_HASH
#define VER GIT_HASH #define VER GIT_HASH
#else #else
#define VER "105" #define VER "106"
#endif #endif
#ifndef ONE_OF_ELEVEN_VER #ifndef ONE_OF_ELEVEN_VER