0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-19 14:48:03 +03:00

AIRCOPY update

This commit is contained in:
OneOfEleven
2023-10-12 14:55:10 +01:00
parent 571c722f75
commit 17deb5a237
15 changed files with 167 additions and 131 deletions

View File

@ -27,95 +27,128 @@
#include "ui/inputbox.h"
#include "ui/ui.h"
static const uint16_t Obfuscation[8] = {0x6C16, 0xE614, 0x912E, 0x400D, 0x3521, 0x40D5, 0x0313, 0x80E9};
#define AIRCOPY_MAGIC_START 0xABCD
#define AIRCOPY_MAGIC_END 0xDCBA
const uint8_t g_air_copy_block_max = 120;
uint8_t g_air_copy_block_number;
uint8_t g_errors_during_air_copy;
#define AIRCOPY_LAST_EEPROM_ADDR 0x1E00
static const uint16_t Obfuscation[] = {
0x6C16, 0xE614, 0x912E, 0x400D, 0x3521, 0x40D5, 0x0313, 0x80E9
};
const uint8_t g_aircopy_block_max = 120;
uint8_t g_aircopy_block_number;
uint8_t g_aircopy_rx_errors;
aircopy_state_t g_aircopy_state;
uint16_t g_fsk_buffer[36];
uint16_t g_aircopy_fsk_buffer[36];
uint8_t g_aircopy_send_count_down_10ms;
unsigned int g_aircopy_fsk_write_index;
void AIRCOPY_SendMessage(void)
{
unsigned int i;
unsigned int i;
const uint16_t eeprom_addr = (uint16_t)g_aircopy_block_number * 64;
// *********
g_fsk_buffer[1] = (g_air_copy_block_number & 0x3FF) << 6;
// packet start
g_aircopy_fsk_buffer[0] = AIRCOPY_MAGIC_START;
EEPROM_ReadBuffer(g_fsk_buffer[1], &g_fsk_buffer[2], 64);
// eeprom address
g_aircopy_fsk_buffer[1] = eeprom_addr;
g_fsk_buffer[34] = CRC_Calculate(&g_fsk_buffer[1], 2 + 64);
// data
EEPROM_ReadBuffer(eeprom_addr, &g_aircopy_fsk_buffer[2], 64);
// data CRC
g_aircopy_fsk_buffer[34] = CRC_Calculate(&g_aircopy_fsk_buffer[1], 2 + 64);
// packet end
g_aircopy_fsk_buffer[35] = AIRCOPY_MAGIC_END;
// *********
// scramble the packet
for (i = 0; i < 34; i++)
g_fsk_buffer[i + 1] ^= Obfuscation[i % 8];
g_aircopy_fsk_buffer[1 + i] ^= Obfuscation[i % ARRAY_SIZE(Obfuscation)];
if (++g_air_copy_block_number >= g_air_copy_block_max)
RADIO_SetTxParameters();
BK4819_SendFSKData(g_aircopy_fsk_buffer);
BK4819_SetupPowerAmplifier(0, 0);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1, false);
if (++g_aircopy_block_number >= g_aircopy_block_max)
{
g_aircopy_state = AIRCOPY_TX_COMPLETE;
g_update_display = true;
}
RADIO_SetTxParameters();
BK4819_SendFSKData(g_fsk_buffer);
BK4819_SetupPowerAmplifier(0, 0);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1, false);
g_air_copy_send_count_down = 30;
// TX pause/gap time
#if 0
g_aircopy_send_count_down_10ms = 300 / 10; // 300ms
#else
g_aircopy_send_count_down_10ms = 30 / 10; // 30ms
#endif
}
void AIRCOPY_StorePacket(void)
{
uint16_t Status;
if (g_fsk_wite_index < 36)
if (g_aircopy_fsk_write_index < ARRAY_SIZE(g_aircopy_fsk_buffer))
return;
g_fsk_wite_index = 0;
g_update_display = true;
g_aircopy_fsk_write_index = 0;
g_update_display = true;
Status = BK4819_ReadRegister(BK4819_REG_0B);
BK4819_PrepareFSKReceive();
// Doc says bit 4 should be 1 = CRC OK, 0 = CRC FAIL, but original firmware checks for FAIL.
// Doc says bit 4 should be 1 = CRC OK, 0 = CRC FAIL, but original firmware checks for FAIL
if ((Status & 0x0010U) == 0 && g_fsk_buffer[0] == 0xABCD && g_fsk_buffer[35] == 0xDCBA)
if ((Status & (1u << 4)) == 0 && g_aircopy_fsk_buffer[0] == AIRCOPY_MAGIC_START && g_aircopy_fsk_buffer[35] == AIRCOPY_MAGIC_END)
{
uint16_t CRC;
unsigned int i;
for (i = 0; i < 34; i++)
g_fsk_buffer[i + 1] ^= Obfuscation[i % 8];
g_aircopy_fsk_buffer[1 + i] ^= Obfuscation[i % ARRAY_SIZE(Obfuscation)];
CRC = CRC_Calculate(&g_fsk_buffer[1], 2 + 64);
CRC = CRC_Calculate(&g_aircopy_fsk_buffer[1], 2 + 64);
if (g_fsk_buffer[34] == CRC)
if (g_aircopy_fsk_buffer[34] == CRC)
{
const uint16_t *pData;
uint16_t Offset = g_fsk_buffer[1];
if (Offset < 0x1E00)
uint16_t eeprom_addr = g_aircopy_fsk_buffer[1];
if (eeprom_addr < AIRCOPY_LAST_EEPROM_ADDR)
{
pData = &g_fsk_buffer[2];
const uint16_t *pData = &g_aircopy_fsk_buffer[2];
for (i = 0; i < 8; i++)
{
EEPROM_WriteBuffer(Offset, pData);
pData += 4;
Offset += 8;
EEPROM_WriteBuffer(eeprom_addr, pData);
pData += 4;
eeprom_addr += 8;
}
if (Offset == 0x1E00)
{
//g_aircopy_block_number++;
g_aircopy_block_number = eeprom_addr / 64;
if (eeprom_addr >= AIRCOPY_LAST_EEPROM_ADDR)
{ // reached end of eeprom config area
g_aircopy_state = AIRCOPY_RX_COMPLETE;
g_update_display = true;
}
g_air_copy_block_number++;
return;
}
}
}
g_errors_during_air_copy++;
g_aircopy_rx_errors++;
}
static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
@ -154,7 +187,7 @@ static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
// round the frequency to nearest step size
Frequency = ((Frequency + (g_rx_vfo->step_freq / 2)) / g_rx_vfo->step_freq) * g_rx_vfo->step_freq;
g_air_copy_freq = Frequency;
g_aircopy_freq = Frequency;
#ifdef ENABLE_AIRCOPY_FREQ
SETTINGS_SaveSettings(); // remeber the frequency for the next time
#endif
@ -188,14 +221,14 @@ static void AIRCOPY_Key_EXIT(bool key_pressed, bool key_held)
else
{ // enter RX mode
g_aircopy_state = AIRCOPY_RX;
g_update_display = true;
g_aircopy_state = AIRCOPY_RX;
g_update_display = true;
GUI_DisplayScreen();
g_fsk_wite_index = 0;
g_air_copy_block_number = 0;
g_errors_during_air_copy = 0;
g_input_box_index = 0;
g_aircopy_fsk_write_index = 0;
g_aircopy_block_number = 0;
g_aircopy_rx_errors = 0;
g_input_box_index = 0;
BK4819_PrepareFSKReceive();
}
@ -209,16 +242,17 @@ static void AIRCOPY_Key_MENU(bool key_pressed, bool key_held)
if (!key_held && key_pressed)
{ // enter TX mode
g_aircopy_state = AIRCOPY_TX;
g_update_display = true;
g_aircopy_state = AIRCOPY_TX;
g_update_display = true;
GUI_DisplayScreen();
g_fsk_wite_index = 0;
g_air_copy_block_number = 0;
g_input_box_index = 0;
g_fsk_buffer[0] = 0xABCD;
g_fsk_buffer[1] = 0;
g_fsk_buffer[35] = 0xDCBA;
g_input_box_index = 0;
g_aircopy_fsk_write_index = 0;
g_aircopy_block_number = 0;
g_aircopy_fsk_buffer[0] = AIRCOPY_MAGIC_START;
g_aircopy_fsk_buffer[1] = 0; // block number
g_aircopy_fsk_buffer[35] = AIRCOPY_MAGIC_END;
AIRCOPY_SendMessage();
}

View File

@ -17,8 +17,6 @@
#ifndef APP_AIRCOPY_H
#define APP_AIRCOPY_H
#ifdef ENABLE_AIRCOPY
#include "driver/keyboard.h"
enum aircopy_state_e
@ -31,17 +29,16 @@ enum aircopy_state_e
};
typedef enum aircopy_state_e aircopy_state_t;
extern const uint8_t g_air_copy_block_max;
extern uint8_t g_air_copy_block_number;
extern uint8_t g_errors_during_air_copy;
extern const uint8_t g_aircopy_block_max;
extern uint8_t g_aircopy_block_number;
extern uint8_t g_aircopy_rx_errors;
extern aircopy_state_t g_aircopy_state;
extern uint16_t g_fsk_buffer[36];
extern uint16_t g_aircopy_fsk_buffer[36];
extern uint8_t g_aircopy_send_count_down_10ms;
extern unsigned int g_aircopy_fsk_write_index;
void AIRCOPY_SendMessage(void);
void AIRCOPY_StorePacket(void);
void AIRCOPY_ProcessKeys(key_code_t Key, bool bKeyPressed, bool bKeyHeld);
void AIRCOPY_ProcessKeys(key_code_t key, bool key_pressed, bool key_held);
#endif
#endif

