[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r1104 - /projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/communication/AFLayer.java

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Sat Nov 15 16:19:04 CET 2014


Author: stefano.lenzi
Date: Sat Nov 15 16:19:04 2014
New Revision: 1104

Log:
Updating the code for better reability and using retry as expected ( refs #270 )


Modified:
    projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/communication/AFLayer.java

Modified: projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/communication/AFLayer.java
==============================================================================
--- projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/communication/AFLayer.java	(original)
+++ projects/zb4osgi/trunk/zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/communication/AFLayer.java	Sat Nov 15 16:19:04 2014
@@ -166,26 +166,28 @@
 			}
 			logger.warn( "Following the list of filtered cluster that we are going to register: {} ", clusters );
 		} 
+		/*
+		 * //TODO We should provide a workaround for the maximum number of registered EndPoint
+		 * For example, with the CC2480 we could reset the dongle
+		 */			
 		AF_REGISTER_SRSP result = null;
 		int retry = 0;
 		do {
-			result = driver.sendAFRegister(new AF_REGISTER(
-				endPoint, si.profileId, (short)0, (byte)0,
-				clusters,clusters						
-			));
-			//FIX We should retry only when Status != 0xb8  ( ZApsDuplicateEntry )
-			if( result.getStatus() != 0 ){
-				if ( retry < Activator.getCurrentConfiguration().getAutomaticFreeEndPointRetry() ) {
-					endPoint = getFreeEndPoint();
+			result = driver.sendAFRegister( new AF_REGISTER(
+				endPoint, si.profileId, (short) 0, (byte) 0, clusters, clusters						
+			) );
+			
+			if ( result != null && result.getStatus() == 0 ) {
+				break;
+			}
+			if ( retry >= Activator.getCurrentConfiguration().getAutomaticFreeEndPointRetry() ) {
+				if ( result == null ) {
+					throw new IllegalStateException("No answer to AF_REGISTER command");			
 				} else {
-					/*
-					 * //TODO We should provide a workaround for the maximum number of registered EndPoint
-					 * For example, with the CC2480 we could reset the dongle
-					 */			
 					throw new IllegalStateException("Unable create a new Endpoint. AF_REGISTER command failed with "+result.getStatus()+":"+result.getErrorMsg());			
 				}
 			} else {
-				break;
+				retry++;
 			}
 		} while( true );
 		logger.debug("Registered endpoint {} with clusters: {}", endPoint, clusters);




More information about the Commit mailing list