Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1.  
  2. function LM335(type, name, id)
  3. {
  4.     this.CanService(type, name, id);
  5.    
  6.     this.myLastValue = new Array();
  7. }
  8.  
  9. extend(LM335, CanService);
  10.  
  11. LM335.prototype.myReportInterval = null;
  12. LM335.prototype.myLastValue = null;
  13.  
  14. LM335.prototype.canMessageHandler = function(canMessage)
  15. {
  16.     var self = this;
  17.     if (canMessage.getDirectionFlag() == "From_Owner")
  18.     {
  19.         switch (canMessage.getCommandName())
  20.         {
  21.         case "Temperature_Celsius":
  22.         log(this.myName + ":" + this.myId + "> New value: " + canMessage.getData("Value") + "\n");
  23.         this.myLastValue[canMessage.getData("SensorId")] = canMessage.getData("Value");
  24.         //this.callEvent("newValue", canMessage.getData("SensorId"));
  25.         var dataArray = new Array();
  26.         dataArray["service"] = self;
  27.         dataArray["sensor"] = canMessage.getData("SensorId");
  28.         dataArray["value"] = canMessage.getData("Value");
  29.         dataArray["moduleName"] = canMessage.getModuleName();
  30.         dataArray["moduleId"] = canMessage.getModuleId();
  31.         this.callEvent("newValue", dataArray);
  32.         break;
  33.        
  34.         case "Sensor_Report_Interval":
  35.         log(this.myName + ":" + this.myId + "> New report interval: " + canMessage.getData("Time") + "\n");
  36.         this.myReportInterval = canMessage.getData("Time");
  37.         break;
  38.         }
  39.     }
  40.    
  41.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  42. }
  43.  
  44. LM335.prototype.getValue = function(sensorId)
  45. {
  46.     return this.myLastValue[sensorId];
  47. }
  48.  
  49. LM335.prototype.setReportInterval = function(time)
  50. {
  51.     var canMessage = new CanMessage("sns", "To_Owner", this.myName, this.myId, "Sensor_Report_Interval");
  52.     canMessage.setData("Time", time);
  53.     sendMessage(canMessage);
  54. }
  55.