Searching Circular Buffer - Any Advice?
Posted: Thu Jan 04, 2018 11:22 am
Hi All
I'm just about to start a little project that will require the use of the RS232 component to receive data. I'm pretty confident of using an interrupt to signal when data is present, and from examples it seems I should be feeding this data into a Circular Buffer for processing. All good so far.
I have simulated a CB and populated it with random data and I've retrieved data too. I have also used the "Lookforvalue" function and I can determine if the buffer contains a specific value(s). This is all just "playtime" to familiarise myself with things before I start on the project.
I will be sending data to the RS232/CB and I can structure this data any way I wish. I imagine I will need a way to identify the start of my data followed by an "ID" and "Status", these could just be three bytes or the like (start,ID,status). The length of the "packet" won't change, just the second and third bytes (start would be a unique identifier and I do appreciate that I will probably end up using a more complex packet but that isn't my issue at present).
What would be the best way to search and extract this data from a CB? The "Lookforvalue" would only be able to identify non changing data such as the "start" byte and it doesn't provide any means to return found position within the CB to enable me to directly grab the following two bytes that I care about.
I can create a loop that extracts each byte from the buffer one byte at a time and I can test this byte to see if it is my unique "Start" value and if so go from there, but it seems a bit rough and ready. Has anyone got a better idea of searching the CB etc? Is there a way to first identify if and where in the buffer a target is located and then extract it?
I've looked through posts but I haven't quite seen anything similar so any pointers appreciated.
Thanks in advance.
I'm just about to start a little project that will require the use of the RS232 component to receive data. I'm pretty confident of using an interrupt to signal when data is present, and from examples it seems I should be feeding this data into a Circular Buffer for processing. All good so far.
I have simulated a CB and populated it with random data and I've retrieved data too. I have also used the "Lookforvalue" function and I can determine if the buffer contains a specific value(s). This is all just "playtime" to familiarise myself with things before I start on the project.
I will be sending data to the RS232/CB and I can structure this data any way I wish. I imagine I will need a way to identify the start of my data followed by an "ID" and "Status", these could just be three bytes or the like (start,ID,status). The length of the "packet" won't change, just the second and third bytes (start would be a unique identifier and I do appreciate that I will probably end up using a more complex packet but that isn't my issue at present).
What would be the best way to search and extract this data from a CB? The "Lookforvalue" would only be able to identify non changing data such as the "start" byte and it doesn't provide any means to return found position within the CB to enable me to directly grab the following two bytes that I care about.
I can create a loop that extracts each byte from the buffer one byte at a time and I can test this byte to see if it is my unique "Start" value and if so go from there, but it seems a bit rough and ready. Has anyone got a better idea of searching the CB etc? Is there a way to first identify if and where in the buffer a target is located and then extract it?
I've looked through posts but I haven't quite seen anything similar so any pointers appreciated.
Thanks in advance.