A GPS disciplined clock
Dependencies: net lpc1768 crypto clock web log
web-this/home/web-home-script.js@93:2cce06dd2bcc, 2020-04-03 (annotated)
- Committer:
- andrewboyson
- Date:
- Fri Apr 03 08:15:37 2020 +0000
- Revision:
- 93:2cce06dd2bcc
- Parent:
- 87:5052e316994a
Increased NMEA confidence delay from 10 to 20 minutes after an incident where it took 13 minutes to settle.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 60:7cab896b0fd4 | 1 | //Home script |
andrewboyson | 27:eb5728b9052b | 2 | 'use strict'; |
andrewboyson | 27:eb5728b9052b | 3 | |
andrewboyson | 60:7cab896b0fd4 | 4 | let rtc = new Clock(); |
andrewboyson | 60:7cab896b0fd4 | 5 | |
andrewboyson | 60:7cab896b0fd4 | 6 | let diffMs = 0; |
andrewboyson | 27:eb5728b9052b | 7 | |
andrewboyson | 87:5052e316994a | 8 | let messagesOk = false; |
andrewboyson | 87:5052e316994a | 9 | let fixMessagesOk = false; |
andrewboyson | 87:5052e316994a | 10 | let timeMessagesOk = false; |
andrewboyson | 87:5052e316994a | 11 | let ppsStable = false; |
andrewboyson | 87:5052e316994a | 12 | let nmeaStable = false; |
andrewboyson | 87:5052e316994a | 13 | |
andrewboyson | 60:7cab896b0fd4 | 14 | let rtcIsSet = false; |
andrewboyson | 60:7cab896b0fd4 | 15 | let clockIsSet = false; |
andrewboyson | 87:5052e316994a | 16 | let sourceIsOk = false; |
andrewboyson | 60:7cab896b0fd4 | 17 | let rateIsLocked = false; |
andrewboyson | 60:7cab896b0fd4 | 18 | let timeIsLocked = false; |
andrewboyson | 27:eb5728b9052b | 19 | |
andrewboyson | 60:7cab896b0fd4 | 20 | const DISPLAY_LEAP_MS = 10000; |
andrewboyson | 60:7cab896b0fd4 | 21 | |
andrewboyson | 60:7cab896b0fd4 | 22 | function parse() |
andrewboyson | 27:eb5728b9052b | 23 | { |
andrewboyson | 60:7cab896b0fd4 | 24 | let lines = Ajax.response.split('\n'); |
andrewboyson | 60:7cab896b0fd4 | 25 | rtc.ms = Ajax.date.getTime(); |
andrewboyson | 60:7cab896b0fd4 | 26 | rtc.ms += parseInt(lines[0], 16); |
andrewboyson | 60:7cab896b0fd4 | 27 | rtc.ms -= Ajax.ms; |
andrewboyson | 60:7cab896b0fd4 | 28 | diffMs = rtc.ms + Ajax.ms - Date.now(); |
andrewboyson | 87:5052e316994a | 29 | messagesOk = Ajax.hexToBit(lines[1], 11); |
andrewboyson | 87:5052e316994a | 30 | fixMessagesOk = Ajax.hexToBit(lines[1], 10); |
andrewboyson | 87:5052e316994a | 31 | timeMessagesOk = Ajax.hexToBit(lines[1], 9); |
andrewboyson | 87:5052e316994a | 32 | ppsStable = Ajax.hexToBit(lines[1], 8); |
andrewboyson | 87:5052e316994a | 33 | nmeaStable = Ajax.hexToBit(lines[1], 7); |
andrewboyson | 87:5052e316994a | 34 | rtcIsSet = Ajax.hexToBit(lines[1], 6); |
andrewboyson | 87:5052e316994a | 35 | clockIsSet = Ajax.hexToBit(lines[1], 5); |
andrewboyson | 87:5052e316994a | 36 | sourceIsOk = Ajax.hexToBit(lines[1], 4); |
andrewboyson | 87:5052e316994a | 37 | rateIsLocked = Ajax.hexToBit(lines[1], 3); |
andrewboyson | 87:5052e316994a | 38 | timeIsLocked = Ajax.hexToBit(lines[1], 2); |
andrewboyson | 60:7cab896b0fd4 | 39 | rtc.months1970 = parseInt(lines[2], 16); |
andrewboyson | 60:7cab896b0fd4 | 40 | rtc.leaps = parseInt(lines[3], 16); |
andrewboyson | 27:eb5728b9052b | 41 | } |
andrewboyson | 60:7cab896b0fd4 | 42 | function display() |
andrewboyson | 27:eb5728b9052b | 43 | { |
andrewboyson | 60:7cab896b0fd4 | 44 | let elem; |
andrewboyson | 87:5052e316994a | 45 | elem = Ajax.getElementOrNull('ajax-msgs-ok' ); if (elem) elem.setAttribute('dir', messagesOk ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 46 | elem = Ajax.getElementOrNull('ajax-fix-msgs-ok' ); if (elem) elem.setAttribute('dir', fixMessagesOk ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 47 | elem = Ajax.getElementOrNull('ajax-time-msgs-ok' ); if (elem) elem.setAttribute('dir', timeMessagesOk ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 48 | elem = Ajax.getElementOrNull('ajax-pps-stable' ); if (elem) elem.setAttribute('dir', ppsStable ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 49 | elem = Ajax.getElementOrNull('ajax-nmea-stable' ); if (elem) elem.setAttribute('dir', nmeaStable ? 'rtl' : 'ltr'); |
andrewboyson | 60:7cab896b0fd4 | 50 | |
andrewboyson | 87:5052e316994a | 51 | elem = Ajax.getElementOrNull('ajax-rtc-set' ); if (elem) elem.setAttribute('dir', rtcIsSet ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 52 | elem = Ajax.getElementOrNull('ajax-clock-set' ); if (elem) elem.setAttribute('dir', clockIsSet ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 53 | elem = Ajax.getElementOrNull('ajax-source-ok' ); if (elem) elem.setAttribute('dir', sourceIsOk ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 54 | elem = Ajax.getElementOrNull('ajax-rate-locked' ); if (elem) elem.setAttribute('dir', rateIsLocked ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 55 | elem = Ajax.getElementOrNull('ajax-time-locked' ); if (elem) elem.setAttribute('dir', timeIsLocked ? 'rtl' : 'ltr'); |
andrewboyson | 87:5052e316994a | 56 | |
andrewboyson | 87:5052e316994a | 57 | elem = Ajax.getElementOrNull('ajax-date-diff' ); if (elem) elem.textContent = diffMs; |
andrewboyson | 60:7cab896b0fd4 | 58 | |
andrewboyson | 60:7cab896b0fd4 | 59 | elem = Ajax.getElementOrNull('ajax-leap-year' ); if (elem) elem.value = rtc.months1970 ? rtc.leapYear : ''; |
andrewboyson | 60:7cab896b0fd4 | 60 | elem = Ajax.getElementOrNull('ajax-leap-month' ); if (elem) elem.value = rtc.months1970 ? rtc.leapMonth : ''; |
andrewboyson | 60:7cab896b0fd4 | 61 | elem = Ajax.getElementOrNull('ajax-leap-count' ); if (elem) elem.value = rtc.leaps; |
andrewboyson | 27:eb5728b9052b | 62 | } |
andrewboyson | 27:eb5728b9052b | 63 | |
andrewboyson | 60:7cab896b0fd4 | 64 | function handleTick() //This typically called every 100ms |
andrewboyson | 27:eb5728b9052b | 65 | { |
andrewboyson | 87:5052e316994a | 66 | rtc.adjustLeap (Ajax.ms); |
andrewboyson | 87:5052e316994a | 67 | rtc.displayTime(Ajax.ms); |
andrewboyson | 27:eb5728b9052b | 68 | } |
andrewboyson | 27:eb5728b9052b | 69 | |
andrewboyson | 60:7cab896b0fd4 | 70 | Ajax.server = '/home-ajax'; |
andrewboyson | 60:7cab896b0fd4 | 71 | Ajax.onResponse = function() { parse(); display(); }; |
andrewboyson | 60:7cab896b0fd4 | 72 | Ajax.onTick = handleTick; |
andrewboyson | 60:7cab896b0fd4 | 73 | Ajax.init(); |
andrewboyson | 27:eb5728b9052b | 74 |