Search in sources :

Example 16 with ExtendedPanId

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

the class DefaultDeserializerTest method testDeserialize_EXTENDED_PANID.

@Test
public void testDeserialize_EXTENDED_PANID() {
    int[] valIn = { 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12 };
    ExtendedPanId valOut = new ExtendedPanId("1234567890123456");
    testDeserialize(valIn, valOut, ZclDataType.EXTENDED_PANID);
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) Test(org.junit.Test)

Example 17 with ExtendedPanId

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

the class SerializerIntegrationTest method testSerialize_EXTENDED_PANID.

@Test
public void testSerialize_EXTENDED_PANID() {
    ExtendedPanId valIn = new ExtendedPanId("1234567890123456");
    testSerializer(valIn, ZclDataType.EXTENDED_PANID);
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) Test(org.junit.Test)

Example 18 with ExtendedPanId

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

the class DefaultSerializer method appendZigBeeType.

@Override
public void appendZigBeeType(Object data, ZclDataType type) throws IllegalArgumentException {
    if (data == null) {
        throw new IllegalArgumentException("You can not append null data to a stream");
    }
    switch(type) {
        case BOOLEAN:
            buffer[length++] = (Boolean) data ? 1 : 0;
            break;
        case NWK_ADDRESS:
        case BITMAP_16_BIT:
        case SIGNED_16_BIT_INTEGER:
        case UNSIGNED_16_BIT_INTEGER:
        case ENUMERATION_16_BIT:
        case CLUSTERID:
            final short shortValue = ((Number) data).shortValue();
            buffer[length++] = shortValue & 0xFF;
            buffer[length++] = (shortValue >> 8) & 0xFF;
            break;
        case ENDPOINT:
        case DATA_8_BIT:
        case BITMAP_8_BIT:
        case SIGNED_8_BIT_INTEGER:
        case UNSIGNED_8_BIT_INTEGER:
        case ENUMERATION_8_BIT:
            final byte byteValue = ((Number) data).byteValue();
            buffer[length++] = byteValue & 0xFF;
            break;
        case EXTENDED_PANID:
            int[] panId = ((ExtendedPanId) data).getValue();
            buffer[length++] = panId[0];
            buffer[length++] = panId[1];
            buffer[length++] = panId[2];
            buffer[length++] = panId[3];
            buffer[length++] = panId[4];
            buffer[length++] = panId[5];
            buffer[length++] = panId[6];
            buffer[length++] = panId[7];
            break;
        case IEEE_ADDRESS:
            int[] address = ((IeeeAddress) data).getValue();
            buffer[length++] = address[0];
            buffer[length++] = address[1];
            buffer[length++] = address[2];
            buffer[length++] = address[3];
            buffer[length++] = address[4];
            buffer[length++] = address[5];
            buffer[length++] = address[6];
            buffer[length++] = address[7];
            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:
            List<Integer> intArray16 = (List<Integer>) data;
            buffer[length++] = intArray16.size();
            for (int value : intArray16) {
                buffer[length++] = value & 0xFF;
                buffer[length++] = (value >> 8) & 0xFF;
            }
            break;
        case N_X_UNSIGNED_8_BIT_INTEGER:
            List<Integer> intArrayNX8 = (List<Integer>) data;
            buffer[length++] = intArrayNX8.size();
            for (int value : intArrayNX8) {
                buffer[length++] = value & 0xFF;
            }
            break;
        case UNSIGNED_8_BIT_INTEGER_ARRAY:
            int[] intArrayN8 = (int[]) data;
            for (int value : intArrayN8) {
                buffer[length++] = value & 0xFF;
            }
            break;
        case X_UNSIGNED_8_BIT_INTEGER:
            List<Integer> intArrayX8 = (List<Integer>) data;
            for (int value : intArrayX8) {
                buffer[length++] = value & 0xFF;
            }
            break;
        case N_X_ATTRIBUTE_IDENTIFIER:
            List<Integer> intArrayX16 = (List<Integer>) data;
            for (int value : intArrayX16) {
                buffer[length++] = value & 0xFF;
                buffer[length++] = (value >> 8) & 0xFF;
            }
            break;
        case N_X_WRITE_ATTRIBUTE_RECORD:
            break;
        case N_X_WRITE_ATTRIBUTE_STATUS_RECORD:
            break;
        case CHARACTER_STRING:
        case OCTET_STRING:
            final String str = (String) data;
            buffer[length++] = ((byte) (str.length() & (0xFF)));
            for (int strByte : str.getBytes()) {
                buffer[length++] = strByte;
            }
            break;
        case SIGNED_32_BIT_INTEGER:
            final int intValue = (Integer) data;
            buffer[length++] = intValue & 0xFF;
            buffer[length++] = (intValue >> 8) & 0xFF;
            buffer[length++] = (intValue >> 16) & 0xFF;
            buffer[length++] = (intValue >> 24) & 0xFF;
            break;
        case BITMAP_32_BIT:
        case UNSIGNED_32_BIT_INTEGER:
            final int uintValue = (Integer) data;
            buffer[length++] = uintValue & 0xFF;
            buffer[length++] = (uintValue >> 8) & 0xFF;
            buffer[length++] = (uintValue >> 16) & 0xFF;
            buffer[length++] = (uintValue >> 24) & 0xFF;
            break;
        case UTCTIME:
            break;
        case ZDO_STATUS:
            buffer[length++] = ((ZdoStatus) data).getId();
            break;
        case ZCL_STATUS:
            buffer[length++] = ((ZclStatus) data).getId();
            break;
        case BYTE_ARRAY:
            final ByteArray byteArray = (ByteArray) data;
            buffer[length++] = byteArray.size();
            for (byte valByte : byteArray.get()) {
                buffer[length++] = valByte & 0xff;
            }
            break;
        case ZIGBEE_DATA_TYPE:
            buffer[length++] = ((ZclDataType) data).getId();
            break;
        default:
            throw new IllegalArgumentException("No writer defined in " + ZigBeeDeserializer.class.getSimpleName() + " for " + type.toString() + " (" + type.getId() + ")");
    }
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) ByteArray(com.zsmartsystems.zigbee.zcl.field.ByteArray) List(java.util.List)

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