Browse Source

bugfixes

lookup-tables
Stephan Richter 5 years ago
parent
commit
92923aec30
  1. 2
      pom.xml
  2. 8
      resources/logback.xml
  3. 2
      resources/translations/Application.de.translation
  4. 2
      src/main/java/de/srsoftware/web4rail/Command.java
  5. 9
      src/main/java/de/srsoftware/web4rail/ControlUnit.java
  6. 2
      src/main/java/de/srsoftware/web4rail/PathFinder.java
  7. 8
      src/main/java/de/srsoftware/web4rail/Route.java
  8. 15
      src/main/java/de/srsoftware/web4rail/moving/Train.java
  9. 2
      src/main/java/de/srsoftware/web4rail/tiles/Contact.java
  10. 25
      src/main/java/de/srsoftware/web4rail/tiles/Tile.java

2
pom.xml

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId> <groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId> <artifactId>web4rail</artifactId>
<version>1.2.53</version> <version>1.2.54</version>
<name>Web4Rail</name> <name>Web4Rail</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Java Model Railway Control</description> <description>Java Model Railway Control</description>

8
resources/logback.xml

@ -1,4 +1,5 @@
<configuration> <configuration scan="true">
<!-- scan="true" enables automatic updates if config file changes, see http://logback.qos.ch/manual/configuration.html -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder> <encoder>
@ -6,10 +7,11 @@
</encoder> </encoder>
</appender> </appender>
<logger name="de.srsoftware.web4rail" level="INFO"/> <logger name="de.srsoftware.web4rail" level="DEBUG"/>
<logger name="de.srsoftware.web4rail.Application" level="INFO"/> <logger name="de.srsoftware.web4rail.Application" level="DEBUG"/>
<logger name="de.srsoftware.web4rail.Command" level="INFO"/> <logger name="de.srsoftware.web4rail.Command" level="INFO"/>
<logger name="de.srsoftware.web4rail.ControlUnit" level="INFO"/> <logger name="de.srsoftware.web4rail.ControlUnit" level="INFO"/>
<logger name="de.srsoftware.web4rail.moving" level="DEBUG"/>
<root level="info"> <root level="info">
<appender-ref ref="STDOUT" /> <appender-ref ref="STDOUT" />

2
resources/translations/Application.de.translation

@ -148,7 +148,7 @@ NORTH : Norden
Not connected to other bridge part! : Nicht mit anderem Brücken-Teil verbunden! Not connected to other bridge part! : Nicht mit anderem Brücken-Teil verbunden!
Notes : Notizen Notes : Notizen
No tile moved. : keine Kachel verschoben. No tile moved. : keine Kachel verschoben.
{} now heading for {} : {} ist nun unterweg nach {} {} now heading for {} : {} ist nun unterwegs nach {}
{} now in auto-mode : {} ist nun im Automatikmodus {} now in auto-mode : {} ist nun im Automatikmodus
Occupied area\: : Belegte Abschnitte: Occupied area\: : Belegte Abschnitte:
Off : Aus Off : Aus

2
src/main/java/de/srsoftware/web4rail/Command.java

