A GPS disciplined clock

Dependencies:   net lpc1768 crypto clock web log

Committer:
andrewboyson
Date:
Fri Apr 03 08:15:37 2020 +0000
Revision:
93:2cce06dd2bcc
Parent:
60:7cab896b0fd4
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?

UserRevisionLine numberNew contents of line
andrewboyson 60:7cab896b0fd4 1 "//Nmea script\n"
andrewboyson 48:9f1ab7784067 2 "'use strict';\n"
andrewboyson 48:9f1ab7784067 3 "\n"
andrewboyson 49:115a5e4fac0c 4 "const NMEA_DEG_UNIT = 10000000;\n"
andrewboyson 49:115a5e4fac0c 5 "const NMEA_HGT_UNIT = 1000000;\n"
andrewboyson 49:115a5e4fac0c 6 "\n"
andrewboyson 60:7cab896b0fd4 7 "let gpsTrace = false;\n"
andrewboyson 60:7cab896b0fd4 8 "let gpsVerbose = false;\n"
andrewboyson 60:7cab896b0fd4 9 "let msgTrace = false;\n"
andrewboyson 60:7cab896b0fd4 10 "let cmdTrace = false;\n"
andrewboyson 60:7cab896b0fd4 11 "let lat = 0;\n"
andrewboyson 60:7cab896b0fd4 12 "let lng = 0;\n"
andrewboyson 60:7cab896b0fd4 13 "let hgt = 0;\n"
andrewboyson 60:7cab896b0fd4 14 "let hgtAboveMsl = 0;\n"
andrewboyson 60:7cab896b0fd4 15 "let mslAboveWgs = 0;\n"
andrewboyson 60:7cab896b0fd4 16 "let dop = 0;\n"
andrewboyson 60:7cab896b0fd4 17 "let satCount = 0;\n"
andrewboyson 60:7cab896b0fd4 18 "let fixQuality = 0;\n"
andrewboyson 60:7cab896b0fd4 19 "let sensorHeight = 0;\n"
andrewboyson 60:7cab896b0fd4 20 "let bucketCount = 0;\n"
andrewboyson 60:7cab896b0fd4 21 "let buckets = '';\n"
andrewboyson 48:9f1ab7784067 22 "\n"
andrewboyson 60:7cab896b0fd4 23 "function parseVariables(text)\n"
andrewboyson 49:115a5e4fac0c 24 "{\n"
andrewboyson 60:7cab896b0fd4 25 " let lines = text.split('\\n');\n"
andrewboyson 60:7cab896b0fd4 26 " gpsTrace = Ajax.hexToBit (lines[0], 0);\n"
andrewboyson 60:7cab896b0fd4 27 " gpsVerbose = Ajax.hexToBit (lines[0], 1);\n"
andrewboyson 60:7cab896b0fd4 28 " msgTrace = Ajax.hexToBit (lines[0], 2);\n"
andrewboyson 60:7cab896b0fd4 29 " cmdTrace = Ajax.hexToBit (lines[0], 3);\n"
andrewboyson 60:7cab896b0fd4 30 " lat = Ajax.hexToSignedInt32(lines[1]);\n"
andrewboyson 60:7cab896b0fd4 31 " lng = Ajax.hexToSignedInt32(lines[2]);\n"
andrewboyson 60:7cab896b0fd4 32 " hgt = Ajax.hexToSignedInt32(lines[3]);\n"
andrewboyson 60:7cab896b0fd4 33 " hgtAboveMsl = Ajax.hexToSignedInt32(lines[4]);\n"
andrewboyson 60:7cab896b0fd4 34 " mslAboveWgs = Ajax.hexToSignedInt32(lines[5]);\n"
andrewboyson 60:7cab896b0fd4 35 " dop = Ajax.hexToSignedInt32(lines[6]);\n"
andrewboyson 60:7cab896b0fd4 36 " satCount = Ajax.hexToSignedInt32(lines[7]);\n"
andrewboyson 60:7cab896b0fd4 37 " fixQuality = Ajax.hexToSignedInt32(lines[8]);\n"
andrewboyson 60:7cab896b0fd4 38 " sensorHeight = Ajax.hexToSignedInt32(lines[9]);\n"
andrewboyson 49:115a5e4fac0c 39 "}\n"
andrewboyson 60:7cab896b0fd4 40 "function parseBuckets(text)\n"
andrewboyson 48:9f1ab7784067 41 "{\n"
andrewboyson 60:7cab896b0fd4 42 " let lines = text.split('\\n');\n"
andrewboyson 60:7cab896b0fd4 43 " bucketCount = Ajax.hexToSignedInt32(lines[0]);\n"
andrewboyson 49:115a5e4fac0c 44 " buckets = '';\n"
andrewboyson 60:7cab896b0fd4 45 " for (let i = 0; i < bucketCount; i++)\n"
andrewboyson 49:115a5e4fac0c 46 " {\n"
andrewboyson 60:7cab896b0fd4 47 " buckets += (i * 50).toString().padStart(3, '0') + ' ' + Ajax.hexToSignedInt32(lines[i + 1]) + '\\r\\n';\n"
andrewboyson 49:115a5e4fac0c 48 " }\n"
andrewboyson 49:115a5e4fac0c 49 "}\n"
andrewboyson 60:7cab896b0fd4 50 "function parse()\n"
andrewboyson 60:7cab896b0fd4 51 "{\n"
andrewboyson 60:7cab896b0fd4 52 " let topics = Ajax.response.split('\\f');\n"
andrewboyson 60:7cab896b0fd4 53 " parseVariables(topics[0]);\n"
andrewboyson 60:7cab896b0fd4 54 " parseBuckets (topics[1]);\n"
andrewboyson 60:7cab896b0fd4 55 "}\n"
andrewboyson 49:115a5e4fac0c 56 "function degToString(plus, minus, deg)\n"
andrewboyson 49:115a5e4fac0c 57 "{\n"
andrewboyson 49:115a5e4fac0c 58 " deg /= NMEA_DEG_UNIT;\n"
andrewboyson 49:115a5e4fac0c 59 " if (deg >= 0) return plus + deg.toFixed(5);\n"
andrewboyson 49:115a5e4fac0c 60 " else return minus + (-deg).toFixed(5);\n"
andrewboyson 49:115a5e4fac0c 61 "}\n"
andrewboyson 49:115a5e4fac0c 62 "function hgtToString(plus, minus, hgt)\n"
andrewboyson 49:115a5e4fac0c 63 "{\n"
andrewboyson 49:115a5e4fac0c 64 " hgt /= NMEA_HGT_UNIT;\n"
andrewboyson 49:115a5e4fac0c 65 " if (hgt >= 0) return plus + hgt.toFixed(1);\n"
andrewboyson 49:115a5e4fac0c 66 " else return minus + (-hgt).toFixed(1);\n"
andrewboyson 48:9f1ab7784067 67 "}\n"
andrewboyson 60:7cab896b0fd4 68 "function display()\n"
andrewboyson 48:9f1ab7784067 69 "{\n"
andrewboyson 60:7cab896b0fd4 70 " let elem;\n"
andrewboyson 60:7cab896b0fd4 71 " elem = Ajax.getElementOrNull('ajax-trace-gps' ); if (elem) elem.setAttribute('dir', gpsTrace ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 72 " elem = Ajax.getElementOrNull('ajax-trace-verbose'); if (elem) elem.setAttribute('dir', gpsVerbose ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 73 " elem = Ajax.getElementOrNull('ajax-trace-msg' ); if (elem) elem.setAttribute('dir', msgTrace ? 'rtl' : 'ltr');\n"
andrewboyson 60:7cab896b0fd4 74 " elem = Ajax.getElementOrNull('ajax-trace-cmd' ); if (elem) elem.setAttribute('dir', cmdTrace ? 'rtl' : 'ltr');\n"
andrewboyson 48:9f1ab7784067 75 "\n"
andrewboyson 60:7cab896b0fd4 76 " elem = Ajax.getElementOrNull('ajax-position' ); if (elem) elem.textContent = degToString('N', 'S', lat) + ' ' +\n"
andrewboyson 60:7cab896b0fd4 77 " degToString('E', 'W', lng) + ' ' +\n"
andrewboyson 60:7cab896b0fd4 78 " hgtToString('H', 'D', hgt);\n"
andrewboyson 60:7cab896b0fd4 79 " elem = Ajax.getElementOrNull('ajax-msl-above-wgs'); if (elem) elem.textContent = hgtToString('H', 'D', mslAboveWgs);\n"
andrewboyson 60:7cab896b0fd4 80 " elem = Ajax.getElementOrNull('ajax-hgt-above-msl'); if (elem) elem.textContent = hgtToString('H', 'D', hgtAboveMsl);\n"
andrewboyson 60:7cab896b0fd4 81 " elem = Ajax.getElementOrNull('ajax-gnd-above-msl'); if (elem) elem.textContent = hgtToString('H', 'D', hgtAboveMsl - sensorHeight * NMEA_HGT_UNIT);\n"
andrewboyson 48:9f1ab7784067 82 "\n"
andrewboyson 60:7cab896b0fd4 83 " elem = Ajax.getElementOrNull('ajax-dop' ); if (elem) elem.textContent = dop / 100;\n"
andrewboyson 60:7cab896b0fd4 84 " elem = Ajax.getElementOrNull('ajax-sat-count' ); if (elem) elem.textContent = satCount;\n"
andrewboyson 60:7cab896b0fd4 85 " elem = Ajax.getElementOrNull('ajax-fix-quality' ); if (elem) elem.textContent = fixQuality;\n"
andrewboyson 48:9f1ab7784067 86 " \n"
andrewboyson 60:7cab896b0fd4 87 " elem = Ajax.getElementOrNull('ajax-sensor-hgt' ); if (elem) elem.value = sensorHeight;\n"
andrewboyson 60:7cab896b0fd4 88 " \n"
andrewboyson 60:7cab896b0fd4 89 " elem = Ajax.getElementOrNull('ajax-bucket-count' ); if (elem) elem.textContent = bucketCount;\n"
andrewboyson 60:7cab896b0fd4 90 " elem = Ajax.getElementOrNull('ajax-buckets' ); if (elem) elem.textContent = buckets;\n"
andrewboyson 48:9f1ab7784067 91 "}\n"
andrewboyson 48:9f1ab7784067 92 "\n"
andrewboyson 60:7cab896b0fd4 93 "Ajax.server = '/nmea-ajax';\n"
andrewboyson 60:7cab896b0fd4 94 "Ajax.onResponse = function() { parse(); display(); };\n"
andrewboyson 60:7cab896b0fd4 95 "Ajax.init();"