Subversion Repositories HomeAutomation

Rev

Rev 1011 | Rev 1022 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function IntelHex(hexLines)
  3. {
  4. //print("constructor of IntelHex\n");
  5.     this.myValid = false;
  6.     this.myHexLength = 0;
  7.     this.myAddrLower = 0x7FFFFFFF;
  8.     this.myAddrUpper = 0;
  9.     this.myHexData = new Array(524288);
  10.     for (var i = 0; i < 524288; i++) this.myHexData[i] = 0xFF;
  11.  
  12.     var lineDataCount = 0;
  13.     var lineAddrHigh = 0;
  14.     var lineAddr = 0;
  15.     var lineCode = 0;
  16.     var fullAddr = 0;
  17.  
  18.     for (var n = 0; n < hexLines.length; n++)
  19.     {
  20.         if (hexLines[n].length>=11 && hexLines[n].substr(0,1)==":") {
  21.             lineDataCount = hex2uint(hexLines[n].substr(1,2));
  22.             lineAddr =  hex2uint(hexLines[n].substr(3,4)) & 65535;   
  23.             lineCode = hex2uint(hexLines[n].substr(7,2));  
  24.             fullAddr = (lineAddrHigh * 65536) + lineAddr;
  25.  
  26.             switch(lineCode)
  27.             {
  28.                 case 0:
  29.                     this.myHexLength +=lineDataCount;
  30.                     if ((fullAddr + lineDataCount - 1) > this.myAddrUpper) this.myAddrUpper = fullAddr + lineDataCount - 1;
  31.                     if (lineCode == 0 && fullAddr < this.myAddrLower) this.myAddrLower = fullAddr;
  32.                     for (var j = 0; j < lineDataCount; j++) {
  33.                         this.myHexData[fullAddr] = hex2uint(hexLines[n].substr(j * 2 + 9, 2));
  34.                         //this.myHexData[fullAddr] &= 255;
  35.                         fullAddr++;
  36.                     }
  37. //print("found a record of type 0, fulladdr: "+fullAddr+"\nhexLines.length: "+hexLines.length+"\n"+hexLines[n]+"\n");
  38.                     break;
  39.                 case 4:
  40.                     lineAddrHigh = hex2uint(hexLines[n].Substring(9, 4)) & 65535;
  41.                     break;
  42.                 case 1:
  43. //print("found a record of type 1");
  44.                     this.myValid = true;
  45.                     break;
  46.                
  47.             }
  48.         }
  49.     }
  50. }
  51.  
  52. IntelHex.prototype.myHexData = null;
  53. IntelHex.prototype.myHexLength = null;
  54. IntelHex.prototype.myAddrLower = null;
  55. IntelHex.prototype.myAddrUpper = null;
  56. IntelHex.prototype.myValid = null;
  57.  
  58. IntelHex.prototype.getLength = function()
  59. {
  60.     return this.myHexLength;
  61. }
  62.  
  63. IntelHex.prototype.isValid = function()
  64. {
  65.     return this.myValid;
  66. }
  67.  
  68. IntelHex.prototype.getAddrLower = function()
  69. {
  70.     return this.myAddrLower;
  71. }
  72.  
  73. IntelHex.prototype.getByte = function(address)
  74. {
  75.     var byte = 0xff;
  76.     if (address < 524288 && this.myValid) {
  77.         byte = this.myHexData[address];
  78.     }
  79.  
  80.     return byte;
  81. }
  82.