Search in sources :

Example 6 with ExtendedPanId

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

the class TelegesisNetworkJoinedEventTest method test.

@Test
public void test() {
    TelegesisNetworkJoinedEvent event = new TelegesisNetworkJoinedEvent();
    event.deserialize(stringToIntArray("JPAN:18,9876,0793E14FFB220A38"));
    System.out.println(event);
    assertEquals(Integer.valueOf(18), event.getChannel());
    assertEquals(Integer.valueOf(0x9876), event.getPanId());
    assertEquals(new ExtendedPanId("0793E14FFB220A38"), event.getEpanId());
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) Test(org.junit.Test)

Example 7 with ExtendedPanId

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

the class DefaultDeserializer method readZigBeeType.

@Override
public /**
 * {@inheritDoc}
 */
Object readZigBeeType(ZclDataType type) {
    if (index == payload.length) {
        return null;
    }
    Object[] value = new Object[1];
    switch(type) {
        case BOOLEAN:
            value[0] = payload[index++] == 0 ? false : true;
            break;
        case CHARACTER_STRING:
        case OCTET_STRING:
            int size = payload[index++];
            if (size == 255) {
                value[0] = null;
                break;
            }
            int length = size;
            for (int cnt = 0; cnt < size; cnt++) {
                if (payload[index + cnt] == 0) {
                    length = cnt;
                }
            }
            value[0] = new String(payload, index, length);
            index += size;
            break;
        case ENDPOINT:
        case BITMAP_8_BIT:
        case DATA_8_BIT:
        case ENUMERATION_8_BIT:
            value[0] = Integer.valueOf((byte) payload[index++] & 0xFF);
            break;
        case EXTENDED_PANID:
            int[] panId = new int[8];
            for (int iCnt = 7; iCnt >= 0; iCnt--) {
                panId[iCnt] = payload[index + iCnt];
            }
            index += 8;
            value[0] = new ExtendedPanId(panId);
            break;
        case IEEE_ADDRESS:
            int[] address = new int[8];
            for (int iCnt = 7; iCnt >= 0; iCnt--) {
                address[iCnt] = payload[index + iCnt];
            }
            index += 8;
            value[0] = new IeeeAddress(address);
            break;
        case N_X_ATTRIBUTE_INFORMATION:
            break;
        case N_X_ATTRIBUTE_RECORD:
            break;
        case N_X_ATTRIBUTE_REPORT:
            break;
        case N_X_ATTRIBUTE_REPORTING_CONFIGURATION_RECORD:
            break;
        case N_X_ATTRIBUTE_SELECTOR:
            break;
        case N_X_ATTRIBUTE_STATUS_RECORD:
            break;
        case N_X_EXTENSION_FIELD_SET:
            break;
        case N_X_NEIGHBORS_INFORMATION:
            break;
        case N_X_READ_ATTRIBUTE_STATUS_RECORD:
            break;
        case N_X_UNSIGNED_16_BIT_INTEGER:
            int cntN16 = Integer.valueOf((byte) payload[index++] & 0xFF);
            List<Integer> arrayN16 = new ArrayList<Integer>(cntN16);
            for (int arrayIndex = 0; arrayIndex < cntN16; arrayIndex++) {
                arrayN16.add(Integer.valueOf(payload[index++] + ((payload[index++] << 8) & 0xffff)));
            }
            value[0] = arrayN16;
            break;
        case N_X_UNSIGNED_8_BIT_INTEGER:
            int cntN8 = Integer.valueOf((byte) payload[index++] & 0xFF);
            List<Integer> arrayN8 = new ArrayList<Integer>(cntN8);
            for (int arrayIndex = 0; arrayIndex < cntN8; arrayIndex++) {
                arrayN8.add(Integer.valueOf(payload[index++]));
            }
            value[0] = arrayN8;
            break;
        case X_UNSIGNED_8_BIT_INTEGER:
            int cntX8 = payload.length - index;
            List<Integer> arrayX8 = new ArrayList<Integer>(cntX8);
            for (int arrayIndex = 0; arrayIndex < cntX8; arrayIndex++) {
                arrayX8.add(Integer.valueOf(payload[index++]));
            }
            value[0] = arrayX8;
            break;
        case N_X_ATTRIBUTE_IDENTIFIER:
            int cntX16 = (payload.length - index) / 2;
            List<Integer> arrayX16 = new ArrayList<Integer>(cntX16);
            for (int arrayIndex = 0; arrayIndex < cntX16; arrayIndex++) {
                arrayX16.add(Integer.valueOf(payload[index++]));
            }
            value[0] = arrayX16;
            break;
        case UNSIGNED_8_BIT_INTEGER_ARRAY:
            int cnt8Array = payload.length - index;
            int[] intarray8 = new int[cnt8Array];
            for (int arrayIndex = 0; arrayIndex < cnt8Array; arrayIndex++) {
                intarray8[arrayIndex] = payload[index++];
            }
            value[0] = intarray8;
            break;
        case N_X_WRITE_ATTRIBUTE_RECORD:
            break;
        case N_X_WRITE_ATTRIBUTE_STATUS_RECORD:
            break;
        case CLUSTERID:
        case NWK_ADDRESS:
        case BITMAP_16_BIT:
        case ENUMERATION_16_BIT:
        case SIGNED_16_BIT_INTEGER:
        case UNSIGNED_16_BIT_INTEGER:
            short s = (short) (payload[index++] + (payload[index++] << 8));
            if (type == ZclDataType.SIGNED_16_BIT_INTEGER) {
                value[0] = Integer.valueOf(s);
            } else {
                value[0] = Integer.valueOf(s & 0xFFFF);
            }
            break;
        case BITMAP_32_BIT:
        case SIGNED_32_BIT_INTEGER:
        case UNSIGNED_32_BIT_INTEGER:
            value[0] = payload[index++] + (payload[index++] << 8) + (payload[index++] << 16) + (payload[index++] << 24);
            break;
        case SIGNED_8_BIT_INTEGER:
            value[0] = Integer.valueOf((byte) payload[index++]);
            break;
        case UNSIGNED_8_BIT_INTEGER:
            value[0] = Integer.valueOf((byte) payload[index++] & 0xFF);
            break;
        case UTCTIME:
            break;
        case ROUTING_TABLE:
            RoutingTable routingTable = new RoutingTable();
            routingTable.deserialize(this);
            value[0] = routingTable;
            break;
        case NEIGHBOR_TABLE:
            NeighborTable neighborTable = new NeighborTable();
            neighborTable.deserialize(this);
            value[0] = neighborTable;
            break;
        case NODE_DESCRIPTOR:
            NodeDescriptor nodeDescriptor = new NodeDescriptor();
            nodeDescriptor.deserialize(this);
            value[0] = nodeDescriptor;
            break;
        case POWER_DESCRIPTOR:
            PowerDescriptor powerDescriptor = new PowerDescriptor();
            powerDescriptor.deserialize(this);
            value[0] = powerDescriptor;
            break;
        case BINDING_TABLE:
            BindingTable bindingTable = new BindingTable();
            bindingTable.deserialize(this);
            value[0] = bindingTable;
            break;
        case SIMPLE_DESCRIPTOR:
            SimpleDescriptor simpleDescriptor = new SimpleDescriptor();
            simpleDescriptor.deserialize(this);
            value[0] = simpleDescriptor;
            break;
        case ZCL_STATUS:
            value[0] = ZclStatus.getStatus(payload[index++]);
            break;
        case ZDO_STATUS:
            value[0] = ZdoStatus.getStatus(payload[index++]);
            break;
        case ZIGBEE_DATA_TYPE:
            value[0] = ZclDataType.getType(payload[index++]);
            break;
        case BYTE_ARRAY:
            int cntB8 = Integer.valueOf((byte) payload[index++] & 0xFF);
            byte[] arrayB8 = new byte[cntB8];
            for (int arrayIndex = 0; arrayIndex < cntB8; arrayIndex++) {
                arrayB8[arrayIndex] = (byte) (payload[index++] & 0xff);
            }
            value[0] = new ByteArray(arrayB8);
            break;
        default:
            throw new IllegalArgumentException("No reader defined in " + ZigBeeDeserializer.class.getSimpleName() + " for " + type.toString() + " (" + type.getId() + ")");
    }
    return value[0];
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) ArrayList(java.util.ArrayList) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor) RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) BindingTable(com.zsmartsystems.zigbee.zdo.field.BindingTable) NeighborTable(com.zsmartsystems.zigbee.zdo.field.NeighborTable) ByteArray(com.zsmartsystems.zigbee.zcl.field.ByteArray) PowerDescriptor(com.zsmartsystems.zigbee.zdo.field.PowerDescriptor)

