mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-04-28 22:31:25 +03:00
fix mdc crc bug and tx/rx freq bug after using up/dn buttons
This commit is contained in:
parent
06a19ee05c
commit
4f6063f492
@ -16,6 +16,9 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifndef ENABLE_OVERLAY
|
||||
#include "ARMCM0.h"
|
||||
#endif
|
||||
#include "app/aircopy.h"
|
||||
#include "audio.h"
|
||||
#include "bsp/dp32g030/gpio.h"
|
||||
|
@ -834,6 +834,8 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
|
||||
}
|
||||
#endif
|
||||
|
||||
g_tx_vfo->freq_config_tx.frequency = g_tx_vfo->freq_config_rx.frequency;
|
||||
|
||||
// find the first channel that contains this frequency
|
||||
g_tx_vfo->frequency_channel = BOARD_find_channel(g_tx_vfo->freq_config_rx.frequency);
|
||||
|
||||
@ -904,6 +906,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
|
||||
|
||||
// save the new frequency into the VFO
|
||||
g_tx_vfo->freq_config_rx.frequency = frequency;
|
||||
g_tx_vfo->freq_config_tx.frequency = frequency;
|
||||
|
||||
// find the first channel that contains this frequency
|
||||
//
|
||||
|
@ -1930,9 +1930,10 @@ void BK4819_PlayRogerMDC1200(void)
|
||||
uint16_t fsk_reg59;
|
||||
|
||||
#ifdef ENABLE_MDC1200
|
||||
|
||||
const uint8_t op = MDC1200_OP_CODE_POST_ID;
|
||||
const uint8_t arg = 0x00;
|
||||
const uint16_t id = 0x5678;
|
||||
const uint16_t id = 0xB183;
|
||||
|
||||
uint8_t packet[8 + 40];
|
||||
memset(packet + 0, 0x00, 4);
|
||||
@ -2036,8 +2037,8 @@ void BK4819_PlayRogerMDC1200(void)
|
||||
BK4819_WriteRegister(BK4819_REG_70, // 0 0000000 1 1100000
|
||||
( 0u << 15) |
|
||||
( 0u << 8) |
|
||||
// ( 1u << 7) |
|
||||
( 0u << 7) |
|
||||
( 1u << 7) |
|
||||
// ( 0u << 7) |
|
||||
(96u << 0));
|
||||
|
||||
// Set FSK data length
|
||||
@ -2100,7 +2101,8 @@ void BK4819_PlayRogerMDC1200(void)
|
||||
// <7:0> 0x55 FSK Sync Byte 1
|
||||
//
|
||||
// BK4819_WriteRegister(BK4819_REG_5A, 0x5555);
|
||||
BK4819_WriteRegister(BK4819_REG_5A, 0xAAAA);
|
||||
// BK4819_WriteRegister(BK4819_REG_5A, 0xAAAA);
|
||||
BK4819_WriteRegister(BK4819_REG_5A, 0);
|
||||
|
||||
// REG_5B
|
||||
// <15:8> 0x55 FSK Sync Byte 2 (Sync Byte 0 first, then 1,2,3)
|
||||
@ -2137,8 +2139,8 @@ void BK4819_PlayRogerMDC1200(void)
|
||||
// enable TX
|
||||
BK4819_WriteRegister(BK4819_REG_59, (1u << 11) | fsk_reg59);
|
||||
|
||||
{ // packet takes 175ms long
|
||||
unsigned int timeout = 250 / 5; // allow up to 250ms for the TX to complete
|
||||
{ // a small packet takes 175ms long
|
||||
unsigned int timeout = 500 / 5; // allow up to 500ms for the TX to complete
|
||||
while (timeout-- > 0)
|
||||
{
|
||||
SYSTEM_DelayMs(5);
|
||||
|
BIN
firmware.bin
BIN
firmware.bin
Binary file not shown.
Binary file not shown.
116
mdc1200.c
116
mdc1200.c
@ -2,19 +2,46 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "mdc1200.h"
|
||||
/*
|
||||
uint8_t bitReverse8(uint8_t n)
|
||||
{
|
||||
n = ((n >> 1) & 0x55u) | ((n << 1) & 0xAAu);
|
||||
n = ((n >> 2) & 0x33u) | ((n << 2) & 0xCCu);
|
||||
n = ((n >> 4) & 0x0Fu) | ((n << 4) & 0xF0u);
|
||||
return n;
|
||||
}
|
||||
|
||||
uint16_t flip_crc(const uint16_t crc, const unsigned int bit_num)
|
||||
uint16_t bitReverse16(uint16_t n)
|
||||
{ // untested
|
||||
n = ((n >> 1) & 0x5555u) | ((n << 1) & 0xAAAAu);
|
||||
n = ((n >> 2) & 0x3333u) | ((n << 2) & 0xCCCCu);
|
||||
n = ((n >> 4) & 0x0F0Fu) | ((n << 4) & 0xF0F0u);
|
||||
n = ((n >> 8) & 0x00FFu) | ((n << 8) & 0xFF00u);
|
||||
return n;
|
||||
}
|
||||
|
||||
uint32_t bitReverse32(uint32_t n)
|
||||
{
|
||||
n = ((n >> 1) & 0x55555555u) | ((n << 1) & 0xAAAAAAAAu);
|
||||
n = ((n >> 2) & 0x33333333u) | ((n << 2) & 0xCCCCCCCCu);
|
||||
n = ((n >> 4) & 0x0F0F0F0Fu) | ((n << 4) & 0xF0F0F0F0u);
|
||||
n = ((n >> 8) & 0x00FF00FFu) | ((n << 8) & 0xFF00FF00u);
|
||||
n = ((n >> 16) & 0x0000FFFFu) | ((n << 16) & 0xFFFF0000u);
|
||||
return n;
|
||||
}
|
||||
*/
|
||||
uint16_t reverse_bits(const uint16_t bits_in, const unsigned int bit_num)
|
||||
{
|
||||
uint16_t i;
|
||||
uint16_t bit;
|
||||
uint16_t crc_out;
|
||||
for (i = 1u << (bit_num - 1), bit = 1u, crc_out = 0u; i > 0u; i >>= 1)
|
||||
uint16_t bits_out;
|
||||
for (i = 1u << (bit_num - 1), bit = 1u, bits_out = 0u; i > 0u; i >>= 1)
|
||||
{
|
||||
if (crc & i)
|
||||
crc_out |= bit;
|
||||
if (bits_in & i)
|
||||
bits_out |= bit;
|
||||
bit <<= 1;
|
||||
}
|
||||
return crc_out;
|
||||
return bits_out;
|
||||
}
|
||||
|
||||
uint16_t compute_crc(const uint8_t *data, const unsigned int data_len)
|
||||
@ -24,20 +51,22 @@ uint16_t compute_crc(const uint8_t *data, const unsigned int data_len)
|
||||
|
||||
for (i = 0; i < data_len; i++)
|
||||
{
|
||||
unsigned int mask;
|
||||
const uint16_t c = flip_crc(*data++, 8);
|
||||
for (mask = 0x80; mask > 0; mask >>= 1)
|
||||
uint16_t mask;
|
||||
|
||||
const uint16_t b = reverse_bits(*data++, 8); // bit reverse each data byte
|
||||
|
||||
for (mask = 0x0080; mask > 0; mask >>= 1)
|
||||
{
|
||||
uint16_t bit = crc & 0x8000;
|
||||
crc <<= 1;
|
||||
if (c & mask)
|
||||
if (b & mask)
|
||||
bit ^= 0x8000;
|
||||
if (bit)
|
||||
crc ^= 0x1021;
|
||||
}
|
||||
}
|
||||
|
||||
return ~flip_crc(crc, 16);
|
||||
return reverse_bits(crc, 16) ^ 0xffff; // bit reverse and invert the CRC
|
||||
}
|
||||
|
||||
uint8_t * encode_data(uint8_t *data)
|
||||
@ -48,8 +77,7 @@ uint8_t * encode_data(uint8_t *data)
|
||||
int csr[7];
|
||||
int lbits[112];
|
||||
|
||||
uint16_t ccrc = compute_crc(data, 4);
|
||||
|
||||
const uint16_t ccrc = compute_crc(data, 4);
|
||||
data[4] = (ccrc >> 0) & 0x00ff;
|
||||
data[5] = (ccrc >> 8) & 0x00ff;
|
||||
|
||||
@ -102,41 +130,57 @@ uint8_t * encode_data(uint8_t *data)
|
||||
|
||||
const uint8_t header[] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x07, 0x09, 0x2a, 0x44, 0x6f};
|
||||
|
||||
int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id)
|
||||
unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id)
|
||||
{
|
||||
memcpy(data, header, sizeof(header));
|
||||
data += sizeof(header);
|
||||
uint8_t *p = data;
|
||||
|
||||
data[0] = op;
|
||||
data[1] = arg;
|
||||
data[2] = (unit_id >> 8) & 0x00ff;
|
||||
data[3] = (unit_id >> 0) & 0x00ff;
|
||||
#if 0
|
||||
memcpy(p, header, sizeof(header));
|
||||
p += sizeof(header);
|
||||
#else
|
||||
memcpy(p + 7, header, sizeof(header));
|
||||
p += sizeof(header) - 7;
|
||||
#endif
|
||||
|
||||
encode_data(data);
|
||||
p[0] = op;
|
||||
p[1] = arg;
|
||||
p[2] = (unit_id >> 8) & 0x00ff;
|
||||
p[3] = (unit_id >> 0) & 0x00ff;
|
||||
|
||||
return 26;
|
||||
p = encode_data(p);
|
||||
|
||||
return (unsigned int)(p - data);
|
||||
// return 26;
|
||||
}
|
||||
|
||||
int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3)
|
||||
unsigned int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3)
|
||||
{
|
||||
memcpy(data, header, sizeof(header));
|
||||
data += sizeof(header);
|
||||
uint8_t *p = data;
|
||||
|
||||
data[0] = op;
|
||||
data[1] = arg;
|
||||
data[2] = (unit_id >> 8) & 0x00ff;
|
||||
data[3] = (unit_id >> 0) & 0x00ff;
|
||||
#if 0
|
||||
memcpy(p, header, sizeof(header));
|
||||
p += sizeof(header);
|
||||
#else
|
||||
memcpy(p + 7, header, sizeof(header));
|
||||
p += sizeof(header) - 7;
|
||||
#endif
|
||||
|
||||
data = encode_data(data);
|
||||
p[0] = op;
|
||||
p[1] = arg;
|
||||
p[2] = (unit_id >> 8) & 0x00ff;
|
||||
p[3] = (unit_id >> 0) & 0x00ff;
|
||||
|
||||
data[0] = b0;
|
||||
data[1] = b1;
|
||||
data[2] = b2;
|
||||
data[3] = b3;
|
||||
p = encode_data(p);
|
||||
|
||||
encode_data(data);
|
||||
p[0] = b0;
|
||||
p[1] = b1;
|
||||
p[2] = b2;
|
||||
p[3] = b3;
|
||||
|
||||
return 40;
|
||||
p = encode_data(p);
|
||||
|
||||
// return 40;
|
||||
return (unsigned int)(p - data);
|
||||
}
|
||||
/*
|
||||
void test(void)
|
||||
|
@ -28,7 +28,7 @@ enum mdc1200_op_code_e {
|
||||
MDC1200_OP_CODE_RADIO_CHECK = 0x63
|
||||
};
|
||||
|
||||
int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id);
|
||||
int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3);
|
||||
unsigned int MDC1200_encode_single_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id);
|
||||
unsigned int MDC1200_encode_double_packet(uint8_t *data, const uint8_t op, const uint8_t arg, const uint16_t unit_id, const uint8_t b0, const uint8_t b1, const uint8_t b2, const uint8_t b3);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user