Hi mark
I have a strange behaviour wise ufat, i try to write the same file many time ,each time i had new data to previous one.
The problem is that it look that the last write command was not executed, for example if want to write 4 time the same string i need to execute 5 time the write command.
Here's the code I used, did I done something wrong ?
I call multi_write()
UTDIRECTORY *ptr_utDirectory = 0;
char Init_Tmp[300];
void Write_XML_Data(char* Nom_Fichier)
{
UTFILE utFile;
char ID[] = "test.txt";
char Version[] = "1.0";
char Type[] = "THL";
char First_Use = 0;
char *Last_Entry = 0;
char File_Open = 0;
if (ptr_utDirectory == 0)
{
ptr_utDirectory = utAllocateDirectory(DISK_D, UT_PATH_LENGTH); // allocate a directory for use by this module associated with D: and reserve its path name string length
}
if (!(ptr_utDirectory->ucDirectoryFlags & UTDIR_VALID)) // directory not valid
{
if (utOpenDirectory(0, ptr_utDirectory) != UTFAT_SUCCESS) // open the root directory
{
fnDebugMsg("No SD-Card ready\r\n");
return;
}
}
utFile.ptr_utDirObject = ptr_utDirectory;
if (utOpenFile(Nom_Fichier, &utFile, (UTFAT_OPEN_FOR_READ | UTFAT_OPEN_FOR_WRITE | UTFAT_CREATE)) != UTFAT_PATH_IS_FILE) // change the directory location
fnDebugMsg("Create file failed\r\n");
if(utFile.ulFileSize == 0)
First_Use = 1;
if(First_Use == 1)
{
Last_Entry = uStrcpy(Init_Tmp,XML_Header);
Last_Entry = uStrcpy(Last_Entry,"<head Version=\"");
Last_Entry = uStrcpy(Last_Entry,Version);
Last_Entry = uStrcpy(Last_Entry,"\" Type=\"");
Last_Entry = uStrcpy(Last_Entry,Type);
Last_Entry = uStrcpy(Last_Entry,"\" Id=\"");
Last_Entry = uStrcpy(Last_Entry,ID);
Last_Entry = uStrcpy(Last_Entry,"\">\n");
}
else
{
utSeek(&utFile, 0, UTFAT_SEEK_END);
Last_Entry = uStrcpy(Init_Tmp,"\n<Data>");
Last_Entry = uStrcpy(Last_Entry,"\n\t<Ts>");
Last_Entry = uStrcpy(Last_Entry,"1272962844");
Last_Entry = uStrcpy(Last_Entry,"</Ts>");
Last_Entry = uStrcpy(Last_Entry,"\n\t<Tc_1>");
Last_Entry = uStrcpy(Last_Entry,"32.2");
Last_Entry = uStrcpy(Last_Entry,"</Tc_1>");
Last_Entry = uStrcpy(Last_Entry,"\n\t<Tc_2>");
Last_Entry = uStrcpy(Last_Entry,"24.2");
Last_Entry = uStrcpy(Last_Entry,"</Tc_2>");
Last_Entry = uStrcpy(Last_Entry,"\n</Data>");
}
if(utWriteFile(&utFile,(unsigned char*)Init_Tmp,uStrlen(Init_Tmp)) != UTFAT_SUCCESS)
fnDebugMsg("Write failed\r\n");
utCloseFile(&utFile);
}
void multi_write(void)
{
Write_XML_Data("test1");
Write_XML_Data("test1");
Write_XML_Data("test1");
Write_XML_Data("test1");
Write_XML_Data("test1");
}
The result obtained :
<?xml version="1.0" encoding="ISO-8859-1"?>
<head Version="1.0" Type="THL" Id="test.txt">
<Data>
<Ts>1272962844</Ts>
<Tc_1>32.2</Tc_1>
<Tc_2>24.2</Tc_2>
</Data>
<Data>
<Ts>1272962844</Ts>
<Tc_1>32.2</Tc_1>
<Tc_2>24.2</Tc_2>
</Data>
<Data>
<Ts>1272962844</Ts>
<Tc_1>32.2</Tc_1>
<Tc_2>24.2</Tc_2>
</Data>
<Data>