From be39ae5c507794524a8a25b753e4e25de604196c Mon Sep 17 00:00:00 2001 From: "XProjects B.Hummel" Date: Thu, 11 Feb 2021 18:25:44 +0100 Subject: [PATCH 1/2] Adding BusInfo to Remote-Device --- pom.xml | 2 +- .../java/x/DeviceUtils/DeviceListUtils.java | 9 +++++++ src/main/java/x/DeviceUtils/Types.java | 2 ++ src/main/java/x/bus/BaseBus.java | 11 ++++++++ src/main/java/x/main/XHomeautomationMain.java | 2 +- .../java/x/utils/RemoteAccessRequest.java | 25 +++++++++++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0b3b618..d14fc95 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 x Alpdesk-Automationservice - 2.2.7 + 2.2.8 jar diff --git a/src/main/java/x/DeviceUtils/DeviceListUtils.java b/src/main/java/x/DeviceUtils/DeviceListUtils.java index 9e83b12..8e410f0 100755 --- a/src/main/java/x/DeviceUtils/DeviceListUtils.java +++ b/src/main/java/x/DeviceUtils/DeviceListUtils.java @@ -22,6 +22,7 @@ public class DeviceListUtils { private int maxInputBusaddress = -1; private int maxOutputBusaddress = -1; private int maxAnalogInBusaddress = -1; + private String lastBusUpdate = ""; private static DeviceListUtils singleton = null; @@ -43,6 +44,14 @@ public List getDeviceList() { return this.deviceList; } + public String getLastBusUpdate() { + return lastBusUpdate; + } + + public void setLastBusUpdate(String lastBusUpdate) { + this.lastBusUpdate = lastBusUpdate; + } + public ArrayList getInputDevicesByCategorie(String categorie) { ArrayList list = new ArrayList<>(); for (Object device : deviceList) { diff --git a/src/main/java/x/DeviceUtils/Types.java b/src/main/java/x/DeviceUtils/Types.java index 25dab5c..e2a7c82 100755 --- a/src/main/java/x/DeviceUtils/Types.java +++ b/src/main/java/x/DeviceUtils/Types.java @@ -2,6 +2,8 @@ public class Types { + public static final int TYPE_BUSINFO = 100000; + public static final int TYPE_INPUT = 1000; public static final int TYPE_OUTPUT = 2000; public static final int TYPE_TEMPERATURE = 3000; diff --git a/src/main/java/x/bus/BaseBus.java b/src/main/java/x/bus/BaseBus.java index b2c5f4f..f3c9187 100644 --- a/src/main/java/x/bus/BaseBus.java +++ b/src/main/java/x/bus/BaseBus.java @@ -1,6 +1,7 @@ package x.bus; import java.lang.reflect.Field; +import java.text.SimpleDateFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import x.DeviceUtils.DeviceListUtils; @@ -11,10 +12,12 @@ import x.utils.FieldParser; import x.utils.PropertyInfo; import x.websocket.model.AsyncStatusMessage; +import java.util.Calendar; public class BaseBus { private final Logger logger = LoggerFactory.getLogger(BaseBus.class); + private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); public void start() { @@ -71,6 +74,14 @@ public void updateDeviceHandleStatusForWebSocket(int cycleTime, long elapsedTime } } } + MessageHandler.getInstance().messageToWebSocketClients(globalASM); + + try { + DeviceListUtils.getInstance().setLastBusUpdate(dateFormat.format(Calendar.getInstance().getTime())); + } catch (Exception e) { + DeviceListUtils.getInstance().setLastBusUpdate("-"); + } + } } diff --git a/src/main/java/x/main/XHomeautomationMain.java b/src/main/java/x/main/XHomeautomationMain.java index 82483af..e317e6e 100755 --- a/src/main/java/x/main/XHomeautomationMain.java +++ b/src/main/java/x/main/XHomeautomationMain.java @@ -31,7 +31,7 @@ public class XHomeautomationMain implements ApplicationRunner { Logger logger = LoggerFactory.getLogger(XHomeautomationMain.class); - public static final String VERSION = "2.2.7"; + public static final String VERSION = "2.2.8"; @Autowired RetainProcess retainProcess; diff --git a/src/main/java/x/utils/RemoteAccessRequest.java b/src/main/java/x/utils/RemoteAccessRequest.java index 2a8e7bc..8a96b9d 100755 --- a/src/main/java/x/utils/RemoteAccessRequest.java +++ b/src/main/java/x/utils/RemoteAccessRequest.java @@ -58,11 +58,36 @@ private void getStatefulDeviceProperties(Object deviceHandleObject, int deviceHa } } + private void addSystemInfo(AutomationRequestParams atRequestParams) { + + HashMap busInfoMap = new HashMap<>(); + busInfoMap.put("type", Types.TYPE_BUSINFO); + busInfoMap.put("categorie", "System"); + busInfoMap.put("name", "Systeminfo"); + + ArrayList list = new ArrayList<>(); + HashMap m = new HashMap<>(); + m.put("handle", 0); + m.put("displayName", "Last Busupdate"); + m.put("value", DeviceListUtils.getInstance().getLastBusUpdate()); + m.put("stateful", false); + m.put("editable", false); + list.add(0, m); + busInfoMap.put("properties", list); + + atRequestParams.getParams().put((Types.TYPE_BUSINFO * -1), busInfoMap); + } + private AutomationRequest generateCommitMessage() { + AutomationRequest atRequest = new AutomationRequest(); atRequest.setPlugin("automation"); + AutomationRequestParams atRequestParams = new AutomationRequestParams(); atRequestParams.setMethod("commit"); + + addSystemInfo(atRequestParams); + for (Object deviceHandle : DeviceListUtils.getInstance().getDeviceList()) { HashMap tmpMap = new HashMap<>(); if (deviceHandle instanceof OutputDevice) { From ef451ac4e984e3074008839d4cbd4ada72989fd6 Mon Sep 17 00:00:00 2001 From: "XProjects B.Hummel" Date: Thu, 11 Feb 2021 18:46:14 +0100 Subject: [PATCH 2/2] Rename SystemInfo-Type --- src/main/java/x/DeviceUtils/Types.java | 2 +- src/main/java/x/utils/RemoteAccessRequest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/x/DeviceUtils/Types.java b/src/main/java/x/DeviceUtils/Types.java index e2a7c82..93a7bed 100755 --- a/src/main/java/x/DeviceUtils/Types.java +++ b/src/main/java/x/DeviceUtils/Types.java @@ -2,7 +2,7 @@ public class Types { - public static final int TYPE_BUSINFO = 100000; + public static final int TYPE_SYSTEMINFO = 100000; public static final int TYPE_INPUT = 1000; public static final int TYPE_OUTPUT = 2000; diff --git a/src/main/java/x/utils/RemoteAccessRequest.java b/src/main/java/x/utils/RemoteAccessRequest.java index 8a96b9d..81c8027 100755 --- a/src/main/java/x/utils/RemoteAccessRequest.java +++ b/src/main/java/x/utils/RemoteAccessRequest.java @@ -61,7 +61,7 @@ private void getStatefulDeviceProperties(Object deviceHandleObject, int deviceHa private void addSystemInfo(AutomationRequestParams atRequestParams) { HashMap busInfoMap = new HashMap<>(); - busInfoMap.put("type", Types.TYPE_BUSINFO); + busInfoMap.put("type", Types.TYPE_SYSTEMINFO); busInfoMap.put("categorie", "System"); busInfoMap.put("name", "Systeminfo"); @@ -75,7 +75,7 @@ private void addSystemInfo(AutomationRequestParams atRequestParams) { list.add(0, m); busInfoMap.put("properties", list); - atRequestParams.getParams().put((Types.TYPE_BUSINFO * -1), busInfoMap); + atRequestParams.getParams().put((Types.TYPE_SYSTEMINFO * -1), busInfoMap); } private AutomationRequest generateCommitMessage() {