From d0088522b843dfb70827b471a1bdb1603f3e5e34 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 18 Sep 2020 11:51:17 +0100 Subject: [PATCH] more GPS functionality added --- testing/GPS-comms.js | 77 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/testing/GPS-comms.js b/testing/GPS-comms.js index 67df178f8..b9c2c645c 100644 --- a/testing/GPS-comms.js +++ b/testing/GPS-comms.js @@ -1,22 +1,13 @@ -/* This code allows you to communicate with the GPS -receiver in Bangle.js in order to set it up. - -Protocol spec: - -https://cdn.sparkfun.com/assets/0/b/0/f/7/u-blox8-M8_ReceiverDescrProtSpec__UBX-13003221__Public.pdf - -*/ - Bangle.setGPSPower(1) //Bangle.on('GPS',print); -Bangle.on('GPS-raw',function (d) { +/*Bangle.on('GPS-raw',function (d) { if (d[0]=="$") return; if (d.startsWith("\xB5\x62\x05\x01")) print("GPS ACK"); else if (d.startsWith("\xB5\x62\x05\x00")) print("GPS NACK"); // 181,98 sync chars else print("GPS",E.toUint8Array(d).join(",")); -}); +});*/ function writeGPScmd(cmd) { var d = [0xB5,0x62]; // sync chars d = d.concat(cmd); @@ -28,6 +19,23 @@ function writeGPScmd(cmd) { d.push(a,b); Serial1.write(d); } +function readGPScmd(cmd, callback) { + var prefix = String.fromCharCode(0xb5,0x62,cmd[0],cmd[1]); + function handler(d) { + if (!d.startsWith(prefix)) return; + clearInterval(timeout); + var a = E.toUint8Array(d); + // cut off id + length + a = new Uint8Array(a.buffer,6, a.length-8); + callback(a); + } + Bangle.on('GPS-raw',handler); + var timeout = setTimeout(function() { + callback(); + Bangle.removeListener('GPS-raw',handler); + }, 2000); + writeGPScmd(cmd); +} function UBX_CFG_PMS() { // UBX-CFG-PMS - enable power management - Super-E writeGPScmd([0x06,0x86, // msg class + type @@ -64,4 +72,49 @@ function UBX_CFG_MSG(msg,enable) { // Enter super-e low power // UBX_CFG_PMS() // Disable DTM messages (see UBX_CFG_MSG comments): -UBX_CFG_MSG("DTM",false); \ No newline at end of file +//UBX_CFG_MSG("DTM",false); +// UBX-CFG-HNR (0x06 0x5C) - high rate (up to 30hz) + + +// GPS 181,98,6,62,60,0,0,32,32,7,0,8,16,0,1,0,1,1,1,1,3,0,0,0,1,1,2,4,8,0,0,0,1,1,3,8,16,0,1,0,1,1,4,0,8,0,0,0,1,3,5,0,3,0,1,0,1,5,6,8,14,0,0,0,1,1,84,27 +//GPS ACK + +function getUBX_CFG_GNSS() { + // + readGPScmd([0x06,0x3E,0,0], function(a) { + print("CFG_GNSS",a.join(","), a.length); + var info = { + numTrkChHw : a[1], + numTrkChUse : a[2], + configs : [] + }; + for (var i=4;i