From b910557f5225cb3f267bae49df92745c5efb87bc Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 2 Jan 2011 01:37:11 +0000 Subject: [PATCH] hostside/safety: correctly pass JUSTDET back to predict() inside safetymanager_safety_stop if need be (involves adding new predictflags arg to predict() et al) --- hostside/safety.c | 2 +- hostside/safety.h | 4 +++- hostside/speed.c | 16 +++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/hostside/safety.c b/hostside/safety.c index bb3d2ed..2780bc0 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -1264,7 +1264,7 @@ void safety_notify_detection(Segment *seg) { tra->maxinto= tra->uncertainty= maxinto; report_train_position(tra); - speedmanager_safety_stop(tra,tnow); + speedmanager_safety_stop(tra,tnow, PREDF_JUSTDET|PREDF_OLDPLAN); } ErrorCode safety_movposchange(Segment *seg, MovPosComb comb, diff --git a/hostside/safety.h b/hostside/safety.h index 4ab7b61..d61e88a 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -255,7 +255,9 @@ ErrorCode speedmanager_speedchange_request(Train *tra, int step, PredictionProblemCallback *ppc, void *ppcu); /* ppc and ppcu as for predict_confirm */ -void speedmanager_safety_stop(Train *tra, struct timeval tnow); +void speedmanager_safety_stop(Train *tra, struct timeval tnow, + unsigned predictflags); + /* Ignores value of PREDF_OLDPLAN */ void speedmanager_reset_train(Train *tra); void speedmanager_getinfo(Train *tra, struct timeval tnow, SpeedInfo*); diff --git a/hostside/speed.c b/hostside/speed.c index 06e57c9..44f21ac 100644 --- a/hostside/speed.c +++ b/hostside/speed.c @@ -107,7 +107,10 @@ int speedmanager_stopped(Train *tra) { } static ErrorCode request_core(Train *tra, int step, struct timeval tnow, + unsigned predictflags, PredictionProblemCallback *ppc, void *ppcu) { + /* We ignore the value of PREDF_OLDPLAN in predictflags, as we can tell + * whether the old plan is good by the change in speed */ ErrorCode ec, ec2; double vnow, vtarg, vmax; SpeedInfo try; @@ -140,13 +143,15 @@ static ErrorCode request_core(Train *tra, int step, struct timeval tnow, tra->uncertainty += tra->maxinto - oldmaxinto; } + predictflags &= ~PREDF_OLDPLAN; + ec= predict(tra,tnow, - step <= tra->speed.step ? PREDF_OLDPLAN : 0, + predictflags | (step <= tra->speed.step ? PREDF_OLDPLAN : 0), 0,0, &try, ppc,ppcu); if (ec) { tra->uncertainty -= tra->maxinto - oldmaxinto; tra->maxinto= oldmaxinto; - ec2= predict(tra,tnow, PREDF_OLDPLAN,0,0, 0, + ec2= predict(tra,tnow, predictflags | PREDF_OLDPLAN, 0,0, 0, 0,(char*)"abandoned acceleration"); assert(!ec2); return ec; @@ -172,12 +177,13 @@ ErrorCode speedmanager_speedchange_request(Train *tra, int step, MUSTECR( safety_checktrain(tra,ppc,ppcu) ); mgettimeofday(&tnow); - return request_core(tra,step,tnow,ppc,ppcu); + return request_core(tra,step, tnow,0, ppc,ppcu); } -void speedmanager_safety_stop(Train *tra, struct timeval tnow) { +void speedmanager_safety_stop(Train *tra, struct timeval tnow, + unsigned predictflags) { ErrorCode ec; - ec= request_core(tra,0,tnow,0,(char*)"emergency stop"); + ec= request_core(tra,0,tnow,predictflags, 0,(char*)"emergency stop"); assert(!ec); } -- 2.30.2