chiark / gitweb /
better handling of resolution problems
authorian <ian>
Sun, 8 Jun 2008 15:16:01 +0000 (15:16 +0000)
committerian <ian>
Sun, 8 Jun 2008 15:16:01 +0000 (15:16 +0000)
hostside/gui
hostside/gui-plan.c
hostside/multiplex
hostside/multiplex-config
hostside/xg.gdb [new file with mode: 0644]

index e06579f8f3c798cc7d014f25ed951e7190291158..fa04dd7de2ceb002739e98f3f13754024d53279b 100755 (executable)
@@ -690,9 +690,16 @@ proc train-event-eof {args} {
 register-event ?stastate {ctxch state} {^(.)stastate (\w+|\-) } {
     global ctrain trains stastate
     set stastate $state
+    report-problem "stastate: $state"
     if {[string compare $ctxch |]} speedws-stastate-hook
 }
 
+register-event ?resolution_inexplicable {message} \
+       {^.resolution (\S+ .*)$} {
+    if {[string match "problems *" $message]} return
+    report-problem "resolution: $message"
+}
+
 register-event {} {} {^=connected } {
     global pages gui_pipe server port event_selections
 
index 69a31d8f8851ff5c4eb920815598dd6b25633235..f59c0b47a921c248c932e967a7bab49e40e89b38 100644 (file)
@@ -26,6 +26,7 @@ typedef int ErrorCode;
 #include "dliste.h"
 #include "../layout/plan-data-format.h"
 #include "../layout/layout-data.h"
+#include "stastate.h"
 
 #include <oop.h>
 #include <oop-read.h>
@@ -46,7 +47,8 @@ struct PosnState {
 };
 
 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;
@@ -74,6 +76,7 @@ typedef struct {
 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;
@@ -81,6 +84,8 @@ static int redraw_needed_count, expose_count;
 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;
 
@@ -513,6 +518,8 @@ static void mx_redraw_feat(int s, int f) {
   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);
 }
 
@@ -529,12 +536,16 @@ static void mx_redraw_all(void) {
     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);
@@ -572,8 +583,7 @@ static void si_polarity(ParseState *ps) {
 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; }
 
@@ -660,6 +670,42 @@ struct MuxEventInfo {
 };
 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;
@@ -721,21 +767,26 @@ static void si_ack(ParseState *ps) {
 }
 
 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 }
 };
 
index 2b2a038bcb98594ac95859724bb2de3efb70285d..bc8beb412090bceb91d72e50c54ee94fc6681aa1 100755 (executable)
@@ -113,7 +113,7 @@ proc savereplay-clear-re {re} { # re is anchored at start
     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) }
     }
 }
 
@@ -182,8 +182,13 @@ proc global/!save-dump {conn args} {
 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"
+       }
     }
 }
 
@@ -366,7 +371,6 @@ proc xmit-only-noreport {conn msg} {
     if {[msel/$conn $msg]} { xmit-puts $conn $msg }
 }
 proc xmit-only {conn msg} {
-    puts "<$conn $msg"
     xmit-only-noreport $conn $msg
 }
 
@@ -555,7 +559,9 @@ proc realtime-inputline {dummy l} {
                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]} {
@@ -576,7 +582,7 @@ proc realtime-inputline {dummy l} {
        if {[info exists value]} {
            set rep $value
        } else {
-           append rep $value
+           append rep $addvalue "\n"
        }
     }
 
@@ -681,7 +687,7 @@ proc binding {addr blist} {
 }
 
 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]}
@@ -693,6 +699,7 @@ proc startup {} {
     realtime-notrunning-init
     if {!$testmode} {
        start_commandloop
+       realtime-start $realtime_xopts
     } else {
        fconfig-trainproto stdin
        fconfig-trainproto stdout
index 4e87d3a94dd7f204a5669c051619c3032a3c632b..5a5ec922d17a203c72ccd9e87f3ad43a58955033 100644 (file)
@@ -15,3 +15,4 @@ set records {
        homes.record
 }
 set detectlag 100
+set realtime_xopts {}
diff --git a/hostside/xg.gdb b/hostside/xg.gdb
new file mode 100644 (file)
index 0000000..2f4317b
--- /dev/null
@@ -0,0 +1,6 @@
+file ./gui-plan-bot
+set args @localhost,2883
+
+break mx_resolution_problem
+
+run