Search in sources :

Example 1 with EzspSendBroadcastRequest

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest 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 2 with EzspSendBroadcastRequest

use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest 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

EzspSendBroadcastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest)2 EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)2 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)1 EzspFrameRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameRequest)1 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)1 EzspSendMulticastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendMulticastRequest)1 EzspSendUnicastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendUnicastRequest)1 DefaultSerializer (com.zsmartsystems.zigbee.serialization.DefaultSerializer)1 ZclFieldSerializer (com.zsmartsystems.zigbee.zcl.ZclFieldSerializer)1 ManagementPermitJoiningRequest (com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest)1 Test (org.junit.Test)1