Search in sources :

Example 66 with IeeeAddress

use of com.zsmartsystems.zigbee.IeeeAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeOtaFile method readOtaFile.

/**
 * Create a {@link ZigBeeOtaFile} from a {@link File}. This reads the file and gets all the header items we need to
 * use for the transfer.
 */
private void readOtaFile() {
    if (fileData == null) {
        throw new IllegalArgumentException("ZigBeeOtaFile data can not be null.");
    }
    // types on disk. The value is defined to be ā€œ0x0BEEF11Eā€.
    if (readUnsigned32() != FILE_SIGNATURE) {
        throw new IllegalArgumentException("ZigBee OTA file is not a valid format");
    }
    // Unsigned 16-bit integer, OTA Header version
    headerVersion = readUnsigned16();
    // Unsigned 16-bit integer, OTA Header length
    headerLength = readUnsigned16();
    // Unsigned 16-bit integer, OTA Header Field control
    headerFieldControl = readUnsigned16();
    // Unsigned 16-bit integer, Manufacturer code
    manufacturerCode = readUnsigned16();
    // Unsigned 16-bit integer, Image type
    imageType = readUnsigned16();
    // Unsigned 32-bit integer, File version
    fileVersion = readUnsigned32();
    // Unsigned 16-bit integer, ZigBee Stack version
    stackVersion = ZigBeeStackType.getStackType(readUnsigned16());
    // Character string [32], OTA Header string
    byte[] stringBytes = Arrays.copyOfRange(fileData, filePointer, filePointer + 32);
    filePointer += 32;
    for (int cnt = 0; cnt < 32; cnt++) {
        if (stringBytes[cnt] == 0) {
            stringBytes = Arrays.copyOfRange(stringBytes, 0, cnt);
            break;
        }
    }
    headerString = new String(stringBytes);
    // Unsigned 32-bit integer, Total Image size (including header)
    imageSize = readUnsigned32();
    if ((headerFieldControl & FIELD_CTL_SECURITY_CREDENTIAL) != 0) {
        // Unsigned 8-bit integer, Security credential version [optional]
        securityCredentialVersion = readUnsigned8();
    }
    if ((headerFieldControl & FIELD_CTL_DEVICE_SPECIFIC) != 0) {
        // IEEE Address, Upgrade file destination [optional]
        int[] addressBytes = new int[8];
        for (int cnt = 0; cnt < 8; cnt++) {
            addressBytes[cnt] = readUnsigned16();
        }
        destination = new IeeeAddress(addressBytes);
    }
    if ((headerFieldControl & FIELD_CTL_HARDWARE_VERSIONS) != 0) {
        // Unsigned 16-bit integer, Minimum hardware version [optional]
        minimumHardware = readUnsigned16();
        // Unsigned 16-bit integer, Maximum hardware version [optional]
        maximumHardware = readUnsigned16();
    }
    // Read the tags
    while ((fileData.length - filePointer) >= 6) {
        // Tag Header -:
        // The tag identifier denotes the type and format of the data contained within the sub-element.
        int tagId = readUnsigned16();
        ZigBeeOtaTagType tagType = ZigBeeOtaTagType.getTagType(tagId);
        // The length dictates the length of the rest of the data within the sub-element in bytes. It does not
        // include the size of the Tag ID or the Length Fields.
        long tagLength = readUnsigned32();
        // Skip over the tag data
        filePointer += tagLength;
        logger.debug("Reading OTA image tag {}[{}] ({} bytes long)", tagType, String.format("%04X", tagId), tagLength);
    }
}
Also used : IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress)

Aggregations

IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)66 Test (org.junit.Test)53 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)12 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)12 CommandTest (com.zsmartsystems.zigbee.CommandTest)7 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)7 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)7 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)6 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)6 ArrayList (java.util.ArrayList)6 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)5 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)4 CommandResult (com.zsmartsystems.zigbee.CommandResult)3 ExtendedPanId (com.zsmartsystems.zigbee.ExtendedPanId)3 NodeDescriptor (com.zsmartsystems.zigbee.zdo.field.NodeDescriptor)3 HashSet (java.util.HashSet)3 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)2 EmberInitialSecurityState (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberInitialSecurityState)2 EmberKeyData (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData)2 XBeeFrameHandler (com.zsmartsystems.zigbee.dongle.xbee.internal.XBeeFrameHandler)2