Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Add permitJoin methods to ZigBeeApi
Browse files Browse the repository at this point in the history
The permitJoin methods allow the configuration of the permit join state on the
routers and coordinators.  Timeout duration is configurable.
  • Loading branch information
presslab-us committed Mar 26, 2015
1 parent f190c9f commit 0fbd31b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
63 changes: 62 additions & 1 deletion zigbee-api/src/main/java/org/bubblecloud/zigbee/ZigBeeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.bubblecloud.zigbee.network.model.DiscoveryMode;
import org.bubblecloud.zigbee.network.model.DriverStatus;
import org.bubblecloud.zigbee.network.model.NetworkMode;
import org.bubblecloud.zigbee.network.packet.ZToolAddress16;
import org.bubblecloud.zigbee.network.packet.zdo.ZDO_MGMT_PERMIT_JOIN_REQ;
import org.bubblecloud.zigbee.network.packet.zdo.ZDO_MGMT_PERMIT_JOIN_RSP;
import org.bubblecloud.zigbee.api.DeviceListener;
import org.bubblecloud.zigbee.network.impl.ApplicationFrameworkLayer;
import org.bubblecloud.zigbee.api.*;
Expand Down Expand Up @@ -166,7 +169,6 @@ public boolean startup() {
}

ApplicationFrameworkLayer.getAFLayer(networkManager).createDefaultSendingEndPoint();

discoveryManager.startup();

return true;
Expand All @@ -181,6 +183,7 @@ public boolean isInitialBrowsingComplete() {
return discoveryManager.isInitialNetworkBrowsingComplete();
}


/**
* Shuts down network manager, network, context and discovery manager.
*/
Expand All @@ -191,6 +194,64 @@ public void shutdown() {
networkManager.shutdown();
}

/**
* Changes the permit join state.
*
* @param joinState boolean join state, true for enabled indefinetly, false for disabled
*
* @return true if success
*/
public boolean permitJoin(boolean joinState) {
if (joinState) {
return sendPermitJoin((byte)0xFF);
} else {
return sendPermitJoin((byte)0);
}
}

/**
* Changes the permit join state with a timeout duration.
*
* @param durationSeconds join duration in seconds, from 1-254
*
* @return true if success
*/
public boolean permitJoin(int durationSeconds) {
if (durationSeconds < 1 || durationSeconds > 254) {
LOGGER.error("permitJoin durationSeconds out of range: {}", durationSeconds);
return false;
}
return sendPermitJoin((byte)durationSeconds);
}

/**
* Sends the permit join state to routers and coordinators.
*
* @param data the data in the permit join request
*
* @return true if success
*/
private boolean sendPermitJoin(byte data) {
ZDO_MGMT_PERMIT_JOIN_RSP result;
final byte AddrBroadcast = 0x0F;
final byte AddrUnicast = 0x02;

LOGGER.debug("Sending permit join with data: {}", data);

/* Notify routers of permit join change; don't check result because they're not obligated to respond */
result = networkManager.sendPermitJoinRequest(new ZDO_MGMT_PERMIT_JOIN_REQ(AddrBroadcast, ZToolAddress16.ZCZR_BROADCAST, data, 1));

/* Notify coordinator of permit join change */
result = networkManager.sendPermitJoinRequest(new ZDO_MGMT_PERMIT_JOIN_REQ(AddrUnicast, new ZToolAddress16(0, 0), data, 1));

if (result == null || result.Status != 0) {
LOGGER.error("Error sending ZDO_MGMT_PERMIT_JOIN_REQ");
return false;
}

return true;
}

/**
* Serializes network state.
* @return the network state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ZToolAddress16 extends ZToolAddress {

public static final ZToolAddress16 BROADCAST = new ZToolAddress16(0xFF, 0xFF);
public static final ZToolAddress16 ZNET_BROADCAST = new ZToolAddress16(0xFF, 0xFE);
public static final ZToolAddress16 ZCZR_BROADCAST = new ZToolAddress16(0xFF, 0xFC);

private DoubleByte doubleByte = new DoubleByte();

Expand Down

0 comments on commit 0fbd31b

Please sign in to comment.