Thoughts about how to bit shift large amounts of data
I'm new to the forums :(party):, so go easy, eh?
I'm trying to write an application that does the following:
- Recieve UDP Packet
- Sequence with remainder of previous packet
- Find start bits, read following 100 bytes
- Reformat these bytes from 12 bits -> 16 bits
- Rebroadcast 512 byte segments
Let me explain the situation further.
Each UDP packet comes in with 512 bytes of data. Somewhere in the data are some start bits (a 24 bit word). I need to find this word, and then read the 100 bytes following this word. The data contained within these 100 bytes are in 12 bit format, so I need to recondition the data such that there are 4 leading 0s on each piece (making the values 2 bytes a piece). I then need to rebroadcast this data.
Here are some of the issues:
Data will always be split between packets; including the synch word sometimes. I need to be able to double buffer the packets, and remove data away as this happens (I'm not so worried about being able to do this part)
What I AM having trouble with, is how to handle this data in a bit-wise fashion. While the synch word DOES fit nicely into 3 bytes, it's not guaranteed that it will fall spatially into 3 bytes (e.x. if the synch word was 000000000000000000000001, the word that i'm looking for COULD be 00 00 01, or (XXX0) 00 00 0 (001X), or (XX00) 00 00 0(01XX), etc. I would think that I need to start at the beginning, bitshift all of the data and read 24 bytes until I find my synch word.
I also need some help thinking about how to recondition those 12 bit values into two bytes.
I know its a lot! Thanks for any help that anyone can give :(happy):