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