From 325e369bfd691b767144a76e63f5cc48cf8179e9 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sat, 4 Apr 2015 16:37:43 -0700 Subject: [PATCH] FRONTPANEL: Added mount and dismount commands for removable media --- frontpanel/FrontPanelTest.c | 14 +++++++ scp.c | 11 ++--- scp.h | 1 + sim_console.c | 3 +- sim_console.h | 2 + sim_frontpanel.c | 81 +++++++++++++++++++++++++++++++++++++ sim_frontpanel.h | 38 +++++++++++++++++ 7 files changed, 144 insertions(+), 6 deletions(-) diff --git a/frontpanel/FrontPanelTest.c b/frontpanel/FrontPanelTest.c index 52090418..ef09fcf7 100644 --- a/frontpanel/FrontPanelTest.c +++ b/frontpanel/FrontPanelTest.c @@ -309,6 +309,20 @@ if (!sim_panel_get_registers (panel, NULL)) { printf ("Unexpected success getting register data: %s\n", sim_panel_get_error()); goto Done; } +sim_panel_clear_error (); +if (!sim_panel_dismount (panel, "RL0")) { + printf ("Unexpected success while dismounting media file from non mounted RL0: %s\n", sim_panel_get_error()); + goto Done; + } +if (sim_panel_mount (panel, "RL0", "-N", "TEST-RL.DSK")) { + printf ("Error while mounting media file TEST-RL.DSK on RL0: %s\n", sim_panel_get_error()); + goto Done; + } +if (sim_panel_dismount (panel, "RL0")) { + printf ("Error while dismounting media file from RL0: %s\n", sim_panel_get_error()); + goto Done; + } +remove ("TEST-RL.DSK"); while (1) { size_t i; char cmd[512]; diff --git a/scp.c b/scp.c index 15bd5b99..db82badd 100644 --- a/scp.c +++ b/scp.c @@ -490,7 +490,7 @@ static int32 noqueue_time; volatile int32 stop_cpu = 0; static char **sim_argv; t_value *sim_eval = NULL; -t_value sim_last_val; +static t_value sim_last_val; FILE *sim_log = NULL; /* log file */ FILEREF *sim_log_ref = NULL; /* log file file reference */ FILE *sim_deb = NULL; /* debug file */ @@ -503,7 +503,7 @@ static int32 sim_goto_line[MAX_DO_NEST_LVL+1]; /* the current line numb static int32 sim_do_echo = 0; /* the echo status of the currently open do file */ static int32 sim_show_message = 1; /* the message display status of the currently open do file */ static int32 sim_on_inherit = 0; /* the inherit status of on state and conditions when executing do files */ -int32 sim_do_depth = 0; +static int32 sim_do_depth = 0; static int32 sim_on_check[MAX_DO_NEST_LVL+1]; static char *sim_on_actions[MAX_DO_NEST_LVL+1][SCPE_MAX_ERR+1]; @@ -511,7 +511,7 @@ static char sim_do_filename[MAX_DO_NEST_LVL+1][CBUFSIZE]; static char *sim_do_ocptr[MAX_DO_NEST_LVL+1]; static char *sim_do_label[MAX_DO_NEST_LVL+1]; -static t_stat sim_last_cmd_stat; /* Command Status */ +t_stat sim_last_cmd_stat; /* Command Status */ static SCHTAB sim_stabr; /* Register search specifier */ static SCHTAB sim_staba; /* Memory search specifier */ @@ -7026,8 +7026,9 @@ t_stat get_yn (const char *ques, t_stat deflt) { char cbuf[CBUFSIZE], *cptr; -printf ("%s ", ques); -cptr = read_line (cbuf, sizeof(cbuf), stdin); +if (sim_rem_cmd_active_line != -1) + return deflt; +cptr = read_line_p (ques, cbuf, sizeof(cbuf), stdin); if ((cptr == NULL) || (*cptr == 0)) return deflt; if ((*cptr == 'Y') || (*cptr == 'y')) diff --git a/scp.h b/scp.h index cd8d0150..a205335e 100644 --- a/scp.h +++ b/scp.h @@ -221,6 +221,7 @@ extern int32 sim_interval; extern int32 sim_switches; extern int32 sim_quiet; extern int32 sim_step; +extern t_stat sim_last_cmd_stat; /* Command Status */ extern FILE *sim_log; /* log file */ extern FILEREF *sim_log_ref; /* log file file reference */ extern FILE *sim_deb; /* debug file */ diff --git a/sim_console.c b/sim_console.c index 24ff195e..3d639174 100644 --- a/sim_console.c +++ b/sim_console.c @@ -411,7 +411,7 @@ static TMXR sim_rem_con_tmxr = { 0, 0, 0, NULL, NULL, &sim_remote_console };/* r static uint32 sim_rem_read_timeout = 30; /* seconds before automatic continue */ static uint32 *sim_rem_read_timeouts = NULL;/* per line read timeout (default from sim_rem_read_timeout) */ static int32 sim_rem_active_number = -1; /* -1 - not active, >= 0 is index of active console */ -static int32 sim_rem_cmd_active_line = -1; /* step in progress on line # */ +int32 sim_rem_cmd_active_line = -1; /* step in progress on line # */ static CTAB *sim_rem_active_command = NULL; /* active command */ static char *sim_rem_command_buf; /* active command buffer */ static t_bool sim_log_temp = FALSE; /* temporary log file active */ @@ -688,6 +688,7 @@ sim_ttcmd (); /* restore console */ stat = sim_rem_active_command->action (sim_rem_active_command->arg, cptr);/* execute command */ if (stat != SCPE_OK) stat = _sim_rem_message (gbuf, stat); /* display results */ +sim_last_cmd_stat = SCPE_BARE_STATUS(stat); sim_ttrun (); /* set console mode */ sim_cancel (&sim_rem_con_unit[1]); /* force immediate activation of sim_rem_con_data_svc */ sim_activate (&sim_rem_con_unit[1], -1); diff --git a/sim_console.h b/sim_console.h index 33eef6cd..2c72676f 100644 --- a/sim_console.h +++ b/sim_console.h @@ -120,6 +120,8 @@ int32 sim_tt_outcvt (int32 c, uint32 mode); t_stat sim_tt_settabs (UNIT *uptr, int32 val, char *cptr, void *desc); t_stat sim_tt_showtabs (FILE *st, UNIT *uptr, int32 val, void *desc); +extern int32 sim_rem_cmd_active_line; /* command in progress on line # */ + extern int32 sim_int_char; /* interrupt character */ extern int32 sim_brk_char; /* break character */ extern int32 sim_tt_pchar; /* printable character mask */ diff --git a/sim_frontpanel.c b/sim_frontpanel.c index 82b819c3..ef77816e 100644 --- a/sim_frontpanel.c +++ b/sim_frontpanel.c @@ -28,6 +28,8 @@ 03-Apr-15 MP Added logic to pass simulator startup messages in panel error text if the connection to the simulator shuts down while it is starting. + 04-Apr-15 MP Added mount and dismount routines to connect and + disconnect removable media This module provides interface between a front panel application and a simh simulator. Facilities provide ways to gather information from and to @@ -1344,6 +1346,83 @@ if (_panel_sendf (panel, 1, NULL, "DEPOSIT %s %s", name, value)) return 0; } +/** + sim_panel_mount + + device the name of a simulator device/unit + switches any switches appropriate for the desire attach + path the path on the local system to be attached + + */ +int +sim_panel_mount (PANEL *panel, + const char *device, + const char *switches, + const char *path) +{ +char *response = NULL, *status = NULL; + +if (!panel || (panel->State == Error)) { + sim_panel_set_error ("Invalid Panel"); + return -1; + } +if (_panel_sendf (panel, 1, &response, "ATTACH %s %s %s", switches, device, path)) { + free (response); + return -1; + } +if (_panel_sendf (panel, 1, &status, "ECHO %%STATUS%%")) { + free (response); + free (status); + return -1; + } +if (!status || (strcmp (status, "00000000\r\n"))) { + sim_panel_set_error (response); + free (response); + free (status); + return -1; + } +free (response); +free (status); +return 0; +} + +/** + sim_panel_dismount + + device the name of a simulator device/unit + + */ +int +sim_panel_dismount (PANEL *panel, + const char *device) +{ +char *response = NULL, *status = NULL; + +if (!panel || (panel->State == Error)) { + sim_panel_set_error ("Invalid Panel"); + return -1; + } +if (_panel_sendf (panel, 1, &response, "DETACH %s", device)) { + free (response); + return -1; + } +if (_panel_sendf (panel, 1, &status, "ECHO %%STATUS%%")) { + free (response); + free (status); + return -1; + } +if (!status || (strcmp (status, "00000000\r\n"))) { + sim_panel_set_error (response); + free (response); + free (status); + return -1; + } +free (response); +free (status); +return 0; +} + + static void * _panel_reader(void *arg) { @@ -1705,6 +1784,7 @@ if (wait_for_completion) { strcat (buf, command_done_echo); strcat (buf, "\r"); pthread_mutex_lock (&p->io_lock); + p->io_response_data = 0; } ret = (strlen (buf) == _panel_send (p, buf, strlen (buf))) ? 0 : -1; @@ -1723,6 +1803,7 @@ if (wait_for_completion) { memcpy (*response, p->io_response, p->io_response_data + 1); } p->io_response_data = 0; + p->io_response[0] = '\0'; } pthread_mutex_unlock (&p->io_lock); } diff --git a/sim_frontpanel.h b/sim_frontpanel.h index 159d309a..2de866ed 100644 --- a/sim_frontpanel.h +++ b/sim_frontpanel.h @@ -28,6 +28,8 @@ 03-Apr-15 MP Added logic to pass simulator startup messages in panel error text if the connection to the simulator shuts down while it is starting. + 04-Apr-15 MP Added mount and dismount routines to connect and + disconnect removable media This module defines interface between a front panel application and a simh simulator. Facilities provide ways to gather information from and to @@ -323,6 +325,42 @@ sim_panel_set_register_value (PANEL *panel, const char *name, const char *value); +/** + + When a front panel application may needs to change the media + in a simulated removable media device one of the following + routines should be called: + + sim_panel_mount - mounts the indicated media file on a device + sim_panel_dismount - dismounts the currently mounted media file + from a device + + */ + +/** + sim_panel_mount + + device the name of a simulator device/unit + switches any switches appropriate for the desire attach + path the path on the local system to be attached + + */ +int +sim_panel_mount (PANEL *panel, + const char *device, + const char *switches, + const char *path); + +/** + sim_panel_dismount + + device the name of a simulator device/unit + + */ +int +sim_panel_dismount (PANEL *panel, + const char *device); + typedef enum { Halt, /* Simulation is halted (instructions not being executed) */