Search in sources :

Example 1 with EmberApsFrame

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class EzspSendUnicastTest method testSendPermitJoining.

@Test
public void testSendPermitJoining() {
    EzspFrame.setEzspVersion(4);
    ManagementPermitJoiningRequest permitJoining = new ManagementPermitJoiningRequest();
    permitJoining.setDestinationAddress(new ZigBeeEndpointAddress(0x401C));
    permitJoining.setSourceAddress(new ZigBeeEndpointAddress(0));
    permitJoining.setTcSignificance(false);
    permitJoining.setPermitDuration(60);
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    permitJoining.serialize(fieldSerializer);
    int[] payload = serializer.getPayload();
    EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest();
    EmberApsFrame apsFrame = new EmberApsFrame();
    apsFrame.setClusterId(permitJoining.getClusterId());
    apsFrame.setProfileId(0);
    apsFrame.setSourceEndpoint(1);
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setSequence(0x88);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_RETRY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY);
    apsFrame.setGroupId(0xffff);
    emberUnicast.setMessageTag(0x99);
    emberUnicast.setSequenceNumber(0xaa);
    emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT);
    emberUnicast.setApsFrame(apsFrame);
    emberUnicast.setIndexOrDestination(permitJoining.getDestinationAddress().getAddress());
    emberUnicast.setMessageContents(payload);
    int[] messageToSend = emberUnicast.serialize();
    System.out.println(emberUnicast.toString());
    System.out.println(Arrays.toString(messageToSend));
    String out = "";
    for (int c : messageToSend) {
        out += String.format("%02X ", c);
    }
    System.out.println(out);
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) EmberApsFrame(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) ManagementPermitJoiningRequest(com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) Test(org.junit.Test)

Example 2 with EmberApsFrame

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleEzsp method sendCommand.

@Override
public void sendCommand(final ZigBeeApsFrame apsFrame) {
    if (ashHandler == null) {
        return;
    }
    EzspFrameRequest emberCommand;
    EmberApsFrame emberApsFrame = new EmberApsFrame();
    emberApsFrame.setClusterId(apsFrame.getCluster());
    emberApsFrame.setProfileId(apsFrame.getProfile());
    emberApsFrame.setSourceEndpoint(apsFrame.getSourceEndpoint());
    emberApsFrame.setDestinationEndpoint(apsFrame.getDestinationEndpoint());
    emberApsFrame.setSequence(apsFrame.getApsCounter());
    emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_RETRY);
    emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY);
    emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY);
    if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && apsFrame.getDestinationAddress() < 0xfff8) {
        EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest();
        emberUnicast.setIndexOrDestination(apsFrame.getDestinationAddress());
        emberUnicast.setMessageTag(apsFrame.getSequence());
        emberUnicast.setSequenceNumber(apsFrame.getSequence());
        emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT);
        emberUnicast.setApsFrame(emberApsFrame);
        emberUnicast.setMessageContents(apsFrame.getPayload());
        emberCommand = emberUnicast;
    } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && apsFrame.getDestinationAddress() >= 0xfff8) {
        EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest();
        emberBroadcast.setDestination(apsFrame.getDestinationAddress());
        emberBroadcast.setMessageTag(apsFrame.getSequence());
        emberBroadcast.setSequenceNumber(apsFrame.getSequence());
        emberBroadcast.setApsFrame(emberApsFrame);
        emberBroadcast.setRadius(apsFrame.getRadius());
        emberBroadcast.setMessageContents(apsFrame.getPayload());
        emberCommand = emberBroadcast;
    } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) {
        emberApsFrame.setGroupId(apsFrame.getGroupAddress());
        EzspSendMulticastRequest emberMulticast = new EzspSendMulticastRequest();
        emberMulticast.setApsFrame(emberApsFrame);
        emberMulticast.setHops(apsFrame.getRadius());
        emberMulticast.setNonmemberRadius(apsFrame.getNonMemberRadius());
        emberMulticast.setMessageTag(apsFrame.getSequence());
        emberMulticast.setMessageContents(apsFrame.getPayload());
        emberCommand = emberMulticast;
    } else {
        logger.debug("EZSP message not sent: {}, {}", apsFrame);
        // apsFrame.setGroupId(groupAddress.getGroupId());
        return;
    }
    logger.debug(emberCommand.toString());
    ashHandler.queueFrame(emberCommand);
