chiark / gitweb /
add topology-dump; add information about fixed segments to layout-data.c
authorian <ian>
Wed, 28 May 2008 18:18:04 +0000 (18:18 +0000)
committerian <ian>
Wed, 28 May 2008 18:18:04 +0000 (18:18 +0000)
hostside/.cvsignore
hostside/Makefile
hostside/README.commands
hostside/daemons.h
hostside/topology-dump.c [new file with mode: 0644]
layout/data2safety
layout/layout-data.h

index c634ab7aede18a0dcb4f2365f59e15e39bd7bbf5..89bed14076415b0d4f7ba5563db8020eacb16845 100644 (file)
@@ -2,6 +2,7 @@ realtime
 hostside-old
 hostside
 safety
+topology-dump
 t
 u
 t.*
index eff205b60b5df54ee7489365d606aa2d680a65f6..7971012664c70e7bb107cf6c68085bec1cda5603 100644 (file)
@@ -5,7 +5,7 @@ TRAINS=         santafe shinkansen
 AUTOINCS=      auproto-pic.h layoutinfo.h selectors.h retransmit-table.h \
                errorcodes.h stastate.h record-y.h record-l.h \
                realtime+dflags.h
-TARGETS=       hostside-old gui-plan-bot realtime \
+TARGETS=       hostside-old gui-plan-bot realtime topology-dump \
                $(addsuffix .speeds.ps, $(TRAINS)) \
                $(addsuffix .speeds.record, $(TRAINS))
 
@@ -47,6 +47,9 @@ realtime:     $(REALTIME_CORE_OBJS)                           \
 proto-expanded:        ../cebpic/README.protocol
                expand <$< $o
 
+topology-dump: topology-dump.o utils.o ../layout/ours.layout-data.o
+               $(LINK)
+
 gui-plan-bot: gui-plan-%: gui-plan.o utils.o parseutils.o obc.o \
                 ../layout/ours.dgram-%.plandata.o \
                 __oop-read-copy.o -loop
index afa30aa31a114c2e3747da13e19b39c1b873830d..0d69e3f81f9281a12639d46b9612768db9bd0f63 100644 (file)
@@ -4,6 +4,8 @@ Protocol over new hostside stdin and to multiplexer:
  R<   ditto, but saved for replay too
  S    messages to simulation log
 
+ D<   static data printed by topology-dump
+
  C>   commands (reflected to other clients)
  L>   commands implemented by multiplexer and not reflected to other clients
  O<   framming output from commands
@@ -188,3 +190,13 @@ DIRECT NMRA AND PIC INSTRUCTIONS
     !pic =<pic-bytes>    and
     !nmra _<pic-bytes>
  do exactly the same.
+
+======================================================================
+
+TOPOLOGY DUMP
+
+ D< topology segment <segment> <n_movfeats> <n_poscombs> i|n
+ D< topology movfeat <segment> <feat> <posns> <weight> point|relay
+ D< topology movposcomb <segment> <pname>|- \
+             <posn> <dist> [-]<backwards>|- [-]<forwards>|-
+ D< topology movfeatfixed <segment> <feat> <posn>
index 655c42c545bb50f0840fd5e8940300d723b8a528..c103cdb0f63beb2cc38d743425b36967ca6f052a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * declarations common to
  *  - realtime daemon
- *  - multiplexer daemon
+ *  - gui-plan-* displayers
  */
 
 #ifndef DAEMONS_H
diff --git a/hostside/topology-dump.c b/hostside/topology-dump.c
new file mode 100644 (file)
index 0000000..8515a8d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * topology dumper
+ */
+
+#include "common.h"
+#include "../layout/layout-data.h"
+
+static const char *mfkpnames[/*MovFeatKind*/]=
+  { 0,"point","relay" };
+
+static void plink(const SegmentLinkInfo *p) {
+  putchar(' ');
+  if (!SOMEP(p->next)) { putchar('-'); return; }
+  if (p->next_backwards) putchar('-');
+  fputs(info_segments[p->next].pname,stdout);
+}
+
+const char *progname= "topology-dump";
+
+void die_hook(void) { }
+void die_vprintf_hook(const char *fmt, va_list al) { }
+
+int main(int argc, char **argv) {
+  const SegmentInfo *segi;
+  const MovFeatInfo *mfi;
+  const SegPosCombInfo *spci;
+  int segn, mfn, posn;
+
+  if (argc!=1) badusage("no arguments permitted");
+
+  for (segn=0, segi=info_segments; segn<info_nsegments; segn++, segi++) {
+    printf("topology segment %s %d %d %c\n", segi->pname,
+          segi->n_movfeats, segi->n_poscombs, "ni"[segi->invertible]);
+    for (mfn=0, mfi=segi->movfeats; mfn<segi->n_movfeats; mfn++, mfi++) {
+      MovFeatKind k= mfi->kind;
+      printf("topology movfeat %s %s %d %d %s\n", segi->pname, mfi->pname,
+            mfi->posns, mfi->weight, mfkpnames[k]);
+    }
+    for (mfn=0; mfn<segi->n_fixedmovfeats; mfn++, mfi++) {
+      printf("topology movfeatfixed %s %s %d\n", segi->pname, mfi->pname,
+            mfi->posns);
+    }
+    for (posn=0, spci=segi->poscombs; posn<segi->n_poscombs; posn++, spci++) {
+      printf("topology movposcomb %s %s %d %d", segi->pname,
+            segi->n_poscombs>1 ? spci->pname : "-",
+            posn, spci->dist);
+      plink(&spci->link[1]);
+      plink(&spci->link[0]);
+      putchar('\n');
+    }
+  }
+  mflushstdout();
+  return 0;
+}
index fa336be0e3488e300c1fab40617cfdaf8ba0d964..8a9c73eb74dfbe04acb15b7b41965e54c4004845 100755 (executable)
@@ -18,6 +18,7 @@ our (%segs);
 # $segs{$seg}{BoOb}
 # $segs{$seg}{Posns}
 # $segs{$seg}{FeatCount}                does not include Fixed
+# $segs{$seg}{FeatCountFixed}
 # $segs{$seg}{Feats}{$feat}{Kind}       Point, Fixed, or Relay
 # $segs{$seg}{Feats}{$feat}{Weight}     ) for Point or Relay only
 # $segs{$seg}{Feats}{$feat}{Posns}      ) for Point or Relay only
@@ -154,6 +155,7 @@ sub line_fixed () {
        Kind => Fixed,
        Fixed => $pos,
     });
+    $segs{$seg}{FeatCountFixed}++;
 }
 
 sub begin_segment () { }
@@ -170,7 +172,8 @@ sub line_segment () {
                                   Obj => $boob->{Obj} } : undef,
        Posns => 1,
        Feats => { },
-       FeatCount => 0
+       FeatCount => 0,
+       FeatCountFixed => 0
     };
     &{"line_segment_".($invertible?'invertible':'vanilla')}($boob);
 }
