I need help again. I have the data being in a complete message in my tempArray[ ]. If I serial print the full tempArray I can see the message is complete and all of the byte segments are the correct length.
This message contains a header of 27 data bytes plus a 0x00 followed by 30 byte segments for each satelite. Each segment starts with either a 0x01 or 0x02 and each ends with a 0x00 byte.
I want to take the 30 byte segments and save them to an external FRAM but first I am trying to serial print ln the section of the array.
I am trying to check for the 1 or 2 at the beginning and then check for the 0 at the end of the segment. However when I run this I get 2 satelites worth of data then it just runs on collecting bytes forever. Where am I going wrong here?
case pF5sCollectTheData: //header is 27 bytes, 1 null 0x00, message 30 per sv last byte of 30 is 0x00
TimerA = millis();
if(n<z){
Serial2_WaitForByte(&inbyte);
if(inbyte == 0x03){
if(tempArray[n] == 0x10){
n++;
tempArray[n] = inbyte;
z=n+1; //sets z for next phase to 1 byte past 0x03
state = F5parse;
}
else{ //if not end byte advance and store in array
n++;
tempArray[n] = inbyte;
}
}
else{
n++;
tempArray[n] = inbyte;
}
}
else{
TimerA = millis();
state = F5parse;
}
if (millis()-TimerA >= 400UL){
Serial.println("time out error F5collect data");
state = Fini;
}
break;
case F5parse: //check for and remove double 0x10 bytes sent from device
Serial.println("F5 parse begin");
for(n=0; n<z; n++){
if(tempArray[n] == 0x10 && tempArray[n+1] == 0x10){
for(w = n; w < z; w++){
tempArray[w] = tempArray[w+1]; //recopy all bytes after first 0x10
}
z=w+1;
}
}
for(n=0; n<z; n++){
if(tempArray[n] == 0x03 && tempArray[n-1] == 0x10){ //shorten any extra to end bytes
z = n+1;
}
}
Serial.println("entering F5 save data state");
for(n=0; n<28; n++) { //header info
//WriteF5h(addr,n*8,tempArray[n]);
Serial.println(tempArray[n]);
}
Serial.println("split");
TimerA = millis();
state = F5saveData;
if (millis()-TimerA >= 400UL){
Serial.println("time out errorF5 parse data");
state = Fini;
}
break;
case F5saveData: //go through tempArray
for( n=28; n< z-30; n++){
if(tempArray[n] == 0x01){ //glonass 30 bytes data good
if(tempArray[n+29] == 0x00){
for(int i=n; i<i+29; i++){
//WriteF5hGLO(addr,i*8,tempArray[i]);
Serial.println(tempArray[i]);
}
Serial.println("split");
countGLO++;
}
}
if(tempArray[n] == 0x02){ //gps 30 bytes data good
if(tempArray[n+29] == 0x00){
for(int i=n; i<i+30; i++){
//WriteF5hGPS(addr,i*8,tempArray[i]);
Serial.println(tempArray[i]);
}
Serial.println("split");
countGPS++;
}
}
}
state = Fini;
if (millis()-TimerA >= 400UL){
Serial.println("time out errorF5 save data");
state = Fini;
}
break;