Shop OBEX P1 Docs P2 Docs Learn Events
Putting a date on an SD card file - Anybody have a snippet that works with the — Parallax Forums

Putting a date on an SD card file - Anybody have a snippet that works with the

ElectricAyeElectricAye Posts: 4,561
edited 2008-09-13 14:13 in Propeller 1
Ladies and Gentlemen,
I was wondering if anybody has a snippet of code that will easily put a date stamp on the files created by the SD card object. Currently, I have a system that reads my real time clock and gives each file a name that is based on the time and date, but I notice that there's an "official" date that gets attached to SD card files, and this looks like it's locked in as January 2007. I was just wondering if anyone already has a convenient code snippet for stamping a real "official" date on the SD card files.

thanks,
Mark

smile.gif

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-09-11 14:06
    Is there a chance you are using a clock chip in your project?

    Could add the object to the SD driver and grab the time from there.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2008-09-11 14:51
    A GPS chip is another alternative.

    There is plenty of code in the Obex to parse the data

    Just a thought

    Ron
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-11 15:20
    OBC,
    yes, I have a real time clock chip, a DS1307, which is what I use for getting the date and time that I integrate into each of the SD card's file names. For example, 9032416.csv would be year 2009, month 3, day 24, hour 16. So it's not like I don't already have a way to get the date and time, it's just that I was curious if anyone already had a code snippet for setting the date on the files of the SD card. Apparently there are some internal doo-hickeys that can be set through the FAT system???? The Sd card object has a comment about doing it, implying some heavy bit banging was involved, the kind of thing that rolls my eyes into the back of my head. So I was just wondering if somebody had already done it for the sheer thrill and excitement that such things bring to all manners of people - except me.


    turn.gif
  • rokickirokicki Posts: 1,000
    edited 2008-09-11 22:08
    This link explains the encoding of date/time on fat16 files:

    http://en.wikipedia.org/wiki/File_Allocation_Table

    Look in the "Directory Table" part.

    It would be pretty straightforward to either make fsrw collect the date from somewhere, or else
    for you to add a setdate() call on a file.

    I don't think anyone has done this yet.
  • PyrotomPyrotom Posts: 84
    edited 2008-09-11 23:55
    Did you look at the "pdate" routine in the fsrw.spin object? Here it is...

    pri pdate
    {{
    '   Get the current date and time, as a long, in the format required
    '   by FAT16.  Right now it"s hardwired to return the date this
    '   software was created on (April 7, 2007).  You can change this
    '   to return a valid date/time if you have access to this data in
    '   your setup.
    }}
       return constant(((2007-1980) << 25) + (1 << 21) + (7 << 16) + (4 << 11))
    
    



    This is referenced down farther in the "popen" routine to set the file creation date. So you need to rewrite the pdate routine to use the date you're getting from your real time clock....
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-12 05:28
    Thanks, guys, but, uh, I'll have to leave this one for more ambitious young whippersnappers to work on.

    Mark

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It might be the Information Age but the Eon of Ignorance has yet to end.
  • rokickirokicki Posts: 1,000
    edited 2008-09-12 15:12
    Mark,

    It's probably not hard at all.

    Figure out how to make an object that returns the date information, maybe filling an array of
    a few ints or something.

    Add a call to that object in the pdate subroutine in the fsrw code.

    That's all you need to do. And then you can show us all how you did it!
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-09-12 15:14
    Go for it Mark!

    If you get stuck, everyone hasn't gone anywhere.. [noparse]:)[/noparse]
    (Besides, anyone who mastered the Propeller Boebot can do this.. [noparse]:)[/noparse]

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
  • Mike CookMike Cook Posts: 829
    edited 2008-09-12 15:45
    More info about adding at time stamp to your files written on the SD card can be found here (about the 11th post down):
    ·
    http://forums.parallax.com/showthread.php?p=622673
    ·
    I’ve got a method written somewhere, if I can find it I’ll post it tonight when I get home. However for my application I decided to have the date encoded in the 8.3 file name for my logging application.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-12 19:03
    Pyro,
    yes, I saw that pdate code but got confused because it says the date will be set for 4 April 2007, but it's actually set for January 2007 4 AM. And the stuff on wikipedia about FAT dating bits is way above my head, I think. Anyway, I'll study this some more and see what Mike Cook has cooked up, too.

    thanks, you guys
    Mark

    smile.gif
  • Mike CookMike Cook Posts: 829
    edited 2008-09-12 21:50
    Ok, the code that I wrote, sometime ago (1-8-2007) is kind of a mess, I can post this project,·if you get stuck.

    Here is what I did to modify the fsrw.spin file to time stamp the file when it was created.


    First I added the following variables to the bottom of the VAR section:
       word year  
       byte month 
       byte day   
       byte hour  
       byte minute
       byte sec
     
    


    Then I modifed the pdate to the following:
    pri pdate 
    {{
    '   Get the current date and time, as a long, in the format required
    '   by FAT16.  Right now it"s hardwired to return the date this
    '   software was created on (December 26, 2006).  You can change this
    '   to return a valid date/time if you have access to this data in
    '   your setup.
    }}
        '                 YEAR                 MONTH        DAY          HOUR         MINUTE      SECOND**
        'return constant(((2006-1980) << 25) + (12 << 21) + (28 << 16) + (23 << 11) + (59 << 5) + (29))
        '
        ' ** Seconds are counted with 2 seconds interval, so a value of 29 in this field gives 58 seconds.
        
        return ((year-1980) << 25) + (month << 21) + (day << 16) + (hour << 11) + (minute << 5) + (sec)
        
    


    And then added the following method to the fsrw.spin file:
    pub pSetTimeDate(y, m, d, h, mi, s)  ' ***** MUST BE DONE BEFORE OPENING FILE !!! *****
        year   := 2000 + y                                     ' FAT16 expects a four digit year
        month  := m
        day    := d
        hour   := h
        minute := mi
        sec    := s / 2                                        ' In FAT16 Seconds are counted with 2 seconds interval
     
    


    Now to use this mess, in my top file I call this method BEFORE I open a file for write:
    PUB FileSetDateTime | year, month, day, hour, minute, second
    ' Set File Date and Time Creation  ***** MUST BE DONE BEFORE OPENING FILE FOR WRITE !!! *****
      rtc.getdate                                              ' get date from DS1307
      rtc.gettime                                              ' get time from DS1307
      year   := rtc.getYears                                   ' assign Date and Time Variables
      month  := rtc.getMonths
      day    := rtc.getDays
      hour   := rtc.getHours
      minute := rtc.getMinutes
      second := rtc.getSeconds
      
      sdfat.pSetTimeDate (year, month, day, hour, minute, second)  ' set the date/time variables in _mjc_fsrw.spin
       
    


    Here is an example of it's use:
    PUB WriteFile(mode) | r, idx
      FileSetDateTime                                          ' Set File Date and Time Creation
                                                               ' ***** MUST BE DONE BEFORE OPENING FILE !!! *****
      r := sdfat.popen(@FileName, mode)                        ' OPEN a file for WRITE
     
    



    In the original program that I pulled this code this from, I was getting time from a DS1307 chip.

    Hope this is enough info to get you started. There are probably better ways of doing this, but this 'quick & dirty' worked for my use.


    Note: Edits to this post were for formatting and spelling typo's

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    Post Edited (Mike Cook) : 9/12/2008 11:25:41 PM GMT
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-13 13:45
    Thanks, Mike, it will take me a while to contemplate this.

    Mark

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It might be the Information Age but the Eon of Ignorance has yet to end.
  • PyrotomPyrotom Posts: 84
    edited 2008-09-13 14:13
    ElectricAye said...
    Pyro,
    yes, I saw that pdate code but got confused because it says the date will be set for 4 April 2007, but it's actually set for January 2007 4 AM.
    Ah, yes. The perils of accepting a comment as the truth, instead of reading the code. I was a professional programmer for 35 years, and learned the hard way that comments should always be used as clues to help in reading and understanding the code, but never taken as gospel. I'd make a small bet that the original version of this code did set the date to April, but at some point rokicki changed the code to January, but never changed the comment. I'm not really faulting rokicki here - I'm constantly finding places in my own code where I have done the same thing... shakehead.gif
Sign In or Register to comment.