[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r520 - in /projects/zb4osgi/trunk/zigbee.zcl.library/src: main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/ test/java/it/cnr/isti/zigbee/zcl/library/ test/java/it/cnr/isti/zigbee/zcl/library/impl/ test/java/it/cnr/isti/zigbee/zcl/library/impl/global/ test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Thu Oct 18 16:12:09 CEST 2012


Author: stefano.lenzi
Date: Thu Oct 18 16:12:09 2012
New Revision: 520

Log:
Added support for Octet string, Long octet string, Long character string data types
Fixed serialization of Character string ( refs 132 )
Added test JUnit for WriteAttributeCommand that checks the getPayload()



Added:
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java   (with props)
Modified:
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultSerializer.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ZigBeeType.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommand.java

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultSerializer.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultSerializer.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultSerializer.java Thu Oct 18 16:12:09 2012
@@ -63,12 +63,8 @@
 	
 	public void appendString(String str){
 		final byte[] raw = str.getBytes();
-		if ( raw.length > 255 ) {
-			throw new IllegalArgumentException("String give '"+str+"' is too long maxium String size is 255");
-		}
-		index += raw.length + 1;
-		payload[index] = (byte) (raw.length & 0xFF);
-		System.arraycopy(raw, 0, payload, index+1, raw.length);
+		System.arraycopy(raw, 0, payload, index, raw.length);
+		index += raw.length;
 	}
 
 	public void appendZigBeeType(Object data, ZigBeeType type) {
@@ -102,10 +98,16 @@
 					append_int(i.intValue());
 				}				
 			break;
-			case CharacterString:
+			case CharacterString: case OctectString: {
 				final String str = (String) data;
+				append_byte( (byte) (str.length() & (0xFF) ));
 				appendString(str);
-			break;
+			} break;
+			case LongCharacterString: case LongOctectString: {
+				final String str = (String) data;
+				append_short((short) (str.length() & (0xFFFF)));
+				appendString(str);
+			} break;
 			default:
 				throw new IllegalArgumentException(
 						"No reader defined by this "+ZBDeserializer.class.getName()+

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ZigBeeType.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ZigBeeType.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ZigBeeType.java Thu Oct 18 16:12:09 2012
@@ -33,6 +33,8 @@
  */
 public enum ZigBeeType {
 	
+	//TODO Add missing data types
+	
 	Boolean(0x10, 1, false, Boolean.class),
 	Data8bit(0x08, 1, false, Integer.class),
 	Data16bit(0x09, 2, false, Integer.class),
@@ -46,10 +48,13 @@
 	UnsignedInteger16bit(0x21, 2, true, Integer.class),
 	UnsignedInteger24bit(0x22, 3, true, Integer.class),
 	UnsignedInteger32bit(0x23, 4, true, Long.class),
+	OctectString(0x41, -1, false, String.class),
 	CharacterString(0x42, -1, false, String.class),
+	LongOctectString(0x43, -1, false, String.class),
+	LongCharacterString(0x44, -1, false, String.class),
 	Enumeration8bit(0x30, 1, false, Byte.class),
 	Enumeration16bit(0x31, 2, false, Byte.class),
-	IEEEAddress(0xf0, -1, false, String.class), // TODO: Check 
+	IEEEAddress(0xf0, 8, false, String.class), 
 	SignedInteger8bit(0x28, 1, true, Integer.class),
 	SignedInteger16bit(0x29, 2, true, Integer.class),
 	SignedInteger24bit(0x2a, 3, true, Integer.class),

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommand.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommand.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommand.java Thu Oct 18 16:12:09 2012
@@ -52,7 +52,17 @@
 				int len = attributeRecord[i].getAttributeDataType().getLength();
 				if(len == -1){
 					//TODO Use a general method instead of assuming that variable length is applied only for String 
-					length = length + ((String) attributeRecord[i].getAttributeData()).length();
+					switch( attributeRecord[i].getAttributeDataType() ) {
+						case CharacterString : case OctectString :
+							length = length + ((String) attributeRecord[i].getAttributeData()).length() + 1;
+						break;
+						case LongOctectString : case LongCharacterString :
+							length = length + ((String) attributeRecord[i].getAttributeData()).length() + 2;
+						break;
+						default:
+							throw new IllegalArgumentException("Data type "+attributeRecord[i].getAttributeDataType()+" is not supported yet");
+					}
+					
 				} else {
 					length = length + len;
 				}

Added: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java (added)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java Thu Oct 18 16:12:09 2012
@@ -1,0 +1,54 @@
+/*
+   Copyright 2008-2010 CNR-ISTI, http://isti.cnr.it
+   Institute of Information Science and Technologies 
+   of the Italian National Research Council 
+
+
+   See the NOTICE file distributed with this work for additional 
+   information regarding copyright ownership
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+package it.cnr.isti.zigbee.zcl.library.impl.global.write;
+
+import static org.junit.Assert.*;
+import it.cnr.isti.zigbee.zcl.library.api.core.Attribute;
+import it.cnr.isti.zigbee.zcl.library.api.global.WriteAttributeRecord;
+import it.cnr.isti.zigbee.zcl.library.impl.attribute.Attributes;
+import it.cnr.isti.zigbee.zcl.library.impl.core.AttributeImpl;
+
+import org.junit.Test;
+
+/**
+ * 
+ * @author <a href="mailto:stefano.lenzi at isti.cnr.it">Stefano "Kismet" Lenzi</a>
+ * @version $LastChangedRevision$ ($LastChangedDate$)
+ * @since 0.7.1
+ *
+ */
+public class WriteAttributeCommandTest {
+
+	@Test
+	public void testGetPayload() {
+		AttributeImpl attribute = new AttributeImpl(null, null, Attributes.LOCATION_DESCRIPTION);
+		WriteAttributeRecord[] values = new WriteAttributeRecord[]{
+				new WriteAttributeRecordImpl( attribute, "garage" )
+		};
+		WriteAttributeCommand command = new WriteAttributeCommand(values);
+		assertArrayEquals(new byte[]{
+				0x10, 0x00, 0x42, 0x06, 0x67, 0x61, 0x72, 0x61, 0x67, 0x65
+		}, command.getPayload()
+		);
+	}
+
+}

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributeCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the Commit mailing list