Search in sources :

Example 41 with IeeeAddress

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

the class TelegesisReceiveMulticastEventTest method testRemoteAddressRssiLqi.

@Test
public void testRemoteAddressRssiLqi() {
    TelegesisReceiveMulticastEvent event = new TelegesisReceiveMulticastEvent();
    event.deserialize(stringToIntArray("MCAST:000D6F000005A666,04=test,A0,45"));
    System.out.println(event);
    assertEquals(new IeeeAddress("000D6F000005A666"), event.getRemoteAddress());
    assertTrue(Arrays.equals(stringToIntArray("test"), event.getMessageData()));
    assertEquals(Integer.valueOf(160), event.getRssi());
    assertEquals(Integer.valueOf(69), event.getLqi());
}
Also used : IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Example 42 with IeeeAddress

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

the class ConBeeReadParameterResponseTest method readMacAddress.

@Test
public void readMacAddress() {
    ConBeeReadParameterResponse readParameter = new ConBeeReadParameterResponse(new int[] { 0x0A, 0x02, 0x00, 0x10, 0x00, 0x09, 0x00, 0x01, 0x8C, 0x0A, 0x01, 0xFF, 0xFF, 0x2E, 0x21, 0x00, 0xF6, 0xFC });
    System.out.println(readParameter);
    assertEquals(2, readParameter.getSequence());
    assertEquals(ConBeeStatus.SUCCESS, readParameter.getStatus());
    assertEquals(ConBeeNetworkParameter.MAC_ADDRESS, readParameter.getParameter());
    assertEquals(new IeeeAddress("00212EFFFF010A8C"), readParameter.getValue());
}
Also used : ConBeeReadParameterResponse(com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeReadParameterResponse) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Example 43 with IeeeAddress

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

the class ConBeeReadReceivedDataResponseTest method readResponse.

@Test
public void readResponse() {
    ConBeeReadReceivedDataResponse readResponse = new ConBeeReadReceivedDataResponse(new int[] { 0x17, 0x0C, 0x00, 0x32, 0x00, 0x2B, 0x00, 0x26, 0x02, 0x00, 0x00, 0x00, 0x03, 0x8C, 0x0A, 0x01, 0xFF, 0xFF, 0x2E, 0x21, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x0E, 0x00, 0x00, 0x00, 0x8C, 0x0A, 0x01, 0xFF, 0xFF, 0x2E, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAF, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x4B, 0xF8, 0xC0 });
    System.out.println(readResponse);
    assertEquals(12, readResponse.getSequence());
    assertEquals(ConBeeStatus.SUCCESS, readResponse.getStatus());
    assertEquals(0x8001, readResponse.getClusterId());
    assertEquals(14, readResponse.getAdsuData().length);
    assertEquals(new IeeeAddress("00212EFFFF010A8C"), readResponse.getSourceIeeeAddress());
}
Also used : ConBeeReadReceivedDataResponse(com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeReadReceivedDataResponse) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Example 44 with IeeeAddress

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

the class TelegesisSleepyDeviceAnnounceEventTest method testBasic.

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

Example 45 with IeeeAddress

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

the class ZigBeeDongleXBee method initialize.

