I'm trying to figure out the best method of filling an array of data based on a size of data packet byte.
Example:
Device sends a header of 0x24 then the next byte tells us how much data is expected to follow, lets say it's 0x05
So, say we get 0x24 0x05 0x01 0x02 0x03 0x04 0x05
Can someone help me with what method I would use to look to the data where 0x05 is and then place that amount of data into an array? If anything follows it it can be ignored and trashed.
I have tried numerous different methods but I'm not keying on the right thing.
I was playing around with this as a basis:
void loop()
{
while(Serial.available() > 0)
{
if(index < 39)
{
inChar = Serial.read();
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
I was thinking of maybe a second Serial.read after inChar to get to the length byte then somehow use that information with index+ to constrain it but when I try different combinations of things it doesn't work.