[dss-commits] digitalSTROM Server branch, master, updated. d545151f73185e53773fac786159778dbd27f86c

git version control dss-commits at forum.digitalstrom.org
Fri Nov 20 14:01:40 CET 2009


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "digitalSTROM Server".

The branch, master has been updated
       via  d545151f73185e53773fac786159778dbd27f86c (commit)
      from  13ab94d03df4ca2aac54ca124b0ac2e04b92f492 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d545151f73185e53773fac786159778dbd27f86c
Author: Johannes Winkelmann <johannes.winkelmann at aizo.com>
Date:   Fri Nov 20 14:01:29 2009 +0100

    add iPhone plugin, optimize power consumption queries (refs #95)

-----------------------------------------------------------------------

Changes:
diff --git a/core/model.cpp b/core/model.cpp
index 8068fb8..76fff37 100644
--- a/core/model.cpp
+++ b/core/model.cpp
@@ -987,6 +987,14 @@ namespace dss {
     }
   } // modulatorReady
 
+  void Apartment::setPowerConsumption(int _modulatorBusID, unsigned long _value) {
+    getModulatorByBusID(_modulatorBusID).setPowerConsumption(_value);
+  } // powerConsumption
+
+  void Apartment::setEnergyMeterValue(int _modulatorBusID, unsigned long _value) {
+    getModulatorByBusID(_modulatorBusID).setEnergyMeterValue(_value);
+  } // energyMeterValue
+
   void Apartment::handleModelEvents() {
     if(!m_ModelEvents.empty()) {
       ModelEvent& event = m_ModelEvents.front();
@@ -1047,6 +1055,22 @@ namespace dss {
         log("Got bus ready event.", lsInfo);
         initializeFromBus();
         break;
+      case ModelEvent::etPowerConsumption:
+        if(event.getParameterCount() != 2) {
+          log("Expected exactly 2 parameter for ModelEvent::etPowerConsumption");
+        } else {
+          setPowerConsumption(event.getParameter(0), event.getParameter(1));
+        }
+        break;
+      case ModelEvent::etEnergyMeterValue:
+        if(event.getParameterCount() != 2) {
+          log("Expected exactly 2 parameter for ModelEvent::etEnergyMeterValue");
+        } else {
+          setEnergyMeterValue(event.getParameter(0), event.getParameter(1));
+        }
+        break;
+
+
       default:
         assert(false);
         break;
@@ -1795,6 +1819,23 @@ namespace dss {
     return m_EnergyMeterValue;
   } // getEnergyMeterValue
 
+
+  /** set the consumption in mW */
+  void Modulator::setPowerConsumption(unsigned long _value)
+  {
+    DateTime now;
+    m_PowerConsumptionAge = now;
+    m_PowerConsumption = _value;
+  }
+
+  /** set the meter value in Wh */
+  void Modulator::setEnergyMeterValue(unsigned long _value)
+  {
+    DateTime now;
+    m_EnergyMeterValueAge = now;
+    m_EnergyMeterValue = _value;
+  }
+
   unsigned long Modulator::getCachedPowerConsumption() {
     return m_PowerConsumption;
   } // getPowerConsumption
diff --git a/core/model.h b/core/model.h
index 9f67eba..31757dc 100644
--- a/core/model.h
+++ b/core/model.h
@@ -556,6 +556,12 @@ namespace dss {
     /** Returns the meter value in Wh */
     unsigned long getEnergyMeterValue();
 
+
+    /** set the consumption in mW */
+    void setPowerConsumption(unsigned long _value);
+    /** set the meter value in Wh */
+    void setEnergyMeterValue(unsigned long _value);
+
     /** Returns the last consumption in mW returned from dS485 Bus, but never request it*/
     unsigned long getCachedPowerConsumption();
     /** Returns the last meter value in Wh returned from dS485 Bus, but never request it*/
@@ -750,7 +756,9 @@ namespace dss {
                    etNewModulator, /**< A new modulator has joined the bus */
                    etLostModulator, /**< We've lost a modulator on the bus */
                    etModulatorReady, /**< A modulator has completed its scanning cycle and is now ready */
-                   etBusReady /**< The bus transitioned into ready state */
+                   etBusReady, /**< The bus transitioned into ready state */
+                   etPowerConsumption, /**< Powerconsumption message happened */
+                   etEnergyMeterValue /**< Powerconsumption message happened */
                  } EventType;
   private:
     EventType m_EventType;
@@ -805,6 +813,8 @@ namespace dss {
     void newModulator(int _modulatorBusID);
     void lostModulator(int _modulatorBusID);
     void modulatorReady(int _modulatorBusID);
+    void setPowerConsumption(int _modulatorBusID, unsigned long _value);
+    void setEnergyMeterValue(int _modulatorBusID, unsigned long _value);
     void scheduleRescan();
   protected:
     virtual void doStart();
diff --git a/examples/plugins/iPhone_plugin/Makefile b/examples/plugins/iPhone_plugin/Makefile
new file mode 100644
index 0000000..b135569
--- /dev/null
+++ b/examples/plugins/iPhone_plugin/Makefile
@@ -0,0 +1,14 @@
+INSTALL_TARGET=../../../data/webplugins/
+
+
+all:	iPhone_plugin.so install
+
+iPhone_plugin.so2:	iPhone_plugin.o
+	g++ -shared -o iPhone_plugin.so *.o
+
+iPhone_plugin.so:	iPhone_plugin.cpp ../../../core/web/plugin/webserver_plugin.h
+	g++ -I../../../ -g3 -O0 -Wall -fPIC -shared iPhone_plugin.cpp -o iPhone_plugin.so
+
+install:	iPhone_plugin.so
+	mkdir -p $(INSTALL_TARGET)
+	cp iPhone_plugin.so $(INSTALL_TARGET)
diff --git a/examples/plugins/iPhone_plugin/iPhone_plugin.cpp b/examples/plugins/iPhone_plugin/iPhone_plugin.cpp
new file mode 100644
index 0000000..fc2bc24
--- /dev/null
+++ b/examples/plugins/iPhone_plugin/iPhone_plugin.cpp
@@ -0,0 +1,232 @@
+#include <stdlib.h>
+
+#include <sstream>
+#include <iomanip>
+
+#include "core/web/plugin/webserver_plugin.h" 
+#include "core/base.h"
+#include "core/datetools.h" 
+#include "core/dss.h" 
+#include "core/model.h" 
+#include "core/ds485client.h" 
+#include "unix/ds485.h" 
+#include "core/ds485const.h" 
+
+using namespace dss;
+
+int plugin_getversion() {
+	return WEBSERVER_PLUGIN_API_VERSION;
+} // plugin_getversion
+
+
+bool dataRequest(DSS& _dss, HashMapConstStringString& _parameter,
+		std::string& result) {
+	std::stringstream sStream;
+	std::vector<Modulator*>& modulators = _dss.getApartment().getModulators();
+	std::vector<Zone*>& zones = _dss.getApartment().getZones();
+	
+	sStream << "{\"Name\":\""<<_dss.getApartment().getName() <<"\",";
+	sStream << "\"Zone\":[";
+
+	bool firstZone = true;
+	for (std::vector<Zone*>::iterator ipZone = zones.begin(),
+			endZone = zones.end(); ipZone != endZone; ++ipZone) {
+		if (firstZone) {
+			firstZone = false;
+		} else {
+			sStream << ",";
+		}
+		sStream << "{\"Name\":\""<< (*ipZone)->getName() << "\",";
+		sStream << "\"ID\":"<< (*ipZone)->getID() << ",";
+		sStream << "\"Groups\":[";
+
+		bool firstGroup = true;
+		std::vector<Group*> groups = (*ipZone)->getGroups();
+		for (std::vector<Group*>::iterator
+				ipGroup = groups.begin(), endGroup= groups.end(); ipGroup
+				!= endGroup; ++ipGroup) {
+			if (firstGroup) {
+				firstGroup = false;
+			} else {
+				sStream << ",";
+			}
+			sStream << "{\"lastScene\":"<< (*ipGroup)->getLastCalledScene() << ",";
+			
+			Set pSet=(*ipGroup)->getDevices();
+			sStream << "\"DeviceCount\":" << pSet.length() << ",";
+			//sStream << "\"DeviceCount\":1,";
+			sStream << "\"Name\":\"" << (*ipGroup)->getName() << "\",";
+
+			sStream << "\"ID\":"<< (*ipGroup)->getID() << "}";
+
+		}
+		sStream << "]}";
+	}
+
+	sStream << "],\"Circuit\":[ ";
+
+	bool firstModulator = true;
+	for (std::vector<Modulator*>::iterator ipModulator =
+			modulators.begin(), endModulator = modulators.end(); ipModulator
+			!= endModulator; ++ipModulator) {
+		if (firstModulator) {
+			firstModulator = false;
+		} else {
+			sStream << ",";
+		}
+
+		sStream << "{\"Name\":\""<<(*ipModulator)->getName() <<"\",";
+		sStream << "\"dSID\":\"" << (*ipModulator)->getDSID().toString() << "\",";
+		sStream << "\"HardwareVersion\":\"" << (*ipModulator)->getHardwareVersion() << "\",";
+		sStream << "\"SoftwareVersion\":\"" << (*ipModulator)->getSoftwareVersion() << "\",";
+		sStream << "\"orangeEnergyLevel\":" << (*ipModulator)->getEnergyLevelOrange() << ",";
+		sStream << "\"redEnergyLevel\":" << (*ipModulator)->getEnergyLevelRed() << "";
+		sStream << "}";
+	}
+	sStream << "]}";
+
+	result = sStream.str();
+	return true;
+}
+
+bool steadyCallRequest(DSS& _dss, HashMapConstStringString& _parameter,
+		std::string& result) {
+	bool energyAnfrage=strToIntDef(_parameter["parameter"], -1) & 0x01;
+	bool lastSceneAnfrage=strToIntDef(_parameter["parameter"], -1) & 0x02;
+	bool firstModulator;
+	DS485Client oClient; 
+	DS485CommandFrame frame;
+
+    std::stringstream sStream;
+	sStream << "{";
+	if (energyAnfrage) 
+	{
+		frame.getHeader().setBroadcast(1);
+	    frame.getHeader().setDestination(0);
+	    frame.getHeader().setCounter(1);
+	    frame.setCommand(0x09); 
+	    frame.getPayload().add<uint8_t>(0x94);
+	    oClient.sendFrameDiscardResult(frame);  
+		
+		
+		std::vector<Modulator*>& modulators = _dss.getApartment().getModulators();
+
+		sStream << "\"Energy\":[";
+
+		firstModulator = true;
+		for (std::vector<Modulator*>::iterator ipModulator =
+				modulators.begin(), endModulator = modulators.end(); ipModulator
+				!= endModulator; ++ipModulator) {
+			if (firstModulator) {
+				firstModulator = false;
+			} else {
+				sStream << ",";
+			}
+
+			sStream << "{\"dSID\":\""<< (*ipModulator)->getDSID().toString() <<"\",";
+			sStream << "\"value\":" << (*ipModulator)->getCachedPowerConsumption() << "}";
+		}
+		
+		sStream << "]";
+	}
+	if (energyAnfrage && lastSceneAnfrage) 
+	{
+		sStream << ",";
+	}
+	if (lastSceneAnfrage) 
+	{
+		sStream << "\"lastScene\":[";
+		
+		std::vector<Zone*>& zones = _dss.getApartment().getZones();		
+		bool firstZone = true;
+		for (std::vector<Zone*>::iterator ipZone = zones.begin(),
+				endZone = zones.end(); ipZone != endZone; ++ipZone) {
+			if (firstZone) {
+				firstZone = false;
+			} else {
+				sStream << ",";
+			}
+			sStream << "{\"ID\":"<< (*ipZone)->getID() << ",";
+			sStream << "\"Groups\":[";
+
+			bool firstGroup = true;
+			std::vector<Group*> groups = (*ipZone)->getGroups();
+			for (std::vector<Group*>::iterator
+					ipGroup = groups.begin(), endGroup= groups.end(); ipGroup
+					!= endGroup; ++ipGroup) {
+				if (firstGroup) {
+					firstGroup = false;
+				} else {
+					sStream << ",";
+				}
+				sStream << "{\"lastScene\":"<< (*ipGroup)->getLastCalledScene() << ",";
+				sStream << "\"ID\":"<< (*ipGroup)->getID() << "}";
+
+			}
+			sStream << "]}";
+		}
+		
+		sStream << "]";
+	}
+	sStream << "}";
+	result = sStream.str();
+	
+	return true;
+}
+
+bool actionRequest(DSS& _dss, HashMapConstStringString& _parameter,
+		std::string& result) {
+	int iZoneID=strToIntDef(_parameter["zoneID"], -1);
+	int iGroupID=strToIntDef(_parameter["groupID"], -1);
+	int iSzeneID=strToIntDef(_parameter["szeneID"], -1);
+	Zone &pZone=_dss.getApartment().getZone(iZoneID);
+	Group *pGroup=pZone.getGroup(iGroupID);
+	pGroup->callScene(iSzeneID);
+	result = "";
+	return true;	
+}
+
+bool dimmUpRequest(DSS& _dss, HashMapConstStringString& _parameter,
+		std::string& result) {
+	int iZoneID=strToIntDef(_parameter["zoneID"], -1);
+	int iGroupID=strToIntDef(_parameter["groupID"], -1);
+	Zone &pZone=_dss.getApartment().getZone(iZoneID);
+	Group *pGroup=pZone.getGroup(iGroupID);
+	pGroup->increaseValue();
+	result = "";
+	return true;	
+}
+
+bool dimmDownRequest(DSS& _dss, HashMapConstStringString& _parameter,
+		std::string& result) {
+	int iZoneID=strToIntDef(_parameter["zoneID"], -1);
+	int iGroupID=strToIntDef(_parameter["groupID"], -1);
+	Zone &pZone=_dss.getApartment().getZone(iZoneID);
+	Group *pGroup=pZone.getGroup(iGroupID);
+	pGroup->decreaseValue();
+	result = "";
+	return true;	
+}
+
+bool plugin_handlerequest(const std::string& _uri,
+		HashMapConstStringString& _parameter, DSS& _dss,
+		std::string& result) {
+
+	if (_uri == "/iPhone/data") {
+		return dataRequest(_dss, _parameter, result);
+	}
+	if (_uri == "/iPhone/steadyCall") {
+		return steadyCallRequest(_dss, _parameter, result);
+	}
+	if (_uri == "/iPhone/action") {
+		return actionRequest(_dss, _parameter, result);
+	}
+	if (_uri == "/iPhone/dimmUp") {
+		return dimmUpRequest(_dss, _parameter, result);
+	}
+	if (_uri == "/iPhone/dimmDown") {
+		return dimmDownRequest(_dss, _parameter, result);
+	}
+	return false;
+} // plugin_handlerequest
+
diff --git a/unix/ds485proxy.cpp b/unix/ds485proxy.cpp
index 79e6990..d531c0c 100644
--- a/unix/ds485proxy.cpp
+++ b/unix/ds485proxy.cpp
@@ -1427,6 +1427,27 @@ namespace dss {
             log(string("Response for: ") + FunctionIDToString(functionID));
             boost::shared_ptr<ReceivedFrame> rf(new ReceivedFrame(m_DS485Controller.getTokenCount(), frame));
 
+            PayloadDissector pd2(frame->getPayload());
+            pd2.get<uint8_t>();
+            if (functionID == FunctionModulatorGetPowerConsumption) {   
+              /* hard optimized */
+              //getDSS().getApartment().getModulatorByBusID((int)(frame->getHeader().getSource())).setPowerConsumption(pd2.get<uint32_t>());
+                int modID = frame->getHeader().getSource();
+                ModelEvent* pEvent = new ModelEvent(ModelEvent::etPowerConsumption);
+                pEvent->addParameter(modID);
+                pEvent->addParameter(pd2.get<uint32_t>());
+                getDSS().getApartment().addModelEvent(pEvent);
+            }
+            if (functionID == FunctionModulatorGetEnergyMeterValue) {
+              /* hard optimized */
+              //getDSS().getApartment().getModulatorByBusID((int)(frame->getHeader().getSource())).setEnergyMeterValue(pd2.get<uint32_t>());
+                int modID = frame->getHeader().getSource();
+                ModelEvent* pEvent = new ModelEvent(ModelEvent::etEnergyMeterValue);
+                pEvent->addParameter(modID);
+                pEvent->addParameter(pd2.get<uint32_t>());
+                getDSS().getApartment().addModelEvent(pEvent);
+            }
+
             bool bucketFound = false;
             // search for a bucket to put the frame in
             m_FrameBucketsGuard.lock();


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list