Search in sources :

Example 1 with EzspSendUnicastRequest

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

Aggregations

EzspFrameRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameRequest)1 EzspSendBroadcastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest)1 EzspSendMulticastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendMulticastRequest)1 EzspSendUnicastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendUnicastRequest)1 EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)1