Added location and speed service to transmit GPS data
parent
c0ac05488a
commit
cf9f724d36
|
|
@ -109,6 +109,11 @@ function transmitUpdatedSensorData() {
|
|||
isNewBarData = false;
|
||||
}
|
||||
|
||||
if(isNewGpsData && gps.lat && gps.lon) {
|
||||
data.push(encodeGpsServiceData());
|
||||
isNewGpsData = false;
|
||||
}
|
||||
|
||||
if(isNewHrmData) {
|
||||
data.push({ 0x2a37: [ 0, hrm.bpm ] });
|
||||
isNewHrmData = false;
|
||||
|
|
@ -145,6 +150,35 @@ function encodeBarServiceData() {
|
|||
}
|
||||
|
||||
|
||||
// Encode the GPS service data using the Location and Speed characteristic
|
||||
function encodeGpsServiceData() {
|
||||
let latEncoded = Math.round(gps.lat * 10000000);
|
||||
let lonEncoded = Math.round(gps.lon * 10000000);
|
||||
let hEncoded = Math.round(gps.course * 100);
|
||||
let sEncoded = Math.round(1000 * gps.speed / 36);
|
||||
|
||||
if(gps.lat < 0) {
|
||||
latEncoded += 0x100000000;
|
||||
}
|
||||
if(gps.lon < 0) {
|
||||
lonEncoded += 0x100000000;
|
||||
}
|
||||
|
||||
let s = [ sEncoded & 0xff, (sEncoded >> 8) & 0xff ];
|
||||
let lat = [ latEncoded & 0xff, (latEncoded >> 8) & 0xff,
|
||||
(latEncoded >> 16) & 0xff, (latEncoded >> 24) & 0xff ];
|
||||
let lon = [ lonEncoded & 0xff, (lonEncoded >> 8) & 0xff,
|
||||
(lonEncoded >> 16) & 0xff, (lonEncoded >> 24) & 0xff ];
|
||||
let h = [ hEncoded & 0xff, (hEncoded >> 8) & 0xff ];
|
||||
|
||||
return [
|
||||
0x02, 0x01, 0x06, // Flags
|
||||
0x11, 0x16, 0x67, 0x2a, 0x95, 0x02, s[0], s[1], lat[0], lat[1], lat[2],
|
||||
lat[3], lon[0], lon[1], lon[2], lon[3], h[0], h[1] // Location and Speed
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
// Update acceleration
|
||||
Bangle.on('accel', function(newAcc) {
|
||||
acc = newAcc;
|
||||
|
|
|
|||
Loading…
Reference in New Issue