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. 17
      src/main/java/de/srsoftware/web4rail/moving/Train.java
  9. 4
      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 @@ @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>1.2.53</version>
<version>1.2.54</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

8
resources/logback.xml

@ -1,4 +1,5 @@ @@ -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">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
@ -6,10 +7,11 @@ @@ -6,10 +7,11 @@
</encoder>
</appender>
<logger name="de.srsoftware.web4rail" level="INFO"/>
<logger name="de.srsoftware.web4rail.Application" level="INFO"/>
<logger name="de.srsoftware.web4rail" level="DEBUG"/>
<logger name="de.srsoftware.web4rail.Application" level="DEBUG"/>
<logger name="de.srsoftware.web4rail.Command" level="INFO"/>
<logger name="de.srsoftware.web4rail.ControlUnit" level="INFO"/>
<logger name="de.srsoftware.web4rail.moving" level="DEBUG"/>
<root level="info">
<appender-ref ref="STDOUT" />

2
resources/translations/Application.de.translation

@ -148,7 +148,7 @@ NORTH : Norden @@ -148,7 +148,7 @@ NORTH : Norden
Not connected to other bridge part! : Nicht mit anderem Brücken-Teil verbunden!
Notes : Notizen
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
Occupied area\: : Belegte Abschnitte:
Off : Aus

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

@ -38,7 +38,7 @@ public class Command { @@ -38,7 +38,7 @@ public class Command {
milis = Integer.parseInt(word.substring(word.length()-3));
code = scanner.nextInt();
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{ @@ -256,7 +256,7 @@ public class ControlUnit extends Thread implements Constants{
if (command == null || command.toString() == null) return;
String data = command.toString().replace("{}", ""+bus);
commandSocket.getOutputStream().write((data+"\n").getBytes(StandardCharsets.US_ASCII));
LOG.info("sent {}.",data);
LOG.debug("sent {}.",data);
command.readReplyFrom(commandScanner);
}
@ -315,7 +315,12 @@ public class ControlUnit extends Thread implements Constants{ @@ -315,7 +315,12 @@ public class ControlUnit extends Thread implements Constants{
case FEEDBACK:
int addr = Integer.parseInt(parts[5]);
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:
break;
default:

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

@ -14,7 +14,7 @@ import de.srsoftware.web4rail.moving.Train; @@ -14,7 +14,7 @@ import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tiles.Block;
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){
LOG.debug("PathFinder.availableRoutes({})",context);

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

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

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

@ -104,13 +104,15 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -104,13 +104,15 @@ public class Train extends BaseClass implements Comparable<Train> {
if (isSet(route)) {
if (o instanceof String) plan.stream((String)o);
//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);
}
} catch (Exception e) {
e.printStackTrace();
}
}
autopilot = null;
if (isSet(currentBlock)) plan.place(currentBlock);
}
}
@ -180,6 +182,8 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -180,6 +182,8 @@ public class Train extends BaseClass implements Comparable<Train> {
}
public void addToTrace(Vector<Tile> newTiles) {
Route.LOG.debug("{}.addToTrace({})",this,newTiles);
Route.LOG.debug("old trace: {}",trace);
boolean active = trace.isEmpty();
for (Tile tile : newTiles) {
if (active) {
@ -189,6 +193,7 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -189,6 +193,7 @@ public class Train extends BaseClass implements Comparable<Train> {
if (dummy == tile) active = true;
}
}
Route.LOG.debug("new trace: {}",trace);
showTrace();
}
@ -502,6 +507,11 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -502,6 +507,11 @@ public class Train extends BaseClass implements Comparable<Train> {
public boolean nextRoutePrepared() {
return isSet(nextRoute) && nextRoute.state() == Route.State.PREPARED;
}
public boolean onTrace(Tile t) {
return trace.contains(t);
}
@Override
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
@ -719,10 +729,12 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -719,10 +729,12 @@ public class Train extends BaseClass implements Comparable<Train> {
}
public void showTrace() {
Route.LOG.debug("{}.showTrace()",this);
int remainingLength = length();
if (remainingLength<1) remainingLength=1;
for (int i=0; i<trace.size(); i++) {
Tile tile = trace.get(i);
Route.LOG.debug("current tile: {}, remaining length: {}",tile,remainingLength);
if (remainingLength>0) {
remainingLength-=tile.length();
tile.setTrain(this);
@ -732,6 +744,7 @@ public class Train extends BaseClass implements Comparable<Train> { @@ -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
}
}
Route.LOG.debug("remaining length: {}",remainingLength);
}
private Tag slower(int steps) {

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

@ -49,7 +49,7 @@ public class Contact extends Tile{ @@ -49,7 +49,7 @@ public class Contact extends Tile{
@Override
public void run() {
try {
for (int ticks = 0; ticks<10; ticks++) {
for (int ticks = 0; ticks<50; ticks++) {
if (!aborted) sleep(10);
}
timer = null;
@ -210,7 +210,7 @@ public class Contact extends Tile{ @@ -210,7 +210,7 @@ public class Contact extends Tile{
}
public void stream() {
try {
try {
Tag tag = tag(null);
if (state) tag.clazz(tag.get("class")+" active");
plan.stream("place "+tag);

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

@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory; @@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.BaseClass;
import de.srsoftware.web4rail.Connector;
import de.srsoftware.web4rail.PathFinder;
import de.srsoftware.web4rail.Plan;
import de.srsoftware.web4rail.Plan.Direction;
import de.srsoftware.web4rail.Route;
@ -113,18 +114,18 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{ @@ -113,18 +114,18 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
}
public boolean isFreeFor(Context context) {
LOG.debug("{}.isFreeFor({})",this,context);
PathFinder.LOG.debug("{}.isFreeFor({})",this,context);
if (disabled) {
LOG.debug("{} is disabled!",this);
PathFinder.LOG.debug("{} is disabled!",this);
return false;
}
if (isNull(context)) {
if (isSet(train)) {
LOG.debug("{} is occupied by {}",this,train);
PathFinder.LOG.debug("{} is occupied by {}",this,train);
return false;
}
if (isSet(route)) {
LOG.debug("{} is occupied by {}",this,route);
PathFinder.LOG.debug("{} is occupied by {}",this,route);
return false;
}
@ -132,26 +133,26 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{ @@ -132,26 +133,26 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
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!
if (free) {
LOG.debug("already reserved by {} → true",train);
PathFinder.LOG.debug("already reserved by {} → true",train);
} else {
LOG.debug("occupied by {} → false",train);
PathFinder.LOG.debug("occupied by {} → false",train);
}
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 (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 (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;
}
}
LOG.debug("{}.route.train = {} → false",this,route.train());
PathFinder.LOG.debug("{}.route.train = {} → false",this,route.train());
return false;
}
LOG.debug("free");
PathFinder.LOG.debug("free");
return true;
}
@ -359,14 +360,14 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{ @@ -359,14 +360,14 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
}
public Tile setTrain(Train newTrain) {
LOG.debug("{}.set({})",this,newTrain);
Route.LOG.debug("{}.setTrain({})",this,newTrain);
if (newTrain == train) return this; // nothing to update
this.train = newTrain;
return plan.place(this);
}
public Tile setRoute(Route lockingRoute) {
LOG.debug("{}.setRoute({})",this,lockingRoute);
Route.LOG.debug("{}.setRoute({})",this,lockingRoute);
if (isNull(lockingRoute)) throw new NullPointerException();
if (isSet(route)) {
if (route == lockingRoute) return this; // nothing changed

Loading…
Cancel
Save