Skip to content

Commit 4f5cf25

Browse files
committed
More work on the new CommandStationDialog Sensor are updated
1 parent 81cb023 commit 4f5cf25

File tree

11 files changed

+921
-199
lines changed

11 files changed

+921
-199
lines changed

src/main/java/jcs/commandStation/GenericController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package jcs.commandStation;
1717

18+
import java.util.List;
19+
import jcs.commandStation.entities.Device;
1820
import jcs.entities.CommandStationBean;
1921
import jcs.commandStation.entities.InfoBean;
2022
import jcs.commandStation.events.ConnectionEventListener;
@@ -39,6 +41,8 @@ public interface GenericController {
3941

4042
InfoBean getCommandStationInfo();
4143

44+
List<Device> getDevices();
45+
4246
String getIp();
4347

4448
}

src/main/java/jcs/commandStation/dccex/DccExCommandStationImpl.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package jcs.commandStation.dccex;
1717

1818
import java.awt.Image;
19+
import java.util.ArrayList;
1920
import java.util.List;
2021
import java.util.concurrent.Executors;
2122
import jcs.JCS;
@@ -26,6 +27,7 @@
2627
import jcs.commandStation.dccex.connection.DccExMessageListener;
2728
import jcs.commandStation.dccex.events.CabEvent;
2829
import jcs.commandStation.dccex.events.DccExMeasurementEvent;
30+
import jcs.commandStation.entities.Device;
2931
import jcs.commandStation.events.AccessoryEvent;
3032
import jcs.commandStation.events.AccessoryEventListener;
3133
import jcs.commandStation.events.ConnectionEvent;
@@ -57,7 +59,6 @@ public class DccExCommandStationImpl extends AbstractController implements Decod
5759
private boolean powerStatusSet = false;
5860

