Skip to content

Commit

Permalink
OTA Upgrade: Respect that CurrentFileVersion attribute is optional
Browse files Browse the repository at this point in the history
Fixes #1087

Signed-off-by: Stefan Triller <[email protected]>
  • Loading branch information
triller-telekom committed Jul 24, 2020
1 parent 597ba85 commit 8ea6349
Showing 1 changed file with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,18 +463,50 @@ public void run() {
// some time to complete, we retry this a few times.
for (int cnt = 0; cnt < CURRENT_FW_VERSION_REQUEST_RETRIES; cnt++) {
Thread.sleep(CURRENT_FW_VERSION_REQUEST_DELAY);
Integer fileVersion = (Integer) cluster
.getAttribute(ZclOtaUpgradeCluster.ATTR_CURRENTFILEVERSION).readValue(0);
if (fileVersion == null) {
CommandResult currentVersionCommandResult = cluster.sendCommand(
new ReadAttributesCommand(Arrays.asList(ZclOtaUpgradeCluster.ATTR_CURRENTFILEVERSION)))
.get();

if (currentVersionCommandResult == null) {
continue;
}

if (fileVersion.equals(otaFile.getFileVersion())) {
updateStatus(ZigBeeOtaServerStatus.OTA_UPGRADE_COMPLETE);
return;
ZigBeeCommand currentVersionResponse = currentVersionCommandResult.getResponse();

if (currentVersionResponse instanceof ReadAttributesResponse) {
ReadAttributesResponse attributesResponse = (ReadAttributesResponse) currentVersionResponse;
logger.debug("{} : OTA file version to be installed={} Received ReadAttributesResponse: {}",
cluster.getZigBeeAddress(), otaFile.getFileVersion(), attributesResponse);
if (!attributesResponse.getRecords().isEmpty()
&& attributesResponse.getRecords().get(0).getStatus() == ZclStatus.SUCCESS) {
Integer fileVersion = (Integer) attributesResponse.getRecords().get(0)
.getAttributeValue();

if (fileVersion == null) {
continue;
}

if (fileVersion.equals(otaFile.getFileVersion())) {
updateStatus(ZigBeeOtaServerStatus.OTA_UPGRADE_COMPLETE);
return;
}
}
} else if (currentVersionResponse instanceof DefaultResponse) {
DefaultResponse defaultResponse = (DefaultResponse) currentVersionResponse;
logger.debug("{} : Received DefaultResponse: {}", cluster.getZigBeeAddress(),
defaultResponse);
if (defaultResponse.getStatusCode() == ZclStatus.UNSUPPORTED_ATTRIBUTE) {
// since this attribute is optional in the specification, we take a reply with
// UNSUPPORTED_ATTRIBUTE as the case where the device is reachable again after it has
// successfully rebooted
updateStatus(ZigBeeOtaServerStatus.OTA_UPGRADE_COMPLETE);
return;
}
}
}

logger.debug(
"{} : All attempts to reach the device failed after it should have rebooted, taking this as a failure.",
cluster.getZigBeeAddress());
updateStatus(ZigBeeOtaServerStatus.OTA_UPGRADE_FAILED);
} catch (InterruptedException | ExecutionException e) {
logger.debug("Error during OTA completeUpgrade ", e);
Expand Down

0 comments on commit 8ea6349

Please sign in to comment.