[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r554 - in /projects/zb4osgi/trunk/zigbee.zcl.library/src: main/java/it/cnr/isti/zigbee/zcl/library/api/core/ main/java/it/cnr/isti/zigbee/zcl/library/impl/ main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ main/java/it/cnr/isti/zigbee/zcl/library/impl/general/scenes/ test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Tue Oct 23 11:49:35 CEST 2012


Author: stefano.lenzi
Date: Tue Oct 23 11:49:35 2012
New Revision: 554

Log:
Verified and fixed parsing of "View Group Response" command ( refs #152 )
Adde Test Unit for verification of the parsing

Added:
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/RawClusterImpl.java   (with props)
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java   (with props)
Modified:
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/api/core/ZBDeserializer.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultDeserializer.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImpl.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/scenes/RemoveAllScenesCommand.java   (props changed)

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/api/core/ZBDeserializer.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/api/core/ZBDeserializer.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/api/core/ZBDeserializer.java Tue Oct 23 11:49:35 2012
@@ -51,8 +51,10 @@
 	 * 
 	 * @return the parsed {@link String} 
 	 * @since 0.4.0
+	 * @deprecated {@link #readZigBeeType(ZigBeeType)} should be used instead
 	 */
 	public String readString();
+	
 	
 	/**
 	 * Since version <b>0.4.0</b> the method must not used, use {@link #readZigBeeType(ZigBeeType)} instead.<br>

Added: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/RawClusterImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/RawClusterImpl.java (added)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/RawClusterImpl.java Tue Oct 23 11:49:35 2012
@@ -1,0 +1,50 @@
+/*
+   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;
+import it.cnr.isti.zigbee.api.Cluster;
+import it.cnr.isti.zigbee.zcl.library.impl.core.ZCLFrame;
+/**
+ * 
+ * @author <a href="mailto:stefano.lenzi at isti.cnr.it">Stefano "Kismet" Lenzi</a>
+ * @version $LastChangedRevision$ ($LastChangedDate: 2010-09-23 14:21:48 +0200(Thu, 23 Sep 2010) $)
+ * @since 0.8.0
+ *
+ */
+public class RawClusterImpl implements Cluster {
+	
+	private byte[] frame;
+	private short id;
+
+	public RawClusterImpl(short id, byte[] frame) {
+		this.frame = frame;
+		this.id = id;
+	}
+
+	public byte[] getClusterMsg() {
+		return frame;
+	}
+
+	public short getId() {
+		return id;
+	}
+
+}

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/RawClusterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/RawClusterImpl.java
------------------------------------------------------------------------------
    svn:keywords = Data Author Id Revision HeadURL

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/RawClusterImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultDeserializer.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultDeserializer.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/DefaultDeserializer.java Tue Oct 23 11:49:35 2012
@@ -126,6 +126,12 @@
 		return result;
 	}
 
+	public String readString(int size) {
+		final String result = new String(payload, index, size);
+		index += size;
+		return result;
+	}	
+	
 	public Object readZigBeeType(ZigBeeType type) {
 		Object[] value = new Object[1];
 		switch(type){
@@ -160,10 +166,14 @@
 				int i24 = read_int24bit();
 				value[0] = new Integer(i24);
 			break;
-			case CharacterString:
-				value[0] = readString();
-			break;
-			default:
+			case CharacterString: case OctectString:{
+				int size = read_byte();
+				value[0] = readString(size);
+			}break;
+			case LongCharacterString: case LongOctectString:{
+				int size = read_short();
+				value[0] = readString(size);
+			}default:
 				throw new IllegalArgumentException(
 						"No reader defined by this "+ZBDeserializer.class.getName()+
 						" for "+type.toString()+" ("+type.getId()+")"

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImpl.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImpl.java Tue Oct 23 11:49:35 2012
@@ -29,6 +29,7 @@
 import it.cnr.isti.zigbee.zcl.library.api.general.groups.ViewGroupResponse;
 import it.cnr.isti.zigbee.zcl.library.impl.core.DefaultDeserializer;
 import it.cnr.isti.zigbee.zcl.library.impl.core.ResponseImpl;
+import it.cnr.isti.zigbee.zcl.library.impl.core.ZigBeeType;
 /**
  * 
  * @author <a href="mailto:stefano.lenzi at isti.cnr.it">Stefano "Kismet" Lenzi</a>
@@ -50,10 +51,7 @@
 		ZBDeserializer deserializer = new DefaultDeserializer(getPayload(),0);
 		status = deserializer.read_byte();
 		groupId = deserializer.read_short();
-		//TODO: Variable length?
-		//TODO use the deserializer.readZigBeeType(ZigBeeType)
-		groupName = (String) deserializer.readObject(String.class);
-		//groupName = getPayload()[3]; 
+		groupName = (String) deserializer.readZigBeeType(ZigBeeType.CharacterString);
 	}
 	
 	public int getGroupId() {

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/scenes/RemoveAllScenesCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/scenes/RemoveAllScenesCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java (added)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java Tue Oct 23 11:49:35 2012
@@ -1,0 +1,65 @@
+/*
+   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.general.groups;
+
+import static org.junit.Assert.*;
+import it.cnr.isti.zigbee.api.Cluster;
+import it.cnr.isti.zigbee.zcl.library.api.core.Response;
+import it.cnr.isti.zigbee.zcl.library.api.core.ZigBeeClusterException;
+import it.cnr.isti.zigbee.zcl.library.api.general.Groups;
+import it.cnr.isti.zigbee.zcl.library.api.general.groups.ViewGroupResponse;
+import it.cnr.isti.zigbee.zcl.library.impl.RawClusterImpl;
+import it.cnr.isti.zigbee.zcl.library.impl.core.ResponseImpl;
+
+import org.junit.Test;
+
+/**
+ * 
+ * @author <a href="mailto:stefano.lenzi at isti.cnr.it">Stefano "Kismet" Lenzi</a>
+ * @version $LastChangedRevision$ ($LastChangedDate$)
+ * @since 0.8.0
+ *
+ */
+public class ViewGroupResponseImplTest {
+
+	@Test
+	public void testResponseImplResponse() {
+		Cluster c = new RawClusterImpl((short) 0x04, new byte[]{
+				0x19,
+				0x15,
+				0x01,
+				0x00, // Status = SUCCESS
+				0x10, 0x00, // GroupId = 16
+				0x03, 0x61, 0x62, 0x63 // GroupName = "abc"
+		});
+		Response r;
+		try {
+			r = new ResponseImpl(c,Groups.ID);
+			ViewGroupResponseImpl aux = new ViewGroupResponseImpl(r);
+			assertEquals(16, aux.getGroupId() );
+			assertEquals("abc", aux.getGroupName() );
+		} catch (ZigBeeClusterException e) {
+			e.printStackTrace();
+		}
+	}
+
+}

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Data Author Id Revision HeadURL

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




More information about the Commit mailing list