use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZdoIeeeAddress method create.
public static ZigBeeApsFrame create(ZToolPacket packet) {
ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
apsFrame.setCluster(ZdoCommandType.IEEE_ADDRESS_RESPONSE.getClusterId());
apsFrame.setDestinationEndpoint(0);
apsFrame.setSourceAddress(packet.getPacket()[13] + (packet.getPacket()[14] << 8));
apsFrame.setSourceEndpoint(0);
apsFrame.setProfile(0);
int[] temp = Arrays.copyOfRange(packet.getPacket(), 3, packet.getPacket().length - 1);
int a = temp[12];
temp[12] = temp[13];
temp[13] = a;
temp[0] = 0;
apsFrame.setPayload(temp);
return apsFrame;
}
use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZdoManagementLqi method create.
public static ZigBeeApsFrame create(ZToolPacket packet) {
ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
apsFrame.setCluster(ZdoCommandType.MANAGEMENT_LQI_RESPONSE.getClusterId());
apsFrame.setDestinationEndpoint(0);
apsFrame.setSourceAddress(packet.getPacket()[4] + (packet.getPacket()[5] << 8));
apsFrame.setSourceEndpoint(0);
apsFrame.setProfile(0);
apsFrame.setPayload(Arrays.copyOfRange(packet.getPacket(), 5, packet.getPacket().length - 1));
return apsFrame;
}
use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZdoNodeDescriptor method create.
public static ZigBeeApsFrame create(ZToolPacket packet) {
ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
apsFrame.setCluster(ZdoCommandType.NODE_DESCRIPTOR_RESPONSE.getClusterId());
apsFrame.setDestinationEndpoint(0);
apsFrame.setSourceAddress(packet.getPacket()[4] + (packet.getPacket()[5] << 8));
apsFrame.setSourceEndpoint(0);
apsFrame.setProfile(0);
apsFrame.setPayload(Arrays.copyOfRange(packet.getPacket(), 5, packet.getPacket().length - 1));
return apsFrame;
}
use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeDongleXBee method xbeeEventReceived.
@Override
public void xbeeEventReceived(XBeeEvent event) {
if (event instanceof XBeeReceivePacketExplicitEvent) {
XBeeReceivePacketExplicitEvent rxMessage = (XBeeReceivePacketExplicitEvent) event;
ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
apsFrame.setCluster(rxMessage.getClusterId());
apsFrame.setDestinationEndpoint(rxMessage.getDestinationEndpoint());
apsFrame.setProfile(rxMessage.getProfileId());
apsFrame.setSourceEndpoint(rxMessage.getSourceEndpoint());
apsFrame.setSourceAddress(rxMessage.getNetworkAddress());
apsFrame.setPayload(rxMessage.getData());
zigbeeTransportReceive.receiveCommand(apsFrame);
return;
}
// Handle devices joining and leaving
if (event instanceof XBeeModemStatusEvent) {
XBeeModemStatusEvent modemStatus = (XBeeModemStatusEvent) event;
switch(modemStatus.getStatus()) {
case COORDINATOR_STARTED:
coordinatorStarted = true;
if (initialisationComplete) {
zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.ONLINE);
}
break;
case DISASSOCIATED:
zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
break;
case HARDWARE_RESET:
break;
case JOINED_NETWORK:
break;
case NETWORK_SECURITY_KEY_UPDATED:
break;
case WATCHDOG_TIMER_RESET:
break;
default:
break;
}
return;
}
// if (event instanceof TelegesisDeviceLeftNetworkEvent) {
// TelegesisDeviceLeftNetworkEvent deviceLeftEvent = (TelegesisDeviceLeftNetworkEvent) event;
// zigbeeTransportReceive.nodeStatusUpdate(ZigBeeNodeStatus.DEVICE_LEFT, deviceLeftEvent.getNetworkAddress(),
// deviceLeftEvent.getIeeeAddress());
// return;
// }
// Handle link changes and notify framework or just reset link with dongle?
// if (event instanceof TelegesisNetworkLeftEvent | event instanceof TelegesisNetworkLostEvent) {
// zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
// return;
// }
// if (event instanceof TelegesisNetworkJoinedEvent) {
// zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.ONLINE);
// return;
// }
logger.debug("Unhandled XBee Frame: {}", event.toString());
}
use of com.zsmartsystems.zigbee.ZigBeeApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeDongleXBeeTest method sendCommand.
@Test
public void sendCommand() {
XBeeFrameHandler frameHandler = Mockito.mock(XBeeFrameHandler.class);
ArgumentCaptor<XBeeCommand> commandCapture = ArgumentCaptor.forClass(XBeeCommand.class);
Mockito.when(frameHandler.sendRequestAsync(commandCapture.capture())).thenReturn(null);
ZigBeeDongleXBee dongle = new ZigBeeDongleXBee(null);
Field field;
try {
field = dongle.getClass().getDeclaredField("frameHandler");
field.setAccessible(true);
field.set(dongle, frameHandler);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
MatchDescriptorResponse command = new MatchDescriptorResponse();
command.setDestinationAddress(new ZigBeeEndpointAddress(46946));
command.setNwkAddrOfInterest(46946);
command.setStatus(ZdoStatus.SUCCESS);
command.setTransactionId(0x2A);
List<Integer> matchList = new ArrayList<>();
matchList.add(1);
command.setMatchList(matchList);
ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
apsFrame.setDestinationAddress(46946);
apsFrame.setDestinationEndpoint(0);
apsFrame.setDestinationIeeeAddress(new IeeeAddress("000D6F00057CF7C6"));
apsFrame.setCluster(32774);
apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE);
apsFrame.setRadius(31);
apsFrame.setSequence(42);
apsFrame.setPayload(new int[] { 0x00, 0x00, 0x2E, 0x5B, 0x01, 0x01 });
System.out.println(command);
System.out.println(apsFrame);
dongle.sendCommand(apsFrame);
assertEquals(1, commandCapture.getAllValues().size());
XBeeTransmitRequestExplicitCommand sentCommand = (XBeeTransmitRequestExplicitCommand) commandCapture.getValue();
sentCommand.setFrameId(32);
System.out.println(sentCommand);
int[] payload = new int[] { 0, 26, 17, 32, 0, 13, 111, 0, 5, 124, 247, 198, 183, 98, 0, 0, 128, 6, 0, 0, 0, 32, 0, 0, 46, 91, 1, 1, 202 };
int[] output = sentCommand.serialize();
assertTrue(Arrays.equals(payload, output));
}
Aggregations