use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZDO_MSG_CB_INCOMING method translate.
/**
* Translates the ZigBee ZDO cluster packet into a ZTool RSP packet
*/
public ZToolPacket translate() {
ZToolPacket newPacket;
int[] frame;
logger.trace("Translating ZDO cluster callback {}", ClusterId);
Class<? extends ZToolPacket> newPacketClass = clusterToRSP.get(ClusterId.get16BitValue());
if (newPacketClass == null) {
logger.error("Unhandled ZDO cluster callback {}", ClusterId);
return this;
} else if (newPacketClass == ZDO_NWK_ADDR_RSP.class || newPacketClass == ZDO_IEEE_ADDR_RSP.class) {
// The address responses don't need SrcAddr. NumAssocDev and StartIndex positions are reversed.
// The new response frame is at least 13 bytes long.
frame = new int[Math.max(Data.length, 13)];
System.arraycopy(Data, 0, frame, 0, Data.length);
// If RequestType == 1 there are two extra bytes in the frame
if (Data.length > 12) {
// NumAssocDev
frame[11] = Data[12];
// StartIndex
frame[12] = Data[11];
} else {
frame[11] = 0;
frame[12] = 0;
}
} else {
// Default frame translation, this works for most callbacks.
// Get 2 extra bytes at the beginning to put source address into.
frame = new int[Data.length + 2];
System.arraycopy(Data, 0, frame, 2, Data.length);
frame[0] = SrcAddr.getLsb();
frame[1] = SrcAddr.getMsb();
}
try {
newPacket = newPacketClass.getConstructor(int[].class).newInstance(frame);
} catch (Exception e) {
logger.error("Error constructing response packet {}", e);
return this;
}
// Set checksum with original packet checksum
newPacket.setFCS(this.FCS);
return newPacket;
}
Aggregations