Skip to content

Commit

Permalink
Merge pull request #16 from xprojects-de/development
Browse files Browse the repository at this point in the history
Move SystemInfo to seperate Class
  • Loading branch information
xprojects-de authored Feb 11, 2021
2 parents ddb0842 + 72f2df0 commit 2a5a8ba
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 22 deletions.
9 changes: 0 additions & 9 deletions src/main/java/x/DeviceUtils/DeviceListUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -44,14 +43,6 @@ public List<BaseDevice> getDeviceList() {
return this.deviceList;
}

public String getLastBusUpdate() {
return lastBusUpdate;
}

public void setLastBusUpdate(String lastBusUpdate) {
this.lastBusUpdate = lastBusUpdate;
}

public ArrayList<InputDevice> getInputDevicesByCategorie(String categorie) {
ArrayList<InputDevice> list = new ArrayList<>();
for (Object device : deviceList) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/x/bus/BaseBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import x.utils.PropertyInfo;
import x.websocket.model.AsyncStatusMessage;
import java.util.Calendar;
import x.utils.SystemInfo;

public class BaseBus {

Expand Down Expand Up @@ -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("-");
}

}
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/x/bus/ModbusMasterHomeautomation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,29 +83,38 @@ 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 {
writeModbusDigitalOutputs();
} catch (Exception ex) {
logger.error(ex.getMessage());
connectModbus(true);
sendUpdateInfo = false;
}

try {
writeModbusDimmerAnalogOutputs();
} catch (Exception ex) {
logger.error(ex.getMessage());
connectModbus(true);
sendUpdateInfo = false;
}

if (cyclicCounter % 150 == 0) {
Expand All @@ -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 {
Expand All @@ -136,6 +148,7 @@ public void start() {
worstCycleTime = elapsedTime;
}
}

cyclicCounter++;
}
} else {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/x/bus/ModbusMasterMemograph.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -89,6 +95,7 @@ public void start() {
} catch (Exception ex) {
logger.error(ex.getMessage());
connectModbus(true);
sendUpdateInfo = false;
}
}

Expand All @@ -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 {
Expand All @@ -121,6 +130,7 @@ public void start() {
worstCycleTime = elapsedTime;
}
}

cyclicCounter++;
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/x/main/XHomeautomationMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/x/utils/RemoteAccessRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,23 @@ private void addSystemInfo(AutomationRequestParams atRequestParams) {
busInfoMap.put("name", "Systeminfo");

ArrayList<Object> list = new ArrayList<>();
HashMap<Object, Object> 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<Object, Object> 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<Object, Object> 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);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/x/utils/SystemInfo.java
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 2a5a8ba

Please sign in to comment.