implemented loco programming
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.3.32</version>
|
||||
<version>1.3.33</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -106,6 +106,12 @@ function connectCu(){
|
||||
return request({realm:CU,action:"connect"});
|
||||
}
|
||||
|
||||
function copyCv(ev){
|
||||
var td = ev.parentNode.previousSibling;
|
||||
$('input[name=cv]').val(td.previousSibling.innerText);
|
||||
$('input[name=val]').val(td.innerText);
|
||||
}
|
||||
|
||||
function dropClass(data){
|
||||
var parts = data.split(" ");
|
||||
for (var i=1; i<parts.length; i++) $('#'+parts[0]).removeClass(parts[i]);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>DEBUG</level>
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ Block properties : Block-Eigenschaften
|
||||
blocks of train : Blöcke des Zugs
|
||||
{}bound : nach {}
|
||||
BrakeCancel : Bremsvorgang abbrechen
|
||||
braking delay : Bremsverzögerung
|
||||
BrakeStart : Bremsvorgang starten
|
||||
BrakeStop : Bremsvorgang abschließen
|
||||
Brake time¹, forward : Bremszeit¹, vorwärts
|
||||
@@ -126,6 +127,7 @@ Drop : Verwerfen
|
||||
Dropped destination of {}. : Ziel von {} verworfen.
|
||||
1) Duration between 5 {} steps during brake process. : 1) Zeit zwischen 5 {}-Schritten beim Bremsvorgang.
|
||||
EAST : Osten
|
||||
edit : bearbeiten
|
||||
Editable properties : veränderliche Eigenschaften
|
||||
editable train properties : veränderliche Zug-Eigenschaften
|
||||
Edit json : JSON bearbeiten
|
||||
@@ -137,6 +139,7 @@ enable {} : {} aktivieren
|
||||
Engage {} : {} aktivieren
|
||||
EngageDecoupler : Entkuppler aktivieren
|
||||
Enter new name for plan : Neuen Namen für den Plan eingeben
|
||||
extended address : erweiterte Adresse
|
||||
export : exportieren
|
||||
Faster (10 {}) : 10 {} schneller
|
||||
Final speed after breaking, before halting : Endgeschwindigkeit nach Bremsvorgang, vor dem Anhalten
|
||||
@@ -186,9 +189,12 @@ Manage locos : Lokomotiven verwalten
|
||||
Manage trains : Züge verwalten
|
||||
Maximum delay : maximale Verzögerung
|
||||
Maximum Speed : Höchstgeschwindigkeit
|
||||
maximum speed v<sub>max</sub> : Höchstgeschwindigkeit v<sub>max</sub>
|
||||
Maximum train length : maximale Zug-Länge
|
||||
mid speed v<sub>mid</sub> : mittlere Geschwindigeit v<sub>mid</sub>
|
||||
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 starting voltage v<sub>min</sub> : Mindestanfahrspannung v<sub>min</sub>
|
||||
Move tiles : Kacheln verschieben
|
||||
name : Name
|
||||
new car : neuer Waggon
|
||||
@@ -208,7 +214,9 @@ No tile moved. : keine Kachel verschoben.
|
||||
{} now in auto-mode : {} ist nun im Automatikmodus
|
||||
Occupied area : Belegte Abschnitte
|
||||
Off : Aus
|
||||
OFF : aus
|
||||
On : An
|
||||
ON: an
|
||||
One of : eine von
|
||||
One way : Richtung
|
||||
Online Documentation : Online-Dokumentation
|
||||
@@ -226,11 +234,13 @@ parked trains : abgestellte Züge
|
||||
Plan saved as "{}". : Plan als „{}“ gespeichert.
|
||||
Port for state {} : Anschluss für Status {}
|
||||
PreserveRoute : Anschlußroute vorwählen
|
||||
Programming : Programmierung
|
||||
Properties : Eigenschaften
|
||||
Properties of {} : Eigenschaften von {}
|
||||
Properties of {} @ ({},{}) : Eigenschaften von {} @ ({},{})
|
||||
PushPullTrain : Wendezug
|
||||
Push-pull train : Wendezug
|
||||
PWM rate : PWM-Frequenz
|
||||
quit autopilot : Autopilot beenden
|
||||
{} reached it`s destination! : {} ist am Ziel angekommen!
|
||||
ReactivateContact : Kontakt reaktivieren
|
||||
@@ -282,6 +292,7 @@ SetSpeed : Geschwindigkeit ändern
|
||||
Set {} to {} {} : {} auf {} {} gesetzt
|
||||
Set speed to {} {} : Geschwindigkeit auf {} {} setzen
|
||||
Set {} to {} : {} auf {} setzen
|
||||
setting : Einstellung
|
||||
SetPower : Strom schalten
|
||||
Set speed to : Geschwindigkeit setzen
|
||||
SetTurnout : Weiche stellen
|
||||
@@ -304,6 +315,7 @@ Stock ID : Inventarnummer
|
||||
Stop settings : Halte-Einstellungen
|
||||
Start autopilot : Autopilot starten
|
||||
Started {} : {} gestartet
|
||||
starting delay : Anfahrverzögerung
|
||||
State : Status
|
||||
StopAllTrains : Alle Züge stoppen
|
||||
StartStopAuto : Automatikmodus an/abschalten
|
||||
@@ -360,6 +372,7 @@ turn train : Richtung des Zuges Wechseln
|
||||
Turn allowed : Wenden erlaubt
|
||||
Turn at destination : Richtung am Ziel umkehren
|
||||
{} turned. : {} gewendet.
|
||||
Turned power {}. : Strom {}geschaltet.
|
||||
Turnout : Weiche
|
||||
TurnoutLE : WeicheLE
|
||||
TurnoutLN : WeicheLN
|
||||
@@ -375,6 +388,7 @@ Turns the train, as if it went through a loop. : Dreht den ZUg, als wenn er eine
|
||||
Unknown action\: {} : Unbekannte Aktion: {}
|
||||
Use negative number to count from end. : Nutze negative Nummern, um von Ende zu zählen.
|
||||
unset : ungesetzt
|
||||
value : Wert
|
||||
WaitForContact : Auf Kontakt warten
|
||||
Wait for {}, then : auf {} warten, dann
|
||||
Wait {} ms, then : {} ms warten, dann
|
||||
|
||||
@@ -365,7 +365,7 @@ public class ControlUnit extends Thread implements Constants{
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
plan.stream(t("Turned power {}.",PW));
|
||||
plan.stream(t("Turned power {}.",t(PW)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -138,11 +138,11 @@ public class Route extends BaseClass {
|
||||
LOG.debug("Estimated distance: {}",estimatedDistance);
|
||||
|
||||
Integer newTimeStep = timeStep;
|
||||
while (calcDistance(newTimeStep) < estimatedDistance) {
|
||||
newTimeStep += 1+newTimeStep/8;
|
||||
while (calcDistance(newTimeStep) < estimatedDistance) { // zu schnell gebremst
|
||||
newTimeStep += (1+newTimeStep/8);
|
||||
}
|
||||
while (calcDistance(newTimeStep) > estimatedDistance) {
|
||||
newTimeStep -= 1+newTimeStep/16;
|
||||
while (calcDistance(newTimeStep) > estimatedDistance) { // zu langsam gebremst
|
||||
newTimeStep -= 1+(newTimeStep/16);
|
||||
}
|
||||
|
||||
if (newTimeStep != timeStep) {
|
||||
|
||||
@@ -5,12 +5,16 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Command;
|
||||
import de.srsoftware.web4rail.Command.Reply;
|
||||
import de.srsoftware.web4rail.Constants;
|
||||
import de.srsoftware.web4rail.Device;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
@@ -29,11 +33,20 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
|
||||
private static final String REVERSE = "reverse";
|
||||
public static final String LOCOMOTIVE = "locomotive";
|
||||
private static final Integer CV_ADDR = 1;
|
||||
private static final String CVS = "cvs";
|
||||
private static final String ACTION_PROGRAM = "program";
|
||||
private static final String CV = "cv";
|
||||
private static final String VALUE = "val";
|
||||
private static final String MODE = "mode";
|
||||
private static final String POM = "pom";
|
||||
private static final String TRACK = "track";
|
||||
private Protocol proto = Protocol.DCC128;
|
||||
private int address = 3;
|
||||
private int speed = 0;
|
||||
private boolean f1,f2,f3,f4;
|
||||
private boolean init = false;
|
||||
private TreeMap<Integer,Integer> cvs = new TreeMap<Integer, Integer>();
|
||||
|
||||
public Locomotive(String name) {
|
||||
super(name);
|
||||
@@ -54,6 +67,8 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
return loco.faster(10);
|
||||
case ACTION_MOVE:
|
||||
return loco.moveUp();
|
||||
case ACTION_PROGRAM:
|
||||
return loco.update(params);
|
||||
case ACTION_PROPS:
|
||||
return loco == null ? Locomotive.manager() : loco.properties();
|
||||
case ACTION_SLOWER10:
|
||||
@@ -230,8 +245,8 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
JSONObject loco = new JSONObject();
|
||||
loco.put(REVERSE, orientation);
|
||||
loco.put(PROTOCOL, proto);
|
||||
loco.put(ADDRESS, address);
|
||||
json.put(LOCOMOTIVE, loco);
|
||||
loco.put(CVS, cvs);
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -242,7 +257,12 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
||||
if (loco.has(REVERSE)) orientation = loco.getBoolean(REVERSE);
|
||||
if (loco.has(PROTOCOL)) proto = Protocol.valueOf(loco.getString(PROTOCOL));
|
||||
if (loco.has(ADDRESS)) address = loco.getInt(ADDRESS);
|
||||
if (loco.has(ADDRESS)) setAddress(loco.getInt(ADDRESS));
|
||||
if (loco.has(CVS)) {
|
||||
JSONObject jCvs = loco.getJSONObject(CVS);
|
||||
for (String key : jCvs.keySet()) cvs.put(Integer.parseInt(key),jCvs.getInt(key));
|
||||
address = cvs.get(CV_ADDR);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -275,6 +295,51 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
return win;
|
||||
}
|
||||
|
||||
private String program(int cv,int val,boolean pom) {
|
||||
if (cv != 0) {
|
||||
if (val < 0) {
|
||||
cvs.remove(cv);
|
||||
return null;
|
||||
}
|
||||
init();
|
||||
Command command = new Command("SET {} SM "+(pom?address:-1)+" CV "+cv+" "+val);
|
||||
try {
|
||||
Reply reply = plan.queue(command).reply();
|
||||
if (reply.succeeded()) {
|
||||
cvs.put(cv, val);
|
||||
if (cv == CV_ADDR) address = val;
|
||||
return null;
|
||||
}
|
||||
return reply.message();
|
||||
} catch (TimeoutException e) {
|
||||
return t("Timeout while sending programming command!");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Fieldset programming() {
|
||||
Fieldset fieldset = new Fieldset(t("Programming"));
|
||||
|
||||
Form form = new Form("cv-form");
|
||||
new Input(REALM,REALM_LOCO).hideIn(form);
|
||||
new Input(ID,id()).hideIn(form);
|
||||
new Input(ACTION,ACTION_PROGRAM).hideIn(form);
|
||||
|
||||
Table table = new Table();
|
||||
table.addHead(t("setting"),t("CV"),t("value"),t("actions"));
|
||||
for (Entry<Integer, Integer> entry : cvs.entrySet()){
|
||||
int cv = entry.getKey();
|
||||
int val = entry.getValue();
|
||||
table.addRow(setting(cv),cv,val,new Button(t("edit"), "copyCv(this);"));
|
||||
}
|
||||
Tag mode = new Tag("div");
|
||||
new Radio(MODE, POM, t("program on main"), true).addTo(mode);
|
||||
new Radio(MODE, TRACK, t("prgramming track"), false).addTo(mode);
|
||||
table.addRow(mode,new Input(CV,0).numeric(),new Input(VALUE,0).numeric(),new Button(t("Apply"),form));
|
||||
return table.addTo(form).addTo(fieldset);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||
preForm.add(cockpit(this));
|
||||
@@ -284,9 +349,10 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
}
|
||||
formInputs.add(t("Protocol"),div);
|
||||
formInputs.add(t("Address"),new Input(ADDRESS, address).numeric());
|
||||
postForm.add(programming());
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
|
||||
private void queue() {
|
||||
int step = proto.steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
||||
init();
|
||||
@@ -300,6 +366,12 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
});
|
||||
}
|
||||
|
||||
private Locomotive setAddress(int newAddress) {
|
||||
address = newAddress;
|
||||
cvs.put(CV_ADDR, newAddress);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String setFunction(int num, boolean active) {
|
||||
switch (num) {
|
||||
case 1:
|
||||
@@ -336,6 +408,30 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
return t("Speed of {} set to {}.",this,speed);
|
||||
}
|
||||
|
||||
private Object setting(int cv) {
|
||||
switch (cv) {
|
||||
case 1:
|
||||
return t("Address");
|
||||
case 2:
|
||||
return t("minimum starting voltage v<sub>min</sub>");
|
||||
case 3:
|
||||
return t("starting delay");
|
||||
case 4:
|
||||
return t("braking delay");
|
||||
case 5:
|
||||
return t("maximum speed v<sub>max</sub>");
|
||||
case 6:
|
||||
return t("mid speed v<sub>mid</sub>");
|
||||
case 8:
|
||||
return t("PWM rate");
|
||||
case 17:
|
||||
case 18:
|
||||
return t("extended address");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public Object stop() {
|
||||
setSpeed(0);
|
||||
return properties();
|
||||
@@ -370,9 +466,19 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
int newAddress = Integer.parseInt(params.get(ADDRESS));
|
||||
if (newAddress != address) {
|
||||
init = false;
|
||||
address = newAddress;
|
||||
setAddress(newAddress);
|
||||
}
|
||||
}
|
||||
return properties();
|
||||
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) {}
|
||||
Window props = properties();
|
||||
if (isSet(error)) new Tag("span").content(error).addTo(props);
|
||||
return props;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user