Search in sources :

Example 1 with EmberFirmwareUpdateHandler

use of com.zsmartsystems.zigbee.dongle.ember.internal.EmberFirmwareUpdateHandler in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleEzsp method updateFirmware.

@Override
public boolean updateFirmware(final InputStream firmware, final ZigBeeTransportFirmwareCallback callback) {
    if (ashHandler != null) {
        logger.debug("ashHandler is operating in updateFirmware");
        return false;
    }
    if (!initialiseEzspProtocol()) {
        return false;
    }
    zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
    callback.firmwareUpdateCallback(ZigBeeTransportFirmwareStatus.FIRMWARE_UPDATE_STARTED);
    // Send the bootload command, but ignore the response since there doesn't seem to be one
    // despite what the documentation seems to indicate
    EzspLaunchStandaloneBootloaderRequest bootloadCommand = new EzspLaunchStandaloneBootloaderRequest();
    EzspTransaction bootloadTransaction = ashHandler.sendEzspTransaction(new EzspSingleResponseTransaction(bootloadCommand, EzspLaunchStandaloneBootloaderResponse.class));
    EzspLaunchStandaloneBootloaderResponse bootloadResponse = (EzspLaunchStandaloneBootloaderResponse) bootloadTransaction.getResponse();
    logger.debug(bootloadResponse.toString());
    logger.debug("EZSP bootloadResponse {}", bootloadResponse.getStatus());
    if (bootloadResponse.getStatus() != EzspStatus.EZSP_SUCCESS) {
        callback.firmwareUpdateCallback(ZigBeeTransportFirmwareStatus.FIRMWARE_UPDATE_FAILED);
        logger.debug("EZSP bootload failed: bootloadResponse {}", bootloadResponse.getStatus());
        return false;
    }
    // Stop the handler and close the serial port
    logger.debug("EZSP closing frame handler");
    ashHandler.setClosing();
    serialPort.close();
    ashHandler.close();
    ashHandler = null;
    bootloadHandler = new EmberFirmwareUpdateHandler(this, firmware, serialPort, callback);
    bootloadHandler.startBootload();
    return true;
}
Also used : EmberFirmwareUpdateHandler(com.zsmartsystems.zigbee.dongle.ember.internal.EmberFirmwareUpdateHandler) EzspLaunchStandaloneBootloaderRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspLaunchStandaloneBootloaderRequest) EzspTransaction(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.transaction.EzspTransaction) EzspSingleResponseTransaction(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.transaction.EzspSingleResponseTransaction) EzspLaunchStandaloneBootloaderResponse(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspLaunchStandaloneBootloaderResponse)

Aggregations

EmberFirmwareUpdateHandler (com.zsmartsystems.zigbee.dongle.ember.internal.EmberFirmwareUpdateHandler)1 EzspLaunchStandaloneBootloaderRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspLaunchStandaloneBootloaderRequest)1 EzspLaunchStandaloneBootloaderResponse (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspLaunchStandaloneBootloaderResponse)1 EzspSingleResponseTransaction (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.transaction.EzspSingleResponseTransaction)1 EzspTransaction (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.transaction.EzspTransaction)1