#include "dliste.h"
#include "../layout/plan-data-format.h"
#include "../layout/layout-data.h"
+#include "stastate.h"
#include <oop.h>
#include <oop-read.h>
};
typedef struct {
- unsigned on:1, inv:1, det:1, trainown:2, updated_tmp:1;
+ unsigned on:1, inv:1, det:1, trainown:2, updated_tmp:1,
+ resolution_problem:1; /* for multiplexer client only */
} SegFlags;
typedef struct SegmovfeatState SegmovfeatState;
static FILE *debug;
static SegState *state;
static SegmovfeatState *states_head;
+static StartupState stastate;
static Display *d;
static oop_source_sys *sys_events;
static Window w;
static Pixmap bg_pixmap;
static unsigned long train_pixel, owned_pixel;
+static const char *stastate_names[]= DEFINE_STASTATE_DATA;
+
static const char *badcmdreport_data;
static size_t badcmdreport_recsz;
SegmovfeatState *fs= &ss->mfs[f];
fs->flags= ss->flags;
fs->flags.on= poweron;
+ if (stastate==Sta_Resolving)
+ fs->flags.trainown= ss->flags.resolution_problem ? 2 : 0;
redraw_mark(fs);
}
mx_redraw_seg(s);
}
+static int ps_needsegment(ParseState *ps) {
+ int r= ps_needword(ps); if (r) return -1;
+ return lstrpdbsearch_segment(ps->thisword,ps->lthisword);
+}
+
static void si_detect(ParseState *ps) {
long dl;
int r, s;
- r= ps_needword(ps); if (r) return;
- s= lstrpdbsearch_segment(ps->thisword,ps->lthisword); if (s==-1) return;
+ s= ps_needsegment(ps); if (s<0) return;
r= ps_neednumber(ps,&dl,0,1,"detection flag"); if (r) return;
state[s].flags.det= dl;
mx_redraw_seg(s);
static void si_movpos(ParseState *ps) {
long pl;
int r,s,f, n_posns;
- r= ps_needword(ps); if (r) return;
- s= lstrpdbsearch_segment(ps->thisword,ps->lthisword); if (s<0) return;
+ s= ps_needsegment(ps); if (s<0) return;
r= ps_needword(ps); if (r) return;
if (thiswordstrcmp(ps,"feat")) { badcmd(ps,"weird movpos"); return; }
};
static const MuxEventInfo muxeventinfos[];
+static void si_stastate(ParseState *ps) {
+ int s;
+ const char *const *new_stastate;
+
+ new_stastate= some_needword_lookup(ps, stastate_names, "stastate");
+ stastate= new_stastate ? new_stastate - stastate_names : 0;
+
+ FOR_S {
+ state[s].flags.resolution_problem= 0;
+ }
+ if (stastate <= Sta_Resolving) {
+ FOR_S {
+ state[s].flags.det= 0;
+ state[s].flags.trainown= 0;
+ }
+ }
+ mx_redraw_all();
+}
+
+static void mx_resolution_problem(int s) {
+ state[s].flags.resolution_problem= 1;
+ mx_redraw_seg(s);
+}
+static void si_resolution_inexplicable(ParseState *ps) {
+ int s;
+ s= ps_needsegment(ps); if (s<0) return;
+ mx_resolution_problem(s);
+}
+static void si_resolution_mispositioned(ParseState *ps) {
+ int r, s;
+ r= ps_needword(ps); /* head|tail */ if (r) return;
+ r= ps_needword(ps); /* <train> */ if (r) return;
+ s= ps_needsegment(ps); if (s<0) return;
+ mx_resolution_problem(s);
+}
+
static void si_connected(ParseState *ps) {
const MuxEventInfo *mxi;
const char *p;
}
static const MuxEventInfo muxeventinfos[]= {
- { "?detect", "", si_detect },
- { "?picio out polarity", "", si_polarity },
- { "?movpos", "_*_feat", si_movpos },
- { "?picio out on", "", si_on },
- { "?picio out off", "", si_off },
- { "?train", "_*_has", si_train },
-
- { "=connected", "", si_connected },
- { "=permission", "", 0 },
-
- { "+executing", 0, 0 },
- { "+ack", 0, si_ack },
- { "+nak", 0, si_fatal },
- { "=failed", 0, si_fatal },
- { "=denied", 0, si_fatal },
+ { "?detect", "", si_detect },
+ { "?picio out polarity", "", si_polarity },
+ { "?movpos", "_*_feat", si_movpos },
+ { "?picio out on", "", si_on },
+ { "?picio out off", "", si_off },
+ { "?train", "_*_has", si_train },
+
+ { "?stastate", "", si_stastate },
+
+ { "?resolution inexplicable", "", si_resolution_inexplicable },
+ { "?resolution mispositioned", "", si_resolution_mispositioned },
+
+ { "=connected", "", si_connected },
+ { "=permission", "", 0 },
+
+ { "+executing", 0, 0 },
+ { "+ack", 0, si_ack },
+ { "+nak", 0, si_fatal },
+ { "=failed", 0, si_fatal },
+ { "=denied", 0, si_fatal },
{ 0 }
};
global replay
if {![info exists replay]} return
foreach pk [array names replay] {
- if {[regexp -- ^$re $pk]} { unset replay($pk) }
+ if {[regexp -- ^$re "$pk "]} { unset replay($pk) }
}
}
proc do-replay {conn} {
global replay
foreach pk [lsort [array names replay]] {
- set m "|[string range $pk 3 end] $replay($pk)"
- xmit-only $conn $m
+ set pri [string range $pk 0 2]
+ set lhs [string range $pk 3 end]
+ set r [string trimright $replay($pk) "\n"]
+ foreach m [split $r "\n"] {
+ puts "<$conn|$pri|$lhs $m"
+ xmit-only-noreport $conn "|$lhs $m"
+ }
}
}
if {[msel/$conn $msg]} { xmit-puts $conn $msg }
}
proc xmit-only {conn msg} {
- puts "<$conn $msg"
xmit-only-noreport $conn $msg
}
clear-replay-detects
savereplay-clear-re {^60 train \S+ speed }
}
- Resolving { catch { unset replay("50 resolution") } }
+ Resolving {
+ savereplay-clear-re {^50 resolution }
+ }
}
set pri 10
} elseif {[regexp {^(resolution) (.*)$} $l dummy key addvalue]} {
if {[info exists value]} {
set rep $value
} else {
- append rep $value
+ append rep $addvalue "\n"
}
}
}
proc startup {} {
- global queueing executing testmode realtime port
+ global queueing executing testmode realtime port realtime_xopts
catch { close $master }; catch { unset master }
setting testmode 0 {[01]}
realtime-notrunning-init
if {!$testmode} {
start_commandloop
+ realtime-start $realtime_xopts
} else {
fconfig-trainproto stdin
fconfig-trainproto stdout