07-25-2019 01:39 PM
I have an ideal array of n strings of 9 bytes (B) in hexadecimal with the following pattern:
B1 B2 B3 B4 B5 B6 B7 B8 B9
A1 00 4C 44 A4 5B 49 10 BA -> String 1
A1 01 4C 44 A4 5B 49 10 BA ->String 2
A1 02 DC 26 A4 5B 49 10 BA .
A1 03 7C 24 A4 5B 49 10 BA .
09 00 4C 44 A4 5B 49 10 BA .
09 01 4C 44 A4 5B 49 10 BA .
09 02 DC 26 A4 5B 49 10 BA .
09 03 7C 24 A4 5B 49 10 BA .
AA 00 4C 44 A4 5B 49 10 BA .
AA 01 4C 44 A4 5B 49 10 BA .
AA 02 DC 26 A4 5B 49 10 BA .
AA 03 7C 24 A4 5B 49 10 BA ->String n
Where the first byte corresponds to the number of a specific message, in this example I got 3 different messages indicated with the indexes, A1, 09, and AA. These indexes do not follow any sequence. However, every message is made up of 4 different strings that are indicated by sub-indexes, 00, 01, 02, and 03 (located in the second byte of every string).
-> message A1
A1 00 4C 44 A4 5B 49 10 BA -> (4C 44 A4 5B 49 10 BA) part 00 of message A1
A1 01 AC 4A A4 5B 49 10 BA -> (AC 4A A4 5B 49 10 BA) part 01 of message A1
A1 02 DC 26 A4 5B 49 10 BA -> (DC 26 A4 5B 49 10 BA) part 02 of message A1
A1 03 7C 24 A4 5B 49 10 BA -> (7C 24 A4 5B 49 10 BA) part 03 of message A1
-> message 09
09 00 4C 44 A4 5B 49 10 BA -> .
09 01 4C 44 A4 5B 49 10 BA -> .
09 02 DC 26 A4 5B 49 10 BA -> .
09 03 7C 24 A4 5B 49 10 BA -> .
-> message AA
AA 00 4C 44 A4 5B 49 10 BA -> .
AA 01 4C 44 A4 5B 49 10 BA -> .
AA 02 DC 26 A4 5B 49 10 BA -> .
AA 03 7C 24 A4 5B 49 10 BA -> .
Unfortunately, I never get an ideal array of strings. Sometimes I get something like this:
A1 00 4C 44 A4 5B 49 10 BA
A1 02 DC 26 A4 5B 49 10 BA
09 01 4C 44 A4 5B 49 10 BA
09 02 DC 26 A4 5B 49 10 BA
09 03 7C 24 A4 5B 49 10 BA
AA 00 4C 44 A4 5B 49 10 BA
AA 03 7C 24 A4 5B 49 10 BA
Which means that I missed some data, for example:
From message A1 I missed part 01 and part 03 of the message.
From message 09 I missed part 00 of the message.
From message AA I missed part 01 and part 02 of the message.
A1 00 4C 44 A4 5B 49 10 BA -> (4C 44 A4 5B 49 10 BA) part 00 of message A1
-> part 01 of message A1???
A1 02 DC 26 A4 5B 49 10 BA -> (DC 26 A4 5B 49 10 BA) part 02 of message A1
-> part 03 of message A1???
What I would like to do is to add the string that corresponds to missing part of the message, and filled the part of this message with zeros.
For example, retaking the previous missing data:
A1 00 4C 44 A4 5B 49 10 BA -> (4C 44 A4 5B 49 10 BA) part 00 of message A1
A1 01 00 00 00 00 00 00 00 -> part 01 of message A1 filled with ceros
A1 02 DC 26 A4 5B 49 10 BA -> (DC 26 A4 5B 49 10 BA) part 02 of message A1
A1 03 00 00 00 00 00 00 00 -> part 03 of message A1 filled with ceros
As a result, I have all the allocations of my message A1 although some were filled with zeros because I missed that information.
Find attached a picture from the array.
07-25-2019 02:34 PM
That was a bit hard to follow but if I under stand correctly, you want to pad your 2D array with dummy data. Ignoring the obvious question about WHY the data is missing... (IE fix the source instead of bandaid-ing the problem)
Looks like you will need parse the array, row by row looking at the second column and when you are missing data, create the dummy data.
What have you tried? If you could attach your code (not a picture) I am sure some one can help get you going in the right direction.
07-25-2019 03:12 PM
See the attached "Fill Array Example." There may be some edge cases I missed but I believe this correctly creates an output array based on your description. This solutions makes a few assumptions: the input array is already sorted by message ID, and that each message has exactly four parts numbered 00-03. If either of these assumptions is not valid then you may need to make some modifications.
07-25-2019 06:17 PM
Thank you, I appreciate your help. Also, I noticed two things. First, when I run the program that the data that correponds to the message 09 of the part 02 is missing in the array out. Second, the last message (28) missed the last two parts (02 and 03).
I´m attaching the image which explains the issue.
Best regards
07-26-2019 07:32 AM - edited 07-26-2019 07:32 AM
I would detect when a new message has started and just pre-populate the array for that message. This way you know you will have all of the items from the start. Then you just replace the lines as you get the sub-indecies.