Rev 1040 | Rev 1043 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1040 | Rev 1042 | ||
|---|---|---|---|
| Line 46... | Line 46... | ||
| 46 | 46 | ||
| 47 | CanNode.prototype.reset = function(callback) |
47 | CanNode.prototype.reset = function(callback) |
| 48 | { |
48 | { |
| 49 | var self = this; |
49 | var self = this; |
| 50 | 50 | ||
| - | 51 | if (callback) |
|
| - | 52 | { |
|
| 51 | this.myResetCallback = callback; |
53 | this.myResetCallback = callback; |
| 52 | if (this.myResetTimer) |
54 | if (this.myResetTimer) |
| 53 | { |
55 | { |
| 54 | this.myResetTimer.stop(); |
56 | this.myResetTimer.stop(); |
| 55 | } |
57 | } |
| 56 | 58 | ||
| 57 | this.myResetTimer = new Interval( function() |
59 | this.myResetTimer = new Interval( function() |
| 58 | { |
60 | { |
| 59 | self.myResetTimer.stop(); |
61 | self.myResetTimer.stop(); |
| 60 | self.myResetTimer = null; |
62 | self.myResetTimer = null; |
| 61 | self.myResetCallback(false); |
63 | self.myResetCallback(false); |
| 62 | self.myResetCallback = null; |
64 | self.myResetCallback = null; |
| 63 | }, 5000); |
65 | }, 5000); |
| 64 | this.myResetTimer.start(); |
66 | this.myResetTimer.start(); |
| - | 67 | } |
|
| 65 | 68 | ||
| 66 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
69 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
| 67 | canMessage.setData("HardwareId", this.myHardwareId); |
70 | canMessage.setData("HardwareId", this.myHardwareId); |
| 68 | canMessage.send(); |
71 | canMessage.send(); |
| 69 | 72 | ||
| 70 | this.setOffline(); |
73 | this.setOffline(); |
| 71 | } |
74 | } |
| 72 | 75 | ||
| 73 | CanNode.prototype.startApplication = function() |
76 | CanNode.prototype.startApplication = function() |
| 74 | { |
77 | { |
| 75 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
78 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
| 76 | canMessage.setData("HardwareId", this.myHardwareId); |
79 | canMessage.setData("HardwareId", this.myHardwareId); |
| 77 | canMessage.send(); |
80 | canMessage.send(); |
| 78 | } |
81 | } |
| 79 | 82 | ||
| 80 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
83 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
| 81 | { |
84 | { |
| 82 | if (numberOfModules) |
85 | if (numberOfModules) |
| 83 | { |
86 | { |
| 84 | this.myNumberOfModules = numberOfModules; |
87 | this.myNumberOfModules = numberOfModules; |
| 85 | } |
88 | } |
| 86 | 89 | ||
| 87 | if (this.myNumberOfModules == null || this.myNumberOfModules > this.myModules.length) |
90 | if (this.myNumberOfModules == null || this.myNumberOfModules > this.myModules.length) |
| 88 | { |
91 | { |
| 89 | var canMessage = new CanMessage("mnmt", "To_Owner", "", 0, "List"); |
92 | var canMessage = new CanMessage("mnmt", "To_Owner", "", 0, "List"); |
| 90 | canMessage.setData("HardwareId", this.myHardwareId); |
93 | canMessage.setData("HardwareId", this.myHardwareId); |
| 91 | canMessage.send(); |
94 | canMessage.send(); |
| 92 | } |
95 | } |
| 93 | 96 | ||
| 94 | this.onlineHandler(); |
97 | this.onlineHandler(); |
| 95 | } |
98 | } |
| 96 | 99 | ||
| 97 | CanNode.prototype.startProgramming = function(hexData, progressCallback, isBios) |
100 | CanNode.prototype.startProgramming = function(hexData, progressCallback, isBios) |
| 98 | { |
101 | { |
| 99 | if (isBios) |
102 | if (isBios) |
| 100 | { |
103 | { |
| 101 | this.myProgrammingIsBios = isBios; |
104 | this.myProgrammingIsBios = isBios; |
| Line 106... | Line 109... | ||
| 106 | } |
109 | } |
| 107 | 110 | ||
| 108 | this.myProgramming = true; |
111 | this.myProgramming = true; |
| 109 | this.myProgrammingHex = hexData; |
112 | this.myProgrammingHex = hexData; |
| 110 | this.myProgrammingCallback = progressCallback; |
113 | this.myProgrammingCallback = progressCallback; |
| 111 | 114 | ||
| 112 | CanProgrammingNode = this; |
115 | CanProgrammingNode = this; |
| 113 | 116 | ||
| 114 | var self = this; |
117 | var self = this; |
| 115 | this.myProgrammingTimeout = new Interval(function() { self.programmingTimeout() }, 6000); |
118 | this.myProgrammingTimeout = new Interval(function() { self.programmingTimeout() }, 6000); |
| 116 | this.myProgrammingTimeout.start(); |
119 | this.myProgrammingTimeout.start(); |
| Line 146... | Line 149... | ||
| 146 | break; |
149 | break; |
| 147 | } |
150 | } |
| 148 | } |
151 | } |
| 149 | 152 | ||
| 150 | CanNode.prototype.programmingResend = function() |
153 | CanNode.prototype.programmingResend = function() |
| 151 | { |
154 | { |
| 152 | this.myProgrammingResend.setTimeout(200); |
155 | this.myProgrammingResend.setTimeout(200); |
| 153 | //if we did not got ack then try to resend the data |
156 | //if we did not got ack then try to resend the data |
| 154 | this.myProgrammingLastPacket.send(); |
157 | this.myProgrammingLastPacket.send(); |
| 155 | } |
158 | } |
| 156 | 159 | ||
| Line 186... | Line 189... | ||
| 186 | var self = this; |
189 | var self = this; |
| 187 | this.myProgrammingTimeout.setTimeout(1000); |
190 | this.myProgrammingTimeout.setTimeout(1000); |
| 188 | 191 | ||
| 189 | //this.myProgrammingResend = new Interval(function() { self.programmingResend() }, 1100); |
192 | //this.myProgrammingResend = new Interval(function() { self.programmingResend() }, 1100); |
| 190 | //this.myProgrammingResend.start(); |
193 | //this.myProgrammingResend.start(); |
| 191 | 194 | ||
| 192 | var date = new Date(); |
195 | var date = new Date(); |
| 193 | this.myProgrammingTimeStarted = date.getTime(); |
196 | this.myProgrammingTimeStarted = date.getTime(); |
| 194 | 197 | ||
| 195 | this.myProgrammingCallback(true, "START", "Started programming of node", false); |
198 | this.myProgrammingCallback(true, "START", "Started programming of node", false); |
| 196 | this.myProgrammingCallback(true, "", " 0% [", true); |
199 | this.myProgrammingCallback(true, "", " 0% [", true); |
| 197 | } |
200 | } |
| 198 | } |
201 | } |
| 199 | 202 | ||
| 200 | CanNode.prototype.handleNack = function(data) |
203 | CanNode.prototype.handleNack = function(data) |
| 201 | { |
204 | { |
| 202 | stopProgramming(true, "Failed, got NACK, sending reset"); |
205 | stopProgramming(true, "Failed, got NACK, sending reset"); |
| 203 | this.reset(); |
206 | this.reset(); |
| 204 | if (false) |
207 | if (false) |
| 205 | { |
208 | { |
| 206 | } |
209 | } |
| 207 | } |
210 | } |
| 208 | 211 | ||
| 209 | CanNode.prototype.handleAck = function(data) |
212 | CanNode.prototype.handleAck = function(data) |
| 210 | { |
213 | { |
| 211 | this.myProgrammingTimeout. |
214 | this.myProgrammingTimeout.reset(); |
| 212 | 215 | ||
| 213 | if (data == this.myProgrammingWantAck) |
216 | if (data == this.myProgrammingWantAck) |
| 214 | { |
217 | { |
| 215 | switch (this.myProgrammingState) |
218 | switch (this.myProgrammingState) |
| 216 | { |
219 | { |