home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / 3b1 / volume02 / nistchk / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-09-03  |  34.3 KB

  1. Path: comp-sources-3b1
  2. From: zebra!vern (Vernon C. Hoxie)
  3. Subject:  v02i029:  NIST.timechk, version 2.1, Part01/02
  4. Newsgroups: comp.sources.3b1
  5. Approved: dave@galaxia.network23.com
  6. X-Checksum-Snefru: 41c2cca0 a782d1f2 eca4b6b8 ee982173
  7.  
  8. Submitted-by: zebra!vern (Vernon C. Hoxie)
  9. Posting-number: Volume 2, Issue 29
  10. Archive-name: nistchk/part01
  11.  
  12. [ Hello Boys and Girls..                                                   ]
  13. [ I have finally returned from my vacation and managed to wade my way all  ]
  14. [ the way through my mailbox.  This was the only source submitted during   ]
  15. [ the month I was away, so source postings are now up to date.  By the     ]
  16. [ time you read this, the corrupted files in the osu/uunet archives should ]
  17. [ be corrected.                                                            ]
  18. [ Keep those source postings coming and maybe I will be encouraged to dig  ]
  19. [ through my pile of floppies to find some more goodies for you all.       ]
  20. [ Maybe Santa will bring you another set of Dave's nifty utilities!        ]
  21. [ -- Dave                                                                  ]
  22.  
  23. Dave:
  24.     This is revised version of NBS.timechk which is archived at osu
  25. as NBSchk.cpio.Z.  There will be some confusion with the current
  26. NISTime.cpio.Z.  That is from someone else.
  27.  
  28. Vernon C. Hoxie                            {ncar,boulder}!scicom!zebra!vern
  29. 3975 W. 29th Ave.                                       voice: 303-477-1780
  30. Denver, Colo., 80212                                     uucp: 303-455-2670
  31.  
  32. ------------------------------- cut here ----------------------------------
  33. #! /bin/sh
  34. # This is a shell archive.  Remove anything before this line, then unpack
  35. # it by saving it into a file and typing "sh file".  To overwrite existing
  36. # files, type "sh file -c".  You can also feed this as standard input via
  37. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  38. # will see the following message at the end:
  39. #        "End of archive 1 (of 2)."
  40. # Contents:  Files MANIFEST Makefile NIST.info NISTtime.h README
  41. #   log.boot modem.c
  42. # Wrapped by vern@zebra on Thu Aug 27 11:06:30 1992
  43. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  44. if test -f Files -a "${1}" != "-c" ; then 
  45.   echo shar: Will not over-write existing file \"Files\"
  46. else
  47. echo shar: Extracting \"Files\" \(93 characters\)
  48. sed "s/^X//" >Files <<'END_OF_Files'
  49. XFiles
  50. XMANIFEST
  51. XMakefile
  52. XNIST.info
  53. XNISTtime.c
  54. XNISTtime.h
  55. XREADME
  56. Xcalc.c
  57. Xlog.boot
  58. Xmodem.c
  59. Xobm.c
  60. END_OF_Files
  61. if test 93 -ne `wc -c <Files`; then
  62.     echo shar: \"Files\" unpacked with wrong size!
  63. fi
  64. # end of overwriting check
  65. fi
  66. if test -f MANIFEST -a "${1}" != "-c" ; then 
  67.   echo shar: Will not over-write existing file \"MANIFEST\"
  68. else
  69. echo shar: Extracting \"MANIFEST\" \(683 characters\)
  70. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  71. X   File Name        Archive #    Description
  72. X-----------------------------------------------------------
  73. X Files                     1    A list for producing a cpio file
  74. X MANIFEST                  1    
  75. X Makefile                  1    The cook book
  76. X NIST.info                 1    Explaination of NIST time signals
  77. X NISTtime.c                2    The working section
  78. X NISTtime.h                1    Generic includes and variables
  79. X README                    1    Substitute for a manual
  80. X calc.c                    2    Update calculations
  81. X log.boot                  1    To reset clocks when rebooting
  82. X modem.c                   1    Interface to 'smart' modems
  83. X obm.c                     2    Interface to 3b1 On Board Modem
  84. END_OF_MANIFEST
  85. if test 683 -ne `wc -c <MANIFEST`; then
  86.     echo shar: \"MANIFEST\" unpacked with wrong size!
  87. fi
  88. # end of overwriting check
  89. fi
  90. if test -f Makefile -a "${1}" != "-c" ; then 
  91.   echo shar: Will not over-write existing file \"Makefile\"
  92. else
  93. echo shar: Extracting \"Makefile\" \(2291 characters\)
  94. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  95. X#sccs    "@(#)    NIST.time:Makefile    2.1"    8/27/92
  96. X
  97. X# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  98. X#                                                                      *
  99. X#   Copyright (c) July, 24, 1989, August 8, 1992 by Vernon C. Hoxie    *
  100. X#                                                                      *
  101. X#       This source code may be freely distributed as long as this     *
  102. X#       copyright notice is included.  No monetary charges should      *
  103. X#       be made in excess of the cost of copying and distribution.     *
  104. X#                                                                      *
  105. X#       Any profits which might be derived from the sale of this       *
  106. X#       work must be shared with me.  Other monetary contributions     *
  107. X#       will be gratefully accepted.                                   *
  108. X#                                                                      *
  109. X#          Vernon C. Hoxie, zebra!vern, vern@zebra.alphacdc.com        *
  110. X#                                                                      *
  111. X#  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  112. X
  113. X
  114. X
  115. X# Comment the next line for operational version
  116. X# CFLAGS     = -g -DDEBUG -DNOSET
  117. X
  118. X#Comment the next two lines for DEBUGing
  119. XCFLAGS     = -v -O
  120. XLDFLAGS    = -s
  121. X
  122. XLIBS       =
  123. X
  124. XOBJS       = calc.o NISTtime.o modem.o obm.o
  125. XTARGET     = NIST.time
  126. XDEST       = /etc
  127. XSHAREDLIB  = /lib/crt0s.o /lib/shlib.ifile
  128. X
  129. X$(TARGET): $(OBJS)
  130. X    $(LD) $(LDFLAGS) -o $(TARGET) $(OBJS) $(SHAREDLIB)
  131. X
  132. X$(OBJS):  NISTtime.h Makefile
  133. X.c.o:
  134. X    $(CC) $(CFLAGS) -c $<
  135. X
  136. X# You should check "log.boot" to see that it call the correct port.
  137. X# Also, only run this once or you will end up with a whole bunch of
  138. X# these in /etc/rc.
  139. Xboot:
  140. X    cat log.boot >> /etc/rc
  141. X
  142. Xinstall: $(TARGET)
  143. X    chmod 550 ${TARGET}
  144. X    chgrp bin ${TARGET}
  145. X    chown bin ${TARGET}
  146. X    mv ${TARGET} ${DEST}/${TARGET}
  147. X
  148. XLINTFLAGS = -u -x
  149. XLINTLIB   =
  150. XLINTOBJS  = calc.c NISTtime.c modem.c obm.c
  151. Xlint:
  152. X    lint $(LINTFLAGS) $(LINTLIB) $(LINTOBJS)
  153. X
  154. Xclean:
  155. X    rm -f *.o core MANIFEST.BAK
  156. X
  157. Xclobber:    clean
  158. X    rm -rf kit
  159. X    rm -f NIST.time NIST.log NIST.errs
  160. X
  161. XFiles:    clobber
  162. X    find . -print > Files
  163. X    sort Files -o Files
  164. X
  165. Xcpio:
  166. X    cpio -oBvcd < Files > NIST.cpio
  167. X    rm -f NIST.cpio.Z
  168. X    compress NIST.cpio
  169. X
  170. Xkit:
  171. X    mkdir kit
  172. X    makekit -m -s38k -n./kit/Part
  173. END_OF_Makefile
  174. if test 2291 -ne `wc -c <Makefile`; then
  175.     echo shar: \"Makefile\" unpacked with wrong size!
  176. fi
  177. # end of overwriting check
  178. fi
  179. if test -f NIST.info -a "${1}" != "-c" ; then 
  180.   echo shar: Will not over-write existing file \"NIST.info\"
  181. else
  182. echo shar: Extracting \"NIST.info\" \(5294 characters\)
  183. sed "s/^X//" >NIST.info <<'END_OF_NIST.info'
  184. X                             DESCRIPTION OF THE
  185. X                 AUTOMATED COMPUTER TELEPHONE SERVICE (ACTS)
  186. X
  187. X
  188. XThe following is transmitted (at 1200 Baud) after completion of the
  189. Xtelephone connection.
  190. X
  191. X             ? = HELP
  192. X             National Institute of Standards and Technology
  193. X             Telephone Time Service
  194. X
  195. X                                     D  L D
  196. X              MJD  YR MO DA H  M  S  ST S UT1 msADV        <OTM>
  197. X             47999 90-04-18 21:39:15 50 0 +.1 045.0 UTC(NIST) *
  198. X             47999 90-04-18 21:39:16 50 0 +.1 045.0 UTC(NIST) *
  199. X             47999 90-04-18 21:39:17 50 0 +.1 045.0 UTC(NIST) *
  200. X             47999 90-04-18 21:39:18 50 0 +.1 045.0 UTC(NIST) *
  201. X             47999 90-04-18 21:39:19 50 0 +.1 037.6 UTC(NIST) #
  202. X             47999 90-04-18 21:39:20 50 0 +.1 037.6 UTC(NIST) #
  203. X             etc..etc...etc.......
  204. X
  205. XUTC = Universal Time Coordinated, the official world time referred to the
  206. Xzero meridian.
  207. X_________________________________________________________________________
  208. X
  209. XDST = Daylight savings time characters, valid for the continental U.S., are
  210. Xset as follows:
  211. X  00 = We are on standard time (ST).    50 = We are on DST.
  212. X  99 to 51 = Now on ST, go to DST when your local time is 2:00 am and the
  213. X    count is 51.  The count is decremented daily at 00 (UTC).
  214. X  49 to 01 = Now on DST, go to ST when your local time is 2:00 am and the
  215. X    count is 01.  The count is decremented daily at 00 (UTC).
  216. XThe two DST characters provide up to 48 days advance notice of a change in
  217. Xtime.  The count remains at 00 or 50 at other times.
  218. X_________________________________________________________________________
  219. X
  220. XLS = Leap second flag is set to "1" to indicate that a leap second is to be
  221. Xadded as 23:59:60 (UTC) on the last day of the current UTC month.  The LS
  222. Xflag will be reset to "0" starting with 23:59:60 (UTC).  The flag will
  223. Xremain on for the entire month before the second is added.  Leap seconds
  224. Xare added as needed at the end of any month.  Usually June and/or December
  225. Xare chosen.
  226. X
  227. X__________________________________________________________________________
  228. X
  229. XDUT1 = Approximate difference between earth rotation time (UT1) and UTC, in
  230. Xsteps of 0.1 second.         DUT1 = UT1 - UTC
  231. X___________________________________________________________________________
  232. X
  233. XMJD = Modified Julian Date, often used to tag certain scientific data.
  234. X___________________________________________________________________________
  235. X
  236. XThe full time format is sent at 1200 Baud, 8 bit, 1 stop, no parity.
  237. XThe format at 300 Baud is also 8 bit, 1 stop, no parity. 
  238. XAt 300 Baud the MJD and DUT1 values are deleted and the
  239. Xtime is transmitted only on even seconds.
  240. X___________________________________________________________________________
  241. X
  242. XMaximum on line time will be 56 seconds.  If all lines are busy at any time,
  243. Xthe oldest call will be terminated if it has been on line more than 28
  244. Xseconds, else, the call that first reaches 28 seconds will be terminated. 
  245. X___________________________________________________________________________
  246. X
  247. XCurrent time is valid at the "on-time" marker (OTM), either "*" or "#". 
  248. XThe nominal on-time marker (*) will be transmitted 45 ms early to account
  249. Xfor the 8 ms required to send 1 character at 1200 Baud, plus an additional
  250. X7 ms for delay from NIST to the user, and approximately 30 ms "scrambler"
  251. Xdelay inherent in 1200 Baud modems.  If the caller echoes all characters,
  252. XNIST will measure the round trip delay and advance the on-time marker so
  253. Xthat the midpoint of the stop bit arrives at the user on time.  The amount
  254. Xof msADV will reflect the actual required advance in milliseconds and the
  255. XOTM will be a "#".  The NIST system requires 4 or 5 consecutive delay
  256. Xmeasurements which are consistent before switching from "*" to "#".
  257. XIf the user has a 1200 Baud modem with the same internal delay as that used
  258. Xby NIST, then the "#" OTM should arrive at the user within +-2 ms of the
  259. Xcorrect time.  However, NIST has studied different brands of 1200 Baud
  260. Xmodems and found internal delays from 24 ms to 40 ms and offsets of the
  261. X"#" OTM of +-10 ms.  For many computer users, +-10 ms accuracy should be
  262. Xmore than adequate since many computer internal clocks can only be set with
  263. Xgranularity of 20 to 50 ms.  In any case, the repeatability of the offset
  264. Xfor the "#" OTM should be within +-2 ms, if the dial-up path is reciprocal
  265. Xand the user doesn't change the brand or model of modem used. This should
  266. Xbe true even if the dial-up path on one day is a land-line of less than
  267. X40 ms (one way) and on the next day is a satellite link of 260 to 300 ms.
  268. XIn the rare event that the path is one way by satellite and the other way
  269. Xby land line with a round trip measurement in the range of 90 to 260 ms,
  270. Xthe OTM will remain a "*" indicating 45 ms advance.
  271. X___________________________________________________________________________
  272. X
  273. XFor user comments write:
  274. XNIST-ACTS
  275. XTime and Frequency Division
  276. XMail Stop 524
  277. X325 Broadway
  278. XBoulder, CO  80303
  279. X
  280. XSoftware for setting (PC)DOS compatable machines is available
  281. Xon a 360-kbyte diskette for $35.00 from:
  282. XNIST Office of Standard Reference Materials
  283. XB311-Chemistry Bldg, NIST, Gaithersburg, MD, 20899, (301) 975-6776
  284. X
  285. X--------------------------------------------------------------------------
  286. X--------TIME CODE GENERATOR C
  287. END_OF_NIST.info
  288. if test 5294 -ne `wc -c <NIST.info`; then
  289.     echo shar: \"NIST.info\" unpacked with wrong size!
  290. fi
  291. # end of overwriting check
  292. fi
  293. if test -f NISTtime.h -a "${1}" != "-c" ; then 
  294.   echo shar: Will not over-write existing file \"NISTtime.h\"
  295. else
  296. echo shar: Extracting \"NISTtime.h\" \(4584 characters\)
  297. sed "s/^X//" >NISTtime.h <<'END_OF_NISTtime.h'
  298. X#sccs    "@(#)    NIST.time:NISTtime.h    2.1"    8/27/92
  299. X
  300. X/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  301. X *                                                                     *
  302. X *  Copyright (c) July, 24, 1989, August 8, 1992 by Vernon C. Hoxie    *
  303. X *                                                                     *
  304. X *      This source code may be freely distributed as long as this     *
  305. X *      copyright notice is included.  No monetary charges should      *
  306. X *      be made in excess of the cost of copying and distribution.     *
  307. X *                                                                     *
  308. X *      Any profits which might be derived from the sale of this       *
  309. X *      work must be shared with me.  Other monetary contributions     *
  310. X *      will be gratefully accepted.                                   *
  311. X *                                                                     *
  312. X *         Vernon C. Hoxie, zebra!vern, vern@zebra.alphacdc.com        *
  313. X *                                                                     *
  314. X * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  315. X
  316. X
  317. X
  318. X
  319. X#include <errno.h>
  320. X#include <fcntl.h>
  321. X#include <malloc.h>
  322. X#include <setjmp.h>
  323. X#include <stdio.h>
  324. X#include <termio.h>
  325. X#include <sys/ioctl.h>
  326. X#include <sys/signal.h>
  327. X#include <sys/param.h>
  328. X#include <sys/phone.h>
  329. X
  330. X#define DEVPATH "/dev/"
  331. X#define LCKPATH "/usr/spool/uucp/LCK.."
  332. X
  333. X    /* Comment out the options you don't want. */
  334. X#define UNIXPC            /* Updates the real time clock also.   */
  335. X#define OBM             /* If you want a 'ph0' or 'ph1' option */
  336. X/* #define QUIET        /* Turns the modem speaker off         */
  337. X#define TONE            /* Sets OBM for Touch Tone dialing.    */
  338. X    /* On a UNIXPC, you can have both OBM and EXTERNAL  */
  339. X#define EXTERNAL        /* If you want a 'tty###' option */
  340. X
  341. X/* Set these values appropiate for your system.  The value for           */
  342. X/* INIT_BAUD is termio.h macro for the baud rate your modem uses for   */
  343. X/* the quiesent state.                                                 */
  344. X/* RUN_BAUD is the speed the computer should use when talking to NIST. */
  345. X/* RUN_CHAT is a series of commands to the modem for use during        */
  346. X/* the conversation.                                                   */
  347. X
  348. X/* Set this to quiesent speed of your modem.  B19200 works on my       */
  349. X/* TrailBlazer for 'uucico' but it has to be B9600 here.  I don't      */
  350. X/* know why. */
  351. X#define INIT_BAUD B9600                                  /*  */
  352. X
  353. X/* For modems set to autobaud, use these options. */
  354. X#define RUN_BAUD B1200                                        /*  */
  355. X#define RUN_CHAT "ATS0=0S50=2S51=1S95=0\r\n"            /*  */
  356. X
  357. X/* For modems lacked at 19200, use these options. */
  358. X/* #define RUN_BAUD B19200                                    /*  */
  359. X/* #define RUN_CHAT "ATS0=0S50=2S51=5S95=0\r\n"        /*  */
  360. X
  361. X/* You should be sure that all modems are set to not echo commands     */
  362. X/* during the run state.  Try these settings for MICOM.                */
  363. X/* #define RUN_BAUD B1200            /*  */
  364. X/* #define RUN_CHAT "ATQ\r\n"        /*  */
  365. X
  366. X/* There is a section in 'modem.c' which dials the number.  This code   */
  367. X/* uses the ATDT sequence of commands.  If your modem requires some     */
  368. X/* other protocol, the code will have to be altered.                    */
  369. X
  370. X/* This is  long distance number, for Local calls use 494-4774          */
  371. X/* Notes to users who may require specal dialing sequences such         */
  372. X/* as needed on PBX's:                                                  */
  373. X/* The OBM uses 'phone(7)'.   Refer to the 'phone(7)' manual, page 4,   */
  374. X/* for special commands.  The trailing '@' is compiled in.              */
  375. X
  376. X/* #define PHNUM "13034944774"    /* */
  377. X#define PHNUM "4944774"             /* */
  378. X
  379. X    /* Comment this out if you don't have a 'uugetty'      */
  380. X    /* running.  It is not needed if you use a call        */
  381. X    /* out only line.  It is gennerally required for       */
  382. X   /* the OBM.                                            */
  383. X#define DUMPGETTY                            /*  */
  384. X
  385. X#ifdef DEBUG
  386. X/* #define NOSET        /* Disable corrections during DEBUG */
  387. X#define LOG_NAME "NIST.log"
  388. X#define LOG_ERRS "NIST.errs"
  389. X#define TMP_ERRS "NIST.tmp"
  390. X#else
  391. X#define LOG_NAME "/usr/adm/NIST.log"
  392. X#define LOG_ERRS "/usr/adm/NIST.errs"
  393. X#define TMP_ERRS "/tmp/NIST"
  394. X#endif
  395. X#define LOG_SIZE 23           /* size in lines ( One full screen ) */
  396. X#define ERR_SIZE 2048         /* 2048 size in bytes */
  397. X
  398. Xint tiofd;
  399. Xint hasLock;
  400. Xint boot;
  401. Xchar lck_file[ 30 ];
  402. Xchar nist_file[ 30 ];
  403. Xjmp_buf place;
  404. Xstruct termio old_getty;
  405. X
  406. Xextern char *sys_errlist;
  407. Xextern int errno;
  408. X
  409. X#ifdef OBM
  410. Xstruct updata old_phset;
  411. X#endif
  412. X
  413. X#ifdef DUMPGETTY
  414. Xchar had_getty;
  415. X#endif
  416. END_OF_NISTtime.h
  417. if test 4584 -ne `wc -c <NISTtime.h`; then
  418.     echo shar: \"NISTtime.h\" unpacked with wrong size!
  419. fi
  420. # end of overwriting check
  421. fi
  422. if test -f README -a "${1}" != "-c" ; then 
  423.   echo shar: Will not over-write existing file \"README\"
  424. else
  425. echo shar: Extracting \"README\" \(9465 characters\)
  426. sed "s/^X//" >README <<'END_OF_README'
  427. X    This program calls the National Institute of Standards and
  428. XTechnology ( NIST ) in Boulder, Colorado.  It accesses their modem which
  429. Xtransmits precision time in ASCII format.  Eight samples of the time
  430. Xdifferences are collected and the average difference is calculated.  The
  431. Xsystem software time clock and the hardware Real Time Clock ( RTC ) are
  432. Xthen corrected by that average amount.
  433. X
  434. X    When invoked with the '-i' ( for initialize ), the first sample
  435. Xis used to set the complete date.  Eight samples are then collected to
  436. Xrefine the seconds value.  The '-c' ( for correction ) assumes that the
  437. Xclock is correct to the nearest day, will only make corrections to
  438. Xhours, minutes and seconds.
  439. X
  440. X    Although the NIST data is accurate to milli-seconds, corrections
  441. Xare made only to one second accuracy.  NIST does have a program which
  442. Xwill provide the fullest accuracy possible.  This is available via FTP
  443. Xfrom them.  More information about this may be obtained from the Time
  444. Xand Frequency Division of the National Institute of Standards and
  445. XTechnology.  Their phone number is 1-303-497-3276.
  446. X
  447. X    This program is intended to be run from the '/usr/lib/crontab'
  448. Xwith an entry of:
  449. Xmm hh * * * /bin/su root % /etc/NIST.time -c tty###
  450. X
  451. Xor:
  452. Xmm hh * * * /bin/su root % /etc/NIST.time -c ph#
  453. X
  454. Xwhere 'mm' and 'hh' are minutes and hours of your choice.  If experience
  455. Xshows that your clock is accurate over longer periods, appropriate
  456. Xrevisions to this entry can be made.  See cron(1M).
  457. X
  458. X    I have tried to implement this so that it will create the least
  459. Xdisturbance to the 'cron' controlled functions.  You should avoid
  460. Xscheduling anything in the same minute or the minute following
  461. X'NIST.time'.
  462. X
  463. X    Every time the program is run, an entry is made into the file
  464. X"/usr/adm/NIST.log".  The size of this log is limited to 23 lines which
  465. Xis one screen full on the 3b1 when called by more(1) .  The new entries
  466. Xare made to the top of the page and the oldest is deleted.  Entries are
  467. Xof the form:
  468. X
  469. XSat Aug  8 09:23:44 1992, Sys. Corr:  -2 sec. RTC Corr:  -1 sec.  50 dst
  470. X
  471. XThe initial date and time are the time prior to correction of the
  472. Xclocks.  Following are the corrections to the System clock and RTC.  In
  473. Xthis example, the system clock was 2 seconds fast and was corrected by
  474. Xminus 2 seconds.  The last entry is merely a notation copied from the
  475. XNIST data.  Read the NIST.info files to understand the meaning of this
  476. Xentry.
  477. X
  478. X    Error messages are logged in "/usr/adm/NIST.errs".  This file is
  479. Xmaintained at less than 2024 bytes in reverse chronological order.
  480. XHopefully they are sufficient to explain failures.
  481. X
  482. X    The shell script. 'log.boot', is included if you want to reset
  483. Xyour clock when you reboot.  It should be placed as the very last
  484. Xitem in '/etc/rc'.  This gives the user the option to call or not call
  485. Xfor a time correction.  When the user opts to call the NIST, the program
  486. Xwill run in the background with 'nohup' so that he/she can proceed
  487. Xthrough the login process while the corrections to the clock are being
  488. Xmade.  This is particularily helpful if the hardware clock battery has
  489. Xgone dead.
  490. X
  491. X    Installation of this feature is not part of the "make install"
  492. Xscript.  You can install it with this command:
  493. X$ cat log.boot >> /etc/rc
  494. X
  495. X**************************  Reference Manual *************************
  496. X
  497. X    Command line options are:
  498. X
  499. X    -c    This compares the system time with the time received
  500. X        from NIST.  Corrections are parsed at 30 seconds per
  501. X        minute.  This is the option to use from cron.
  502. X
  503. X    -i    This zeroes the system time and resets it with the
  504. X        information received from NIST.  This can be run in
  505. X        '/etc/rc' during boot or from the shell by 'su'.
  506. X        It is intended for systems with dead batteries for
  507. X        the clock.  See the file "log.boot" for a recommended
  508. X        script.
  509. X
  510. X    tty###    This field should contain the device to which a modem
  511. X    ph#    is connected to make the call to NIST.
  512. X
  513. XNote:  Lenny Tropiano's 'dstconvert' should be installed to correct the
  514. Xdate which the spring daylight savings time is made.
  515. X
  516. XCAUTION:  The use of 'ph0' or 'ph1' must agree with the way your system
  517. Xis configured from the "Install" window.  If you have a single line and
  518. Xselect 'ph0' for 'NIST.time' you are OK.  If you have two lines and
  519. Xhave the system configured for data on 'ph1' and 'NIST.time'
  520. Xcalls out on 'ph1', you are OK.  But if you have the system configured
  521. Xwith 'ph1' as data and you call 'NIST.time' with 'ph0', you will find
  522. Xtrouble, the 'phtoggle(1)' used in this program will toggle 'ph1' to
  523. XVOICE instead of toggling 'ph0' to DATA.
  524. X
  525. XTesting:
  526. X
  527. X    If the beginning of the Makefile is changed from:
  528. X
  529. X#CFLAGS     = -g -DDEBUG -DNOSET
  530. X
  531. XCFLAGS     = -v -O
  532. XLDFLAGS    = -s
  533. X
  534. X    to:
  535. X
  536. XCFLAGS     = -g -DDEBUG -DNOSET
  537. X
  538. X#CFLAGS     = -v -O
  539. X#LDFLAGS    = -s
  540. X
  541. X
  542. Xthe result will be writen to the NIST.log file in the current
  543. Xdirectory. Error messages will be writen to NIST.errs, also in the
  544. Xcurrent directory.  Additional 'debugging' messages will be printed to
  545. Xthe screen.  The test program must be run by 'su' because of the parts
  546. Xwhich dump the 'uugetty'.
  547. X
  548. X    Corrections to the clocks will be made in DEBUG mode if the
  549. XNOSET flag in 'time.h' is commented out and deleted from the Makefile.
  550. X
  551. X    This was designed for possible use on other systems so some of
  552. Xthe complexity is superfluous.  For instance, 'geton.sh' and 'getoff.sh'
  553. Xcould have been used instead of the 'dump_getty' function.  Also, the
  554. Xcompile options to exclude the OBM add to the confusion.
  555. X
  556. X    If you are not using a 'uugetty' on the port, make the appropriate
  557. Xchanges to the #defines in 'NIST.time.h', then the testing procedure
  558. Xmay be run in 'user' mode.  Operations with the OBM always require you
  559. Xto be 'root' durinf testing/
  560. X
  561. XInstallation:
  562. X
  563. XThe options in 'NIST.time.h' are:
  564. X
  565. X    DEVPATH, The pathname to where where your device drivers are
  566. Xstored.
  567. X
  568. X    LCKPATH, The pathname and file prefix to where the uucp lock
  569. Xfiles are kept.
  570. X    UNIXPC, the includes code to update the Real Time Clock ( RTC )
  571. Xas well as systime(2).  Other systems which require special commands to
  572. Xchange a hardware clocks will have to make their own modifications to
  573. Xthe code.
  574. X
  575. X    OBM, this allows the selection of either "ph0" or "ph1" as the
  576. Xport from a Unix-pc.  You must have the system configured for the line you
  577. Xtell 'NIST.time' to use.
  578. X
  579. X    QUIET, only pertinent to the On Board Modem for the UnixPc. 
  580. XCauses the call to be made without using the system speaker.
  581. X
  582. X    EXTERNAL,  this allows you to select a port "/dev/tty###" for
  583. Xuse with an external modem.
  584. X
  585. X    TRAILBLAZER, the 'chat' script in 'modem.c' is set up for a
  586. XTelebit TrailBlazer.  You will have to make your own revisions if you
  587. Xare using another make or model.  Send these revisions to me so that
  588. Xthey may be included in future releases.  Options are included for
  589. Xoperations with the computer/modem baud rate locked at 19200.
  590. X
  591. X    MICOM, issues a command to wake up the modem.  See the comments
  592. Xin time.h.
  593. X
  594. X    DUMPGETTY, this removes a 'uugetty' that might be running on the
  595. Xselected external port.  It is not needed if the port is 'call out' only.
  596. XIt is coded in for the OBM operation.  When included, the program may be
  597. Xrun only by 'su' whether compiled with DEBUG set or not.
  598. X
  599. X    NOSET, inhibits corrections to the clock.  It is only effective
  600. Xwhen the -DDEBUG option is set in the 'Makefile'.
  601. X
  602. X    The 'Makefile' references the Unix-pc calls to the systems
  603. Xshared library.  You may have to revise these to the libraries which are
  604. Xused on your system.
  605. X
  606. XAcknowledgments:
  607. X
  608. X    The present incarnation includes a 'Makefile" generated by
  609. Xprogram called 'mmk'.  It was kindly supplied to me by Tanya Katz.
  610. XAn 'install:' option has been added.
  611. X
  612. X    There is also a function called 'do_getty()' which is a
  613. Xvariation of a program posted to the net by John Milton.
  614. X
  615. X    A handy little function called 'mpause()' is a direct steal from
  616. XKermit.  Other parts of this program were also inspired by the Kermit
  617. Xrelease.  ( Check this in 'utils.c' for the clock freq of your system. )
  618. X
  619. X    Augustine Cano provided the chat script for using a WORLDBLAZER
  620. Xwith the interface speed locked to 19200.
  621. X
  622. XTo Do:
  623. X
  624. X    Include options for other modems.  (Depending upon feedback from
  625. X        other users).
  626. X    Someone else to port it to versions of Unix other than SysV.
  627. X
  628. XRevised Jan 3, 1990.
  629. X1.    Deleted reference to options for daylight savings time date
  630. X    changes.  See the comments above about 'dstconvert()'.
  631. X2.    Changed location of 'log.boot' reccomendation from '/etc/daemons'
  632. X    to '/etc/rc'.
  633. X
  634. XRevised May 30, 1990
  635. X1.    Added reference to MICOM and ACTIVE.
  636. X2.    Rewrote part pf open_tty() per suggestion from Karl Swartz ( ditka ).
  637. X
  638. XRevised July 26, 1991
  639. X1.    Added sleep(2) to modem.c and obm.c.
  640. X2.    Revised some of the error messages.
  641. X3. Revised LCK.. file sequence per suggestion from Karl Swartz.
  642. X3.    Rewrote trunc_errs().
  643. X
  644. XVersion 2.0, August 8, 1992.
  645. X1.    Major rewrite of the OBM run_obm() sequence.
  646. X2.    Made only one 'struct termio'.  Revisons made at appropiate time
  647. X    with the code.
  648. X3.    Changed the reading of data from reading at a line at time to
  649. X    reading single characters and forming the test line within the
  650. X    code.  This is because of problems with the OBM reading correctly.
  651. X4. Also changed the read technique in 'modem.c' for consistency.
  652. X4.    Changed the name from "NBS.timechk" to "NIST.time" in accordance
  653. X    with the name change of the facility.  Other references to NBS
  654. X    also changed.
  655. X
  656. XVernon C. Hoxie               {ncar,nbires,boulder,isis}!scicom!zebra!vern
  657. X3975 W. 29th Ave.                    voice: 303-477-1780
  658. XDenver, Colo., 80212                ( TB+ )  uucp: 303-455-2670
  659. END_OF_README
  660. if test 9465 -ne `wc -c <README`; then
  661.     echo shar: \"README\" unpacked with wrong size!
  662. fi
  663. # end of overwriting check
  664. fi
  665. if test -f log.boot -a "${1}" != "-c" ; then 
  666.   echo shar: Will not over-write existing file \"log.boot\"
  667. else
  668. echo shar: Extracting \"log.boot\" \(655 characters\)
  669. sed "s/^X//" >log.boot <<'END_OF_log.boot'
  670. X# This can be added to the end of your '/etc/rc' script to query the
  671. X# user about calling NIST for a time check during reboot.  It will
  672. X# make the call in the background while you continue to login.
  673. X# Revised May 30, 1990
  674. X# Revised Aug 8, 1992
  675. X
  676. Xmessage -i "Do you wish to call the National Institute
  677. X    of Standards and Technology to reset the time?\n
  678. XEnter <Cancel> to cancel the call.
  679. XEnter <Return> to make the call. "
  680. Xif [ $? -eq 0 ]
  681. Xthen
  682. X    nohup /etc/NIST.time -i ph0 &
  683. Xfi
  684. XTMPFILE=/usr/adm/old.log
  685. XLOGFILE=/usr/adm/NIST.log
  686. Xmv $LOGFILE $TMPFILE
  687. Xnow=`date '+%a %h %d %H:%M:%S 19%y'`
  688. Xecho "$now, Rebooted." > $LOGFILE
  689. Xcat $TMPFILE >> $LOGFILE
  690. Xrm $TMPFILE
  691. END_OF_log.boot
  692. if test 655 -ne `wc -c <log.boot`; then
  693.     echo shar: \"log.boot\" unpacked with wrong size!
  694. fi
  695. chmod +x log.boot
  696. # end of overwriting check
  697. fi
  698. if test -f modem.c -a "${1}" != "-c" ; then 
  699.   echo shar: Will not over-write existing file \"modem.c\"
  700. else
  701. echo shar: Extracting \"modem.c\" \(5396 characters\)
  702. sed "s/^X//" >modem.c <<'END_OF_modem.c'
  703. X#sccs    "@(#)    NIST.time:modem.c    2.1"    8/27/92
  704. X
  705. X/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  706. X *                                                                     *
  707. X *  Copyright (c) July, 24, 1989, August 8, 1992 by Vernon C. Hoxie    *
  708. X *                                                                     *
  709. X *      This source code may be freely distributed as long as this     *
  710. X *      copyright notice is included.  No monetary charges should      *
  711. X *      be made in excess of the cost of copying and distribution.     *
  712. X *                                                                     *
  713. X *      Any profits which might be derived from the sale of this       *
  714. X *      work must be shared with me.  Other monetary contributions     *
  715. X *      will be gratefully accepted.                                   *
  716. X *                                                                     *
  717. X *         Vernon C. Hoxie, zebra!vern, vern@zebra.alphacdc.com        *
  718. X *                                                                     *
  719. X * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  720. X
  721. X
  722. X
  723. X#include "NISTtime.h"
  724. X
  725. Xextern struct termio my_getty;
  726. X#ifdef EXTERNAL
  727. X
  728. X    /* Return values from this function have the following meaning: */
  729. X    /*    -1 System failure, abort.                                 */
  730. X    /*     0 Success, proceed to perform 'update()'                 */
  731. X    /*    NN A failure in the communication link.  The value        */
  732. X    /*       returned to 'main()' signifies the amount of           */
  733. X    /*       seconds to sleep before retrying.                      */
  734. X
  735. Xint run_mod( dev )
  736. Xchar *dev;
  737. X{
  738. X    extern void sig_sleep( );
  739. X    extern void sig_timeout( );
  740. X    extern int lock_it( );
  741. X    extern int open_tty( );
  742. X#ifdef DUMPGETTY
  743. X    extern int do_getty( );
  744. X#endif
  745. X    int chat();
  746. X    int c_flag;
  747. X
  748. X    int j, k;
  749. X    char buf[85];
  750. X    char *err_msg;
  751. X    tiofd = 0;
  752. X
  753. X    if (( j = lock_it( dev )) != 0 )
  754. X    {
  755. X        printf( "lock_it() returned %d\n", j );
  756. X        return( j );
  757. X    }
  758. X#ifdef DUMPGETTY
  759. X    if (( j = do_getty( dev, ':' )) < 0 ) return( -1 );
  760. X#endif     /* DUMPGETTY */
  761. X
  762. X    if (( tiofd = open_tty( dev ) ) < 0 ) return( -1 );
  763. X    err_msg = "Setting up modem.\n";
  764. X    alarm( 20 );
  765. X    signal( SIGALRM, sig_timeout );
  766. X    if (( j = setjmp( place ) ) != 0 )
  767. X    {
  768. X        fprintf( stderr, err_msg );
  769. X        return( 5 );
  770. X    }
  771. X
  772. X/* Start of modem specific sequences, modify to your own modem */
  773. X
  774. X        /* Sends "A's" for the modem to sync on */
  775. X    
  776. X     for ( j = 0; j < 5; j++ )
  777. X    {
  778. X        write( tiofd, "A\n\r", 4 );
  779. X        mpause( 5 );
  780. X    }
  781. X#ifdef DEBUG
  782. X    printf( "Running first 'AT OK'.\n" );
  783. X#endif
  784. X
  785. X    if (( j = chat( 5, "AT\r\n", "OK" ) ) != 0 ) return( j );
  786. X
  787. X    err_msg = "Changing speed.\n";
  788. X#ifdef DEBUG
  789. X    printf( "Setting speed to %o.\n", RUN_BAUD );
  790. X#endif
  791. X    if (( j = chat( 5, RUN_CHAT, "OK" ) ) != 0 )
  792. X        return( j );
  793. X    c_flag = my_getty.c_cflag & ~(CBAUD | CLOCAL );
  794. X
  795. X    my_getty.c_cflag = c_flag | RUN_BAUD;
  796. X    if (( ioctl( tiofd, TCSETA, &my_getty ) ) < 0 )
  797. X    {
  798. X        fprintf( stderr, "run_mod(), TCSETA my_getty, %s\n",
  799. X                sys_errlist[errno] );
  800. X        return( -1 );
  801. X    }
  802. X
  803. X#ifdef DEBUG
  804. X    printf( "Dialing.\n" );
  805. X#endif
  806. X
  807. X    mpause( 500 );                            /* 1/2 seconds */
  808. X    err_msg = "Dialing modem.\n";
  809. X    strcat( strcat (strcpy( buf, "ATDTW" ), PHNUM ), "\r\n" );
  810. X
  811. X            /* Key on the first word received
  812. X             * instead of CONNECT from the modem. */
  813. X    if (( j = chat( 35, buf, "HELP" )) != 0 )
  814. X                 return( j );
  815. X
  816. X#ifdef DEBUG
  817. X    printf( "Starting to read.\n" );
  818. X#endif
  819. X    alarm( 20 );
  820. X    if (( j = setjmp( place ) ) != 0 ) {
  821. X        fprintf( stderr, err_msg );
  822. X        return( 5 );
  823. X    }
  824. X
  825. X    err_msg = "Reading modem.\n";
  826. X     for( k = 0; k < 8; ) {
  827. X        register char *p, *q;
  828. X
  829. X        q = buf + sizeof( buf );
  830. X        for ( p = buf; p < q; *p++ = '\0' );
  831. X        for ( p = buf; *p != '\n' && p < q; ) {
  832. X            read( tiofd, p, 1 );
  833. X            if (( *p >= ' ' && *p <= '~' )) *p++;
  834. X        }
  835. X#ifdef DEBUG
  836. X        if (( j = p - buf ) > 0 )
  837. X            printf( "%d %d >%c< %s", k, j, *(p-1), buf );
  838. X#endif
  839. X        for ( q = buf; q < p; q++ ) {
  840. X            char *bpt, *npt;
  841. X
  842. X            bpt = q;
  843. X            npt = "NO CARRIER" ;
  844. X            while ( *bpt == *npt ) bpt++, npt++;
  845. X            if ( ! *npt )
  846. X            {
  847. X                fprintf( stderr, "Lost Carrier\n" );
  848. X                return( 20 );
  849. X            }
  850. X        }
  851. X        if ( *--p == '*' || *p == '#' ) k += get_data( buf );
  852. X    }
  853. X    return( 0 );
  854. X}
  855. X
  856. Xint chat( secs, tx, rx )
  857. Xint secs;
  858. Xchar *tx, *rx;
  859. X{
  860. X    int j;
  861. X    char buf[30];
  862. X    char *busy = "BUSY";
  863. X    char *expect, *bpt, *pbusy;
  864. X    
  865. X    alarm( secs );
  866. X     if (( j = write( tiofd, tx, strlen( tx ) )) < 0 )
  867. X    {
  868. X        fprintf( stderr, "Couldn't write to modem.\n" );
  869. X        return( -1 );
  870. X    }
  871. X#ifdef DEBUG
  872. X    printf( "Send: >%s<\nExpect: >%s<\n", tx, rx );
  873. X#endif
  874. X
  875. X    pbusy = busy;
  876. X    expect = rx;
  877. X    while ( 1 )
  878. X    {
  879. X        j = read( tiofd, buf, sizeof( buf ));
  880. X        if ( j < 0 )
  881. X        {
  882. X            fprintf( stderr, "Couldn't read from modem.\n" );
  883. X            return( -1 );
  884. X        }
  885. X#ifdef DEBUG
  886. X        if ( j > 0 ) printf( "j = %d bytes, Got: >%s<\n", j, buf );
  887. X#endif
  888. X        bpt = buf;
  889. X        while ( j > 0 )
  890. X        {
  891. X            if ( *bpt == *expect ) expect++;
  892. X            else expect = rx;
  893. X            if ( ! *expect ) return( 0 );
  894. X                /* Test for "BUSY" */
  895. X            if ( *bpt == *pbusy ) pbusy++;
  896. X            else pbusy = busy;
  897. X            if ( ! *pbusy )
  898. X            {
  899. X                fprintf( stderr,
  900. X                    "Line busy, wait 3 min.\n");
  901. X                return( 180 );
  902. X            }
  903. X            bpt++;
  904. X            j--;
  905. X        }
  906. X    }
  907. X}        /* chat() */
  908. X
  909. X#else
  910. X    /* Dummy if compiled as OBM only */
  911. Xint run_mod( dev )
  912. Xchar *dev;
  913. X
  914. X{
  915. X    fprintf( stderr,
  916. X "You need to set the EXTERNAL flag in NIST.time.h' and recompile \n" );
  917. X    fprintf( stderr,
  918. X "in order to use a modem connected to the '/dev/%s port.\n", dev );
  919. X    return( 0 );
  920. X}
  921. X
  922. X#endif        /* EXTERNAL */
  923. X
  924. END_OF_modem.c
  925. if test 5396 -ne `wc -c <modem.c`; then
  926.     echo shar: \"modem.c\" unpacked with wrong size!
  927. fi
  928. # end of overwriting check
  929. fi
  930. echo shar: End of archive 1 \(of 2\).
  931. cp /dev/null ark1isdone
  932. MISSING=""
  933. for I in 1 2 ; do
  934.     if test ! -f ark${I}isdone ; then
  935.     MISSING="${MISSING} ${I}"
  936.     fi
  937. done
  938. if test "${MISSING}" = "" ; then
  939.     echo You have unpacked both archives.
  940.     rm -f ark[1-9]isdone
  941. else
  942.     echo You still need to unpack the following archives:
  943.     echo "        " ${MISSING}
  944. fi
  945. ##  End of shell archive.
  946. exit 0
  947.  
  948. -- 
  949. Vernon C. Hoxie                            {ncar,boulder}!scicom!zebra!vern
  950. 3975 W. 29th Ave.                                       voice: 303-477-1780
  951. Denver, Colo., 80212                                     uucp: 303-455-2670
  952. -- 
  953. David H. Brierley
  954. Home: dave@galaxia.network23.com; Work: dhb@quahog.ssd.ray.com
  955. Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.network23.com
  956. %% Can I be excused, my brain is full. **
  957.