A GPS disciplined clock

Dependencies:   net lpc1768 crypto clock web log

Committer:
andrewboyson
Date:
Wed May 06 18:40:02 2020 +0000
Revision:
97:af023452967f
Parent:
60:7cab896b0fd4
Changed PPS timeout to 8000ms (it was 1000ms)

Who changed what in which revision?

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