// emberUnicast = (EzspSendUnicast) ashHandler.sendEzspRequestAsync(emberUnicast);
}
Also used : EzspFrameRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameRequest) EmberApsFrame(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame) EzspSendBroadcastRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest) EzspSendUnicastRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendUnicastRequest) EzspSendMulticastRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendMulticastRequest)

Example 3 with EmberApsFrame

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleEzsp method handlePacket.

@Override
public void handlePacket(EzspFrame response) {
    logger.debug("RX: " + response.toString());
    if (response instanceof EzspIncomingMessageHandler) {
        EzspIncomingMessageHandler incomingMessage = (EzspIncomingMessageHandler) response;
        EmberApsFrame emberApsFrame = incomingMessage.getApsFrame();
        ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
        apsFrame.setApsCounter(emberApsFrame.getSequence());
        apsFrame.setCluster(emberApsFrame.getClusterId());
        apsFrame.setDestinationEndpoint(emberApsFrame.getDestinationEndpoint());
        apsFrame.setProfile(emberApsFrame.getProfileId());
        apsFrame.setSourceEndpoint(emberApsFrame.getSourceEndpoint());
        apsFrame.setSequence(incomingMessage.getSequenceNumber());
        apsFrame.setSourceAddress(incomingMessage.getSender());
        apsFrame.setPayload(incomingMessage.getMessageContents());
        zigbeeTransportReceive.receiveCommand(apsFrame);
        return;
    }
    // TODO: Check if this should be done only after initialisation is complete?
    if (response instanceof EzspStackStatusHandler) {
        switch(((EzspStackStatusHandler) response).getStatus()) {
            case EMBER_NETWORK_BUSY:
                break;
            case EMBER_NETWORK_DOWN:
                zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
                break;
            case EMBER_NETWORK_UP:
                break;
            default:
                break;
        }
        return;
    }
    if (response instanceof EzspTrustCenterJoinHandler) {
        EzspTrustCenterJoinHandler joinHandler = (EzspTrustCenterJoinHandler) response;
        ZigBeeNodeStatus status;
        switch(joinHandler.getStatus()) {
            case EMBER_HIGH_SECURITY_UNSECURED_JOIN:
            case EMBER_STANDARD_SECURITY_UNSECURED_JOIN:
                status = ZigBeeNodeStatus.UNSECURED_JOIN;
                break;
            case EMBER_HIGH_SECURITY_UNSECURED_REJOIN:
            case EMBER_STANDARD_SECURITY_UNSECURED_REJOIN:
                status = ZigBeeNodeStatus.UNSECURED_REJOIN;
                break;
            case EMBER_HIGH_SECURITY_SECURED_REJOIN:
            case EMBER_STANDARD_SECURITY_SECURED_REJOIN:
                status = ZigBeeNodeStatus.SECURED_REJOIN;
                break;
            case EMBER_DEVICE_LEFT:
                status = ZigBeeNodeStatus.DEVICE_LEFT;
                break;
            default:
                logger.debug("Unknown state in trust centre join handler {}", joinHandler.getStatus());
                return;
        }
        zigbeeTransportReceive.nodeStatusUpdate(status, joinHandler.getNewNodeId(), joinHandler.getNewNodeEui64());
        return;
    }
    if (response instanceof EzspChildJoinHandler) {
        EzspChildJoinHandler joinHandler = (EzspChildJoinHandler) response;
        zigbeeTransportReceive.nodeStatusUpdate(ZigBeeNodeStatus.UNSECURED_JOIN, joinHandler.getChildId(), joinHandler.getChildEui64());
        return;
    }
    logger.debug("Unhandled EZSP Frame: {}", response.toString());
}
Also used : ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) EzspStackStatusHandler(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspStackStatusHandler) EmberApsFrame(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame) ZigBeeNodeStatus(com.zsmartsystems.zigbee.ZigBeeNodeStatus) EzspIncomingMessageHandler(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspIncomingMessageHandler) EzspTrustCenterJoinHandler(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspTrustCenterJoinHandler) EzspChildJoinHandler(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspChildJoinHandler)

