chiark / gitweb /
coalesce flapping detection
authorian <ian>
Tue, 15 Jul 2008 20:34:42 +0000 (20:34 +0000)
committerian <ian>
Tue, 15 Jul 2008 20:34:42 +0000 (20:34 +0000)
hostside/realtime.c
hostside/realtime.h
hostside/safety.h
hostside/startup.c

index 9a73731f49ca34211d69292f39a33b79c4d78bfd..54c2ea9a7b795044245c19a6cedf494a37014a48 100644 (file)
@@ -495,6 +495,7 @@ int main(int argc, const char **argv) {
   cmdi.out.fd= 1;
   cmdi.out.error= obc_error;
   cmdi.doline= command_doline;
+  cmdi.out.empty= cmdi_output_bufferempty;
 
   debug_setup();
 
index 6df39a7451704e2a6e314b64b59a64f243434322..751fd9a074132a798ea8626a5083177633be2860 100644 (file)
@@ -122,6 +122,7 @@ void serial_moredata(PicInsn *buf);
 
 extern StartupState sta_state;
 extern const char *const stastatelist[];
+void cmdi_output_bufferempty(OutBufferChain *obc);
 
 void resolve_begin(void); /* from resolve.c */
 int resolve_complete(void);
index 992b998ba3252899c5efa31f1ae185a58e8d48b4..1f1fdafda92181eeced49fb094e896f4f9a55fd2 100644 (file)
@@ -75,7 +75,10 @@ struct Segment {
     moving:1, /* feature(s) have been told to change */
     mark0:1,mark1:1,mark2:1,mark3:1, /* for temporary private uses */
     res_movposset:1, /* we have set the position so it is known good */
-    res_detect:1; /* detection noticed here during resolution */
+    res_detect:1, /* detection noticed here during resolution */
+    detect_actual:1, /* last detection state received */
+    detect_reported:1; /* detection state reported to parent */
+  int detect_flaps;
   MovPosComb movposcomb; /* -1 means not known or moving */
   MovPosChange *motion; /* if ->moving, owned by movpos, otherwise by safety */
   TimeInterval until;            /* } for use by safety.c */
index 1e42ae82815e84abd8b90a9d80a6b41057fcb609..5fadd1a72d47cadf8118721562fc219eb5fd28cb 100644 (file)
@@ -284,6 +284,13 @@ void on_pic_spurious(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
 void on_pic_pointed(const PicInsnInfo *pii, const PicInsn *pi, int objnum) { }
 void on_pic_retriable(const PicInsnInfo *pii, const PicInsn *pi, int objnum){}
 
+static int coalescing_detects;
+
+static void detect_report_now(Segment *seg) {
+  ouprintf_only("detect %s %d\n", seg->i->pname, seg->detect_actual);
+  seg->detect_reported= seg->detect_actual;
+}
+
 static SegmentNum on_pic_detect_prep(int detyn, int objnum) {
   SegmentNum segn;
 
@@ -291,14 +298,44 @@ static SegmentNum on_pic_detect_prep(int detyn, int objnum) {
       (segn= info_segmentmap[objnum]) < 0)
     die("PIC sent detect%d @#%#x not in map",detyn,objnum);
 
+  Segment *seg= &segments[segn];
+  seg->detect_actual= detyn;
+
   if (!(picio_send_noise <= 1 &&
-       segments[segn].owner &&
-       segments[segn].det_ignore))
-    ouprintf_only("detect %s %d\n", info_segments[segn].pname, detyn);
+       seg->owner &&
+       seg->det_ignore)) {
+    if (cmdi.out.total >= 1024) coalescing_detects= 1;
+
+    if (coalescing_detects &&
+       seg->det_ignore &&
+       seg->detect_reported) {
+      assert(seg->detect_flaps < INT_MAX);
+      seg->detect_flaps++;
+    } else {
+      detect_report_now(seg);
+    }
+  }
 
   return segn;
 }
 
+void cmdi_output_bufferempty(OutBufferChain *obc) {
+  SEG_IV;
+  
+  if (!coalescing_detects) return;
+  coalescing_detects= 0;
+
+  FOR_SEG {
+    if (seg->detect_flaps) {
+      ouprintf_only("detect-flaps %s %d\n", segi->pname, seg->detect_flaps);
+      seg->detect_flaps= 0;
+    }
+    if (seg->detect_actual != seg->detect_reported) {
+      detect_report_now(seg);
+    }
+  }
+}
+
 void on_pic_detect1(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
   SegmentNum segn;
   Segment *seg;