added SendCommand action
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>0.10.12</version>
|
<version>0.10.13</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>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ Current location\: : Aktueller Ort:
|
|||||||
Actions and contacts : Aktionen und Kontakte
|
Actions and contacts : Aktionen und Kontakte
|
||||||
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
||||||
click here to setup relay : Hier klicken, um Relais einzurichten
|
click here to setup relay : Hier klicken, um Relais einzurichten
|
||||||
|
Command to send to control unit\: : Kommando, welches zur Zentrale gesendet werden soll:
|
||||||
Create action : Aktion erzeugen
|
Create action : Aktion erzeugen
|
||||||
DelayedAction : verzögerte Aktion
|
DelayedAction : verzögerte Aktion
|
||||||
delete : entfernen
|
delete : entfernen
|
||||||
@@ -81,6 +82,8 @@ Route will only be available to trains fulfilling all conditions. : Route ist nu
|
|||||||
Save : speichern
|
Save : speichern
|
||||||
Select contact\: : Kotakt auswählen:
|
Select contact\: : Kotakt auswählen:
|
||||||
Select relay\: : Relais auswählen:
|
Select relay\: : Relais auswählen:
|
||||||
|
SendCommand : Kommando senden
|
||||||
|
Send command \"{}\" to control unit : Kommando „{}“ an Zentrale senden
|
||||||
SetRelay : Relais schalten
|
SetRelay : Relais schalten
|
||||||
SetSignalsToStop : Signale auf Halt stellen
|
SetSignalsToStop : Signale auf Halt stellen
|
||||||
SetSpeed : Geschwindigkeit ändern
|
SetSpeed : Geschwindigkeit ändern
|
||||||
|
|||||||
@@ -576,7 +576,7 @@ public class Plan extends BaseClass{
|
|||||||
for (Tile tile: newRoute.path()) tile.add(newRoute);
|
for (Tile tile: newRoute.path()) tile.add(newRoute);
|
||||||
int routeId = newRoute.id();
|
int routeId = newRoute.id();
|
||||||
Route existingRoute = routes.get(routeId);
|
Route existingRoute = routes.get(routeId);
|
||||||
if (isSet(existingRoute)) newRoute.addActionsFrom(existingRoute);
|
if (isSet(existingRoute)) newRoute.addPropertiesFrom(existingRoute);
|
||||||
routes.put(routeId, newRoute);
|
routes.put(routeId, newRoute);
|
||||||
return newRoute;
|
return newRoute;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,20 +149,6 @@ public class Route extends BaseClass{
|
|||||||
actions.add(action);
|
actions.add(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addActionsFrom(Route existingRoute) {
|
|
||||||
LOG.debug("addActionsFrom({})",existingRoute);
|
|
||||||
setupActions.addActionsFrom(existingRoute.setupActions);
|
|
||||||
for (Entry<String, ActionList> entry : triggers.entrySet()) {
|
|
||||||
String trigger = entry.getKey();
|
|
||||||
ActionList existingActionList = existingRoute.triggers.get(trigger);
|
|
||||||
if (isSet(existingActionList)) {
|
|
||||||
LOG.debug("found action list for {} on existing route {}: {}",trigger,existingRoute,existingActionList);
|
|
||||||
ActionList newActionList = entry.getValue();
|
|
||||||
newActionList.addActionsFrom(existingActionList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addBasicPropertiesTo(Window win) {
|
private void addBasicPropertiesTo(Window win) {
|
||||||
if (isSet(train)) link("span",Map.of(REALM,REALM_TRAIN,ID,train.id,ACTION,ACTION_PROPS),t("Train: {}",train)).addTo(win);
|
if (isSet(train)) link("span",Map.of(REALM,REALM_TRAIN,ID,train.id,ACTION,ACTION_PROPS),t("Train: {}",train)).addTo(win);
|
||||||
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
||||||
@@ -237,6 +223,21 @@ public class Route extends BaseClass{
|
|||||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPropertiesFrom(Route existingRoute) {
|
||||||
|
LOG.debug("addPropertiesFrom({})",existingRoute);
|
||||||
|
disabled = existingRoute.disabled;
|
||||||
|
setupActions.addActionsFrom(existingRoute.setupActions);
|
||||||
|
for (Entry<String, ActionList> entry : triggers.entrySet()) {
|
||||||
|
String trigger = entry.getKey();
|
||||||
|
ActionList existingActionList = existingRoute.triggers.get(trigger);
|
||||||
|
if (isSet(existingActionList)) {
|
||||||
|
LOG.debug("found action list for {} on existing route {}: {}",trigger,existingRoute,existingActionList);
|
||||||
|
ActionList newActionList = entry.getValue();
|
||||||
|
newActionList.addActionsFrom(existingActionList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addSignal(Signal signal) {
|
void addSignal(Signal signal) {
|
||||||
signals.add(signal);
|
signals.add(signal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public abstract class Action extends BaseClass {
|
|||||||
|
|
||||||
public Context(Contact c) {
|
public Context(Contact c) {
|
||||||
contact = c;
|
contact = c;
|
||||||
|
plan = contact.plan();
|
||||||
route = contact.route();
|
route = contact.route();
|
||||||
if (route == null) return;
|
if (route == null) return;
|
||||||
train = route.train;
|
train = route.train;
|
||||||
@@ -48,10 +49,12 @@ public abstract class Action extends BaseClass {
|
|||||||
|
|
||||||
public Context(Train train) {
|
public Context(Train train) {
|
||||||
this.train = train;
|
this.train = train;
|
||||||
|
if (isSet(train)) plan = train.locos().get(0).plan();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context(Route route) {
|
public Context(Route route) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
|
if (isSet(route)) plan = route.path().firstElement().plan();
|
||||||
train = route.train;
|
train = route.train;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +104,7 @@ public abstract class Action extends BaseClass {
|
|||||||
|
|
||||||
public static List<Class<? extends Action>> list() {
|
public static List<Class<? extends Action>> list() {
|
||||||
return List.of(
|
return List.of(
|
||||||
|
SendCommand.class,
|
||||||
ConditionalAction.class,
|
ConditionalAction.class,
|
||||||
SetSpeed.class,
|
SetSpeed.class,
|
||||||
SetSignalsToStop.class,
|
SetSignalsToStop.class,
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Command;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
|
||||||
|
public class SendCommand extends Action{
|
||||||
|
|
||||||
|
public static final String COMMAND = "command";
|
||||||
|
private String command = "SET 1 POWER OFF";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
context.plan.queue(new Command(command) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(Reply reply) {
|
||||||
|
super.onResponse(reply);
|
||||||
|
context.plan.stream(reply.message());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
json.put(COMMAND, command);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
command = json.getString(COMMAND);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window properties(HashMap<String, String> params) {
|
||||||
|
Window win = super.properties(params);
|
||||||
|
Form form = new Form("action-prop-form-"+id);
|
||||||
|
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||||
|
new Input(ID,params.get(ID)).hideIn(form);
|
||||||
|
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||||
|
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||||
|
Label label = new Label(t("Command to send to control unit:")+NBSP);
|
||||||
|
new Input(COMMAND, command).addTo(label).addTo(form);
|
||||||
|
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return t("Send command \"{}\" to control unit",command);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
LOG.debug("update: {}",params);
|
||||||
|
String error = null;
|
||||||
|
command = params.get(COMMAND);
|
||||||
|
Window win = properties(params);
|
||||||
|
return new Tag("span").content(error).addTo(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -162,6 +162,10 @@ public class Car extends BaseClass {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Plan plan() {
|
||||||
|
return plan;
|
||||||
|
}
|
||||||
|
|
||||||
public Car plan(Plan plan) {
|
public Car plan(Plan plan) {
|
||||||
this.plan = plan;
|
this.plan = plan;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -263,6 +264,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return locoList.addTo(locoProp);
|
return locoList.addTo(locoProp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Car> cars(){
|
||||||
|
return new Vector<Car>(cars);
|
||||||
|
}
|
||||||
|
|
||||||
private static Object create(HashMap<String, String> params, Plan plan) {
|
private static Object create(HashMap<String, String> params, Plan plan) {
|
||||||
Locomotive loco = (Locomotive) Locomotive.get(params.get(Train.LOCO_ID));
|
Locomotive loco = (Locomotive) Locomotive.get(params.get(Train.LOCO_ID));
|
||||||
if (isNull(loco)) return t("unknown locomotive: {}",params.get(ID));
|
if (isNull(loco)) return t("unknown locomotive: {}",params.get(ID));
|
||||||
@@ -400,6 +405,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return locoList.addTo(locoProp);
|
return locoList.addTo(locoProp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Car> locos(){
|
||||||
|
return new Vector<Car>(locos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Object manager() {
|
public static Object manager() {
|
||||||
Window win = new Window("train-manager", t("Train manager"));
|
Window win = new Window("train-manager", t("Train manager"));
|
||||||
new Tag("h4").content(t("known trains")).addTo(win);
|
new Tag("h4").content(t("known trains")).addTo(win);
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class Contact extends Tile{
|
|||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
if (addr > 0) json.put(ADDRESS, addr);
|
if (addr > 0) json.put(ADDRESS, addr);
|
||||||
|
if (!actions.isEmpty()) json.put(REALM_ACTIONS, actions.json());
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +83,7 @@ public class Contact extends Tile{
|
|||||||
protected Tile load(JSONObject json) throws IOException {
|
protected Tile load(JSONObject json) throws IOException {
|
||||||
super.load(json);
|
super.load(json);
|
||||||
if (json.has(ADDRESS)) addr(json.getInt(ADDRESS));
|
if (json.has(ADDRESS)) addr(json.getInt(ADDRESS));
|
||||||
|
if (json.has(REALM_ACTIONS)) actions = ActionList.load(json.getJSONArray(REALM_ACTIONS));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user