Thursday, December 14th 2017, 10:46am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Date of registration: Jan 20th 2016

Posts: 6

1

Wednesday, January 20th 2016, 9:42am

Automatic folder creation & date stamping

Hello,

I'm working on PSoC 4BLE. I created a project using emFile(SPI) component for SD card. I'm able to store data in folder & file. I want to store the data according to time. I want to store today's data in folder name as 01/20/2016, tomorrow's data in another folder name as 01/21/2016 like that.It means folder will create by daily basis & data will store in itso whenever i need previous data i can fetch the data using sd card date folder. I tried so many things there but the structure is const char type. so i'm not able to pass a variable there.I'm attaching a file here please review it & give me some suggestions.

Thanks in advance for your help.
chopra.arpita92 has attached the following file:
  • SD Card.txt (8.47 kB - 550 times downloaded - Last download: Today, 7:53am)

SEGGER - Marius

Super Moderator

Date of registration: Aug 10th 2011

Posts: 31

2

Wednesday, January 20th 2016, 4:20pm

Hello chopra.arpita92,

It seems that you are trying to create a file with a name longer than 8 characters.
This works only when the support for long file names is enabled in the file system.
The support for long file names is disabled by default. It can be enabled by calling
FS_FAT_SupportLFN() API function.

Would it be possible to try this in your application?

Best regards,
Marius

Date of registration: Jan 20th 2016

Posts: 6

3

Thursday, January 21st 2016, 12:49pm

Hello Marius,

Thank you for your suggestion. I want to ask you one more thing which is that i'm getting the date is 31-12-1969. I tried to correct it but not getting correct values.

Thanks,

SEGGER - Marius

Super Moderator

Date of registration: Aug 10th 2011

Posts: 31

4

Thursday, January 21st 2016, 4:37pm

Hello,

Would it be possible to provide more details about how do you get this date?

Best regards,
Marius

Date of registration: Jan 20th 2016

Posts: 6

5

Thursday, January 21st 2016, 7:31pm

Hello Marius,

I'm using RTC here but in programming i'm getting correct date & time in length = sprintf() but here whem i'm trying to get the time & date it is not giving me correct date. Here is an API U32 FS_X_GetTimeDate(void)
{
U32 r;
U16 Sec, Min, Hour;
U16 Day, Month, Year;

Sec = 0; /* 0 based. Valid range: 0..59 */
Min = 0; /* 0 based. Valid range: 0..59 */
Hour = 0; /* 0 based. Valid range: 0..23 */
Day = 1; /* 1 based. Means that 1 is 1. Valid range is 1..31 (depending on month) */
Month = 1; /* 1 based. Means that January is 1. Valid range is 1..12. */
Year = 0; /* 1980 based. Means that 2007 would be 27. */
r = Sec / 2 + (Min << 5) + (Hour << 11);
r |= (U32)(Day + (Month << 1) + (Year << 16)) << 20;
return r;
}

Is this effecting to my code. Please let me know.

Thanks,

SEGGER - Marius

Super Moderator

Date of registration: Aug 10th 2011

Posts: 31

6

Friday, January 22nd 2016, 9:58am

Hello,

The file system uses the FS_X_GetTimeDate() function to generate the timestamps of files and directories.
In order to have correct timestamps, you should add calls to your RTC routines in this function
as documented in the emFile manual.

Best regards,
Marius

Date of registration: Jan 20th 2016

Posts: 6

7

Wednesday, January 27th 2016, 5:32am

Thank you Marius,

Now i'm getting all the correct values. I just want to ask one thing which is that i want to put long directory name (01-27-2016) according to time stamping but i'm not able to do this. if i will remove dash(-) between them then i'll get correct (01272016) nos but with dash it is not possible. is there something for long directory name.

Thanks,

SEGGER - Marius

Super Moderator

Date of registration: Aug 10th 2011

Posts: 31

8

Wednesday, January 27th 2016, 10:36am

Hello,

I tested here with the version 4.00b of the file system.
With support for long file names enabled, I was able to successfully create a file with the name "01-27-2016".
Which version of the file system are you using?
Does the file system report any errors when you try to create the file?

Best regards,
Marius

Date of registration: Jan 20th 2016

Posts: 6

9

Wednesday, January 27th 2016, 10:49am

Hello Marius,

Thank you for your time. I'm also able to give the file name according to date stamping. I want to put long folder (directory) name. I'm getting a folder from FS_Mkdir(""), I want to put directory name as 01-27-2016, but now i'm just getting(01272016). FS_FAT_SupportLFN(); for long file name. Is there something for long directory(folder) name.

Thanks,

This post has been edited 1 times, last edit by "chopra.arpita92" (Jan 27th 2016, 10:53am)


SEGGER - Marius

Super Moderator

Date of registration: Aug 10th 2011

Posts: 31

10

Wednesday, January 27th 2016, 5:39pm

Hello,

The file system treats the name of the files and of the directories in the same way.
FS_FAT_SupportLFN() enables the support for long file name for files as well as for directories.
Could you please check the return value of FS_MkDir()? The error code should give
a hint about what went wrong during the operation.

Best regards,
Marius

Date of registration: Jan 20th 2016

Posts: 6

11

Friday, January 29th 2016, 7:33am

Hello Marius,

I'm already using FS_FAT_SupportLFN(); but not able to capture date. Please check the bold area. If i'm putting dash it is not creating folder. I need to add any source or header file? Please let me know.

FS_Init();
void FS_FAT_SupportLFN();
/* Get volume name of SD card #0 */
if(0 != FS_GetVolumeName(0u, &sdVolName[0], 9u))
{
/* Getting volume name succeeded */
UART_UartPutString(" mixBuffer ");
UART_UartPutString(sdVolName);
}
else
{
/* Operation Failed - indicate this */
UART_UartPutString("Failed to get mixBuffer");
}

/* Extend support for file creation with long name. */


/* Initialization of Folder and File creation at the beginning of execution. */

/* Get Date and Time from RTC */
time1 = RTC_GetTime();
date=RTC_GetDate();

/* Capture File Name for MM-DD-YYYY */
sprintf(dir_name, "%02lu%02lu%02lu", RTC_GetMonth(date),RTC_GetDay(date),RTC_GetYear(date));

/* Capture File Name for Dir_name\HH.txt */
sprintf(sdFile, "%s\\%02lu-%02lu.txt", dir_name, RTC_GetDay(date), RTC_GetHours(time1));

/* Create Directory */
FS_MkDir(dir_name);

Thanks,

SEGGER - Marius

Super Moderator

Date of registration: Aug 10th 2011

Posts: 31

12

Friday, January 29th 2016, 4:05pm

Hello,

Could you please check the return value of FS_MkDir()?

In case of an error the function returns a negative value
indicating the reason why the operation failed.
The possible error codes are defined at the beginning of the FS.h file (FS_ERRCODE_...)
You can get a short text description of the error
by calling FS_ErrorNo2Text() with the error code as parameter.

Best regards,
Marius