Rev 1020 | Rev 1043 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1020 | Rev 1022 | ||
|---|---|---|---|
| Line 54... | Line 54... | ||
| 54 | IntelHex.prototype.myHexData = null; |
54 | IntelHex.prototype.myHexData = null; |
| 55 | IntelHex.prototype.myHexLength = null; |
55 | IntelHex.prototype.myHexLength = null; |
| 56 | IntelHex.prototype.myAddrLower = null; |
56 | IntelHex.prototype.myAddrLower = null; |
| 57 | IntelHex.prototype.myAddrUpper = null; |
57 | IntelHex.prototype.myAddrUpper = null; |
| 58 | IntelHex.prototype.myValid = null; |
58 | IntelHex.prototype.myValid = null; |
| 59 | - | ||
| 60 | /* |
- | |
| 61 | public int calcCRC(HexFile hf) { |
- | |
| 62 | int crc=0; |
- | |
| 63 | for (ulong i=hf.getAddrLower(); i <= hf.getAddrUpper(); i++) { |
- | |
| 64 | crc = crc16_update(crc, hf.getByte(i)); |
- | |
| 65 | } |
- | |
| 66 | return crc; |
- | |
| 67 | } |
- | |
| 68 | */ |
- | |
| 69 | 59 | ||
| 70 | IntelHex.prototype.getCRC16 = function() |
60 | IntelHex.prototype.getCRC16 = function() |
| 71 | { |
61 | { |
| 72 | var crc=0; |
62 | var crc=0; |
| 73 | for (var i = 0; i < this.myHexLength; i++) |
63 | for (var i = 0; i < this.myHexLength; i++) |
| 74 | { |
64 | { |
| 75 | crc = this.crc16_update(crc, this.myHexData[i]); |
65 | crc = this.crc16_update(crc, this.myHexData[i]); |
| 76 | } |
66 | } |
| 77 | return crc&0xffff; |
67 | return crc&0xffff; |
| 78 | } |
68 | } |
| 79 | 69 | ||
| 80 | IntelHex.prototype.crc16_update = function(crc, byte) |
70 | IntelHex.prototype.crc16_update = function(crc, byte) |
| 81 | { |
71 | { |
| 82 | crc ^= byte; |
72 | crc ^= byte; |
| 83 | for (var i = 0; i<8; ++i) |
73 | for (var i = 0; i<8; ++i) |
| 84 | { |
74 | { |
| 85 | if ((crc & 1) != 0) |
75 | if ((crc & 1) != 0) |
| 86 | { |
76 | { |
| 87 | crc = (crc >> 1) ^ 0xA001; |
- | |
| 88 | } |
- | |
| 89 | else |
- | |
| 90 | { |
- | |
| 91 | crc = (crc >> 1); |
- | |
| 92 | } |
- | |
| 93 | } |
- | |
| 94 | return crc; |
- | |
| 95 | } |
- | |
| 96 | - | ||
| 97 | /* |
- | |
| 98 | public int crc16_update(int crc, byte a) { |
- | |
| 99 | int i; |
- | |
| 100 | crc ^= a; |
- | |
| 101 | for (i = 0; i < 8; ++i) { |
- | |
| 102 | if ((crc & 1) != 0) |
- | |
| 103 | crc = (crc >> 1) ^ 0xA001; |
77 | crc = (crc >> 1) ^ 0xA001; |
| - | 78 | } |
|
| 104 | else |
79 | else |
| - | 80 | { |
|
| 105 | crc = (crc >> 1); |
81 | crc = (crc >> 1); |
| - | 82 | } |
|
| 106 | } |
83 | } |
| 107 | return crc; |
84 | return crc; |
| 108 | } |
85 | } |
| 109 | */ |
- | |
| 110 | 86 | ||
| 111 | IntelHex.prototype.getLength = function() |
87 | IntelHex.prototype.getLength = function() |
| 112 | { |
88 | { |
| 113 | return this.myHexLength; |
89 | return this.myHexLength; |
| 114 | } |
90 | } |