Subversion Repositories HomeAutomation

Rev

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

Rev 1042 Rev 1043
Line 13... Line 13...
13
CanNode.prototype.myHardwareId = null;
13
CanNode.prototype.myHardwareId = null;
14
CanNode.prototype.myNumberOfModules = null;
14
CanNode.prototype.myNumberOfModules = null;
15
CanNode.prototype.myModules = null;
15
CanNode.prototype.myModules = null;
16
CanNode.prototype.myHeartbeatTime = null;
16
CanNode.prototype.myHeartbeatTime = null;
17
CanNode.prototype.myProgrammingIsBios = null;
17
CanNode.prototype.myProgrammingIsBios = null;
-
 
18
CanNode.prototype.myProgrammingBiosOffset = null;
18
CanNode.prototype.myProgramming = null;
19
CanNode.prototype.myProgramming = null;
19
CanNode.prototype.myProgrammingHex = null;
20
CanNode.prototype.myProgrammingHex = null;
20
CanNode.prototype.myProgrammingHexAddress = null;
21
CanNode.prototype.myProgrammingHexAddress = null;
21
CanNode.prototype.myProgrammingOffset = null;
22
CanNode.prototype.myProgrammingOffset = null;
22
CanNode.prototype.myProgrammingCallback = null;
23
CanNode.prototype.myProgrammingCallback = null;
Line 100... Line 101...
100
CanNode.prototype.startProgramming = function(hexData, progressCallback, isBios)
101
CanNode.prototype.startProgramming = function(hexData, progressCallback, isBios)
101
{
102
{
102
    if (isBios)
103
    if (isBios)
103
    {
104
    {
104
        this.myProgrammingIsBios = isBios;
105
        this.myProgrammingIsBios = isBios;
-
 
106
        this.myProgrammingBiosOffset = hexData.getAddrLower();
-
 
107
this.myProgrammingCallback(true, "", "got IsBios, address: " + this.myProgrammingBiosOffset, false);
105
    }
108
    }
106
    else
109
    else
107
    {
110
    {
108
        this.myProgrammingIsBios = false;
111
        this.myProgrammingIsBios = false;
109
    }
112
    }
Line 150... Line 153...
150
    }
153
    }
151
}
154
}
152
 
155
 
153
CanNode.prototype.programmingResend = function()
156
CanNode.prototype.programmingResend = function()
154
{
157
{
-
 
158
this.myProgrammingCallback(true, "", "Resend timeout, a packet was lost, either program data or ack", false);
155
    this.myProgrammingResend.setTimeout(200);
159
    this.myProgrammingResend.reset();
156
    //if we did not got ack then try to resend the data
160
    //if we did not got ack then try to resend the data
157
    this.myProgrammingLastPacket.send();
161
    this.myProgrammingLastPacket.send();
158
}
162
}
159
 
163
 
160
CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication)
164
CanNode.prototype.handleBiosStart = function(biosVersion, hasApplication)
Line 173... Line 177...
173
 
177
 
174
//print("node was reset and bios just started, ver:" + biosVersion);
178
//print("node was reset and bios just started, ver:" + biosVersion);
175
    if (this.myProgramming)
179
    if (this.myProgramming)
176
    {
180
    {
177
        this.myProgrammingHexAddress = this.myProgrammingHex.getAddrLower();
181
        this.myProgrammingHexAddress = this.myProgrammingHex.getAddrLower();
178
        this.myProgrammingWantAck = ((this.myProgrammingHexAddress<<8)|(this.myProgrammingHexAddress>>8))&0xffff;
182
        this.myProgrammingWantAck = (((this.myProgrammingHexAddress-this.myProgrammingBiosOffset)<<8)|((this.myProgrammingHexAddress-this.myProgrammingBiosOffset)>>8))&0xffff;
179
   
183
 
180
        var canMessage = new CanNMTMessage("nmt", "Pgm_Start");
184
        var canMessage = new CanNMTMessage("nmt", "Pgm_Start");
181
        canMessage.setData("HardwareId", this.myHardwareId);
185
        canMessage.setData("HardwareId", this.myHardwareId);
182
        canMessage.setData("Address0", this.myProgrammingHexAddress&0xff);
186
        canMessage.setData("Address0", (this.myProgrammingHexAddress-this.myProgrammingBiosOffset)&0xff);
183
        canMessage.setData("Address1", (this.myProgrammingHexAddress>>8)&0xff);
187
        canMessage.setData("Address1", ((this.myProgrammingHexAddress-this.myProgrammingBiosOffset)>>8)&0xff);
184
        canMessage.setData("Address3", (this.myProgrammingHexAddress>>16)&0xff);
188
        canMessage.setData("Address3", ((this.myProgrammingHexAddress-this.myProgrammingBiosOffset)>>16)&0xff);
185
        canMessage.setData("Address4", (this.myProgrammingHexAddress>>24)&0xff);
189
        canMessage.setData("Address4", ((this.myProgrammingHexAddress-this.myProgrammingBiosOffset)>>24)&0xff);
186
        canMessage.send();
190
        canMessage.send();
187
        this.myProgrammingState = "DATA";
191
        this.myProgrammingState = "DATA";
188
       
192
       
189
        var self = this;
193
        var self = this;
190
        this.myProgrammingTimeout.setTimeout(1000);
194
        this.myProgrammingTimeout.setTimeout(1000);
191
       
195
       
192
        //this.myProgrammingResend = new Interval(function() { self.programmingResend() }, 1100);
196
        this.myProgrammingResend = new Interval(function() { self.programmingResend() }, 1100);
193
        //this.myProgrammingResend.start();
197
        this.myProgrammingResend.start();
194
 
198
 
195
        var date = new Date();
199
        var date = new Date();
196
        this.myProgrammingTimeStarted = date.getTime();
200
        this.myProgrammingTimeStarted = date.getTime();
197
 
201
 
198
        this.myProgrammingCallback(true, "START", "Started programming of node", false);
202
        this.myProgrammingCallback(true, "START", "Started programming of node", false);
Line 200... Line 204...
200
    }
204
    }
201
}
205
}
202
 
206
 
203
CanNode.prototype.handleNack = function(data)
207
CanNode.prototype.handleNack = function(data)
204
{
208
{
205
    stopProgramming(true, "Failed, got NACK, sending reset");
209
    this.stopProgramming(true, "Failed, got NACK, sending reset");
206
    this.reset();
210
    this.reset();
207
    if (false) 
211
    if (false) 
208
    {
212
    {
209
    }
213
    }
210
}
214
}
Line 217... Line 221...
217
    {
221
    {
218
        switch (this.myProgrammingState)
222
        switch (this.myProgrammingState)
219
        {
223
        {
220
        case "DATA":
224
        case "DATA":
221
            var offset = this.myProgrammingHexOffset;
225
            var offset = this.myProgrammingHexOffset;
222
            //this.myProgrammingResend.setTimeout(100);
226
            this.myProgrammingResend.setTimeout(100);
-
 
227
            this.myProgrammingResend.reset();
223
       
228
       
224
            this.myProgrammingWantAck = ((offset<<8)|(offset>>8))&0xffff;
229
            this.myProgrammingWantAck = ((offset<<8)|(offset>>8))&0xffff;
225
            //var bytesLeft = this.myProgrammingHex.getAddrUpper() - (this.myProgrammingHexAddress+this.myProgrammingHexOffset);
-
 
226
            var bytesLeft = this.myProgrammingHex.getLength() - this.myProgrammingHexOffset;
230
            var bytesLeft = this.myProgrammingHex.getLength() - this.myProgrammingHexOffset;
227
           
231
           
228
            //here we must handle the possibility that data is less then 48 bits
232
            //here we must handle the possibility that data is less then 48 bits
229
            var canMessage = new CanNMTMessage("nmt", "Pgm_Data_48");
233
            var canMessage = new CanNMTMessage("nmt", "Pgm_Data_48");
230
            switch (bytesLeft)
234
            switch (bytesLeft)
Line 251... Line 255...
251
            for (var i=0; i<bytesLeft && i<6; i++)
255
            for (var i=0; i<bytesLeft && i<6; i++)
252
            {
256
            {
253
                switch (i)
257
                switch (i)
254
                {
258
                {
255
                case 0:
259
                case 0:
256
                    canMessage.setData("Data0", this.myProgrammingHex.getByte(offset));
260
                    canMessage.setData("Data0", this.myProgrammingHex.getByte(this.myProgrammingHexAddress+offset));
257
                    break;
261
                    break;
258
                case 1:
262
                case 1:
259
                    canMessage.setData("Data1", this.myProgrammingHex.getByte(offset));
263
                    canMessage.setData("Data1", this.myProgrammingHex.getByte(this.myProgrammingHexAddress+offset));
260
                    break;
264
                    break;
261
                case 2:
265
                case 2:
262
                    canMessage.setData("Data2", this.myProgrammingHex.getByte(offset));
266
                    canMessage.setData("Data2", this.myProgrammingHex.getByte(this.myProgrammingHexAddress+offset));
263
                    break;
267
                    break;
264
                case 3:
268
                case 3:
265
                    canMessage.setData("Data3", this.myProgrammingHex.getByte(offset));
269
                    canMessage.setData("Data3", this.myProgrammingHex.getByte(this.myProgrammingHexAddress+offset));
266
                    break;
270
                    break;
267
                case 4:
271
                case 4:
268
                    canMessage.setData("Data4", this.myProgrammingHex.getByte(offset));
272
                    canMessage.setData("Data4", this.myProgrammingHex.getByte(this.myProgrammingHexAddress+offset));
269
                    break;
273
                    break;
270
                case 5:
274
                case 5:
271
                    canMessage.setData("Data5", this.myProgrammingHex.getByte(offset));
275
                    canMessage.setData("Data5", this.myProgrammingHex.getByte(this.myProgrammingHexAddress+offset));
272
                    break;
276
                    break;
273
                }
277
                }
274
                offset++;
278
                offset++;
275
            }
279
            }
276
            canMessage.send();
280
            canMessage.send();
Line 330... Line 334...
330
 
334
 
331
            break;
335
            break;
332
           
336
           
333
        case "CRC":
337
        case "CRC":
334
            //is this a bios programming?
338
            //is this a bios programming?
335
            if (false)
339
            if (this.myProgrammingIsBios)
336
            {
340
            {
337
                this.myProgrammingState = "COPY";
341
                this.myProgrammingState = "COPY";
338
                this.myProgrammingCallback(true, "PROGRESS", "Start to copy bios to new location", false);
342
                this.myProgrammingCallback(true, "\nBIOS", "Start to copy bios to new location", false);
339
                var canMessage = new CanNMTMessage("nmt", "Pgm_Copy");
343
                var canMessage = new CanNMTMessage("nmt", "Pgm_Copy");
340
                canMessage.setData("Source0", source);
344
                canMessage.setData("Source0", 0);
341
                canMessage.setData("Source1", source);
345
                canMessage.setData("Source1", 0);
342
                canMessage.setData("Destination0", destination);
346
                canMessage.setData("Destination0", this.myProgrammingBiosOffset&0xff);
343
                canMessage.setData("Destination1", destination);
347
                canMessage.setData("Destination1", (this.myProgrammingBiosOffset>>8)&0xff);
344
                canMessage.setData("Length0", length);
348
                canMessage.setData("Length0", (this.myProgrammingHex.getLength()+1)&0xff);
345
                canMessage.setData("Length1", length);
349
                canMessage.setData("Length1", ((this.myProgrammingHex.getLength()+1)>>8)&0xff);
346
                canMessage.send();
350
                canMessage.send();
347
                this.stopProgramming();
351
                this.stopProgramming();
348
            }
352
            }
349
            else
353
            else
350
            {
354
            {
Line 400... Line 404...
400
    this.myProgrammingState = "";
404
    this.myProgrammingState = "";
401
    this.myProgrammingLastPercent = 0;
405
    this.myProgrammingLastPercent = 0;
402
    this.myProgrammingLastTenPercent = 0;
406
    this.myProgrammingLastTenPercent = 0;
403
    this.myProgrammingnrOfTicks = 0;
407
    this.myProgrammingnrOfTicks = 0;
404
    this.myProgrammingTimeStarted = 0;
408
    this.myProgrammingTimeStarted = 0;
-
 
409
    this.myProgrammingBiosOffset = 0;
405
 
410
 
406
    if (this.myProgrammingTimeout != null)
411
    if (this.myProgrammingTimeout != null)
407
    {
412
    {
408
        /* Stop the interval */
413
        /* Stop the interval */
409
        this.myProgrammingTimeout.stop();
414
        this.myProgrammingTimeout.stop();