Subversion Repositories HomeAutomation

Rev

Rev 1028 | Rev 1037 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1028 Rev 1034
Line 20... Line 20...
20
CanNode.prototype.myProgrammingHexAddress = null;
20
CanNode.prototype.myProgrammingHexAddress = null;
21
CanNode.prototype.myProgrammingOffset = null;
21
CanNode.prototype.myProgrammingOffset = null;
22
CanNode.prototype.myProgrammingCallback = null;
22
CanNode.prototype.myProgrammingCallback = null;
23
CanNode.prototype.myProgrammingWantAck = null;
23
CanNode.prototype.myProgrammingWantAck = null;
24
CanNode.prototype.myProgrammingState = null;
24
CanNode.prototype.myProgrammingState = null;
-
 
25
CanNode.prototype.myProgrammingLastPercent = null;
-
 
26
CanNode.prototype.myProgrammingLastTenPercent = null;
-
 
27
CanNode.prototype.myProgrammingnrOfTicks = null;
-
 
28
CanNode.prototype.myProgrammingTimeout = null;
-
 
29
CanNode.prototype.myProgrammingResend = null;
-
 
30
CanNode.prototype.myProgrammingLastPacket = null;
25
 
31
 
26
CanNode.prototype.isOnline = function()
32
CanNode.prototype.isOnline = function()
27
{
33
{
28
    return this.myIsOnline;
34
    return this.myIsOnline;
29
}
35
}
Line 81... Line 87...
81
    this.myProgrammingHex = hexData;
87
    this.myProgrammingHex = hexData;
82
    this.myProgrammingCallback = progressCallback;
88
    this.myProgrammingCallback = progressCallback;
83
   
89
   
84
    CanProgrammingNode = this;
90
    CanProgrammingNode = this;
85
   
91
   
-
 
92
    var self = this;
-
 
93
    this.myProgrammingTimeout = new Interval(function() { self.programmingTimeout() }, 6000);
-
 
94
    this.myProgrammingTimeout.start();
-
 
95
    this.myProgrammingState = "RESET";
-
 
96
 
-
 
97
    this.reset();
-
 
98
}
-
 
99
 
-
 
100
CanNode.prototype.programmingTimeout = function()
-
 
101
{
-
 
102
    switch (this.myProgrammingState)
-
 
103
    {
-
 
104
    case "RESET":
-
 
105
        this.stopProgramming(true, "Timeout while waiting for node to reset");
-
 
106
        this.reset();
-
 
107
        break;
-
 
108
    case "DATA":
-
 
109
        this.stopProgramming(true, "Timeout while waiting for node to ack data packet");
-
 
110
        this.reset();
-
 
111
        break;
-
 
112
    case "END":
-
 
113
        this.stopProgramming(true, "Timeout while waiting for node to ack data packet*");
-
 
114
        this.reset();
-
 
115
        break;
-
 
116
    case "CRC":
-
 
117
        this.stopProgramming(true, "Timeout while waiting for node to send crc");
86
    this.reset();
118
        this.reset();
-
 
119
        break;
-
 
120
    case "COPY":
-
 
121
        //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself
-
 
122
        break;
-
 
123
    default:
-
 
124
        break;
-
 
125
    }
87
}
126
}
-
 
127
 
-
 
128
CanNode.prototype.programmingResend = function()
-
 
129
{
-
 
130
    this.myProgrammingResend.setTimeout(200);
-
 
131
    //if we did not got ack then try to resend the data
-
 
132
    this.myProgrammingLastPacket.send();
-
 
133
}
88
 
134
 
89
CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication)
135
CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication)
90
{
136
{
91
//print("node was reset and bios just started, ver:" + biosVersion);
137
//print("node was reset and bios just started, ver:" + biosVersion);
92
    if (this.myProgramming)
138
    if (this.myProgramming)
Line 100... Line 146...
100
        canMessage.setData("Address1", (this.myProgrammingHexAddress>>8)&0xff);
146
        canMessage.setData("Address1", (this.myProgrammingHexAddress>>8)&0xff);
101
        canMessage.setData("Address3", (this.myProgrammingHexAddress>>16)&0xff);
147
        canMessage.setData("Address3", (this.myProgrammingHexAddress>>16)&0xff);
102
        canMessage.setData("Address4", (this.myProgrammingHexAddress>>24)&0xff);
148
        canMessage.setData("Address4", (this.myProgrammingHexAddress>>24)&0xff);
103
        canMessage.send();
149
        canMessage.send();
104
        this.myProgrammingState = "DATA";
150
        this.myProgrammingState = "DATA";
105
       
151
       
-
 
152
        var self = this;
-
 
153
        this.myProgrammingTimeout.setTimeout(1000);
-
 
154
       
-
 
155
        //this.myProgrammingResend = new Interval(function() { self.programmingResend() }, 1100);
-
 
156
        //this.myProgrammingResend.start();
-
 
157
 
106
        this.myProgrammingCallback(true, "START", "Started programming of node");
158
        this.myProgrammingCallback(true, "START", "Started programming of node", false);
-
 
159
        this.myProgrammingCallback(true, "", "  0% [", true);
107
    }
160
    }
