diff --git a/app/aircopy.c b/app/aircopy.c index 332bf8f..5dbfa75 100644 --- a/app/aircopy.c +++ b/app/aircopy.c @@ -452,6 +452,9 @@ void AIRCOPY_process_fsk_rx_10ms(void) UART_printf("aircopy invalid CRC %04X %04X\r\n", crc2, crc1); #endif + if (g_aircopy_state == AIRCOPY_RX) + goto send_req; + g_fsk_write_index = 0; return; } @@ -494,52 +497,24 @@ void AIRCOPY_process_fsk_rx_10ms(void) } if (g_fsk_buffer[0] != AIRCOPY_MAGIC_START || g_fsk_buffer[g_fsk_write_index - 1] != AIRCOPY_MAGIC_END) - { // invalid magics .. ignore it + { // invalid magics g_aircopy_rx_errors_magic++; - g_fsk_write_index = 0; - return; + goto send_req; } if (eeprom_addr != (block_num * block_size)) { // eeprom address not block aligned .. ignore it - g_fsk_write_index = 0; - return; + goto send_req; } if (block_num != g_aircopy_block_number) { // not the block number we're expecting .. request the correct one - - g_fsk_write_index = 0; - - #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) - UART_printf("aircopy TX req %04X %04X\r\n", g_aircopy_block_number * 64, block_num * 64); - #endif - - // this packet takes 150ms start to finish - AIRCOPY_start_fsk_tx(g_aircopy_block_number); - g_fsk_tx_timeout_10ms = 200 / 5; // allow up to 200ms for the TX to complete - while (g_fsk_tx_timeout_10ms-- > 0) - { - SYSTEM_DelayMs(5); - if (BK4819_ReadRegister(BK4819_REG_0C) & (1u << 0)) - { // we have interrupt flags - BK4819_WriteRegister(BK4819_REG_02, 0); - const uint16_t interrupt_bits = BK4819_ReadRegister(BK4819_REG_02); - if (interrupt_bits & BK4819_REG_02_FSK_TX_FINISHED) - g_fsk_tx_timeout_10ms = 0; // TX is complete - } - } - AIRCOPY_stop_fsk_tx(); - - BK4819_start_fsk_rx(AIRCOPY_DATA_PACKET_SIZE); - - return; + goto send_req; } if ((eeprom_addr + block_size) > AIRCOPY_LAST_EEPROM_ADDR) { // ignore it - g_fsk_write_index = 0; - return; + goto send_req; } // clear the error counts @@ -582,6 +557,33 @@ void AIRCOPY_process_fsk_rx_10ms(void) g_aircopy_state = AIRCOPY_RX_COMPLETE; AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP); } + + return; + +send_req: + g_fsk_write_index = 0; + + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) + UART_printf("aircopy TX req %04X %04X\r\n", g_aircopy_block_number * 64, block_num * 64); + #endif + + // this packet takes 150ms start to finish + AIRCOPY_start_fsk_tx(g_aircopy_block_number); + g_fsk_tx_timeout_10ms = 200 / 5; // allow up to 200ms for the TX to complete + while (g_fsk_tx_timeout_10ms-- > 0) + { + SYSTEM_DelayMs(5); + if (BK4819_ReadRegister(BK4819_REG_0C) & (1u << 0)) + { // we have interrupt flags + BK4819_WriteRegister(BK4819_REG_02, 0); + const uint16_t interrupt_bits = BK4819_ReadRegister(BK4819_REG_02); + if (interrupt_bits & BK4819_REG_02_FSK_TX_FINISHED) + g_fsk_tx_timeout_10ms = 0; // TX is complete + } + } + AIRCOPY_stop_fsk_tx(); + + BK4819_start_fsk_rx(AIRCOPY_DATA_PACKET_SIZE); } static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) diff --git a/firmware.bin b/firmware.bin index a90c669..e77e700 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index c853997..50adead 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/ui/aircopy.c b/ui/aircopy.c index 1c4d52c..b9242cc 100644 --- a/ui/aircopy.c +++ b/ui/aircopy.c @@ -46,11 +46,11 @@ void UI_DisplayAircopy(void) 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, " RDONE"); break; - case AIRCOPY_TX_COMPLETE: strcat(str, " TDONE"); break; + case AIRCOPY_RX_COMPLETE: strcat(str, " DONE"); break; + case AIRCOPY_TX_COMPLETE: strcat(str, " DONE"); break; default: strcat(str, " ERR"); break; } - UI_PrintString(str, 0, LCD_WIDTH - 1, 0, 8); + UI_PrintString(str, 0, LCD_WIDTH, 0, 8); // ********************************** // center frequency text line @@ -74,21 +74,10 @@ void UI_DisplayAircopy(void) switch (g_aircopy_state) { - case AIRCOPY_TX_COMPLETE: -// UI_PrintString("TX COMPLETE", 0, LCD_WIDTH - 1, 5, 8); -// break; - case AIRCOPY_READY: - UI_PrintString("EXIT rx M tx", 0, LCD_WIDTH - 1, 5, 7); + UI_PrintString("EXIT rx M tx", 0, LCD_WIDTH, 5, 7); break; - case AIRCOPY_RX_COMPLETE: - if (errors == 0) - { - UI_PrintString("RX COMPLETE", 0, LCD_WIDTH - 1, 5, 8); - break; - } - case AIRCOPY_RX: sprintf(str, "RX %u.%u", g_aircopy_block_number, g_aircopy_block_max); if (errors > 0) @@ -102,18 +91,26 @@ void UI_DisplayAircopy(void) g_aircopy_rx_errors_crc); #endif } - UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7); + UI_PrintString(str, 0, LCD_WIDTH, 5, 7); break; case AIRCOPY_TX: 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, 5, 7); + break; + + case AIRCOPY_RX_COMPLETE: + UI_PrintString("RX COMPLETE", 0, LCD_WIDTH, 5, 8); + break; + + case AIRCOPY_TX_COMPLETE: + UI_PrintString("TX COMPLETE", 0, LCD_WIDTH, 5, 8); break; default: strcpy(str, "ERROR"); - UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7); + UI_PrintString(str, 0, LCD_WIDTH, 5, 7); break; }