From: ian Date: Tue, 15 Jul 2008 20:34:42 +0000 (+0000) Subject: coalesce flapping detection X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=adc39046f0335c8c5badc53ab9cbee1d04f73672;p=trains.git coalesce flapping detection --- diff --git a/hostside/realtime.c b/hostside/realtime.c index 9a73731..54c2ea9 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -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(); diff --git a/hostside/realtime.h b/hostside/realtime.h index 6df39a7..751fd9a 100644 --- a/hostside/realtime.h +++ b/hostside/realtime.h @@ -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); diff --git a/hostside/safety.h b/hostside/safety.h index 992b998..1f1fdaf 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -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 */ diff --git a/hostside/startup.c b/hostside/startup.c index 1e42ae8..5fadd1a 100644 --- a/hostside/startup.c +++ b/hostside/startup.c @@ -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;