Search in sources :

Example 1 with EzspFrameRequest

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

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

the class AshFrameHandler method sendNextFrame.

// Synchronize this method so we can do the window check without interruption.
// Otherwise this method could be called twice from different threads that could end up with
// more than the TX_WINDOW number of frames sent.
private synchronized boolean sendNextFrame() {
    // We're not allowed to send if we're not connected
    if (!stateConnected) {
        logger.debug("ASH: Trying to send when not connected.");
        return false;
    }
    // Check how many frames are outstanding
    if (sentQueue.size() >= TX_WINDOW) {
        // check timer task
        if (timerTask == null) {
            startRetryTimer();
        }
        return false;
    }
    EzspFrameRequest nextFrame = sendQueue.poll();
    if (nextFrame == null) {
        // Nothing to send
        return false;
    }
    // Encapsulate the EZSP frame into the ASH packet
    logger.debug("TX EZSP: {}", nextFrame);
    AshFrameData ashFrame = new AshFrameData(nextFrame);
    sendFrame(ashFrame);
    return true;
}
Also used : EzspFrameRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameRequest)

Aggregations

EzspFrameRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameRequest)2 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