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

git version control dss-commits at forum.digitalstrom.org
Mon Jan 18 16:55:31 CET 2010


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  ede78a64c1c92ceeb5f46540dc171055ccbb9547 (commit)
      from  ebec34a0cd3521bedf0a4f82e7dd0a761baa09e6 (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 ede78a64c1c92ceeb5f46540dc171055ccbb9547
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Mon Jan 18 16:48:32 2010 +0100

    Store last known meter dsid on the device
    
    References #124

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

Changes:
diff --git a/core/model/busscanner.cpp b/core/model/busscanner.cpp
index 30710dd..cbba103 100644
--- a/core/model/busscanner.cpp
+++ b/core/model/busscanner.cpp
@@ -119,7 +119,7 @@ namespace dss {
         log("scanDSMeter:    Function ID: " + unsignedLongIntToHexString(functionID));
         Device& dev = m_Apartment.allocateDevice(dsid);
         dev.setShortAddress(devID);
-        dev.setDSMeterID(dsMeterID);
+        dev.setDSMeter(_dsMeter);
         dev.setZoneID(zoneID);
         dev.setFunctionID(functionID);
 
diff --git a/core/model/device.cpp b/core/model/device.cpp
index 8c144a1..b690949 100644
--- a/core/model/device.cpp
+++ b/core/model/device.cpp
@@ -29,6 +29,7 @@
 #include "core/model/modelevent.h"
 #include "core/model/apartment.h"
 #include "core/model/modelmaintenance.h"
+#include "core/model/modulator.h"
 
 namespace dss {
 
@@ -41,6 +42,8 @@ namespace dss {
     m_DSID(_dsid),
     m_ShortAddress(ShortAddressStaleDevice),
     m_ZoneID(0),
+    m_DSMeterID(-1),
+    m_LastKnownMeterDSID(NullDSID),
     m_FunctionID(0),
     m_LastCalledScene(SceneOff),
     m_Consumption(0),
@@ -155,8 +158,13 @@ namespace dss {
     return m_DSMeterID;
   } // getDSMeterID
 
-  void Device::setDSMeterID(const int _dsMeterID) {
-    m_DSMeterID = _dsMeterID;
+  const dsid_t& Device::getLastKnownDSMeterDSID() const {
+    return m_LastKnownMeterDSID;
+  } // getLastKnownDSMeterDSID
+
+  void Device::setDSMeter(const DSMeter& _dsMeter) {
+    m_DSMeterID = _dsMeter.getBusID();
+    m_LastKnownMeterDSID = _dsMeter.getDSID();
   } // setDSMeterID
 
   int Device::getZoneID() const {
diff --git a/core/model/device.h b/core/model/device.h
index 09997d8..5525a94 100644
--- a/core/model/device.h
+++ b/core/model/device.h
@@ -38,6 +38,7 @@ namespace dss {
   class PropertyNode;
   typedef boost::shared_ptr<PropertyNode> PropertyNodePtr;
   class Group;
+  class DSMeter;
 
   /** Represents a dsID */
   class Device : public AddressableModelItem,
@@ -46,8 +47,9 @@ namespace dss {
     std::string m_Name;
     dsid_t m_DSID;
     devid_t m_ShortAddress;
-    int m_DSMeterID;
     int m_ZoneID;
+    int m_DSMeterID;
+    dsid_t m_LastKnownMeterDSID;
     std::bitset<63> m_GroupBitmask;
     std::vector<int> m_Groups;
     int m_FunctionID;
@@ -138,8 +140,8 @@ namespace dss {
     dsid_t getDSID() const;
     /** Returns the id of the dsMeter the device is connected to */
     int getDSMeterID() const;
-    /** Sets the dsMeterID of the device. */
-    void setDSMeterID(const int _dsMeterID);
+    const dsid_t& getLastKnownDSMeterDSID() const;
+    void setDSMeter(const DSMeter& _dsMeter);
 
     /** Returns the zone ID the device resides in. */
     int getZoneID() const;
diff --git a/core/model/modelmaintenance.cpp b/core/model/modelmaintenance.cpp
index 2ef4d39..c027597 100644
--- a/core/model/modelmaintenance.cpp
+++ b/core/model/modelmaintenance.cpp
@@ -429,15 +429,15 @@ namespace dss {
       }
     }
 
+    DSMeter& dsMeter = m_pApartment->getDSMeterByBusID(_modID);
+
     // update device
-    dev.setDSMeterID(_modID);
+    dev.setDSMeter(dsMeter);
     dev.setZoneID(_zoneID);
     dev.setShortAddress(_devID);
     dev.setFunctionID(_functionID);
     dev.setIsPresent(true);
 
-    // add to new dsMeter
-    DSMeter& dsMeter = m_pApartment->getDSMeterByBusID(_modID);
     dsMeter.addDevice(devRef);
 
     // add to new zone
diff --git a/core/model/modulator.h b/core/model/modulator.h
index 96bd7fa..1b87068 100644
--- a/core/model/modulator.h
+++ b/core/model/modulator.h
@@ -36,7 +36,7 @@ namespace dss {
 
   /** Represents a DSMeter */
   class DSMeter : public DeviceContainer,
-                    public PhysicalModelItem {
+                  public PhysicalModelItem {
   private:
     dsid_t m_DSID;
     int m_BusID;
diff --git a/tests/modeljstests.cpp b/tests/modeljstests.cpp
index f22da2b..5e6a092 100644
--- a/tests/modeljstests.cpp
+++ b/tests/modeljstests.cpp
@@ -31,6 +31,7 @@
 #include "core/propertysystem.h"
 #include "core/model/apartment.h"
 #include "core/model/device.h"
+#include "core/model/modulator.h"
 
 #include <boost/scoped_ptr.hpp>
 #include <memory>
@@ -64,9 +65,12 @@ BOOST_AUTO_TEST_CASE(testBasics) {
 BOOST_AUTO_TEST_CASE(testSets) {
   Apartment apt(NULL);
 
+  DSMeter& meter = apt.allocateDSMeter(dsid_t(0,10));
+  meter.setBusID(1);
+
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
-  dev1.setDSMeterID(1);
+  dev1.setDSMeter(meter);
   dev1.addToGroup(1);
   dev1.setIsPresent(true);
   dev1.setZoneID(1);
@@ -74,7 +78,7 @@ BOOST_AUTO_TEST_CASE(testSets) {
   dev1.setFunctionID(1);
   Device& dev2 = apt.allocateDevice(dsid_t(0,2));
   dev2.setShortAddress(2);
-  dev2.setDSMeterID(1);
+  dev2.setDSMeter(meter);
   dev2.addToGroup(1);
   dev2.setIsPresent(false);
   dev2.setZoneID(2);
diff --git a/tests/modeltests.cpp b/tests/modeltests.cpp
index 6c1a7ad..87a1a9b 100644
--- a/tests/modeltests.cpp
+++ b/tests/modeltests.cpp
@@ -48,10 +48,13 @@ BOOST_AUTO_TEST_SUITE(Model)
 BOOST_AUTO_TEST_CASE(testApartmentAllocateDeviceReturnsTheSameDeviceForDSID) {
   Apartment apt(NULL);
 
+  DSMeter& meter = apt.allocateDSMeter(dsid_t(0,10));
+  meter.setBusID(1);
+
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
   dev1.setName("dev1");
-  dev1.setDSMeterID(1);
+  dev1.setDSMeter(meter);
 
   Device& dev2 = apt.allocateDevice(dsid_t(0,1));
   BOOST_CHECK_EQUAL(dev1.getShortAddress(), dev2.getShortAddress());
@@ -62,15 +65,20 @@ BOOST_AUTO_TEST_CASE(testApartmentAllocateDeviceReturnsTheSameDeviceForDSID) {
 BOOST_AUTO_TEST_CASE(testSetGetByBusID) {
   Apartment apt(NULL);
 
+  DSMeter& meter1 = apt.allocateDSMeter(dsid_t(0,10));
+  meter1.setBusID(1);
+  DSMeter& meter2 = apt.allocateDSMeter(dsid_t(0,11));
+  meter2.setBusID(2);
+
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
   dev1.setName("dev1");
-  dev1.setDSMeterID(1);
+  dev1.setDSMeter(meter1);
 
   Device& dev2 = apt.allocateDevice(dsid_t(0,2));
   dev2.setShortAddress(1);
   dev2.setName("dev2");
-  dev2.setDSMeterID(2);
+  dev2.setDSMeter(meter2);
 
   DSMeter& mod1 = apt.allocateDSMeter(dsid_t(0,3));
   mod1.setBusID(1);
@@ -115,6 +123,22 @@ BOOST_AUTO_TEST_CASE(testSetRemoveDevice) {
   BOOST_CHECK_EQUAL(set.get(0).getDevice(), dev2);
 } // testSetRemoveDevice
 
+BOOST_AUTO_TEST_CASE(testDeviceLastKnownDSMeterDSIDWorks) {
+  Apartment apt(NULL);
+
+  DSMeter& mod = apt.allocateDSMeter(dsid_t(0,10));
+  mod.setBusID(1);
+
+  Device& dev1 = apt.allocateDevice(dsid_t(0,1));
+
+  BOOST_CHECK_EQUAL(dev1.getLastKnownDSMeterDSID().toString(), NullDSID.toString());
+
+  dev1.setDSMeter(mod);
+
+  BOOST_CHECK_EQUAL(dev1.getDSMeterID(), 1);
+  BOOST_CHECK_EQUAL(dev1.getLastKnownDSMeterDSID().toString(), dsid_t(0,10).toString());
+} // testDeviceLastKnownDSMeterDSIDWorks
+
 BOOST_AUTO_TEST_CASE(testApartmentGetDeviceByShortAddress) {
   Apartment apt(NULL);
 
@@ -124,7 +148,7 @@ BOOST_AUTO_TEST_CASE(testApartmentGetDeviceByShortAddress) {
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
   dev1.setName("dev1");
-  dev1.setDSMeterID(1);
+  dev1.setDSMeter(mod);
 
   BOOST_CHECK_EQUAL("dev1", apt.getDeviceByShortAddress(mod, 1).getName());
 } // testApartmentGetDeviceByShortAddress
@@ -159,21 +183,25 @@ BOOST_AUTO_TEST_CASE(testApartmentGetDSMeterByBusID) {
 BOOST_AUTO_TEST_CASE(testZoneMoving) {
   Apartment apt(NULL);
 
+  DSMeter& meter = apt.allocateDSMeter(dsid_t(0,10));
+  meter.setBusID(1);
+
+
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
-  dev1.setDSMeterID(1);
+  dev1.setDSMeter(meter);
   DeviceReference devRef1(dev1, &apt);
   Device& dev2 = apt.allocateDevice(dsid_t(0,2));
   dev2.setShortAddress(2);
-  dev2.setDSMeterID(1);
+  dev2.setDSMeter(meter);
   DeviceReference devRef2(dev2, &apt);
   Device& dev3 = apt.allocateDevice(dsid_t(0,3));
   dev3.setShortAddress(3);
-  dev3.setDSMeterID(1);
+  dev3.setDSMeter(meter);
   DeviceReference devRef3(dev3, &apt);
   Device& dev4 = apt.allocateDevice(dsid_t(0,4));
   dev4.setShortAddress(4);
-  dev4.setDSMeterID(1);
+  dev4.setDSMeter(meter);
   DeviceReference devRef4(dev4, &apt);
 
   Zone& zone1 = apt.allocateZone(1);
@@ -228,18 +256,21 @@ BOOST_AUTO_TEST_CASE(testZoneMoving) {
 BOOST_AUTO_TEST_CASE(testSet) {
   Apartment apt(NULL);
 
+  DSMeter& meter = apt.allocateDSMeter(dsid_t(0,10));
+  meter.setBusID(1);
+
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setShortAddress(1);
-  dev1.setDSMeterID(1);
+  dev1.setDSMeter(meter);
   Device& dev2 = apt.allocateDevice(dsid_t(0,2));
   dev2.setShortAddress(2);
-  dev2.setDSMeterID(1);
+  dev2.setDSMeter(meter);
   Device& dev3 = apt.allocateDevice(dsid_t(0,3));
   dev3.setShortAddress(3);
-  dev3.setDSMeterID(1);
+  dev3.setDSMeter(meter);
   Device& dev4 = apt.allocateDevice(dsid_t(0,4));
   dev4.setShortAddress(4);
-  dev4.setDSMeterID(1);
+  dev4.setDSMeter(meter);
 
   Set allDevices = apt.getDevices();
 
@@ -505,19 +536,19 @@ BOOST_AUTO_TEST_CASE(testCallScenePropagation) {
   Device& dev1 = apt.allocateDevice(dsid_t(0,1));
   dev1.setName("dev1");
   dev1.setShortAddress(1);
-  dev1.setDSMeterID(76);
+  dev1.setDSMeter(mod);
   DeviceReference devRef1(dev1, &apt);
   mod.addDevice(devRef1);
   Device& dev2 = apt.allocateDevice(dsid_t(0,2));
   dev2.setName("dev2");
   dev2.setShortAddress(2);
-  dev2.setDSMeterID(76);
+  dev2.setDSMeter(mod);
   DeviceReference devRef2(dev2, &apt);
   mod.addDevice(devRef2);
   Device& dev3 = apt.allocateDevice(dsid_t(0,3));
   dev3.setName("dev3");
   dev3.setShortAddress(3);
-  dev3.setDSMeterID(76);
+  dev3.setDSMeter(mod);
   DeviceReference devRef3(dev3, &apt);
   mod.addDevice(devRef3);
 


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list