[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r612 - 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/core/ main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Wed Jan 30 17:34:04 CET 2013


Author: stefano.lenzi
Date: Wed Jan 30 17:34:04 2013
New Revision: 612

Log:
Parsing of cluster was broken again because they were expecting Generic Response instead of Cluster Specific Response ( refs #174 )
Fixed parsing of Get Group Membership Command ( refs #153 )
Added method for readin uint8 and uint16 from ZCL Frame ( refs #153 ) to DefaultDeserializer and ZBDeserializer


Added:
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImplTest.java   (with props)
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImplTest.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/AddGroupResponseImpl.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImpl.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/RemoveGroupResponseImpl.java
    projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java

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 Wed Jan 30 17:34:04 2013
@@ -77,6 +77,12 @@
 	
 	/**
 	 * 
+	 * @return the 8bit unsigned
+	 * @since 0.8.0
+	 */
+	public short read_uint8bit();
+	/**
+	 * 
 	 * @return the 24bit parsed
 	 * @since 0.4.0
 	 */
@@ -96,5 +102,13 @@
 	 * @since 0.2.0
 	 */
 	public void skip(int n);
+
+
+	/**
+	 * 
+	 * @return an integer read from a 16bit
+	 * @since 0.8.0
+	 */
+	public int read_uint16bit();
 	
 }

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 Wed Jan 30 17:34:04 2013
@@ -88,6 +88,20 @@
 		return value;
 	}
 
+	public short read_uint8bit() {
+		short value = Integers.readByte(payload, index);
+		value = (short) (value & 0x000000FF);
+		index+=1;
+		return value;
+	}
+	
+	public int read_uint16bit() {
+		int value = Integers.readShort(payload, index);
+		value = value & 0x0000FFFF;
+		index += 2;
+		return value;
+	}	
+	
 	public byte read_byte() {
 		byte value = Integers.readByte(payload, index);
 		index+=1;

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImpl.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImpl.java Wed Jan 30 17:34:04 2013
@@ -45,10 +45,10 @@
 	
 	public AddGroupResponseImpl(Response response) throws ZigBeeClusterException {
 		super(response);
-		ResponseImpl.checkGeneralCommandFrame(response, AddGroupResponse.ID);
+		ResponseImpl.checkSpecificCommandFrame(response, AddGroupResponse.ID);
 		ZBDeserializer deserializer = new DefaultDeserializer(getPayload(),0);
 		status = deserializer.read_byte();
-		groupId = deserializer.read_short();		
+		groupId = deserializer.read_uint16bit();		
 	}
 	
 	public int getGroupId() {

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImpl.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImpl.java Wed Jan 30 17:34:04 2013
@@ -44,12 +44,13 @@
 	
 	public GetGroupMembershipResponseImpl(Response response) throws ZigBeeClusterException {
 		super(response);
-		ResponseImpl.checkGeneralCommandFrame(response, GetGroupMembershipResponse.ID);
+		ResponseImpl.checkSpecificCommandFrame(response, GetGroupMembershipResponse.ID);
 		ZBDeserializer deserializer = new DefaultDeserializer(getPayload(),0);
-		capacity =  deserializer.read_short();
-		int count = deserializer.read_short();
+		capacity =  (short) deserializer.read_uint8bit();
+		int count = deserializer.read_uint8bit();
+		groupList = new int[count];
 		for (int i = 0; i < count; i++) {
-			groupList[i] = deserializer.read_int(); 
+			groupList[i] = deserializer.read_short(); 
 		}	
 	}
 	

Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/RemoveGroupResponseImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/RemoveGroupResponseImpl.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/RemoveGroupResponseImpl.java Wed Jan 30 17:34:04 2013
@@ -43,7 +43,7 @@
 
 	public RemoveGroupResponseImpl(Response response) throws ZigBeeClusterException {
 		super(response);
-		ResponseImpl.checkGeneralCommandFrame(response, RemoveGroupResponse.ID);
+		ResponseImpl.checkSpecificCommandFrame(response, RemoveGroupResponse.ID);
 		ZBDeserializer deserializer = new DefaultDeserializer(getPayload(),0);
 		status = deserializer.read_byte();
 		groupId = deserializer.read_short();

Added: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImplTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImplTest.java (added)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImplTest.java Wed Jan 30 17:34:04 2013
@@ -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.zcl.library.api.core.Status;
+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.impl.ClusterImpl;
+import it.cnr.isti.zigbee.zcl.library.impl.RawClusterImpl;
+import it.cnr.isti.zigbee.zcl.library.impl.core.ResponseImpl;
+import it.cnr.isti.zigbee.zcl.library.impl.core.ZCLFrame;
+
+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 AddGroupResponseImplTest {
+
+	@Test
+	public void testAddGroupResponseImpl() {
+		try {
+			AddGroupResponseImpl response = new AddGroupResponseImpl(
+				new ResponseImpl(
+						new RawClusterImpl(
+								Groups.ID, 
+								new byte[]{0x09, 0x18, 0x00, 0x00, 0x00, (byte) 0xf0 }
+						), 
+						Groups.ID 
+				)
+			);
+			assertEquals( Status.SUCCESS, response.getStatus() );
+			assertEquals( 0xf000, response.getGroupId() );
+		} catch (ZigBeeClusterException e) {
+			e.printStackTrace();
+			fail("Exception thrwon "+e.getMessage());
+		}
+	}
+
+}

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

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImplTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/AddGroupResponseImplTest.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/general/groups/AddGroupResponseImplTest.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/GetGroupMembershipResponseImplTest.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImplTest.java (added)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImplTest.java Wed Jan 30 17:34:04 2013
@@ -1,0 +1,80 @@
+/*
+
+   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.zcl.library.api.core.ZigBeeClusterException;
+import it.cnr.isti.zigbee.zcl.library.api.general.Groups;
+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 GetGroupMembershipResponseImplTest {
+
+	@Test
+	public void testGetGroupMembershipResponseImpl() {
+		try {
+			GetGroupMembershipResponseImpl response = new GetGroupMembershipResponseImpl(
+				new ResponseImpl(
+						new RawClusterImpl(
+								Groups.ID, 
+								new byte[]{0x09, 0x18, 0x02, 0x07, 0x01, 0x0f, 0x00}
+						), 
+						Groups.ID 
+				)
+			);
+			assertEquals(7, response.getCapacity());
+			assertEquals(1, response.getGroupList().length);
+			assertArrayEquals(new int[]{0x0f}, response.getGroupList());
+		} catch (ZigBeeClusterException e) {
+			e.printStackTrace();
+			fail("Exception thrwon "+e.getMessage());
+		}
+		
+		try {
+			GetGroupMembershipResponseImpl response = new GetGroupMembershipResponseImpl(
+				new ResponseImpl(
+						new RawClusterImpl(
+								Groups.ID, 
+								new byte[]{0x09, 0x18, 0x02, (byte) 0xF0, 0x03, 0x0f, 0x00, 0x00, (byte) 0xf0, 0x34, 0x12}
+						), 
+						Groups.ID 
+				)
+			);
+			assertEquals(240, response.getCapacity());
+			assertEquals(3, response.getGroupList().length);
+			assertArrayEquals(new int[]{0x0f, 0xfffff000, 0x1234}, response.getGroupList());
+		} catch (ZigBeeClusterException e) {
+			e.printStackTrace();
+			fail("Exception thrwon "+e.getMessage());
+		}
+	}
+}

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

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImplTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/GetGroupMembershipResponseImplTest.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/general/groups/GetGroupMembershipResponseImplTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 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 (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/test/java/it/cnr/isti/zigbee/zcl/library/impl/general/groups/ViewGroupResponseImplTest.java Wed Jan 30 17:34:04 2013
@@ -42,7 +42,7 @@
 public class ViewGroupResponseImplTest {
 
 	@Test
-	public void testResponseImplResponse() {
+	public void testViewGroupResponseImpl() {
 		Cluster c = new RawClusterImpl((short) 0x04, new byte[]{
 				0x19,
 				0x15,




More information about the Commit mailing list