ALMHX AlarmClockTime

From Sharpfin
Jump to navigation Jump to search

ALMHX_AlarmClockTime.txt

File Format

The file contains a number of rows (one for each alarm). Rows are in the format:

hh:mm t cccccccccc w a o
  • hh - Hours to display for alarm time
  • mm - Minutes to display for alarm time
  • d - Day of week (0=Sunday, 1=Monday)
  • cc - Unix time for alarm time (assumes always on GMT!)
  • w - 0=Once, 2=Daily, 3=Weekly, 4=WeekDays, 5=Weekends
  • a - 0=Buzzer, 1=presetAlarm.txt, 2=presetAlarm1.txt ...
  • o - 0=off, 1=on

Example:

07:15 5 1209712500 4 1 1

Alarm On and set for 07:15, at Midnight on Sunday/Monday, Alarm Once, and use Buzzer.

Direct Manipulation of File

If this file is edited outside of the ir application (e.g. directly from a webserver), the ir application ignores the changes.

Following an external update, the ir application must be restarted, either by a radio reboot, or by using "init 3 ; init 2" in a script.

Calculating cccccccccccc

The radio uses and maintains this number to work out the actual alarm time, so it must be correctly calculated each time it is changed / updated. This means that we need to know the current time.

The ir application performs its own time management, and the operating system time is left back in the 1970s. There is no rdate program compiled into the OS.

Be aware that the radio ignores timezones, and actually adjusts GMT when the clocks move on/back - consequently, the cccccc value is the local time, and is not GMT as would normally be expected.

 <syntaxhighlight>
 #include <stdio.h>
 #include <sys/time.h>

 main(int argc, char *argv[]) {
        time_t t ;
        if (argc!=2) {
                printf("ctime cccccccc

") ;

                exit(1) ;
        } 
       t=atoi(argv[1]) ;
       printf("%s",ctime(&t));
 }
 </syntaxhighlight>

The above function returns the following, when supplied with 1209712500:

On the Radio: Fri May 2 07:15:00 2008 Under Cygwin: Fri May 2 08:15:00 2008

Writing a web-based Alarm management page

In order to write a web-based Alarm manager script, the following tools are needed:

  • Get correct network time (rdate type program)
  • Convert hh:mm to a real unix time (undoing timezone adjustments done by the ir application)
  • Identify the current day (0=Sunday ...)

Alternatively, a web-based Alarm manager application could be written instead of a script. In this case, some steps shouldbe avoided to prevent repeated ntp requests (perhaps by managing the synchronisation of the unix clock)