Example 8 with ExtendedPanId

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

the class ConBeeReadParameterResponseTest method readNwkExtendedPanId.

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

Example 9 with ExtendedPanId

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

the class EmberNetworkInitialisation method formNetwork.

/**
 * This utility function uses emberStartScan, emberStopScan, emberScanCompleteHandler, emberEnergyScanResultHandler,
 * and emberNetworkFoundHandler to discover other networks or determine the background noise level. It then uses
 * emberFormNetwork to create a new network with a unique PAN-ID on a channel with low background noise.
 * <p>
 * Setting the PAN-ID or Extended PAN-ID to 0 will set these values to a random value.
 * <p>
 * If channel is set to 0, the quietest channel will be used.
 *
 * @param networkParameters the required {@link EmberNetworkParameters}
 * @param networkKey the {@link EmberKeyData} with the network key. This can not be set to all 00 or all FF.
 */
public void formNetwork(EmberNetworkParameters networkParameters, EmberKeyData networkKey) {
    if (networkParameters.getExtendedPanId() == null) {
        networkParameters.setExtendedPanId(new ExtendedPanId());
    }
    logger.debug("Initialising Ember network with configuration {}", networkParameters);
    // 6
    int scanDuration = 1;
    // Leave the current network so we can initialise a new network
    if (checkNetworkJoined()) {
        doLeaveNetwork();
    }
    // Perform an energy scan to find a clear channel
    int quietestChannel = doEnergyScan(scanDuration);
    logger.debug("Energy scan reports quietest channel is {}", quietestChannel);
    // Check if any current networks were found and avoid those channels, PAN ID and especially Extended PAN ID
    doActiveScan(scanDuration);
    // Read the current network parameters
    getNetworkParameters();
    // Create a random PAN ID and Extended PAN ID
    if (networkParameters.getPanId() == 0 || networkParameters.getExtendedPanId().equals(new ExtendedPanId())) {
        Random random = new Random();
        int panId = random.nextInt(65535);
        networkParameters.setPanId(panId);
        logger.debug("Created random PAN ID: {}", panId);
        int[] extendedPanId = new int[8];
        StringBuilder extendedPanIdBuilder = new StringBuilder();
        for (int cnt = 0; cnt < 8; cnt++) {
            extendedPanId[cnt] = random.nextInt(256);
            extendedPanIdBuilder.append(String.format("%02X", extendedPanId[cnt]));
        }
        networkParameters.setExtendedPanId(new ExtendedPanId(extendedPanId));
        logger.debug("Created random Extended PAN ID: {}", extendedPanIdBuilder.toString());
    }
    if (networkParameters.getRadioChannel() == 0) {
        networkParameters.setRadioChannel(quietestChannel);
    }
    // If the channel set is empty, use the single channel defined above
    if (networkParameters.getChannels() == 0) {
        networkParameters.setChannels(1 << networkParameters.getRadioChannel());
    }
    // Initialise security
    setSecurityState(networkKey);
    // And now form the network
    doFormNetwork(networkParameters.getPanId(), networkParameters.getExtendedPanId(), networkParameters.getRadioChannel());
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) Random(java.util.Random)

