Hi, I'm trying to parse this hexadecimal array. I need to find the location of a "tag" which is followed by a data length byte. For example: 0x9F, 0x66, 0x04. 9F66 is the tag, and 04 is the data length. There are multiple tags in this array which have the same 1st byte, for example 9F66 and 9F02. I need to be able to generate a new array with the data each tag has requested in the order that the tags appear in the first array. I have uploaded the code I've managed to do so far, but it seems that the way I am using the for loop is incorrect. What I am trying to code is to go through the array, find a byte that matches 0x9F, then checking if the next byte equals 0x66 or 0x02, or any of the other second bytes. This code just assigns the length of the first tag to every other tag. Almost like it gets stuck on the first "i" that has success and just runs with it. Any help would be much appreciated as I've spent hours trying to figure this out.
int PDOL_response[] = {0x9F, 0x66, 0x04, 0x9F, 0x02, 0x06, 0x9F, 0x03, 0x06, 0x9F, 0x1A, 0x02};
void setup(){
Serial.begin(9600);
}
void loop(){
for (int i = 0; i<sizeof(PDOL_response); i++){
if ((PDOL_response[i],HEX) == (0x9F,HEX) && (PDOL_response[i+1],HEX == (0x66,HEX))){
Serial.println("9F66 Length:");
Serial.println(PDOL_response[i+2],HEX);
break;
}
}
for (int i = 0; i<sizeof(PDOL_response); i++){
if ((PDOL_response[i],HEX) == (0x9F,HEX) && (PDOL_response[i+1],HEX == (0x02,HEX))){
Serial.println("9F02 Length:");
Serial.println(PDOL_response[i+2],HEX);
break;
}
}
for (int i = 0; i<sizeof(PDOL_response); i++){
if ((PDOL_response[i],HEX) == (0x9F,HEX) && (PDOL_response[i+1],HEX == (0x03,HEX))){
Serial.println("9F03 Length:");
Serial.println(PDOL_response[i+2],HEX);
break;
}
}
}