[zb4osgi-changeset] [scm] ZigBee 4 OSGi repository change: r999 - in /projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester: pom.xml src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java

scm-notify at zb4osgi.aaloa.org scm-notify at zb4osgi.aaloa.org
Thu Apr 24 16:49:16 CEST 2014


Author: giancarlo.riolo
Date: Thu Apr 24 16:49:16 2014
New Revision: 999

Log:
noGUI Tester Reporting working. 

Modified:
    projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/pom.xml
    projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java

Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/pom.xml
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/pom.xml (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/pom.xml Thu Apr 24 16:49:16 2014
@@ -97,7 +97,8 @@
 							it.cnr.isti.zigbee.ha.*,
 							org.osgi.*,
 							org.slf4j;
-							provider=paxlogging
+							provider=paxlogging,
+							it.cnr.isti.zigbee.api
 						</Import-Package>
 					</instructions>
 				</configuration>

Modified: projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java
==============================================================================
--- projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java (original)
+++ projects/zb4osgi/sandbox/giancarlo.riolo/zigbee.noGUI.tester/src/main/java/it/cnr/isti/zb4osgi/zigbee/noGUI/tester/TesterConfiguration.java Thu Apr 24 16:49:16 2014
@@ -27,12 +27,15 @@
 import it.cnr.isti.zigbee.ha.driver.core.HADevice;
 import it.cnr.isti.zigbee.zcl.library.api.core.AnalogSubscription;
 import it.cnr.isti.zigbee.zcl.library.api.core.Attribute;
+import it.cnr.isti.zigbee.zcl.library.api.core.ReportListener;
 import it.cnr.isti.zigbee.zcl.library.api.core.Subscription;
 import it.cnr.isti.zigbee.zcl.library.api.core.ZigBeeType;
 
 import java.util.ArrayList;
 import java.util.Dictionary;
+import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
 
 import org.osgi.framework.BundleContext;
@@ -54,6 +57,7 @@
 			.getLogger(TesterConfiguration.class);
 
 	private final HashMap<String, Object> configuration = new HashMap<String, Object>();
+	private Hashtable<Attribute, ReportListener> subscription = new Hashtable<Attribute, ReportListener>();
 	private BundleContext context;
 	private DeviceMonitor monitor;
 
@@ -170,44 +174,46 @@
 					logger.debug(
 							"Subscription found for clusterID {} and attributeID {}",
 							clusterID, attributeID);
-					try {
-						sub.setMaximumReportingInterval(reportingTimeMax);
-					} catch (NumberFormatException ex) {
-
-						sub.setMaximumReportingInterval(Subscription.DEFAULT_MAX_REPORTING_INTERVAL);
+					ReportListener listener = subscription.get(attribute);
+					if (listener == null) {
+						listener = new LogListener(device);
+
+						try {
+							sub.setMaximumReportingInterval(reportingTimeMax);
+						} catch (NumberFormatException ex) {
+
+							sub.setMaximumReportingInterval(Subscription.DEFAULT_MAX_REPORTING_INTERVAL);
+						}
+						try {
+							sub.setMinimumReportingInterval(reportingTimeMin);
+						} catch (NumberFormatException ex) {
+
+							sub.setMinimumReportingInterval(Subscription.DEFAULT_MIN_REPORTING_INTERVAL);
+						}
+						if (sub instanceof AnalogSubscription) {
+							AnalogSubscription asub = (AnalogSubscription) sub;
+							final ZigBeeType type = attribute.getZigBeeType();
+							try {
+								asub.setReportableChange(delta);
+							} catch (NumberFormatException ex) {
+
+								asub.setReportableChange(AnalogSubscription.DEFAULT_REPORTABLE_CHANGE_INTERVAL);
+							}
+							logger.debug(
+									"Subscribed reporting  ClusterID {} AttributeID {}:",
+									clusterID, attributeID);
+
+						}
+
+						if (sub.addReportListener(listener)) {
+							logger.debug("Subscribed to " + attribute.getName()
+									+ "\n\t" + "Status: SUCCESS\n");
+							subscription.put(attribute, listener);
+						} else {
+							logger.debug("Subscribed to " + attribute.getName()
+									+ "\n\t" + "Status: FAILED\n");
+						}
 					}
-					try {
-						sub.setMinimumReportingInterval(reportingTimeMin);
-					} catch (NumberFormatException ex) {
-
-						sub.setMinimumReportingInterval(Subscription.DEFAULT_MIN_REPORTING_INTERVAL);
-					}
-					if (sub instanceof AnalogSubscription) {
-						AnalogSubscription asub = (AnalogSubscription) sub;
-						final ZigBeeType type = attribute.getZigBeeType();
-						try {
-							asub.setReportableChange(delta);
-						} catch (NumberFormatException ex) {
-
-							asub.setReportableChange(AnalogSubscription.DEFAULT_REPORTABLE_CHANGE_INTERVAL);
-						}
-						logger.debug(
-								"Subscribed reporting  ClusterID {} AttributeID {}:",
-								clusterID, attributeID);
-
-					}
-
-					// if
-					// (attribute.getSubscription().addReportListener(listener))
-					// {
-					// logger.debug("Subscribed to " + attribute.getName()
-					// + "\n\t" + "Status: SUCCESS\n");
-					// HashMap<String, Object> subscription;
-					// subscription.put(attribute, listener);
-					// } else {
-					// logger.debug("Subscribed to " + attribute.getName()
-					// + "\n\t" + "Status: FAILED\n");
-					// }
 				} else {
 					logger.debug(
 							"Not reportable AttributeID {} and ClusterID {}",
@@ -224,4 +230,24 @@
 					(Integer) clusterID, device.getName());
 		}
 	}
+	class LogListener implements ReportListener {
+
+		final HADevice device;
+
+		LogListener(HADevice d) {
+			device = d;
+		}
+
+		public void receivedReport(Dictionary<Attribute, Object> reports) {
+			Enumeration<Attribute> attributes = reports.keys();
+			while (attributes.hasMoreElements()) {
+				Attribute a = (Attribute) attributes.nextElement();
+				Object v = reports.get(a);
+				logger.debug("Received Event from device " + device.getName()
+						+ "[" + device.getZBDevice().getUniqueIdenfier()
+						+ "] for attribute " + a.getName() + " with value " + v);
+
+			}
+		}
+	}
 }




More information about the Commit mailing list