Rev 1037 | Rev 1042 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1037 | Rev 1040 | ||
|---|---|---|---|
| Line 27... | Line 27... | ||
| 27 | CanNode.prototype.myProgrammingnrOfTicks = null; |
27 | CanNode.prototype.myProgrammingnrOfTicks = null; |
| 28 | CanNode.prototype.myProgrammingTimeout = null; |
28 | CanNode.prototype.myProgrammingTimeout = null; |
| 29 | CanNode.prototype.myProgrammingResend = null; |
29 | CanNode.prototype.myProgrammingResend = null; |
| 30 | CanNode.prototype.myProgrammingLastPacket = null; |
30 | CanNode.prototype.myProgrammingLastPacket = null; |
| 31 | CanNode.prototype.myProgrammingTimeStarted = null; |
31 | CanNode.prototype.myProgrammingTimeStarted = null; |
| - | 32 | CanNode.prototype.myResetCallback = null; |
|
| - | 33 | CanNode.prototype.myResetTimer = null; |
|
| 32 | 34 | ||
| 33 | CanNode.prototype.isOnline = function() |
35 | CanNode.prototype.isOnline = function() |
| 34 | { |
36 | { |
| 35 | return this.myIsOnline; |
37 | return this.myIsOnline; |
| 36 | } |
38 | } |
| Line 40... | Line 42... | ||
| 40 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
42 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
| 41 | canMessage.setData("HardwareId", this.myHardwareId); |
43 | canMessage.setData("HardwareId", this.myHardwareId); |
| 42 | canMessage.send(); |
44 | canMessage.send(); |
| 43 | } |
45 | } |
| 44 | 46 | ||
| 45 | CanNode.prototype.reset = function() |
47 | CanNode.prototype.reset = function(callback) |
| 46 | { |
48 | { |
| - | 49 | var self = this; |
|
| - | 50 | ||
| - | 51 | this.myResetCallback = callback; |
|
| - | 52 | if (this.myResetTimer) |
|
| - | 53 | { |
|
| - | 54 | this.myResetTimer.stop(); |
|
| - | 55 | } |
|
| - | 56 | ||
| - | 57 | this.myResetTimer = new Interval( function() |
|
| - | 58 | { |
|
| - | 59 | self.myResetTimer.stop(); |
|
| - | 60 | self.myResetTimer = null; |
|
| - | 61 | self.myResetCallback(false); |
|
| - | 62 | self.myResetCallback = null; |
|
| - | 63 | }, 5000); |
|
| - | 64 | this.myResetTimer.start(); |
|
| - | 65 | ||
| 47 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
66 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
| 48 | canMessage.setData("HardwareId", this.myHardwareId); |
67 | canMessage.setData("HardwareId", this.myHardwareId); |
| 49 | canMessage.send(); |
68 | canMessage.send(); |
| - | 69 | ||
| - | 70 | this.setOffline(); |
|
| 50 | } |
71 | } |
| 51 | 72 | ||
| 52 | CanNode.prototype.startApplication = function() |
73 | CanNode.prototype.startApplication = function() |
| 53 | { |
74 | { |
| 54 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
75 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
| 55 | canMessage.setData("HardwareId", this.myHardwareId); |
76 | canMessage.setData("HardwareId", this.myHardwareId); |
| 56 | canMessage.send(); |
77 | canMessage.send(); |
| 57 | } |
78 | } |
| 58 | 79 | ||
| 59 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
80 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
| 60 | { |
81 | { |
| 61 | if (numberOfModules) |
82 | if (numberOfModules) |
| 62 | { |
83 | { |
| 63 | this.myNumberOfModules = numberOfModules; |
84 | this.myNumberOfModules = numberOfModules; |
| Line 76... | Line 97... | ||
| 76 | CanNode.prototype.startProgramming = function(hexData, progressCallback, isBios) |
97 | CanNode.prototype.startProgramming = function(hexData, progressCallback, isBios) |
| 77 | { |
98 | { |
| 78 | if (isBios) |
99 | if (isBios) |
| 79 | { |
100 | { |
| 80 | this.myProgrammingIsBios = isBios; |
101 | this.myProgrammingIsBios = isBios; |
| 81 | } |
102 | } |
| 82 | else |
103 | else |
| 83 | { |
104 | { |
| 84 | this.myProgrammingIsBios = false; |
105 | this.myProgrammingIsBios = false; |
| 85 | } |
106 | } |
| 86 | 107 | ||
| 87 | this.myProgramming = true; |
108 | this.myProgramming = true; |
| 88 | this.myProgrammingHex = hexData; |
109 | this.myProgrammingHex = hexData; |
| 89 | this.myProgrammingCallback = progressCallback; |
110 | this.myProgrammingCallback = progressCallback; |
| 90 | 111 | ||
| 91 | CanProgrammingNode = this; |
112 | CanProgrammingNode = this; |
| 92 | 113 | ||
| 93 | var self = this; |
114 | var self = this; |
| 94 | this.myProgrammingTimeout = new Interval(function() { self.programmingTimeout() }, 6000); |
115 | this.myProgrammingTimeout = new Interval(function() { self.programmingTimeout() }, 6000); |
| 95 | this.myProgrammingTimeout.start(); |
116 | this.myProgrammingTimeout.start(); |
| 96 | this.myProgrammingState = "RESET"; |
117 | this.myProgrammingState = "RESET"; |
| 97 | 118 | ||
| Line 110... | Line 131... | ||
| 110 | this.stopProgramming(true, "Timeout while waiting for node to ack data packet"); |
131 | this.stopProgramming(true, "Timeout while waiting for node to ack data packet"); |
| 111 | this.reset(); |
132 | this.reset(); |
| 112 | break; |
133 | break; |
| 113 | case "END": |
134 | case "END": |
| 114 | this.stopProgramming(true, "Timeout while waiting for node to ack data packet*"); |
135 | this.stopProgramming(true, "Timeout while waiting for node to ack data packet*"); |
| 115 | this.reset(); |
136 | this.reset(); |
| 116 | break; |
137 | break; |
| 117 | case "CRC": |
138 | case "CRC": |
| 118 | this.stopProgramming(true, "Timeout while waiting for node to send crc"); |
139 | this.stopProgramming(true, "Timeout while waiting for node to send crc"); |
| 119 | this.reset(); |
140 | this.reset(); |
| 120 | break; |
141 | break; |
| 121 | case "COPY": |
142 | case "COPY": |
| 122 | //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself |
143 | //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself |
| 123 | break; |
144 | break; |
| 124 | default: |
145 | default: |
| 125 | break; |
146 | break; |
| 126 | } |
147 | } |
| 127 | } |
148 | } |
| 128 | 149 | ||
| 129 | CanNode.prototype.programmingResend = function() |
150 | CanNode.prototype.programmingResend = function() |
| 130 | { |
151 | { |
| 131 | this.myProgrammingResend.setTimeout(200); |
152 | this.myProgrammingResend.setTimeout(200); |
| 132 | //if we did not got ack then try to resend the data |
153 | //if we did not got ack then try to resend the data |
| 133 | this.myProgrammingLastPacket.send(); |
154 | this.myProgrammingLastPacket.send(); |
| 134 | } |
155 | } |
| 135 | 156 | ||
| 136 | CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication) |
157 | CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication) |
| 137 | { |
158 | { |
| - | 159 | if (this.myResetCallback) |
|
| - | 160 | { |
|
| - | 161 | this.myResetCallback(true); |
|
| - | 162 | this.myResetCallback = null; |
|
| - | 163 | } |
|
| - | 164 | ||
| - | 165 | if (this.myResetTimer) |
|
| - | 166 | { |
|
| - | 167 | this.myResetTimer.stop(); |
|
| - | 168 | this.myResetTimer = null; |
|
| - | 169 | } |
|
| - | 170 | ||
| 138 | //print("node was reset and bios just started, ver:" + biosVersion); |
171 | //print("node was reset and bios just started, ver:" + biosVersion); |
| 139 | if (this.myProgramming) |
172 | if (this.myProgramming) |
| 140 | { |
173 | { |
| 141 | this.myProgrammingHexAddress = this.myProgrammingHex.getAddrLower(); |
174 | this.myProgrammingHexAddress = this.myProgrammingHex.getAddrLower(); |
| 142 | this.myProgrammingWantAck = ((this.myProgrammingHexAddress<<8)|(this.myProgrammingHexAddress>>8))&0xffff; |
175 | this.myProgrammingWantAck = ((this.myProgrammingHexAddress<<8)|(this.myProgrammingHexAddress>>8))&0xffff; |