more cleanup

pull/3/head
cTn 11 years ago
parent 2773919538
commit cc13ab5760

@ -28,27 +28,25 @@ function read_hex_file(data) {
switch (record_type) { switch (record_type) {
case 0x00: // data record case 0x00: // data record
if (byte_count > 0) { var crc = byte_count + parseInt(address.substr(0, 2), 16) + parseInt(address.substr(2, 2), 16) + record_type;
var crc = byte_count + parseInt(address.substr(0, 2), 16) + parseInt(address.substr(2, 2), 16) + record_type; for (var needle = 0; needle < byte_count * 2; needle += 2) {
for (var needle = 0; needle < byte_count * 2; needle += 2) { var num = parseInt(content.substr(needle, 2), 16); // get one byte in hex and convert it to decimal
var num = parseInt(content.substr(needle, 2), 16); // get one byte in hex and convert it to decimal result.data.push(num);
result.data.push(num);
crc += num;
result.bytes++;
}
// change crc to 2's complement (same as checksum) crc += num;
crc = ~crc + 1; result.bytes++;
crc &= 0xFF; }
// change crc to 2's complement (same as checksum)
crc = ~crc + 1;
crc &= 0xFF;
// verify
if (crc != checksum) {
hexfile_valid = false;
// verify // break out of the for loop as crc is wrong anyway, we dont need to process any more data
if (crc != checksum) { i = data.length;
hexfile_valid = false;
// break out of the for loop as crc is wrong anyway, we dont need to process any more data
i = data.length;
}
} }
break; break;
case 0x01: // end of file record case 0x01: // end of file record

Loading…
Cancel
Save