@ -38,7 +38,7 @@ public class Command {
milis = Integer.parseInt(word.substring(word.length()-3)); milis = Integer.parseInt(word.substring(word.length()-3));
code = scanner.nextInt(); code = scanner.nextInt();
message = scanner.nextLine().trim(); message = scanner.nextLine().trim();
LOG.info("recv {}.{} {} {}.",secs,milis,code,message); LOG.debug("recv {}.{} {} {}.",secs,milis,code,message);
} }
/** /**

9
src/main/java/de/srsoftware/web4rail/ControlUnit.java

@ -256,7 +256,7 @@ public class ControlUnit extends Thread implements Constants{
if (command == null || command.toString() == null) return; if (command == null || command.toString() == null) return;
String data = command.toString().replace("{}", ""+bus); String data = command.toString().replace("{}", ""+bus);
commandSocket.getOutputStream().write((data+"\n").getBytes(StandardCharsets.US_ASCII)); commandSocket.getOutputStream().write((data+"\n").getBytes(StandardCharsets.US_ASCII));
LOG.info("sent {}.",data); LOG.debug("sent {}.",data);
command.readReplyFrom(commandScanner); command.readReplyFrom(commandScanner);
} }
@ -315,7 +315,12 @@ public class ControlUnit extends Thread implements Constants{
case FEEDBACK: case FEEDBACK:
int addr = Integer.parseInt(parts[5]); int addr = Integer.parseInt(parts[5]);
boolean active = !parts[6].equals("0"); boolean active = !parts[6].equals("0");
ControlUnit.this.plan.sensor(addr,active); new Thread() {
@Override
public void run() {
ControlUnit.this.plan.sensor(addr,active);
}
}.start();
case ACESSORY: case ACESSORY:
break; break;
default: default:

2
src/main/java/de/srsoftware/web4rail/PathFinder.java

@ -14,7 +14,7 @@ import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tiles.Block; import de.srsoftware.web4rail.tiles.Block;
public class PathFinder extends BaseClass{ public class PathFinder extends BaseClass{
private static final Logger LOG = LoggerFactory.getLogger(PathFinder.class); public static final Logger LOG = LoggerFactory.getLogger(PathFinder.class);
private static TreeMap<Integer,List<Route>> availableRoutes(Context context,HashSet<Route> visitedRoutes){ private static TreeMap<Integer,List<Route>> availableRoutes(Context context,HashSet<Route> visitedRoutes){
LOG.debug("PathFinder.availableRoutes({})",context); LOG.debug("PathFinder.availableRoutes({})",context);

8
src/main/java/de/srsoftware/web4rail/Route.java

@ -54,7 +54,7 @@ public class Route extends BaseClass {
public enum State { public enum State {
FREE, LOCKED, PREPARED, STARTED; FREE, LOCKED, PREPARED, STARTED;
} }
private static final Logger LOG = LoggerFactory.getLogger(Route.class); public static final Logger LOG = LoggerFactory.getLogger(Route.class);
private static final String ACTIONS = "actions"; private static final String ACTIONS = "actions";
private static final String BRAKE_TIMES = "brake_times"; private static final String BRAKE_TIMES = "brake_times";
@ -439,6 +439,7 @@ public class Route extends BaseClass {
train.setWaitTime(endBlock.getWaitTime(train,train.direction())); train.setWaitTime(endBlock.getWaitTime(train,train.direction()));
} }
if (train.route == this) train.route = null; if (train.route == this) train.route = null;
if (!train.onTrace(startBlock)) startBlock.setTrain(null);
} }
train = null; train = null;
triggeredContacts.clear(); triggeredContacts.clear();
@ -477,10 +478,10 @@ public class Route extends BaseClass {
} }
public boolean isFreeFor(Context context) { public boolean isFreeFor(Context context) {
LOG.debug("{}.isFreeFor({})",this,context); PathFinder.LOG.debug("{}.isFreeFor({})",this,context);
for (int i=1; i<path.size(); i++) { for (int i=1; i<path.size(); i++) {
if (!path.get(i).isFreeFor(context)) { if (!path.get(i).isFreeFor(context)) {
LOG.debug("{}.isFreeFor(...) → false",this); PathFinder.LOG.debug("{}.isFreeFor(...) → false",this);
return false; return false;
} }
} }
@ -900,6 +901,7 @@ public class Route extends BaseClass {
} }
private void traceTrainFrom(Tile tile) { private void traceTrainFrom(Tile tile) {
LOG.debug("{}.traceTrainFrom({})",this,tile);
Vector<Tile> trace = new Vector<Tile>(); Vector<Tile> trace = new Vector<Tile>();
for (Tile t:path) { for (Tile t:path) {
trace.add(t); trace.add(t);

15
src/main/java/de/srsoftware/web4rail/moving/Train.java

@ -104,13 +104,15 @@ public class Train extends BaseClass implements Comparable<Train> {
if (isSet(route)) { if (isSet(route)) {
if (o instanceof String) plan.stream((String)o); if (o instanceof String) plan.stream((String)o);
//if (isSet(destination)) Thread.sleep(1000); // limit load on PathFinder //if (isSet(destination)) Thread.sleep(1000); // limit load on PathFinder
} else Thread.sleep(1000); // limit load on PathFinder } else waitTime = 1000; // limit load on PathFinder
} }
} else Thread.sleep(250); } else Thread.sleep(250);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
autopilot = null;
if (isSet(currentBlock)) plan.place(currentBlock);
} }
} }
@ -180,6 +182,8 @@ public class Train extends BaseClass implements Comparable<Train> {
} }
public void addToTrace(Vector<Tile> newTiles) { public void addToTrace(Vector<Tile> newTiles) {
Route.LOG.debug("{}.addToTrace({})",this,newTiles);
Route.LOG.debug("old trace: {}",trace);
boolean active = trace.isEmpty(); boolean active = trace.isEmpty();
for (Tile tile : newTiles) { for (Tile tile : newTiles) {
if (active) { if (active) {
@ -189,6 +193,7 @@ public class Train extends BaseClass implements Comparable<Train> {
if (dummy == tile) active = true; if (dummy == tile) active = true;
} }
} }
Route.LOG.debug("new trace: {}",trace);
showTrace(); showTrace();
} }
@ -503,6 +508,11 @@ public class Train extends BaseClass implements Comparable<Train> {
return isSet(nextRoute) && nextRoute.state() == Route.State.PREPARED; return isSet(nextRoute) && nextRoute.state() == Route.State.PREPARED;
} }
public boolean onTrace(Tile t) {
return trace.contains(t);
}
@Override @Override
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) { protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
Fieldset otherTrainProsps = new Fieldset(t("other train properties")); Fieldset otherTrainProsps = new Fieldset(t("other train properties"));
@ -719,10 +729,12 @@ public class Train extends BaseClass implements Comparable<Train> {
} }
public void showTrace() { public void showTrace() {
Route.LOG.debug("{}.showTrace()",this);
int remainingLength = length(); int remainingLength = length();
if (remainingLength<1) remainingLength=1; if (remainingLength<1) remainingLength=1;
for (int i=0; i<trace.size(); i++) { for (int i=0; i<trace.size(); i++) {
Tile tile = trace.get(i); Tile tile = trace.get(i);
Route.LOG.debug("current tile: {}, remaining length: {}",tile,remainingLength);
if (remainingLength>0) { if (remainingLength>0) {
remainingLength-=tile.length(); remainingLength-=tile.length();
tile.setTrain(this); tile.setTrain(this);
@ -732,6 +744,7 @@ public class Train extends BaseClass implements Comparable<Train> {
i--; // do not move to next index: remove shifted the next index towards us i--; // do not move to next index: remove shifted the next index towards us
} }
} }
Route.LOG.debug("remaining length: {}",remainingLength);
} }
private Tag slower(int steps) { private Tag slower(int steps) {

2
src/main/java/de/srsoftware/web4rail/tiles/Contact.java

@ -49,7 +49,7 @@ public class Contact extends Tile{
@Override @Override
public void run() { public void run() {
try { try {
for (int ticks = 0; ticks<10; ticks++) { for (int ticks = 0; ticks<50; ticks++) {
if (!aborted) sleep(10); if (!aborted) sleep(10);
} }
timer = null; timer = null;

25
src/main/java/de/srsoftware/web4rail/tiles/Tile.java

@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import de.srsoftware.tools.Tag; import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.BaseClass; import de.srsoftware.web4rail.BaseClass;
import de.srsoftware.web4rail.Connector; import de.srsoftware.web4rail.Connector;
import de.srsoftware.web4rail.PathFinder;
import de.srsoftware.web4rail.Plan; import de.srsoftware.web4rail.Plan;
import de.srsoftware.web4rail.Plan.Direction; import de.srsoftware.web4rail.Plan.Direction;
import de.srsoftware.web4rail.Route; import de.srsoftware.web4rail.Route;
@ -113,18 +114,18 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
} }
public boolean isFreeFor(Context context) { public boolean isFreeFor(Context context) {
LOG.debug("{}.isFreeFor({})",this,context); PathFinder.LOG.debug("{}.isFreeFor({})",this,context);
if (disabled) { if (disabled) {
LOG.debug("{} is disabled!",this); PathFinder.LOG.debug("{} is disabled!",this);
return false; return false;
} }
if (isNull(context)) { if (isNull(context)) {
if (isSet(train)) { if (isSet(train)) {
LOG.debug("{} is occupied by {}",this,train); PathFinder.LOG.debug("{} is occupied by {}",this,train);
return false; return false;
} }
if (isSet(route)) { if (isSet(route)) {
LOG.debug("{} is occupied by {}",this,route); PathFinder.LOG.debug("{} is occupied by {}",this,route);
return false; return false;
} }
@ -132,26 +133,26 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
if (isSet(train)) { if (isSet(train)) {
boolean free = train == context.train(); // during train.reserveNext, we may encounter, parts, that are already reserved by the respective train, but having another route. do not compare routes in that case! boolean free = train == context.train(); // during train.reserveNext, we may encounter, parts, that are already reserved by the respective train, but having another route. do not compare routes in that case!
if (free) { if (free) {
LOG.debug("already reserved by {} → true",train); PathFinder.LOG.debug("already reserved by {} → true",train);
} else { } else {
LOG.debug("occupied by {} → false",train); PathFinder.LOG.debug("occupied by {} → false",train);
} }
return free; return free;
} }
// if we get here, the tile is not occupied by a train, but reserved by a route, yet. thus, the tile is not available for another route // if we get here, the tile is not occupied by a train, but reserved by a route, yet. thus, the tile is not available for another route
if (isSet(route) && route != context.route()) { if (isSet(route) && route != context.route()) {
LOG.debug("reserved by other route: {}",route); PathFinder.LOG.debug("reserved by other route: {}",route);
if (isSet(route.train())) { if (isSet(route.train())) {
if (route.train() == context.train()) { if (route.train() == context.train()) {
LOG.debug("that route is used by {}, which is also requesting this tile → true",route.train()); PathFinder.LOG.debug("that route is used by {}, which is also requesting this tile → true",route.train());
return true; return true;
} }
} }
LOG.debug("{}.route.train = {} → false",this,route.train()); PathFinder.LOG.debug("{}.route.train = {} → false",this,route.train());
return false; return false;
} }
LOG.debug("free"); PathFinder.LOG.debug("free");
return true; return true;
} }
@ -359,14 +360,14 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
} }
public Tile setTrain(Train newTrain) { public Tile setTrain(Train newTrain) {
LOG.debug("{}.set({})",this,newTrain); Route.LOG.debug("{}.setTrain({})",this,newTrain);
if (newTrain == train) return this; // nothing to update if (newTrain == train) return this; // nothing to update
this.train = newTrain; this.train = newTrain;
return plan.place(this); return plan.place(this);
} }
public Tile setRoute(Route lockingRoute) { public Tile setRoute(Route lockingRoute) {
LOG.debug("{}.setRoute({})",this,lockingRoute); Route.LOG.debug("{}.setRoute({})",this,lockingRoute);
if (isNull(lockingRoute)) throw new NullPointerException(); if (isNull(lockingRoute)) throw new NullPointerException();
if (isSet(route)) { if (isSet(route)) {
if (route == lockingRoute) return this; // nothing changed if (route == lockingRoute) return this; // nothing changed

Loading…
Cancel
Save