diff --git a/src/main/java/x/DeviceUtils/DeviceListUtils.java b/src/main/java/x/DeviceUtils/DeviceListUtils.java index 8e410f0..9e83b12 100755 --- a/src/main/java/x/DeviceUtils/DeviceListUtils.java +++ b/src/main/java/x/DeviceUtils/DeviceListUtils.java @@ -22,7 +22,6 @@ public class DeviceListUtils { private int maxInputBusaddress = -1; private int maxOutputBusaddress = -1; private int maxAnalogInBusaddress = -1; - private String lastBusUpdate = ""; private static DeviceListUtils singleton = null; @@ -44,14 +43,6 @@ 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/bus/BaseBus.java b/src/main/java/x/bus/BaseBus.java index f3c9187..89044e5 100644 --- a/src/main/java/x/bus/BaseBus.java +++ b/src/main/java/x/bus/BaseBus.java @@ -13,6 +13,7 @@ import x.utils.PropertyInfo; import x.websocket.model.AsyncStatusMessage; import java.util.Calendar; +import x.utils.SystemInfo; public class BaseBus { @@ -78,9 +79,9 @@ public void updateDeviceHandleStatusForWebSocket(int cycleTime, long elapsedTime MessageHandler.getInstance().messageToWebSocketClients(globalASM); try { - DeviceListUtils.getInstance().setLastBusUpdate(dateFormat.format(Calendar.getInstance().getTime())); + SystemInfo.getInstance().setLastBusUpdate(dateFormat.format(Calendar.getInstance().getTime())); } catch (Exception e) { - DeviceListUtils.getInstance().setLastBusUpdate("-"); + SystemInfo.getInstance().setLastBusUpdate("-"); } } diff --git a/src/main/java/x/bus/ModbusMasterHomeautomation.java b/src/main/java/x/bus/ModbusMasterHomeautomation.java index 4884332..f20c5fe 100755 --- a/src/main/java/x/bus/ModbusMasterHomeautomation.java +++ b/src/main/java/x/bus/ModbusMasterHomeautomation.java @@ -27,6 +27,7 @@ public class ModbusMasterHomeautomation extends BaseBus { long elapsedTime = 0; int cyclicCounter = 0; boolean modBusInit = false; + boolean sendUpdateInfo = true; private String modbusHost = "192.168.1.1"; private final int modbusPort = Modbus.DEFAULT_PORT; ModbusTCPMaster modbusMaster = null; @@ -82,15 +83,22 @@ private void connectModbus(boolean reconnect) { @Override public void start() { + connectModbus(false); + if (modBusInit == true) { while (true) { + + sendUpdateInfo = true; + startTime = System.currentTimeMillis(); + try { readModbusDigitalInputs(); } catch (Exception ex) { logger.error(ex.getMessage()); connectModbus(true); + sendUpdateInfo = false; } try { @@ -98,6 +106,7 @@ public void start() { } catch (Exception ex) { logger.error(ex.getMessage()); connectModbus(true); + sendUpdateInfo = false; } try { @@ -105,6 +114,7 @@ public void start() { } catch (Exception ex) { logger.error(ex.getMessage()); connectModbus(true); + sendUpdateInfo = false; } if (cyclicCounter % 150 == 0) { @@ -113,17 +123,19 @@ public void start() { } catch (Exception ex) { logger.error(ex.getMessage()); connectModbus(true); + sendUpdateInfo = false; } } - if (cyclicCounter % 50 == 0) { + if (cyclicCounter % 50 == 0 && sendUpdateInfo) { updateDeviceHandleStatusForWebSocket(cycleTime, elapsedTime, worstCycleTime); } - if (cyclicCounter >= 1000) { + if (cyclicCounter >= 1000 && sendUpdateInfo) { cyclicCounter = 0; logger.debug("INFO <" + cycleTime + "ms><" + elapsedTime + "ms><" + worstCycleTime + "ms>"); } + elapsedTime = System.currentTimeMillis() - startTime; if (elapsedTime < cycleTime) { try { @@ -136,6 +148,7 @@ public void start() { worstCycleTime = elapsedTime; } } + cyclicCounter++; } } else { diff --git a/src/main/java/x/bus/ModbusMasterMemograph.java b/src/main/java/x/bus/ModbusMasterMemograph.java index 87f2ddd..a95ad39 100644 --- a/src/main/java/x/bus/ModbusMasterMemograph.java +++ b/src/main/java/x/bus/ModbusMasterMemograph.java @@ -27,6 +27,7 @@ public class ModbusMasterMemograph extends BaseBus { long elapsedTime = 0; int cyclicCounter = 0; boolean modBusInit = false; + boolean sendUpdateInfo = true; private String modbusHost = "192.168.1.1"; private final int modbusPort = Modbus.DEFAULT_PORT; ModbusTCPMaster modbusMaster = null; @@ -78,9 +79,14 @@ private void connectModbus(boolean reconnect) { @Override public void start() { + connectModbus(false); + if (modBusInit == true) { while (true) { + + sendUpdateInfo = true; + startTime = System.currentTimeMillis(); if (cyclicCounter % 50 == 0) { @@ -89,6 +95,7 @@ public void start() { } catch (Exception ex) { logger.error(ex.getMessage()); connectModbus(true); + sendUpdateInfo = false; } } @@ -98,17 +105,19 @@ public void start() { } catch (Exception ex) { logger.error(ex.getMessage()); connectModbus(true); + sendUpdateInfo = false; } } - if (cyclicCounter % 50 == 0) { + if (cyclicCounter % 50 == 0 && sendUpdateInfo) { updateDeviceHandleStatusForWebSocket(cycleTime, elapsedTime, worstCycleTime); } - if (cyclicCounter >= 1000) { + if (cyclicCounter >= 1000 && sendUpdateInfo) { cyclicCounter = 0; logger.debug("INFO <" + cycleTime + "ms><" + elapsedTime + "ms><" + worstCycleTime + "ms>"); } + elapsedTime = System.currentTimeMillis() - startTime; if (elapsedTime < cycleTime) { try { @@ -121,6 +130,7 @@ public void start() { worstCycleTime = elapsedTime; } } + cyclicCounter++; } } else { diff --git a/src/main/java/x/main/XHomeautomationMain.java b/src/main/java/x/main/XHomeautomationMain.java index e317e6e..58f3038 100755 --- a/src/main/java/x/main/XHomeautomationMain.java +++ b/src/main/java/x/main/XHomeautomationMain.java @@ -23,6 +23,7 @@ import x.bus.ModbusMasterMemograph; import x.retain.RetainProcess; import x.utils.DeviceXMLParser; +import x.utils.SystemInfo; @SpringBootApplication(scanBasePackages = {"x.rest", "x.websocket", "x.retain"}) @EntityScan("x.retain.database") @@ -99,6 +100,7 @@ public void run(ApplicationArguments args) throws Exception { } if (argsv.length >= 1) { logger.info("Version: " + XHomeautomationMain.VERSION); + SystemInfo.getInstance().setVersion(VERSION); Properties prop = new Properties(); BufferedInputStream stream; try { diff --git a/src/main/java/x/utils/RemoteAccessRequest.java b/src/main/java/x/utils/RemoteAccessRequest.java index 81c8027..1bc5fdf 100755 --- a/src/main/java/x/utils/RemoteAccessRequest.java +++ b/src/main/java/x/utils/RemoteAccessRequest.java @@ -66,13 +66,23 @@ private void addSystemInfo(AutomationRequestParams atRequestParams) { 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); + + HashMap version = new HashMap<>(); + version.put("handle", 0); + version.put("displayName", "Systemversion"); + version.put("value", SystemInfo.getInstance().getVersion()); + version.put("stateful", false); + version.put("editable", false); + list.add(version); + + HashMap bus = new HashMap<>(); + bus.put("handle", 1); + bus.put("displayName", "Last Busupdate"); + bus.put("value", SystemInfo.getInstance().getLastBusUpdate()); + bus.put("stateful", false); + bus.put("editable", false); + list.add(bus); + busInfoMap.put("properties", list); atRequestParams.getParams().put((Types.TYPE_SYSTEMINFO * -1), busInfoMap); diff --git a/src/main/java/x/utils/SystemInfo.java b/src/main/java/x/utils/SystemInfo.java new file mode 100644 index 0000000..65b0f9f --- /dev/null +++ b/src/main/java/x/utils/SystemInfo.java @@ -0,0 +1,36 @@ +package x.utils; + +public class SystemInfo { + + private static SystemInfo singleton = null; + + private String version = ""; + private String lastBusUpdate = ""; + + public SystemInfo() { + } + + public static SystemInfo getInstance() { + if (singleton == null) { + singleton = new SystemInfo(); + } + return singleton; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getLastBusUpdate() { + return lastBusUpdate; + } + + public void setLastBusUpdate(String lastBusUpdate) { + this.lastBusUpdate = lastBusUpdate; + } + +}