0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +03:00

Updated AIRCOPY + fixed F+4 save to VFO

This commit is contained in:
OneOfEleven 2023-10-12 22:48:48 +01:00
parent d1c9d184d0
commit 55ceb92a61
13 changed files with 452 additions and 176 deletions

View File

@ -14,11 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
#include <string.h>
#include "app/aircopy.h" #include "app/aircopy.h"
#include "audio.h" #include "audio.h"
#include "driver/bk4819.h" #include "driver/bk4819.h"
#include "driver/crc.h" #include "driver/crc.h"
#include "driver/eeprom.h" #include "driver/eeprom.h"
#include "driver/system.h"
#include "frequencies.h" #include "frequencies.h"
#include "misc.h" #include "misc.h"
#include "radio.h" #include "radio.h"
@ -32,19 +35,18 @@
#define AIRCOPY_LAST_EEPROM_ADDR 0x1E00 #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; const uint8_t g_aircopy_block_max = 120;
uint8_t g_aircopy_block_number; uint8_t g_aircopy_block_number;
uint8_t g_aircopy_rx_errors; uint8_t g_aircopy_rx_errors;
aircopy_state_t g_aircopy_state; aircopy_state_t g_aircopy_state;
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(const uint8_t request_packet) uint8_t aircopy_send_count_down_10ms;
uint16_t g_fsk_buffer[36];
unsigned int g_fsk_write_index;
uint16_t g_fsk_tx_timeout_10ms;
void AIRCOPY_start_FSK_tx(const uint8_t request_packet)
{ {
unsigned int i; unsigned int i;
const uint16_t eeprom_addr = (uint16_t)g_aircopy_block_number * 64; const uint16_t eeprom_addr = (uint16_t)g_aircopy_block_number * 64;
@ -55,55 +57,165 @@ void AIRCOPY_SendMessage(const uint8_t request_packet)
// ********* // *********
// packet start // packet start
g_aircopy_fsk_buffer[0] = AIRCOPY_MAGIC_START; g_fsk_buffer[0] = AIRCOPY_MAGIC_START;
// eeprom address // eeprom address
g_aircopy_fsk_buffer[1] = eeprom_addr; g_fsk_buffer[1] = eeprom_addr;
// data // data
EEPROM_ReadBuffer(eeprom_addr, &g_aircopy_fsk_buffer[2], 64); EEPROM_ReadBuffer(eeprom_addr, &g_fsk_buffer[2], 64);
// data CRC // data CRC
g_aircopy_fsk_buffer[34] = CRC_Calculate(&g_aircopy_fsk_buffer[1], 2 + 64); g_fsk_buffer[34] = CRC_Calculate(&g_fsk_buffer[1], 2 + 64);
// packet end // packet end
g_aircopy_fsk_buffer[35] = AIRCOPY_MAGIC_END; g_fsk_buffer[35] = AIRCOPY_MAGIC_END;
// ********* // *********
// scramble the packet { // scramble the packet
for (i = 0; i < 34; i++) //for (i = 0; i < 34; i++)
g_aircopy_fsk_buffer[1 + i] ^= Obfuscation[i % ARRAY_SIZE(Obfuscation)]; //g_fsk_buffer[1 + i] ^= Obfuscation[i % ARRAY_SIZE(Obfuscation)];
uint8_t *p = (uint8_t *)&g_fsk_buffer[1];
for (i = 0; i < (34 * 2); i++)
*p++ ^= obfuscate_array[i % ARRAY_SIZE(obfuscate_array)];
}
// TX the packet // TX the packet
RADIO_SetTxParameters(); RADIO_SetTxParameters();
BK4819_SetupPowerAmplifier(0, g_current_vfo->pTX->frequency); // VERY low TX power BK4819_SetupPowerAmplifier(0, g_current_vfo->pTX->frequency); // VERY low TX power
BK4819_SendFSKData(g_aircopy_fsk_buffer);
// turn the RED LED on
BK4819_set_GPIO_pin(BK4819_GPIO1_PIN29_RED, true);
// start sending the packet
// let the TX stabilize
SYSTEM_DelayMs(10);
BK4819_WriteRegister(BK4819_REG_3F, BK4819_REG_3F_FSK_TX_FINISHED);
BK4819_WriteRegister(BK4819_REG_59, 0x8068);
BK4819_WriteRegister(BK4819_REG_59, 0x0068);
// load the packet
for (i = 0; i < 36; i++)
BK4819_WriteRegister(BK4819_REG_5F, g_fsk_buffer[i]);
// SYSTEM_DelayMs(20);
BK4819_WriteRegister(BK4819_REG_59, 0x2868);
g_fsk_tx_timeout_10ms = 1000 / 10; // 1 second timeout
}
void AIRCOPY_stop_FSK_tx(void)
{
if (g_aircopy_state != AIRCOPY_TX && g_fsk_tx_timeout_10ms == 0)
return;
g_fsk_tx_timeout_10ms = 0;
BK4819_WriteRegister(BK4819_REG_02, 0); // disable all interrupts
// SYSTEM_DelayMs(20);
BK4819_ResetFSK();
// disable the TX
BK4819_SetupPowerAmplifier(0, 0); BK4819_SetupPowerAmplifier(0, 0);
BK4819_set_GPIO_pin(BK4819_GPIO5_PIN1, false); BK4819_set_GPIO_pin(BK4819_GPIO5_PIN1, false);
// turn the RED LED off
BK4819_set_GPIO_pin(BK4819_GPIO1_PIN29_RED, false);
if (++g_aircopy_block_number >= g_aircopy_block_max) if (++g_aircopy_block_number >= g_aircopy_block_max)
{ { // transfer is complete
g_aircopy_state = AIRCOPY_TX_COMPLETE; g_aircopy_state = AIRCOPY_TX_COMPLETE;
g_update_display = true; }
else
{
// TX pause/gap time till we start the next packet
#if 0
aircopy_send_count_down_10ms = 300 / 10; // 300ms
#else
aircopy_send_count_down_10ms = 10 / 10; // 10ms
#endif
} }
// TX pause/gap time g_update_display = true;
#if 0 GUI_DisplayScreen();
g_aircopy_send_count_down_10ms = 300 / 10; // 300ms
#else
g_aircopy_send_count_down_10ms = 30 / 10; // 30ms
#endif
} }
void AIRCOPY_StorePacket(void) void AIRCOPY_process_FSK_tx_10ms(void)
{ {
uint16_t Status; if (g_aircopy_state != AIRCOPY_TX)
if (g_aircopy_fsk_write_index < ARRAY_SIZE(g_aircopy_fsk_buffer))
return; return;
g_aircopy_fsk_write_index = 0; if (g_fsk_tx_timeout_10ms == 0)
{ // not currently TX'ing
if (g_aircopy_block_number < g_aircopy_block_max)
{ // not yet finished the complete transfer
if (aircopy_send_count_down_10ms > 0)
{ // waiting till it's time to TX next packet
if (--aircopy_send_count_down_10ms == 0)
{ // start next packet
AIRCOPY_start_FSK_tx(0xff);
g_update_display = true;
GUI_DisplayScreen();
}
}
}
return;
}
if (--g_fsk_tx_timeout_10ms > 0)
{ // still TX'ing
if ((BK4819_ReadRegister(BK4819_REG_0C) & (1u << 0)) == 0)
return; /// TX not yet finished
}
AIRCOPY_stop_FSK_tx();
}
void AIRCOPY_process_FSK_rx_10ms(const uint16_t interrupt_status_bits)
{
unsigned int i;
uint16_t Status;
if (g_aircopy_state != AIRCOPY_RX)
return;
if (interrupt_status_bits & BK4819_REG_02_FSK_RX_SYNC)
{
// turn the green LED on
// BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, true);
}
if (interrupt_status_bits & BK4819_REG_02_FSK_RX_FINISHED)
{
// turn the green LED off
// BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, false);
}
if (interrupt_status_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL)
{
for (i = 0; i < 4; i++)
g_fsk_buffer[g_fsk_write_index++] = BK4819_ReadRegister(BK4819_REG_5F);
if (g_fsk_write_index < ARRAY_SIZE(g_fsk_buffer))
{
// turn the green LED on
BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, true);
return;
}
// turn the green LED off
BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, false);
g_fsk_write_index = 0;
g_update_display = true; g_update_display = true;
Status = BK4819_ReadRegister(BK4819_REG_0B); Status = BK4819_ReadRegister(BK4819_REG_0B);
@ -112,51 +224,96 @@ void AIRCOPY_StorePacket(void)
// 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 & (1u << 4)) == 0 && g_aircopy_fsk_buffer[0] == AIRCOPY_MAGIC_START && g_aircopy_fsk_buffer[35] == AIRCOPY_MAGIC_END) if ((Status & (1u << 4)) == 0 &&
g_fsk_buffer[0] == AIRCOPY_MAGIC_START &&
g_fsk_buffer[35] == AIRCOPY_MAGIC_END)
{ {
uint16_t CRC;
unsigned int i; unsigned int i;
uint16_t CRC;
for (i = 0; i < 34; i++) { // unscramble the packet
g_aircopy_fsk_buffer[1 + i] ^= Obfuscation[i % ARRAY_SIZE(Obfuscation)]; uint8_t *p = (uint8_t *)&g_fsk_buffer[1];
for (i = 0; i < (34 * 2); i++)
*p++ ^= obfuscate_array[i % ARRAY_SIZE(obfuscate_array)];
}
CRC = CRC_Calculate(&g_aircopy_fsk_buffer[1], 2 + 64); CRC = CRC_Calculate(&g_fsk_buffer[1], 2 + 64);
if (g_aircopy_fsk_buffer[34] == CRC) if (g_fsk_buffer[34] == CRC)
{ { // CRC is valid
uint16_t eeprom_addr = g_aircopy_fsk_buffer[1]; uint16_t eeprom_addr = g_fsk_buffer[1];
if (eeprom_addr < AIRCOPY_LAST_EEPROM_ADDR) if (eeprom_addr == 0)
{ { // start again
const uint16_t *pData = &g_aircopy_fsk_buffer[2]; g_aircopy_block_number = 0;
g_aircopy_rx_errors = 0;
}
if ((eeprom_addr + 64) <= AIRCOPY_LAST_EEPROM_ADDR)
{ // eeprom block is valid .. write it directly to eeprom
uint16_t *pData = &g_fsk_buffer[2];
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
EEPROM_WriteBuffer(eeprom_addr, pData); if (eeprom_addr == 0x0E98)
{ // power-on password .. wipe it
#ifndef ENABLE_PWRON_PASSWORD
pData[0] = 0xffff;
pData[1] = 0xffff;
#endif
}
else
if (eeprom_addr == 0x0F30)
{ // AES key .. wipe it
#ifdef ENABLE_RESET_AES_KEY
pData[0] = 0xffff;
pData[1] = 0xffff;
pData[2] = 0xffff;
pData[3] = 0xffff;
#endif
}
EEPROM_WriteBuffer(eeprom_addr, pData); // 8 bytes at a time
pData += 4; pData += 4;
eeprom_addr += 8; eeprom_addr += 8;
} }
//g_aircopy_block_number++;
g_aircopy_block_number = eeprom_addr / 64; g_aircopy_block_number = eeprom_addr / 64;
if (eeprom_addr >= AIRCOPY_LAST_EEPROM_ADDR) if (eeprom_addr >= AIRCOPY_LAST_EEPROM_ADDR)
{ // reached end of eeprom config area { // reached end of eeprom config area
g_aircopy_state = AIRCOPY_RX_COMPLETE; g_aircopy_state = AIRCOPY_RX_COMPLETE;
// turn the green LED off
BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, false);
g_update_display = true; g_update_display = true;
} }
memset(g_fsk_buffer, 0, sizeof(g_fsk_buffer));
return; return;
} }
} }
} }
g_aircopy_rx_errors++; g_aircopy_rx_errors++;
}
} }
static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
{ {
if (g_aircopy_state == AIRCOPY_RX || g_aircopy_state == AIRCOPY_TX)
return;
if (g_aircopy_state != AIRCOPY_READY)
{
AIRCOPY_stop_FSK_tx();
g_aircopy_state = AIRCOPY_READY;
g_update_display = true;
GUI_DisplayScreen();
}
if (!key_held && key_pressed) if (!key_held && key_pressed)
{ {
uint32_t Frequency; uint32_t Frequency;
@ -216,35 +373,72 @@ static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
static void AIRCOPY_Key_EXIT(bool key_pressed, bool key_held) static void AIRCOPY_Key_EXIT(bool key_pressed, bool key_held)
{ {
if (!key_held && key_pressed) if (!key_pressed)
return;
if (g_aircopy_state != AIRCOPY_READY)
{ {
if (!key_held)
{
// turn the green LED off
BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, false);
AIRCOPY_stop_FSK_tx();
g_input_box_index = 0;
g_aircopy_state = AIRCOPY_READY;
g_update_display = true;
GUI_DisplayScreen();
}
}
else
if (key_held)
{
if (g_input_box_index > 0)
{ // cancel the frequency input
g_input_box_index = 0;
g_update_display = true;
GUI_DisplayScreen();
}
}
else
if (g_input_box_index > 0) if (g_input_box_index > 0)
{ // entering a new frequency to use { // entering a new frequency to use
g_input_box[--g_input_box_index] = 10; g_input_box[--g_input_box_index] = 10;
GUI_DisplayScreen();
} }
else else
{ // enter RX mode { // enter RX mode
// turn the green LED off
BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, false);
g_input_box_index = 0;
g_aircopy_state = AIRCOPY_RX; g_aircopy_state = AIRCOPY_RX;
g_update_display = true; g_update_display = true;
GUI_DisplayScreen(); GUI_DisplayScreen();
g_aircopy_fsk_write_index = 0; g_fsk_write_index = 0;
g_aircopy_block_number = 0; g_aircopy_block_number = 0;
g_aircopy_rx_errors = 0; g_aircopy_rx_errors = 0;
g_input_box_index = 0; memset(g_fsk_buffer, 0, sizeof(g_fsk_buffer));
BK4819_PrepareFSKReceive(); BK4819_PrepareFSKReceive();
} }
g_request_display_screen = DISPLAY_AIRCOPY;
}
} }
static void AIRCOPY_Key_MENU(bool key_pressed, bool key_held) static void AIRCOPY_Key_MENU(bool key_pressed, bool key_held)
{ {
if (!key_held && key_pressed) (void)key_held;
{ // enter TX mode
if (g_aircopy_state == AIRCOPY_RX || g_aircopy_state == AIRCOPY_TX)
return; // busy
if (key_pressed && !key_held)
{ // key released
// enter TX mode
g_input_box_index = 0;
g_aircopy_state = AIRCOPY_TX; g_aircopy_state = AIRCOPY_TX;
g_update_display = true; g_update_display = true;
@ -252,13 +446,12 @@ static void AIRCOPY_Key_MENU(bool key_pressed, bool key_held)
g_input_box_index = 0; g_input_box_index = 0;
g_aircopy_fsk_write_index = 0; g_fsk_write_index = 0;
g_aircopy_block_number = 0; g_aircopy_block_number = 0;
g_aircopy_rx_errors = 0;
// send initial packet g_fsk_tx_timeout_10ms = 0;
//AIRCOPY_SendMessage(0xff); aircopy_send_count_down_10ms = 30 / 10; // 30ms
g_aircopy_send_count_down_10ms = 30 / 10; // 30ms
} }
} }

