1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-21 15:25:36 +03:00

more cleanup

This commit is contained in:
cTn 2013-11-16 20:33:58 +01:00
parent 2773919538
commit cc13ab5760

View file

@ -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; crc += num;
result.bytes++; result.bytes++;
} }
// change crc to 2's complement (same as checksum) // change crc to 2's complement (same as checksum)
crc = ~crc + 1; crc = ~crc + 1;
crc &= 0xFF; crc &= 0xFF;
// verify // verify
if (crc != checksum) { if (crc != checksum) {
hexfile_valid = false; hexfile_valid = false;
// break out of the for loop as crc is wrong anyway, we dont need to process any more data // break out of the for loop as crc is wrong anyway, we dont need to process any more data
i = data.length; i = data.length;
}
} }
break; break;
case 0x01: // end of file record case 0x01: // end of file record