Subversion Repositories HomeAutomation

Rev

Rev 1053 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

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