I need help making this Communication buffer work
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
pub Get_A_Byte : bite if readPointer == buffercount ' any characters in the buffer? return -1 ' if not, return -1 to indicate buffer is empty bite := buffer[readPointer++] ' get character in buffer if readPointer == 254 readPointer := 0The problem with this is that there's no way to tell that the input buffer is already full. You need to add the following to your buffer writing routine: Alternatively, you can also keep a byte count of the number of bytes stored in the buffer. Increment it when you put something in and decrement it when you take something out. If it's zero, the buffer is empty. If it's equal to 254 (or whatever your buffer size is), the buffer is full.256 just gives you the rollover for free because a byte variable would automatically go back to 0 when adding 1 to 255.