mirror of
https://github.com/silenty4ng/uv-k5-firmware-chinese-lts
synced 2025-03-29 21:56:51 +00:00
106 MDC crc fix
This commit is contained in:
parent
98ae937059
commit
79e40d98b7
7 changed files with 60 additions and 41 deletions
2
Makefile
2
Makefile
|
@ -46,7 +46,7 @@ ENABLE_BLMIN_TMP_OFF := 0
|
|||
ENABLE_SCAN_RANGES := 1
|
||||
ENABLE_MDC1200 := 1
|
||||
ENABLE_MDC1200_SHOW_OP_ARG := 0
|
||||
ENABLE_MDC1200_SIDE_BEEP := 1
|
||||
ENABLE_MDC1200_SIDE_BEEP := 0
|
||||
# ---- DEBUGGING ----
|
||||
ENABLE_AM_FIX_SHOW_DATA := 0
|
||||
ENABLE_AGC_SHOW_DATA := 0
|
||||
|
|
|
@ -85,6 +85,8 @@ void AIRCOPY_StorePacket(void)
|
|||
g_FSK_Buffer[i + 1] ^= Obfuscation[i % 8];
|
||||
|
||||
CRC = CRC_Calculate(&g_FSK_Buffer[1], 2 + 64);
|
||||
CRC_Init();
|
||||
|
||||
if (g_FSK_Buffer[34] == CRC)
|
||||
{
|
||||
const uint16_t *pData;
|
||||
|
|
|
@ -13,7 +13,7 @@ const uint8_t mdc1200_sync[5] = {0x07, 0x09, 0x2a, 0x44, 0x6f};
|
|||
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)
|
||||
{ // 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
|
||||
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)
|
||||
{ // using the reverse computation and polynominal avoids having to reverse the bit order during and after
|
||||
unsigned int i;
|
||||
const uint8_t *data8 = (const uint8_t *)data;
|
||||
uint16_t crc = 0;
|
||||
for (i = 0; i < data_len; i++)
|
||||
{
|
||||
unsigned int k;
|
||||
crc ^= data8[i];
|
||||
for (k = 8; k > 0; k--)
|
||||
crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1;
|
||||
}
|
||||
return crc ^ 0xffff;
|
||||
}
|
||||
return CRC_Calculate(data, data_len);
|
||||
}
|
||||
//uint16_t compute_crc( void *data, const unsigned int data_len)
|
||||
// { // using the reverse computation and polynominal avoids having to reverse the bit order during and after
|
||||
// unsigned int i;
|
||||
// uint8_t *data8 = ( uint8_t *)data;
|
||||
// uint16_t crc = 0;
|
||||
// for (i = 0; i < data_len; i++)
|
||||
// {
|
||||
// unsigned int k;
|
||||
// crc ^= data8[i];
|
||||
// for (k = 8; k > 0; k--)
|
||||
// crc = (crc & 1u) ? (crc >> 1) ^ 0x8408 : crc >> 1;
|
||||
// }
|
||||
// return crc ^ 0xffff;
|
||||
// }
|
||||
|
||||
#else
|
||||
|
||||
|
@ -528,7 +531,7 @@ void MDC1200_process_rx(const uint16_t interrupt_bits)
|
|||
&mdc1200_op,
|
||||
&mdc1200_arg,
|
||||
&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;
|
||||
|
||||
}
|
||||
|
|
|
@ -516,9 +516,9 @@ bool UART_IsCommandAvailable(void)
|
|||
// for (int i = 0; i < Size; i++) {
|
||||
// tmp[i]=UART_Command.Buffer[i];
|
||||
// }
|
||||
bool judge=(CRC_Calculate1(UART_Command.Buffer, Size)!= CRC) ? false : true;
|
||||
|
||||
|
||||
return (CRC_Calculate(UART_Command.Buffer, Size)!= CRC) ? false : true;
|
||||
return judge;
|
||||
}
|
||||
|
||||
void UART_HandleCommand(void)
|
||||
|
|
52
driver/crc.c
52
driver/crc.c
|
@ -48,28 +48,11 @@ void CRC_InitReverse(void)
|
|||
CRC_IV = 0;
|
||||
}
|
||||
#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
|
||||
|
||||
uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size) {
|
||||
const uint8_t *pData = (const uint8_t *)pBuffer;
|
||||
uint16_t CRC_Calculate1( void *pBuffer, uint16_t Size)
|
||||
{
|
||||
uint8_t *pData = ( uint8_t *)pBuffer;
|
||||
uint16_t crc = 0; // 初始CRC值为0
|
||||
|
||||
while (Size--) {
|
||||
|
@ -85,3 +68,32 @@ uint16_t CRC_Calculate(const void *pBuffer, uint16_t Size) {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#ifdef GIT_HASH
|
||||
#define VER GIT_HASH
|
||||
#else
|
||||
#define VER "105"
|
||||
#define VER "106"
|
||||
#endif
|
||||
|
||||
#ifndef ONE_OF_ELEVEN_VER
|
||||
|
|
Loading…
Add table
Reference in a new issue