Merge pull request #2232 from myxor/agpsdata_v0.04
agpsdata: Write AGPS data chunks with delay to improve reliabilitymaster
commit
0e65f02685
|
|
@ -2,3 +2,4 @@
|
|||
0.02: Load AGPS data on app start and automatically in background
|
||||
0.03: Do not load AGPS data on boot
|
||||
Increase minimum interval to 6 hours
|
||||
0.04: Write AGPS data chunks with delay to improve reliability
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ function updateAgps() {
|
|||
g.clear();
|
||||
if (!waiting) {
|
||||
waiting = true;
|
||||
display("Updating A-GPS...");
|
||||
display("Updating A-GPS...", "takes ~ 10 seconds");
|
||||
require("agpsdata").pull(function() {
|
||||
waiting = false;
|
||||
display("A-GPS updated.", "touch to close");
|
||||
|
|
|
|||
|
|
@ -8,41 +8,52 @@ var FILE = "agpsdata.settings.json";
|
|||
var settings;
|
||||
readSettings();
|
||||
|
||||
function setAGPS(data) {
|
||||
var js = jsFromBase64(data);
|
||||
try {
|
||||
eval(js);
|
||||
return true;
|
||||
}
|
||||
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
|
||||
function setAGPS(b64) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var initCommands = "Bangle.setGPSPower(1);\n"; // turn GPS on
|
||||
const gnsstype = settings.gnsstype || 1; // default GPS
|
||||
initCommands += `Serial1.println("${CASIC_CHECKSUM("$PCAS04," + gnsstype)}")\n`; // set GNSS mode
|
||||
// What about:
|
||||
// NAV-TIMEUTC (0x01 0x10)
|
||||
// NAV-PV (0x01 0x03)
|
||||
// or AGPS.zip uses AID-INI (0x0B 0x01)
|
||||
|
||||
for (var i=0;i<bin.length;i+=chunkSize) {
|
||||
var chunk = bin.substr(i,chunkSize);
|
||||
js += `Serial1.write(atob("${btoa(chunk)}"))\n`;
|
||||
eval(initCommands);
|
||||
|
||||
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) {
|
||||
var cs = 0;
|
||||
for (var i=1;i<cmd.length;i++)
|
||||
for (var i = 1; i < cmd.length; i++)
|
||||
cs = cs ^ cmd.charCodeAt(i);
|
||||
return cmd+"*"+cs.toString(16).toUpperCase().padStart(2, '0');
|
||||
return cmd + "*" + cs.toString(16).toUpperCase().padStart(2, '0');
|
||||
}
|
||||
|
||||
function updateLastUpdate() {
|
||||
|
|
@ -53,23 +64,30 @@ function updateLastUpdate() {
|
|||
}
|
||||
|
||||
exports.pull = function(successCallback, failureCallback) {
|
||||
let uri = "https://www.espruino.com/agps/casic.base64";
|
||||
if (Bangle.http){
|
||||
Bangle.http(uri, {timeout:10000}).then(event => {
|
||||
let result = setAGPS(event.resp);
|
||||
if (result) {
|
||||
const uri = "https://www.espruino.com/agps/casic.base64";
|
||||
if (Bangle.http) {
|
||||
Bangle.http(uri, {timeout : 10000})
|
||||
.then(event => {
|
||||
setAGPS(event.resp)
|
||||
.then(r => {
|
||||
updateLastUpdate();
|
||||
if (successCallback) successCallback();
|
||||
} else {
|
||||
console.log("error applying AGPS data");
|
||||
if (failureCallback) failureCallback("Error applying AGPS data");
|
||||
}
|
||||
}).catch((e)=>{
|
||||
if (successCallback)
|
||||
successCallback();
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("error", e);
|
||||
if (failureCallback) failureCallback(e);
|
||||
if (failureCallback)
|
||||
failureCallback(e);
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("error", e);
|
||||
if (failureCallback)
|
||||
failureCallback(e);
|
||||
});
|
||||
} else {
|
||||
console.log("error: No http method found");
|
||||
if (failureCallback) failureCallback(/*LANG*/"No http method");
|
||||
if (failureCallback)
|
||||
failureCallback(/*LANG*/ "No http method");
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "A-GPS Data Downloader App",
|
||||
"shortName":"A-GPS Data",
|
||||
"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.",
|
||||
"tags": "boot,tool,assisted,gps,agps,http",
|
||||
"allow_emulator":true,
|
||||
|
|
|
|||
Loading…
Reference in New Issue