Read text file in flash

24 Mar 2011

In this code I read the 6 analog inputs for 1 hour and stored it in text file in flash.

I get the text file like this with 60 datas. 1: 1300971050,2.175,2.174,2.176,2.169,2.177,2.168

I need to read this analog.txt file. I am using UART to send this data. How can I read and send? Kindly help me...

void read_analog()
{

   FILE *fp = fopen("/local/analog.txt","w"); 
   
    while (count < 60) {
        avg[0] = (float)ain_UseA.read_u16()* vdiv;
        avg[1] = (float)ain_UseB.read_u16()* vdiv;
        avg[2] = (float)ain_UseC.read_u16()* vdiv;
        avg[3] = (float)ain_UseD.read_u16()* vdiv;
        avg[4] = (float)ain_UseE.read_u16()* vdiv;
        avg[5] = (float)ain_UseF.read_u16()* vdiv;
               
       uint16_t temp;
       uint8_t i;
    
        for(i=2;i<8;i++)
        {
        temp = avg[i-2] * 1000;
        payload[(i * 2)]     = temp >> 8;
        payload[(i * 2) + 1] = temp;
        payload_len += 2;
    }
    payload_len = 16;


    payload[0] = seconds >> 24;
    payload[1] = seconds >> 16;
    payload[2] = seconds >> 8;
    payload[3] = seconds; 
    
        fprintf (fp, "%3i:%d,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f\r\n", count+1,seconds,avg[0],avg[1],avg[2],avg[3],avg[4],avg[5]); 
    uart_PC.printf("Time:%d,S1:%5.3f,S2:%5.3f,S3:%5.3f,S4:%5.3f,S5:%5.3f,S6:%5.3f\r\n",seconds,avg[0],avg[1],avg[2],avg[3],avg[4],avg[5]);
    count++; 
        wait(60); 
        }
        
       fclose(fp);
                }
        
24 Mar 2011

Hi,

You need to reopen the file with "r" as access parameter and use fgets.

See http://www.cplusplus.com/reference/clibrary/cstdio/fgets/