Rev 974 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 974 | Rev 986 | ||
|---|---|---|---|
| Line 1... | Line -... | ||
| 1 | - | ||
| 2 | 1 | ||
| 3 | function CanService(name, id) |
2 | function CanService(name, id) |
| 4 | { |
3 | { |
| 5 | this.Service(name, id); |
4 | this.Service(name, id); |
| 6 | 5 | ||
| 7 | this.myIsOnline = false; |
- | |
| 8 | this. |
6 | this.myNode = null; |
| 9 | this.myHeartbeatTime = 0; |
- | |
| 10 | } |
7 | } |
| 11 | 8 | ||
| 12 | extend(CanService, Service); |
9 | extend(CanService, Service); |
| 13 | 10 | ||
| 14 | CanService.prototype. |
11 | CanService.prototype.myNode = null; |
| 15 | CanService.prototype.myHardwareId = null; |
- | |
| 16 | CanService.prototype.myHeartbeatTime = null; |
- | |
| 17 | 12 | ||
| 18 | CanService.prototype.canMessageHandler = function(canMessage) |
13 | CanService.prototype.canMessageHandler = function(canMessage) |
| 19 | { |
14 | { |
| 20 | } |
15 | } |
| 21 | 16 | ||
| 22 | CanService.prototype. |
17 | CanService.prototype.setOnline = function() |
| 23 | { |
18 | { |
| 24 | log(this.myName + ":" + this.myId + "> Service went online\n"); |
19 | 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); |
20 | 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 | } |
21 | } |
| 50 | 22 | ||
| 51 | CanService.prototype.setOffline = function() |
23 | CanService.prototype.setOffline = function() |
| 52 | { |
- | |
| 53 | if (this.myIsOnline) |
- | |
| 54 | { |
24 | { |
| 55 | log(this.myName + ":" + this.myId + "> Service went offline\n"); |
25 | log(this.myName + ":" + this.myId + "> Service went offline\n"); |
| 56 | this.myIsOnline = false; |
- | |
| 57 | this.callEvent("offline", null); |
26 | this.callEvent("offline", null); |
| 58 | } |
- | |
| 59 | } |
27 | } |
| 60 | 28 | ||
| 61 | CanService.prototype.isOnline = function() |
29 | CanService.prototype.isOnline = function() |
| 62 | { |
30 | { |
| - | 31 | if (this.myNode) |
|
| - | 32 | { |
|
| 63 | return |
33 | return this.myNode.isOnline(); |
| - | 34 | } |
|
| - | 35 | ||
| - | 36 | return false; |
|
| 64 | } |
37 | } |
| 65 | 38 | ||
| 66 | CanService.prototype. |
39 | CanService.prototype.setNode = function(node) |
| 67 | { |
40 | { |
| 68 | this. |
41 | this.myNode = node; |
| 69 | } |
42 | } |
| 70 | 43 | ||
| 71 | CanService.prototype. |
44 | CanService.prototype.getNode = function() |
| 72 | { |
45 | { |
| 73 | return this. |
46 | return this.myNode; |
| 74 | } |
47 | } |