108
}
161
}
109
 
162
 
110
CanNode.prototype.handleNack = function(data)
163
CanNode.prototype.handleNack = function(data)
111
{
164
{
112
    stopProgramming(true, "Failed, got NACK, sending reset");
165
    stopProgramming(true, "Failed, got NACK, sending reset");
113
    this.reset();
166
    this.reset();
114
    if (false) 
167
    if (false) 
115
    {
168
    {
116
    }
169
    }
117
}
170
}
118
 
171
 
119
CanNode.prototype.handleAck = function(data)
172
CanNode.prototype.handleAck = function(data)
120
{
173
{
121
//this.myProgrammingCallback(true, "DBG", "data: "+data+", myProgrammingWantAck: "+this.myProgrammingWantAck+"");
174
    this.myProgrammingTimeout.setTimeout(1000);
122
   
175
 
123
    if (data == this.myProgrammingWantAck) 
176
    if (data == this.myProgrammingWantAck) 
124
    {
177
    {
125
 
-
 
126
        switch (this.myProgrammingState)
178
        switch (this.myProgrammingState)
127
        {
179
        {
128
        case "DATA":
180
        case "DATA":
129
            var offset = this.myProgrammingHexOffset;
181
            var offset = this.myProgrammingHexOffset;
-
 
182
            //this.myProgrammingResend.setTimeout(100);
130
       
183
       
131
            this.myProgrammingWantAck = ((offset<<8)|(offset>>8))&0xffff;
184
            this.myProgrammingWantAck = ((offset<<8)|(offset>>8))&0xffff;
132
            //var bytesLeft = this.myProgrammingHex.getAddrUpper() - (this.myProgrammingHexAddress+this.myProgrammingHexOffset);
185
            //var bytesLeft = this.myProgrammingHex.getAddrUpper() - (this.myProgrammingHexAddress+this.myProgrammingHexOffset);
133
            var bytesLeft = this.myProgrammingHex.getLength() - this.myProgrammingHexOffset;
186
            var bytesLeft = this.myProgrammingHex.getLength() - this.myProgrammingHexOffset;
134
           
187
           
Line 148... Line 201...
148
            case 4:
201
            case 4:
149
                canMessage = new CanNMTMessage("nmt", "Pgm_Data_32");
202
                canMessage = new CanNMTMessage("nmt", "Pgm_Data_32");
150
                break;
203
                break;
151
            case 5:
204
            case 5:
152
                canMessage = new CanNMTMessage("nmt", "Pgm_Data_40");
205
                canMessage = new CanNMTMessage("nmt", "Pgm_Data_40");
153
                break;
206
                break;
154
            }
207
            }
155
           
208
           
156
            canMessage.setData("Offset0", offset&0xff);
209
            canMessage.setData("Offset0", offset&0xff);
157
            canMessage.setData("Offset1", (offset>>8)&0xff);
210
            canMessage.setData("Offset1", (offset>>8)&0xff);
158
            for (var i=0; i<bytesLeft && i<6; i++)
211
            for (var i=0; i<bytesLeft && i<6; i++)
159
            {
212
            {
Line 171... Line 224...
171
                case 3:
224
                case 3:
172
                    canMessage.setData("Data3", this.myProgrammingHex.getByte(offset));
225
                    canMessage.setData("Data3", this.myProgrammingHex.getByte(offset));
173
                    break;
226
                    break;
174
                case 4:
227
                case 4:
175
                    canMessage.setData("Data4", this.myProgrammingHex.getByte(offset));
228
                    canMessage.setData("Data4", this.myProgrammingHex.getByte(offset));
176
                    break;
229
                    break;
177
                case 5:
230
                case 5:
178
                    canMessage.setData("Data5", this.myProgrammingHex.getByte(offset));
231
                    canMessage.setData("Data5", this.myProgrammingHex.getByte(offset));
179
                    break;
232
                    break;
180
                }
233
                }
181
                offset++;
234
                offset++;
182
            }
235
            }
183
            canMessage.send();
236
            canMessage.send();
184
            this.myProgrammingHexOffset = offset;
237
            this.myProgrammingHexOffset = offset;
185
 
238
 
186
            if (this.myProgrammingHexOffset >= this.myProgrammingHex.getLength()) {
239
            if (this.myProgrammingHexOffset >= this.myProgrammingHex.getLength()) {
187
                this.myProgrammingState = "END";
240
                this.myProgrammingState = "END";
188
            }
241
            }
189
           
242
           
190
            this.myProgrammingCallback(true, "PROGRESS", this.myProgrammingHexOffset + ":" + this.myProgrammingHex.getLength());
243
            //this.myProgrammingCallback(true, "PROGRESS", this.myProgrammingHexOffset + ":" + this.myProgrammingHex.getLength(), false);
-
 
244
            var percent = 100*this.myProgrammingHexOffset / this.myProgrammingHex.getLength();
-
 
245
            if (percent >= this.myProgrammingLastPercent+2.5)
-
 
246
            {
-
 
247
                this.myProgrammingCallback(true, "", "=", true);
-
 
248
                this.myProgrammingLastPercent+=2.5;
-
 
249
                this.myProgrammingnrOfTicks++;
-
 
250
            }
-
 
251
            if (percent > this.myProgrammingLastTenPercent+10)
-
 
252
            {
-
 
253
                for (var i=this.myProgrammingnrOfTicks; i<40; i++) this.myProgrammingCallback(true, "", " ", true);
-
 
254
                this.myProgrammingCallback(true, "", "]", true);
-
 
255
                this.myProgrammingCallback(true, "", "\r", true);
-
 
256
                this.myProgrammingCallback(true, "", " "+Math.round(percent)+"% [", true);
-
 
257
                this.myProgrammingLastTenPercent+=10;
-
 
258
                for (var i=0; i<this.myProgrammingnrOfTicks; i++) this.myProgrammingCallback(true, "", "=", true);
-
 
259
            }
-
 
260
           
-
 
261
            this.myProgrammingLastPacket = canMessage;
191
            break;
262
            break;
192
       
263
       
193
        case "END":
264
        case "END":
194
            this.myProgrammingWantAck = ((this.myProgrammingHex.getCRC16()<<8)|(this.myProgrammingHex.getCRC16()>>8))&0xffff;
265
            this.myProgrammingWantAck = ((this.myProgrammingHex.getCRC16()<<8)|(this.myProgrammingHex.getCRC16()>>8))&0xffff;
195
       
266
       
196
            var canMessage = new CanNMTMessage("nmt", "Pgm_End");
267
            var canMessage = new CanNMTMessage("nmt", "Pgm_End");
197
            canMessage.send();
268
            canMessage.send();
198
 
269
 
199
            this.myProgrammingState = "CRC";
270
            this.myProgrammingState = "CRC";
-
 
271
            for (var i=this.myProgrammingnrOfTicks; i<40; i++) this.myProgrammingCallback(true, "", " ", true);
-
 
272
            this.myProgrammingCallback(true, "", "]", true);
-
 
273
            this.myProgrammingCallback(true, "", "\r", true);
-
 
274
            this.myProgrammingCallback(true, "", "100% [========================================]", true);
-
 
275
 
-
 
276
            if (this.myProgrammingResend != null)
-
 
277
            {
-
 
278
                /* Stop the interval */
-
 
279
                this.myProgrammingResend.stop();
-
 
280
            }
-
 
281
 
200
            break;
282
            break;
201
           
283
           
202
        case "CRC":
284
        case "CRC":
203
            //is this a bios programming?
285
            //is this a bios programming?
204
            if (false)
286
            if (false)
205
            {
287
            {
206
                this.myProgrammingState = "COPY";
288
                this.myProgrammingState = "COPY";
207
                this.myProgrammingCallback(true, "PROGRESS", "Start to copy bios to new location");
289
                this.myProgrammingCallback(true, "PROGRESS", "Start to copy bios to new location", false);
208
                var canMessage = new CanNMTMessage("nmt", "Pgm_Copy");
290
                var canMessage = new CanNMTMessage("nmt", "Pgm_Copy");
209
                canMessage.setData("Source0", source);
291
                canMessage.setData("Source0", source);
210
                canMessage.setData("Source1", source);
292
                canMessage.setData("Source1", source);
211
                canMessage.setData("Destination0", destination);
293
                canMessage.setData("Destination0", destination);
212
                canMessage.setData("Destination1", destination);
294
                canMessage.setData("Destination1", destination);
213
                canMessage.setData("Length0", length);
295
                canMessage.setData("Length0", length);
214
                canMessage.setData("Length1", length);
296
                canMessage.setData("Length1", length);
215
                canMessage.send();
297
                canMessage.send();
216
                this.stopProgramming();
298
                this.stopProgramming();
217
            }
299
            }
218
            else
300
            else
219
            {
301
            {
220
                this.stopProgramming(true, "Done, sucessful");
302
                this.stopProgramming(true, "Done, successful");
221
                this.reset();
303
                this.reset();
222
            }
304
            }
223
            break;
305
            break;
224
       
306
       
225
        case "COPY":    //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself
307
        case "COPY":    //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself
226
            break;
308
            break;
227
           
309
           
228
        default:
310
        default:
229
            break;
311
            break;
230
        }
312
        }
231
    }
313
    }
232
    else
314
    else
233
    {
315
    {
234
        switch (this.myProgrammingState)
316
        switch (this.myProgrammingState)
235
        {
317
        {
236
        case "DATA":
318
        case "DATA":
237
            //Fall through
319
            //Fall through
238
        case "END":
320
        case "END":
239
            ///TODO: We got something that was not correct... we should abort
321
            ///TODO: We got something that was not correct... we should abort
240
            this.stopProgramming(true, "Failed to program, ack had wrong offset, expected data: "+this.myProgrammingWantAck+" got: "+data);
322
            this.stopProgramming(true, "Failed to program, ack had wrong offset, expected data: "+this.myProgrammingWantAck+" got: "+data);
241
            this.reset();
323
            this.reset();
242
            break;
324
            break;
243
        case "CRC":
325
        case "CRC":
244
            this.stopProgramming(true, "Failed to program, CRC not matching, expected data: "+this.myProgrammingWantAck+" got: "+data);
326
            this.stopProgramming(true, "Failed to program, CRC not matching, expected data: "+this.myProgrammingWantAck+" got: "+data);
245
            this.reset();
327
            this.reset();
246
            break;
328
            break;
247
        case "COPY":    //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself
329
        case "COPY":    //this will never occur, bios does not send ack for copy command, it just moves data in flash then reset itself
248
            break;
330
            break;
249
        default:
331
        default:
250
            break;
332
            break;
251
        }
333
        }
252
    }
334
    }
253
}
335
}
254
 
336
 
255
CanNode.prototype.stopProgramming = function(status, text)
337
CanNode.prototype.stopProgramming = function(status, text)
256
{
338
{
257
    if (status && text)
339
    if (status && text)
258
    {
340
    {
259
        this.myProgrammingCallback(status, "STOP", text);
341
        this.myProgrammingCallback(status, "\nSTOP", text, false);
260
    }
342
    }
261
 
343
 
262
    this.myProgrammingIsBios = false;
344
    this.myProgrammingIsBios = false;
263
    this.myProgramming = false;
345
    this.myProgramming = false;
264
    this.myProgrammingHex = new Array();
346
    this.myProgrammingHex = new Array();
265
    this.myProgrammingHexAddress = 0;
347
    this.myProgrammingHexAddress = 0;
266
    this.myProgrammingHexOffset = 0;
348
    this.myProgrammingHexOffset = 0;
267
    this.myProgrammingCallback = function() {};
349
    this.myProgrammingCallback = function() {};
268
    this.myProgrammingWantAck = null;
350
    this.myProgrammingWantAck = null;
269
    this.myProgrammingState = "";
351
    this.myProgrammingState = "";
-
 
352
    this.myProgrammingLastPercent = 0;
-
 
353
    this.myProgrammingLastTenPercent = 0;
-
 
354
    this.myProgrammingnrOfTicks = 0;
-
 
355
 
-
 
356
    if (this.myProgrammingTimeout != null)
-
 
357
    {
-
 
358
        /* Stop the interval */
-
 
359
        this.myProgrammingTimeout.stop();
-
 
360
    }
-
 
361
    if (this.myProgrammingResend != null)
-
 
362
    {
-
 
363
        /* Stop the interval */
-
 
364
        this.myProgrammingResend.stop();
-
 
365
    }
270
   
366
 
271
    CanProgrammingNode = null;
367
    CanProgrammingNode = null;
272
}
368
}
273
 
369
 
274
 
370