View File

@ -926,14 +926,15 @@ void APP_CheckRadioInterrupts(void)
}
#ifdef ENABLE_AIRCOPY
if (interrupt_status_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL &&
g_screen_to_display == DISPLAY_AIRCOPY &&
g_aircopy_state == AIRCOPY_RX)
if (interrupt_status_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL)
{
unsigned int i;
for (i = 0; i < 4; i++)
g_fsk_buffer[g_fsk_wite_index++] = BK4819_ReadRegister(BK4819_REG_5F);
AIRCOPY_StorePacket();
if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_RX)
{
unsigned int i;
for (i = 0; i < 4; i++)
g_aircopy_fsk_buffer[g_aircopy_fsk_write_index++] = BK4819_ReadRegister(BK4819_REG_5F);
AIRCOPY_StorePacket();
}
}
#endif
}
@ -1324,7 +1325,8 @@ void APP_CheckKeys(void)
key_code_t key;
#ifdef ENABLE_AIRCOPY
if (g_setting_killed || (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state != AIRCOPY_READY))
if (g_setting_killed ||
(g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state != AIRCOPY_READY))
return;
#else
if (g_setting_killed)
@ -1552,6 +1554,21 @@ void APP_TimeSlice10ms(void)
if (g_reduced_service)
return;
#ifdef ENABLE_AIRCOPY
if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_TX)
{
if (g_aircopy_send_count_down_10ms > 0)
{
if (--g_aircopy_send_count_down_10ms == 0)
{
AIRCOPY_SendMessage();
GUI_DisplayScreen();
}
}
}
#endif
#ifdef ENABLE_AM_FIX
// if (g_eeprom.vfo_info[g_eeprom.rx_vfo].am_mode && g_setting_am_fix)
if (g_rx_vfo->am_mode && g_setting_am_fix)
@ -1831,20 +1848,6 @@ void APP_TimeSlice10ms(void)
}
}
#ifdef ENABLE_AIRCOPY
if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_TX)
{
if (g_air_copy_send_count_down > 0)
{
if (--g_air_copy_send_count_down == 0)
{
AIRCOPY_SendMessage();
GUI_DisplayScreen();
}
}
}
#endif
APP_CheckKeys();
}