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

git version control dss-commits at forum.digitalstrom.org
Mon Dec 14 17:17:17 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  5374fdc2df8e8d96869dad2f0530ff38660d053f (commit)
       via  a47b33f2c99b59d375dad69c21222f7e6da778c8 (commit)
      from  0950b82b085b14e944d6c426d2bd1a4b2edfc751 (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 5374fdc2df8e8d96869dad2f0530ff38660d053f
Merge: a47b33f2c99b59d375dad69c21222f7e6da778c8 0950b82b085b14e944d6c426d2bd1a4b2edfc751
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Mon Dec 14 17:17:02 2009 +0100

    Merge branch 'master' of ssh://developer.digitalstrom.org/home/git/sources/dss

commit a47b33f2c99b59d375dad69c21222f7e6da778c8
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Mon Dec 14 17:15:07 2009 +0100

    Optimized DS485 scan logic
    
    As suggested by Roman, with minor adaptations
    
    Closes #236

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

Changes:
diff --git a/core/model.cpp b/core/model.cpp
index 76fff37..ffd2970 100644
--- a/core/model.cpp
+++ b/core/model.cpp
@@ -753,26 +753,46 @@ namespace dss {
   } // addDefaultGroupsToZone
 
   bool Apartment::scanModulator(Modulator& _modulator) {
+    _modulator.setIsPresent(true);
+    _modulator.setIsValid(false);
+
     DS485Interface& interface = DSS::getInstance()->getDS485Interface();
     int modulatorID = _modulator.getBusID();
 
-    ModulatorSpec_t spec = interface.getModulatorSpec(modulatorID);
-    _modulator.setSoftwareVersion(spec.get<1>());
-    _modulator.setHardwareVersion(spec.get<2>());
-    _modulator.setHardwareName(spec.get<3>());
-    _modulator.setDeviceType(spec.get<4>());
+    log("scanModulator: Start " + intToString(modulatorID) , lsInfo);
+    vector<int> zoneIDs;
+    try {
+      zoneIDs = interface.getZones(modulatorID);
+    } catch(DS485ApiError& e) {
+      log("scanModulator: Error getting ZoneIDs", lsFatal);
+      return false;
+    }
 
     int levelOrange, levelRed;
-    if(interface.getEnergyBorder(modulatorID, levelOrange, levelRed)) {
-      _modulator.setEnergyLevelOrange(levelOrange);
-      _modulator.setEnergyLevelRed(levelRed);
+    try {
+      if(interface.getEnergyBorder(modulatorID, levelOrange, levelRed)) {
+        _modulator.setEnergyLevelOrange(levelOrange);
+        _modulator.setEnergyLevelRed(levelRed);
+      }
+    } catch(DS485ApiError& e) {
+      log("scanModulator: Error getting EnergyLevels", lsFatal);
+      return false;
+    }
+
+    try {
+      ModulatorSpec_t spec = interface.getModulatorSpec(modulatorID);
+      _modulator.setSoftwareVersion(spec.get<1>());
+      _modulator.setHardwareVersion(spec.get<2>());
+      _modulator.setHardwareName(spec.get<3>());
+      _modulator.setDeviceType(spec.get<4>());
+    } catch(DS485ApiError& e) {
+      log("scanModulator: Error getting dSMSpecs", lsFatal);
+      return false;
     }
-    _modulator.setIsPresent(true);
 
     bool firstZone = true;
-    vector<int> zoneIDs = interface.getZones(modulatorID);
     foreach(int zoneID, zoneIDs) {
-      log("  Found zone with id: " + intToString(zoneID));
+      log("scanModulator:  Found zone with id: " + intToString(zoneID));
       Zone& zone = allocateZone(zoneID);
       zone.addToModulator(_modulator);
       zone.setIsPresent(true);
@@ -780,22 +800,36 @@ namespace dss {
         zone.setFirstZoneOnModulator(modulatorID);
         firstZone = false;
       }
-
-      vector<int> devices = interface.getDevicesInZone(modulatorID, zoneID);
+      vector<int> devices;
+      try {
+        devices = interface.getDevicesInZone(modulatorID, zoneID);
+      } catch(DS485ApiError& e) {
+        log("scanModulator: Error getting getDevicesInZone", lsFatal);
+        return false;
+      }
       foreach(int devID, devices) {
-        dsid_t dsid = interface.getDSIDOfDevice(modulatorID, devID);
-        if(dsid == NullDSID) {
-          log("scanModulator: Error getting DSID of device " + intToString(devID) + " on modulator " + _modulator.getDSID().toString(), lsFatal);
-          continue;
+        dsid_t dsid;
+        try {
+          dsid = interface.getDSIDOfDevice(modulatorID, devID);
+        } catch(DS485ApiError& e) {
+            log("scanModulator: Error getting getDSIDOfDevice", lsFatal);
+            return false;
+        }
+
+        vector<int> results;
+        try {
+          results = interface.sendCommand(cmdGetFunctionID, devID, modulatorID);
+        } catch(DS485ApiError& e) {
+          log("scanModulator: Error getting cmdGetFunctionID", lsFatal);
+          return false;
         }
-        vector<int> results = interface.sendCommand(cmdGetFunctionID, devID, modulatorID);
         int functionID = 0;
         if(results.size() == 1) {
           functionID = results.front();
         }
-        log("    Found device with id: " + intToString(devID));
-        log("    DSID:        " + dsid.toString());
-        log("    Function ID: " + unsignedLongIntToHexString(functionID));
+        log("scanModulator:    Found device with id: " + intToString(devID));
+        log("scanModulator:    DSID:        " + dsid.toString());
+        log("scanModulator:    Function ID: " + unsignedLongIntToHexString(functionID));
         Device& dev = allocateDevice(dsid);
         dev.setShortAddress(devID);
         dev.setModulatorID(modulatorID);
@@ -806,27 +840,33 @@ namespace dss {
         _modulator.addDevice(devRef);
         dev.setIsPresent(true);
       }
+      vector<int> groupIDs;
+      try {
+        groupIDs = interface.getGroups(modulatorID, zoneID);
+      } catch(DS485ApiError& e) {
+        log("scanModulator: Error getting getGroups", lsFatal);
+        return false;
+      }
 
-      vector<int> groupIDs = interface.getGroups(modulatorID, zoneID);
       foreach(int groupID, groupIDs) {
         if(groupID == 0) {
-          log("    Group ID is zero, bailing out... (modulatorID: " 
+          log("scanModulator:    Group ID is zero, bailing out... (modulatorID: "
               + intToString(modulatorID) + 
               "zoneID: " + intToString(zoneID) + ")",
               lsError);
           continue;
         }
-        log("    Found group with id: " + intToString(groupID));
+        log("scanModulator:    Found group with id: " + intToString(groupID));
         try {
           vector<int> devingroup = interface.getDevicesInGroup(modulatorID, zoneID, groupID);
 
           foreach(int devID, devingroup) {
             try {
-              log("     Adding device " + intToString(devID) + " to group " + intToString(groupID));
+              log("scanModulator:     Adding device " + intToString(devID) + " to group " + intToString(groupID));
               Device& dev = getDeviceByShortAddress(_modulator, devID);
               dev.addToGroup(groupID);
               if(zone.getGroup(groupID) == NULL) {
-                log("     Adding new group to zone");
+                log(" scanModulator:    Adding new group to zone");
                 zone.addGroup(new Group(groupID, zone.getID(), *this));
               }
               Group* pGroup = zone.getGroup(groupID);
@@ -838,17 +878,20 @@ namespace dss {
                 Group* pGroup = new Group(groupID, 0, *this);
                 getZone(0).addGroup(pGroup);
                 pGroup->setIsPresent(true);
-                log("     Adding new group to zone 0");
+                log("scanModulator:     Adding new group to zone 0");
+                return false;
               }
             } catch(ItemNotFoundException& e) {
-              log("Could not find device with short-address " + intToString(devID) + " on modulator " + intToString(modulatorID), lsFatal);
+              log("scanModulator: Could not find device with short-address " + intToString(devID) + " on modulator " + intToString(modulatorID), lsFatal);
+              return false;
             }
           }
         } catch(DS485ApiError& e) {
-          log("Error getting devices from group " + intToString(groupID) +
+          log("scanModulator: Error getting devices from group " + intToString(groupID) +
               " on zone " + intToString(zoneID) +
               " on modulator " + intToString(modulatorID) +
               ". Message: " + e.what(), lsFatal);
+          return false;
         }
 
         // get last called scene for zone, group
@@ -856,134 +899,43 @@ namespace dss {
           int lastCalledScene = interface.getLastCalledScene(modulatorID, zoneID, groupID);
           Group* pGroup = zone.getGroup(groupID);
           assert(pGroup != NULL);
-          log(" zoneID: " + intToString(zoneID) + " groupID: " + intToString(groupID) + " lastScene: " + intToString(lastCalledScene));
+          log("scanModulator: zoneID: " + intToString(zoneID) + " groupID: " + intToString(groupID) + " lastScene: " + intToString(lastCalledScene));
           if(lastCalledScene < 0 || lastCalledScene > MaxSceneNumber) {
             log("scanModulator: _sceneID is out of bounds. zoneID: " + intToString(zoneID) + " groupID: " + intToString(groupID) + " scene: " + intToString(lastCalledScene), lsError);
           } else {
             onGroupCallScene(zoneID, groupID, lastCalledScene);
           }
         } catch(DS485ApiError& error) {
-          log(string("Error getting last called scene '") + error.what() + "'", lsError);
+          log(string("scanModulator: Error getting last called scene '") + error.what() + "'", lsError);
+          return false;
         }
       }
     }
+    _modulator.setIsValid(true);
     return true;
-  } // scanModulator
-
-  class SetNotPresentAction : public IDeviceAction {
-  public:
-    virtual bool perform(Device& _device) {
-      _device.setIsPresent(false);
-      return true;
-    }
-  }; // SetNotPresentAction
-
-  void Apartment::initializeFromBus() {
-    DS485Interface& interface = DSS::getInstance()->getDS485Interface();
 
-    // mark modulators as not present
-    foreach(Modulator* pModulator, m_Modulators) {
-      pModulator->setIsPresent(false);
-    }
+  } // scanModulator
 
-    // mark present modulators as present
-    vector<ModulatorSpec_t> modIDs = interface.getModulators();
-    log("Found " + intToString(modIDs.size()) + " modulators...");
-    foreach(ModulatorSpec_t& modulatorSpec, modIDs) {
-      // bus-id, sw-version, hw-version, name, device-id
-      int modulatorID = modulatorSpec.get<0>();
-      log("Found modulator with id: " + intToString(modulatorID));
-      dsid_t modDSID;
-      try {
-        modDSID = interface.getDSIDOfModulator(modulatorID);
-      } catch(DS485ApiError& err) {
-        log("Could not get DSID of modulator with last known bus-id: " + intToString(modulatorID)
-            + ". Message: " + err.what(), lsFatal);
-        scheduleRescan();
-        continue;
-      }
-      log("  DSID: " + modDSID.toString());
-      Modulator& modulator = allocateModulator(modDSID);
-      log("Marking modulator as present");
-      modulator.setIsPresent(true);
-    }
-
-    // scan modulators
-    foreach(ModulatorSpec_t& modulatorSpec, modIDs) {
-      // bus-id, sw-version, hw-version, name, device-id
-      int modulatorID = modulatorSpec.get<0>();
-      log("Found modulator with id: " + intToString(modulatorID));
-      dsid_t modDSID;
-      try {
-        modDSID = interface.getDSIDOfModulator(modulatorID);
-      } catch(DS485ApiError& err) {
-        log("Could not get DSID of modulator with last known bus-id: " + intToString(modulatorID)
-            + ". Message: " + err.what(), lsFatal);
-        scheduleRescan();
-        continue;
-      }
-      log("  DSID: " + modDSID.toString());
-      Modulator& modulator = allocateModulator(modDSID);
-      modulator.setBusID(modulatorID);
+  void Apartment::modulatorReady(int _modulatorBusID) {
+    log("Modulator with id: " + intToString(_modulatorBusID) + " is ready", lsInfo);
+    try {
       try {
-        scanModulator(modulator);
+        Modulator& mod = getModulatorByBusID(_modulatorBusID);
+        if(scanModulator(mod)) {
+          boost::shared_ptr<Event> modulatorReadyEvent(new Event("modulator_ready"));
+          modulatorReadyEvent->setProperty("modulator", mod.getDSID().toString());
+          getDSS().getEventQueue().pushEvent(modulatorReadyEvent);
+        }
       } catch(DS485ApiError& e) {
-        log(std::string("Exception caught while scanning modulator: ") + e.what(), lsFatal);
-        scheduleRescan();
-      }
-    }
+        log(std::string("Exception caught while scanning modulator " + intToString(_modulatorBusID) + " : ") + e.what(), lsFatal);
 
-    // mark devices of absent modulators as not present
-    foreach(Modulator* pModulator, m_Modulators) {
-      if(!pModulator->isPresent()) {
-        Set devices = pModulator->getDevices();
-        SetNotPresentAction action;
-        devices.perform(action);
-      }
-    }
-    boost::shared_ptr<Event> modulatorReadyEvent(new Event("datamodel_changed"));
-    getDSS().getEventQueue().pushEvent(modulatorReadyEvent);
-  } // initializeFromBus
-
-  void Apartment::newModulator(int _modulatorBusID) {
-    DS485Interface& interface = DSS::getInstance()->getDS485Interface();
-
-    vector<ModulatorSpec_t> modIDs = interface.getModulators();
-    log("Found " + intToString(modIDs.size()) + " modulators...");
-    foreach(ModulatorSpec_t& modulatorSpec, modIDs) {
-      // bus-id, sw-version, hw-version, name, device-id
-      int modulatorID = modulatorSpec.get<0>();
-      log("Found modulator with id: " + intToString(modulatorID));
-      dsid_t modDSID;
-      try {
-        modDSID = interface.getDSIDOfModulator(modulatorID);
-      } catch(DS485ApiError& err) {
-        log("newModulator: Could not get DSID of modulator with last known bus-id: " 
-            + intToString(_modulatorBusID)
-            + ". Message: " + err.what(), lsFatal);
-        scheduleRescan();
-        return;
+        ModelEvent* pEvent = new ModelEvent(ModelEvent::etModulatorReady);
+        pEvent->addParameter(_modulatorBusID);
+        addModelEvent(pEvent);
       }
-      log("  DSID: " + modDSID.toString());
-      Modulator& modulator = allocateModulator(modDSID);
-      modulator.setBusID(modulatorID);
-    }
-  } // newModulator
-
-  void Apartment::lostModulator(int _modulatorBusID) {
-    initializeFromBus();
-  } // lostModulator
-
-  void Apartment::modulatorReady(int _modulatorBusID) {
-    log("Modulator with id: " + intToString(_modulatorBusID) + " is ready", lsInfo);
-    initializeFromBus();
-    try { 
-      Modulator& mod = getModulatorByBusID(_modulatorBusID);
-      boost::shared_ptr<Event> modulatorReadyEvent(new Event("modulator_ready"));
-      modulatorReadyEvent->setProperty("modulator", mod.getDSID().toString());
-      getDSS().getEventQueue().pushEvent(modulatorReadyEvent);
-    } catch(ItemNotFoundException&) {
-      Logger::getInstance()->log("modulatorReady: Could not get DSID of modulator", lsFatal);
+    } catch(ItemNotFoundException& e) {
+      log("No modulator for bus-id (" + intToString(_modulatorBusID) + ") found, re-discovering devices");
+      discoverDS485Devices();
     }
   } // modulatorReady
 
@@ -995,6 +947,21 @@ namespace dss {
     getModulatorByBusID(_modulatorBusID).setEnergyMeterValue(_value);
   } // energyMeterValue
 
+  void Apartment::discoverDS485Devices() {
+    // temporary mark all modulators as absent
+    foreach(Modulator* pModulator, m_Modulators) {
+      pModulator->setIsPresent(false);
+    }
+
+    // Request the dsid of all modulators
+    DS485CommandFrame requestFrame;
+    requestFrame.getHeader().setBroadcast(true);
+    requestFrame.getHeader().setDestination(0);
+    requestFrame.setCommand(CommandRequest);
+    requestFrame.getPayload().add<uint8_t>(FunctionModulatorGetDSID);
+    DSS::getInstance()->getDS485Interface().sendFrame(requestFrame);
+  } // discoverDS485Devices
+
   void Apartment::handleModelEvents() {
     if(!m_ModelEvents.empty()) {
       ModelEvent& event = m_ModelEvents.front();
@@ -1031,29 +998,28 @@ namespace dss {
         }
         break;
       case ModelEvent::etNewModulator:
-        if(event.getParameterCount() != 1) {
-          log("Expected exactly 1 parameter for ModelEvent::etNewModulator");
-        } else {
-          newModulator(event.getParameter(0));
-        }
+        discoverDS485Devices();
         break;
       case ModelEvent::etLostModulator:
-        if(event.getParameterCount() != 1) {
-          log("Expected exactly 1 parameter for ModelEvent::etLostModulator");
-        } else {
-          lostModulator(event.getParameter(0));
-        }
+        discoverDS485Devices();
         break;
       case ModelEvent::etModulatorReady:
         if(event.getParameterCount() != 1) {
           log("Expected exactly 1 parameter for ModelEvent::etModulatorReady");
         } else {
-          modulatorReady(event.getParameter(0));
+          try{
+            Modulator& mod = getModulatorByBusID(event.getParameter(0));
+            mod.setIsPresent(true);
+            mod.setIsValid(false);
+          } catch(ItemNotFoundException& e) {
+            log("dSM is ready, but it is not yet known, re-discovering devices");
+            discoverDS485Devices();
+          }
         }
         break;
       case ModelEvent::etBusReady:
         log("Got bus ready event.", lsInfo);
-        initializeFromBus();
+        discoverDS485Devices();
         break;
       case ModelEvent::etPowerConsumption:
         if(event.getParameterCount() != 2) {
@@ -1069,8 +1035,34 @@ namespace dss {
           setEnergyMeterValue(event.getParameter(0), event.getParameter(1));
         }
         break;
-
-
+      case ModelEvent::etDS485DeviceDiscovered:
+        if(event.getParameterCount() != 7) {
+          log("Expected exactly 7 parameter for ModelEvent::etDS485DeviceDiscovered");
+        } else {
+          int busID = event.getParameter(0);
+          uint64_t dsidUpper = (uint64_t(event.getParameter(1)) & 0x00ffff) << 48;
+          dsidUpper |= (uint64_t(event.getParameter(2)) & 0x00ffff) << 32;
+          dsidUpper |= (uint64_t(event.getParameter(3))  & 0x00ffff) << 16;
+          dsidUpper |= (uint64_t(event.getParameter(4)) & 0x00ffff);
+          dsid_t newDSID(dsidUpper,
+                         ((uint32_t(event.getParameter(5)) & 0x00ffff) << 16) | (uint32_t(event.getParameter(6)) & 0x00ffff));
+          log ("Discovered device with busID: " + intToString(busID) + " and dsid: " + newDSID.toString());
+          try{
+             getModulatorByDSID(newDSID).setBusID(busID);
+             log ("dSM present");
+             getModulatorByDSID(newDSID).setIsPresent(true);
+          } catch(ItemNotFoundException& e) {
+             log ("dSM not present");
+             Modulator& modulator = allocateModulator(newDSID);
+             modulator.setBusID(busID);
+             modulator.setIsPresent(true);
+             modulator.setIsValid(false);
+             ModelEvent* pEvent = new ModelEvent(ModelEvent::etModulatorReady);
+             pEvent->addParameter(busID);
+             addModelEvent(pEvent);
+          }
+        }
+        break;
       default:
         assert(false);
         break;
@@ -1081,24 +1073,30 @@ namespace dss {
       m_ModelEventsMutex.unlock();
     } else {
       m_NewModelEvent.waitFor(1000);
-      if(m_RescanBusIn > 0) {
-        m_RescanBusIn--;
+      bool hadToUpdate = false;
+      foreach(Modulator* pModulator, m_Modulators) {
+        if(pModulator->isPresent()) {
+          if(!pModulator->isValid()) {
+            modulatorReady(pModulator->getBusID());
+            hadToUpdate = true;
+            break;
+          }
+        }
       }
-      if(m_RescanBusIn == 0) {
-        m_RescanBusIn = -1;
-        initializeFromBus();
+
+      // If we didn't have to update for one cycle, assume that we're done
+      if(!hadToUpdate && m_IsInitializing) {
+        log("******** Finished loading model from dSM(s)...", lsInfo);
+        m_IsInitializing = false;
+
+        {
+          boost::shared_ptr<Event> readyEvent(new Event("model_ready"));
+          getDSS().getEventQueue().pushEvent(readyEvent);
+        }
       }
     }
   } // handleModelEvents
 
-  void Apartment::scheduleRescan() {
-    const int kBusRescanTimeSeconds = 10;
-    if(m_RescanBusIn <= 0) {
-      m_RescanBusIn = kBusRescanTimeSeconds;
-      log("Rescanning bus in " + intToString(kBusRescanTimeSeconds) + " seconds", lsInfo);
-    }
-  }
-
   void Apartment::execute() {
     {
       boost::shared_ptr<Event> runningEvent(new Event("running"));
@@ -1133,15 +1131,7 @@ namespace dss {
     }
 
     log("Apartment::execute: Interface is ready, enumerating model", lsInfo);
-    initializeFromBus();
-
-    Logger::getInstance()->log("******** Finished loading model from dSM(s)...", lsInfo);
-    m_IsInitializing = false;
-
-    {
-      boost::shared_ptr<Event> readyEvent(new Event("model_ready"));
-      getDSS().getEventQueue().pushEvent(readyEvent);
-    }
+    discoverDS485Devices();
 
     while(!m_Terminated) {
       handleModelEvents();
@@ -1766,7 +1756,8 @@ namespace dss {
   : m_DSID(_dsid),
     m_BusID(0xFF),
     m_PowerConsumption(0),
-    m_EnergyMeterValue(0)
+    m_EnergyMeterValue(0),
+    m_IsValid(false)
   {
   } // ctor
 
diff --git a/core/model.h b/core/model.h
index 31757dc..2f8d02f 100644
--- a/core/model.h
+++ b/core/model.h
@@ -532,6 +532,7 @@ namespace dss {
     int m_SoftwareVersion;
     std::string m_HardwareName;
     int m_DeviceType;
+    bool m_IsValid;
   public:
     /** Constructs a modulator with the given dsid. */
     Modulator(const dsid_t _dsid);
@@ -586,6 +587,10 @@ namespace dss {
     void setHardwareName(const std::string& _value) { m_HardwareName = _value; }
     int getDeviceType() { return m_DeviceType; }
     void setDeviceType(const int _value) { m_DeviceType = _value; }
+
+    /** Returns true if the modulator has been read-out completely. */
+    bool isValid() const { return m_IsValid; }
+    void setIsValid(const bool _value) { m_IsValid = _value; }
   }; // Modulator
 
   /** Represents a predefined group */
@@ -758,7 +763,8 @@ namespace dss {
                    etModulatorReady, /**< A modulator has completed its scanning cycle and is now ready */
                    etBusReady, /**< The bus transitioned into ready state */
                    etPowerConsumption, /**< Powerconsumption message happened */
-                   etEnergyMeterValue /**< Powerconsumption message happened */
+                   etEnergyMeterValue, /**< Powerconsumption message happened */
+                   etDS485DeviceDiscovered, /**< A new device has been discovered on the bus */
                  } EventType;
   private:
     EventType m_EventType;
@@ -810,12 +816,10 @@ namespace dss {
     /** Starts the event-processing */
     virtual void execute();
     void handleModelEvents();
-    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();
+    void discoverDS485Devices();
   protected:
     virtual void doStart();
   public:
@@ -886,7 +890,6 @@ namespace dss {
     void removeDevice(dsid_t _device);
     void removeModulator(dsid_t _modulator);
 
-    void initializeFromBus();
     bool scanModulator(Modulator& _modulator);
   public:
 
diff --git a/core/webserver.cpp b/core/webserver.cpp
index 1ace0bf..5324c5e 100644
--- a/core/webserver.cpp
+++ b/core/webserver.cpp
@@ -843,7 +843,10 @@ namespace dss {
         getDSS().getApartment().setName(_parameter["newName"]);
         result = ResultToJSON(true);
       } else if(endsWith(_method, "/rescan")) {
-        getDSS().getApartment().initializeFromBus();
+        std::vector<Modulator*> mods = getDSS().getApartment().getModulators();
+        foreach(Modulator* pModulator, mods) {
+          pModulator->setIsValid(false);
+        }
         result = ResultToJSON(true);
       } else {
         _handled = false;
diff --git a/unix/ds485proxy.cpp b/unix/ds485proxy.cpp
index e536005..2e9a086 100644
--- a/unix/ds485proxy.cpp
+++ b/unix/ds485proxy.cpp
@@ -1239,9 +1239,12 @@ namespace dss {
 
     case FunctionModulatorGetPowerConsumption:
     	return "Function Modulator Get PowerConsumption";
-
     case FunctionModulatorGetEnergyMeterValue:
       return "Function Modulator Get Energy-Meter Value";
+    case FunctionModulatorGetEnergyLevel:
+      return "Function Modulator Get Energy-Level";
+    case FunctionModulatorSetEnergyLevel:
+      return "Function Modulator Set Energy-Level";
 
     case FunctionGetTypeRequest:
       return "Function Get Type";
@@ -1264,6 +1267,7 @@ namespace dss {
     case EventDSLinkInterrupt:
       return "Function DSLink Interrupt";
       
+
     case FunctionZoneAddDevice:
       return "Function Zone Add Device";
     case FunctionZoneRemoveDevice:
@@ -1434,8 +1438,7 @@ namespace dss {
                 pEvent->addParameter(modID);
                 pEvent->addParameter(pd2.get<uint32_t>());
                 getDSS().getApartment().addModelEvent(pEvent);
-            }
-            if (functionID == FunctionModulatorGetEnergyMeterValue) {
+            } else if (functionID == FunctionModulatorGetEnergyMeterValue) {
               /* hard optimized */
               //getDSS().getApartment().getModulatorByBusID((int)(frame->getHeader().getSource())).setEnergyMeterValue(pd2.get<uint32_t>());
                 int modID = frame->getHeader().getSource();
@@ -1443,6 +1446,17 @@ namespace dss {
                 pEvent->addParameter(modID);
                 pEvent->addParameter(pd2.get<uint32_t>());
                 getDSS().getApartment().addModelEvent(pEvent);
+            } else if (functionID == FunctionModulatorGetDSID) {
+              int sourceID = frame->getHeader().getSource();
+              ModelEvent* pEvent = new ModelEvent(ModelEvent::etDS485DeviceDiscovered);
+              pEvent->addParameter(sourceID);
+              pEvent->addParameter(((pd2.get<uint8_t>() << 8) & 0xff00) | (pd2.get<uint8_t>() & 0x00ff));
+              pEvent->addParameter(((pd2.get<uint8_t>() << 8) & 0xff00) | (pd2.get<uint8_t>() & 0x00ff));
+              pEvent->addParameter(((pd2.get<uint8_t>() << 8) & 0xff00) | (pd2.get<uint8_t>() & 0x00ff));
+              pEvent->addParameter(((pd2.get<uint8_t>() << 8) & 0xff00) | (pd2.get<uint8_t>() & 0x00ff));
+              pEvent->addParameter(((pd2.get<uint8_t>() << 8) & 0xff00) | (pd2.get<uint8_t>() & 0x00ff));
+              pEvent->addParameter(((pd2.get<uint8_t>() << 8) & 0xff00) | (pd2.get<uint8_t>() & 0x00ff));
+              getDSS().getApartment().addModelEvent(pEvent);
             }
 
             bool bucketFound = false;
diff --git a/webservices/model_soap.cpp b/webservices/model_soap.cpp
index 9b4ed36..7047a43 100644
--- a/webservices/model_soap.cpp
+++ b/webservices/model_soap.cpp
@@ -6,6 +6,7 @@
 #include "core/sim/dssim.h"
 #include "core/propertysystem.h"
 #include "core/setbuilder.h"
+#include "core/foreach.h"
 
 #include <vector>
 #include <string>
@@ -368,7 +369,10 @@ int dss__ApartmentRescan(struct soap *soap, int _token, bool& result) {
   }
 
   dss::Apartment& apt = dss::DSS::getInstance()->getApartment();
-  apt.initializeFromBus();
+  std::vector<dss::Modulator*> mods = apt.getModulators();
+  foreach(dss::Modulator* pModulator, mods) {
+    pModulator->setIsValid(false);
+  }
 
   return SOAP_OK;
 } // dss__ApartmentRescan


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list