I have created a file called ACTUAL.CSV which is record of certain operations. Once the operation is carried out the corresponding record in the file is updated with the operation details at the end and in the front a token '&'is changed to '%'. See the sample below :
<%1 ,A02B94FF ,12 ,VrP Part9 ,101,6670 ,Drive shaft DE ,ShellGadus3 , 16.2,05/19/16-16:07, >
<&2 ,604E95FF ,10 ,VrP Part9 ,102,6670 ,Drive shaft NDE ,ShellGadus3 >
<&3 ,2C63B0F8 ,20 ,VrP Part9 ,103,Cold 1 ,CldPrWshCon1TailDE ,ShellGadus3 >
<&4 ,70E691FF ,15 ,VrP Part9 ,104,Cold 1 ,CldPrWshCon1TailNDE ,ShellGadus3 >
SO at the end of the day I need to pull out all records with a '%'token and create a fresh file called PENDING.CSV.
Created a code for that. It compiles OK but does not print as expected. Is there any basic approach issue in my logic ?
// FUNCTION TO CREATE THE PENDING FILE FROM ACTUAL FILE.CSV
void createPendingSummary() {
char letter;
String readString;
unsigned int nextSDC_Index = 0;
getNoOfRecords(); // First find the total number of records
for ( int count = 0; count < noOfRecords + 1; count++) {
File dataFile = SD.open("ACTUAL.CSV", FILE_READ); // Open the existing Actual File
dataFile.seek(nextSDC_Index); // Point to the start of the record to be read..
char letter = dataFile.read();
if ( letter == '<') { // Locate the record start
statusToken = dataFile.read(); // Acquire the token..
dataFile.seek(dataFile.position() - 2); // Move the sdcIndex back to start...to read full row..
}
if ( statusToken == '&') { // Is the record unfinished ??
while ( dataFile.available()) { // If so read the record row into a String...
letter = dataFile.read();
if (letter == '>') {
nextSDC_Index = dataFile.position(); // Save end of row for reading next record...
dataFile.close();
File pendFile = SD.open( "PENDING.CSV", FILE_WRITE) ;
pendFile.print( readString) ;
pendFile.println('>');
pendFile.close(); // Write the record + > into the Pendfile
break;
}
else {
readString += letter;
}
}// while(dataFile.available()
}// statusToken =='&'
} // for loop end
File pendFile = SD.open( "PENDING.CSV", FILE_READ) ;
while (pendFile.available()) { // Data file exists ..read it.
SerialPort.write(pendFile.read());
}
pendFile.close();
} // Function end
NB : SerialPort refers to Serial in this case.