minor bugfixes + more debug logging

This commit is contained in:
Stephan Richter
2021-03-29 20:09:15 +02:00
parent da2ad054ed
commit 0dde9693d1
11 changed files with 66 additions and 27 deletions

View File

@@ -40,8 +40,8 @@ public class BrakeProcess extends BaseClass implements Runnable{
long dist = 0;
int s = startSpeed;
while (s > Train.defaultEndSpeed) {
s -= SPEED_STEP;
dist += s*ts;
s -= SPEED_STEP;
}
LOG.debug("Estimated distamce with {} ms timestep: {}",ts,dist);
return dist;
@@ -56,6 +56,7 @@ public class BrakeProcess extends BaseClass implements Runnable{
@Override
public void run() {
timeStep = train.route().brakeTime(train.brakeId());
LOG.debug("{}.run() with timestep = {} ms",this,timeStep);
if (timeStep == null) timeStep = defaultTimeStep;
startSpeed = train.speed;
lastTime = timestamp();
@@ -100,7 +101,7 @@ public class BrakeProcess extends BaseClass implements Runnable{
if (!newTimeStep.equals(timeStep)) {
route.brakeTime(brakeId,newTimeStep);
calculated = calcDistance(newTimeStep);
LOG.debug("Corrected brake timestep for {} @ {} from {} to {} ms.",train,route,timeStep,newTimeStep);
LOG.debug("Corrected brake timestep from {} to {} ms for {} @ {}.",timeStep,newTimeStep,train,route);
LOG.debug("Differemce from estimated distance: {} ({}%)",distance-calculated,100*(distance-calculated)/(float)distance);
}
}

View File

@@ -22,9 +22,10 @@ public class RoutePrepper extends BaseClass implements Runnable{
private List<EventListener> failListeners = new LinkedList<>();
private List<EventListener> foundListeners = new LinkedList<>();
private List<EventListener> lockedListeners = new LinkedList<>();
private List<EventListener> preparedListeners= new LinkedList<>();
private EventListener preparedListener = null;
public RoutePrepper(Context c) {
LOG.debug("new RoutePrepper({})",c);
List<String> errors = new LinkedList<>();
if (isNull(c.train())) errors.add(t("No train in context for {}",getClass().getSimpleName()));
if (isNull(c.block())) errors.add(t("No block in context for {}",getClass().getSimpleName()));
@@ -182,7 +183,7 @@ public class RoutePrepper extends BaseClass implements Runnable{
}
public void onRoutePrepared(EventListener l) {
preparedListeners.add(l);
preparedListener = l;
}
@@ -196,7 +197,7 @@ public class RoutePrepper extends BaseClass implements Runnable{
if (!route.reserveFor(context)) return fail();
notify(lockedListeners);
if (!route.prepareAndLock()) return fail();
notify(preparedListeners);
if (isSet(preparedListener)) preparedListener.fire();
return true;
}
@@ -207,6 +208,7 @@ public class RoutePrepper extends BaseClass implements Runnable{
@Override
public void run() {
LOG.debug("{}.run()",this);
prepareRoute();
}
@@ -217,4 +219,9 @@ public class RoutePrepper extends BaseClass implements Runnable{
public void stop() {
context.invalidate();
}
@Override
public String toString() {
return getClass().getSimpleName()+"("+context+")";
}
}