本文整理了Java中com.zsmartsystems.zigbee.app.otaserver.ZclOtaUpgradeServer
类的一些代码示例,展示了ZclOtaUpgradeServer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZclOtaUpgradeServer
类的具体详情如下:
包路径:com.zsmartsystems.zigbee.app.otaserver.ZclOtaUpgradeServer
类名称:ZclOtaUpgradeServer
[英]This class implements the logic to implement the Over The Air (OTA) server for a ZigBee node.
OTA upgrade messages do not differ from typical ZigBee APS messages so the upgrade process should not interrupt the general network operation.
OTA Upgrade cluster commands, the frame control value shall follow the description below:
Users can register with #addListener to receive ZigBeeOtaStatusCallback calls when the status changes.
Upgrade lifecycle overview -:
Server instantiated. Status set to ZigBeeOtaServerStatus#OTA_UNINITIALISED.
#setFirmware(ZigBeeOtaFile) is called to set the firmware. Status set to ZigBeeOtaServerStatus#OTA_WAITING
Server sends Image Notify when the firmware is set.
User can call #notifyClient() periodically to send Image Notify.
Client sends Query Next Image Request. Status set to ZigBeeOtaServerStatus#OTA_TRANSFER_IN_PROGRESS.
Server sends Query Next Image Response
Client sends Image Block/Page Request
Server sends Image Block Response
Client sends Image Block/Page Request
Server sends Image Block Response
... repeat to end of transfer
Client sends Upgrade End Request. Status set to ZigBeeOtaServerStatus#OTA_TRANSFER_COMPLETE.
Server waits for #completeUpgrade() to be called unless ZclOtaUpgradeServer#autoUpgrade is true.
Server checks the client state. If it is ImageUpgradeStatus.DOWNLOAD_COMPLETE it sends Upgrade End Response.
Client should respond with the default response, but this may not always be implemented as the device may start to run the new firmware. Status set to ZigBeeOtaServerStatus#OTA_UPGRADE_FIRMWARE_RESTARTING.
Server requests the current file version running on the client and checks this against the OTA file version that was loaded. Status set to ZigBeeOtaServerStatus#OTA_UPGRADE_COMPLETE if the version is consistent, or Status set to ZigBeeOtaServerStatus#OTA_UPGRADE_FAILED on error.
When new firmware becomes available, the process begins from the top.
The following error conditions apply -:
Once the transfer is started, if the client doesn't send an image block/page request within a defined period the transfer will time out. This period is set with the #setTransferTimeoutPeriod(long) method.
If the server receives messages out of sequence, they will be ignored and the transfer will abort. For example if an ImageBlockRequest is received when the server has not received a QueryNextImageRequest the transfer will terminate.
This class uses the ZigBeeOtaCluster which provides the low level commands.
[中]此类实现了为ZigBee节点实现空中传送(OTA)服务器的逻辑。
OTA升级消息与典型的ZigBee APS消息没有区别,因此升级过程不应中断一般网络操作。
OTA升级集群命令,帧控制值应遵循以下说明:
*帧类型为0x01:命令特定于群集(不是全局命令)。
*特定于制造商的是0x00:命令不是特定于制造商的。
*方向:应为0x00(客户端->服务器)或0x01(服务器->客户端),具体取决于命令。
*对于从客户端发送到服务器的所有OTA请求命令,禁用默认响应为0x00:当服务器收到其不支持的OTA升级群集请求命令或发生错误时,应发送默认响应命令。对于每个OTA群集命令,将详细解释每个错误情况及其建议的操作。
*对于所有OTA响应命令(从服务器发送到客户端)和广播/多播映像通知命令,禁用默认响应为0x01:当客户端收到有效的OTA升级群集响应命令或接收广播或多播映像通知命令时,不会发送默认响应命令。但是,如果客户端收到无效的OTA升级集群响应命令,则应发送默认响应。对于每个OTA群集命令,将详细解释每个错误情况及其建议的操作。
用户可以向#addListener注册,以便在状态更改时接收ZigBeeOtaStatusCallback调用。
升级生命周期概述-:
*服务器已实例化。状态设置为ZigBeeOtaServerStatus#OTA_未初始化。
*#调用setFirmware(ZigBeeOtaFile)来设置固件。状态设置为ZigBeeOta服务器状态#OTA_等待
*设置固件时,服务器发送映像通知。
*用户可以定期调用#notifyClient()发送图像通知。
*客户端发送查询下一个图像请求。状态设置为ZigBeeOtaServerStatus#OTA_TRANSFER_IN_PROGRESS。
*服务器发送查询下一个图像响应
*客户端发送图像块/页面请求
*服务器发送图像块响应
*客户端发送图像块/页面请求
*服务器发送图像块响应
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
if (otaServer == null) {
otaServer = new ZclOtaUpgradeServer();
otaServer.addListener(new ZigBeeOtaStatusCallback() {
@Override
public void otaStatusUpdate(ZigBeeOtaServerStatus status, int percent) {
otaServer.completeUpgrade();
} else {
Path file = FileSystems.getDefault().getPath("./", args[2]);
print("OTA File: " + otaFile, out);
otaServer.setFirmware(otaFile);
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
private void cmdDisplayNode(ZigBeeEndpoint endpoint, ZclOtaUpgradeServer otaServer, PrintStream out) {
out.println("OTA Upgrade configuration for " + endpoint.getEndpointAddress());
out.println("Current state : " + otaServer.getServerStatus());
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
@Test
public void getClusterId() {
ZclOtaUpgradeServer server = new ZclOtaUpgradeServer();
// Use static number for independent check of cluster ID!
assertEquals(25, server.getClusterId());
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
ZclOtaUpgradeServer server = new ZclOtaUpgradeServer();
assertEquals(ZigBeeStatus.SUCCESS, server.appStartup(cluster));
server.addListener(this);
server.setDataSize(30);
server.setAutoUpgrade(false);
server.setAllowExistingFile(true);
server.setTransferTimeoutPeriod(Integer.MAX_VALUE);
server.cancelUpgrade();
assertEquals(0, otaStatusCapture.size());
Mockito.when(otaFile.getImageType()).thenReturn(987);
server.setFirmware(otaFile);
assertTrue(otaStatusCapture.contains(ZigBeeOtaServerStatus.OTA_WAITING));
query.setImageType(987);
server.commandReceived(query);
assertTrue(otaStatusCapture.contains(ZigBeeOtaServerStatus.OTA_TRANSFER_IN_PROGRESS));
server.cancelUpgrade();
Awaitility.await().atMost(1000, TimeUnit.MILLISECONDS).until(() -> otaListenerUpdated());
assertEquals(ZigBeeOtaServerStatus.OTA_CANCELLED, server.getServerStatus());
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
ZclOtaUpgradeServer server = new ZclOtaUpgradeServer();
assertEquals(ZigBeeStatus.SUCCESS, server.appStartup(cluster));
server.addListener(this);
server.setFirmware(otaFile);
assertTrue(notifyCommand.getQueryJitter() >= 1 && notifyCommand.getQueryJitter() <= 100);
server.removeListener(this);
System.out.println(server.toString());
代码示例来源:origin: openhab/org.openhab.binding.zigbee
otaServer = new ZclOtaUpgradeServer();
otaEndpoint.addApplication(otaServer);
otaServer.setFirmware(otaFile);
otaServer.addListener(new ZigBeeOtaStatusCallback() {
@Override
public void otaStatusUpdate(ZigBeeOtaServerStatus status, int percent) {
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
@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());
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
@Override
public void nodeAdded(ZigBeeNode node) {
for (ZigBeeEndpoint endpoint : node.getEndpoints()) {
if (endpoint.getOutputCluster(ZclOtaUpgradeCluster.CLUSTER_ID) != null) {
endpoint.addApplication(new ZclOtaUpgradeServer());
break;
}
}
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
stopTransferTimer();
updateStatus(ZigBeeOtaServerStatus.OTA_UPGRADE_FAILED);
return;
case REQUIRE_MORE_IMAGE:
updateStatus(ZigBeeOtaServerStatus.OTA_WAITING);
return;
default:
updateStatus(ZigBeeOtaServerStatus.OTA_TRANSFER_COMPLETE);
if (autoUpgrade) {
completeUpgrade();
代码示例来源:origin: openhab/org.openhab.binding.zigbee
finalOtaServer.cancelUpgrade();
Integer fileVersion = finalOtaServer.getCurrentFileVersion();
if (fileVersion != null) {
updateProperty(Thing.PROPERTY_FIRMWARE_VERSION, String.format("%08X", fileVersion));
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
private void cmdDisplayAllNodes(ZigBeeNetworkManager networkManager, PrintStream out) {
Map<Integer, ZigBeeEndpoint> applications = getApplications(networkManager, ZclOtaUpgradeCluster.CLUSTER_ID);
if (applications.isEmpty()) {
out.println("No OTA upgrade servers found.");
return;
}
out.println("Address Ieee Address State ");
for (ZigBeeEndpoint endpoint : applications.values()) {
ZclOtaUpgradeServer otaServer = (ZclOtaUpgradeServer) endpoint
.getApplication(ZclOtaUpgradeCluster.CLUSTER_ID);
out.println(String.format("%-9s %s %-8s", endpoint.getEndpointAddress(), endpoint.getIeeeAddress(),
otaServer.getServerStatus()));
}
}
内容来源于网络,如有侵权,请联系作者删除!