Fastest way of reading contents from a file in flash drive(Arduino Mega ADK)

Hello,

Here is the current code:

void filesnfprocessFunc(){
  String dataTokens1[42];
  String dataTokens2[42];
  String _oString;
  char send_data[30];
  char fat1[8];
  char snf1[8];
  char rate1[8];
  int data_mode = 0;
  int mode = 0;
  int i;
  int ind;
  // While we can read a character:
     while (((c = file.read()) != -1) ) {
         if (c != '\n') {
           Buffer[pos] = c;
           pos++;
         }
        while((c == '\n')){
          data_mode = 0;                   
          if(iRun4){
          iRun4 = false;
          for(int z=0; z<strlen(Buffer); z++){
            Buffer1[z] = Buffer[z];
          }          
          String str1(Buffer1);
          iIndex1 = getTokens(dataTokens1,str1,',');
          memset(Buffer, '\0',sizeof(Buffer));
          pos = 0;
          break;
        }      
        String str2(Buffer);
        strcat(Buffer,",|");
        i = 0;
        ind = 1;
        memset(fat1, '\0', sizeof(fat1));
        while(Buffer[i] != '|') 
        {
          if(data_mode == 0)
          {
            while(Buffer[i] != ',')
            {
             fat1[strlen(fat1)] = Buffer[i];
             i++; 
            }
            i++;
            memset(rate1, '\0', sizeof(rate1));
            while(Buffer[i] != ',')
            {
             rate1[strlen(rate1)] = Buffer[i];
             i++; 
            }
            i++;                       
            String snf2(dataTokens1[ind]);        
            snf2.toCharArray(snf1, 6);        
            memset(send_data, '\0', sizeof(send_data));
            sprintf(send_data,"$%s,%s,%s|",fat1,snf1,rate1);
            if(send_data[0] == '

The above code reads contents from csv file. I attached the sample csv file to this message.

At the moment, whenever we issue “#” from serial port, it reads the file and outputs data which is in the form of "$fat1,snf1,rate1| (ex:$5,6.1,24.2|). Please check the attached csv file.

For now, it outputs single record for single “#”. I need to modify it such that it outputs 50 records at a time for single “#”. or any other way for faster reading.

could anyone of you help me regarding this?

Thank you

Regards,
Vamshi

bufsnf.txt (6.71 KB)){
           while(1){        
           char r = Serial1.read();
           if((r == ‘#’))
           {
            textprintf(5,0,"==    ==     ==");        
            Serial1.println(send_data);        
            delay(200);
            textprintf(5,0,"==    ==        “);
            textprintf(5,0,”==              “);
            data_mode = 1;
           break;
           }
           }
           ind++;
           }  
         }else{
           memset(rate1, ‘\0’, sizeof(rate1));
           while(Buffer[i] != ‘,’)
           {
            rate1[strlen(rate1)] = Buffer[i];
            i++;
           }
           i++;
                       
           String snf2(dataTokens1[ind]);
           snf2.toCharArray(snf1, 6);        
           memset(send_data, ‘\0’, sizeof(send_data));
           sprintf(send_data,”$%s,%s,%s|",fat1,snf1,rate1);
           if(send_data[0] == ’


The above code reads contents from csv file. I attached the sample csv file to this message.

At the moment, whenever we issue "#" from serial port, it reads the file and outputs data which is in the form of "$fat1,snf1,rate1| (ex:$5,6.1,24.2|). Please check the attached csv file.

For now, it outputs single record for single "#". I need to modify it such that it outputs 50 records at a time for single "#". or any other way for faster reading.

could anyone of you help me regarding this?

Thank you

Regards,
Vamshi

[bufsnf.txt|attachment](upload://pcamovvIsS9i4gsPCHfm8OQ2dS5.txt) (6.71 KB)){
            while(1){        
            char r = Serial1.read();
            if((r == '#'))
            {
             textprintf(5,0,"==    ==     ==");        
             Serial1.println(send_data);        
             delay(200); 
             textprintf(5,0,"==    ==        ");
             textprintf(5,0,"==              ");
             break;
            }
            }
            ind++;
            }    
          }
                 
        
        }      
    pos = 0;                    // ready for next element
    memset(Buffer, '\0', sizeof(Buffer));
    iCounter++;
    break;
    }
    }
    
    while(c == -1){
    char r = Serial1.read();
    if((r == '#'))
    {
    Serial1.println("$#$");
    break;
    }
    }
    file.close(); 
    }

long int getTokens(String *dataTokens,String iString, char delimiter){
  
  int i=0;
  while(iString.indexOf(',')!=-1){     
    dataTokens[i]=iString.substring(0,iString.indexOf(',')); 
    iString=iString.substring(iString.indexOf(',')+1,iString.length());      
    i++;
  }
  dataTokens[i]=iString;  
  return i;
}

The above code reads contents from csv file. I attached the sample csv file to this message.

At the moment, whenever we issue “#” from serial port, it reads the file and outputs data which is in the form of "$fat1,snf1,rate1| (ex:$5,6.1,24.2|). Please check the attached csv file.

For now, it outputs single record for single “#”. I need to modify it such that it outputs 50 records at a time for single “#”. or any other way for faster reading.

could anyone of you help me regarding this?

Thank you

Regards,
Vamshi

bufsnf.txt (6.71 KB)