View File

@ -33,12 +33,13 @@ extern const uint8_t g_aircopy_block_max;
extern uint8_t g_aircopy_block_number; extern uint8_t g_aircopy_block_number;
extern uint8_t g_aircopy_rx_errors; extern uint8_t g_aircopy_rx_errors;
extern aircopy_state_t g_aircopy_state; extern aircopy_state_t g_aircopy_state;
extern uint16_t g_aircopy_fsk_buffer[36]; extern uint16_t g_fsk_buffer[36];
extern uint8_t g_aircopy_send_count_down_10ms; extern unsigned int g_fsk_write_index;
extern unsigned int g_aircopy_fsk_write_index; extern uint16_t g_fsk_tx_timeout_10ms;
void AIRCOPY_SendMessage(const uint8_t request_packet); void AIRCOPY_process_FSK_tx_10ms(void);
void AIRCOPY_StorePacket(void); void AIRCOPY_process_FSK_rx_10ms(const uint16_t interrupt_status_bits);
void AIRCOPY_stop_FSK_tx(void);
void AIRCOPY_ProcessKeys(key_code_t key, bool key_pressed, bool key_held); void AIRCOPY_ProcessKeys(key_code_t key, bool key_pressed, bool key_held);
#endif #endif

View File

@ -916,25 +916,22 @@ void APP_CheckRadioInterrupts(void)
if (interrupt_status_bits & BK4819_REG_02_SQUELCH_LOST) if (interrupt_status_bits & BK4819_REG_02_SQUELCH_LOST)
{ {
g_squelch_lost = true; g_squelch_lost = true;
// turn the LED off
BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, true); BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, true);
} }
if (interrupt_status_bits & BK4819_REG_02_SQUELCH_FOUND) if (interrupt_status_bits & BK4819_REG_02_SQUELCH_FOUND)
{ {
g_squelch_lost = false; g_squelch_lost = false;
// turn the LED on
BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, false); BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_GREEN, false);
} }
#ifdef ENABLE_AIRCOPY #ifdef ENABLE_AIRCOPY
if (interrupt_status_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL) if (g_screen_to_display == DISPLAY_AIRCOPY)
{ {
if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_RX) AIRCOPY_process_FSK_rx_10ms(interrupt_status_bits);
{ // AIRCOPY_process_FSK_tx_10ms(interrupt_status_bits);
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 #endif
} }
@ -1324,13 +1321,15 @@ void APP_CheckKeys(void)
key_code_t key; key_code_t key;
#ifdef ENABLE_AIRCOPY
if (g_setting_killed ||
(g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state != AIRCOPY_READY))
return;
#else
if (g_setting_killed) if (g_setting_killed)
return; return;
#ifdef ENABLE_AIRCOPY
if (g_screen_to_display == DISPLAY_AIRCOPY &&
(g_aircopy_state == AIRCOPY_RX || g_aircopy_state == AIRCOPY_TX))
{ // AIRCOPY is busy RX/TX or we've been killed
// return;
}
#endif #endif
// ***************** // *****************
@ -1338,7 +1337,11 @@ void APP_CheckKeys(void)
if (ptt_pressed) if (ptt_pressed)
{ // PTT pressed { // PTT pressed
if (!g_ptt_is_pressed) #ifdef ENABLE_AIRCOPY
if (!g_setting_killed && !g_ptt_is_pressed && g_screen_to_display != DISPLAY_AIRCOPY)
#else
if (!g_setting_killed && !g_ptt_is_pressed)
#endif
{ {
if (++g_ptt_debounce >= 3) // 30ms if (++g_ptt_debounce >= 3) // 30ms
{ // start TX'ing { // start TX'ing
@ -1411,7 +1414,15 @@ void APP_CheckKeys(void)
UART_printf(" old key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held); UART_printf(" old key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held);
#endif #endif
#ifdef ENABLE_AIRCOPY
if (g_screen_to_display != DISPLAY_AIRCOPY)
APP_ProcessKey(g_key_prev, false, g_key_held); APP_ProcessKey(g_key_prev, false, g_key_held);
else
AIRCOPY_ProcessKeys(g_key_prev, false, g_key_held);
#else
APP_ProcessKey(g_key_prev, false, g_key_held);
#endif
g_key_debounce_press = 0; g_key_debounce_press = 0;
g_key_debounce_repeat = 0; g_key_debounce_repeat = 0;
g_key_prev = KEY_INVALID; g_key_prev = KEY_INVALID;
@ -1443,7 +1454,14 @@ void APP_CheckKeys(void)
g_key_prev = key; g_key_prev = key;
#ifdef ENABLE_AIRCOPY
if (g_screen_to_display != DISPLAY_AIRCOPY)
APP_ProcessKey(g_key_prev, true, g_key_held); APP_ProcessKey(g_key_prev, true, g_key_held);
else
AIRCOPY_ProcessKeys(g_key_prev, true, g_key_held);
#else
APP_ProcessKey(g_key_prev, true, g_key_held);
#endif
g_update_status = true; g_update_status = true;
g_update_display = true; g_update_display = true;
@ -1461,7 +1479,14 @@ void APP_CheckKeys(void)
UART_printf("long key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held); UART_printf("long key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held);
#endif #endif
#ifdef ENABLE_AIRCOPY
if (g_screen_to_display != DISPLAY_AIRCOPY)
APP_ProcessKey(g_key_prev, true, g_key_held); APP_ProcessKey(g_key_prev, true, g_key_held);
else
AIRCOPY_ProcessKeys(g_key_prev, true, g_key_held);
#else
APP_ProcessKey(g_key_prev, true, g_key_held);
#endif
//g_update_status = true; //g_update_status = true;
//g_update_display = true; //g_update_display = true;
@ -1478,7 +1503,14 @@ void APP_CheckKeys(void)
UART_printf("rept key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held); UART_printf("rept key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held);
#endif #endif
#ifdef ENABLE_AIRCOPY
if (g_screen_to_display != DISPLAY_AIRCOPY)
APP_ProcessKey(g_key_prev, true, g_key_held); APP_ProcessKey(g_key_prev, true, g_key_held);
else
AIRCOPY_ProcessKeys(g_key_prev, true, g_key_held);
#else
APP_ProcessKey(g_key_prev, true, g_key_held);
#endif
//g_update_status = true; //g_update_status = true;
//g_update_display = true; //g_update_display = true;
@ -1554,18 +1586,30 @@ void APP_TimeSlice10ms(void)
if (g_reduced_service) if (g_reduced_service)
return; return;
#ifdef ENABLE_AIRCOPY #ifdef ENABLE_AIRCOPY
if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_TX) if (g_screen_to_display == DISPLAY_AIRCOPY)
{ {
if (g_aircopy_send_count_down_10ms > 0) APP_CheckRadioInterrupts();
{
if (--g_aircopy_send_count_down_10ms == 0) if (g_aircopy_state == AIRCOPY_RX)
{ { // we're RX'ing
AIRCOPY_SendMessage(0xff); //AIRCOPY_process_FSK_rx_10ms(0);
}
else
if (g_aircopy_state == AIRCOPY_TX)
{ // we're TX'ing
AIRCOPY_process_FSK_tx_10ms();
}
APP_CheckKeys();
if (g_update_display)
GUI_DisplayScreen(); GUI_DisplayScreen();
}
} if (g_update_status)
UI_DisplayStatus(false);
return;
} }
#endif #endif

View File

@ -258,7 +258,7 @@ static void SCANNER_Key_MENU(bool key_pressed, bool key_held)
} }
else else
{ {
#if 0 #if 1
// save the VFO // save the VFO
g_scanner_edit_state = SCAN_EDIT_STATE_DONE; g_scanner_edit_state = SCAN_EDIT_STATE_DONE;
#else #else

View File

@ -155,10 +155,6 @@ static union
} __attribute__((packed)); } __attribute__((packed));
} __attribute__((packed)) UART_Command; } __attribute__((packed)) UART_Command;
static const uint8_t Obfuscation[16] = {
0x16, 0x6C, 0x14, 0xE6, 0x2E, 0x91, 0x0D, 0x40, 0x21, 0x35, 0xD5, 0x40, 0x13, 0x03, 0xE9, 0x80
};
uint32_t time_stamp = 0; uint32_t time_stamp = 0;
uint16_t write_index = 0; uint16_t write_index = 0;
bool is_encrypted = true; bool is_encrypted = true;
@ -180,7 +176,7 @@ static void SendReply(void *preply, uint16_t Size)
uint8_t *pBytes = (uint8_t *)preply; uint8_t *pBytes = (uint8_t *)preply;
unsigned int i; unsigned int i;
for (i = 0; i < Size; i++) for (i = 0; i < Size; i++)
pBytes[i] ^= Obfuscation[i % 16]; pBytes[i] ^= obfuscate_array[i % 16];
} }
Header.ID = 0xCDAB; Header.ID = 0xCDAB;
@ -190,8 +186,8 @@ static void SendReply(void *preply, uint16_t Size)
if (is_encrypted) if (is_encrypted)
{ {
Footer.pad[0] = Obfuscation[(Size + 0) % 16] ^ 0xFF; Footer.pad[0] = obfuscate_array[(Size + 0) % 16] ^ 0xFF;
Footer.pad[1] = Obfuscation[(Size + 1) % 16] ^ 0xFF; Footer.pad[1] = obfuscate_array[(Size + 1) % 16] ^ 0xFF;
} }
else else
{ {
@ -565,7 +561,7 @@ bool UART_IsCommandAvailable(void)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < (Size + 2u); i++) for (i = 0; i < (Size + 2u); i++)
UART_Command.Buffer[i] ^= Obfuscation[i % 16]; UART_Command.Buffer[i] ^= obfuscate_array[i % 16];
} }
CRC = UART_Command.Buffer[Size] | (UART_Command.Buffer[Size + 1] << 8); CRC = UART_Command.Buffer[Size] | (UART_Command.Buffer[Size + 1] << 8);

