I am trying to parse TLV string:
24 00 35 E1 31 9F 08 02 38 30 9F 37 04 4A 66 6B 69 DF AE 05 01 41 9F 26 08 73 30 35 76 4F 6A 36 4E DF AE 06 0C 33 34 71 76 69 70 6B 4D 53 63 66 55 9F 36 02 00 01 90 00 7B
In this case 9F08 is tag followed by length field and data. I am able to get the required fields with the current input string i have, but there could be a scenario where the tag ("9F08") could also be in the data part of another field. I am confused as to how to proceed on this.
public void bleToPos(String hex) {
sb=new StringBuilder();
tlv=new TLVData();
int noOfCharacters=0,src=0,dest=0;
String epiolgue="",epligueData="";
String [] hexArray=hex.split(" ");
//Extract 1st 3 bytes and last 3 bytes. last 3 bytes should contain 90 00 otherwise not valid string
epiolgue=hexArray[hexArray.length-3];
epiolgue= epiolgue + hexArray[hexArray.length-2];
epligueData = hexArray[hexArray.length-1];
if(!epiolgue.equals("9000")) {
System.out.println(" Not a valid tlv no need to process");
return;
}
tlv.setEpilogue(epligueData);
int arrayLength=hexArray.length;
if(hexArray!=null && hexArray.length>0) {
for(int i=0;i<hexArray.length;i++) {
try {
if(hexArray[i].equals("9F")) {
if((i+1)<arrayLength && hexArray[i+1].equals("08")) {
noOfCharacters= (char)Integer.parseInt(hexArray[i+2], 16);
src=i+3;
dest=src+noOfCharacters;
copyArrayElementsIntoString(src, dest, hexArray);
tlv.setVersion(sb.toString());
sb.setLength(0);
}
else if((i+1)<arrayLength && hexArray[i+1].equals("37")) {
noOfCharacters= (char)Integer.parseInt(hexArray[i+2], 16);
src=i+3;
dest=src+noOfCharacters;
copyArrayElementsIntoString(src, dest, hexArray);
tlv.setDssid(sb.toString());
sb.setLength(0);
}
else if((i+1)<arrayLength && hexArray[i+1].equals("26")) {
noOfCharacters= (char)Integer.parseInt(hexArray[i+2], 16);
src=i+3;
dest=src+noOfCharacters;
copyArrayElementsIntoString(src, dest, hexArray);
tlv.setMac(sb.toString());
sb.setLength(0);
}
else if((i+1)<arrayLength && hexArray[i+1].equals("36")) {
noOfCharacters= (char)Integer.parseInt(hexArray[i+2], 16);
src=i+3;
dest=src+noOfCharacters;
copyArrayElementsIntoString(src, dest, hexArray);
tlv.setAtc(sb.toString());
sb.setLength(0);
}
i=dest-1;
src=0;
dest=0;
continue;
}
if(hexArray[i].equals("DF")) {
if((i+1)<arrayLength && hexArray[i+1].equals("AE")) {
if((i+2)<arrayLength && hexArray[i+2].equals("05")) {
noOfCharacters= (char)Integer.parseInt(hexArray[i+3], 16);
src=i+4;
dest=src+noOfCharacters;
copyArrayElementsIntoString(src, dest, hexArray);
tlv.setCvb(sb.toString());
sb.setLength(0);
}
else if((i+2)<arrayLength && hexArray[i+2].equals("06")) {
noOfCharacters= (char)Integer.parseInt(hexArray[i+3], 16);
src=i+4;
dest=src+noOfCharacters;
copyArrayElementsIntoString(src, dest, hexArray);
tlv.setToken(sb.toString());
sb.setLength(0);
}
}
i=dest-1;
src=0;
dest=0;
continue;
}
/*if(hexArray[i].equals("90")) {
if((i+1)<arrayLength && hexArray[i+1].equals("00")) {
}
}*/
}catch(Exception e) {
}
}
}
}