0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +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

@ -8,7 +8,7 @@ ENABLE_SWD := 0
ENABLE_OVERLAY := 0
ENABLE_LTO := 1
ENABLE_UART := 1
ENABLE_UART_DEBUG := 1
ENABLE_UART_DEBUG := 0
ENABLE_AIRCOPY := 1
ENABLE_AIRCOPY_FREQ := 1
ENABLE_FMRADIO := 1
@ -48,6 +48,14 @@ ENABLE_COPY_CHAN_TO_VFO := 1
TARGET = firmware
GIT_HASH_TMP := $(shell git rev-parse --short HEAD)
ifeq ($(GIT_HASH_TMP),)
GIT_HASH := "NOGIT"
else
GIT_HASH := $(GIT_HASH_TMP)
endif
$(info GIT_HASH = $(GIT_HASH))
ifeq ($(ENABLE_UART), 0)
ENABLE_UART_DEBUG := 0
endif
@ -195,13 +203,6 @@ endif
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
# the user might not have/want git installed
# can set own version string here (max 7 chars)
GIT_HASH := $(shell git rev-parse --short HEAD)
#GIT_HASH := 230930b
$(info GIT_HASH = $(GIT_HASH))
ASFLAGS = -c -mcpu=cortex-m0
ifeq ($(ENABLE_OVERLAY),1)
ASFLAGS += -DENABLE_OVERLAY

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;
const uint16_t eeprom_addr = (uint16_t)g_aircopy_block_number * 64;
g_fsk_buffer[1] = (g_air_copy_block_number & 0x3FF) << 6;
// *********
EEPROM_ReadBuffer(g_fsk_buffer[1], &g_fsk_buffer[2], 64);
// packet start
g_aircopy_fsk_buffer[0] = AIRCOPY_MAGIC_START;
g_fsk_buffer[34] = CRC_Calculate(&g_fsk_buffer[1], 2 + 64);
// eeprom address
g_aircopy_fsk_buffer[1] = eeprom_addr;
// 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_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);
EEPROM_WriteBuffer(eeprom_addr, pData);
pData += 4;
Offset += 8;
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
@ -192,9 +225,9 @@ static void AIRCOPY_Key_EXIT(bool key_pressed, bool key_held)
g_update_display = true;
GUI_DisplayScreen();
g_fsk_wite_index = 0;
g_air_copy_block_number = 0;
g_errors_during_air_copy = 0;
g_aircopy_fsk_write_index = 0;
g_aircopy_block_number = 0;
g_aircopy_rx_errors = 0;
g_input_box_index = 0;
BK4819_PrepareFSKReceive();
@ -213,12 +246,13 @@ static void AIRCOPY_Key_MENU(bool key_pressed, bool key_held)
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_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,15 +926,16 @@ 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)
{
if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_RX)
{
unsigned int i;
for (i = 0; i < 4; i++)
g_fsk_buffer[g_fsk_wite_index++] = BK4819_ReadRegister(BK4819_REG_5F);
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();
}

View File

@ -634,7 +634,7 @@ void BOARD_EEPROM_load(void)
{
if (array.air_copy_freq >= FREQ_BAND_TABLE[i].lower && array.air_copy_freq < FREQ_BAND_TABLE[i].upper)
{
g_air_copy_freq = array.air_copy_freq;
g_aircopy_freq = array.air_copy_freq;
break;
}
}

Binary file not shown.

Binary file not shown.

View File

@ -19,7 +19,7 @@
#include "settings.h"
// the initial AIRCOPY frequency to use
uint32_t g_air_copy_freq = 41002500;
uint32_t g_aircopy_freq = 41002500;
// the BK4819 has 2 bands it covers, 18MHz ~ 630MHz and 760MHz ~ 1300MHz
const freq_band_table_t BX4819_band1 = { 1800000, 63000000};

View File

@ -26,7 +26,7 @@ typedef struct {
const uint32_t upper;
} freq_band_table_t;
extern uint32_t g_air_copy_freq;
extern uint32_t g_aircopy_freq;
extern const freq_band_table_t BX4819_band1;
extern const freq_band_table_t BX4819_band2;

View File

@ -80,7 +80,7 @@ void BOOT_ProcessMode(boot_mode_t Mode)
g_eeprom.key2_short_press_action = ACTION_OPT_NONE;
g_eeprom.key2_long_press_action = ACTION_OPT_NONE;
RADIO_InitInfo(g_rx_vfo, FREQ_CHANNEL_LAST - 1, g_air_copy_freq);
RADIO_InitInfo(g_rx_vfo, FREQ_CHANNEL_LAST - 1, g_aircopy_freq);
g_rx_vfo->channel_bandwidth = BANDWIDTH_WIDE;
g_rx_vfo->output_power = OUTPUT_POWER_LOW;

4
misc.c
View File

@ -227,10 +227,6 @@ bool g_rx_vfo_is_active;
uint8_t g_menu_list_count;
uint8_t g_backup_cross_vfo_rx_tx;
uint8_t g_scan_delay_10ms;
#ifdef ENABLE_AIRCOPY
uint8_t g_air_copy_send_count_down;
#endif
uint8_t g_fsk_wite_index;
#ifdef ENABLE_NOAA
bool g_is_noaa_mode;

