Skip to content

Commit fd013a9

Browse files
committed
New CommandStation Dialog is now the default in the settings
1 parent 0bb731e commit fd013a9

26 files changed

+2434
-2177
lines changed

src/main/java/jcs/commandStation/FeedbackController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.List;
1919
import jcs.commandStation.events.SensorEvent;
2020
import jcs.commandStation.events.SensorEventListener;
21-
import jcs.entities.FeedbackModuleBean;
21+
import jcs.commandStation.entities.FeedbackModule;
2222

2323
public interface FeedbackController extends GenericController {
2424

@@ -28,7 +28,7 @@ public interface FeedbackController extends GenericController {
2828

2929
//DeviceBean getFeedbackDevice();
3030

31-
List<FeedbackModuleBean> getFeedbackModules();
31+
List<FeedbackModule> getFeedbackModules();
3232

3333
void fireSensorEventListeners(SensorEvent sensorEvent);
3434

src/main/java/jcs/entities/FeedbackModuleBean.java renamed to src/main/java/jcs/commandStation/entities/FeedbackModule.java

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package jcs.entities;
16+
package jcs.commandStation.entities;
1717

1818
import java.util.ArrayList;
1919
import java.util.List;
2020
import jcs.commandStation.events.SensorEvent;
21+
import jcs.entities.SensorBean;
2122
import org.tinylog.Logger;
2223

2324
/**
2425
* Represents 1 Feedback Module (S88) with a number of ports (usually 16)
2526
*/
26-
public class FeedbackModuleBean implements Comparable<FeedbackModuleBean> {
27+
public class FeedbackModule implements Comparable<FeedbackModule> {
2728

2829
private Integer id;
2930
private Integer moduleNumber;
@@ -32,6 +33,7 @@ public class FeedbackModuleBean implements Comparable<FeedbackModuleBean> {
3233
private Integer identifier;
3334
private Integer busNumber;
3435
private String commandStationId;
36+
private Integer busSize;
3537

3638
private int[] ports;
3739
private int[] prevPorts;
@@ -40,15 +42,15 @@ public class FeedbackModuleBean implements Comparable<FeedbackModuleBean> {
4042
public static int DEFAULT_ADDRESS_OFFSET = 0;
4143
public static int DEFAULT_IDENTIFIER = 0;
4244

43-
public FeedbackModuleBean() {
45+
public FeedbackModule() {
4446
this(null, null, null);
4547
}
4648

47-
public FeedbackModuleBean(Integer id, Integer moduleNumber, String commandStationId) {
49+
public FeedbackModule(Integer id, Integer moduleNumber, String commandStationId) {
4850
this(id, moduleNumber, DEFAULT_PORT_COUNT, DEFAULT_ADDRESS_OFFSET, DEFAULT_IDENTIFIER, commandStationId);
4951
}
5052

51-
public FeedbackModuleBean(Integer id, Integer moduleNumber, Integer portCount, Integer addressOffset, Integer identifier, String commandStationId) {
53+
public FeedbackModule(Integer id, Integer moduleNumber, Integer portCount, Integer addressOffset, Integer identifier, String commandStationId) {
5254
this.id = id;
5355
this.moduleNumber = moduleNumber;
5456
this.portCount = portCount;
@@ -61,7 +63,7 @@ public FeedbackModuleBean(Integer id, Integer moduleNumber, Integer portCount, I
6163
}
6264

6365
@Override
64-
public int compareTo(FeedbackModuleBean o) {
66+
public int compareTo(FeedbackModule o) {
6567
int bn = 0;
6668
if (busNumber != null) {
6769
bn = busNumber;
@@ -147,13 +149,13 @@ public void setPorts(int[] ports) {
147149

148150
public void setPortValue(int port, boolean active) {
149151
//save current values
150-
System.arraycopy(this.ports, 0, this.prevPorts, 0, this.ports.length);
151-
this.ports[port] = active ? 1 : 0;
152+
System.arraycopy(ports, 0, prevPorts, 0, ports.length);
153+
ports[port] = active ? 1 : 0;
152154
}
153155

154156
public boolean isPort(int port) {
155157
if (ports != null && port < ports.length) {
156-
return this.ports[port] == 1;
158+
return ports[port] == 1;
157159
} else {
158160
return false;
159161
}
@@ -187,6 +189,14 @@ public void setCommandStationId(String commandStationId) {
187189
this.commandStationId = commandStationId;
188190
}
189191

192+
public Integer getBusSize() {
193+
return busSize;
194+
}
195+
196+
public void setBusSize(Integer busSize) {
197+
this.busSize = busSize;
198+
}
199+
190200
public SensorBean getSensor(int port) {
191201
int sid;
192202
int offset = 0;
@@ -196,23 +206,28 @@ public SensorBean getSensor(int port) {
196206
if (addressOffset != null) {
197207
offset = addressOffset;
198208
}
199-
sid = offset + moduleNumber * portCount + port;
200-
name = "M" + String.format("%02d", moduleNumber) + "-C" + String.format("%02d", port);
209+
sid = offset + (moduleNumber - 1) * portCount + port;
210+
name = "M" + String.format("%02d", moduleNumber) + "-C" + String.format("%02d", port + 1);
201211
} else {
202212
//Part of a bus, there should be an offset...
203213
if (addressOffset != null) {
204214
offset = addressOffset;
205215
} else {
206216
Logger.warn("Module connected to bus " + busNumber + " but bus address offset is not specified!");
207217
}
208-
sid = offset + moduleNumber * portCount + port;
209-
name = "B" + busNumber.toString() + "-M" + String.format("%02d", moduleNumber) + "-C" + String.format("%02d", port);
218+
sid = offset + (moduleNumber - 1) * portCount + port;
219+
name = "B" + busNumber.toString() + "-M" + String.format("%02d", moduleNumber) + "-C" + String.format("%02d", port + 1);
210220
}
211221

212222
int status = ports[port];
213223
int prevStatus = prevPorts[port];
214224

215-
SensorBean sb = new SensorBean(sid, moduleNumber, port, identifier, status, prevStatus, commandStationId);
225+
int busNr = 0;
226+
if (busNumber != null) {
227+
busNr = busNumber;
228+
}
229+
230+
SensorBean sb = new SensorBean(sid, moduleNumber, port + 1, identifier, status, prevStatus, commandStationId, busNr);
216231
sb.setName(name);
217232
return sb;
218233
}

src/main/java/jcs/commandStation/esu/ecos/EsuEcosCommandStationImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import jcs.commandStation.events.SensorEvent;
3838
import jcs.entities.AccessoryBean;
3939
import jcs.entities.CommandStationBean;
40-
import jcs.entities.FeedbackModuleBean;
40+
import jcs.commandStation.entities.FeedbackModule;
4141
import jcs.commandStation.entities.InfoBean;
4242
import jcs.commandStation.esu.ecos.net.EcosHTTPConnection;
4343
import jcs.commandStation.events.AccessoryEvent;
@@ -252,7 +252,7 @@ public void disconnect() {
252252
try {
253253
if (connected) {
254254
Logger.trace("Unsubsribe from " + feedbackManager.getSize() + " feedback modules...");
255-
for (FeedbackModuleBean fm : feedbackManager.getModules().values()) {
255+
for (FeedbackModule fm : feedbackManager.getModules().values()) {
256256
connection.sendMessage(EcosMessageFactory.unSubscribeFeedbackModule(fm.getId()));
257257
}
258258
Logger.trace("Unsubscribe from " + accessoryManager.getSize() + " accessories...");
@@ -571,8 +571,8 @@ EcosConnection getConnection() {
571571
}
572572

573573
@Override
574-
public List<FeedbackModuleBean> getFeedbackModules() {
575-
List<FeedbackModuleBean> feedbackModules = new ArrayList<>(this.feedbackManager.getModules().values());
574+
public List<FeedbackModule> getFeedbackModules() {
575+
List<FeedbackModule> feedbackModules = new ArrayList<>(this.feedbackManager.getModules().values());
576576
return feedbackModules;
577577
}
578578

@@ -762,9 +762,9 @@ public static void main(String[] a) {
762762
//
763763
// cs.pause(1000);
764764
//
765-
List<FeedbackModuleBean> feedbackModules = cs.getFeedbackModules();
765+
List<FeedbackModule> feedbackModules = cs.getFeedbackModules();
766766
Logger.trace("There are " + feedbackModules + " Feedback Modules");
767-
for (FeedbackModuleBean fm : feedbackModules) {
767+
for (FeedbackModule fm : feedbackModules) {
768768
Logger.trace("Module id: " + fm.getId() + " Module nr: " + fm.getModuleNumber() + " ports: " + fm.getPortCount() + " NodeId: " + fm.getIdentifier() + " BusNr: " + fm.getBusNumber());
769769
Logger.trace("FBModule id: " + fm.getId() + " S 1 id:" + fm.getSensor(0).getId() + " contactId: " + fm.getSensor(0).getContactId() + " ModuleNr: " + fm.getSensor(0).getDeviceId() + " Name " + fm.getSensor(0).getName());
770770
Logger.trace("FBModule id: " + fm.getId() + " S 15 id:" + fm.getSensor(15).getId() + " contactId: " + fm.getSensor(15).getContactId() + " ModuleNr: " + fm.getSensor(15).getDeviceId() + " Name " + fm.getSensor(15).getName());

src/main/java/jcs/commandStation/esu/ecos/FeedbackManager.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.List;
2121
import java.util.Map;
2222
import jcs.commandStation.events.SensorEvent;
23-
import jcs.entities.FeedbackModuleBean;
23+
import jcs.commandStation.entities.FeedbackModule;
2424
import org.tinylog.Logger;
2525

2626
/**
@@ -36,7 +36,7 @@ class FeedbackManager {
3636
private static final String ESU_ECOS_CS = "esu-ecos";
3737

3838
private final EsuEcosCommandStationImpl ecosCommandStation;
39-
private final Map<Integer, FeedbackModuleBean> modules;
39+
private final Map<Integer, FeedbackModule> modules;
4040

4141
FeedbackManager(EsuEcosCommandStationImpl ecosCommandStation, EcosMessage message) {
4242
this.ecosCommandStation = ecosCommandStation;
@@ -53,14 +53,14 @@ private List<SensorEvent> parse(EcosMessage message) {
5353
int objectId = message.getObjectId();
5454

5555
if (ID != objectId) {
56-
FeedbackModuleBean feedbackModule;
56+
FeedbackModule feedbackModule;
5757
if (modules.containsKey(objectId)) {
5858
feedbackModule = modules.get(objectId);
5959
} else {
60-
feedbackModule = new FeedbackModuleBean();
60+
feedbackModule = new FeedbackModule();
6161
feedbackModule.setId(objectId);
6262
feedbackModule.setAddressOffset(0);
63-
feedbackModule.setModuleNumber(objectId - S88_OFFSET);
63+
feedbackModule.setModuleNumber(objectId - S88_OFFSET + 1);
6464
//ESU ECoS has 1 bus
6565
feedbackModule.setIdentifier(0);
6666
//In Unit Testcase the command station is null
@@ -100,12 +100,13 @@ private List<SensorEvent> parse(EcosMessage message) {
100100
if (values.containsKey(Ecos.SIZE)) {
101101
int size = Integer.parseInt(values.get(Ecos.SIZE).toString());
102102
for (int i = 0; i < size; i++) {
103-
FeedbackModuleBean fbmb = new FeedbackModuleBean();
103+
FeedbackModule fbmb = new FeedbackModule();
104104
fbmb.setAddressOffset(0);
105-
fbmb.setModuleNumber(i);
105+
fbmb.setModuleNumber(i + 1);
106106
fbmb.setId(S88_OFFSET + i);
107107
fbmb.setPortCount(S88_DEFAULT_PORT_COUNT);
108108
fbmb.setIdentifier(0);
109+
fbmb.setBusSize(size);
109110

110111
//In Unit Testcase the command station is null
111112
if (ecosCommandStation != null) {
@@ -132,7 +133,7 @@ public int getSize() {
132133
return this.modules.size();
133134
}
134135

135-
void updatePorts(String state, FeedbackModuleBean s88) {
136+
void updatePorts(String state, FeedbackModule s88) {
136137
String val = state.replace("0x", "");
137138
int l = 4 - val.length();
138139
for (int i = 0; i < l; i++) {
@@ -143,8 +144,8 @@ void updatePorts(String state, FeedbackModuleBean s88) {
143144
int[] prevPorts = s88.getPrevPorts();
144145

145146
if (ports == null) {
146-
ports = new int[FeedbackModuleBean.DEFAULT_PORT_COUNT];
147-
prevPorts = new int[FeedbackModuleBean.DEFAULT_PORT_COUNT];
147+
ports = new int[FeedbackModule.DEFAULT_PORT_COUNT];
148+
prevPorts = new int[FeedbackModule.DEFAULT_PORT_COUNT];
148149
}
149150
//Set the previous ports State
150151
System.arraycopy(ports, 0, prevPorts, 0, ports.length);
@@ -160,11 +161,11 @@ void updatePorts(String state, FeedbackModuleBean s88) {
160161
s88.setPorts(ports);
161162
}
162163

163-
public Map<Integer, FeedbackModuleBean> getModules() {
164+
public Map<Integer, FeedbackModule> getModules() {
164165
return modules;
165166
}
166167

167-
public FeedbackModuleBean getFeedbackModule(int id) {
168+
public FeedbackModule getFeedbackModule(int id) {
168169
return modules.get(id);
169170
}
170171
}

src/main/java/jcs/commandStation/esu/ecos/net/EcosVirtualConnection.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import jcs.commandStation.events.SensorEvent;
2727
import jcs.commandStation.VirtualConnection;
2828
import jcs.entities.AccessoryBean;
29-
import jcs.entities.FeedbackModuleBean;
29+
import jcs.commandStation.entities.FeedbackModule;
3030
import jcs.entities.FunctionBean;
3131
import jcs.entities.LocomotiveBean;
3232
import jcs.entities.SensorBean;
@@ -197,7 +197,7 @@ public synchronized EcosMessage sendMessage(EcosMessage message) {
197197
}
198198
} else if (objId >= 100 && objId < 999) {
199199
if (Ecos.CMD_GET.equals(cmd)) {
200-
FeedbackModuleBean module = getFeedbackModule(objId);
200+
FeedbackModule module = getFeedbackModule(objId);
201201
replyBuilder.append(module.getAddressOffset() + module.getModuleNumber());
202202
replyBuilder.append(" state[0x");
203203
replyBuilder.append(module.getAccumulatedPortsValue());
@@ -334,6 +334,7 @@ public synchronized EcosMessage sendMessage(EcosMessage message) {
334334
replyBuilder.append("]");
335335
}
336336
}
337+
337338
}
338339

339340
replyBuilder.append("<END 0 (OK)>");
@@ -402,11 +403,11 @@ static String getSymbol(String type) {
402403
};
403404
}
404405

405-
FeedbackModuleBean getFeedbackModule(int moduleId) {
406+
FeedbackModule getFeedbackModule(int moduleId) {
406407
List<SensorBean> sensors = PersistenceFactory.getService().getSensors();
407408
int id = moduleId;
408409
int moduleNr = id - 100;
409-
FeedbackModuleBean module = new FeedbackModuleBean();
410+
FeedbackModule module = new FeedbackModule();
410411
module.setId(id);
411412
module.setModuleNumber(moduleNr);
412413
module.setPortCount(16);
@@ -426,7 +427,7 @@ FeedbackModuleBean getFeedbackModule(int moduleId) {
426427
@Override
427428
public void sendEvent(SensorEvent sensorEvent) {
428429
Logger.trace("Device: " + sensorEvent.getDeviceId() + " contact: " + sensorEvent.getContactId() + " -> " + sensorEvent.isActive());
429-
FeedbackModuleBean fbm = getFeedbackModule(100 + sensorEvent.getDeviceId());
430+
FeedbackModule fbm = getFeedbackModule(100 + sensorEvent.getDeviceId());
430431
//Logger.trace(fbm.getIdString()+" nr: "+fbm.getModuleNumber() + " Current ports: " + fbm.portToString());
431432
int port = sensorEvent.getContactId() - 1;
432433
fbm.setPortValue(port, sensorEvent.isActive());

src/main/java/jcs/commandStation/hsis88/HSIImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static jcs.commandStation.hsis88.HSIConnection.COMMAND_VERSION;
3131
import jcs.entities.CommandStationBean;
3232
import jcs.entities.CommandStationBean.ConnectionType;
33-
import jcs.entities.FeedbackModuleBean;
33+
import jcs.commandStation.entities.FeedbackModule;
3434
import jcs.commandStation.entities.InfoBean;
3535
import jcs.commandStation.VirtualConnection;
3636
import jcs.commandStation.entities.Device;
@@ -168,7 +168,7 @@ public List<Device> getDevices() {
168168
}
169169

170170
@Override
171-
public List<FeedbackModuleBean> getFeedbackModules() {
171+
public List<FeedbackModule> getFeedbackModules() {
172172
return null;
173173
}
174174

0 commit comments

Comments
 (0)