Merge pull request #2232 from myxor/agpsdata_v0.04

agpsdata: Write AGPS data chunks with delay to improve reliability
master
Gordon Williams 2022-11-07 08:51:42 +00:00 committed by GitHub
commit 0e65f02685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 45 deletions

View File

@ -2,3 +2,4 @@
0.02: Load AGPS data on app start and automatically in background 0.02: Load AGPS data on app start and automatically in background
0.03: Do not load AGPS data on boot 0.03: Do not load AGPS data on boot
Increase minimum interval to 6 hours Increase minimum interval to 6 hours
0.04: Write AGPS data chunks with delay to improve reliability

View File

@ -36,7 +36,7 @@ function updateAgps() {
g.clear(); g.clear();
if (!waiting) { if (!waiting) {
waiting = true; waiting = true;
display("Updating A-GPS..."); display("Updating A-GPS...", "takes ~ 10 seconds");
require("agpsdata").pull(function() { require("agpsdata").pull(function() {
waiting = false; waiting = false;
display("A-GPS updated.", "touch to close"); display("A-GPS updated.", "touch to close");

View File

@ -8,34 +8,45 @@ var FILE = "agpsdata.settings.json";
var settings; var settings;
readSettings(); readSettings();
function setAGPS(data) { function setAGPS(b64) {
var js = jsFromBase64(data); return new Promise(function(resolve, reject) {
try { var initCommands = "Bangle.setGPSPower(1);\n"; // turn GPS on
eval(js); const gnsstype = settings.gnsstype || 1; // default GPS
return true; initCommands += `Serial1.println("${CASIC_CHECKSUM("$PCAS04," + gnsstype)}")\n`; // set GNSS mode
}
catch(e) {
console.log("error:", e);
}
return false;
}
function jsFromBase64(b64) {
var bin = atob(b64);
var chunkSize = 128;
var js = "Bangle.setGPSPower(1);\n"; // turn GPS on
var gnsstype = settings.gnsstype || 1; // default GPS
js += `Serial1.println("${CASIC_CHECKSUM("$PCAS04,"+gnsstype)}")\n`; // set GNSS mode
// What about: // What about:
// NAV-TIMEUTC (0x01 0x10) // NAV-TIMEUTC (0x01 0x10)
// NAV-PV (0x01 0x03) // NAV-PV (0x01 0x03)
// or AGPS.zip uses AID-INI (0x0B 0x01) // or AGPS.zip uses AID-INI (0x0B 0x01)
for (var i=0;i<bin.length;i+=chunkSize) { eval(initCommands);
var chunk = bin.substr(i,chunkSize);
js += `Serial1.write(atob("${btoa(chunk)}"))\n`; try {
writeChunks(atob(b64), resolve);
} catch (e) {
console.log("error:", e);
reject();
} }
return js; });
}
var chunkI = 0;
function writeChunks(bin, resolve) {
return new Promise(function(resolve2) {
const chunkSize = 128;
setTimeout(function() {
if (chunkI < bin.length) {
var chunk = bin.substr(chunkI, chunkSize);
js = `Serial1.write(atob("${btoa(chunk)}"))\n`;
eval(js);
chunkI += chunkSize;
writeChunks(bin, resolve);
} else {
if (resolve)
resolve(); // call outer resolve
}
}, 200);
});
} }
function CASIC_CHECKSUM(cmd) { function CASIC_CHECKSUM(cmd) {
@ -53,23 +64,30 @@ function updateLastUpdate() {
} }
exports.pull = function(successCallback, failureCallback) { exports.pull = function(successCallback, failureCallback) {
let uri = "https://www.espruino.com/agps/casic.base64"; const uri = "https://www.espruino.com/agps/casic.base64";
if (Bangle.http) { if (Bangle.http) {
Bangle.http(uri, {timeout:10000}).then(event => { Bangle.http(uri, {timeout : 10000})
let result = setAGPS(event.resp); .then(event => {
if (result) { setAGPS(event.resp)
.then(r => {
updateLastUpdate(); updateLastUpdate();
if (successCallback) successCallback(); if (successCallback)
} else { successCallback();
console.log("error applying AGPS data"); })
if (failureCallback) failureCallback("Error applying AGPS data"); .catch((e) => {
}
}).catch((e)=>{
console.log("error", e); console.log("error", e);
if (failureCallback) failureCallback(e); if (failureCallback)
failureCallback(e);
});
})
.catch((e) => {
console.log("error", e);
if (failureCallback)
failureCallback(e);
}); });
} else { } else {
console.log("error: No http method found"); console.log("error: No http method found");
if (failureCallback) failureCallback(/*LANG*/"No http method"); if (failureCallback)
failureCallback(/*LANG*/ "No http method");
} }
}; };

View File

@ -2,7 +2,7 @@
"name": "A-GPS Data Downloader App", "name": "A-GPS Data Downloader App",
"shortName":"A-GPS Data", "shortName":"A-GPS Data",
"icon": "agpsdata.png", "icon": "agpsdata.png",
"version":"0.03", "version":"0.04",
"description": "Once installed, this app allows you to download assisted GPS (A-GPS) data directly to your Bangle.js **via Gadgetbridge on an Android phone** when you run the app. If you just want to upload the latest AGPS data from this app loader, please use the `Assisted GPS Update (AGPS)` app.", "description": "Once installed, this app allows you to download assisted GPS (A-GPS) data directly to your Bangle.js **via Gadgetbridge on an Android phone** when you run the app. If you just want to upload the latest AGPS data from this app loader, please use the `Assisted GPS Update (AGPS)` app.",
"tags": "boot,tool,assisted,gps,agps,http", "tags": "boot,tool,assisted,gps,agps,http",
"allow_emulator":true, "allow_emulator":true,