Example 10 with ExtendedPanId

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

the class ZigBeeDongleEzspTest method setZigBeeExtendedPanId.

@Test
public void setZigBeeExtendedPanId() {
    ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null);
    dongle.setZigBeeExtendedPanId(new ExtendedPanId("123456789abcdef"));
    assertEquals(new ExtendedPanId("123456789abcdef"), dongle.getZigBeeExtendedPanId());
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) Test(org.junit.Test)

Aggregations

ExtendedPanId (com.zsmartsystems.zigbee.ExtendedPanId)18 Test (org.junit.Test)13 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)3 ConBeeReadParameterResponse (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeReadParameterResponse)3 ByteArray (com.zsmartsystems.zigbee.zcl.field.ByteArray)2 ArrayList (java.util.ArrayList)2 CommandTest (com.zsmartsystems.zigbee.CommandTest)1 ZigBeeKey (com.zsmartsystems.zigbee.ZigBeeKey)1 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)1 ZigBeeNetworkMeshMonitor (com.zsmartsystems.zigbee.ZigBeeNetworkMeshMonitor)1 ZigBeeNetworkStateSerializer (com.zsmartsystems.zigbee.ZigBeeNetworkStateSerializer)1 ZigBeeConsoleCommand (com.zsmartsystems.zigbee.console.ZigBeeConsoleCommand)1 EmberConsoleNcpChildrenCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpChildrenCommand)1 EmberConsoleNcpCountersCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpCountersCommand)1 EmberConsoleNcpStateCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpStateCommand)1 EmberConsoleNcpVersionCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpVersionCommand)1 EmberConsoleNetworkStateCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNetworkStateCommand)1 EmberConsoleSecurityStateCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleSecurityStateCommand)1 ZigBeeDongleTiCc2531 (com.zsmartsystems.zigbee.dongle.cc2531.ZigBeeDongleTiCc2531)1 ZigBeeDongleConBee (com.zsmartsystems.zigbee.dongle.conbee.ZigBeeDongleConBee)1