Hi everybody!
I need advice, I'm trying make code which is dividing data in to 37 MB files. The data comes from GPS.
I did code, when I turn on board it creates file and starts save in to SD card, I turn off and turn again on it creates new file and starts save data, that's ok, I deal with this. But I want make code which is saves files with volume 37 MB during saving process also, example: gpslog00, gpslog01 and so on. I think you got idea.
This is what I did in setup():
void setup()
{
Serial.begin(19200);
flag = 0;
card.init();
// initialize a FAT16 volume
Fat16::init(&card);
int i;
for(i=0; i<100; i++)
{
name[6] = '0'+i/10;
name[7] = '0'+i%10;
if(!myFile.open(name, O_EXCL))
{
break;
}
}
myFile.open(name, O_CREAT | O_APPEND | O_WRITE);
MsTimer2::set(450,stopGps);//Set Timer2 Interrupt every 900ms(at 8MHz)
}
and I couldn't figure out how make do dividing files during process of saving.
void loop()
{
if(Serial.available())
{
recv = Serial.read();
if(recv == 0x0A)
{
recvBuf = "";
}
recvBuf += recv;
nameIndex = recvBuf.indexOf(HeadMessage);
if(nameIndex != -1)//if there has HeadMessage there will not return -1,so we can know is ther a new message
{
recvBuf = "";
flag = 1;
}
if(flag == 1)
{
Gpsflag = 1;
MsTimer2::start();
myFile.print(HeadMessage);//wo miss the headmessage up there,so we add the head message before we add the next
while(Gpsflag)//Get one Packet message during the 900ms,cause the GPS send the message every 1 second
{
while(Serial.available())
{
myFile.print((char)Serial.read());
}
}
flag = 0;//clear the flag,waiting for the next Packet
MsTimer2::stop();
myFile.close();//Close and Save
myFile.open(name,O_APPEND | O_WRITE);//allow to Write
Serial.flush();//Clrean the Serial Buff
}
}
}
Please help, I will be really appreciate!
BR,
kea2288