Search in sources :

Example 1 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclClusterTest method unbind.

@Test
public void unbind() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    cluster.unbind(new IeeeAddress("1234567890ABCDEF"), 11);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof UnbindRequest);
    UnbindRequest unbindCommand = (UnbindRequest) command;
    assertEquals(new ZigBeeEndpointAddress(1234, 0), unbindCommand.getDestinationAddress());
    assertEquals(new IeeeAddress("1234567890ABCDEF"), unbindCommand.getDstAddress());
    assertEquals(Integer.valueOf(5), unbindCommand.getSrcEndpoint());
    assertEquals(Integer.valueOf(11), unbindCommand.getDstEndpoint());
    assertEquals(Integer.valueOf(3), unbindCommand.getDstAddrMode());
    assertEquals(Integer.valueOf(0x0022), unbindCommand.getClusterId());
    assertEquals(Integer.valueOf(6), unbindCommand.getBindCluster());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) UnbindRequest(com.zsmartsystems.zigbee.zdo.command.UnbindRequest) Test(org.junit.Test)

Example 2 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclClusterTest method getReporting.

@Test
public void getReporting() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    ZclAttribute attribute = cluster.getAttribute(0);
    cluster.getReporting(attribute);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof ReadReportingConfigurationCommand);
    ReadReportingConfigurationCommand cfgCommand = (ReadReportingConfigurationCommand) command;
    assertEquals(1, cfgCommand.getRecords().size());
    AttributeRecord record = cfgCommand.getRecords().get(0);
    assertEquals(0, record.getAttributeIdentifier());
    assertEquals(0, record.getDirection());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) AttributeRecord(com.zsmartsystems.zigbee.zcl.field.AttributeRecord) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) ReadReportingConfigurationCommand(com.zsmartsystems.zigbee.zcl.clusters.general.ReadReportingConfigurationCommand) Test(org.junit.Test)

Example 3 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleReportingUnsubscribeCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length != 6) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    final int clusterId = parseCluster(args[3]);
    final ZclCluster cluster;
    final String direction = args[2].toUpperCase();
    if ("IN".equals(direction)) {
        cluster = endpoint.getInputCluster(clusterId);
    } else if ("OUT".equals(direction)) {
        cluster = endpoint.getOutputCluster(clusterId);
    } else {
        throw new IllegalArgumentException("Cluster direction must be IN or OUT");
    }
    final int attributeId = parseAttribute(args[4]);
    final ZclAttribute attribute = cluster.getAttribute(attributeId);
    final CommandResult result = cluster.setReporting(attribute, 0, 0xFFFF, null).get();
    if (result.isSuccess()) {
        final ConfigureReportingResponse response = result.getResponse();
        final ZclStatus statusCode = response.getRecords().get(0).getStatus();
        if (statusCode == ZclStatus.SUCCESS) {
            out.println("Attribute value configure reporting success.");
        } else {
            out.println("Attribute value configure reporting error: " + statusCode);
        }
    } else {
        out.println("Error executing command: " + result);
    }
}
Also used : ZclStatus(com.zsmartsystems.zigbee.zcl.ZclStatus) ZclAttribute(com.zsmartsystems.zigbee.zcl.ZclAttribute) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult) ConfigureReportingResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)

Example 4 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleUnbindCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length < 3) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final int clusterId = parseCluster(args[1]);
    final ZigBeeEndpoint source = getEndpoint(networkManager, args[2]);
    ZclCluster cluster = source.getInputCluster(clusterId);
    if (cluster == null) {
        throw new IllegalArgumentException("Cluster '" + clusterId + "' not found.");
    }
    IeeeAddress destAddress;
    int destEndpoint;
    if (args.length >= 4) {
        ZigBeeEndpoint destination = getEndpoint(networkManager, args[3]);
        destAddress = destination.getIeeeAddress();
        destEndpoint = destination.getEndpointId();
    } else {
        destAddress = networkManager.getNode(0).getIeeeAddress();
        destEndpoint = 1;
    }
    final CommandResult response = cluster.unbind(destAddress, destEndpoint).get();
    processDefaultResponse(response, out);
}
Also used : ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 5 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleAttributeReadCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length != 4) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    final Integer clusterId = parseCluster(args[2]);
    ZclCluster cluster = endpoint.getInputCluster(clusterId);
    if (cluster != null) {
        out.println("Using input cluster");
    } else {
        cluster = endpoint.getOutputCluster(clusterId);
        if (cluster != null) {
            out.println("Using output cluster");
        } else {
            out.println("Cluster not found");
            return;
        }
    }
    final Integer attributeId = parseAttribute(args[3]);
    String attributeName;
    ZclAttribute attribute = cluster.getAttribute(attributeId);
    if (attribute == null) {
        attributeName = "Attribute " + attributeId;
    } else {
        attributeName = attribute.getName();
    }
    out.println("Reading " + cluster.getClusterName() + ", " + attributeName);
    CommandResult result;
    result = cluster.read(attributeId).get();
    if (result.isSuccess()) {
        final ReadAttributesResponse response = result.getResponse();
        if (response.getRecords().size() == 0) {
            out.println("No records returned");
            return;
        }
        final ZclStatus statusCode = response.getRecords().get(0).getStatus();
        if (statusCode == ZclStatus.SUCCESS) {
            out.println("Cluster " + String.format("%04X", response.getClusterId()) + ", Attribute " + response.getRecords().get(0).getAttributeIdentifier() + ", type " + response.getRecords().get(0).getAttributeDataType() + ", value: " + response.getRecords().get(0).getAttributeValue());
        } else {
            out.println("Attribute value read error: " + statusCode);
        }
        return;
    } else {
        out.println("Error executing command: " + result);
        return;
    }
}
Also used : ZclStatus(com.zsmartsystems.zigbee.zcl.ZclStatus) ZclAttribute(com.zsmartsystems.zigbee.zcl.ZclAttribute) ReadAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Aggregations

ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)25 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)12 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)12 Test (org.junit.Test)10 CommandResult (com.zsmartsystems.zigbee.CommandResult)9 ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)8 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)8 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)6 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)6 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)5 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)5 ArrayList (java.util.ArrayList)4 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)2 ConfigureReportingResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)2 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)2 HashSet (java.util.HashSet)2 ZigBeeOtaFile (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile)1 ZigBeeOtaServer (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServer)1 ZigBeeOtaServerStatus (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServerStatus)1 ZigBeeOtaStatusCallback (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaStatusCallback)1