Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve timeout download checks #20

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions configurator/src/floppydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ __uint16_t floppy_db()
locate(0, 22);
printf("Press [ESC] to return to main menu.");
}

ConfigEntry *download_timeout_secs = get_config_entry(PARAM_DOWNLOAD_TIMEOUT_SEC);
int download_timeout = download_timeout_secs != NULL ? atoi(download_timeout_secs->value) : FLOPPYLOAD_WAIT_TIME;

PRINT_APP_HEADER(VERSION);

printf("\r\n");
Expand Down Expand Up @@ -123,13 +127,12 @@ __uint16_t floppy_db()

printf("\r\nLoading floppy. Wait until the led in the board blinks a 'F' in morse...");

send_sync_command(DOWNLOAD_FLOPPY, &app_number, 2, FLOPPYLOAD_WAIT_TIME, TRUE);
send_sync_command(DOWNLOAD_FLOPPY, &app_number, 2, download_timeout, COUNTDOWN);

__uint16_t download_status = *((__uint16_t *)(DB_FILES_LIST_START_ADDRESS));

if (download_status == 0)
{
sleep_seconds(5, FALSE);
printf("\r\033KFloppy image file loaded. ");
return 1; // different than zero is OK
}
Expand Down
9 changes: 5 additions & 4 deletions configurator/src/floppyselector.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ static __uint8_t get_floppy_size_input()

