mirror of https://github.com/espruino/BangleApps
more GPS functionality added
parent
b1fe7201c8
commit
d0088522b8
|
@ -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.setGPSPower(1)
|
||||||
//Bangle.on('GPS',print);
|
//Bangle.on('GPS',print);
|
||||||
|
|
||||||
Bangle.on('GPS-raw',function (d) {
|
/*Bangle.on('GPS-raw',function (d) {
|
||||||
if (d[0]=="$") return;
|
if (d[0]=="$") return;
|
||||||
if (d.startsWith("\xB5\x62\x05\x01")) print("GPS ACK");
|
if (d.startsWith("\xB5\x62\x05\x01")) print("GPS ACK");
|
||||||
else if (d.startsWith("\xB5\x62\x05\x00")) print("GPS NACK");
|
else if (d.startsWith("\xB5\x62\x05\x00")) print("GPS NACK");
|
||||||
// 181,98 sync chars
|
// 181,98 sync chars
|
||||||
else print("GPS",E.toUint8Array(d).join(","));
|
else print("GPS",E.toUint8Array(d).join(","));
|
||||||
});
|
});*/
|
||||||
function writeGPScmd(cmd) {
|
function writeGPScmd(cmd) {
|
||||||
var d = [0xB5,0x62]; // sync chars
|
var d = [0xB5,0x62]; // sync chars
|
||||||
d = d.concat(cmd);
|
d = d.concat(cmd);
|
||||||
|
@ -28,6 +19,23 @@ function writeGPScmd(cmd) {
|
||||||
d.push(a,b);
|
d.push(a,b);
|
||||||
Serial1.write(d);
|
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() {
|
function UBX_CFG_PMS() {
|
||||||
// UBX-CFG-PMS - enable power management - Super-E
|
// UBX-CFG-PMS - enable power management - Super-E
|
||||||
writeGPScmd([0x06,0x86, // msg class + type
|
writeGPScmd([0x06,0x86, // msg class + type
|
||||||
|
@ -64,4 +72,49 @@ function UBX_CFG_MSG(msg,enable) {
|
||||||
// Enter super-e low power
|
// Enter super-e low power
|
||||||
// UBX_CFG_PMS()
|
// UBX_CFG_PMS()
|
||||||
// Disable DTM messages (see UBX_CFG_MSG comments):
|
// Disable DTM messages (see UBX_CFG_MSG comments):
|
||||||
UBX_CFG_MSG("DTM",false);
|
//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<a.length;i+=8) {
|
||||||
|
info.configs.push({
|
||||||
|
gnss : ["GPS","SBAS","Galileo","BeiDou","IMES","QZSS","GLONASS"][a[i+0]],
|
||||||
|
reservedCh : a[1+1],
|
||||||
|
maxCh : a[i+2],
|
||||||
|
enabled : a[i+4]&1,
|
||||||
|
sigCfgMask : a[i+6],
|
||||||
|
flags : [a[i+4],a[i+5],a[i+6],a[i+7]]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
print(info);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUBX_CFG_NMEA() {
|
||||||
|
readGPScmd([0x06,0x17,0,0], function(a) {
|
||||||
|
print("CFG_NMEA",a.join(","), a.length);
|
||||||
|
var info = {
|
||||||
|
filter : a[0],
|
||||||
|
nmeaVersion : {0x4b:4.11,0x41:4.1,0x40:4,0x23:2.3,0x21:2.1}[a[1]],
|
||||||
|
flags : a[3]
|
||||||
|
};
|
||||||
|
print(info);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getUBX_CFG_NMEA();
|
||||||
|
|
||||||
|
// UBX-MGA-INI-TIME_UTC looks promising for a start time
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue