It might easier for you to simply read all received data byte-by-byte instead of trying to segment it in the first place.
- At the beginning of received data your code will see "0805" numbers (Indicating Codec ID = 8 and that 5 data records is received)
- Therefore you can start 5 cycles, but do not specify at which byte they should end. E.g. you can run infinite while cycle (which would be run 5 times in the row, for 5 records)
- Inside the cycle, read each byte one by one and parse the data. At first that would be UTC timestamp and GPS information, then I/O element part, in which there will be information how many I/O element records are present in total and how many of them are 1/2/4/8 bytes long.
- This means that when your application would reach end of 8 bytes I/O element records (e.g. read last 8 byte I/O records, or find out, that no 8 byte records are present), it would know that this is the end of first GPS data record (out of initial 5). At this point you can break/escape the cycle, so that cycle could repeat for next GPS data record.
Hope this explanation how everything could be achieved was understandable. You probably already have similar information, but if you do not, here you can find good example how to handle AVL data records: https://wiki.teltonika-networks.com/view/RUT955_Protocols#Example
Teltonika also have made AVL data reader/parser, which you can implement into your server (source codes are available), or use them as a reference point. Applications can be downloaded from here: