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

git version control dss-commits at forum.digitalstrom.org
Wed Dec 16 15:45:15 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  ed3e0c4c6d4c466f5255896f47f08fb17d8939bb (commit)
       via  37e32c1de912cd07d2310064da4fa298fe8ce6a9 (commit)
       via  cc00c69b5ab78feaaa6798251b1bd32d59775bed (commit)
       via  1a79cd595dc84aaed34b6e44251dbd77e99d4362 (commit)
      from  c4ff032f2aec22dac64f008110bf189f74f2fe68 (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 ed3e0c4c6d4c466f5255896f47f08fb17d8939bb
Merge: 37e32c1de912cd07d2310064da4fa298fe8ce6a9 c4ff032f2aec22dac64f008110bf189f74f2fe68
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Wed Dec 16 15:44:47 2009 +0100

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

commit 37e32c1de912cd07d2310064da4fa298fe8ce6a9
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Wed Dec 16 15:44:16 2009 +0100

    Implemented Sensorpolling
    
    Closes #249

commit cc00c69b5ab78feaaa6798251b1bd32d59775bed
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Wed Dec 16 15:43:58 2009 +0100

    deviceGetName doesn't exist anymore

commit 1a79cd595dc84aaed34b6e44251dbd77e99d4362
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Wed Dec 16 14:39:08 2009 +0100

    Print out the failed filename too

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

Changes:
diff --git a/core/DS485Interface.h b/core/DS485Interface.h
index 8de86b1..ddefdaa 100644
--- a/core/DS485Interface.h
+++ b/core/DS485Interface.h
@@ -143,6 +143,7 @@ namespace dss {
     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;
+    virtual int getSensorValue(const Device& _device, const int _sensorID) = 0;
   };
 
   class DS485ApiError : public DSSException {
diff --git a/core/ds485const.h b/core/ds485const.h
index 2733fd4..9b50bf8 100644
--- a/core/ds485const.h
+++ b/core/ds485const.h
@@ -97,8 +97,8 @@ namespace dss {
   const uint8_t FunctionDeviceGetDSID = 0x65;
   const uint8_t FunctionDeviceGetFunctionID = 0x66;
   const uint8_t FunctionDeviceGetGroups = 0x67;
-  const uint8_t FunctionDeviceGetName = 0x68;
-  const uint8_t FunctionDeviceGetVersion = 0x69;
+  const uint8_t FunctionDeviceGetVersion = 0x68;
+  const uint8_t FunctionDeviceGetSensorValue = 0x69;
   
   const uint8_t FunctionGetTypeRequest = 0x90;
   const uint8_t FunctionModulatorGetDSID = 0x91;
diff --git a/core/metering/seriespersistence.cpp b/core/metering/seriespersistence.cpp
index 0495616..1728de2 100644
--- a/core/metering/seriespersistence.cpp
+++ b/core/metering/seriespersistence.cpp
@@ -234,7 +234,7 @@ namespace dss {
       std::cout << "renaming: " << Timestamp().getDifference(renaming) << std::endl;
 #endif
     } else {
-      Logger::getInstance()->log("Could not open file for writing");
+      Logger::getInstance()->log("Could not open file '" + tmpOut + "' for writing", lsFatal);
     }
 
     return true;
diff --git a/core/model.cpp b/core/model.cpp
index a790b2c..4f3f442 100644
--- a/core/model.cpp
+++ b/core/model.cpp
@@ -336,6 +336,9 @@ namespace dss {
     return DSS::getInstance()->getDS485Interface().dSLinkSend(m_ModulatorID, m_ShortAddress, _value, flags);
   } // dsLinkSend
 
+  int Device::getSensorValue(const int _sensorID) {
+    return DSS::getInstance()->getDS485Interface().getSensorValue(*this,_sensorID);
+  } // getSensorValue
 
   //================================================== Set
 
diff --git a/core/model.h b/core/model.h
index 9d2f26c..f99f783 100644
--- a/core/model.h
+++ b/core/model.h
@@ -342,6 +342,7 @@ namespace dss {
     /** Sends a byte to the device using dsLink. If \a _writeOnly is \c true,
      * the result of the function is not defined. */
     uint8_t dsLinkSend(uint8_t _value, bool _lastByte, bool _writeOnly);
+    int getSensorValue(const int _sensorID);
 
     const PropertyNodePtr& getPropertyNode() const { return m_pPropertyNode; }
     PropertyNodePtr getPropertyNode() { return m_pPropertyNode; }
diff --git a/core/scripting/modeljs.cpp b/core/scripting/modeljs.cpp
index 85a8f76..f18fefe 100644
--- a/core/scripting/modeljs.cpp
+++ b/core/scripting/modeljs.cpp
@@ -27,6 +27,7 @@
 #include "core/dss.h"
 #include "core/logger.h"
 #include "core/propertysystem.h"
+#include "core/DS485Interface.h"
 
 namespace dss {
   const std::string ModelScriptcontextExtensionName = "modelextension";
@@ -611,6 +612,26 @@ namespace dss {
     return JS_FALSE;
   } // dev_dslink_send
 
+  JSBool dev_get_sensor_value(JSContext* cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
+    ScriptContext* ctx = static_cast<ScriptContext*>(JS_GetContextPrivate(cx));
+
+    ScriptObject self(obj, *ctx);
+    if(self.is("device")) {
+      DeviceReference* intf = static_cast<DeviceReference*>(JS_GetPrivate(cx, obj));
+      if(argc == 1) {
+        try {
+          int sensorValue = ctx->convertTo<int>(argv[0]);
+          int retValue= (intf->getDevice().getSensorValue(sensorValue));
+          *rval = INT_TO_JSVAL(retValue);
+        } catch(const DS485ApiError&) {
+          *rval = JSVAL_NULL;
+        }
+        return JS_TRUE;
+      }
+    }
+    return JS_FALSE;
+  } // dev_get_last_called_scene
+
   class JSDeviceAction : public IDeviceAction {
   private:
     jsval m_Function;
@@ -663,6 +684,7 @@ namespace dss {
     {"saveScene", dev_save_scene, 1, 0, 0},
     {"undoScene", dev_undo_scene, 1, 0, 0},
     {"dSLinkSend", dev_dslink_send, 3, 0, 0},
+    {"getSensorValue", dev_get_sensor_value, 1, 0, 0},
     {NULL, NULL, 0, 0, 0}
   };
 
diff --git a/core/sim/dssim.cpp b/core/sim/dssim.cpp
index 89a3860..de4a8c2 100644
--- a/core/sim/dssim.cpp
+++ b/core/sim/dssim.cpp
@@ -666,14 +666,6 @@ namespace dss {
                 distributeFrame(response);
               }
               break;
-            case FunctionDeviceGetName:
-              {
-                devid_t devID = pd.get<devid_t>();
-                std::string name = m_DeviceNames[devID];
-                response = createResponse(cmdFrame, cmdNr);
-
-              }
-              break;
             case FunctionDeviceGetParameterValue:
               {
                 int devID = pd.get<uint16_t>();
diff --git a/unix/ds485proxy.cpp b/unix/ds485proxy.cpp
index cdbf73e..c05e15e 100644
--- a/unix/ds485proxy.cpp
+++ b/unix/ds485proxy.cpp
@@ -1018,6 +1018,56 @@ namespace dss {
     return true;
   } // getEnergyBorder
 
+  int DS485Proxy::getSensorValue(const Device& _device, const int _sensorID) {
+    DS485CommandFrame cmdFrame;
+    cmdFrame.getHeader().setDestination(_device.getModulatorID());
+    cmdFrame.getHeader().setBroadcast(false);
+    cmdFrame.getHeader().setType(1);
+    cmdFrame.setCommand(CommandRequest);
+    cmdFrame.getPayload().add<uint8_t>(FunctionDeviceGetSensorValue);
+    cmdFrame.getPayload().add<uint16_t>(_device.getShortAddress());
+    cmdFrame.getPayload().add<uint16_t>(_sensorID);
+    log("GetSensorValue");
+
+    boost::shared_ptr<FrameBucketCollector> bucket = sendFrameAndInstallBucket(cmdFrame, FunctionDeviceGetSensorValue);
+    bucket->waitForFrame(2000);
+    boost::shared_ptr<ReceivedFrame> recFrame;
+    if(bucket->isEmpty()) {
+      log(string("received no ack for request getSensorValue"));
+      throw DS485ApiError("no Ack for sensorValue");
+    } else if(bucket->getFrameCount() == 1) {
+        // first frame received, wait for the next frame
+      recFrame= bucket->popFrame();
+      bucket->waitForFrame(2000);
+    } else
+        recFrame= bucket->popFrame();
+    // first frame is only request ack;
+
+    PayloadDissector pd(recFrame->getFrame()->getPayload());
+    pd.get<uint8_t>(); // discard functionID
+    checkResultCode((int)pd.get<uint16_t>()); // check first ack
+
+    if(bucket->isEmpty()) {
+        // no next frame after additional waiting.
+        throw DS485ApiError("no Answer for sensorValue");
+    }
+
+    recFrame = bucket->popFrame();
+
+    if(recFrame.get() != NULL) {
+        PayloadDissector pd(recFrame->getFrame()->getPayload());
+        pd.get<uint8_t>(); // discard functionID
+        pd.get<uint16_t>();
+        pd.get<uint16_t>();
+        checkResultCode((int)pd.get<uint16_t>()); // check sensorvalue
+        int result = int(pd.get<uint16_t>());
+        log(string("result ") + intToString(result));
+        return result;
+    } else {
+      throw std::runtime_error("received frame is NULL but bucket->isEmpty() returns false");
+    }
+  } // getSensorValue
+
   uint8_t DS485Proxy::dSLinkSend(const int _modulatorID, devid_t _devAdr, uint8_t _value, uint8_t _flags) {
     DS485CommandFrame cmdFrame;
     cmdFrame.getHeader().setDestination(_modulatorID);
@@ -1241,6 +1291,8 @@ namespace dss {
       return "Function Device Get DSID";
     case FunctionDeviceGetGroups:
       return "Function Device Get Groups";
+    case FunctionDeviceGetSensorValue:
+      return "Function Device Get Sensor Value";
 
     case FunctionModulatorGetDSID:
       return "Function Modulator Get DSID";
diff --git a/unix/ds485proxy.h b/unix/ds485proxy.h
index b7066bd..f4b036d 100644
--- a/unix/ds485proxy.h
+++ b/unix/ds485proxy.h
@@ -232,6 +232,7 @@ namespace dss {
     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);
+    virtual int getSensorValue(const Device& _device, const int _sensorID);
     //------------------------------------------------ Helpers
     DS485Controller& getController() { return m_DS485Controller; }
   }; // DS485Proxy


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list