virtualdave
Well-known member
This question has been on my mind for...years? And now I'm finally sitting down to try to figure this out.
Let's say I have an array of numbers coming in from a PC to a teensy. Each number is a byte which will eventually control the intensity of a bunch of RGB LEDs. I'm reading these raw bytes on a teensy...not their ascii equivalent (e.g. 234 0 100 45 21 94 for the the RGB values for 2 LEDs). The challenge of course is knowing when a packet has started and when it had stopped when any value you use could also appear as an RGB value (and vice versa).
How do others get around this? Simply counting bytes won't work...as soon as 1 byte gets lost/dropped then all the values will be off by one position (as I've seen many times in my testing today even). And I'd rather not convert the data bytes to ascii since it could quadruple the payload (as well as add time to convert the three numbers + space back to a singe byte). Any other suggestions? I'm beginning to see the advantage of working in 9-bits (the 9-th bit set to 1 at the beginning of a packet, otherwise 0). Maybe converting a byte to 2 nibbles, adding something to the nibble so it's always > than the packet headers or footers (which would not be converted), then reassembling the bytes at the receiving end? Still doubles the payload, however.
Anyway...not sure if I am making any sense. If it does make sense, any suggestions on how to tackle this?
Thanks,
David
Let's say I have an array of numbers coming in from a PC to a teensy. Each number is a byte which will eventually control the intensity of a bunch of RGB LEDs. I'm reading these raw bytes on a teensy...not their ascii equivalent (e.g. 234 0 100 45 21 94 for the the RGB values for 2 LEDs). The challenge of course is knowing when a packet has started and when it had stopped when any value you use could also appear as an RGB value (and vice versa).
How do others get around this? Simply counting bytes won't work...as soon as 1 byte gets lost/dropped then all the values will be off by one position (as I've seen many times in my testing today even). And I'd rather not convert the data bytes to ascii since it could quadruple the payload (as well as add time to convert the three numbers + space back to a singe byte). Any other suggestions? I'm beginning to see the advantage of working in 9-bits (the 9-th bit set to 1 at the beginning of a packet, otherwise 0). Maybe converting a byte to 2 nibbles, adding something to the nibble so it's always > than the packet headers or footers (which would not be converted), then reassembling the bytes at the receiving end? Still doubles the payload, however.
Anyway...not sure if I am making any sense. If it does make sense, any suggestions on how to tackle this?
Thanks,
David