Subversion Repositories HomeAutomation

Rev

Rev 971 | 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.             this.setOffline();
  47.         }
  48.     }
  49. }
  50.  
  51. CanService.prototype.setOffline = function()
  52. {
  53.     if (this.myIsOnline)
  54.     {
  55.         log(this.myName + ":" + this.myId + "> Service went offline\n");
  56.         this.myIsOnline = false;
  57.         this.callEvent("offline", null);
  58.     }
  59. }
  60.  
  61. CanService.prototype.isOnline = function()
  62. {
  63.     return this.myIsOnline;
  64. }
  65.  
  66. CanService.prototype.setHardwareId = function(hardwareId)
  67. {
  68.     this.myHardwareId = hardwareId;
  69. }
  70.  
  71. CanService.prototype.getHardwareId = function()
  72. {
  73.     return this.myHardwareId;
  74. }
  75.