Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
...
Collection<Device> devices = gw.listDevices();

getDevice(String)

Usage

Gets Get the device with the corresponding idID.

Assumes that id is unique, and there should only be one device per idID.

* * @param id of the device * @returnĀ 

Parameters

TypeDescription
StringA unique identifier associated with the Device.

...

Return TypeDescription
DeviceDevice associated with the idID; otherwise null on all errors, including if the ID was not found, or if there were duplicate Devices found (i.e. the ID was not unique).

...

upgradeFirmware(ConnectionInfo, File, ResultConsumer<SerialUploadResult>)

Usage

Performs a firmware upgrade of the network interface (i.e. module) represented by the given ConnectionInfo object.

Progress is conveyed via a user-provided ResultConsumer<SerialUploadResult> callback. The callback is called more than once until completion of the upgrade, or if an error occurs.

The callback is called from a dedicated thread.

Notes:

  • If there is an attempt to upgrade to the same ConnectionInfo while an upgrade is already in progress, then that attempt will fail, the ResultConsumer callback will be called with an error, and the CompletableFuture shall return a Status.FAILED immediately.
  • This method is non-blocking.
  • This method is not thread-safe.



@param callback Result, progress, and errors are propagated here.

@return CompletableFuture<Status> where {@link Future#get()} and {@link Future#get(long, TimeUnit)} return * a {@link com.mmbnetworks.gatewayapi.entity.Status}. The {@link com.mmbnetworks.gatewayapi.entity.Status#FAILED} * almost always means something went wrong with the serial upgrade process. * * @throws IllegalArgumentException If connectionInfo is null, upgradeFile is null or is a directory * @see ResultConsumer * @see Future

Parameters

TypeDescription
ConnectionInfoConnectionInfo of the network interface being upgraded (see getConnectionInfo() API).
FileUpgrade file for the specified network interface.
ResultConsumer<SerialUploadResult>User-provided callback in order to receive notifications regarding upgrade progress.

Returns

Return TypeDescription
CompletableFuture<Status>A CompletableFuture that will contain the status of the upgrade result.

Progress is conveyed via a user-provided ResultConsumer<SerialUploadResult> callback. The callback is called more than once until completion of the upgrade, or if an error occurs.

If there is an attempt to upgrade to the same ConnectionInfo while an upgrade is already in progress, then that attempt will fail, the ResultConsumer callback will be called with an error, and the CompletableFuture shall return a Status.FAILED immediately.

Example

Code Block
languagejava
public void doSerialUpgrade() throws InterruptedException, ExecutionException, TimeoutException, IOException {
		// setup
		final GatewayClient gw = new GatewayClient(new ConnectionInfo(ConnectionType.ZIGBEE_UART, "/dev/ttyUSB0"));
        final File upgradeFile = new File("/path/to/file");

        // start the upgrade
        final Collection<ConnectionInfo> connections = gw.getConnectionInfo();
        for (ConnectionInfo c : connections) {
            if (c.getType() == ConnectionType.ZIGBEE_UART) {
                final Status status = gw.upgradeFirmware(c, upgradeFile, serialCallback).get(UPGRADE_TIMEOUT_MINUTES, TimeUnit.MINUTES);
                System.out.println("Status: " + status);            }
        }
    }
    
private final static ResultConsumer<SerialUploadResult> serialCallback = ResultConsumer.createResultConsumer(
    (result) -> {
        SerialUploadResult r = (SerialUploadResult)result;
        IntegrationTestUtils.testPrint("Progress: " + r.getProgress());
    },
    (throwable) -> {
        fail("Serial upload failed: " + throwable.getMessage());
     }
);


Network API

getNetworkStatus(ConnectionInfo)

...