gpt4 book ai didi

com.zsmartsystems.zigbee.app.otaserver.ZclOtaUpgradeServer类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 14:35:31 24 4
gpt4 key购买 nike

本文整理了Java中com.zsmartsystems.zigbee.app.otaserver.ZclOtaUpgradeServer类的一些代码示例,展示了ZclOtaUpgradeServer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZclOtaUpgradeServer类的具体详情如下:
包路径:com.zsmartsystems.zigbee.app.otaserver.ZclOtaUpgradeServer
类名称: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:

  • Frame type is 0x01: commands are cluster specific (not a global command).
  • Manufacturer specific is 0x00: commands are not manufacturer specific.
  • Direction: shall be either 0x00 (client->server) or 0x01 (server->client) depending on the commands.
  • Disable default response is 0x00 for all OTA request commands sent from client to server: default response command shall be sent when the server receives OTA Upgrade cluster request commands that it does not support or in case an error case happens. A detailed explanation of each error case along with its recommended action is described for each OTA cluster command.
  • Disable default response is 0x01 for all OTA response commands (sent from server to client) and for broadcast/multicast Image Notify command: default response command is not sent when the client receives a valid OTA Upgrade cluster response commands or when it receives broadcast or multicast Image Notify command. However, if a client receives invalid OTA Upgrade cluster response command, a default response shall be sent. A detailed explanation of each error case along with its recommended action is described for each OTA cluster command.

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。
*服务器发送查询下一个图像响应
*客户端发送图像块/页面请求
*服务器发送图像块响应
*客户端发送图像块/页面请求
*服务器发送图像块响应

  • ... 重复到传输结束
    *客户端发送升级结束请求。状态设置为ZigBeeOta服务器状态#OTA_传输_完成。
    *服务器等待调用#completeUpgrade(),除非ZclOtaUpgradeServer#autoUpgrade为true。
    *服务器检查客户端状态。如果是ImageUpgradeStatus。下载完成后发送升级结束响应。
    *客户端应使用默认响应进行响应,但由于设备可能会开始运行新固件,因此这可能并不总是能够实现。状态设置为ZigBeeOta服务器状态#OTA_升级_固件_重启。
    *服务器请求客户端上运行的当前文件版本,并根据加载的OTA文件版本进行检查。如果版本一致,状态设置为ZigBeeOtaServerStatus#OTA_UPGRADE_COMPLETE,或错误时状态设置为ZigBeeOtaServerStatus#OTA_UPGRADE_FAILED。
    *当新固件可用时,该过程从顶部开始。
    以下错误条件适用-:
    *一旦传输开始,如果客户端没有在定义的时间段内发送图像块/页面请求,传输将超时。此时段使用#setTransferTimeoutPeriod(long)方法设置。
    *如果服务器接收到的消息顺序不正确,它们将被忽略,传输将中止。例如,如果在服务器未收到QueryNext ImageRequest时收到ImageBlockRequest,则传输将终止。
    这个类使用ZigBeeOta集群,它提供低级命令。

代码示例

代码示例来源: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()));
  }
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com