[dss-commits] r8750 - in dss/trunk: core core/sim unix
dss-commits at forum.digitalstrom.org
dss-commits at forum.digitalstrom.org
Wed Sep 9 11:48:58 CEST 2009
Author: pstaehlin
Date: 2009-09-09 11:48:58 +0200 (Wed, 09 Sep 2009)
New Revision: 8750
Modified:
dss/trunk/core/ds485const.h
dss/trunk/core/model.cpp
dss/trunk/core/model.h
dss/trunk/core/sim/dssim.cpp
dss/trunk/unix/ds485proxy.cpp
Log:
- Support for modulators joining/leaving the bus
=> Closes #116
- Corrected constants for dSLink
Modified: dss/trunk/core/ds485const.h
===================================================================
--- dss/trunk/core/ds485const.h 2009-09-08 15:57:11 UTC (rev 8749)
+++ dss/trunk/core/ds485const.h 2009-09-09 09:48:58 UTC (rev 8750)
@@ -96,8 +96,6 @@
const uint8_t FunctionDeviceGetDSID = 0x65;
const uint8_t FunctionDeviceGetGroups = 0x67;
- const uint8_t FunctionKeyPressed = 0x80;
-
const uint8_t FunctionModulatorGetDSID = 0x91;
const uint8_t FunctionModulatorGetPowerConsumption = 0x94;
const uint8_t FunctionModulatorGetEnergyMeterValue = 0x95;
@@ -111,11 +109,16 @@
const uint8_t FunctionDSLinkConfigWrite = 0xa0;
const uint8_t FunctionDSLinkConfigRead = 0xa1;
- const uint8_t FunctionDSLinkSend = 0xa2;
+ const uint8_t FunctionDSLinkSendDevice = 0xc2;
+ const uint8_t FunctionDSLinkSendGroup = 0xc4;
const uint8_t DSLinkSendLastByte = 0x01;
const uint8_t DSLinkSendWriteOnly = 0x02;
const uint8_t FunctionDSLinkReceive = 0xa3;
const uint8_t FunctionDSLinkInterrupt = 0x85;
+
+ const uint8_t EventNewDS485Device = 0x80;
+ const uint8_t EventLostDS485Device = 0x81;
+ const uint8_t EventDeviceReady = 0x82;
// Scene constants for devices
const uint8_t SceneOff = 0x00;
Modified: dss/trunk/core/model.cpp
===================================================================
--- dss/trunk/core/model.cpp 2009-09-08 15:57:11 UTC (rev 8749)
+++ dss/trunk/core/model.cpp 2009-09-09 09:48:58 UTC (rev 8750)
@@ -834,7 +834,41 @@
scanModulator(modulator);
}
} // initializeFromBus
+
+ void Apartment::newModulator(int _modulatorBusID) {
+ DS485Interface& interface = DSS::getInstance()->getDS485Interface();
+ log("Found modulator with id: " + intToString(_modulatorBusID));
+ dsid_t modDSID = interface.getDSIDOfModulator(_modulatorBusID);
+ log(" DSID: " + modDSID.toString());
+ Modulator& modulator = allocateModulator(modDSID);
+ modulator.setBusID(_modulatorBusID);
+ scanModulator(modulator);
+ } // newModulator
+ class SetNotPresentAction : public IDeviceAction {
+ public:
+ virtual bool perform(Device& _device) {
+ _device.setIsPresent(false);
+ return true;
+ }
+ }; // SetNotPresentAction
+
+ void Apartment::lostModulator(int _modulatorBusID) {
+ try {
+ Modulator& modulator = getModulatorByBusID(_modulatorBusID);
+ modulator.setIsPresent(false);
+ Set devices = modulator.getDevices();
+ SetNotPresentAction action;
+ devices.perform(action);
+ } catch(ItemNotFoundException& e) {
+ log(std::string("Apartment::lostModulator: ") + e.what(), lsError);
+ }
+ } // lostModulator
+
+ void Apartment::modulatorReady(int _modulatorBusID) {
+ newModulator(_modulatorBusID);
+ } // modulatorReady
+
void Apartment::handleModelEvents() {
if(!m_ModelEvents.empty()) {
ModelEvent& event = m_ModelEvents.front();
@@ -870,6 +904,27 @@
onDSLinkInterrupt(event.getParameter(0), event.getParameter(1), event.getParameter(2));
}
break;
+ case ModelEvent::etNewModulator:
+ if(event.getParameterCount() != 1) {
+ log("Expected exactly 1 parameter for ModelEvent::etNewModulator");
+ } else {
+ newModulator(event.getParameter(0));
+ }
+ break;
+ case ModelEvent::etLostModulator:
+ if(event.getParameterCount() != 1) {
+ log("Expected exactly 1 parameter for ModelEvent::etLostModulator");
+ } else {
+ lostModulator(event.getParameter(0));
+ }
+ break;
+ case ModelEvent::etModulatorReady:
+ if(event.getParameterCount() != 1) {
+ log("Expected exactly 1 parameter for ModelEvent::etModulatorReady");
+ } else {
+ modulatorReady(event.getParameter(0));
+ }
+ break;
default:
assert(false);
break;
Modified: dss/trunk/core/model.h
===================================================================
--- dss/trunk/core/model.h 2009-09-08 15:57:11 UTC (rev 8749)
+++ dss/trunk/core/model.h 2009-09-09 09:48:58 UTC (rev 8750)
@@ -724,7 +724,10 @@
etCallSceneDevice, /**< A device has changed the scene (only raised from the simulation at the moment). */
etNewDevice, /**< A new device has been detected */
etModelDirty, /**< A parameter that will be stored in \c apartment.xml has been changed. */
- etDSLinkInterrupt /**< An interrupt has occured */
+ etDSLinkInterrupt, /**< An interrupt has occured */
+ 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 */
} EventType;
private:
EventType m_EventType;
@@ -778,6 +781,9 @@
void initializeFromBus();
void scanModulator(Modulator& _modulator);
void handleModelEvents();
+ void newModulator(int _modulatorBusID);
+ void lostModulator(int _modulatorBusID);
+ void modulatorReady(int _modulatorBusID);
protected:
virtual void doStart();
public:
Modified: dss/trunk/core/sim/dssim.cpp
===================================================================
--- dss/trunk/core/sim/dssim.cpp 2009-09-08 15:57:11 UTC (rev 8749)
+++ dss/trunk/core/sim/dssim.cpp 2009-09-09 09:48:58 UTC (rev 8750)
@@ -1060,7 +1060,7 @@
distributeFrame(response);
}
break;
- case FunctionDSLinkSend:
+ case FunctionDSLinkSendDevice:
{
devid_t devID = pd.get<devid_t>();
DSIDInterface& dev = lookupDevice(devID);
Modified: dss/trunk/unix/ds485proxy.cpp
===================================================================
--- dss/trunk/unix/ds485proxy.cpp 2009-09-08 15:57:11 UTC (rev 8749)
+++ dss/trunk/unix/ds485proxy.cpp 2009-09-09 09:48:58 UTC (rev 8750)
@@ -933,7 +933,7 @@
DS485CommandFrame cmdFrame;
cmdFrame.getHeader().setDestination(_modulatorID);
cmdFrame.setCommand(CommandRequest);
- cmdFrame.getPayload().add<uint8_t>(FunctionDSLinkSend);
+ cmdFrame.getPayload().add<uint8_t>(FunctionDSLinkSendDevice);
cmdFrame.getPayload().add<uint16_t>(_devAdr);
cmdFrame.getPayload().add<uint16_t>(_value);
cmdFrame.getPayload().add<uint16_t>(_flags);
@@ -1150,21 +1150,27 @@
case FunctionGetTypeRequest:
return "Function Get Type";
- case FunctionKeyPressed:
- return "Function Key Pressed";
-
case FunctionDeviceGetFunctionID:
return "Function Device Get Function ID";
case FunctionDSLinkConfigWrite:
return "Function dSLink Config Write";
case FunctionDSLinkConfigRead:
return "Function dSLink Config Read";
- case FunctionDSLinkSend:
- return "Function dSLink Send";
+ case FunctionDSLinkSendDevice:
+ return "Function dSLink Send Device";
+ case FunctionDSLinkSendGroup:
+ return "Function dSLink Send Group";
case FunctionDSLinkReceive:
return "Function dSLink Receive";
case FunctionDSLinkInterrupt:
return "Function DSLink Interrupt";
+
+ case EventNewDS485Device:
+ return "Event New DS485 Device";
+ case EventLostDS485Device:
+ return "Event Lost DS485 Device";
+ case EventDeviceReady:
+ return "Event Device Ready";
}
return "";
} // functionIDToString
@@ -1255,6 +1261,23 @@
pEvent->addParameter(devID);
pEvent->addParameter(priority);
getDSS().getApartment().addModelEvent(pEvent);
+ } else if(functionID == EventNewDS485Device) {
+ pd.get<uint8_t>(); // functionID
+ int modID = pd.get<uint16_t>();
+ ModelEvent* pEvent = new ModelEvent(ModelEvent::etNewModulator);
+ pEvent->addParameter(modID);
+ getDSS().getApartment().addModelEvent(pEvent);
+ } else if(functionID == EventLostDS485Device) {
+ pd.get<uint8_t>(); // functionID
+ int modID = pd.get<uint16_t>();
+ ModelEvent* pEvent = new ModelEvent(ModelEvent::etLostModulator);
+ pEvent->addParameter(modID);
+ getDSS().getApartment().addModelEvent(pEvent);
+ } else if(functionID == EventDeviceReady) {
+ int modID = frame->getHeader().getDestination();
+ ModelEvent* pEvent = new ModelEvent(ModelEvent::etModulatorReady);
+ pEvent->addParameter(modID);
+ getDSS().getApartment().addModelEvent(pEvent);
}
} else {
std::ostringstream sstream;
More information about the dss-commits
mailing list