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.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
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
|
||||||
|
|
@ -8,41 +8,52 @@ 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
|
||||||
}
|
// What about:
|
||||||
catch(e) {
|
// NAV-TIMEUTC (0x01 0x10)
|
||||||
console.log("error:", e);
|
// NAV-PV (0x01 0x03)
|
||||||
}
|
// or AGPS.zip uses AID-INI (0x0B 0x01)
|
||||||
return false;
|
|
||||||
|
eval(initCommands);
|
||||||
|
|
||||||
|
try {
|
||||||
|
writeChunks(atob(b64), resolve);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("error:", e);
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsFromBase64(b64) {
|
var chunkI = 0;
|
||||||
var bin = atob(b64);
|
function writeChunks(bin, resolve) {
|
||||||
var chunkSize = 128;
|
return new Promise(function(resolve2) {
|
||||||
var js = "Bangle.setGPSPower(1);\n"; // turn GPS on
|
const chunkSize = 128;
|
||||||
var gnsstype = settings.gnsstype || 1; // default GPS
|
setTimeout(function() {
|
||||||
js += `Serial1.println("${CASIC_CHECKSUM("$PCAS04,"+gnsstype)}")\n`; // set GNSS mode
|
if (chunkI < bin.length) {
|
||||||
// What about:
|
var chunk = bin.substr(chunkI, chunkSize);
|
||||||
// NAV-TIMEUTC (0x01 0x10)
|
js = `Serial1.write(atob("${btoa(chunk)}"))\n`;
|
||||||
// NAV-PV (0x01 0x03)
|
eval(js);
|
||||||
// or AGPS.zip uses AID-INI (0x0B 0x01)
|
|
||||||
|
|
||||||
for (var i=0;i<bin.length;i+=chunkSize) {
|
chunkI += chunkSize;
|
||||||
var chunk = bin.substr(i,chunkSize);
|
writeChunks(bin, resolve);
|
||||||
js += `Serial1.write(atob("${btoa(chunk)}"))\n`;
|
} else {
|
||||||
}
|
if (resolve)
|
||||||
return js;
|
resolve(); // call outer resolve
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function CASIC_CHECKSUM(cmd) {
|
function CASIC_CHECKSUM(cmd) {
|
||||||
var cs = 0;
|
var cs = 0;
|
||||||
for (var i=1;i<cmd.length;i++)
|
for (var i = 1; i < cmd.length; i++)
|
||||||
cs = cs ^ cmd.charCodeAt(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() {
|
function updateLastUpdate() {
|
||||||
|
|
@ -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)
|
||||||
updateLastUpdate();
|
.then(r => {
|
||||||
if (successCallback) successCallback();
|
updateLastUpdate();
|
||||||
} else {
|
if (successCallback)
|
||||||
console.log("error applying AGPS data");
|
successCallback();
|
||||||
if (failureCallback) failureCallback("Error applying AGPS data");
|
})
|
||||||
}
|
.catch((e) => {
|
||||||
}).catch((e)=>{
|
console.log("error", e);
|
||||||
console.log("error", e);
|
if (failureCallback)
|
||||||
if (failureCallback) failureCallback(e);
|
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");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue