Subversion Repositories HomeAutomation

Rev

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

Rev 1043 Rev 1063
Line 3... Line 3...
3
 
3
 
4
function IntelHex(hexLines)
4
function IntelHex(hexLines)
5
{
5
{
6
//print("constructor of IntelHex\n");
6
//print("constructor of IntelHex\n");
7
    this.myValid = false;
7
    this.myValid = false;
8
    this.myHexLength = 0;
-
 
9
    this.myAddrLower = 0x7FFFFFFF;
8
    this.myAddrLower = 0x7FFFFFFF;
10
    this.myAddrUpper = 0;
9
    this.myAddrUpper = 0;
11
    this.myHexData = new Array(MAX_SIZE);
10
    this.myHexData = new Array(MAX_SIZE);
12
    for (var i = 0; i < MAX_SIZE; i++) this.myHexData[i] = 0xFF;
11
    for (var i = 0; i < MAX_SIZE; i++) this.myHexData[i] = 0xFF;
13
 
12
 
Line 26... Line 25...
26
            fullAddr = (lineAddrHigh * 65536) + lineAddr;
25
            fullAddr = (lineAddrHigh * 65536) + lineAddr;
27
 
26
 
28
            switch(lineCode)
27
            switch(lineCode)
29
            {
28
            {
30
                case 0:
29
                case 0:
31
                    //this.myHexLength +=lineDataCount; //(this does now work since it does not count "holes" in hexfile)
-
 
32
                    if ((fullAddr + lineDataCount - 1) > this.myAddrUpper) this.myAddrUpper = fullAddr + lineDataCount - 1;
30
                    if ((fullAddr + lineDataCount - 1) > this.myAddrUpper) this.myAddrUpper = fullAddr + lineDataCount - 1;
33
                    if (lineCode == 0 && fullAddr < this.myAddrLower) this.myAddrLower = fullAddr;
31
                    if (lineCode == 0 && fullAddr < this.myAddrLower) this.myAddrLower = fullAddr;
34
                    for (var j = 0; j < lineDataCount; j++) {
32
                    for (var j = 0; j < lineDataCount; j++) {
35
                        this.myHexData[fullAddr] = hex2uint(hexLines[n].substr(j * 2 + 9, 2));
33
                        this.myHexData[fullAddr] = hex2uint(hexLines[n].substr(j * 2 + 9, 2));
36
                        //this.myHexData[fullAddr] &= 255;
34
                        //this.myHexData[fullAddr] &= 255;
37
                        fullAddr++;
35
                        fullAddr++;
38
                    }
36
                    }
39
//print("found a record of type 0, fulladdr: "+fullAddr+"\nhexLines.length: "+hexLines.length+"\n"+hexLines[n]+"\n");
37
//print("found a record of type 0, fulladdr: "+fullAddr+"\nhexLines.length: "+hexLines.length+"\n"+hexLines[n]+"\n");
40
                    break;
38
                    break;
41
                case 4:
39
                case 4:
42
                    lineAddrHigh = hex2uint(hexLines[n].Substring(9, 4)) & 65535;
40
                    lineAddrHigh = hex2uint(hexLines[n].substr(9, 4)) & 65535;
43
                    break;
41
                    break;
44
                case 1:
42
                case 1:
45
//print("found a record of type 1");
43
//print("found a record of type 1");
46
                    this.myValid = true;
44
                    this.myValid = true;
47
                    break;
45
                    break;
48
               
46
               
49
            }
47
            }
50
        }
48
        }
51
        this.myHexLength = this.myAddrUpper - this.myAddrLower;
-
 
52
    }
49
    }
53
}
50
}
54
 
51
 
55
IntelHex.prototype.myHexData = null;
52
IntelHex.prototype.myHexData = null;
56
IntelHex.prototype.myHexLength = null;
-
 
57
IntelHex.prototype.myAddrLower = null;
53
IntelHex.prototype.myAddrLower = null;
58
IntelHex.prototype.myAddrUpper = null;
54
IntelHex.prototype.myAddrUpper = null;
59
IntelHex.prototype.myValid = null;
55
IntelHex.prototype.myValid = null;
60
 
56
 
61
IntelHex.prototype.getCRC16 = function()
57
IntelHex.prototype.getCRC16 = function()
62
{
58
{
63
    var crc=0;
59
    var crc=0;
64
    for (var i = 0; i < this.myHexLength; i++)
60
    for (var i = this.myAddrLower; i <= this.myAddrUpper; i++)
65
    {
61
    {
66
        crc = this.crc16_update(crc, this.myHexData[i]);
62
        crc = this.crc16_update(crc, this.myHexData[i]);
67
    }
63
    }
68
    return crc&0xffff;
64
    return crc&0xffff;
69
}
65
}
Line 85... Line 81...
85
    return crc;
81
    return crc;
86
}
82
}
87
 
83
 
88
IntelHex.prototype.getLength = function()
84
IntelHex.prototype.getLength = function()
89
{
85
{
-
 
86
    if (this.myAddrUpper+1>this.myAddrLower)
-
 
87
    {
90
    return this.myHexLength;
88
        return (this.myAddrUpper - this.myAddrLower + 1);
-
 
89
    }
-
 
90
    else
-
 
91
    {
-
 
92
        return 0;
-
 
93
    }
91
}
94
}
92
 
95
 
93
IntelHex.prototype.isValid = function()
96
IntelHex.prototype.isValid = function()
94
{
97
{
95
    return this.myValid;
98
    return this.myValid;