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);
}
}
Aggregations