Understanding Timestamps

Top  Previous  Next

Sometimes it is necessary to remember the date/time of the most recent setting modification. This can be useful, for instance, when synchronizing settings between several devices.

To enable timestamps, click (enable) the Timestamp option in the configurator. Timestamps occupy an additional 7 bytes of memory for each setting (in the EEPROM, flash disk file, or in RAM, depending on how the setting is stored). This is why timestamps are disabled by default.

There is a single timestamp for each setting, even if this setting includes multiple members. Timestamps are read and written through the stg_timestamp global variable. Note that it is the responsibility of your application to set and interpret timestamps. The STG library does not access the real-time clock of your system and does not verify the contents of stg_timestamp variable.

To set the new timestamp for the setting, fill out the stg_timestamp variable with desired data prior to calling stg_set() or stg_sg(,,,EN_STG_SET). Here is an example:

 

 

...

rtc.getdata(stg_timestamp.ts_daycount,stg_timestamp.ts_mincount,stg_timestamp.ts_seconds)

stg_timestamp.ts_milsec=0 'our RTC does not provide ms data

stg_set("IP",0,"192.168.1.50")

...

 

 

You can also set just the timestamp, without altering setting value:

 

 

...

rtc.getdata(stg_timestamp.ts_daycount,stg_timestamp.ts_mincount,stg_timestamp.ts_seconds)

stg_timestamp.ts_milsec=0 'our RTC does not provide ms data

if stg_set_ts("IP")<>EN_STG_STATUS_OK then sys.halt

...

 

 

Note that initializing settings (restoring their values to defaults) through stg_restore_multiple() and stg_restore_member() also sets the timestamp of each affected setting.

 

Stg_timestamp variable is updated every time you read the setting with stg_get() or stg_sg(,,,EN_STG_GET). In the following example, we read the setting in order to get its timestamp, then set new setting value if the setting hasn't been yet modified today:

 

 

...

dim daycount,mincount as word

dim seconds as byte

 

rtc.getdata(daycount,mincount,seconds)

stg_get("IP",0)

if stg_timestamp.ts_daycount<daycount then

 stg_set("IP",0,"ABC")

end if

...