1
0
mirror of https://github.com/simh/simh.git synced 2026-04-27 12:28:49 +00:00

SCP: Added EXPECT and SEND commands to react to data from and inject data into the simulated console port (and other MUX ports)

Ideas based on Dave Bryan's console halt efforts.

	sim> SEND {<mux>:line} {DELAY=n,}"string"

Where <mux> is the name of the device pointed to by the TMXR structure.  If <mux>:line isn't specified, then the console device is implicitly being referenced.
Delay is optional and once set persists for subsequent SEND operations to the same device.  Delay defaults to 1000.  The DELAY value is a minimum number of instructions which must execute before the next character in the provided string will be injected to the console port.  The DELAY value has effect between the characters delivered as well.  "string" requires quotes and within the quoted string, common C escape character syntax is available (\r\r\t, etc.).

Each device (console, and each line in each mux) has a separate value for DELAY.

An arbitrary number of 'expect' conditions can be defined.  The command syntax is:

              sim> EXPECT {<mux>:line} {[cnt]} "matchstring" {actioncommand {; actioncommand ...}}

Where <mux> is the name of the device pointed to by the TMXR structure.  If <mux>:line isn't specified, then the console device is implicitly being referenced.
"matchstring" requires quotes and within the quoted string, common C escape character syntax is available (\r\r\t, etc.).  The quotes used can be single or double quotes, but the closing quote must match the opening quote.  The match string might be extended to allow the use of perl style regular expressions in the "matchstring" when a -R switch is specified on the command line.

              sim> EXPECT "Enter Color: "  SEND "Red\r"; g

A specific 'expect' condition can be removed with:

              sim> NOEXPECT {<mux>:line} "matchstring"

All 'expect' conditions can be removed with:

              sim> NOEXPECT {<mux>:line}

'expect' conditions can be examined with:

              sim> SHOW EXPECT {<mux>:line}

Expect rules are one-shots (i.e. they disappear once a match has occurred) unless they are explicitly described as persistent with the -P switch.
The -C switch is available when defining expect rules.  The effect of a rule defined with the -C flag is that when an expect match occurs for that rule, ALL rules are cleared for that device (console or <mux>:line).
This commit is contained in:
Mark Pizzolato
2014-10-14 10:49:24 -07:00
parent d0865d37f5
commit 02e90de6a4
7 changed files with 1030 additions and 62 deletions

View File

@@ -313,8 +313,9 @@ typedef uint32 t_addr;
#define SCPE_AFAIL (SCPE_BASE + 42) /* assert failed */
#define SCPE_INVREM (SCPE_BASE + 43) /* invalid remote console command */
#define SCPE_NOTATT (SCPE_BASE + 44) /* not attached */
#define SCPE_EXPECT (SCPE_BASE + 45) /* expect matched */
#define SCPE_MAX_ERR (SCPE_BASE + 45) /* Maximum SCPE Error Value */
#define SCPE_MAX_ERR (SCPE_BASE + 46) /* Maximum SCPE Error Value */
#define SCPE_KFLAG 0x1000 /* tti data flag */
#define SCPE_BREAK 0x2000 /* tti break flag */
#define SCPE_NOMESSAGE 0x10000000 /* message display supression flag */
@@ -632,6 +633,40 @@ struct sim_brktab {
char *act; /* action string */
};
/* Expect rule */
struct sim_exptab {
uint8 *match; /* match string */
uint32 size; /* match string size */
int32 cnt; /* proceed count */
int32 switches; /* flags */
#define EXP_TYP_PERSIST (SWMASK ('P')) /* rule persists after match, default is once a rule matches, it is removed */
#define EXP_TYP_CLEARALL (SWMASK ('C')) /* clear all rules after matching this rule, default is to once a rule matches, it is removed */
char *act; /* action string */
};
/* Expect Context */
struct sim_expect {
struct sim_exptab *rules; /* match rules */
int32 size; /* count of match rules */
uint8 *buf; /* buffer of output data which has produced */
uint32 buf_ins; /* buffer insertion point for the next output data */
uint32 buf_size; /* buffer size */
};
/* Send Context */
struct sim_send {
uint32 delay; /* instruction delay before/between sent data */
#define SEND_DEFAULT_DELAY 1000 /* default delay instruction count */
double next_time; /* execution time when next data can be sent */
uint8 *buffer; /* buffer */
size_t bufsize; /* buffer size */
int32 insoff; /* insert offset */
int32 extoff; /* extra offset */
};
/* Debug table */
struct sim_debtab {
@@ -745,6 +780,9 @@ typedef struct sim_shtab SHTAB;
typedef struct sim_mtab MTAB;
typedef struct sim_schtab SCHTAB;
typedef struct sim_brktab BRKTAB;
typedef struct sim_exptab EXPTAB;
typedef struct sim_expect EXPECT;
typedef struct sim_send SEND;
typedef struct sim_debtab DEBTAB;
typedef struct sim_fileref FILEREF;
typedef struct sim_bitfield BITFIELD;