Skip to content

Commit

Permalink
Merge pull request #15 from xprojects-de/development
Browse files Browse the repository at this point in the history
Adding BusInfo to Remote-Device
  • Loading branch information
xprojects-de authored Feb 11, 2021
2 parents 771c9ce + ef451ac commit ddb0842
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>x</groupId>
<artifactId>Alpdesk-Automationservice</artifactId>
<version>2.2.7</version>
<version>2.2.8</version>

<packaging>jar</packaging>

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/x/DeviceUtils/DeviceListUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,6 +44,14 @@ 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
2 changes: 2 additions & 0 deletions src/main/java/x/DeviceUtils/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class Types {

public static final int TYPE_SYSTEMINFO = 100000;

public static final int TYPE_INPUT = 1000;
public static final int TYPE_OUTPUT = 2000;
public static final int TYPE_TEMPERATURE = 3000;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/x/bus/BaseBus.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {

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

}
}
2 changes: 1 addition & 1 deletion src/main/java/x/main/XHomeautomationMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/x/utils/RemoteAccessRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,36 @@ private void getStatefulDeviceProperties(Object deviceHandleObject, int deviceHa
}
}

private void addSystemInfo(AutomationRequestParams atRequestParams) {

HashMap<Object, Object> busInfoMap = new HashMap<>();
busInfoMap.put("type", Types.TYPE_SYSTEMINFO);
busInfoMap.put("categorie", "System");
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);
busInfoMap.put("properties", list);

atRequestParams.getParams().put((Types.TYPE_SYSTEMINFO * -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<Object, Object> tmpMap = new HashMap<>();
if (deviceHandle instanceof OutputDevice) {
Expand Down

0 comments on commit ddb0842

Please sign in to comment.