Rev 986 | Rev 1013 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 986 | Rev 1008 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 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.myIsOnline = false; |
8 | this.myIsOnline = false; |
| - | 9 | ||
| - | 10 | this.stopProgramming(); |
|
| 9 | } |
11 | } |
| 10 | 12 | ||
| 11 | CanNode.prototype.myIsOnline = null; |
13 | CanNode.prototype.myIsOnline = null; |
| 12 | CanNode.prototype.myHardwareId = null; |
14 | CanNode.prototype.myHardwareId = null; |
| 13 | CanNode.prototype.myNumberOfModules = null; |
15 | CanNode.prototype.myNumberOfModules = null; |
| 14 | CanNode.prototype.myModules = null; |
16 | CanNode.prototype.myModules = null; |
| 15 | CanNode.prototype.myHeartbeatTime = null; |
17 | CanNode.prototype.myHeartbeatTime = null; |
| - | 18 | CanNode.prototype.myProgrammingIsBios = null; |
|
| - | 19 | CanNode.prototype.myProgramming = null; |
|
| - | 20 | CanNode.prototype.myProgrammingHex = null; |
|
| - | 21 | CanNode.prototype.myProgrammingHexIndex = null; |
|
| - | 22 | CanNode.prototype.myProgrammingCallback = null; |
|
| - | 23 | CanNode.prototype.myProgrammingWantAck = null; |
|
| 16 | 24 | ||
| 17 | CanNode.prototype.isOnline = function() |
25 | CanNode.prototype.isOnline = function() |
| 18 | { |
26 | { |
| 19 | return this.myIsOnline; |
27 | return this.myIsOnline; |
| - | 28 | } |
|
| - | 29 | ||
| - | 30 | CanNode.prototype.start = function() |
|
| - | 31 | { |
|
| - | 32 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
|
| - | 33 | canMessage.setData("HardwareId", this.myHardwareId); |
|
| - | 34 | canMessage.send(); |
|
| 20 | } |
35 | } |
| 21 | 36 | ||
| 22 | CanNode.prototype.reset = function() |
37 | CanNode.prototype.reset = function() |
| 23 | { |
38 | { |
| 24 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
39 | var canMessage = new CanNMTMessage("nmt", "Reset"); |
| 25 | canMessage.setData("HardwareId", this.myHardwareId); |
40 | canMessage.setData("HardwareId", this.myHardwareId); |
| 26 |
|
41 | canMessage.send(); |
| 27 | } |
42 | } |
| 28 | 43 | ||
| 29 | CanNode.prototype.startApplication = function() |
44 | CanNode.prototype.startApplication = function() |
| 30 | { |
45 | { |
| 31 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
46 | var canMessage = new CanNMTMessage("nmt", "Start_App"); |
| 32 | canMessage.setData("HardwareId", this.myHardwareId); |
47 | canMessage.setData("HardwareId", this.myHardwareId); |
| 33 |
|
48 | canMessage.send(); |
| 34 | } |
49 | } |
| 35 | 50 | ||
| 36 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
51 | CanNode.prototype.handleHeartbeat = function(numberOfModules) |
| 37 | { |
52 | { |
| - | 53 | if (numberOfModules) |
|
| - | 54 | { |
|
| 38 | this.myNumberOfModules = numberOfModules; |
55 | this.myNumberOfModules = numberOfModules; |
| - | 56 | } |
|
| 39 | 57 | ||
| 40 | if (this.myNumberOfModules > this.myModules.length) |
58 | if (this.myNumberOfModules == null || this.myNumberOfModules > this.myModules.length) |
| 41 | { |
59 | { |
| 42 | var canMessage = new CanMessage("mnmt", "To_Owner", "", 0, "List"); |
60 | var canMessage = new CanMessage("mnmt", "To_Owner", "", 0, "List"); |
| 43 | canMessage.setData("HardwareId", this.myHardwareId); |
61 | canMessage.setData("HardwareId", this.myHardwareId); |
| 44 |
|
62 | canMessage.send(); |
| - | 63 | } |
|
| - | 64 | ||
| - | 65 | this.onlineHandler(); |
|
| - | 66 | } |
|
| - | 67 | ||
| - | 68 | CanNode.prototype.startProgramming = function(hexData, progressCallback, isBios) |
|
| - | 69 | { |
|
| - | 70 | if (isBios) |
|
| - | 71 | { |
|
| - | 72 | this.myProgrammingIsBios = bios; |
|
| - | 73 | } |
|
| - | 74 | else |
|
| - | 75 | { |
|
| - | 76 | this.myProgrammingIsBios = false; |
|
| - | 77 | } |
|
| - | 78 | ||
| - | 79 | this.myProgramming = true; |
|
| - | 80 | this.myProgrammingHex = hexData; |
|
| - | 81 | this.myProgrammingCallback = progressCallback; |
|
| - | 82 | ||
| - | 83 | this.reset(); |
|
| - | 84 | } |
|
| - | 85 | ||
| - | 86 | CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication) |
|
| - | 87 | { |
|
| - | 88 | if (this.myProgramming) |
|
| - | 89 | { |
|
| - | 90 | var hexLine = this.myProgrammingHex[this.myProgrammingHexIndex]; |
|
| - | 91 | this.myProgrammingHexIndex++; |
|
| - | 92 | ||
| - | 93 | var address = ""; ///TODO: Fill in something here |
|
| - | 94 | ||
| - | 95 | this.myProgrammingWantAck = ""; ///TODO: Fill in the 16 lower bits of address |
|
| - | 96 | ||
| - | 97 | var canMessage = new CanNMTMessage("nmt", "Pgm_Start"); |
|
| - | 98 | canMessage.setData("HardwareId", this.myHardwareId); |
|
| - | 99 | canMessage.setData("Address", address); |
|
| - | 100 | canMessage.send(); |
|
| - | 101 | ||
| - | 102 | this.myProgrammingCallback(true, "START", "Started programming of node"); |
|
| - | 103 | } |
|
| - | 104 | } |
|
| - | 105 | ||
| - | 106 | CanNode.prototype.handleAck = function(data) |
|
| - | 107 | { |
|
| - | 108 | if (data == this.myProgrammingWantAck) |
|
| - | 109 | { |
|
| - | 110 | var hexLine = this.myProgrammingHex[this.myProgrammingHexIndex]; |
|
| - | 111 | this.myProgrammingHexIndex++; |
|
| - | 112 | ||
| - | 113 | var type = ""; ///TODO: Fill in which type of data we have |
|
| - | 114 | ||
| - | 115 | switch (type) |
|
| - | 116 | { |
|
| - | 117 | case "DATA":///TODO: Maybe it is called something else, maybe a number |
|
| - | 118 | var offset = ""; ///TODO: Fill in something here |
|
| - | 119 | var data = ""; ///TODO: Fill in something here |
|
| - | 120 | ||
| - | 121 | this.myProgrammingWantAck = ""; ///TODO: Fill in something here |
|
| - | 122 | ||
| - | 123 | var canMessage = new CanNMTMessage("nmt", "Pgm_Data"); |
|
| - | 124 | canMessage.setData("Offset", offset); |
|
| - | 125 | canMessage.setData("Data", data); |
|
| - | 126 | canMessage.send(); |
|
| - | 127 | ||
| - | 128 | this.myProgrammingCallback(true, "PROGRESS", this.myProgrammingHexIndex + ":" + this.myProgrammingHex.length); |
|
| - | 129 | break; |
|
| - | 130 | ||
| - | 131 | case "END":///TODO: Maybe it is called something else, maybe a number |
|
| - | 132 | this.myProgrammingWantAck = ""; ///TODO: Fill in something here |
|
| - | 133 | ||
| - | 134 | var canMessage = new CanNMTMessage("nmt", "Pgm_End"); |
|
| - | 135 | canMessage.send(); |
|
| - | 136 | ||
| - | 137 | this.myProgrammingCallback(true, "END", ""); ///TODO: Fill in something meaningfull text |
|
| - | 138 | break; |
|
| - | 139 | ||
| - | 140 | case "COPY":///TODO: Maybe it is called something else, maybe a number |
|
| - | 141 | var source = ""; ///TODO: Fill in something here |
|
| - | 142 | var destination = ""; ///TODO: Fill in something here |
|
| - | 143 | var length = ""; ///TODO: Fill in something here |
|
| - | 144 | ||
| - | 145 | this.myProgrammingWantAck = ""; ///TODO: Fill in something here |
|
| - | 146 | ||
| - | 147 | var canMessage = new CanNMTMessage("nmt", "Pgm_Copy"); |
|
| - | 148 | canMessage.setData("Source", source); |
|
| - | 149 | canMessage.setData("Destination", destination); |
|
| - | 150 | canMessage.setData("Length", length); |
|
| - | 151 | canMessage.send(); |
|
| - | 152 | ||
| - | 153 | this.myProgrammingCallback(true, "END", ""); ///TODO: Fill in something meaningfull text |
|
| - | 154 | break; |
|
| - | 155 | ||
| - | 156 | default: |
|
| - | 157 | ///TODO: Are we done here? I have no idea :) |
|
| - | 158 | ///TODO: But we should call this.stopProgramming(true, "All done"); we are done, maybe restart node? |
|
| - | 159 | } |
|
| - | 160 | } |
|
| - | 161 | else |
|
| - | 162 | { |
|
| - | 163 | ///TODO: We got something that was not correct... we should abort |
|
| - | 164 | stopProgramming(false, ""); ///TODO: Fill in some kind of error text |
|
| - | 165 | } |
|
| - | 166 | } |
|
| - | 167 | ||
| - | 168 | CanNode.prototype.stopProgramming = function(status, text) |
|
| - | 169 | { |
|
| - | 170 | if (status && text) |
|
| - | 171 | { |
|
| - | 172 | this.myProgrammingCallback(status, "STOP", text); |
|
| - | 173 | } |
|
| - | 174 | ||
| - | 175 | this.myProgrammingIsBios = false; |
|
| - | 176 | this.myProgramming = false; |
|
| - | 177 | this.myProgrammingHex = new Array(); |
|
| - | 178 | this.myProgrammingHexIndex = 0; |
|
| - | 179 | this.myProgrammingCallback = function() {}; |
|
| - | 180 | this.myProgrammingWantAck = null; |
|
| 45 | } |
181 | } |
| 46 | 182 | ||
| 47 | this.onlineHandler(); |
- | |
| 48 | } |
183 | |
| 49 | 184 | ||
| 50 | CanNode.prototype.addService = function(sequenceNumber, service) |
185 | CanNode.prototype.addService = function(sequenceNumber, service) |
| 51 | { |
186 | { |
| 52 | this.myModules[sequenceNumber] = service; |
187 | this.myModules[sequenceNumber] = service; |
| 53 | service.setOnline(); |
188 | service.setOnline(); |