14{
15 if (line.empty()) {
16 BUException::WIB_FLASH_IHEX_ERROR e;
17 e.Append("line is empty");
18 throw e;
19 } else if (line[0] != ':') {
20 BUException::WIB_FLASH_IHEX_ERROR e;
21 e.Append("BAD Line in file - does not start with ':'");
22 throw e;
23 } else {
24 line.erase(0, 1);
25 }
27 BUException::WIB_FLASH_IHEX_ERROR e;
28 e.Append("BAD Line in file - incomplete intel hex format\n");
29 throw e;
31 BUException::WIB_FLASH_IHEX_ERROR e;
32 e.Append("BAD Line in file - intel hex format not supported, contains too many characters\n");
33 throw e;
34 } else if (line.size() & 1) {
35 BUException::WIB_FLASH_IHEX_ERROR e;
36 e.Append("BAD Line in file - uneven number of characters\n");
37 throw e;
38 } else {
39 char const* entry = line.c_str();
40 uint32_t line_sum = 0, byte_count = 0,
address = 0, record_type = 0;
41
42 uint32_t byte = 0;
43 for (uint32_t iSum = 0; iSum < line.size(); iSum += 2) {
44 sscanf(entry + iSum, "%2x", &byte);
45 line_sum += byte;
46 }
47
48
49
50 if (0xFF & line_sum) {
51 line_sum = 0xFF & line_sum;
52 BUException::WIB_FLASH_IHEX_ERROR e;
53 e.Append("BAD Line in file - content inconsistent with checksum.\n");
54 throw e;
55 } else {
56 line_sum = 0;
57 }
58
59 sscanf(entry, "%2x %4x %2x ", &byte_count, &address, &record_type);
60 if (4 == record_type) {
61 upperAddr = 0;
62 sscanf(entry + 8, "%4x", &upperAddr);
63 upperAddr = upperAddr << 16;
64 } else if (0 == record_type) {
66 if (
data.size() < (address + byte_count)) {
67 data.resize(address + byte_count, 0xFF);
68 }
69 for (uint32_t iAddr = 0; iAddr < byte_count; iAddr++) {
70 uint32_t tempData = 0;
71 sscanf(entry + (iAddr * 2) + 8, "%02x", &tempData);
73 }
74 }
75 }
76}