From: ian Date: Sun, 18 May 2008 11:59:36 +0000 (+0000) Subject: sort out !movpos crashing sometimes X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=04bc611cb3b9fd157947b88d5ec22180efac3ec1;p=trains.git sort out !movpos crashing sometimes --- diff --git a/hostside/commands.c b/hostside/commands.c index 9b1205c..7da070c 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -240,7 +240,7 @@ static int cmd_movpos(ParseState *ps, const CmdInfo *ci) { MUSTECR( ps_needsegmentperhaps(ps,&move,&movei) ); MUSTECR( ps_needword(ps) ); if (CTYPE(isdigit,*ps->thisword)) { - if (!move) badcmd(ps,"invalid movement specification"); + if (!move) return badcmd(ps,"invalid movement specification"); ps_pushbackword(ps); MUSTECR( ps_neednumber(ps,&poscomb_l,0,movei->n_poscombs, "position number") ); @@ -259,11 +259,14 @@ static int cmd_movpos(ParseState *ps, const CmdInfo *ci) { MUSTECR( ps_neednoargs(ps) ); - if (ci->xarg & CIXF_FORCE) + if (ci->xarg & CIXF_FORCE) { + if (!(sta_state < Sta_Resolving || sta_state == Sta_Manual)) + return badcmd(ps,"movpos queueing arrangements not ready"); MUSTECR( movpos_change(move,poscomb,ms,0) ); - else + } else { MUSTECRPREDICT( safety_movposchange(move, poscomb, ci->xarg & CIXF_U, CMDPPC) ); + } return 0; } @@ -296,6 +299,29 @@ static int cmd_invert(ParseState *ps, const CmdInfo *ci) { return 0; } +/*---------- general machinery and the command table ----------*/ + +void command_doline(ParseState *ps, CommandInput *cmdi_arg) { + int r; + + simlog("command-in %s\n",ps->remain); + simlog_flush(); + current_cmd= 0; + current_cmd= some_needword_lookup(ps, toplevel_cmds, "command"); + if (!current_cmd) return; + oprintf(UPO, "executing %s\n",current_cmd->name); + if (sta_state < Sta_Run && !(current_cmd->xarg & CIXF_ANYSTA)) { + oprintf(UPO,"ack %s InvalidState : layout not ready\n",current_cmd->name); + return; + } + r= current_cmd->fn(ps,current_cmd); + switch (r) { + case 0: oprintf(UPO, "ack %s ok\n", current_cmd->name); break; + case EC_BadCmd: break; + default: oprintf(UPO, "ack %s %s\n", current_cmd->name, errorcodelist[r]); break; + } +} + const CmdInfo toplevel_cmds[]= { { "!pic", cmd_pic, CIXF_ANYSTA|CIXF_FORCE }, { "!nmra", cmd_nmra, CIXF_ANYSTA }, diff --git a/hostside/realtime.c b/hostside/realtime.c index ae8c804..8b246c8 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -168,36 +168,13 @@ static void oprint_nmradata(const PicInsn *pi) { /*---------- command channel handling (oop_read, obc) ----------*/ -static const CmdInfo *ci; - int vbadcmd(ParseState *ps, const char *fmt, va_list al) { - oprintf(UPO,"ack %s BadCmd : ", ci?ci->name:"?"); + oprintf(UPO,"ack %s BadCmd : ", current_cmd?current_cmd->name:"?"); ovprintf(UPO,fmt,al); oprintf(UPO,"\n"); return EC_BadCmd; } -static void command_doline(ParseState *ps, CommandInput *cmdi_arg) { - int r; - - simlog("command-in %s\n",ps->remain); - simlog_flush(); - ci= 0; - ci= some_needword_lookup(ps, toplevel_cmds, "command"); - if (!ci) return; - oprintf(UPO, "executing %s\n",ci->name); - if (sta_state < Sta_Run && !(ci->xarg & CIXF_ANYSTA)) { - oprintf(UPO,"ack %s InvalidState : layout not ready\n",ci->name); - return; - } - r= ci->fn(ps,ci); - switch (r) { - case 0: oprintf(UPO, "ack %s ok\n", ci->name); break; - case EC_BadCmd: break; - default: oprintf(UPO, "ack %s %s\n", ci->name, errorcodelist[r]); break; - } -} - void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v) { if (!pii->argsbits) oprintf(UPO, "picio %s %s\n", dirn, pii->name); diff --git a/hostside/realtime.h b/hostside/realtime.h index f1aa19c..be9ed90 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -113,9 +113,9 @@ extern int picio_send_noise; #define UPO (&(cmdi.out)) -#define CIXF_U 0x00ffffu -#define CIXF_ANYSTA 0x010000u -#define CIXF_FORCE 0x020000u +#define CIXF_U 0x0000ffffu +#define CIXF_FORCE 0x00010000u +#define CIXF_ANYSTA 0x00020000u /*---------- from/for startup.c ----------*/ @@ -154,6 +154,8 @@ void ouhexi(const char *word, const Byte *command, int length); void ouhexo(const char *word, const Byte *command, int length); void serial_transmit(const PicInsn *pi); +void command_doline(ParseState *ps, CommandInput *cmdi_arg); +const CmdInfo *current_cmd; /*---------- for/from simulate.c ----------*/