[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r458 - /projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeDeviceImpl.java

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Mon Sep 24 17:17:01 CEST 2012


Author: manlio.bacco
Date: Mon Sep 24 17:17:01 2012
New Revision: 458

Log:
cosmetic fixes

Modified:
    projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeDeviceImpl.java

Modified: projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeDeviceImpl.java
==============================================================================
--- projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeDeviceImpl.java (original)
+++ projects/zb4osgi/sandbox/manlio.bacco/org.aaloa.osgi.zigbee.basedriver/src/main/java/it/cnr/isti/zigbee/basedriver/api/impl/ZigBeeDeviceImpl.java Mon Sep 24 17:17:01 2012
@@ -86,8 +86,8 @@
 	private final HashSet<AFMessageConsumer> consumers = new HashSet<AFMessageConsumer>();
 	private String uuid = null;	
 
-	public ZigBeeDeviceImpl(final SimpleDriver drv, final ZigBeeNode n, byte ep) throws ZigBeeBasedriverException	
-	{ 
+	public ZigBeeDeviceImpl(final SimpleDriver drv, final ZigBeeNode n, byte ep) throws ZigBeeBasedriverException{
+
 		if ( drv == null || n == null) {
 			logger.error( "Creating {} with some nulls parameters {}", new Object[]{ ZigBeeDevice.class, drv, n, ep } );
 			throw new NullPointerException("Cannot create a device with a null SimpleDriver or a null ZigBeeNode");
@@ -129,9 +129,13 @@
 			TIMEOUT = Long.parseLong(Activator.getBundleContext().getProperty("org.aaloa.zb4osgi.zigbee.basedriver.timeout")); 
 		}
 		catch(Exception ex){
-			TIMEOUT = 10000;
+			TIMEOUT = 5000;
 			//ex.printStackTrace();
-			logger.debug("Unable to read org.aaloa.zb4osgi.zigbee.basedriver.timeout - setting to 10000 ms.");
+			logger.debug("Unable to read org.aaloa.zb4osgi.zigbee.basedriver.timeout - setting to 5000 ms.");
+		}
+
+		if(Activator.getEventingService() != null){
+			Activator.getEventingService().announce(this, deviceId, inputs);
 		}
 	}
 
@@ -212,7 +216,6 @@
 								"Waiting for {}ms before retrying",
 								new Object[]{nwkAddress, endPointAddress, i, waiting}
 						);
-
 			} else {
 				break;
 			}
@@ -276,19 +279,19 @@
 
 		if( response == null){
 			m_removeAFMessageListener();
-			throw new ZigBeeBasedriverException("Unable to send cluster on the ZigBee network due to general error");
+			throw new ZigBeeBasedriverException("Unable to send cluster on the ZigBee network due to general error - is the device sleeping?");
 		} else if (response.getStatus() == 0 ) {
 			m_removeAFMessageListener();
 			throw new ZigBeeBasedriverException("Unable to send cluster on the ZigBee network:"+response.getErrorMsg());
 		} else {
-			//FIX Can't be singelton because only a the invoke method can be invoked by multiple-thread
+			//FIX Can't be singleton because only the invoke method can be invoked by multiple-thread
 			AF_INCOMING_MSG incoming = waiter.getResponse();
 			m_removeAFMessageListener();
 			if(incoming == null){
 				//TODO Add a timeout exception
-				throw new ZigBeeBasedriverException("Timeout expired before recieving an answer");
+				throw new ZigBeeBasedriverException("Timeout expired before receiving an answer");
 			}
-			Cluster result = new ClusterImpl(incoming.getData(), incoming.getClusterId());
+			Cluster result = new ClusterImpl(incoming.getData(), incoming.getClusterId()); 
 			return result;
 		}
 	}
@@ -331,6 +334,7 @@
 			});
 			return false;
 		}
+		//Activator.pub.publish("device "+deviceId+" bounded to device "+device.getDeviceId()+" on cluster "+clusterId, Activator.getBundleContext());
 		return true;
 	}
 
@@ -351,6 +355,7 @@
 			});
 			return false;
 		}
+		//Activator.pub.publish("device "+deviceId+" unbounded from device "+device.getDeviceId()+" on cluster "+clusterId, Activator.getBundleContext());
 		return true;
 	}
 
@@ -373,6 +378,7 @@
 			return false;
 		}
 		boundCluster.add(clusterId);
+		//Activator.pub.publish("device "+deviceId+" bounded to cluster "+clusterId, Activator.getBundleContext());
 		return true;
 	}
 
@@ -396,6 +402,7 @@
 			return false;
 		}
 		boundCluster.remove(clusterId);
+		//Activator.pub.publish("device "+deviceId+" unbounded from cluster "+clusterId, Activator.getBundleContext());
 		return true;
 	}
 
@@ -454,8 +461,8 @@
 				} else  if ( filter.match(c) == true ){
 					listner.handleCluster(this, c);
 				}
-
-			}catch( Throwable t ){
+			}
+			catch( Throwable t ){
 				logger.error("Error during dispatching of Cluster <{},{}>",c.getId(),c.getClusterMsg());
 				logger.error("Error caused by:",t);
 			}
@@ -464,9 +471,15 @@
 
 	public void notify(AF_INCOMING_MSG msg) {
 		//THINK Do the notification in a separated Thread?
-		//THINK Should consume messages only if they was sent from this device?!?!
+		//THINK Should consume messages only if they were sent from this device?!?!
 		if ( msg.isError() ) return;
 		logger.debug("AF_INCOMIN_MSG arrived for {} message is {}", uuid, msg);
+
+		/* */
+		if(Activator.getEventingService() != null)
+			Activator.getEventingService().event(msg.getClusterId(), msg.getData());
+		/* */
+
 		ArrayList<AFMessageConsumer> localConsumers = null;
 		synchronized (consumers) {
 			localConsumers = new ArrayList<AFMessageConsumer>(consumers);
@@ -483,7 +496,7 @@
 
 		if ( msg.getSrcAddr() != node.getNetworkAddress() ) return;
 		if ( msg.getSrcEndpoint() != endPointAddress ) return;
-		logger.debug("Notifying cluster listerner for recived by {}", uuid);
+		logger.debug("Notifying cluster listener for received by {}", uuid);
 		notifyClusterListner(new ClusterImpl(msg.getData(), msg.getClusterId()));
 	}
 
@@ -498,7 +511,7 @@
 			return consumers.remove(consumer);
 		}
 	}
-	
+
 	@SuppressWarnings("unchecked")
 	public Dictionary getDescription(){
 		return properties;




More information about the Commit mailing list