Search in sources :

Example 31 with IeeeAddress

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

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

the class EmberNetworkInitialisation method setSecurityState.

/**
 * Sets the initial security state
 *
 * @param networkKey the initial {@link EmberKeyData}
 * @return true if the security state was set successfully
 */
private boolean setSecurityState(EmberKeyData networkKey) {
    // Define the ZigBeeAliance09 key for HA link-key
    // This is used to encrypt the network key when it is transferred to a newly joining device.
    EmberKeyData linkKey = new EmberKeyData();
    linkKey.setContents(new int[] { 0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 });
    // linkKey.setContents(new int[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    // 0xFF, 0xFF, 0xFF });
    EzspSetInitialSecurityStateRequest securityState = new EzspSetInitialSecurityStateRequest();
    EmberInitialSecurityState state = new EmberInitialSecurityState();
    // state.addBitmask(EmberInitialSecurityBitmask.EMBER_STANDARD_SECURITY_MODE);
    // state.addBitmask(EmberInitialSecurityBitmask.EMBER_DISTRIBUTED_TRUST_CENTER_MODE);//
    // EMBER_TRUST_CENTER_GLOBAL_LINK_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_TRUST_CENTER_GLOBAL_LINK_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_HAVE_PRECONFIGURED_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_HAVE_NETWORK_KEY);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_NO_FRAME_COUNTER_RESET);
    state.addBitmask(EmberInitialSecurityBitmask.EMBER_REQUIRE_ENCRYPTED_KEY);
    state.setNetworkKey(networkKey);
    state.setPreconfiguredKey(linkKey);
    state.setPreconfiguredTrustCenterEui64(new IeeeAddress());
    securityState.setState(state);
    EzspSingleResponseTransaction transaction = new EzspSingleResponseTransaction(securityState, EzspSetInitialSecurityStateResponse.class);
    ashHandler.sendEzspTransaction(transaction);
    EzspSetInitialSecurityStateResponse securityStateResponse = (EzspSetInitialSecurityStateResponse) transaction.getResponse();
    logger.debug(securityStateResponse.toString());
    if (securityStateResponse.getStatus() != EmberStatus.EMBER_SUCCESS) {
        logger.debug("Error during retrieval of network parameters: {}", securityStateResponse);
        return false;
    }
    return true;
}
Also used : EzspSetInitialSecurityStateRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSetInitialSecurityStateRequest) EmberKeyData(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberKeyData) EzspSetInitialSecurityStateResponse(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSetInitialSecurityStateResponse) EzspSingleResponseTransaction(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.transaction.EzspSingleResponseTransaction) EmberInitialSecurityState(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberInitialSecurityState) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress)

Example 33 with IeeeAddress

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

the class EzspLookupEui64ByNodeIdResponseTest method testVersionError.

@Test
public void testVersionError() {
    EzspFrame.setEzspVersion(4);
    EzspLookupEui64ByNodeIdResponse response = new EzspLookupEui64ByNodeIdResponse(getPacketData("05 80 61 00 BF 32 17 00 00 A3 22 00"));
    System.out.println(response);
    assertEquals(5, response.getSequenceNumber());
    assertEquals(true, response.isResponse());
    assertEquals(EzspLookupEui64ByNodeIdResponse.FRAME_ID, response.getFrameId());
    assertEquals(new IeeeAddress("0022A300001732BF"), response.getEui64());
    assertEquals(EmberStatus.EMBER_SUCCESS, response.getStatus());
}
Also used : IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) Test(org.junit.Test)

Example 34 with IeeeAddress

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

the class IeeeAddressConverter method marshal.

@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    IeeeAddress address = (IeeeAddress) value;
    writer.setValue(address.toString());
}
Also used : IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress)

Example 35 with IeeeAddress

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

the class EzspGetNeighborResponseTest method testVersion.

@Test
public void testVersion() {
    EzspFrame.setEzspVersion(4);
    EzspGetNeighborResponse response = new EzspGetNeighborResponse(getPacketData("29 80 79 00 9E 72 FF 01 01 03 CC 43 6B 05 00 6F 0D 00"));
    System.out.println(response);
    assertEquals(true, response.isResponse());
    assertEquals(EzspGetNeighborResponse.FRAME_ID, response.getFrameId());
    assertEquals(EmberStatus.EMBER_SUCCESS, response.getStatus());
    EmberNeighborTableEntry neighbor = response.getValue();
    assertNotNull(neighbor);
    assertEquals(255, neighbor.getAverageLqi());
    assertEquals(1, neighbor.getInCost());
    assertEquals(1, neighbor.getOutCost());
    assertEquals(29342, neighbor.getShortId());
    assertEquals(29342, neighbor.getShortId());
    assertEquals(new IeeeAddress("000D6F00056B43CC"), neighbor.getLongId());
    assertEquals(3, neighbor.getAge());
}
Also used : EmberNeighborTableEntry(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberNeighborTableEntry) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) 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