addcom working on train-control unit interactions
This commit is contained in:
@@ -39,6 +39,7 @@ public class Car {
|
||||
public int length;
|
||||
private String stockId = "";
|
||||
private Train train;
|
||||
protected Plan plan;
|
||||
|
||||
public Car(String name) {
|
||||
this(name,null);
|
||||
@@ -84,7 +85,7 @@ public class Car {
|
||||
return new Tag(tagClass).clazz("link").attr("onclick","car("+id+",'"+Car.SHOW+"')").content(name());
|
||||
}
|
||||
|
||||
public static void loadAll(String filename) throws IOException {
|
||||
public static void loadAll(String filename, Plan plan) throws IOException {
|
||||
cars.clear();
|
||||
BufferedReader file = new BufferedReader(new FileReader(filename));
|
||||
String line = file.readLine();
|
||||
@@ -93,23 +94,29 @@ public class Car {
|
||||
String name = json.getString(Car.NAME);
|
||||
String id = json.getString(Car.ID);
|
||||
Car car = json.has(Locomotive.LOCOMOTIVE) ? new Locomotive(name, id) : new Car(name,id);
|
||||
car.load(json);
|
||||
car.load(json).plan(plan);
|
||||
|
||||
line = file.readLine();
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
protected void load(JSONObject json) {
|
||||
protected Car load(JSONObject json) {
|
||||
if (json.has(ID)) id = json.getString(ID);
|
||||
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
||||
if (json.has(STOCK_ID)) stockId = json.getString(STOCK_ID);
|
||||
return this;
|
||||
}
|
||||
|
||||
String name(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public Car plan(Plan plan) {
|
||||
this.plan = plan;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Tag propertyForm() {
|
||||
Form form = new Form();
|
||||
new Input(Plan.ACTION, Plan.ACTION_UPDATE).hideIn(form);
|
||||
|
||||
@@ -18,7 +18,7 @@ import de.srsoftware.web4rail.tags.Radio;
|
||||
public class Locomotive extends Car {
|
||||
|
||||
public enum Protocol{
|
||||
DCC14,DCC27,DCC28,DCC128,MOTO;
|
||||
DCC14,DCC27,DCC28,DCC128,MOTO,FLEISCH,SELECTRIX,ZIMO;
|
||||
}
|
||||
|
||||
private static final String REVERSE = "reverse";
|
||||
@@ -28,6 +28,7 @@ public class Locomotive extends Car {
|
||||
private boolean reverse = false;
|
||||
private Protocol proto = Protocol.DCC128;
|
||||
private int address = 3;
|
||||
private boolean init = false;
|
||||
|
||||
public Locomotive(String name) {
|
||||
super(name);
|
||||
@@ -36,6 +37,32 @@ public class Locomotive extends Car {
|
||||
public Locomotive(String name, String id) {
|
||||
super(name,id);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (init) return;
|
||||
String proto = null;
|
||||
switch (this.proto) {
|
||||
case FLEISCH:
|
||||
proto = "F"; break;
|
||||
case MOTO:
|
||||
proto = "M 2 100 0"; break; // TODO: make configurable
|
||||
case DCC14:
|
||||
proto = "N 1 14 5"; break; // TODO: make configurable
|
||||
case DCC27:
|
||||
proto = "N 1 27 5"; break; // TODO: make configurable
|
||||
case DCC28:
|
||||
proto = "N 1 28 5"; break; // TODO: make configurable
|
||||
case DCC128:
|
||||
proto = "N 1 128 5"; break; // TODO: make configurable
|
||||
case SELECTRIX:
|
||||
proto = "S"; break;
|
||||
case ZIMO:
|
||||
proto = "Z"; break;
|
||||
}
|
||||
plan.queue("INIT {} GL "+address+" "+proto);
|
||||
init = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
@@ -58,7 +85,7 @@ public class Locomotive extends Car {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load(JSONObject json) {
|
||||
protected Car load(JSONObject json) {
|
||||
super.load(json);
|
||||
if (json.has(LOCOMOTIVE)) {
|
||||
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
||||
@@ -66,6 +93,7 @@ public class Locomotive extends Car {
|
||||
if (loco.has(PROTOCOL)) proto = Protocol.valueOf(loco.getString(PROTOCOL));
|
||||
if (loco.has(ADDRESS)) address = loco.getInt(ADDRESS);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Object manager() {
|
||||
@@ -104,6 +132,8 @@ public class Locomotive extends Car {
|
||||
}
|
||||
|
||||
public void setSpeed(int v) {
|
||||
init();
|
||||
plan.queue("SET {} GL "+address+" "+(reverse?1:0)+" "+v+" 128 0 0 0 0 0");
|
||||
LOG.debug("{}.setSpeed({})",this,v);
|
||||
}
|
||||
|
||||
|
||||
@@ -284,11 +284,11 @@ public class Train {
|
||||
if (block != null) {
|
||||
new Tag("li").content(t("Current location: {}",block)).addTo(list);
|
||||
Tag actions = new Tag("li").clazz().content(t("Actions: "));
|
||||
new Tag("span").clazz("link").attr("onclick","train("+id+",'"+MODE_START+"')").content(" "+t("start")+" ").addTo(actions);
|
||||
new Button(t("start"),"train("+id+",'"+MODE_START+"')").addTo(actions);
|
||||
if (autopilot == null) {
|
||||
new Tag("span").attr("onclick","train("+id+",'"+MODE_AUTO+"')").content(" "+t("auto")+" ").addTo(actions);
|
||||
new Button(t("auto"),"train("+id+",'"+MODE_AUTO+"')").addTo(actions);
|
||||
} else {
|
||||
new Tag("span").clazz("link").attr("onclick","train("+id+",'"+MODE_STOP+"')").content(" "+t("stop")+" ").addTo(actions);
|
||||
new Button(t("stop"),"train("+id+",'"+MODE_STOP+"')").addTo(actions);
|
||||
}
|
||||
actions.addTo(list);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user