[dss-commits] r8728 - in dss/trunk: core core/sim unix
dss-commits at forum.digitalstrom.org
dss-commits at forum.digitalstrom.org
Thu Sep 3 11:34:09 CEST 2009
Author: pstaehlin
Date: 2009-09-03 11:34:09 +0200 (Thu, 03 Sep 2009)
New Revision: 8728
Modified:
dss/trunk/core/DS485Interface.h
dss/trunk/core/model.cpp
dss/trunk/core/model.h
dss/trunk/core/sim/dssim.cpp
dss/trunk/core/webserver.cpp
dss/trunk/unix/ds485proxy.cpp
dss/trunk/unix/ds485proxy.h
Log:
New call setRawValue on device to set device parameter.
Relates to #106
Modified: dss/trunk/core/DS485Interface.h
===================================================================
--- dss/trunk/core/DS485Interface.h 2009-08-27 13:58:05 UTC (rev 8727)
+++ dss/trunk/core/DS485Interface.h 2009-09-03 09:34:09 UTC (rev 8728)
@@ -140,6 +140,8 @@
virtual std::vector<int> sendCommand(DS485Command _cmd, devid_t _id, uint8_t _modulatorID, int _param = -1) = 0;
virtual std::vector<int> sendCommand(DS485Command _cmd, const Zone& _zone, Group& _group, int _param = -1) = 0;
virtual std::vector<int> sendCommand(DS485Command _cmd, const Zone& _zone, uint8_t _groupID, int _param = -1) = 0;
+
+ virtual void setValueDevice(const Device& _device, const uint16_t _value, const uint16_t _parameterID, const int _size) = 0;
};
}
#endif /* DS485INTERFACE_H_ */
Modified: dss/trunk/core/model.cpp
===================================================================
--- dss/trunk/core/model.cpp 2009-08-27 13:58:05 UTC (rev 8727)
+++ dss/trunk/core/model.cpp 2009-09-03 09:34:09 UTC (rev 8728)
@@ -151,8 +151,16 @@
} // hasSwitch
void Device::setValue(const double _value, const int _parameterNr) {
- DSS::getInstance()->getDS485Interface().sendCommand(cmdSetValue, *this, (int)_value);
+ if(_parameterNr == -1) {
+ DSS::getInstance()->getDS485Interface().sendCommand(cmdSetValue, *this, _value);
+ } else {
+ DSS::getInstance()->getDS485Interface().setValueDevice(*this, (int)_value, _parameterNr, 1);
+ }
} // setValue
+
+ void Device::setRawValue(const uint16_t _value, const int _parameterNr, const int _size) {
+ DSS::getInstance()->getDS485Interface().setValueDevice(*this, _value, _parameterNr, _size);
+ } // setRawValue
double Device::getValue(const int _parameterNr) {
vector<int> res = DSS::getInstance()->getDS485Interface().sendCommand(cmdGetValue, *this, _parameterNr);
@@ -372,7 +380,11 @@
} // endDim
void Set::setValue(const double _value, int _parameterNr) {
- DSS::getInstance()->getDS485Interface().sendCommand(cmdSetValue, *this, (int)_value);
+ if(_parameterNr == -1) {
+ DSS::getInstance()->getDS485Interface().sendCommand(cmdSetValue, *this, (int)_value);
+ } else {
+ throw std::runtime_error("Can't set arbitrary parameter on a set");
+ }
} // setValue
void Set::callScene(const int _sceneNr) {
@@ -1657,7 +1669,11 @@
} // endDim
void Zone::setValue(const double _value, const int _parameterNr) {
- DSS::getInstance()->getDS485Interface().sendCommand(cmdSetValue, *this, GroupIDBroadcast, _parameterNr);
+ if(_parameterNr == -1) {
+ DSS::getInstance()->getDS485Interface().sendCommand(cmdSetValue, *this, GroupIDBroadcast, _value);
+ } else {
+ throw std::runtime_error("Can't set arbitrary parameter on a zone");
+ }
} // setValue
void Zone::callScene(const int _sceneNr) {
Modified: dss/trunk/core/model.h
===================================================================
--- dss/trunk/core/model.h 2009-08-27 13:58:05 UTC (rev 8727)
+++ dss/trunk/core/model.h 2009-09-03 09:34:09 UTC (rev 8728)
@@ -197,7 +197,7 @@
virtual void previousScene();
virtual unsigned long getPowerConsumption();
- };
+ }; // DeviceReference
typedef std::vector<DeviceReference> DeviceVector;
typedef DeviceVector::iterator DeviceIterator;
@@ -251,6 +251,7 @@
virtual void startDim(const bool _directionUp, const int _parameterNr = -1);
virtual void endDim(const int _parameterNr = -1);
virtual void setValue(const double _value, const int _parameterNr = -1);
+ void setRawValue(const uint16_t _value, const int _parameterNr, const int _size);
/** Returns the value of _parameterNr.
* @note not yet implemented */
double getValue(const int _parameterNr = -1);
@@ -340,7 +341,7 @@
/** Returns wheter two devices are equal.
* Devices are considered equal if their DSID are a match.*/
bool operator==(const Device& _other) const;
- };
+ }; // Device
std::ostream& operator<<(std::ostream& out, const Device& _dt);
Modified: dss/trunk/core/sim/dssim.cpp
===================================================================
--- dss/trunk/core/sim/dssim.cpp 2009-08-27 13:58:05 UTC (rev 8727)
+++ dss/trunk/core/sim/dssim.cpp 2009-09-03 09:34:09 UTC (rev 8728)
@@ -766,6 +766,19 @@
distributeFrame(response);
}
break;
+ case FunctionDeviceSetParameterValue:
+ {
+ uint16_t devID = pd.get<uint16_t>();
+ DSIDInterface& dev = lookupDevice(devID);
+ uint16_t parameterID = pd.get<uint16_t>();
+ /* uint16_t size = */ pd.get<uint16_t>();
+ uint16_t value = pd.get<uint16_t>();
+ dev.setValue(value, parameterID);
+ response = createResponse(cmdFrame, cmdNr);
+ response->getPayload().add<uint16_t>(1);
+ distributeFrame(response);
+ }
+ break;
case FunctionDeviceSetValue:
{
uint16_t devID = pd.get<uint16_t>();
@@ -795,15 +808,6 @@
distributeFrame(response);
}
break;
- case FunctionDeviceSetParameterValue:
- {
- int devID = pd.get<uint16_t>();
- int paramID = pd.get<uint16_t>();
- uint8_t value = pd.get<uint16_t>();
- lookupDevice(devID).setValue(value, paramID);
- distributeFrame(boost::shared_ptr<DS485CommandFrame>(createAck(cmdFrame, cmdNr)));
- }
- break;
case FunctionModulatorGetZonesSize:
{
response = createResponse(cmdFrame, cmdNr);
Modified: dss/trunk/core/webserver.cpp
===================================================================
--- dss/trunk/core/webserver.cpp 2009-08-27 13:58:05 UTC (rev 8727)
+++ dss/trunk/core/webserver.cpp 2009-09-03 09:34:09 UTC (rev 8728)
@@ -282,8 +282,13 @@
clsDevice.addMethod("endDim")
.withDocumentation("Stops dimming.");
clsDevice.addMethod("setValue")
+ .withParameter("value", "double", true)
+ .withDocumentation("Sets the output value of the device to value");
+ clsDevice.addMethod("setRawValue")
.withParameter("value", "integer", true)
- .withDocumentation("Sets the output value of the device to value");
+ .withParameter("parameterID", "integer", true)
+ .withParameter("size", "integer", true)
+ .withDocumentation("Sets the value of register parameterID to value");
clsDevice.addMethod("callScene")
.withParameter("sceneNr", "integer", true)
.withDocumentation("Calls scene sceneNr on the device.");
@@ -1013,6 +1018,22 @@
} else if(beginsWith(_method, "device/setName")) {
pDevice->setName(_parameter["newName"]);
return ResultToJSON(true);
+ } else if(beginsWith(_method, "device/setRawValue")) {
+ int value = strToIntDef(_parameter["value"], -1);
+ if(value == -1) {
+ return ResultToJSON(false, "Invalid or missing parameter 'value'");
+ }
+ int parameterID = strToIntDef(_parameter["parameterID"], -1);
+ if(parameterID == -1) {
+ return ResultToJSON(false, "Invalid or missing parameter 'parameterID'");
+ }
+ int size = strToIntDef(_parameter["size"], -1);
+ if(size == -1) {
+ return ResultToJSON(false, "Invalid or missing parameter 'size'");
+ }
+
+ pDevice->setRawValue(value, parameterID, size);
+ return JSONOk();
} else if(beginsWith(_method, "device/dSLinkSend")) {
int iValue = strToIntDef(_parameter["value"], -1);
if(iValue == -1) {
Modified: dss/trunk/unix/ds485proxy.cpp
===================================================================
--- dss/trunk/unix/ds485proxy.cpp 2009-08-27 13:58:05 UTC (rev 8727)
+++ dss/trunk/unix/ds485proxy.cpp 2009-09-03 09:34:09 UTC (rev 8728)
@@ -371,13 +371,13 @@
sendFrame(frame);
} else if(_cmd == cmdSetValue) {
frame.getPayload().add<uint8_t>(FunctionGroupSetValue);
- frame.getPayload().add<uint16_t>(toZone);
- frame.getPayload().add<uint16_t>(_groupID);
- frame.getPayload().add<uint16_t>(_param);
+ frame.getPayload().add<devid_t>(toZone);
+ frame.getPayload().add<devid_t>(_groupID);
+ frame.getPayload().add<devid_t>(_param);
sendFrame(frame);
}
return result;
- }
+ } // sendCommand(zone, group)
std::vector<int> DS485Proxy::sendCommand(DS485Command _cmd, const Zone& _zone, Group& _group, int _param) {
return sendCommand(_cmd, _zone, _group.getID(), _param);
@@ -415,13 +415,6 @@
frame.getPayload().add<uint16_t>(_param);
uint8_t res = receiveSingleResult(frame, FunctionDeviceGetParameterValue);
result.push_back(res);
- } else if(_cmd == cmdSetValue) {
- frame.getPayload().add<uint8_t>(FunctionDeviceSetParameterValue);
- frame.getPayload().add<uint16_t>(_id);
- frame.getPayload().add<uint16_t>(_param);
- frame.getPayload().add<uint16_t>(_param); // TODO: introduce a second parameter for the value itself
- uint8_t res = receiveSingleResult(frame, FunctionDeviceSetParameterValue);
- result.push_back(res);
} else if(_cmd == cmdGetFunctionID) {
frame.getPayload().add<uint8_t>(FunctionDeviceGetFunctionID);
frame.getPayload().add<devid_t>(_id);
@@ -464,7 +457,7 @@
sendFrame(frame);
}
return result;
- } // sendCommand
+ } // sendCommand(device)
void DS485Proxy::sendFrame(DS485CommandFrame& _frame) {
bool broadcast = _frame.getHeader().isBroadcast();
@@ -503,7 +496,20 @@
}
} // isSimAddress
-
+ void DS485Proxy::setValueDevice(const Device& _device, const uint16_t _value, const uint16_t _parameterID, const int _size) {
+ DS485CommandFrame frame;
+ frame.getHeader().setDestination(_device.getModulatorID());
+ frame.getHeader().setBroadcast(false);
+ frame.getHeader().setType(1);
+ frame.setCommand(CommandRequest);
+ frame.getPayload().add<uint8_t>(FunctionDeviceSetParameterValue);
+ frame.getPayload().add<uint16_t>(_device.getShortAddress());
+ frame.getPayload().add<uint16_t>(_parameterID);
+ frame.getPayload().add<uint16_t>(_size - 1);
+ frame.getPayload().add<uint16_t>(_value);
+ sendFrame(frame);
+ } // setValueDevice
+
ModulatorSpec_t DS485Proxy::modulatorSpecFromFrame(boost::shared_ptr<DS485CommandFrame> _frame) {
int source = _frame->getHeader().getSource();
Modified: dss/trunk/unix/ds485proxy.h
===================================================================
--- dss/trunk/unix/ds485proxy.h 2009-08-27 13:58:05 UTC (rev 8727)
+++ dss/trunk/unix/ds485proxy.h 2009-09-03 09:34:09 UTC (rev 8728)
@@ -203,6 +203,7 @@
virtual std::vector<int> sendCommand(DS485Command _cmd, const Zone& _zone, Group& _group, int _param);
virtual std::vector<int> sendCommand(DS485Command _cmd, const Zone& _zone, uint8_t _groupID, int _param = -1);
+ void setValueDevice(const Device& _device, const uint16_t _value, const uint16_t _parameterID, const int _size);
//------------------------------------------------ Helpers
DS485Controller& getController() { return m_DS485Controller; }
};
More information about the dss-commits
mailing list