1
0
mirror of https://github.com/open-simh/simh.git synced 2026-05-05 15:43:58 +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

@@ -1530,15 +1530,17 @@ uint32 tmp;
tmxr_debug_trace_line (lp, "tmxr_getc_ln()");
if (lp->conn && lp->rcve) { /* conn & enb? */
j = lp->rxbpi - lp->rxbpr; /* # input chrs */
if (j) { /* any? */
tmp = lp->rxb[lp->rxbpr]; /* get char */
val = TMXR_VALID | (tmp & 0377); /* valid + chr */
if (lp->rbr[lp->rxbpr]) { /* break? */
lp->rbr[lp->rxbpr] = 0; /* clear status */
val = val | SCPE_BREAK; /* indicate to caller */
if (!sim_send_poll_data (&lp->send, &val)) { /* injected input characters available? */
j = lp->rxbpi - lp->rxbpr; /* # input chrs */
if (j) { /* any? */
tmp = lp->rxb[lp->rxbpr]; /* get char */
val = TMXR_VALID | (tmp & 0377); /* valid + chr */
if (lp->rbr[lp->rxbpr]) { /* break? */
lp->rbr[lp->rxbpr] = 0; /* clear status */
val = val | SCPE_BREAK; /* indicate to caller */
}
lp->rxbpr = lp->rxbpr + 1; /* adv pointer */
}
lp->rxbpr = lp->rxbpr + 1; /* adv pointer */
}
} /* end if conn */
if (lp->rxbpi == lp->rxbpr) /* empty? zero ptrs */
@@ -1816,6 +1818,7 @@ if ((lp->txbfd && !lp->notelnet) || (TXBUF_AVAIL(lp) > 1)) {/* room for char (+
lp->xmte = 0; /* disable line */
if (lp->txlog) /* log if available */
fputc (chr, lp->txlog);
sim_exp_check (&lp->expect, chr); /* process expect rules as needed */
return SCPE_OK; /* char sent */
}
++lp->txdrp; lp->xmte = 0; /* no room, dsbl line */
@@ -3198,6 +3201,9 @@ for (i=0; i<tmxr_open_device_count; ++i)
if (!found) {
tmxr_open_devices = (TMXR **)realloc(tmxr_open_devices, (tmxr_open_device_count+1)*sizeof(*tmxr_open_devices));
tmxr_open_devices[tmxr_open_device_count++] = mux;
for (i=0; i<mux->lines; i++)
if (0 == mux->ldsc[i].send.delay)
mux->ldsc[i].send.delay = SEND_DEFAULT_DELAY;
}
#if defined(SIM_ASYNCH_IO) && defined(SIM_ASYNCH_MUX)
pthread_mutex_unlock (&sim_tmxr_poll_lock);
@@ -3226,6 +3232,46 @@ pthread_mutex_unlock (&sim_tmxr_poll_lock);
#endif
}
static t_stat _tmxr_locate_line_send_expect (const char *cptr, SEND **snd, EXPECT **exp)
{
char gbuf[CBUFSIZE];
DEVICE *dptr;
int i;
t_stat r;
if (snd)
*snd = NULL;
if (exp)
*exp = NULL;
cptr = get_glyph(cptr, gbuf, ':');
dptr = find_dev (gbuf); /* device match? */
if (!dptr)
return SCPE_ARG;
for (i=0; i<tmxr_open_device_count; ++i)
if (tmxr_open_devices[i]->dptr == dptr) {
int line = (int)get_uint (cptr, 10, tmxr_open_devices[i]->lines, &r);
if (r != SCPE_OK)
return r;
if (snd)
*snd = &tmxr_open_devices[i]->ldsc[line].send;
if (exp)
*exp = &tmxr_open_devices[i]->ldsc[line].expect;
return SCPE_OK;
}
return SCPE_ARG;
}
t_stat tmxr_locate_line_send (const char *cptr, SEND **snd)
{
return _tmxr_locate_line_send_expect (cptr, snd, NULL);
}
t_stat tmxr_locate_line_expect (const char *cptr, EXPECT **exp)
{
return _tmxr_locate_line_send_expect (cptr, NULL, exp);
}
t_stat tmxr_change_async (void)
{
#if defined(SIM_ASYNCH_IO)
@@ -3812,6 +3858,10 @@ if (lp->modem_control) {
if ((lp->serport == 0) && (lp->sock) && (!lp->datagram))
fprintf (st, " %s\n", (lp->notelnet) ? "Telnet disabled (RAW data)" : "Telnet protocol");
if (lp->send.buffer)
sim_show_send_input (st, &lp->send);
if (lp->expect.buf)
sim_exp_showall (st, &lp->expect);
if (lp->txlog)
fprintf (st, " Logging to %s\n", lp->txlogname);
return;