Example 4 with EmberApsFrame

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class EzspMessageSentHandlerTest method testReceive2.

@Test
public void testReceive2() {
    EzspFrame.setEzspVersion(4);
    EzspMessageSentHandler messageSentHandler = new EzspMessageSentHandler(getPacketData("04 90 3F 00 00 00 00 00 04 00 00 00 40 11 00 00 78 04 00 00"));
    System.out.println(messageSentHandler);
    assertTrue(messageSentHandler.isResponse());
    assertEquals(EmberStatus.EMBER_SUCCESS, messageSentHandler.getStatus());
    assertEquals(0, messageSentHandler.getMessageContents().length);
    assertEquals(0, messageSentHandler.getIndexOrDestination());
    assertEquals(4, messageSentHandler.getMessageTag());
    assertEquals(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, messageSentHandler.getType());
    EmberApsFrame apsFrame = messageSentHandler.getApsFrame();
    assertNotNull(apsFrame);
    assertEquals(3, apsFrame.getOptions().size());
    assertTrue(apsFrame.getOptions().contains(EmberApsOption.EMBER_APS_OPTION_RETRY));
    assertTrue(apsFrame.getOptions().contains(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY));
    assertTrue(apsFrame.getOptions().contains(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY));
    assertEquals(4, apsFrame.getClusterId());
    assertEquals(0, apsFrame.getProfileId());
    assertEquals(120, apsFrame.getSequence());
}
Also used : EmberApsFrame(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) Test(org.junit.Test)

Example 5 with EmberApsFrame

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.

the class EzspSendBroadcastTest method testSendPermitJoining.

@Test
public void testSendPermitJoining() {
    ManagementPermitJoiningRequest permitJoining = new ManagementPermitJoiningRequest();
    permitJoining.setDestinationAddress(new ZigBeeEndpointAddress(0xFFFC));
    permitJoining.setSourceAddress(new ZigBeeEndpointAddress(0));
    permitJoining.setTcSignificance(true);
    permitJoining.setPermitDuration(255);
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    permitJoining.serialize(fieldSerializer);
    int[] payload = serializer.getPayload();
    EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest();
    EmberApsFrame apsFrame = new EmberApsFrame();
    apsFrame.setClusterId(permitJoining.getClusterId());
    apsFrame.setProfileId(0);
    apsFrame.setSourceEndpoint(0);
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setSequence(5);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_RETRY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY);
    apsFrame.setGroupId(0);
    emberBroadcast.setMessageTag(5);
    emberBroadcast.setSequenceNumber(5);
    emberBroadcast.setApsFrame(apsFrame);
    emberBroadcast.setDestination(permitJoining.getDestinationAddress().getAddress());
    emberBroadcast.setMessageContents(payload);
    emberBroadcast.setRadius(31);
    int[] messageToSend = emberBroadcast.serialize();
    String out = "";
    for (int c : messageToSend) {
        out += String.format("%02X ", c);
    }
    System.out.println(out);
    assertTrue(Arrays.equals(getPacketData("05 00 36 FC FF 00 00 36 00 00 00 40 11 00 00 05 1F 05 03 00 FF 01"), messageToSend));
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) EzspSendBroadcastRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest) EmberApsFrame(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) ManagementPermitJoiningRequest(com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) Test(org.junit.Test)

Aggregations

EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)5 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)3 Test (org.junit.Test)3 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)2 EzspSendBroadcastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest)2 DefaultSerializer (com.zsmartsystems.zigbee.serialization.DefaultSerializer)2 ZclFieldSerializer (com.zsmartsystems.zigbee.zcl.ZclFieldSerializer)2 ManagementPermitJoiningRequest (com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest)2 ZigBeeApsFrame (com.zsmartsystems.zigbee.ZigBeeApsFrame)1 ZigBeeNodeStatus (com.zsmartsystems.zigbee.ZigBeeNodeStatus)1 EzspFrameRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameRequest)1 EzspChildJoinHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspChildJoinHandler)1 EzspIncomingMessageHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspIncomingMessageHandler)1 EzspSendMulticastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendMulticastRequest)1 EzspSendUnicastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendUnicastRequest)1 EzspStackStatusHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspStackStatusHandler)1 EzspTrustCenterJoinHandler (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspTrustCenterJoinHandler)1