From: ian Date: Sun, 13 Apr 2008 22:15:28 +0000 (+0000) Subject: check points wrong way X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=daaaf9a59811785491d058950cb0b5a932b91c09;p=trains.git check points wrong way --- diff --git a/hostside/TODO b/hostside/TODO index f3aaccf..4646e4f 100644 --- a/hostside/TODO +++ b/hostside/TODO @@ -2,7 +2,6 @@ dunno but maybe before can test wiring to gui display things not yet considered at all in safety code - coming up against points the wrong way min. curve specifications diff --git a/hostside/safety.c b/hostside/safety.c index 381f9fc..cca1f99 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -72,8 +72,6 @@ static void lay_train_check_clash(LayTrainState *l, Segment *check, return; } } - if (check->movposcomb < 0) - l->ec= safety_problem(l->tra, report, "track route not set"); } static void lay_train_pass(LayTrainState *l, @@ -129,7 +127,25 @@ static void lay_train_pass(LayTrainState *l, *(check_clash ? &seg->until_here : &seg->until_detect)= time_until; if (!remain) break; - trackloc_further(&tloc, &remain); + int r= trackloc_further(&tloc, &remain); + + if (r==-2) { + l->ec= safety_problem(l->tra, seg, "end of track"); + return; + } + if (r==-1) { + l->ec= safety_problem(l->tra, seg, "track route not set"); + return; + } + if (r>1) { + const SegPosCombInfo *pci= trackloc_segposcomb(&tloc); + const SegmentLinkInfo *link= trackloc_segmentlink(&tloc,pci,0); + if (link->next+segments != seg) { + l->ec= safety_problem(l->tra, link->next+segments, + "track route set against us"); + return; + } + } } } diff --git a/hostside/safety.h b/hostside/safety.h index 8796661..4d895a4 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -241,9 +241,16 @@ struct TrackLocation { /* transparent, and manipulable by trackloc_... fns */ long trackloc_remaininseg(const TrackLocation *tloc); /* Returns dist that tloc can advance before it goes into next segment. */ -void trackloc_further(TrackLocation *tloc, long *remain_io); - /* Advances tloc, decrementing *remain_io, until either - * *remain_io becomes zero, or tloc->segn changes. */ +int trackloc_further(TrackLocation *tloc, long *remain_io); + /* Advances tloc, decrementing *remain_io, until one of the + * following happens: + * tloc->segn changes returns +1 + * *remain_io becomes zero returns 0 + * unknown movpos found returns -1 + * end of track reached returns -2 + * Does _not_ check that the movposcomb of the segment we + * are moving into is correct. + */ void trackloc_reverse(TrackLocation *tloc); /* Reverses tloc without changing its actual location. */ diff --git a/hostside/trackloc.c b/hostside/trackloc.c index 0818c6b..4d0ba11 100644 --- a/hostside/trackloc.c +++ b/hostside/trackloc.c @@ -8,6 +8,7 @@ const SegPosCombInfo *trackloc_segposcomb(const TrackLocation *tloc) { Segment *seg= tloc->seg; + if (seg->movposcomb<0) return 0; assert(seg->movposcomb < seg->i->n_poscombs); return &seg->i->poscombs[seg->movposcomb]; } @@ -17,7 +18,7 @@ const SegmentLinkInfo *trackloc_segmentlink(const TrackLocation *tloc, unsigned far) { return (tloc->backwards ^ far) ? &pci->backwards : &pci->forwards; } - + long trackloc_remaininseg(const TrackLocation *tloc) { const SegPosCombInfo *pci; long segment_len; @@ -28,7 +29,7 @@ long trackloc_remaininseg(const TrackLocation *tloc) { return segment_len - tloc->into; } -void trackloc_further(TrackLocation *tloc, long *remain_io) { +int trackloc_further(TrackLocation *tloc, long *remain_io) { const SegPosCombInfo *pci; const SegmentLinkInfo *lnki_far; long segment_remain; @@ -38,13 +39,18 @@ void trackloc_further(TrackLocation *tloc, long *remain_io) { if (*remain_io <= segment_remain) { tloc->into += *remain_io; *remain_io= 0; + return 0; } else { + *remain_io -= segment_remain; + tloc->into += segment_remain; pci= trackloc_segposcomb(tloc); + if (!pci) return -1; lnki_far= trackloc_segmentlink(tloc, pci, 1); - *remain_io -= segment_remain; + if (!SOMEP(lnki_far->next)) return -2; tloc->seg= &segments[lnki_far->next]; tloc->into= 0; tloc->backwards ^= lnki_far->next_backwards; + return +1; } }