From 83598cc6a27b05921410ec097975ee0b80c73647 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Sat, 1 Dec 2018 14:28:35 +0000 Subject: [PATCH] Add helper method to get firmware version from OTA cluster Signed-off-by: Chris Jackson --- .../zigbee/app/otaserver/ZclOtaUpgradeServer.java | 13 +++++++++++++ .../app/otaupgrade/ZclOtaUpgradeServerTest.java | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/app/otaserver/ZclOtaUpgradeServer.java b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/app/otaserver/ZclOtaUpgradeServer.java index 6aa3dacfe4..ad20a77ae7 100644 --- a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/app/otaserver/ZclOtaUpgradeServer.java +++ b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/app/otaserver/ZclOtaUpgradeServer.java @@ -460,6 +460,19 @@ public void run() { return false; } + /** + * The file version of the running firmware image on the device. The information is available for the server to + * query via ZCL read attribute command. The attribute is optional on the client. + *

+ * This calls the synchronous method in the cluster, and always performs an update (ie will not use cached data) to + * ensure it is updated following any OTA upgrade operation. + * + * @return the current firmware version on the remote device + */ + public Integer getCurrentFileVersion() { + return cluster.getCurrentFileVersion(Long.MAX_VALUE); + } + /** * Send an updated status on OTA progress to the listeners * diff --git a/com.zsmartsystems.zigbee/src/test/java/com/zsmartsystems/zigbee/app/otaupgrade/ZclOtaUpgradeServerTest.java b/com.zsmartsystems.zigbee/src/test/java/com/zsmartsystems/zigbee/app/otaupgrade/ZclOtaUpgradeServerTest.java index 97020220ac..973ea85bcc 100644 --- a/com.zsmartsystems.zigbee/src/test/java/com/zsmartsystems/zigbee/app/otaupgrade/ZclOtaUpgradeServerTest.java +++ b/com.zsmartsystems.zigbee/src/test/java/com/zsmartsystems/zigbee/app/otaupgrade/ZclOtaUpgradeServerTest.java @@ -129,6 +129,16 @@ public Future answer(InvocationOnMock invocation) { assertTrue(notifyCommand.getQueryJitter() >= 1 && notifyCommand.getQueryJitter() <= 100); } + @Test + public void getCurrentFileVersion() { + ZclOtaUpgradeCluster cluster = Mockito.mock(ZclOtaUpgradeCluster.class); + Mockito.when(cluster.getCurrentFileVersion(ArgumentMatchers.anyLong())).thenReturn(1234); + + ZclOtaUpgradeServer server = new ZclOtaUpgradeServer(); + server.appStartup(cluster); + assertEquals(Integer.valueOf(1234), server.getCurrentFileVersion()); + } + @Override public void otaStatusUpdate(ZigBeeOtaServerStatus status, int percent) { otaStatusCapture.add(status);