separated decoder settings from locomotive
This commit is contained in:
2
pom.xml
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.4.34</version>
|
<version>1.4.35</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>
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ disabled : deaktiviert
|
|||||||
disable {} : {} deaktivieren
|
disable {} : {} deaktivieren
|
||||||
disabled routes : deaktivierte Fahrstraßen
|
disabled routes : deaktivierte Fahrstraßen
|
||||||
DisableEnableBlock : Block (de)aktivieren
|
DisableEnableBlock : Block (de)aktivieren
|
||||||
|
dismount : ausbauen
|
||||||
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
||||||
Do you know, what you are doing? : Weißt du, was du da tust?
|
Do you know, what you are doing? : Weißt du, was du da tust?
|
||||||
driven distance : zurückgelegte Strecke
|
driven distance : zurückgelegte Strecke
|
||||||
@@ -227,16 +228,20 @@ mileage : Laufleistung
|
|||||||
Minimum delay : minimale Verzögerung
|
Minimum delay : minimale Verzögerung
|
||||||
Minimum and maximum times (in Miliseconds) trains with the respective tag have to wait in this block. : Minamle und maximale Block-Haltezeit (in Millisekunden) für Züge mit der entsprchender Markierung.
|
Minimum and maximum times (in Miliseconds) trains with the respective tag have to wait in this block. : Minamle und maximale Block-Haltezeit (in Millisekunden) für Züge mit der entsprchender Markierung.
|
||||||
minimum starting voltage v<sub>min</sub> : Mindestanfahrspannung v<sub>min</sub>
|
minimum starting voltage v<sub>min</sub> : Mindestanfahrspannung v<sub>min</sub>
|
||||||
|
Mounted into "{}". : In "{}" eingebaut.
|
||||||
|
Mounted decoder "{}". : Decoder "{}" eingebaut.
|
||||||
Move tiles : Kacheln verschieben
|
Move tiles : Kacheln verschieben
|
||||||
move up : nach oben schieben
|
move up : nach oben schieben
|
||||||
name : Name
|
name : Name
|
||||||
new car : neuer Waggon
|
new car : neuer Waggon
|
||||||
new contact : neuer Kontakt
|
new contact : neuer Kontakt
|
||||||
|
new decoder : neuer Decoder
|
||||||
new direction : neue Fahrtrichtung
|
new direction : neue Fahrtrichtung
|
||||||
new locomotive : neue Lok
|
new locomotive : neue Lok
|
||||||
new tag : neue Markierung
|
new tag : neue Markierung
|
||||||
new train : neuer Zug
|
new train : neuer Zug
|
||||||
No : keine
|
No : keine
|
||||||
|
no decoder : kein Decoder
|
||||||
No direct route from {} to {} : keine direkte Verbindung von {} zu {}
|
No direct route from {} to {} : keine direkte Verbindung von {} zu {}
|
||||||
No free routes from {} : keine Route von {} frei
|
No free routes from {} : keine Route von {} frei
|
||||||
NORTH : Norden
|
NORTH : Norden
|
||||||
@@ -272,6 +277,8 @@ Plan updated. : Plan aktualisiert.
|
|||||||
Port for state {} : Anschluss für Status {}
|
Port for state {} : Anschluss für Status {}
|
||||||
PreserveRoute : Anschlußroute vorwählen
|
PreserveRoute : Anschlußroute vorwählen
|
||||||
Programming : Programmierung
|
Programming : Programmierung
|
||||||
|
prgramming track : Programmier-Gleis
|
||||||
|
program on main : Hauptgleis-Programmierung
|
||||||
Properties : Eigenschaften
|
Properties : Eigenschaften
|
||||||
Properties of {} : Eigenschaften von {}
|
Properties of {} : Eigenschaften von {}
|
||||||
Properties of {} @ ({},{}) : Eigenschaften von {} @ ({},{})
|
Properties of {} @ ({},{}) : Eigenschaften von {} @ ({},{})
|
||||||
@@ -285,6 +292,8 @@ Relay : Relais
|
|||||||
Relay/Signal/Turnout : Relais/Signal/Weiche
|
Relay/Signal/Turnout : Relais/Signal/Weiche
|
||||||
Remove tag "{}" from train : Markierung "{}" von Zug entfernen
|
Remove tag "{}" from train : Markierung "{}" von Zug entfernen
|
||||||
Removed {} : {} gelöscht
|
Removed {} : {} gelöscht
|
||||||
|
Removed decoder "{}". : Decoder „{}“ ausgebaut.
|
||||||
|
Removed decoder from "{}". : Decoder aus „{}“ entfernt.
|
||||||
Removed train "{}" : Zug „{}“ gelöscht
|
Removed train "{}" : Zug „{}“ gelöscht
|
||||||
rename : umbenennen
|
rename : umbenennen
|
||||||
Rename plan : Plan umbenennen
|
Rename plan : Plan umbenennen
|
||||||
@@ -437,7 +446,9 @@ TurnoutRW : WeicheRW
|
|||||||
Turnouts : Weichen
|
Turnouts : Weichen
|
||||||
turn within train : innerhalb des Zugs drehen
|
turn within train : innerhalb des Zugs drehen
|
||||||
Turns the train, as if it went through a loop. : Dreht den ZUg, als wenn er eine Wendeschleife passiert hätte.
|
Turns the train, as if it went through a loop. : Dreht den ZUg, als wenn er eine Wendeschleife passiert hätte.
|
||||||
|
Type : Typ
|
||||||
Unknown action\: {} : Unbekannte Aktion: {}
|
Unknown action\: {} : Unbekannte Aktion: {}
|
||||||
|
Unknown decoder type : Unbekannter Decoder-Typ
|
||||||
Use negative number to count from end. : Nutze negative Nummern, um von Ende zu zählen.
|
Use negative number to count from end. : Nutze negative Nummern, um von Ende zu zählen.
|
||||||
unset : ungesetzt
|
unset : ungesetzt
|
||||||
update : aktualisieren
|
update : aktualisieren
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import de.srsoftware.localconfig.Configuration;
|
|||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.actions.ActionList;
|
import de.srsoftware.web4rail.actions.ActionList;
|
||||||
import de.srsoftware.web4rail.conditions.Condition;
|
import de.srsoftware.web4rail.conditions.Condition;
|
||||||
|
import de.srsoftware.web4rail.devices.Decoder;
|
||||||
import de.srsoftware.web4rail.moving.Car;
|
import de.srsoftware.web4rail.moving.Car;
|
||||||
import de.srsoftware.web4rail.moving.Locomotive;
|
import de.srsoftware.web4rail.moving.Locomotive;
|
||||||
import de.srsoftware.web4rail.moving.Train;
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
@@ -126,6 +127,8 @@ public class Application extends BaseClass{
|
|||||||
return Condition.action(params,plan);
|
return Condition.action(params,plan);
|
||||||
case REALM_CU:
|
case REALM_CU:
|
||||||
return plan.controlUnit().process(params);
|
return plan.controlUnit().process(params);
|
||||||
|
case REALM_DECODER:
|
||||||
|
return Decoder.action(params);
|
||||||
case REALM_HISTORY:
|
case REALM_HISTORY:
|
||||||
return History.action(params);
|
return History.action(params);
|
||||||
case REALM_LOCO:
|
case REALM_LOCO:
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import de.srsoftware.web4rail.History.LogEntry;
|
|||||||
import de.srsoftware.web4rail.Plan.Direction;
|
import de.srsoftware.web4rail.Plan.Direction;
|
||||||
import de.srsoftware.web4rail.actions.Action;
|
import de.srsoftware.web4rail.actions.Action;
|
||||||
import de.srsoftware.web4rail.conditions.Condition;
|
import de.srsoftware.web4rail.conditions.Condition;
|
||||||
|
import de.srsoftware.web4rail.devices.Decoder;
|
||||||
import de.srsoftware.web4rail.moving.Car;
|
import de.srsoftware.web4rail.moving.Car;
|
||||||
import de.srsoftware.web4rail.moving.Locomotive;
|
import de.srsoftware.web4rail.moving.Locomotive;
|
||||||
import de.srsoftware.web4rail.moving.Train;
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
@@ -566,6 +567,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
|
|
||||||
public String realm() {
|
public String realm() {
|
||||||
if (this instanceof Contact) return REALM_CONTACT;
|
if (this instanceof Contact) return REALM_CONTACT;
|
||||||
|
if (this instanceof Decoder) return REALM_DECODER;
|
||||||
if (this instanceof Tile) return REALM_PLAN;
|
if (this instanceof Tile) return REALM_PLAN;
|
||||||
|
|
||||||
if (this instanceof Locomotive) return REALM_LOCO;
|
if (this instanceof Locomotive) return REALM_LOCO;
|
||||||
@@ -588,9 +590,10 @@ public abstract class BaseClass implements Constants{
|
|||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseClass register() {
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends BaseClass> T register() {
|
||||||
registry.put(id(),this);
|
registry.put(id(),this);
|
||||||
return this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseClass remove() {
|
public BaseClass remove() {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public interface Constants {
|
|||||||
public static final String REALM_CONDITION = "condition";
|
public static final String REALM_CONDITION = "condition";
|
||||||
public static final String REALM_CONTACT = "contact";
|
public static final String REALM_CONTACT = "contact";
|
||||||
public static final String REALM_CU = "cu";
|
public static final String REALM_CU = "cu";
|
||||||
|
public static final String REALM_DECODER = "decoder";
|
||||||
public static final String REALM_HISTORY = "history";
|
public static final String REALM_HISTORY = "history";
|
||||||
public static final String REALM_LOCO = "loco";
|
public static final String REALM_LOCO = "loco";
|
||||||
public static final String REALM_MAINTENANCE = "maintenance";
|
public static final String REALM_MAINTENANCE = "maintenance";
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
package de.srsoftware.web4rail.devices;
|
package de.srsoftware.web4rail.devices;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.tools.Tools;
|
|
||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
import de.srsoftware.web4rail.Command;
|
import de.srsoftware.web4rail.Command;
|
||||||
import de.srsoftware.web4rail.Command.Reply;
|
import de.srsoftware.web4rail.Command.Reply;
|
||||||
|
import de.srsoftware.web4rail.Constants;
|
||||||
|
import de.srsoftware.web4rail.Protocol;
|
||||||
|
import de.srsoftware.web4rail.moving.Locomotive;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Radio;
|
import de.srsoftware.web4rail.tags.Radio;
|
||||||
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
import de.srsoftware.web4rail.tags.Table;
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
import de.srsoftware.web4rail.tags.Window;
|
import de.srsoftware.web4rail.tags.Window;
|
||||||
import de.srsoftware.web4rail.Constants;
|
|
||||||
import de.srsoftware.web4rail.Protocol;
|
|
||||||
|
|
||||||
public class Decoder extends BaseClass implements Constants, Device {
|
public class Decoder extends BaseClass implements Constants, Device {
|
||||||
|
|
||||||
@@ -38,12 +41,43 @@ public class Decoder extends BaseClass implements Constants, Device {
|
|||||||
private static final String TRACK = "track";
|
private static final String TRACK = "track";
|
||||||
private static final String VALUE = "val";
|
private static final String VALUE = "val";
|
||||||
private static final String CV = "cv";
|
private static final String CV = "cv";
|
||||||
|
private String type;
|
||||||
|
private Locomotive loco;
|
||||||
|
|
||||||
|
public static Object action(HashMap<String, String> params) {
|
||||||
|
Decoder decoder = BaseClass.get(Id.from(params));
|
||||||
|
switch (params.get(Constants.ACTION)) {
|
||||||
|
case ACTION_DECOUPLE:
|
||||||
|
return decoder.dismount();
|
||||||
|
case ACTION_PROGRAM:
|
||||||
|
return decoder.program(params);
|
||||||
|
case ACTION_PROPS:
|
||||||
|
return decoder.properties();
|
||||||
|
case ACTION_UPDATE:
|
||||||
|
return decoder.update(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = BaseClass.t("Unknown action: {}",params.get(Constants.ACTION));
|
||||||
|
return (BaseClass.isNull(decoder)) ? message : decoder.properties(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Window dismount() {
|
||||||
|
if (isNull(loco)) return properties();
|
||||||
|
Locomotive locomotive = loco;
|
||||||
|
locomotive.removeDecoder(this);
|
||||||
|
loco = null;
|
||||||
|
addLogEntry(t("Removed decoder from \"{}\".",locomotive));
|
||||||
|
return locomotive.properties();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int address() {
|
public int address() {
|
||||||
if (isNull(address)) address = cvs.get(CV_ADDR);
|
if (isNull(address)) address = cvs.get(CV_ADDR);
|
||||||
return address;
|
return isNull(address) ? 3 : address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button button() {
|
||||||
|
return super.button(type(),Map.of(REALM,REALM_DECODER));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -84,13 +118,14 @@ public class Decoder extends BaseClass implements Constants, Device {
|
|||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
json.put(CVS, cvs);
|
json.put(CVS, cvs);
|
||||||
json.put(PROTOCOL, proto);
|
json.put(PROTOCOL, proto);
|
||||||
|
json.put(TYPE, type);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag link(String... args) {
|
public Tag link(String... args) {
|
||||||
Tools.notImplemented("Decoder.link(…)");
|
// TODO Auto-generated method stub
|
||||||
return new Tag("span").content("[[Decoder.link() not implemented]]");
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,9 +136,21 @@ public class Decoder extends BaseClass implements Constants, Device {
|
|||||||
JSONObject jCvs = json.getJSONObject(CVS);
|
JSONObject jCvs = json.getJSONObject(CVS);
|
||||||
for (String key : jCvs.keySet()) cvs.put(Integer.parseInt(key),jCvs.getInt(key));
|
for (String key : jCvs.keySet()) cvs.put(Integer.parseInt(key),jCvs.getInt(key));
|
||||||
}
|
}
|
||||||
|
if (json.has(TYPE)) type = json.getString(TYPE);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Window program(HashMap<String, String> params) {
|
||||||
|
String error = null;
|
||||||
|
if (params.get(ACTION).equals(ACTION_PROGRAM)) try {
|
||||||
|
int cv = Integer.parseInt(params.get(CV));
|
||||||
|
int val = Integer.parseInt(params.get(VALUE));
|
||||||
|
boolean pom = !params.get(MODE).equals(TRACK);
|
||||||
|
error = program(cv,val,pom);
|
||||||
|
} catch (NumberFormatException e) {}
|
||||||
|
return properties(error);
|
||||||
|
}
|
||||||
|
|
||||||
private String program(int cv,int val,boolean pom) {
|
private String program(int cv,int val,boolean pom) {
|
||||||
if (cv != 0) {
|
if (cv != 0) {
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
@@ -132,7 +179,7 @@ public class Decoder extends BaseClass implements Constants, Device {
|
|||||||
Fieldset fieldset = new Fieldset(t("Programming")).id("props-cv");
|
Fieldset fieldset = new Fieldset(t("Programming")).id("props-cv");
|
||||||
|
|
||||||
Form form = new Form("cv-form");
|
Form form = new Form("cv-form");
|
||||||
new Input(REALM,REALM_LOCO).hideIn(form);
|
new Input(REALM,REALM_DECODER).hideIn(form);
|
||||||
new Input(ID,id()).hideIn(form);
|
new Input(ID,id()).hideIn(form);
|
||||||
new Input(ACTION,ACTION_PROGRAM).hideIn(form);
|
new Input(ACTION,ACTION_PROGRAM).hideIn(form);
|
||||||
|
|
||||||
@@ -161,12 +208,14 @@ public class Decoder extends BaseClass implements Constants, Device {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm, String... errorMessages) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm, String... errorMessages) {
|
||||||
|
formInputs.add(t("Type"),new Input(TYPE,type()));
|
||||||
Tag div = new Tag("div");
|
Tag div = new Tag("div");
|
||||||
for (Protocol proto : Protocol.values()) {
|
for (Protocol proto : Protocol.values()) {
|
||||||
new Radio(PROTOCOL, proto.toString(), t(proto.toString()), proto == this.proto).addTo(div);
|
new Radio(PROTOCOL, proto.toString(), t(proto.toString()), proto == this.proto).addTo(div);
|
||||||
}
|
}
|
||||||
formInputs.add(t("Protocol"),div);
|
formInputs.add(t("Protocol"),div);
|
||||||
formInputs.add(t("Address"),new Input(ADDRESS, address).numeric());
|
formInputs.add(t("Address"),new Tag("span").content(""+address()));
|
||||||
|
if (isSet(loco)) formInputs.add(t("Locomotive"),loco.button(loco.name()));
|
||||||
postForm.add(programming());
|
postForm.add(programming());
|
||||||
return super.properties(preForm, formInputs, postForm, errorMessages);
|
return super.properties(preForm, formInputs, postForm, errorMessages);
|
||||||
}
|
}
|
||||||
@@ -175,6 +224,25 @@ public class Decoder extends BaseClass implements Constants, Device {
|
|||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Select selector(boolean freeOnly) {
|
||||||
|
Select selector = new Select(REALM_DECODER);
|
||||||
|
List<Decoder> decoders = BaseClass.listElements(Decoder.class);
|
||||||
|
selector.addOption(-1,t("no decoder"));
|
||||||
|
selector.addOption(0,t("new decoder"));
|
||||||
|
for (Decoder d: decoders) {
|
||||||
|
if (freeOnly && isSet(d.loco)) continue;
|
||||||
|
selector.addOption(d.id(), d);
|
||||||
|
}
|
||||||
|
return selector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Decoder setLoco(Locomotive locomotive, boolean log) {
|
||||||
|
loco = locomotive;
|
||||||
|
if (log) addLogEntry(t("Mounted into \"{}\".",loco));
|
||||||
|
locomotive.setDecoder(this,log);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void setProtocol(Protocol proto) {
|
public void setProtocol(Protocol proto) {
|
||||||
this.proto = proto;
|
this.proto = proto;
|
||||||
}
|
}
|
||||||
@@ -202,5 +270,21 @@ public class Decoder extends BaseClass implements Constants, Device {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return type()+" ("+t("Address")+": "+address()+")";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String type() {
|
||||||
|
return isSet(type) ? type : t("Unknown decoder type");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window update(HashMap<String, String> params) {
|
||||||
|
super.update(params);
|
||||||
|
if (params.containsKey(TYPE)) type = params.get(TYPE);
|
||||||
|
if (params.containsKey(Device.PROTOCOL)) setProtocol(Protocol.valueOf(params.get(Device.PROTOCOL)));
|
||||||
|
return isSet(loco) ? loco.properties() : properties();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return train().moveUp(this);
|
return train().moveUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
String name(){
|
public String name(){
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,29 +5,21 @@ import java.util.Comparator;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
import de.srsoftware.web4rail.Command;
|
import de.srsoftware.web4rail.Command;
|
||||||
import de.srsoftware.web4rail.Command.Reply;
|
|
||||||
import de.srsoftware.web4rail.devices.Decoder;
|
|
||||||
import de.srsoftware.web4rail.devices.Device;
|
|
||||||
import de.srsoftware.web4rail.Constants;
|
import de.srsoftware.web4rail.Constants;
|
||||||
import de.srsoftware.web4rail.Plan;
|
import de.srsoftware.web4rail.Plan;
|
||||||
import de.srsoftware.web4rail.Protocol;
|
import de.srsoftware.web4rail.devices.Decoder;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
import de.srsoftware.web4rail.tags.Radio;
|
|
||||||
import de.srsoftware.web4rail.tags.Range;
|
import de.srsoftware.web4rail.tags.Range;
|
||||||
import de.srsoftware.web4rail.tags.Table;
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
import de.srsoftware.web4rail.tags.Window;
|
import de.srsoftware.web4rail.tags.Window;
|
||||||
@@ -60,8 +52,6 @@ public class Locomotive extends Car implements Constants{
|
|||||||
return loco.faster(Train.defaultSpeedStep);
|
return loco.faster(Train.defaultSpeedStep);
|
||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
return loco.moveUp();
|
return loco.moveUp();
|
||||||
/* case ACTION_PROGRAM:
|
|
||||||
return loco.update(params); */
|
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return loco == null ? Locomotive.manager() : loco.properties();
|
return loco == null ? Locomotive.manager() : loco.properties();
|
||||||
case ACTION_SET_SPEED:
|
case ACTION_SET_SPEED:
|
||||||
@@ -211,10 +201,8 @@ public class Locomotive extends Car implements Constants{
|
|||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
JSONObject loco = new JSONObject();
|
JSONObject loco = new JSONObject();
|
||||||
//loco.put(PROTOCOL, proto);
|
|
||||||
json.put(LOCOMOTIVE, loco);
|
json.put(LOCOMOTIVE, loco);
|
||||||
//loco.put(CVS, cvs);
|
if (isSet(decoder)) loco.put(Decoder.DECODER,decoder.json());
|
||||||
loco.put(Decoder.DECODER,decoder.json());
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,16 +210,20 @@ public class Locomotive extends Car implements Constants{
|
|||||||
public Car load(JSONObject json) {
|
public Car load(JSONObject json) {
|
||||||
super.load(json);
|
super.load(json);
|
||||||
if (json.has(LOCOMOTIVE)) {
|
if (json.has(LOCOMOTIVE)) {
|
||||||
if (isNull(decoder)) decoder = new Decoder();
|
|
||||||
|
|
||||||
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
||||||
if (loco.has(Decoder.DECODER)) decoder.load(json.getJSONObject(Decoder.DECODER));
|
if (loco.has(Decoder.DECODER)) {
|
||||||
if (loco.has(Decoder.CVS)) { // Legacy
|
if (isNull(decoder)) decoder = new Decoder();
|
||||||
JSONObject jCvs = loco.getJSONObject(Decoder.CVS);
|
decoder.load(loco.getJSONObject(Decoder.DECODER));
|
||||||
for (String key : jCvs.keySet()) {
|
|
||||||
decoder.cvs.put(Integer.parseInt(key),jCvs.getInt(key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (loco.has(Decoder.CVS)) { // Legacy
|
||||||
|
if (isNull(decoder)) decoder = new Decoder();
|
||||||
|
decoder.register();
|
||||||
|
JSONObject jCvs = loco.getJSONObject(Decoder.CVS);
|
||||||
|
for (String key : jCvs.keySet()) decoder.cvs.put(Integer.parseInt(key),jCvs.getInt(key));
|
||||||
|
}
|
||||||
|
if (isSet(decoder)) decoder.setLoco(this,false);
|
||||||
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -242,7 +234,7 @@ public class Locomotive extends Car implements Constants{
|
|||||||
|
|
||||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||||
|
|
||||||
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Max. Speed",speedUnit),t("Protocol"),t("Address"),t("Length"),t("driven distance"),t("Tags"));
|
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Max. Speed",speedUnit),t("Address"),t("Decoder"),t("Length"),t("driven distance"),t("Tags"));
|
||||||
List<Locomotive> locos = BaseClass.listElements(Locomotive.class);
|
List<Locomotive> locos = BaseClass.listElements(Locomotive.class);
|
||||||
locos.sort(Comparator.comparing(loco -> isSet(loco.decoder) ? loco.decoder.address() : 0));
|
locos.sort(Comparator.comparing(loco -> isSet(loco.decoder) ? loco.decoder.address() : 0));
|
||||||
locos.sort(Comparator.comparing(loco -> loco.stockId));
|
locos.sort(Comparator.comparing(loco -> loco.stockId));
|
||||||
@@ -252,8 +244,8 @@ public class Locomotive extends Car implements Constants{
|
|||||||
table.addRow(loco.stockId,
|
table.addRow(loco.stockId,
|
||||||
loco.link(),
|
loco.link(),
|
||||||
maxSpeed+NBSP+speedUnit,
|
maxSpeed+NBSP+speedUnit,
|
||||||
isSet(loco.decoder) ? loco.decoder.protocol() : null,
|
|
||||||
isSet(loco.decoder) ? loco.decoder.address() : null,
|
isSet(loco.decoder) ? loco.decoder.address() : null,
|
||||||
|
isSet(loco.decoder) ? loco.decoder.button() : null,
|
||||||
loco.length+NBSP+lengthUnit,
|
loco.length+NBSP+lengthUnit,
|
||||||
loco.distanceCounter,
|
loco.distanceCounter,
|
||||||
String.join(", ", loco.tags()));
|
String.join(", ", loco.tags()));
|
||||||
@@ -279,19 +271,32 @@ public class Locomotive extends Car implements Constants{
|
|||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) {
|
||||||
preForm.add(cockpit(this));
|
preForm.add(cockpit(this));
|
||||||
Window props = super.properties(preForm, formInputs, postForm,errors);
|
Window props = super.properties(preForm, formInputs, postForm,errors);
|
||||||
if (isSet(decoder)) {
|
|
||||||
Tag basicProps = props.children().stream().filter(tag -> BaseClass.PROPS_BASIC.equals(tag.get("id"))).findFirst().get();
|
Tag basicProps = props.children().stream().filter(tag -> BaseClass.PROPS_BASIC.equals(tag.get("id"))).findFirst().get();
|
||||||
Tag form = basicProps.children().stream().filter(tag -> tag.is("form")).findFirst().get();
|
Tag form = basicProps.children().stream().filter(tag -> tag.is("form")).findFirst().get();
|
||||||
Table table = (Table) form.children().stream().filter(tag -> tag.is("table")).findFirst().get();
|
Table table = (Table) form.children().stream().filter(tag -> tag.is("table")).findFirst().get();
|
||||||
table.addRow(t("Decoder"),decoder.link());
|
Tag div = new Tag("div");
|
||||||
|
if (isSet(decoder)) {
|
||||||
|
decoder.button().addTo(div);
|
||||||
|
decoder.button(t("dismount"), Map.of(ACTION,ACTION_DECOUPLE)).addTo(div);
|
||||||
|
} else {
|
||||||
|
Decoder.selector(true).addTo(div);
|
||||||
|
}
|
||||||
|
table.addRow(t("Decoder"),div);
|
||||||
Vector<Tag> cols = table.children();
|
Vector<Tag> cols = table.children();
|
||||||
Tag lastRow = cols.lastElement();
|
Tag lastRow = cols.lastElement();
|
||||||
cols.remove(cols.size()-1);
|
cols.remove(cols.size()-1);
|
||||||
cols.insertElementAt(lastRow, 5);
|
cols.insertElementAt(lastRow, 5);
|
||||||
}
|
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeDecoder(Decoder decoder) {
|
||||||
|
if (this.decoder == decoder) {
|
||||||
|
addLogEntry(t("Removed decoder \"{}\".",decoder));
|
||||||
|
this.decoder = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void queue() {
|
private void queue() {
|
||||||
if (isNull(decoder)) return;
|
if (isNull(decoder)) return;
|
||||||
int step = decoder.protocol().steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
int step = decoder.protocol().steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
||||||
@@ -306,6 +311,11 @@ public class Locomotive extends Car implements Constants{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDecoder(Decoder newDecoder, boolean log) {
|
||||||
|
decoder = newDecoder;
|
||||||
|
if (log) addLogEntry(t("Mounted decoder \"{}\".",decoder));
|
||||||
|
}
|
||||||
|
|
||||||
public String setFunction(int num, boolean active) {
|
public String setFunction(int num, boolean active) {
|
||||||
switch (num) {
|
switch (num) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -333,13 +343,15 @@ public class Locomotive extends Car implements Constants{
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Tag setSpeed(int newSpeed) {
|
public Tag setSpeed(int newSpeed) {
|
||||||
LOG.debug(this.detail()+".setSpeed({})",newSpeed);
|
if (isSet(decoder)) {
|
||||||
speed = newSpeed;
|
LOG.debug(this.detail()+".setSpeed({})",newSpeed);
|
||||||
if (speed > maxSpeedForward && maxSpeedForward > 0) speed = maxSpeed();
|
speed = newSpeed;
|
||||||
if (speed < 0) speed = 0;
|
if (speed > maxSpeedForward && maxSpeedForward > 0) speed = maxSpeed();
|
||||||
|
if (speed < 0) speed = 0;
|
||||||
|
|
||||||
queue();
|
queue();
|
||||||
//plan.stream(t("Speed of {} set to {} {}.",this,speed,BaseClass.speedUnit));
|
//plan.stream(t("Speed of {} set to {} {}.",this,speed,BaseClass.speedUnit));
|
||||||
|
}
|
||||||
return properties();
|
return properties();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -375,21 +387,20 @@ public class Locomotive extends Car implements Constants{
|
|||||||
@Override
|
@Override
|
||||||
protected Window update(HashMap<String, String> params) {
|
protected Window update(HashMap<String, String> params) {
|
||||||
super.update(params);
|
super.update(params);
|
||||||
if (isSet(decoder) && params.containsKey(Device.PROTOCOL)) decoder.setProtocol(Protocol.valueOf(params.get(Device.PROTOCOL)));
|
if (params.containsKey(REALM_DECODER)) {
|
||||||
if (isSet(decoder) && params.containsKey(Device.ADDRESS)) {
|
Id decoderId = Id.from(params,REALM_DECODER);
|
||||||
int newAddress = Integer.parseInt(params.get(Device.ADDRESS));
|
Decoder decoder = null;
|
||||||
if (newAddress != decoder.address()) decoder.cvs.put(Decoder.CV_ADDR, newAddress);
|
switch (decoderId.toString()) {
|
||||||
|
case "-1":
|
||||||
|
break;
|
||||||
|
case "0":
|
||||||
|
decoder = new Decoder().register();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
decoder = Decoder.get(decoderId);
|
||||||
|
}
|
||||||
|
if (isSet(decoder)) decoder.setLoco(this,true);
|
||||||
}
|
}
|
||||||
String error = null;
|
return properties();
|
||||||
/*if (params.get(ACTION).equals(ACTION_PROGRAM)) try {
|
|
||||||
int cv = Integer.parseInt(params.get(CV));
|
|
||||||
int val = Integer.parseInt(params.get(VALUE));
|
|
||||||
boolean pom = !params.get(MODE).equals(TRACK);
|
|
||||||
error = program(cv,val,pom);
|
|
||||||
|
|
||||||
} catch (NumberFormatException e) {}*/
|
|
||||||
Window props = properties();
|
|
||||||
if (isSet(error)) new Tag("span").content(error).addTo(props);
|
|
||||||
return props;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user