4
misc.h
View File

@ -302,10 +302,6 @@ extern uint16_t g_alarm_running_counter;
extern uint8_t g_menu_list_count;
extern uint8_t g_backup_cross_vfo_rx_tx;
extern uint8_t g_scan_delay_10ms;
#ifdef ENABLE_AIRCOPY
extern uint8_t g_air_copy_send_count_down;
#endif
extern uint8_t g_fsk_wite_index;
#ifdef ENABLE_NOAA
extern bool g_is_noaa_mode;
extern uint8_t g_noaa_channel;

View File

@ -275,7 +275,7 @@ void SETTINGS_SaveSettings(void)
array.tx_vfo = g_eeprom.tx_vfo;
#ifdef ENABLE_AIRCOPY_FREQ
// remember the AIRCOPY frequency
array.air_copy_freq = g_air_copy_freq;
array.air_copy_freq = g_aircopy_freq;
#endif
EEPROM_WriteBuffer(0x0EA8, &array);

View File

@ -27,37 +27,42 @@
void UI_DisplayAircopy(void)
{
char String[16];
char str[17];
// clear screen/display buffer
memset(g_frame_buffer, 0, sizeof(g_frame_buffer));
// **********************************
// upper text line
strcpy(String, "AIR COPY");
strcpy(str, "AIR COPY");
switch (g_aircopy_state)
{
case AIRCOPY_READY: strcat(String, " READY"); break;
case AIRCOPY_RX: strcat(String, " RX"); break;
case AIRCOPY_TX: strcat(String, " TX"); break;
case AIRCOPY_RX_COMPLETE: strcat(String, " DONE"); break;
case AIRCOPY_TX_COMPLETE: strcat(String, " DONE"); break;
default: strcat(String, " ???"); break;
case AIRCOPY_READY: strcat(str, " READY"); break;
case AIRCOPY_RX: strcat(str, " RX"); break;
case AIRCOPY_TX: strcat(str, " TX"); break;
case AIRCOPY_RX_COMPLETE: strcat(str, " DONE"); break;
case AIRCOPY_TX_COMPLETE: strcat(str, " DONE"); break;
default: strcat(str, " ERR"); break;
}
UI_PrintString(String, 0, LCD_WIDTH - 1, 0, 8);
UI_PrintString(str, 0, LCD_WIDTH - 1, 0, 8);
// **********************************
// center frequency text line
if (g_input_box_index == 0)
{
NUMBER_ToDigits(g_rx_vfo->freq_config_rx.frequency, String);
UI_DisplayFrequency(String, 16, 2, 0, 0);
UI_Displaysmall_digits(2, String + 6, 97, 3, true);
{ // show frequency
NUMBER_ToDigits(g_rx_vfo->freq_config_rx.frequency, str);
UI_DisplayFrequency(str, 16, 2, 0, 0);
UI_Displaysmall_digits(2, str + 6, 97, 3, true);
}
else
{ // user is entering a new frequency
UI_DisplayFrequency(g_input_box, 16, 2, 1, 0);
}
// **********************************
// lower TX/RX status text line
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough="
@ -69,17 +74,17 @@ void UI_DisplayAircopy(void)
break;
case AIRCOPY_RX_COMPLETE:
if (g_errors_during_air_copy == 0)
if (g_aircopy_rx_errors == 0)
{
UI_PrintString("RX COMPLETE", 0, LCD_WIDTH - 1, 5, 8);
break;
}
case AIRCOPY_RX:
sprintf(String, "RX %u.%u", g_air_copy_block_number, g_air_copy_block_max);
if (g_errors_during_air_copy > 0)
sprintf(String + strlen(String), " E %u", g_errors_during_air_copy);
UI_PrintString(String, 0, LCD_WIDTH - 1, 5, 7);
sprintf(str, "RX %u.%u", g_aircopy_block_number, g_aircopy_block_max);
if (g_aircopy_rx_errors > 0)
sprintf(str + strlen(str), " E %u", g_aircopy_rx_errors);
UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7);
break;
case AIRCOPY_TX_COMPLETE:
@ -87,13 +92,13 @@ void UI_DisplayAircopy(void)
break;
case AIRCOPY_TX:
sprintf(String, "TX %u.%u", g_air_copy_block_number, g_air_copy_block_max);
UI_PrintString(String, 0, LCD_WIDTH - 1, 5, 7);
sprintf(str, "TX %u.%u", g_aircopy_block_number, g_aircopy_block_max);
UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7);
break;
default:
strcpy(String, " ???");
UI_PrintString(String, 0, LCD_WIDTH - 1, 5, 7);
strcpy(str, "ERROR");
UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7);
break;
}

View File

@ -85,7 +85,11 @@ center_line_t center_line = CENTER_LINE_NONE;
memset(p_line, 0, LCD_WIDTH);
sprintf(s, "TX %u", secs);
UI_PrintStringSmallBold(s, 2, 0, line); // issue UI_PrintStringSmallBold //UI_PrintStringSmall(s, 2, 0, line);
#ifdef ENABLE_SMALL_BOLD
UI_PrintStringSmallBold(s, 2, 0, line);
#else
UI_PrintStringSmall(s, 2, 0, line);
#endif
#if 1
// solid bar