@@ -584,7 +587,7 @@ sub writeout () {
     my (@segs,$segn,$seg,$segr,$feat,$featv, $delim);
     my ($comb,$pi,$end,$boob);
     my ($node,$side,$otherend,$nodeotherside,$otherseg,$otherbackrelus);
-    my ($ourinter,$pcname,$intere,$intother);
+    my ($ourinter,$pcname,$intere,$intother,$fixedi);
     o("/* autogenerated - do not edit */\n\n");
     @segs=();
     for $seg (sort { nummap($a) cmp nummap($b) } keys %segs) {
@@ -680,7 +683,7 @@ sub writeout () {
        }
        o("\n};\n");
 
-       next unless $segr->{FeatCount};
+       next unless $segr->{FeatCount} || $segr->{FeatCountFixed};
 
        for $feat (keys %{ $segr->{Feats} }) {
            $featv= $segr->{Feats}{$feat};
@@ -697,13 +700,20 @@ sub writeout () {
            
        o("static const MovFeatInfo mfi_${seg}"."[]= {");
        $delim='';
-       for $feat (keys %{ $segr->{Feats} }) {
-           $featv= $segr->{Feats}{$feat};
-           next if exists $featv->{Fixed};
-           o("$delim\n");
-           o("  { \"$feat\", mfk_".lc($featv->{Kind}).",".
-             " $featv->{Posns}, $featv->{Weight}, mfbo_${seg}_$feat }");
-           $delim=',';
+       for $fixedi (qw(0 1)) {
+           for $feat (keys %{ $segr->{Feats} }) {
+               $featv= $segr->{Feats}{$feat};
+               next if $fixedi != !!exists $featv->{Fixed};
+               o("$delim\n");
+               o("  { \"$feat\", mfk_".lc($featv->{Kind}).",");
+               if (!$fixedi) {
+                   o(" $featv->{Posns}, $featv->{Weight}, mfbo_${seg}_$feat");
+               } else {
+                   o(" $featv->{Fixed}, 0, 0");
+               }
+               o(" }");
+               $delim=',';
+           }
        }
        o("\n};\n");
     }
@@ -721,9 +731,10 @@ sub writeout () {
     foreach $seg (@segs) {
        $segr= $segs{$seg};
        o("$delim\n");
-       o(sprintf " { %-7s%d,%d,%2d,%-9s%d,%-10s%-6s,%-7s",
+       o(sprintf " { %-7s%d,%d,%2d,%d,%-9s%d,%-10s%-6s,%-7s",
          "\"$seg\",",$segr->{InvBoOb}?1:0,$segr->{Inter}{Invert},
-         $segr->{FeatCount}, ($segr->{FeatCount} ? "mfi_$seg," : '0,'),
+         $segr->{FeatCount}, $segr->{FeatCountFixed},
+         ($segr->{FeatCount}||$segr->{FeatCountFixed}) ? "mfi_$seg," : '0,',
          $segr->{Posns}, "spci_$seg,",
          so_objboob(1, $segr, \$sensenum),
          so_boob(1, $segr->{InvBoOb}).',');
index 03b877208da5ec7ce3a458ca6785bbf6a045bd50..37801caa16402901a78ae496801c0dddaa3d6ec5 100644 (file)
@@ -27,8 +27,11 @@ typedef int Distance;
 typedef enum {
   mfk_none,
   mfk_point,
-  mfk_relay
-  /* must also add new entries to movpos.c:methods[] */
+  mfk_relay,
+  /* must also add new entries to movpos.c:methods[] and topology-dump.c */
+  /* only entries up to here are used by movpos.c, since only
+   *  the n_fixedmovfeats entries use mfk_ifxed. */
+  mfk_fixed
 } MovFeatKind;
 
 /*========== data from config files and layout cad/cam ==========*/
@@ -41,9 +44,9 @@ typedef struct {
 typedef struct {
   const char *pname;
   MovFeatKind kind;
-  Small posns;
-  MovPosComb weight;
-  const BoardObject *boob;
+  Small posns;             /* for mfk_fixed: is the actual position */
+  MovPosComb weight;       /* for mfk_fixed: is 0 */
+  const BoardObject *boob; /* for mfk_fixed: is 0 */
 } MovFeatInfo;
 
 typedef struct {
@@ -55,8 +58,8 @@ typedef struct {
 typedef struct {
   const char *pname;
   unsigned invertible:1, interferes_polarity_opposed:1;
-  Small n_movfeats;
-  const MovFeatInfo *movfeats;
+  Small n_movfeats, n_fixedmovfeats;
+  const MovFeatInfo *movfeats; /* first n_movfeats then n_fixedmovfeats */
   MovPosComb n_poscombs;
   const SegPosCombInfo *poscombs;
   BoardObject sense, invert;