Search in sources :

Example 21 with IeeeAddress

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

the class ZigBeeNetworkStateSerializerImpl method deserialize.

/**
 * Deserializes the network state.
 *
 * @param networkState the network state
 */
@Override
public void deserialize(final ZigBeeNetworkManager networkState) {
    final File file = new File(networkId);
    boolean networkStateExists = file.exists();
    if (networkStateExists == false) {
        return;
    }
    logger.info("Loading network state...");
    try {
        XStream stream = openStream();
        BufferedReader reader;
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
        final List<Object> objects = (List<Object>) stream.fromXML(reader);
        for (final Object object : objects) {
            if (object instanceof ZigBeeNodeDao) {
                ZigBeeNodeDao nodeDao = (ZigBeeNodeDao) object;
                ZigBeeNode node = new ZigBeeNode(networkState, new IeeeAddress(nodeDao.getIeeeAddress()));
                node.setDao(nodeDao);
                networkState.addNode(node);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    logger.info("Loading network state complete.");
}
Also used : InputStreamReader(java.io.InputStreamReader) XStream(com.thoughtworks.xstream.XStream) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) ZigBeeNodeDao(com.zsmartsystems.zigbee.dao.ZigBeeNodeDao) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 22 with IeeeAddress

use of com.zsmartsystems.zigbee.IeeeAddress 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 23 with IeeeAddress

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

the class ZigBeeConsoleBindCommand 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.bind(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 24 with IeeeAddress

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

the class ZigBeeDongleXBee method sendCommand.

@Override
public void sendCommand(final ZigBeeApsFrame apsFrame) {
    if (frameHandler == null) {
        logger.debug("XBee frame handler not set for send.");
        return;
    }
    XBeeTransmitRequestExplicitCommand command = new XBeeTransmitRequestExplicitCommand();
    command.setNetworkAddress(apsFrame.getDestinationAddress());
    command.setDestinationEndpoint(apsFrame.getDestinationEndpoint());
    command.setSourceEndpoint(apsFrame.getSourceEndpoint());
    command.setProfileId(apsFrame.getProfile());
    command.setCluster(apsFrame.getCluster());
    command.setBroadcastRadius(0);
    if (apsFrame.getDestinationAddress() > 0xFFF8) {
        command.setIeeeAddress(broadcastIeeeAddress);
    } else if (apsFrame.getDestinationIeeeAddress() == null) {
        if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) {
            command.setIeeeAddress(groupIeeeAddress);
        } else {
        }
        command.setIeeeAddress(new IeeeAddress("FFFFFFFFFFFFFFFF"));
    } else {
        command.setIeeeAddress(apsFrame.getDestinationIeeeAddress());
    }
    if (apsFrame.getDestinationAddress() < 0xFFF8 && apsFrame.getDestinationAddress() != 0) {
        // There seems to be a bug in the XBee that causes it to hang if APS Encryption is
        // enabled when sending a command to the local coordinator. Don't do it!
        command.addOptions(TransmitOptions.ENABLE_APS_ENCRYPTION);
    }
    command.setData(apsFrame.getPayload());
    logger.debug("XBee send: {}", command.toString());
    frameHandler.sendRequestAsync(command);
}
Also used : XBeeTransmitRequestExplicitCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress)

Example 25 with IeeeAddress

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

the class TelegesisSleepyDeviceAnnounceEventTest method testExtended.

@Test
public void testExtended() {
    TelegesisSleepyDeviceAnnounceEvent event = new TelegesisSleepyDeviceAnnounceEvent();
    event.deserialize(stringToIntArray("SED:1234567890ABCDEF,9876,44,AA"));
    System.out.println(event);
    assertEquals(new IeeeAddress("1234567890ABCDEF"), event.getIeeeAddress());
    assertEquals(Integer.valueOf(0x9876), event.getNetworkAddress());
    assertEquals(Integer.valueOf(68), event.getRssi());
    assertEquals(Integer.valueOf(0xAA), event.getLqi());
}
Also used : IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Aggregations

IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)66 Test (org.junit.Test)53 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)12 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)12 CommandTest (com.zsmartsystems.zigbee.CommandTest)7 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)7 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)7 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)6 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)6 ArrayList (java.util.ArrayList)6 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)5 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)4 CommandResult (com.zsmartsystems.zigbee.CommandResult)3 ExtendedPanId (com.zsmartsystems.zigbee.ExtendedPanId)3 NodeDescriptor (com.zsmartsystems.zigbee.zdo.field.NodeDescriptor)3 HashSet (java.util.HashSet)3 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)2 EmberInitialSecurityState (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberInitialSecurityState)2 EmberKeyData (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData)2 XBeeFrameHandler (com.zsmartsystems.zigbee.dongle.xbee.internal.XBeeFrameHandler)2