/
Instructables_HEX_File_to_Array_5.c
48 lines (36 loc) · 1.28 KB
/
Instructables_HEX_File_to_Array_5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
DATA.C
bool read_line_from_hex_file(FILE * file, uint8_t line_of_data[], long int * combined_address, int * bytes_this_line)
{
int data_index = 0;
uint8_t char_to_put;
int total_chars_read = 0;
//To hold file hex values.
uint8_t byte_count;
uint8_t datum_address1;
uint8_t datum_address2;
uint8_t datum_record_type;
uint8_t datum_check_sum;
//BYTE COUNT
byte_count = read_byte_from_file(file, &char_to_put, &total_chars_read);
// No need to read, if no data.
if (byte_count == 0){return false;}
//ADDRESS1 //Will create an 8 bit shift. --Bdk6's
datum_address1 = read_byte_from_file(file, &char_to_put, &total_chars_read);
//ADDRESS2
datum_address2 = read_byte_from_file(file, &char_to_put, &total_chars_read);
//RECORD TYPE
datum_record_type = read_byte_from_file(file, &char_to_put, &total_chars_read);
// No need to read, if not data.
if (datum_record_type != 0){return false;}
*combined_address = ((uint16_t)datum_address1 << 8) | datum_address2;
// DATA
while(data_index < byte_count)
{
line_of_data[data_index] = read_byte_from_file(file, &char_to_put, &total_chars_read);
data_index++;
}
*bytes_this_line = data_index;
// CHECKSUM
datum_check_sum = read_byte_from_file(file, &char_to_put, &total_chars_read);
return true;
}