0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 06:11:24 +03:00

Added version string sanity checking to prevent boot problems and serial comm problems

This commit is contained in:
OneOfEleven 2023-10-12 08:39:51 +01:00
parent 5755a92daa
commit 74d31a616f
8 changed files with 129 additions and 116 deletions

181
app/app.c
View File

@ -1147,7 +1147,7 @@ void APP_Update(void)
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
//UART_SendText("dual watch\r\n");
#endif
#ifdef ENABLE_VOICE
if (g_voice_write_index == 0)
#endif
@ -1499,6 +1499,41 @@ void APP_TimeSlice10ms(void)
__enable_irq();
}
// ***********
if (g_flag_SaveVfo)
{
SETTINGS_SaveVfoIndices();
g_flag_SaveVfo = false;
}
if (g_flag_SaveSettings)
{
SETTINGS_SaveSettings();
g_flag_SaveSettings = false;
}
#ifdef ENABLE_FMRADIO
if (g_flag_SaveFM)
{
SETTINGS_SaveFM();
g_flag_SaveFM = false;
}
#endif
if (g_flag_save_channel)
{
SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_flag_save_channel);
g_flag_save_channel = false;
RADIO_ConfigureChannel(g_eeprom.tx_vfo, VFO_CONFIGURE);
RADIO_SetupRegisters(true);
GUI_SelectNextDisplay(DISPLAY_MAIN);
}
// ***********
if (g_serial_config_count_down_500ms > 0)
{ // config upload/download is running
if (g_update_display)
@ -1508,6 +1543,8 @@ void APP_TimeSlice10ms(void)
return;
}
// ***********
#ifdef ENABLE_BOOT_BEEPS
if (g_boot_counter_10ms > 0 && (g_boot_counter_10ms % 25) == 0)
AUDIO_PlayBeep(BEEP_880HZ_40MS_OPTIONAL);
@ -1824,7 +1861,7 @@ void cancelUserInputModes(void)
g_ask_to_delete = false;
g_update_display = true;
}
if (g_dtmf_input_mode || g_dtmf_input_box_index > 0)
{
DTMF_clear_input_box();
@ -2240,7 +2277,8 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
// reset the state so as to remove it from the screen
if (Key != KEY_INVALID && Key != KEY_PTT)
RADIO_Setg_vfo_state(VFO_STATE_NORMAL);
/*
// remember the current backlight state (on / off)
const bool backlight_was_on = GPIO_CheckBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT);
if (Key == KEY_EXIT && !backlight_was_on && g_eeprom.backlight > 0)
@ -2249,15 +2287,30 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
g_beep_to_play = BEEP_NONE;
return;
}
*/
// turn the backlight on
if (key_pressed)
if (Key != KEY_PTT || g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3)
backlight_turn_on();
if (g_current_function == FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_FOREGROUND);
// stay awake - for now
g_battery_save_count_down_10ms = battery_save_count_10ms;
// keep the auto keylock at bay
if (g_eeprom.auto_keypad_lock)
g_key_lock_count_down_500ms = key_lock_timeout_500ms;
if (g_fkey_pressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2))
{ // cancel the F-key
g_fkey_pressed = false;
g_update_status = true;
}
// ********************
if (g_eeprom.key_lock && g_current_function != FUNCTION_TRANSMIT && Key != KEY_PTT)
{ // keyboard is locked
@ -2288,99 +2341,57 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
if (!key_pressed || key_held)
return;
backlight_turn_on();
#ifdef ENABLE_FMRADIO
if (!g_fm_radio_mode)
#endif
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// keypad is locked, tell the user
// keypad is locked, let the user know
g_keypad_locked = 4; // 2 second pop-up
g_update_display = true;
#ifdef ENABLE_FMRADIO
if (!g_fm_radio_mode) // don't beep when the FM radio is on, it cause bad gaps and loud clicks
#endif
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
}
if (!key_pressed)
{
if (g_flag_SaveVfo)
// key beep
if (Key != KEY_PTT && !key_held && key_pressed)
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// ********************
if (Key == KEY_EXIT && key_held && key_pressed)
{ // exit key held pressed
// clear the live DTMF decoder
if (g_dtmf_rx_live[0] != 0)
{
SETTINGS_SaveVfoIndices();
g_flag_SaveVfo = false;
memset(g_dtmf_rx_live, 0, sizeof(g_dtmf_rx_live));
g_dtmf_rx_live_timeout = 0;
g_update_display = true;
}
if (g_flag_SaveSettings)
{
SETTINGS_SaveSettings();
g_flag_SaveSettings = false;
}
#ifdef ENABLE_FMRADIO
if (g_flag_SaveFM)
{
SETTINGS_SaveFM();
g_flag_SaveFM = false;
}
#endif
if (g_flag_save_channel)
{
SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_flag_save_channel);
g_flag_save_channel = false;
RADIO_ConfigureChannel(g_eeprom.tx_vfo, VFO_CONFIGURE);
RADIO_SetupRegisters(true);
GUI_SelectNextDisplay(DISPLAY_MAIN);
}
// cancel user input
cancelUserInputModes();
}
if (key_pressed)
{
if (Key != KEY_PTT || g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3)
backlight_turn_on();
if (key_pressed && g_screen_to_display == DISPLAY_MENU)
g_menu_count_down = menu_timeout_500ms;
if (Key == KEY_EXIT && key_held)
{ // exit key held pressed
// cancel the ringing
if (key_pressed && g_dtmf_decode_ring_count_down_500ms > 0)
g_dtmf_decode_ring_count_down_500ms = 0;
// clear the live DTMF decoder
if (g_dtmf_rx_live[0] != 0)
{
memset(g_dtmf_rx_live, 0, sizeof(g_dtmf_rx_live));
g_dtmf_rx_live_timeout = 0;
g_update_display = true;
}
// cancel user input
cancelUserInputModes();
}
if (g_screen_to_display == DISPLAY_MENU) // 1of11
g_menu_count_down = menu_timeout_500ms;
if (g_dtmf_decode_ring_count_down_500ms > 0)
{ // cancel the ringing
g_dtmf_decode_ring_count_down_500ms = 0;
AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL);
if (Key != KEY_PTT)
{
// g_ptt_was_released = true; // why is this being set ?
return;
}
}
}
// ********************
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
if ((Key >= KEY_0 && Key <= KEY_9) || Key == KEY_F)
{
if (g_scan_state_dir != SCAN_OFF || g_css_scan_mode != CSS_SCAN_MODE_OFF)
{ // FREQ/CTCSS/DCS scanning
if (g_scan_state_dir != SCAN_OFF || g_css_scan_mode != CSS_SCAN_MODE_OFF)
{ // FREQ/CTCSS/CDCSS scanning
if ((Key >= KEY_0 && Key <= KEY_9) || Key == KEY_F)
{
if (key_pressed && !key_held)
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
return;
@ -2389,6 +2400,8 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
#pragma GCC diagnostic pop
// ********************
if (Key == KEY_PTT && g_ptt_was_pressed)
{
flag = key_held;
@ -2400,12 +2413,11 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
}
// this bit of code has caused soooooo many problems due
// to this causing key releases to be totally ignored :( .. 1of11
// to this causing key releases to be ignored :( .. 1of11
if (Key != KEY_PTT && g_ptt_was_released)
{
if (key_held)
flag = true;
// if (!key_pressed)
if (key_pressed) // I now use key released for button press detections
{
flag = true;
@ -2417,17 +2429,11 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
#endif
}
if (g_fkey_pressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2))
{ // cancel the F-key
g_fkey_pressed = false;
g_update_status = true;
}
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("proc key 2 %3u %u %u %u %u\r\n", Key, key_pressed, key_held, g_fkey_pressed, flag);
#endif
if (!flag)
if (!flag) // this flag is responsible for keys being ignored :(
{
if (g_current_function == FUNCTION_TRANSMIT)
{ // transmitting
@ -2515,7 +2521,6 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b
{
case DISPLAY_MAIN:
MAIN_ProcessKeys(Key, key_pressed, key_held);
// key_held = false; // allow the channel setting to be saved
break;
#ifdef ENABLE_FMRADIO

View File

@ -206,10 +206,14 @@ static void SendVersion(void)
{
reply_0514_t reply;
unsigned int slen = strlen(Version_str);
if (slen > (sizeof(reply.Data.Version) - 1))
slen = sizeof(reply.Data.Version) - 1;
memset(&reply, 0, sizeof(reply));
reply.Header.ID = 0x0515;
reply.Header.Size = sizeof(reply.Data);
strcpy(reply.Data.Version, Version);
memmove(reply.Data.Version, Version_str, slen);
reply.Data.has_custom_aes_key = g_has_custom_aes_key;
reply.Data.password_locked = g_password_locked;
reply.Data.Challenge[0] = g_challenge[0];

Binary file not shown.

Binary file not shown.

2
main.c
View File

@ -71,7 +71,7 @@ void Main(void)
g_boot_counter_10ms = 250; // 2.5 sec
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText(UART_Version);
UART_SendText(UART_Version_str);
#endif
// Not implementing authentic device checks

View File

@ -41,9 +41,9 @@ void UI_DisplayReleaseKeys(void)
void UI_DisplayWelcome(void)
{
char WelcomeString0[16];
char WelcomeString1[16];
char WelcomeString2[16];
char str0[17];
char str1[17];
char str2[17];
memset(g_status_line, 0, sizeof(g_status_line));
memset(g_frame_buffer, 0, sizeof(g_frame_buffer));
@ -59,34 +59,38 @@ void UI_DisplayWelcome(void)
}
else
{
memset(WelcomeString0, 0, sizeof(WelcomeString0));
memset(WelcomeString1, 0, sizeof(WelcomeString1));
memset(WelcomeString2, 0, sizeof(WelcomeString2));
unsigned int slen = strlen(Version_str);
if (slen > (sizeof(str2) - 1))
slen = sizeof(str2) - 1;
memset(str0, 0, sizeof(str0));
memset(str1, 0, sizeof(str1));
memset(str2, 0, sizeof(str2));
if (g_eeprom.pwr_on_display_mode == PWR_ON_DISPLAY_MODE_VOLTAGE)
{
strcpy(WelcomeString0, "VOLTAGE");
sprintf(WelcomeString1, "%u.%02uV %u%%",
strcpy(str0, "VOLTAGE");
sprintf(str1, "%u.%02uV %u%%",
g_battery_voltage_average / 100,
g_battery_voltage_average % 100,
BATTERY_VoltsToPercent(g_battery_voltage_average));
#if 0
sprintf(WelcomeString2, "Current %u", g_usb_current); // needs scaling into mA
#endif
}
else
{
EEPROM_ReadBuffer(0x0EB0, WelcomeString0, 16);
EEPROM_ReadBuffer(0x0EC0, WelcomeString1, 16);
EEPROM_ReadBuffer(0x0EB0, str0, 16);
EEPROM_ReadBuffer(0x0EC0, str1, 16);
}
UI_PrintString(WelcomeString0, 0, 127, 0, 10);
UI_PrintString(WelcomeString1, 0, 127, 2, 10);
#if 0
UI_PrintStringSmall(WelcomeString2, 0, 127, 4);
#endif
UI_PrintString(Version, 0, 127, 5, 10);
memmove(str2, Version_str, slen);
UI_PrintString(str0, 0, 127, 0, 10);
UI_PrintString(str1, 0, 127, 2, 10);
if (strlen(str2) <= 12)
UI_PrintString(str2, 0, 127, 5, 10);
else
UI_PrintStringSmallBold(str2, 0, 127, 5);
#if 1
ST7565_BlitStatusLine(); // blank status line

View File

@ -8,9 +8,9 @@
#endif
#ifndef ONE_OF_ELEVEN_VER
const char Version[] = "OEFW-"VER;
const char UART_Version[] = "UV-K5 Firmware, Open Edition, OEFW-"VER"\r\n";
const char Version_str[] = "OEFW-"VER;
const char UART_Version_str[] = "UV-K5 Firmware, Open Edition, OEFW-"VER"\r\n";
#else
const char Version[] = "1o11-"VER;
const char UART_Version[] = "UV-K5 Firmware, Open Edition, 1o11-"VER"\r\n";
const char Version_str[] = "1o11-"VER;
const char UART_Version_str[] = "UV-K5 Firmware, Open Edition, 1o11-"VER"\r\n";
#endif

View File

@ -17,8 +17,8 @@
#ifndef VERSION_H
#define VERSION_H
extern const char Version[];
extern const char UART_Version[];
extern const char Version_str[];
extern const char UART_Version_str[];
#endif