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 */
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;
(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;