home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sources / 3b1 / 82 next >
Encoding:
Internet Message Format  |  1992-09-04  |  34.4 KB

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