@Override
public ZigBeeInitializeResponse initialize() {
    logger.debug("XBee dongle initialize.");
    zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.UNINITIALISED);
    if (!serialPort.open()) {
        logger.error("Unable to open XBee serial port");
        return ZigBeeInitializeResponse.FAILED;
    }
    // Create and start the frame handler
    frameHandler = new XBeeFrameHandler();
    frameHandler.start(serialPort);
    frameHandler.addEventListener(this);
    // Reset to a known state
    // Device sends WATCHDOG_TIMER_RESET event
    // A retry mechanism is used as sometimes the reset response is not received.
    // This appears to happen if there are other events queued in the stick.
    int resetCount = 0;
    do {
        if (resetCount >= MAX_RESET_RETRIES) {
            logger.info("XBee dongle reset failed after {} tries.", ++resetCount);
            return ZigBeeInitializeResponse.FAILED;
        }
        logger.debug("XBee dongle reset {}.", ++resetCount);
        XBeeSetSoftwareResetCommand resetCommand = new XBeeSetSoftwareResetCommand();
        frameHandler.sendRequest(resetCommand);
    } while (frameHandler.eventWait(XBeeModemStatusEvent.class) == null);
    // Enable the API with escaping
    XBeeSetApiEnableCommand apiEnableCommand = new XBeeSetApiEnableCommand();
    apiEnableCommand.setMode(2);
    frameHandler.sendRequest(apiEnableCommand);
    // Set the API mode so we receive detailed data including ZDO
    XBeeSetApiModeCommand apiModeCommand = new XBeeSetApiModeCommand();
    apiModeCommand.setMode(3);
    frameHandler.sendRequest(apiModeCommand);
    // Get the product information
    XBeeGetHardwareVersionCommand hwVersionCommand = new XBeeGetHardwareVersionCommand();
    frameHandler.sendRequest(hwVersionCommand);
    XBeeGetFirmwareVersionCommand fwVersionCommand = new XBeeGetFirmwareVersionCommand();
    frameHandler.sendRequest(fwVersionCommand);
    XBeeGetDetailedVersionCommand versionCommand = new XBeeGetDetailedVersionCommand();
    frameHandler.sendRequest(versionCommand);
    // Get Ieee Address
    XBeeGetIeeeAddressHighCommand ieeeHighCommand = new XBeeGetIeeeAddressHighCommand();
    XBeeIeeeAddressHighResponse ieeeHighResponse = (XBeeIeeeAddressHighResponse) frameHandler.sendRequest(ieeeHighCommand);
    XBeeGetIeeeAddressLowCommand ieeeLowCommand = new XBeeGetIeeeAddressLowCommand();
    XBeeIeeeAddressLowResponse ieeeLowResponse = (XBeeIeeeAddressLowResponse) frameHandler.sendRequest(ieeeLowCommand);
    if (ieeeHighResponse == null || ieeeLowCommand == null) {
        logger.error("Unable to get XBee IEEE address");
        return ZigBeeInitializeResponse.FAILED;
    }
    int[] tmpAddress = new int[8];
    tmpAddress[0] = ieeeLowResponse.getIeeeAddress()[3];
    tmpAddress[1] = ieeeLowResponse.getIeeeAddress()[2];
    tmpAddress[2] = ieeeLowResponse.getIeeeAddress()[1];
    tmpAddress[3] = ieeeLowResponse.getIeeeAddress()[0];
    tmpAddress[4] = ieeeHighResponse.getIeeeAddress()[3];
    tmpAddress[5] = ieeeHighResponse.getIeeeAddress()[2];
    tmpAddress[6] = ieeeHighResponse.getIeeeAddress()[1];
    tmpAddress[7] = ieeeHighResponse.getIeeeAddress()[0];
    ieeeAddress = new IeeeAddress(tmpAddress);
    logger.debug("XBee IeeeAddress={}", ieeeAddress);
    // Set the ZigBee stack profile
    XBeeSetZigbeeStackProfileCommand stackProfile = new XBeeSetZigbeeStackProfileCommand();
    stackProfile.setStackProfile(2);
    frameHandler.sendRequest(stackProfile);
    // Enable Security
    XBeeSetEncryptionEnableCommand enableEncryption = new XBeeSetEncryptionEnableCommand();
    enableEncryption.setEnableEncryption(true);
    frameHandler.sendRequest(enableEncryption);
    XBeeSetEncryptionOptionsCommand encryptionOptions = new XBeeSetEncryptionOptionsCommand();
    encryptionOptions.addEncryptionOptions(EncryptionOptions.ENABLE_TRUST_CENTRE);
    frameHandler.sendRequest(encryptionOptions);
    // Enable coordinator mode
    XBeeSetCoordinatorEnableCommand coordinatorEnable = new XBeeSetCoordinatorEnableCommand();
    coordinatorEnable.setEnable(true);
    frameHandler.sendRequest(coordinatorEnable);
    // Set the network key
    XBeeSetNetworkKeyCommand networkKey = new XBeeSetNetworkKeyCommand();
    networkKey.setNetworkKey(new ZigBeeKey());
    frameHandler.sendRequest(networkKey);
    // Set the link key
    XBeeSetLinkKeyCommand setLinkKey = new XBeeSetLinkKeyCommand();
    setLinkKey.setLinkKey(linkKey);
    frameHandler.sendRequest(setLinkKey);
    // Save the configuration in the XBee
    XBeeSetSaveDataCommand saveData = new XBeeSetSaveDataCommand();
    frameHandler.sendRequest(saveData);
    // Get network information
    XBeeGetPanIdCommand getPanId = new XBeeGetPanIdCommand();
    XBeePanIdResponse panIdResponse = (XBeePanIdResponse) frameHandler.sendRequest(getPanId);
    panId = panIdResponse.getPanId();
    XBeeGetExtendedPanIdCommand getEPanId = new XBeeGetExtendedPanIdCommand();
    XBeeExtendedPanIdResponse epanIdResponse = (XBeeExtendedPanIdResponse) frameHandler.sendRequest(getEPanId);
    extendedPanId = epanIdResponse.getExtendedPanId();
    zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.INITIALISING);
    return ZigBeeInitializeResponse.JOINED;
}
Also used : XBeeSetCoordinatorEnableCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetCoordinatorEnableCommand) XBeeExtendedPanIdResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeExtendedPanIdResponse) XBeeGetHardwareVersionCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeGetHardwareVersionCommand) XBeeSetSoftwareResetCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetSoftwareResetCommand) XBeeModemStatusEvent(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeModemStatusEvent) XBeeGetPanIdCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeGetPanIdCommand) XBeeSetApiEnableCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetApiEnableCommand) XBeePanIdResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeePanIdResponse) XBeeGetExtendedPanIdCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeGetExtendedPanIdCommand) XBeeGetFirmwareVersionCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeGetFirmwareVersionCommand) XBeeFrameHandler(com.zsmartsystems.zigbee.dongle.xbee.internal.XBeeFrameHandler) XBeeSetEncryptionOptionsCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetEncryptionOptionsCommand) XBeeGetDetailedVersionCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeGetDetailedVersionCommand) XBeeIeeeAddressLowResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeIeeeAddressLowResponse) XBeeIeeeAddressHighResponse(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeIeeeAddressHighResponse) XBeeSetLinkKeyCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetLinkKeyCommand) XBeeSetZigbeeStackProfileCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetZigbeeStackProfileCommand) XBeeSetEncryptionEnableCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetEncryptionEnableCommand) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) XBeeGetIeeeAddressHighCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeGetIeeeAddressHighCommand) XBeeSetApiModeCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetApiModeCommand) XBeeGetIeeeAddressLowCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeGetIeeeAddressLowCommand) XBeeSetNetworkKeyCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetNetworkKeyCommand) XBeeSetSaveDataCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeSetSaveDataCommand) ZigBeeKey(com.zsmartsystems.zigbee.ZigBeeKey)

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