Rev 1014 | Rev 1022 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1014 | Rev 1020 | ||
|---|---|---|---|
| Line 3... | Line 3... | ||
| 3 | { |
3 | { |
| 4 | this.myHardwareId = hardwareId; |
4 | this.myHardwareId = hardwareId; |
| 5 | this.myNumberOfModules = numberOfModules; |
5 | this.myNumberOfModules = numberOfModules; |
| 6 | this.myModules = new Array(); |
6 | this.myModules = new Array(); |
| 7 | this.myHeartbeatTime = 0; |
7 | this.myHeartbeatTime = 0; |
| 8 | this.myProgrammingHexAddress = 0; |
- | |
| 9 | this.myIsOnline = false; |
8 | this.myIsOnline = false; |
| 10 | - | ||
| 11 | this.stopProgramming(); |
9 | this.stopProgramming(); |
| 12 | } |
10 | } |
| 13 | 11 | ||
| 14 | CanNode.prototype.myIsOnline = null; |
12 | CanNode.prototype.myIsOnline = null; |
| 15 | CanNode.prototype.myHardwareId = null; |
13 | CanNode.prototype.myHardwareId = null; |
| 16 | CanNode.prototype.myNumberOfModules = null; |
14 | CanNode.prototype.myNumberOfModules = null; |
| 17 | CanNode.prototype.myModules = null; |
15 | CanNode.prototype.myModules = null; |
| 18 | CanNode.prototype.myHeartbeatTime = null; |
16 | CanNode.prototype.myHeartbeatTime = null; |
| 19 | CanNode.prototype.myProgrammingIsBios = null; |
17 | CanNode.prototype.myProgrammingIsBios = null; |
| 20 | CanNode.prototype.myProgramming = null; |
18 | CanNode.prototype.myProgramming = null; |
| 21 | CanNode.prototype.myProgrammingHex = null; |
19 | CanNode.prototype.myProgrammingHex = null; |
| 22 | CanNode.prototype.myProgrammingHexAddress = null; |
20 | CanNode.prototype.myProgrammingHexAddress = null; |
| - | 21 | CanNode.prototype.myProgrammingOffset = null; |
|
| 23 | CanNode.prototype.myProgrammingCallback = null; |
22 | CanNode.prototype.myProgrammingCallback = null; |
| 24 | CanNode.prototype.myProgrammingWantAck = null; |
23 | CanNode.prototype.myProgrammingWantAck = null; |
| - | 24 | CanNode.prototype.myProgrammingState = null; |
|
| 25 | 25 | ||
| 26 | CanNode.prototype.isOnline = function() |
26 | CanNode.prototype.isOnline = function() |
| 27 | { |
27 | { |
| 28 | return this.myIsOnline; |
28 | return this.myIsOnline; |
| 29 | } |
29 | } |
| 30 | 30 | ||
| 31 | CanNode.prototype.start = function() |
31 | CanNode.prototype.start = function() |
| 32 | { |
32 | { |
| 33 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
33 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
| 34 | canMessage.setData("HardwareId", this.myHardwareId); |
34 | canMessage.setData("HardwareId", this.myHardwareId); |
| 35 | canMessage.send(); |
35 | canMessage.send(); |
| 36 | } |
36 | } |
| 37 | 37 | ||
| 38 | CanNode.prototype.reset = function() |
38 | CanNode.prototype.reset = function() |
| 39 | { |
39 | { |
| 40 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
40 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
| 41 | canMessage.setData("HardwareId", this.myHardwareId); |
41 | canMessage.setData("HardwareId", this.myHardwareId); |
| 42 | canMessage.send(); |
42 | canMessage.send(); |
| 43 | } |
43 | } |
| 44 | 44 | ||
| 45 | CanNode.prototype.startApplication = function() |
45 | CanNode.prototype.startApplication = function() |
| 46 | { |
46 | { |
| 47 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
47 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
| 48 | canMessage.setData("HardwareId", this.myHardwareId); |
48 | canMessage.setData("HardwareId", this.myHardwareId); |
| 49 | canMessage.send(); |
49 | canMessage.send(); |
| 50 | } |
50 | } |
| 51 | 51 | ||
| 52 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
52 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
| 53 | { |
53 | { |
| 54 | if (numberOfModules) |
54 | if (numberOfModules) |
| 55 | { |
55 | { |
| 56 | this.myNumberOfModules = numberOfModules; |
56 | this.myNumberOfModules = numberOfModules; |
| 57 | } |
57 | } |
| 58 | 58 | ||
| 59 | if (this.myNumberOfModules == null || this.myNumberOfModules > this.myModules.length) |
59 | if (this.myNumberOfModules == null || this.myNumberOfModules > this.myModules.length) |
| 60 | { |
60 | { |
| 61 | var canMessage = new CanMessage("mnmt", "To_Owner", "", 0, "List"); |
61 | var canMessage = new CanMessage("mnmt", "To_Owner", "", 0, "List"); |
| 62 | canMessage.setData("HardwareId", this.myHardwareId); |
62 | canMessage.setData("HardwareId", this.myHardwareId); |
| 63 | canMessage.send(); |
63 | canMessage.send(); |
| 64 | } |
64 | } |
| 65 | 65 | ||
| Line 88... | Line 88... | ||
| 88 | 88 | ||
| 89 | CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication) |
89 | CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication) |
| 90 | { |
90 | { |
| 91 | //print("node was reset and bios just started, ver:" + biosVersion); |
91 | //print("node was reset and bios just started, ver:" + biosVersion); |
| 92 | if (this.myProgramming) |
92 | if (this.myProgramming) |
| 93 | { |
93 | { |
| 94 |
|
94 | this.myProgrammingHexAddress = this.myProgrammingHex.getAddrLower(); |
| 95 | this.myProgrammingWantAck = |
95 | this.myProgrammingWantAck = this.myProgrammingHexAddress&0xffff; |
| 96 | 96 | ||
| 97 | var canMessage = new CanNMTMessage("nmt", "Pgm_Start"); |
97 | var canMessage = new CanNMTMessage("nmt", "Pgm_Start"); |
| 98 | canMessage.setData("HardwareId", this.myHardwareId); |
98 | canMessage.setData("HardwareId", this.myHardwareId); |
| 99 | canMessage.setData("AddressLow", |
99 | canMessage.setData("AddressLow", this.myProgrammingHexAddress&0xffff); |
| 100 | canMessage.setData("AddressHigh", ( |
100 | canMessage.setData("AddressHigh", (this.myProgrammingHexAddress>16)&0xffff); |
| 101 | canMessage.send(); |
101 | canMessage.send(); |
| - | 102 | this.myProgrammingState = "DATA"; |
|
| 102 | 103 | ||
| 103 | this.myProgrammingCallback(true, "START", "Started programming of node"); |
104 | this.myProgrammingCallback(true, "START", "Started programming of node"); |
| - | 105 | } |
|
| - | 106 | } |
|
| - | 107 | ||
| - | 108 | CanNode.prototype.handleNack = function(data) |
|
| - | 109 | { |
|
| - | 110 | stopProgramming(true, "Failed, got NACK, sending reset"); |
|
| - | 111 | this.reset(); |
|
| - | 112 | if (false) |
|
| - | 113 | { |
|
| 104 | } |
114 | } |
| 105 | } |
115 | } |
| 106 | 116 | ||
| 107 | CanNode.prototype.handleAck = function(data) |
117 | CanNode.prototype.handleAck = function(data) |
| 108 | { |
118 | { |
| 109 |
|
119 | //this.myProgrammingCallback(true, "DBG", "data: "+data+", myProgrammingWantAck: "+this.myProgrammingWantAck+""); |
| 110 | 120 | ||
| 111 |
|
121 | if (data == this.myProgrammingWantAck) |
| - | 122 | { |
|
| - | 123 | ||
| 112 |
|
124 | switch (this.myProgrammingState) |
| 113 | { |
125 | { |
| - | 126 | case "DATA": |
|
| - | 127 | var offset = this.myProgrammingHexOffset; |
|
| 114 | 128 | ||
| - | 129 | this.myProgrammingWantAck = offset; |
|
| - | 130 | //var bytesLeft = this.myProgrammingHex.getAddrUpper() - (this.myProgrammingHexAddress+this.myProgrammingHexOffset); |
|
| 115 | var |
131 | var bytesLeft = this.myProgrammingHex.getLength() - this.myProgrammingHexOffset; |
| 116 | 132 | ||
| - | 133 | this.myProgrammingCallback(true, "DBG", "bytesLeft: "+bytesLeft+", this.myProgrammingHex.getLength(): "+this.myProgrammingHex.getLength()+""); |
|
| - | 134 | //here we must handle the possibility that data is less then 48 bits |
|
| - | 135 | var canMessage = new CanNMTMessage("nmt", "Pgm_Data_48"); |
|
| 117 | switch ( |
136 | switch (bytesLeft) |
| 118 | { |
137 | { |
| - | 138 | case 1: |
|
| 119 |
|
139 | canMessage = new CanNMTMessage("nmt", "Pgm_Data_8"); |
| - | 140 | this.myProgrammingCallback(true, "DBG", "Pgm_Data_8"); |
|
| - | 141 | break; |
|
| - | 142 | case 2: |
|
| 120 |
|
143 | canMessage = new CanNMTMessage("nmt", "Pgm_Data_16"); |
| - | 144 | this.myProgrammingCallback(true, "DBG", "Pgm_Data_16"); |
|
| - | 145 | break; |
|
| - | 146 | case 3: |
|
| 121 |
|
147 | canMessage = new CanNMTMessage("nmt", "Pgm_Data_24"); |
| - | 148 | this.myProgrammingCallback(true, "DBG", "Pgm_Data_24"); |
|
| - | 149 | break; |
|
| 122 | 150 | case 4: |
|
| - | 151 | canMessage = new CanNMTMessage("nmt", "Pgm_Data_32"); |
|
| 123 |
|
152 | this.myProgrammingCallback(true, "DBG", "Pgm_Data_32"); |
| - | 153 | break; |
|
| 124 | 154 | case 5: |
|
| 125 |
|
155 | canMessage = new CanNMTMessage("nmt", "Pgm_Data_40"); |
| - | 156 | this.myProgrammingCallback(true, "DBG", "Pgm_Data_40"); |
|
| - | 157 | break; |
|
| - | 158 | } |
|
| - | 159 | ||
| 126 | canMessage.setData("Offset", offset); |
160 | canMessage.setData("Offset", offset); |
| - | 161 | for (var i=0; i<bytesLeft && i<6; i++) |
|
| - | 162 | { |
|
| - | 163 | switch (i) |
|
| - | 164 | { |
|
| - | 165 | case 0: |
|
| 127 | canMessage |
166 | canMessage.setData("Data0", this.myProgrammingHex.getByte(offset)); |
| - | 167 | this.myProgrammingCallback(true, "DBG", "Data0"); |
|
| - | 168 | break; |
|
| - | 169 | case 1: |
|
| - | 170 | canMessage.setData("Data1", this.myProgrammingHex.getByte(offset)); |
|
| - | 171 | this.myProgrammingCallback(true, "DBG", "Data1"); |
|
| - | 172 | break; |
|
| - | 173 | case 2: |
|
| - | 174 | canMessage.setData("Data2", this.myProgrammingHex.getByte(offset)); |
|
| - | 175 | this.myProgrammingCallback(true, "DBG", "Data2"); |
|
| - | 176 | break; |
|
| - | 177 | case 3: |
|
| - | 178 | canMessage.setData("Data3", this.myProgrammingHex.getByte(offset)); |
|
| - | 179 | this.myProgrammingCallback(true, "DBG", "Data3"); |
|
| - | 180 | break; |
|
| - | 181 | case 4: |
|
| - | 182 | canMessage.setData("Data4", this.myProgrammingHex.getByte(offset)); |
|
| - | 183 | this.myProgrammingCallback(true, "DBG", "Data4"); |
|
| - | 184 | break; |
|
| - | 185 | case 5: |
|
| - | 186 | canMessage.setData("Data5", this.myProgrammingHex.getByte(offset)); |
|
| - | 187 | this.myProgrammingCallback(true, "DBG", "Data5"); |
|
| - | 188 | break; |
|
| - | 189 | } |
|
| - | 190 | offset++; |
|
| - | 191 | } |
|
| 128 | canMessage.send(); |
192 | canMessage.send(); |
| - | 193 | this.myProgrammingHexOffset = offset; |
|
| 129 | 194 | ||
| 130 |
|
195 | if (this.myProgrammingHexOffset >= this.myProgrammingHex.getLength()) { |
| - | 196 | this.myProgrammingState = "END"; |
|
| 131 |
|
197 | } |
| 132 | 198 | ||
| 133 | case "END":///TODO: Maybe it is called something else, maybe a number |
- | |
| 134 | this. |
199 | this.myProgrammingCallback(true, "PROGRESS", this.myProgrammingHexOffset + ":" + this.myProgrammingHex.getLength()); |
| - | 200 | break; |
|
| 135 | 201 | ||
| 136 | var canMessage = new CanNMTMessage("nmt", "Pgm_End"); |
- | |
| 137 |
|
202 | case "END": |
| 138 | - | ||
| 139 | this. |
203 | this.myProgrammingWantAck = this.myProgrammingHex.getCRC16(); ///TODO: Fill in something here |
| 140 | break; |
- | |
| 141 | - | ||
| 142 | case "COPY":///TODO: Maybe it is called something else, maybe a number |
- | |
| 143 | var source = ""; ///TODO: Fill in something here |
- | |
| 144 | var destination = ""; ///TODO: Fill in something here |
- | |
| 145 | var length = ""; ///TODO: Fill in something here |
- | |
| 146 | 204 | ||
| - | 205 | var canMessage = new CanNMTMessage("nmt", "Pgm_End"); |
|
| - | 206 | canMessage.send(); |
|
| - | 207 | ||
| 147 | this. |
208 | this.myProgrammingState = "CRC"; |
| - | 209 | break; |
|
| 148 | 210 | ||
| - | 211 | case "CRC": |
|
| - | 212 | //is this a bios programming? |
|
| - | 213 | if (false) |
|
| - | 214 | { |
|
| - | 215 | this.myProgrammingState = "COPY"; |
|
| - | 216 | this.myProgrammingCallback(true, "PROGRESS", "Start to copy bios to new location"); |
|
| 149 | var canMessage = new CanNMTMessage("nmt", "Pgm_Copy"); |
217 | var canMessage = new CanNMTMessage("nmt", "Pgm_Copy"); |
| 150 | canMessage.setData("Source", source); |
218 | canMessage.setData("Source", source); |
| 151 | canMessage.setData("Destination", destination); |
219 | canMessage.setData("Destination", destination); |
| 152 | canMessage.setData("Length", length); |
220 | canMessage.setData("Length", length); |
| 153 | canMessage.send(); |
221 | canMessage.send(); |
| - | 222 | this.stopProgramming(); |
|
| - | 223 | } |
|
| - | 224 | else |
|
| - | 225 | { |
|
| - | 226 | this.stopProgramming(true, "Done, sucessful"); |
|
| - | 227 | this.reset(); |
|
| - | 228 | } |
|
| - | 229 | break; |
|
| - | 230 | ||
| - | 231 | case "COPY": //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself |
|
| - | 232 | var source = ""; ///TODO: Fill in something here |
|
| - | 233 | var destination = ""; ///TODO: Fill in something here |
|
| - | 234 | var length = ""; ///TODO: Fill in something here |
|
| - | 235 | ||
| - | 236 | this.myProgrammingWantAck = ""; ///TODO: Fill in something here |
|
| - | 237 | ||
| 154 | 238 | ||
| 155 | this.myProgrammingCallback(true, "END", ""); ///TODO: Fill in something meaningfull text |
239 | this.myProgrammingCallback(true, "END", ""); ///TODO: Fill in something meaningfull text |
| 156 | break; |
240 | break; |
| 157 | 241 | ||
| 158 | default: |
242 | default: |
| 159 |
|
243 | break; |
| 160 | ///TODO: But we should call this.stopProgramming(true, "All done"); we are done, maybe restart node? |
- | |
| 161 | } |
244 | } |
| 162 | } |
245 | } |
| 163 | else |
246 | else |
| 164 | { |
247 | { |
| - | 248 | switch (this.myProgrammingState) |
|
| - | 249 | { |
|
| - | 250 | case "DATA": |
|
| - | 251 | //Fall through |
|
| - | 252 | case "END": |
|
| 165 | ///TODO: We got something that was not correct... we should abort |
253 | ///TODO: We got something that was not correct... we should abort |
| - | 254 | this.stopProgramming(true, "Failed to program, ack had wrong offset, expected data: "+this.myProgrammingWantAck+" got: "+data); |
|
| - | 255 | this.reset(); |
|
| - | 256 | break; |
|
| - | 257 | case "CRC": |
|
| 166 | stopProgramming( |
258 | this.stopProgramming(true, "Failed to program, CRC not matching, expected data: "+this.myProgrammingWantAck+" got: "+data); |
| - | 259 | this.reset(); |
|
| - | 260 | break; |
|
| - | 261 | case "COPY": //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself |
|
| - | 262 | break; |
|
| - | 263 | default: |
|
| - | 264 | break; |
|
| - | 265 | } |
|
| 167 | } |
266 | } |
| 168 | } |
267 | } |
| 169 | 268 | ||
| 170 | CanNode.prototype.stopProgramming = function(status, text) |
269 | CanNode.prototype.stopProgramming = function(status, text) |
| 171 | { |
270 | { |
| Line 176... | Line 275... | ||
| 176 | 275 | ||
| 177 | this.myProgrammingIsBios = false; |
276 | this.myProgrammingIsBios = false; |
| 178 | this.myProgramming = false; |
277 | this.myProgramming = false; |
| 179 | this.myProgrammingHex = new Array(); |
278 | this.myProgrammingHex = new Array(); |
| 180 | this.myProgrammingHexAddress = 0; |
279 | this.myProgrammingHexAddress = 0; |
| - | 280 | this.myProgrammingHexOffset = 0; |
|
| 181 | this.myProgrammingCallback = function() {}; |
281 | this.myProgrammingCallback = function() {}; |
| 182 | this.myProgrammingWantAck = null; |
282 | this.myProgrammingWantAck = null; |
| - | 283 | this.myProgrammingState = ""; |
|
| 183 | 284 | ||
| 184 | CanProgrammingNode = null; |
285 | CanProgrammingNode = null; |
| 185 | } |
286 | } |
| 186 | 287 | ||
| 187 | 288 | ||