View File

@ -1083,10 +1083,18 @@ void BK4819_TurnsOffTones_TurnsOnRX(void)
{ {
BK4819_WriteRegister(BK4819_REG_70, 0x00E0); // Enable Tone2, tuning gain 48 BK4819_WriteRegister(BK4819_REG_70, 0x00E0); // Enable Tone2, tuning gain 48
BK4819_WriteRegister(BK4819_REG_72, 0x3065); // Tone2 baudrate 1200 BK4819_WriteRegister(BK4819_REG_72, 0x3065); // Tone2 baudrate 1200
BK4819_WriteRegister(BK4819_REG_58, 0x00C1); // FSK Enable, FSK 1.2K RX Bandwidth, Preamble 0xAA or 0x55, RX Gain 0, RX Mode
// (FSK1.2K, FSK2.4K Rx and NOAA SAME Rx), TX Mode FSK 1.2K and FSK 2.4K Tx BK4819_WriteRegister(BK4819_REG_58, 0x00C1); // FSK Enable
// FSK 1.2K RX Bandwidth
// Preamble 0xAA or 0x55
// RX Gain 0
// RX Mode
// (FSK1.2K, FSK2.4K Rx and NOAA SAME Rx)
// TX Mode FSK 1.2K
// FSK 2.4K Tx
BK4819_WriteRegister(BK4819_REG_5C, 0x5665); // Enable CRC among other things we don't know yet BK4819_WriteRegister(BK4819_REG_5C, 0x5665); // Enable CRC among other things we don't know yet
BK4819_WriteRegister(BK4819_REG_5D, 0x4700); // FSK Data Length 72 Bytes (0xabcd + 2 byte length + 64 byte payload + 2 byte CRC + 0xdcba) BK4819_WriteRegister(BK4819_REG_5D, 0x4700); // FSK Data Length 72 Bytes (0xABCD + 2 byte length + 64 byte payload + 2 byte CRC + 0xDCBA)
} }
#endif #endif
@ -1689,11 +1697,11 @@ uint8_t BK4819_GetCTCType(void)
{ {
return (BK4819_ReadRegister(BK4819_REG_0C) >> 10) & 3u; return (BK4819_ReadRegister(BK4819_REG_0C) >> 10) & 3u;
} }
/*
void BK4819_SendFSKData(uint16_t *pData) void BK4819_SendFSKData(uint16_t *pData)
{ {
unsigned int i; unsigned int i;
uint8_t Timeout = 200; uint8_t Timeout = 1000 / 5; // 1 second
SYSTEM_DelayMs(20); SYSTEM_DelayMs(20);
@ -1701,30 +1709,37 @@ void BK4819_SendFSKData(uint16_t *pData)
BK4819_WriteRegister(BK4819_REG_59, 0x8068); BK4819_WriteRegister(BK4819_REG_59, 0x8068);
BK4819_WriteRegister(BK4819_REG_59, 0x0068); BK4819_WriteRegister(BK4819_REG_59, 0x0068);
// load the packet
for (i = 0; i < 36; i++) for (i = 0; i < 36; i++)
BK4819_WriteRegister(BK4819_REG_5F, pData[i]); BK4819_WriteRegister(BK4819_REG_5F, pData[i]);
SYSTEM_DelayMs(20); SYSTEM_DelayMs(20);
// start sending
BK4819_WriteRegister(BK4819_REG_59, 0x2868); BK4819_WriteRegister(BK4819_REG_59, 0x2868);
while (Timeout-- && (BK4819_ReadRegister(BK4819_REG_0C) & 1u) == 0) // wait till TX is done ?
while (Timeout-- && (BK4819_ReadRegister(BK4819_REG_0C) & (1u << 0)) == 0)
SYSTEM_DelayMs(5); SYSTEM_DelayMs(5);
BK4819_WriteRegister(BK4819_REG_02, 0); BK4819_WriteRegister(BK4819_REG_02, 0); // disable all interrupts
SYSTEM_DelayMs(20); SYSTEM_DelayMs(20);
BK4819_ResetFSK(); BK4819_ResetFSK();
} }
*/
void BK4819_PrepareFSKReceive(void) void BK4819_PrepareFSKReceive(void)
{ {
BK4819_ResetFSK(); BK4819_ResetFSK();
BK4819_WriteRegister(BK4819_REG_02, 0); BK4819_WriteRegister(BK4819_REG_02, 0);
BK4819_WriteRegister(BK4819_REG_3F, 0); BK4819_WriteRegister(BK4819_REG_3F, 0);
BK4819_RX_TurnOn(); BK4819_RX_TurnOn();
BK4819_WriteRegister(BK4819_REG_3F, 0 | BK4819_REG_3F_FSK_RX_FINISHED | BK4819_REG_3F_FSK_FIFO_ALMOST_FULL);
BK4819_WriteRegister(BK4819_REG_3F, BK4819_REG_3F_FSK_RX_SYNC | BK4819_REG_3F_FSK_RX_FINISHED | BK4819_REG_3F_FSK_FIFO_ALMOST_FULL);
// BK4819_WriteRegister(BK4819_REG_3F, BK4819_REG_3F_FSK_RX_FINISHED | BK4819_REG_3F_FSK_FIFO_ALMOST_FULL);
// Clear RX FIFO // Clear RX FIFO
// FSK Preamble Length 7 bytes // FSK Preamble Length 7 bytes

View File

@ -151,7 +151,7 @@ uint8_t BK4819_get_CDCSS_code_type(void);
uint8_t BK4819_GetCTCShift(void); uint8_t BK4819_GetCTCShift(void);
uint8_t BK4819_GetCTCType(void); uint8_t BK4819_GetCTCType(void);
void BK4819_SendFSKData(uint16_t *pData); //void BK4819_SendFSKData(uint16_t *pData);
void BK4819_PrepareFSKReceive(void); void BK4819_PrepareFSKReceive(void);
void BK4819_PlayRoger(void); void BK4819_PlayRoger(void);

Binary file not shown.

Binary file not shown.

4
misc.c
View File

@ -19,6 +19,10 @@
#include "misc.h" #include "misc.h"
#include "settings.h" #include "settings.h"
const uint8_t obfuscate_array[16] = {
0x16, 0x6C, 0x14, 0xE6, 0x2E, 0x91, 0x0D, 0x40, 0x21, 0x35, 0xD5, 0x40, 0x13, 0x03, 0xE9, 0x80
};
// *********************************************** // ***********************************************
const uint8_t fm_resume_countdown_500ms = 2500 / 500; // 2.5 seconds const uint8_t fm_resume_countdown_500ms = 2500 / 500; // 2.5 seconds

2
misc.h
View File

@ -101,6 +101,8 @@ enum scan_next_chan_e {
}; };
typedef enum scan_next_chan_e scan_next_chan_t; typedef enum scan_next_chan_e scan_next_chan_t;
extern const uint8_t obfuscate_array[16];
extern const uint8_t fm_resume_countdown_500ms; extern const uint8_t fm_resume_countdown_500ms;
extern const uint8_t fm_radio_countdown_500ms; extern const uint8_t fm_radio_countdown_500ms;
extern const uint16_t fm_play_countdown_scan_10ms; extern const uint16_t fm_play_countdown_scan_10ms;

View File

@ -41,8 +41,8 @@ void UI_DisplayAircopy(void)
case AIRCOPY_READY: strcat(str, " READY"); break; case AIRCOPY_READY: strcat(str, " READY"); break;
case AIRCOPY_RX: strcat(str, " RX"); break; case AIRCOPY_RX: strcat(str, " RX"); break;
case AIRCOPY_TX: strcat(str, " TX"); break; case AIRCOPY_TX: strcat(str, " TX"); break;
case AIRCOPY_RX_COMPLETE: strcat(str, " DONE"); break; case AIRCOPY_RX_COMPLETE: strcat(str, " RDONE"); break;
case AIRCOPY_TX_COMPLETE: strcat(str, " DONE"); break; case AIRCOPY_TX_COMPLETE: strcat(str, " TDONE"); break;
default: strcat(str, " ERR"); break; default: strcat(str, " ERR"); break;
} }
UI_PrintString(str, 0, LCD_WIDTH - 1, 0, 8); UI_PrintString(str, 0, LCD_WIDTH - 1, 0, 8);
@ -69,6 +69,10 @@ void UI_DisplayAircopy(void)
switch (g_aircopy_state) switch (g_aircopy_state)
{ {
case AIRCOPY_TX_COMPLETE:
// UI_PrintString("TX COMPLETE", 0, LCD_WIDTH - 1, 5, 8);
// break;
case AIRCOPY_READY: case AIRCOPY_READY:
UI_PrintString("EXIT rx M tx", 0, LCD_WIDTH - 1, 5, 7); UI_PrintString("EXIT rx M tx", 0, LCD_WIDTH - 1, 5, 7);
break; break;
@ -87,12 +91,9 @@ void UI_DisplayAircopy(void)
UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7); UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7);
break; break;
case AIRCOPY_TX_COMPLETE:
UI_PrintString("TX COMPLETE", 0, LCD_WIDTH - 1, 5, 8);
break;
case AIRCOPY_TX: case AIRCOPY_TX:
sprintf(str, "TX %u.%u", g_aircopy_block_number, g_aircopy_block_max); strcpy(str, (g_fsk_tx_timeout_10ms > 0) ? "*" : " ");
sprintf(str + 1, " TX %u.%u", g_aircopy_block_number, g_aircopy_block_max);
UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7); UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7);
break; break;

View File

@ -980,13 +980,33 @@ void UI_DisplayMenu(void)
i = 0; i = 0;
while (i < (sizeof(String) - 1) && k < slen) while (i < (sizeof(String) - 1) && k < slen)
{ {
String[i++] = Version_str[k++]; const char c = Version_str[k++];
if (c == ' ' || c == '-' || c == '_')
{
if (m >= 3)
{
String[i++] = '\n';
m = 0;
}
else
String[i++] = c;
}
else
{
String[i++] = c;
if (++m >= 9 && k < slen && i < (sizeof(String) - 1)) if (++m >= 9 && k < slen && i < (sizeof(String) - 1))
{
if (m > 0)
{ {
m = 0; m = 0;
String[i++] = '\n'; String[i++] = '\n';
} }
} }
}
}
// add the date and time
strcat(String, "\n" __DATE__);
strcat(String, "\n" __TIME__);
break; break;
} }