[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r616 - in /projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl: core/ global/read/ global/write/
scm-notify at zb4osgi.aaloa.org
scm-notify at zb4osgi.aaloa.org
Wed Jan 30 17:54:08 CET 2013
Author: stefano.lenzi
Date: Wed Jan 30 17:54:08 2013
New Revision: 616
Log:
The exeception thorwn when reading and writing attribute shows also the ZCLFrame in case of error ( refs #172 )
Replaced DefaultSerializer with ByteArrayOutputStreamSerializer
Modified:
projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/AttributeImpl.java
projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ResponseImpl.java
projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/read/ReadAttributeCommand.java
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/WriteAttributesResponseImpl.java
Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/AttributeImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/AttributeImpl.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/AttributeImpl.java Wed Jan 30 17:54:08 2013
@@ -149,32 +149,33 @@
AttributeDescriptor[] requestedAttributes = new AttributeDescriptor[]{descriptor};
switch ( response.getZCLHeader().getCommandId() ) {
- case ReadAttributesResponse.ID:
- ReadAttributesResponse readResponse = new ReadAttributesResponseImpl(response,requestedAttributes);
- ReadAttributesStatus attributeStatus = readResponse.getReadAttributeStatus()[0];
- if( attributeStatus.getStatus() == Status.SUCCESS.id ) {
- return attributeStatus.getAttributeData();
- } else {
- Status state = Status.getStatus(attributeStatus.getStatus());
+ case ReadAttributesResponse.ID:
+ ReadAttributesResponse readResponse = new ReadAttributesResponseImpl(response,requestedAttributes);
+ ReadAttributesStatus attributeStatus = readResponse.getReadAttributeStatus()[0];
+ if( attributeStatus.getStatus() == Status.SUCCESS.id ) {
+ return attributeStatus.getAttributeData();
+ } else {
+ Status state = Status.getStatus(attributeStatus.getStatus());
+ throw new ZigBeeClusterException(
+ "Read Attribute of "+getId()+" failed." +
+ "Due to "+state+" that means "+state.description
+ );
+ }
+ case DefaultResponse.ID:
+ //Means that the read command is not supported
+ final DefaultResponse result = new DefaultResponseImpl(response);
+ Status state = result.getStatus();
throw new ZigBeeClusterException(
- "Read Attribute of "+getId()+" failed." +
- "Due to "+state+" that means "+state.description
- );
- }
- case DefaultResponse.ID:
- //Means that the read command is not supported
- final DefaultResponse result = new DefaultResponseImpl(response);
- Status state = result.getStatus();
- throw new ZigBeeClusterException(
- "Read Attribute of "+getId()+" failed because command is not supported." +
- "Due to "+state+" that means "+state.description
- );
-
- default:
- throw new ZigBeeClusterException(
- "Read Attribute of "+getId()+" failed." +
- "Due to: Unsupported answer: "+response
- );
+ "Read Attribute of "+getId()+" failed because command is not supported."
+ + "Due to "+state+" that means "+state.description
+ + " Follows the ZCLFrame recieved "+ ResponseImpl.toString( response )
+ );
+
+ default:
+ throw new ZigBeeClusterException(
+ "Read Attribute of "+getId()+" failed due to: Unsupported answer: " + response
+ + " Follows the ZCLFrame recieved "+ ResponseImpl.toString( response )
+ );
}
} catch (ZigBeeBasedriverException e) {
throw new ZigBeeClusterException(e);
@@ -196,9 +197,10 @@
if( attributeStatus.getStatus() != Status.SUCCESS.id ){
Status state = Status.getStatus(attributeStatus.getStatus());
throw new ZigBeeClusterException(
- "Unable to write value " + o.toString() +
- ". It failed with error "+state+"("+state.id+"):"+state.description
- );
+ "Unable to write value " + o.toString()
+ + ". It failed with error "+state+"("+state.id+"):"+state.description
+ + ". Follows the ZCLFrame recieved "+ ResponseImpl.toString( writeResposne )
+ );
}
}
catch (ZigBeeBasedriverException e) {
Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ResponseImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ResponseImpl.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/core/ResponseImpl.java Wed Jan 30 17:54:08 2013
@@ -110,7 +110,7 @@
}
throw new ZigBeeClusterException(
"Expected SpecificCommandFrame (" + expectedCommandId +") but Received:"
- + commandId + " ZCLFrame was " +response,
+ + commandId + " ZCLFrame was " + toString(response),
response
);
}
Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/read/ReadAttributeCommand.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/read/ReadAttributeCommand.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/read/ReadAttributeCommand.java Wed Jan 30 17:54:08 2013
@@ -27,6 +27,7 @@
import it.cnr.isti.zigbee.zcl.library.api.core.ZBSerializer;
import it.cnr.isti.zigbee.zcl.library.impl.core.AbstractCommand;
+import it.cnr.isti.zigbee.zcl.library.impl.core.ByteArrayOutputStreamSerializer;
import it.cnr.isti.zigbee.zcl.library.impl.core.DefaultSerializer;
/**
*
@@ -51,11 +52,11 @@
public byte[] getPayload(){
if( payload == null){
logger.debug("Creating Payload for command");
- payload = new byte[attributeIds.length*2];
- ZBSerializer serializer = new DefaultSerializer(payload,0);
+ ZBSerializer serializer = new ByteArrayOutputStreamSerializer();
for (int i = 0; i < attributeIds.length; i++) {
serializer.append_short((short) attributeIds[i]);
}
+ payload = serializer.getPayload();
}
return payload;
}
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 Wed Jan 30 17:54:08 2013
@@ -25,6 +25,7 @@
import it.cnr.isti.zigbee.zcl.library.api.core.ZBSerializer;
import it.cnr.isti.zigbee.zcl.library.api.global.WriteAttributeRecord;
import it.cnr.isti.zigbee.zcl.library.impl.core.AbstractCommand;
+import it.cnr.isti.zigbee.zcl.library.impl.core.ByteArrayOutputStreamSerializer;
import it.cnr.isti.zigbee.zcl.library.impl.core.DefaultSerializer;
import it.cnr.isti.zigbee.zcl.library.impl.core.ZigBeeType;
/**
@@ -46,30 +47,7 @@
public byte[] getPayload(){
if( payload == null){
- int length = 0;
- for (int i = 0; i < attributeRecord.length; i++){
-
- 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
- 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;
- }
- length = length + 2 + 1; //space for attribute id and attribute data type
- }
- payload = new byte[length];
- ZBSerializer serializer = new DefaultSerializer(payload,0);
+ ZBSerializer serializer = new ByteArrayOutputStreamSerializer();
for (int i = 0; i < attributeRecord.length; i++) {
serializer.append_short( (short) attributeRecord[i].getAttributeId());
@@ -77,6 +55,7 @@
serializer.append_byte((byte) type.getId());
serializer.appendZigBeeType(attributeRecord[i].getAttributeData(), type);
}
+ payload = serializer.getPayload();
}
return payload;
}
Modified: projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributesResponseImpl.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributesResponseImpl.java (original)
+++ projects/zb4osgi/trunk/zigbee.zcl.library/src/main/java/it/cnr/isti/zigbee/zcl/library/impl/global/write/WriteAttributesResponseImpl.java Wed Jan 30 17:54:08 2013
@@ -49,12 +49,12 @@
attributes = new WriteAttributesStatus[descriptors.length];
if( getPayload().length == 1 && getPayload()[0] == Status.SUCCESS.id ) {
for (int i = 0; i < descriptors.length; i++) {
- attributes[i]= new WriteAttributeStatusImpl(descriptors[i]);
+ attributes[i] = new WriteAttributeStatusImpl(descriptors[i]);
}
}else{
ZBDeserializer deserializer = new DefaultDeserializer(getPayload(),0);
for (int i = 0; i < descriptors.length; i++) {
- attributes[i]= new WriteAttributeStatusImpl(descriptors[i], deserializer);
+ attributes[i] = new WriteAttributeStatusImpl(descriptors[i], deserializer);
}
}
}
More information about the Commit
mailing list