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

fix bug in ignore freq add

This commit is contained in:
OneOfEleven
2023-11-06 13:27:35 +00:00
parent 521793ba6f
commit 1ee2662f78
4 changed files with 56 additions and 37 deletions

View File

@ -12,6 +12,10 @@ int ignore_frequencies_count = 0;
void FI_clear_freq_ignored(void)
{ // clear the ignore list
ignore_frequencies_count = 0;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("ignore cleared\r\n");
#endif
}
int FI_freq_ignored(const uint32_t frequency)
@ -20,8 +24,8 @@ int FI_freq_ignored(const uint32_t frequency)
if (frequency == 0 || frequency == 0xffffffff || ignore_frequencies_count <= 0)
return -1;
if (ignore_frequencies_count > 4)
{ // binary search .. becomes much faster than sequencial as the list grows
if (ignore_frequencies_count >= 8)
{ // binary search .. becomes much faster than sequencial search when the list is bigger
int low = 0;
int high = ignore_frequencies_count;
while (low < high)
@ -34,7 +38,12 @@ int FI_freq_ignored(const uint32_t frequency)
if (freq < frequency)
low = mid + 1;
else
{
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("ignored bin %u %u\r\n", frequency, mid);
#endif
return mid;
}
}
}
else
@ -44,7 +53,12 @@ int FI_freq_ignored(const uint32_t frequency)
{
register uint32_t freq = ignore_frequencies[i];
if (frequency == freq)
return i; // found it
{ // found it
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("ignored seq %u %u\r\n", frequency, i);
#endif
return i;
}
if (frequency < freq)
return -1; // can exit loop early as the list is sorted by frequency
}
@ -59,13 +73,16 @@ void FI_add_freq_ignored(const uint32_t frequency)
int i;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("ignore %u\r\n", frequency);
UART_printf("ignore add %u\r\n", frequency);
#endif
if (frequency == 0 || frequency == 0xffffffff)
return;
if (ignore_frequencies_count >= (int)ARRAY_SIZE(ignore_frequencies))
{ // the list is full
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("ignore full\r\n");
UART_SendText("ignore add full\r\n");
#endif
return;
}
@ -77,7 +94,7 @@ void FI_add_freq_ignored(const uint32_t frequency)
if (frequency == freq)
{ // already in the list
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("ignore already\r\n");
UART_SendText("ignore add already\r\n");
#endif
return;
}
@ -88,13 +105,9 @@ void FI_add_freq_ignored(const uint32_t frequency)
// found the location to store the new frequency - the list is kept sorted by frequency
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("ignore adding ..\r\n");
#endif
// make room for the new frequency
if (i < ignore_frequencies_count)
memmove(&ignore_frequencies[i + 1], &ignore_frequencies[i], sizeof(ignore_frequencies[0]) * (ignore_frequencies_count - i - 1));
memmove(&ignore_frequencies[i + 1], &ignore_frequencies[i], sizeof(ignore_frequencies[0]) * (ignore_frequencies_count - i));
// add the frequency to the list
ignore_frequencies[i] = frequency;
@ -109,17 +122,23 @@ void FI_add_freq_ignored(const uint32_t frequency)
void FI_sub_freq_ignored(const uint32_t frequency)
{ // remove a frequency from the ignore list
int index = FI_freq_ignored(frequency);
if (index >= 0)
{
if (index < (ignore_frequencies_count - 1))
memmove(&ignore_frequencies[index], &ignore_frequencies[index + 1], sizeof(ignore_frequencies[0]) * (ignore_frequencies_count - 1));
ignore_frequencies_count--;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("ignore sub %u\r\n", frequency);
#endif
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("ignore freq ..\r\n");
for (index = 0; index < ignore_frequencies_count; index++)
UART_printf("%2u %10u\r\n", index, ignore_frequencies[index]);
#endif
}
if (frequency == 0 || frequency == 0xffffffff)
return;
int index = FI_freq_ignored(frequency);
if (index < 0)
return;
if (index < (ignore_frequencies_count - 1))
memmove(&ignore_frequencies[index], &ignore_frequencies[index + 1], sizeof(ignore_frequencies[0]) * (ignore_frequencies_count - 1));
ignore_frequencies_count--;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
for (index = 0; index < ignore_frequencies_count; index++)
UART_printf("%2u %10u\r\n", index, ignore_frequencies[index]);
#endif
}