static __uint16_t floppy_selector(mode_t floppy_command)
{
ConfigEntry *download_timeout_secs = get_config_entry(PARAM_DOWNLOAD_TIMEOUT_SEC);
int download_timeout = download_timeout_secs != NULL ? atoi(download_timeout_secs->value) : ROMSLOAD_WAIT_TIME;

__uint8_t again = TRUE;
while (again)
{
Expand Down Expand Up @@ -125,7 +128,7 @@ static __uint16_t floppy_selector(mode_t floppy_command)
printf("\r\033KCreating new floppy image...");

#ifndef _DEBUG
send_sync_command(CREATE_FLOPPY, &floppy_header, sizeof(FloppyImageHeader), FLOPPYLOAD_WAIT_TIME, TRUE);
send_sync_command(CREATE_FLOPPY, &floppy_header, sizeof(FloppyImageHeader), FLOPPYLOAD_WAIT_TIME, SPINNING);
#endif
press_key("\r\033KNew floppy image created. Please select it from the list.");

Expand All @@ -142,9 +145,7 @@ static __uint16_t floppy_selector(mode_t floppy_command)
if (floppy_command == LOAD_FLOPPY_RW)
floppy_number--; // Bypass the menu added option to create images

send_sync_command(floppy_command, &floppy_number, 2, FLOPPYLOAD_WAIT_TIME, TRUE);

sleep_seconds(5, FALSE);
send_sync_command(floppy_command, &floppy_number, 2, download_timeout, SPINNING);

printf("\r\033KFloppy image file loaded.");
}
Expand Down
18 changes: 16 additions & 2 deletions configurator/src/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,17 @@ int send_async_command(__uint16_t command, void *payload, __uint16_t payload_siz
return 0;
}

int send_sync_command(__uint16_t command, void *payload, __uint16_t payload_size, __uint32_t timeout, __uint16_t show_spinner)
int send_sync_command(__uint16_t command, void *payload, __uint16_t payload_size, __uint32_t timeout, __uint16_t spinner_type)
{
switch (spinner_type)
{
case 1: // Spinning
printf(" ");
break;
case 2: // Countdown
printf(" ");
break;
}
if (payload_size % 2 != 0)
{
payload_size++;
Expand Down Expand Up @@ -170,9 +179,14 @@ int send_sync_command(__uint16_t command, void *payload, __uint16_t payload_size
while (active_wait > 0 && (remote_random_numer != random_seed))
{
Vsync();
if (show_spinner)
switch (spinner_type)
{
case 1: // Spinning
spinner(1);
break;
case 2: // Countdown
printf("\b\b%02d", active_wait / 50);
break;
}
active_wait--;
remote_random_numer = *((volatile __uint32_t *)RANDOM_NUMBER_ADDRESS);
Expand Down
6 changes: 5 additions & 1 deletion configurator/src/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "screen.h"
#include "commands.h"

#define MAX_ENTRIES 20
#define MAX_ENTRIES 21
#define MAX_KEY_LENGTH 20
#define MAX_STRING_VALUE_LENGTH 64

Expand Down Expand Up @@ -60,6 +60,10 @@ static ConfigData config_data_example = {
#define FALSE 0
#define TRUE 1

#define NO_SPINNING 0
#define SPINNING 1
#define COUNTDOWN 2

#define STATUS_STRING_BUFFER_SIZE 80 // Buffer size to display

ConfigEntry *get_config_entry(char *key);
Expand Down
2 changes: 2 additions & 0 deletions configurator/src/include/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ static __uint32_t random_number = 0x0;
#define KEY_ENTER 0x72000D
#define KEY_ESC 0x1001B

#define PARAM_DOWNLOAD_TIMEOUT_SEC "DOWNLOAD_TIMEOUT_SEC"

#define PRINT_APP_HEADER(version) \
do \
{ \
Expand Down
3 changes: 3 additions & 0 deletions configurator/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ static int run()
case 0x0003000: // Atari Falcon
break;
default:
#ifdef _DEBUG
printf("Atari ST detected with cookie-jar?.\n\r");
#endif
break;
}
}
Expand Down Expand Up @@ -304,6 +306,7 @@ static int run()
__uint16_t feature = err; // If the config is not loaded, exit the program. Otherwise, show the menu
while (feature == 0)
{
send_async_command(CLEAN_START, NULL, 0);
feature = menu();
switch (feature)
{
Expand Down
19 changes: 12 additions & 7 deletions configurator/src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ __uint16_t network_selector()

__uint16_t roms_from_network_selector()
{
ConfigEntry *download_timeout_secs = get_config_entry(PARAM_DOWNLOAD_TIMEOUT_SEC);
int download_timeout = download_timeout_secs != NULL ? atoi(download_timeout_secs->value) : ROMSLOAD_WAIT_TIME;

PRINT_APP_HEADER(VERSION);

printf("\r\n");
Expand Down Expand Up @@ -303,13 +306,15 @@ __uint16_t roms_from_network_selector()

printf("\r\nDownloading ROM. Wait until the led in the board blinks a 'E' or 'D' in morse...");

send_sync_command(DOWNLOAD_ROM, &rom_number, 2, NETWORKLOAD_WAIT_TIME, TRUE);

sleep_seconds(5, FALSE);

printf("\r\033KROM file downloaded. ");

return 1; // Positive is OK
int download_status = send_sync_command(DOWNLOAD_ROM, &rom_number, 2, download_timeout, COUNTDOWN);
if (download_status == 0)
{
printf("\r\033KROM file downloaded. ");
return 1; // different than zero is OK
}
printf("\r\033KError downloading ROM file: %d. Press a key to continue. ", download_status);
press_key("");
return 0; // A zero is return to menu
}

__uint16_t wifi_menu()
Expand Down
18 changes: 12 additions & 6 deletions configurator/src/romselector.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

__uint16_t rom_selector()
{
ConfigEntry *download_timeout_secs = get_config_entry(PARAM_DOWNLOAD_TIMEOUT_SEC);
int download_timeout = download_timeout_secs != NULL ? atoi(download_timeout_secs->value) : ROMSLOAD_WAIT_TIME;

PRINT_APP_HEADER(VERSION);

printf("\r\n");
Expand Down Expand Up @@ -54,11 +57,14 @@ __uint16_t rom_selector()

printf("\r\nLoading ROM. Wait until the led in the board blinks a 'E' or 'D' in morse...");

send_sync_command(LOAD_ROM, &rom_number, 2, ROMSLOAD_WAIT_TIME, TRUE);

sleep_seconds(5, FALSE);

printf("\r\033KROM file loaded. ");
int download_status = send_sync_command(LOAD_ROM, &rom_number, 2, download_timeout, SPINNING);
if (download_status == 0)
{
printf("\r\033KROM file loaded. ");
return 1; // different than zero is OK
}

return 1; // Positive is OK
printf("\r\033KError loading ROM file: %d. Press a key to continue. ", download_status);
press_key("");
return 0; // A zero is return to menu
}
Loading