Subversion Repositories HomeAutomation

Rev

Rev 969 | Rev 986 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2.  
  3. function CanService(name, id)
  4. {
  5.     this.Service(name, id);
  6.  
  7.     this.myIsOnline = false;
  8.     this.myHardwareId = null;
  9.     this.myHeartbeatTime = 0;
  10. }
  11.  
  12. extend(CanService, Service);
  13.  
  14. CanService.prototype.myIsOnline = null;
  15. CanService.prototype.myHardwareId = null;
  16. CanService.prototype.myHeartbeatTime = null;
  17.  
  18. CanService.prototype.canMessageHandler = function(canMessage)
  19. {
  20. }
  21.  
  22. CanService.prototype.onlineHandler = function()
  23. {
  24.     log(this.myName + ":" + this.myId + "> Service went online\n");
  25.     var date = new Date();
  26.     this.myHeartbeatTime = date.getTimestamp();
  27.     this.myIsOnline = true;
  28.     this.callEvent("online", null);
  29. }
  30.  
  31. CanService.prototype.heartbeatHandler = function()
  32. {
  33.     var date = new Date();
  34.     this.myHeartbeatTime = date.getTimestamp();
  35.     this.myIsOnline = true;
  36.     this.callEvent("heartbeat", null);
  37. }
  38.  
  39. CanService.prototype.checkOffline = function()
  40. {
  41.     if (this.myIsOnline)
  42.     {
  43.         var date = new Date();
  44.         if (this.myHeartbeatTime + 10 < date.getTimestamp())
  45.         {
  46.             log(this.myName + ":" + this.myId + "> Service went offline\n");
  47.             this.myIsOnline = false;
  48.             this.callEvent("offline", null);
  49.         }
  50.     }
  51. }
  52.  
  53. CanService.prototype.isOnline = function()
  54. {
  55.     return this.myIsOnline;
  56. }
  57.  
  58. CanService.prototype.setHardwareId = function(hardwareId)
  59. {
  60.     this.myHardwareId = hardwareId;
  61. }
  62.  
  63. CanService.prototype.getHardwareId = function()
  64. {
  65.     return this.myHardwareId;
  66. }
  67.