Shop OBEX P1 Docs P2 Docs Learn Events
Is FSRW's setdate actually supposed to work? - SOLVED! — Parallax Forums

Is FSRW's setdate actually supposed to work? - SOLVED!

ElectricAyeElectricAye Posts: 4,561
edited 2010-10-05 11:36 in Propeller 1
I thought I read (somewhere?) in FSRW's OBEX downloads description that working with dates wasn't yet implemented, but then inside the Object I found setdate, with which I've been tinkering but with no success. Is it supposed to work? or... why else would it be in the Object?

I would like to give my SD card files a date and time stamp, if possible, but I've heard it's one of your typical Microsoft-Rules-The-World problems. So I'm confused about what's going on with FSRW.

Clues?

Comments

  • Kal_ZakkathKal_Zakkath Posts: 72
    edited 2010-10-04 17:13
    I've used setdate with fsrw version 2.6 without problems, like so:
      sd.setDate(rtc.getYear, rtc.getMonth, rtc.getDate, rtc.getHours, rtc.getMinutes, rtc.getSeconds)
    

    I can't speak for earlier versions, comments at the top indicate it might need to be version 2.4a or higher:
    ("v2.4a 6 October 2009 modified setdate to explicitly set year/month/etc.")
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-04 18:00
    I've used setdate with fsrw version 2.6 without problems...

    Kal,

    The "caveats.html" file that came with the fsrw26 folder says"...No explicit date or time support yet." But sometimes those comments are never updated. I'm probably doing something totally stupid, so your feedback gives me encouragement to keep trying.

    thanks,
    Mark
    :)
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-04 21:26
    I've been trying to get the setdate function in FSRW to work properly and I think the reason it's not working for me is because my Real Time Clock object (DS1307) is returning a LONG, but I think FSRW's setdate requires a WORD or a BYTE - I'm not really sure yet. But how do you easily convert a LONG variable into something you can stuff into a BYTE or WORD-sized position? I don't know enough about all these bit shifting techniques going on in FSRW to make any sense of it.

    Is there a simple way to fix this problem? :(
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-04 22:33
    I've used setdate with fsrw version 2.6 without problems, like so:
      sd.setDate(rtc.getYear, rtc.getMonth, rtc.getDate, rtc.getHours, rtc.getMinutes, rtc.getSeconds)
    
    ...

    Kal,
    which Object are you using for rtc? Do you happen to know if it's returning a Byte, a Word, a Long... or what?

    thanks again,
    Mark
  • KyeKye Posts: 2,200
    edited 2010-10-05 05:26
    1: Download my DS1307 RTC object.
    2: Read the documentation.
    3: Write one line of code.
    4: Be happy. =)
  • AleAle Posts: 2,363
    edited 2010-10-05 07:37
    Kye wrote: »
    1: Download my DS1307 RTC object.
    2: Read the documentation.
    3: Write one line of code.
    4: Be happy. =)

    The right sequence is:

    1: Download my DS1307 RTC object.
    2: Read the documentation.
    3: Write one line of code.
    4: Be happy. =)
    5: ???
    6: Profit ! ;-)
  • T ChapT Chap Posts: 4,223
    edited 2010-10-05 08:08
    Is the value of the LONG greater than 8 bits? If not, then you just say that

    bytevar := longvar

    You could also say bytevar := longvar.byte[0] to get the lower byte amount or just use longvar.byte[0] without assigning it to a byte variable.

    If the LONG value is greater than 8 bits, there is no way to 'stuff' the LONG into the byte.
  • ericballericball Posts: 774
    edited 2010-10-05 08:21
    To generalize Kye:

    1: Download the data producer object.
    2: Read it's documentation to determine the output format.
    3: Download the data consumer object.
    4. Read it's documentation to determine it's input format.
    5: Write the necessary code to convert between formats. (Or modify the code for either object.)
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-10-05 08:37
    @ElectricAye

    In the fray of shameless self-promotion you may have missed the answer (posted by T Chap) that you're looking for:

    bytevar := longvar.byte[0]

    You can extract any byte from a long or a word using this syntax.
  • rokickirokicki Posts: 1,000
    edited 2010-10-05 10:58
    Yes, setdate() should work fine. Post what you're trying, and what results you expect, and what you get, and how they differ. You might check that the values you are passing are correct.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-05 11:09
    Kye wrote: »
    1: Download my DS1307 RTC object....

    Kye,

    I used your object to generate times, etc. and inserted them into the FSRW's setdate just as Kal showed, but I'm still getting oddball dates. (I'm still not sure Kal used FSRW or Kye's SD routines.)

    I tried T Chap's technique to create bytes from the longs derived from the DS1307OBJ, bytes that I then put into FSRW's setdate, but I'm still getting oddball dates, though different dates from those generated by Kye's object when used as stated above.

    I'm beginning to suspect that the FSRW does something weird with bytes that I fundamentally don't understand. And perhaps Kye's RTC object works really well with Kye's SD card routine, but maybe not with FSRW. I can't find anywhere in the FSRW documentation what kind of variable setdate is supposed to take - byte, word or what?

    My program originally used the DS1307OBJ from the i2c object:
    http://obex.parallax.com/objects/217/
    which returns longs, so all my other code utilizes those longs. But Kye's object returns bytes. And the FSRW does something to the bytes that I haven't been able to fathom.

    I guess I could just abandon FSRW and use Kye's SD routine with Kye's RTC and see if that works. But I'm freaked out about this FSRW thing.

    Can't a guy get a decent date, even with a microchip? :(
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-05 11:11
    rokicki wrote: »
    Yes, setdate() should work fine. Post what you're trying, and what results you expect, and what you get, and how they differ. You might check that the values you are passing are correct.

    Okay, will do. It's nice to know that it even works since some of the comments said it didn't.
    But what is FSRW want for setdate? A byte?
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-10-05 11:36
    At last I think I figured it out! :):):):) :):):) :):):) :):):) :):):) :):):) :):)

    The DS1307OBJ from the i2c object:
    http://obex.parallax.com/objects/217/

    returns only the last two digits of the year, so when that value gets plugged into setdate, and gets 1980 or whatever subtracted from it in FSRW, it screws up the bit string.


    Maybe a guy can get a decent date after all! :D

    Thanks everyone for your suggestions and patience!
Sign In or Register to comment.