[dss-commits] r8809 - in dss/trunk: core core/scripting core/sim unix webservices
dss-commits at forum.digitalstrom.org
dss-commits at forum.digitalstrom.org
Thu Oct 1 10:38:26 CEST 2009
Author: pstaehlin
Date: 2009-10-01 10:38:26 +0200 (Thu, 01 Oct 2009)
New Revision: 8809
Modified:
dss/trunk/core/model.cpp
dss/trunk/core/model.h
dss/trunk/core/scripting/modeljs.cpp
dss/trunk/core/sim/dssim.cpp
dss/trunk/core/subsystem.cpp
dss/trunk/unix/ds485proxy.cpp
dss/trunk/webservices/webservices.cpp
Log:
Schedule rescan of the bus if we can't enumerate all modulators properly
Modified: dss/trunk/core/model.cpp
===================================================================
--- dss/trunk/core/model.cpp 2009-09-29 14:08:06 UTC (rev 8808)
+++ dss/trunk/core/model.cpp 2009-10-01 08:38:26 UTC (rev 8809)
@@ -664,7 +664,8 @@
: Subsystem(_pDSS, "Apartment"),
Thread("Apartment"),
m_IsInitializing(true),
- m_pPropertyNode()
+ m_pPropertyNode(),
+ m_RescanBusIn(-1)
{ } // ctor
Apartment::~Apartment() {
@@ -728,15 +729,20 @@
_zone.addGroup(grp);
} // addDefaultGroupsToZone
- void Apartment::scanModulator(Modulator& _modulator) {
+ bool Apartment::scanModulator(Modulator& _modulator) {
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>());
+ 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(std::runtime_error& e) {
+ log(std::string("scanModulator: Error getting modulator spec: ") + e.what(), lsFatal);
+ return false;
+ }
int levelOrange, levelRed;
if(interface.getEnergyBorder(modulatorID, levelOrange, levelRed)) {
@@ -755,6 +761,10 @@
vector<int> devices = interface.getDevicesInZone(modulatorID, zoneID);
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;
+ }
vector<int> results = interface.sendCommand(cmdGetFunctionID, devID, modulatorID);
int functionID = 0;
if(results.size() == 1) {
@@ -816,6 +826,7 @@
}
}
}
+ return true;
} // scanModulator
class SetNotPresentAction : public IDeviceAction {
@@ -842,6 +853,11 @@
int modulatorID = modulatorSpec.get<0>();
log("Found modulator with id: " + intToString(modulatorID));
dsid_t modDSID = interface.getDSIDOfModulator(modulatorID);
+ if(modDSID == NullDSID) {
+ log("Could not get DSID of modulator with last known bus-id: " + intToString(modulatorID), lsFatal);
+ scheduleRescan();
+ continue;
+ }
log(" DSID: " + modDSID.toString());
Modulator& modulator = allocateModulator(modDSID);
log("Marking modulator as present");
@@ -855,9 +871,16 @@
log("Found modulator with id: " + intToString(modulatorID));
dsid_t modDSID = interface.getDSIDOfModulator(modulatorID);
log(" DSID: " + modDSID.toString());
+ if(modDSID == NullDSID) {
+ log("Could not get DSID of modulator with last known bus-id: " + intToString(modulatorID), lsFatal);
+ scheduleRescan();
+ continue;
+ }
Modulator& modulator = allocateModulator(modDSID);
modulator.setBusID(modulatorID);
- scanModulator(modulator);
+ if(!scanModulator(modulator)) {
+ scheduleRescan();
+ }
}
// mark devices of absent modulators as not present
@@ -881,6 +904,11 @@
log("Found modulator with id: " + intToString(modulatorID));
dsid_t modDSID = interface.getDSIDOfModulator(modulatorID);
log(" DSID: " + modDSID.toString());
+ if(modDSID == NullDSID) {
+ log("Could not get DSID of modulator with last known bus-id: " + intToString(modulatorID), lsFatal);
+ scheduleRescan();
+ continue;
+ }
Modulator& modulator = allocateModulator(modDSID);
modulator.setBusID(modulatorID);
}
@@ -965,9 +993,24 @@
m_ModelEventsMutex.unlock();
} else {
m_NewModelEvent.waitFor(1000);
+ if(m_RescanBusIn > 0) {
+ m_RescanBusIn--;
+ }
+ if(m_RescanBusIn == 0) {
+ m_RescanBusIn = -1;
+ initializeFromBus();
+ }
}
} // 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() {
// load devices/modulators/etc. from a config-file
std::string configFileName = DSS::getInstance()->getPropertySystem().getStringValue(getConfigPropertyBasePath() + "configfile");
Modified: dss/trunk/core/model.h
===================================================================
--- dss/trunk/core/model.h 2009-09-29 14:08:06 UTC (rev 8808)
+++ dss/trunk/core/model.h 2009-10-01 08:38:26 UTC (rev 8809)
@@ -770,6 +770,7 @@
boost::ptr_vector<ModelEvent> m_ModelEvents;
Mutex m_ModelEventsMutex;
SyncEvent m_NewModelEvent;
+ int m_RescanBusIn;
private:
void loadDevices(XMLNode& _node);
void loadModulators(XMLNode& _node);
@@ -780,11 +781,12 @@
/** Starts the event-processing */
virtual void execute();
void initializeFromBus();
- void scanModulator(Modulator& _modulator);
+ bool scanModulator(Modulator& _modulator);
void handleModelEvents();
void newModulator(int _modulatorBusID);
void lostModulator(int _modulatorBusID);
void modulatorReady(int _modulatorBusID);
+ void scheduleRescan();
protected:
virtual void doStart();
public:
Modified: dss/trunk/core/scripting/modeljs.cpp
===================================================================
--- dss/trunk/core/scripting/modeljs.cpp 2009-09-29 14:08:06 UTC (rev 8808)
+++ dss/trunk/core/scripting/modeljs.cpp 2009-10-01 08:38:26 UTC (rev 8809)
@@ -1092,7 +1092,7 @@
list.add(_changedNode->getDisplayName());
try {
m_pScriptObject->callFunctionByReference<void>(m_Function, list);
- } catch(ScriptRuntimeException& e) {
+ } catch(ScriptException& e) {
Logger::getInstance()->log("PropertyScriptListener::doOnChange: Caught exception while calling handler: " + std::string(e.what()), lsFatal);
}
} // doOnChange
Modified: dss/trunk/core/sim/dssim.cpp
===================================================================
--- dss/trunk/core/sim/dssim.cpp 2009-09-29 14:08:06 UTC (rev 8808)
+++ dss/trunk/core/sim/dssim.cpp 2009-10-01 08:38:26 UTC (rev 8809)
@@ -1050,7 +1050,7 @@
++iCreator;
}
Logger::getInstance()->log(string("Could not find creator for DSID type '") + _identifier + "'");
- throw new runtime_error(string("Could not find creator for DSID type '") + _identifier + "'");
+ throw runtime_error(string("Could not find creator for DSID type '") + _identifier + "'");
} // createDSID
void DSIDFactory::registerCreator(DSIDCreator* _creator) {
Modified: dss/trunk/core/subsystem.cpp
===================================================================
--- dss/trunk/core/subsystem.cpp 2009-09-29 14:08:06 UTC (rev 8808)
+++ dss/trunk/core/subsystem.cpp 2009-10-01 08:38:26 UTC (rev 8809)
@@ -66,7 +66,7 @@
void Subsystem::start() {
if(m_State != ssInitialized) {
- throw new std::runtime_error("Subsystem::start: Subsystem '" + m_Name + "' was not initialized.");
+ throw std::runtime_error("Subsystem::start: Subsystem '" + m_Name + "' was not initialized.");
}
if(m_Enabled) {
doStart();
Modified: dss/trunk/unix/ds485proxy.cpp
===================================================================
--- dss/trunk/unix/ds485proxy.cpp 2009-09-29 14:08:06 UTC (rev 8808)
+++ dss/trunk/unix/ds485proxy.cpp 2009-10-01 08:38:26 UTC (rev 8809)
@@ -600,7 +600,7 @@
boost::shared_ptr<ReceivedFrame> recFrame = receiveSingleFrame(cmdFrame, FunctionGetTypeRequest);
if(recFrame.get() == NULL) {
- throw new runtime_error("No frame received");
+ throw runtime_error("No frame received");
}
ModulatorSpec_t result = modulatorSpecFromFrame(recFrame->getFrame());
Modified: dss/trunk/webservices/webservices.cpp
===================================================================
--- dss/trunk/webservices/webservices.cpp 2009-09-29 14:08:06 UTC (rev 8808)
+++ dss/trunk/webservices/webservices.cpp 2009-10-01 08:38:26 UTC (rev 8809)
@@ -196,7 +196,7 @@
)
);
if(pPlugin == NULL) {
- throw new std::runtime_error("Need EventInterpreterInternalRelay to be registered");
+ throw std::runtime_error("Need EventInterpreterInternalRelay to be registered");
}
m_pEventListener.reset(new WebServiceEventListener(*pPlugin));
}
More information about the dss-commits
mailing list