use of com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest 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);
}
use of com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNode method permitJoin.
/**
* Enables or disables nodes to join to this node.
* <p>
* Nodes can only join the network when joining is enabled. It is not advised to leave joining enabled permanently
* since it allows nodes to join the network without the installer knowing.
*
* @param duration sets the duration of the join enable. Setting this to 0 disables joining. Setting to a value
* greater than 255 seconds will permanently enable joining.
*/
public void permitJoin(final int duration) {
final ManagementPermitJoiningRequest command = new ManagementPermitJoiningRequest();
if (duration > 255) {
command.setPermitDuration(255);
} else {
command.setPermitDuration(duration);
}
command.setTcSignificance(true);
command.setDestinationAddress(new ZigBeeEndpointAddress(0));
command.setSourceAddress(new ZigBeeEndpointAddress(0));
networkManager.sendCommand(command);
}
use of com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest 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));
}
use of com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkManager method permitJoin.
/**
* Enables or disables devices to join the network.
* <p>
* Devices can only join the network when joining is enabled. It is not advised to leave joining enabled permanently
* since it allows devices to join the network without the installer knowing.
*
* @param destination the {@link ZigBeeEndpointAddress} to send the join request to
* @param duration sets the duration of the join enable. Setting this to 0 disables joining. As per ZigBee 3, a
* value of 255 is not permitted and will be ignored.
*/
public boolean permitJoin(final ZigBeeEndpointAddress destination, final int duration) {
if (duration < 0 || duration >= 255) {
logger.debug("Permit join to {} invalid period of {} seconds.", destination, duration);
return false;
}
logger.debug("Permit join to {} for {} seconds.", destination, duration);
ManagementPermitJoiningRequest command = new ManagementPermitJoiningRequest();
command.setPermitDuration(duration);
command.setTcSignificance(true);
command.setDestinationAddress(destination);
command.setSourceAddress(new ZigBeeEndpointAddress(0));
sendCommand(command);
// This seems to be required for some stacks (eg ZNP)
if (ZigBeeBroadcastDestination.getBroadcastDestination(destination.getAddress()) != null) {
command = new ManagementPermitJoiningRequest();
command.setPermitDuration(duration);
command.setTcSignificance(true);
command.setDestinationAddress(new ZigBeeEndpointAddress(0));
command.setSourceAddress(new ZigBeeEndpointAddress(0));
sendCommand(command);
}
return true;
}
Aggregations