Guardian Programmer's Guide

Table Of Contents
Managing Time
Guardian Programmer’s Guide 421922-014
18 - 21
A Sample Long-Range Timer
JULIANTIMESTAMP procedure shows that the desired system time has not yet been
reached.
The user can run the program with no parameters to see the current system time. For
example,
10> RUN TIMER
causes the program to display the system time, in both GMT and LCT, and then to
terminate. The user can set a timer by specifying a time of day in the form
hour minute. A 24-hour clock is always used. For example, to specify the time
14:35, enter the command
11> RUN TIMER 14 35
If it is already past the specified time of day, the timer is set for that time on the
following day. The program then displays the desired system time, in both GMT and
LCT, and displays the number of interval units (0.01 second each) until the halfway
point. At the halfway point, the program displays an indication that there has been a
“timer pop” (timer expiration), displays the time of the timer pop, and displays the
number of interval units until the next interim point. It continues in this manner until it
indicates that the desired system time has been reached.
The main() function contains the main processing loop. It calls the TargetGMT()
function to compute the GMT of the desired system time, and calls the
SetupTimeout() function to implement the “series of intervals” algorithm. For each
timer that is set, the main() function reads $RECEIVE to receive the timeout
message and then calls the SetupTimeout() function again to check if the target has
been reached and, if not, to set a timer for the next interval.
The code for the program follows:
#include <cextdecs>
#include <ktdmtyp.h>
#include <tal.h>
#include <stdio.h>
#include <stdlib.h>
#define GET_GMT 0
#define GMT_TO_LCT 0
#define LCT_TO_GMT 2
#define MY_NODE -1
#define ELAPSED_TIME_TIMEOUT -22
#define SYSTEM_MSG_RECVD 6
#define MAX_TIMEOUT_CENTISECS 0x7FFFFFFF
void showTime(int64 jt, char *txt)
{
int16 err;
int16 DT[8];
INTERPRETTIMESTAMP(jt,DT);
printf("GMT: %d/%02d/%02d %02d:%02d:%02d.%03d%03d",
DT[0],DT[1],DT[2],DT[3],DT[4],DT[5],DT[6],DT[7]);