I need help making this Communication buffer work
Bits
Posts: 414
I have a cog that runs "fullduplexserial" and packs a buffer made up of 255 bytes. I have a problem unpacking the buffer and wanted a sugjestion doing so.
Here is my code that runs 2 cogs. Its function is to monitor the USB port looking for a byte that is within the start and stop range ($20 to $5D). Once it sees this byte is true it begins packing the buffer.
Here is a picture of packing the buffers.
[code]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐
│S││X││X││X││X││S││S││X││X││X││S││S││X││X││X││X││X││X││X││S││ │
└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘
S = START AND STOP BIT
X = NUMBER OR SYMBOL
3 commands are in the buffer, each could different lengths and values
Now I need to figure our a way to run another cog and look at this buffer to see if valid commands are contained within it.
I am at a loss of how to unpack the buffer. I thought about byte shifting but that needs a lot of overhead.
Suggestions?
Here is my code that runs 2 cogs. Its function is to monitor the USB port looking for a byte that is within the start and stop range ($20 to $5D). Once it sees this byte is true it begins packing the buffer.
Here is a picture of packing the buffers.
[code]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐┌─┐
│S││X││X││X││X││S││S││X││X││X││S││S││X││X││X││X││X││X││X││S││ │
└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘└─┘
S = START AND STOP BIT
X = NUMBER OR SYMBOL
3 commands are in the buffer, each could different lengths and values
Now I need to figure our a way to run another cog and look at this buffer to see if valid commands are contained within it.
I am at a loss of how to unpack the buffer. I thought about byte shifting but that needs a lot of overhead.
Suggestions?
Comments
256 just gives you the rollover for free because a byte variable would automatically go back to 0 when adding 1 to 255.