5961
//Map<Integer, ChannelBean> measurementChannels;
60-
6162
public DccExCommandStationImpl(CommandStationBean commandStationBean) {
6263
this(commandStationBean, false);
6364
}
@@ -96,7 +97,6 @@ public DccExCommandStationImpl(CommandStationBean commandStationBean, boolean au
9697
// handleMeasurement(csrq);
9798
// }
9899
// }
99-
100100
@Override
101101
public final boolean connect() {
102102
if (!connected) {
@@ -379,6 +379,12 @@ public InfoBean getCommandStationInfo() {
379379
return this.infoBean;
380380
}
381381

382+
@Override
383+
public List<Device> getDevices() {
384+
List<Device> devices = new ArrayList<>();
385+
return devices;
386+
}
387+
382388
@Override
383389
public boolean isSupportTrackMeasurements() {
384390
return false; // true;
@@ -393,7 +399,6 @@ public boolean isSupportTrackMeasurements() {
393399
// }
394400
// return this.measurementChannels;
395401
// }
396-
397402
private void fireAllDisconnectionEventListeners(final ConnectionEvent disconnectionEvent) {
398403
for (ConnectionEventListener listener : this.connectionEventListeners) {
399404
listener.onConnectionChange(disconnectionEvent);
@@ -534,7 +539,6 @@ private void fireAllAccessoryEventListeners(final AccessoryEvent accessoryEvent)
534539
// }
535540
// }
536541
// }
537-
538542
private void handleInfoMessage(String message) {
539543
//executor.execute(() -> fireAllPowerEventListeners(powerEvent));
540544
Logger.trace("Info: " + message);
@@ -704,6 +708,9 @@ public static void main(String[] a) {
704708
// ((DccExCommandStationImpl) cs).pause(500L);
705709
// cs.power(true);
706710
// Logger.trace("Power is: " + (cs.isPower() ? "On" : "Off"));
711+
712+
713+
707714
/////
708715
//((DccExCommandStationImpl) cs).pause(500L);
709716
// cs.changeFunctionValue(8, 0, true);
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright 2025 fransjacobs.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package jcs.commandStation.entities;
17+
18+
import java.util.Objects;
19+
20+
/**
21+
* Command Station Device is an Object to be able to show the Devices that "live"<br>
22+
* inside a Command Station. Examples <br>
23+
* Marklin CS: <br>
24+
* - GFP internal booster device - Link S88 external feedback device ESU-ECoS:<br>
25+
* - Ecos device self / booster - Locomotive Manager - Accessories Manager - Feedback Manager
26+
*/
27+
public class Device {
28+
29+
private String id;
30+
private String name;
31+
private String hardwareVersion;
32+
private String softwareVersion;
33+
private String serialNumber;
34+
35+
private Integer size;
36+
private Integer channels;
37+
private boolean feedback;
38+
39+
public String getId() {
40+
return id;
41+
}
42+
43+
public void setId(String id) {
44+
this.id = id;
45+
}
46+
47+
public String getName() {
48+
return name;
49+
}
50+
51+
public void setName(String name) {
52+
this.name = name;
53+
}
54+
55+
public String getHardwareVersion() {
56+
return hardwareVersion;
57+
}
58+
59+
public void setHardwareVersion(String hardwareVersion) {
60+
this.hardwareVersion = hardwareVersion;
61+
}
62+
63+
public String getSoftwareVersion() {
64+
return softwareVersion;
65+
}
66+
67+
public void setSoftwareVersion(String softwareVersion) {
68+
this.softwareVersion = softwareVersion;
69+
}
70+
71+
public String getSerialNumber() {
72+
return serialNumber;
73+
}
74+
75+
public void setSerialNumber(String serialNumber) {
76+
this.serialNumber = serialNumber;
77+
}
78+
79+
public Integer getSize() {
80+
return size;
81+
}
82+
83+
public void setSize(Integer size) {
84+
this.size = size;
85+
}
86+
87+
public Integer getChannels() {
88+
return channels;
89+
}
90+
91+
public void setChannels(Integer channels) {
92+
this.channels = channels;
93+
}
94+
95+
public boolean isFeedback() {
96+
return feedback;
97+
}
98+
99+
public void setFeedback(boolean feedback) {
100+
this.feedback = feedback;
101+
}
102+
103+
@Override
104+
public int hashCode() {
105+
int hash = 3;
106+
hash = 67 * hash + Objects.hashCode(this.id);
107+
hash = 67 * hash + Objects.hashCode(this.name);
108+
hash = 67 * hash + Objects.hashCode(this.hardwareVersion);
109+
hash = 67 * hash + Objects.hashCode(this.softwareVersion);
110+
hash = 67 * hash + Objects.hashCode(this.serialNumber);
111+
hash = 67 * hash + Objects.hashCode(this.size);
112+
hash = 67 * hash + Objects.hashCode(this.channels);
113+
hash = 67 * hash + Objects.hashCode(this.feedback);
114+
return hash;
115+
}
116+
117+
@Override
118+
public boolean equals(Object obj) {
119+
if (this == obj) {
120+
return true;
121+
}
122+
if (obj == null) {
123+
return false;
124+
}
125+
if (getClass() != obj.getClass()) {
126+
return false;
127+
}
128+
final Device other = (Device) obj;
129+
if (!Objects.equals(this.id, other.id)) {
130+
return false;
131+
}
132+
if (!Objects.equals(this.name, other.name)) {
133+
return false;
134+
}
135+
if (!Objects.equals(this.hardwareVersion, other.hardwareVersion)) {
136+
return false;
137+
}
138+
if (!Objects.equals(this.softwareVersion, other.softwareVersion)) {
139+
return false;
140+
}
141+
if (!Objects.equals(this.serialNumber, other.serialNumber)) {
142+
return false;
143+
}
144+
if (!Objects.equals(this.size, other.size)) {
145+
return false;
146+
}
147+
if (!Objects.equals(this.feedback, other.feedback)) {
148+
return false;
149+
}
150+
return Objects.equals(this.channels, other.channels);
151+
}
152+
153+
}

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import jcs.commandStation.events.SensorEventListener;
5252
import jcs.commandStation.autopilot.DriveSimulator;
5353
import jcs.commandStation.VirtualConnection;
54+
import jcs.commandStation.entities.Device;
5455
import static jcs.entities.AccessoryBean.AccessoryValue.GREEN;
5556
import static jcs.entities.AccessoryBean.AccessoryValue.RED;
5657
import jcs.entities.LocomotiveBean;
@@ -272,14 +273,14 @@ public void disconnect() {
272273
Logger.trace("Stopping event handling...");
273274
eventMessageHandler.quit();
274275
eventMessageHandler.join();
275-
276+
276277
eventMessageHandler = null;
277278
}
278279
if (connected) {
279280
connection.close();
280281
connected = false;
281282
}
282-
283+
283284
EcosConnectionFactory.disconnectAll();
284285
} catch (Exception ex) {
285286
Logger.error(ex);
@@ -308,6 +309,40 @@ public InfoBean getCommandStationInfo() {
308309
return ib;
309310
}
310311

312+
@Override
313+
public List<Device> getDevices() {
314+
List<Device> devices = new ArrayList<>();
315+
Device ecos = new Device();
316+
ecos.setId(EcosManager.ID + "");
317+
ecos.setName(ecosManager.getName());
318+
ecos.setSerialNumber(ecosManager.getSerialNumber());
319+
ecos.setHardwareVersion(ecosManager.getHardwareVersion());
320+
ecos.setSoftwareVersion(ecosManager.getApplicationVersion());
321+
devices.add(ecos);
322+
323+
Device locs = new Device();
324+
locs.setId(LocomotiveManager.ID + "");
325+
locs.setName("LocomotiveManager");
326+
locs.setSize(locomotiveManager.getSize());
327+
devices.add(locs);
328+
329+
Device acm = new Device();
330+
acm.setId(AccessoryManager.ID + "");
331+
acm.setName("AccessoryManager");
332+
acm.setSize(accessoryManager.getSize());
333+
devices.add(acm);
334+
335+
Device fbm = new Device();
336+
fbm.setId(FeedbackManager.ID + "");
337+
fbm.setName("FeedbackManager");
338+
fbm.setSize(feedbackManager.getSize());
339+
fbm.setChannels(feedbackManager.getModules().size());
340+
fbm.setFeedback(true);
341+
devices.add(fbm);
342+
343+
return devices;
344+
}
345+
311346
@Override
312347
public String getIp() {
313348
if (this.connection != null && this.connection.isConnected()) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class EcosVirtualConnection implements EcosConnection, VirtualConnection {
4747

4848
private EcosMessageListener messageListener;
4949
private boolean debug = false;
50+
51+
private static String ESU_ECOS_ID = "esu-ecos";
5052

5153
EcosVirtualConnection(InetAddress address) {
5254
debug = System.getProperty("message.debug", "false").equalsIgnoreCase("true");
@@ -111,7 +113,7 @@ public synchronized EcosMessage sendMessage(EcosMessage message) {
111113
}
112114
case EcosMessageFactory.QUERY_LOCOMOTIVES -> {
113115
//Query the locomotives from the database
114-
List<LocomotiveBean> locos = PersistenceFactory.getService().getLocomotives();
116+
List<LocomotiveBean> locos = PersistenceFactory.getService().getLocomotivesByCommandStationId(ESU_ECOS_ID);
115117

116118
for (LocomotiveBean loco : locos) {
117119
//name,addr,protocol

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package jcs.commandStation.hsis88;
1717

18+
import java.util.ArrayList;
1819
import java.util.HashMap;
1920
import java.util.LinkedList;
2021
import java.util.List;
@@ -32,6 +33,7 @@
3233
import jcs.entities.FeedbackModuleBean;
3334
import jcs.commandStation.entities.InfoBean;
3435
import jcs.commandStation.VirtualConnection;
36+
import jcs.commandStation.entities.Device;
3537
import jcs.entities.SensorBean;
3638
import jcs.util.RunUtil;
3739
import org.tinylog.Logger;
@@ -124,7 +126,7 @@ public final synchronized boolean connect() {
124126

125127
//DeviceBean d = new DeviceBean();
126128
String[] hsiinfo = info.split("/");
127-
//d.setName(info);
129+
//d.setName(info);
128130
//d.setUid("0");
129131
// for (int i = 0; i < hsiinfo.length; i++) {
130132
// switch (i) {
@@ -155,25 +157,15 @@ public final synchronized boolean connect() {
155157
return connected;
156158
}
157159

158-
// @Override
159-
// public DeviceBean getDevice() {
160-
// return this.mainDevice;
161-
// }
162-
163-
// @Override
164-
// public List<DeviceBean> getDevices() {
165-
// return null;//this.devices.values().stream().collect(Collectors.toList());
166-
// }
167-
168160
@Override
169161
public InfoBean getCommandStationInfo() {
170162
return infoBean;
171163
}
172164

173-
// @Override
174-
// public DeviceBean getFeedbackDevice() {
175-
// return this.feedbackDevice;
176-
// }
165+
public List<Device> getDevices() {
166+
List<Device> devices = new ArrayList<>();
167+
return devices;
168+
}
177169

178170
@Override
179171
public List<FeedbackModuleBean> getFeedbackModules() {

0 commit comments

Comments
 (0)