Skip to content

Commit 063929f

Browse files
committed
Handle 'RAM' as filename to allow direct uploads
Add ability to upload assisted GPS data
1 parent 811611c commit 063929f

File tree

7 files changed

+130
-4
lines changed

7 files changed

+130
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ and which gives information about the app for the Launcher.
241241
// add an icon to allow your app to be tested
242242
243243
"storage": [ // list of files to add to storage
244-
{"name":"appid.js", // filename to use in storage
244+
{"name":"appid.js", // filename to use in storage.
245+
// If name=='RAM', the code is sent directly to Bangle.js and is not saved to a file
245246
"url":"", // URL of file to load (currently relative to apps/)
246247
"content":"..." // if supplied, this content is loaded directly
247248
"evaluate":true // if supplied, data isn't quoted into a String before upload

apps.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,17 @@
895895
{"name":"gpsinfo.img","url": "gps-info-icon.js","evaluate": true}
896896
]
897897
},
898+
{ "id": "assistedgps",
899+
"name": "Assisted GPS Update",
900+
"icon": "app.png",
901+
"version":"0.01",
902+
"description": "Downloads assisted GPS data to Bangle.js for faster GPS startup and more accurate fixes",
903+
"custom": "custom.html",
904+
"tags": "tool,outdoors",
905+
"readme": "README.md",
906+
"storage": [
907+
]
908+
},
898909
{
899910
"id": "pomodo",
900911
"name":"Pomodoro",

apps/assistedgps/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New App!

apps/assistedgps/app.png

1.51 KB
Loading

apps/assistedgps/custom.html

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<html>
2+
<head>
3+
<link rel="stylesheet" href="../../css/spectre.min.css">
4+
</head>
5+
<body>
6+
7+
<h2>Assisted GPS</h2>
8+
<p>GPS can take a long time (~5 minutes) to get an accurate position the first time it is used.
9+
AGPS uploads a few hints to the GPS receiver about satellite positions that allow it
10+
to get a faster, more accurate fix - however they are only valid for a short period of time.</p>
11+
<p>You can upload data that covers a longer period of time, but the upload will take longer.</p>
12+
<div class="form-group">
13+
<label class="form-label">AGPS Validity time</label>
14+
<label class="form-radio">
15+
<input type="radio" name="agpsperiod" value="1d" checked><i class="form-icon"></i> 1 day (8kB)
16+
</label>
17+
<label class="form-radio">
18+
<input type="radio" name="agpsperiod" value="2d"><i class="form-icon"></i> 2 days (14kB)
19+
</label>
20+
<label class="form-radio">
21+
<input type="radio" name="agpsperiod" value="3d"><i class="form-icon"></i> 3 days (20kB)
22+
</label>
23+
<label class="form-radio">
24+
<input type="radio" name="agpsperiod" value="1wk"><i class="form-icon"></i> 1 week (46kB)
25+
</label>
26+
</div>
27+
<p>Click <button id="upload" class="btn btn-primary">Upload</button></p>
28+
29+
<script src="../../core/lib/customize.js"></script>
30+
31+
<script>
32+
// When the 'upload' button is clicked...
33+
document.getElementById("upload").addEventListener("click", function() {
34+
var radios = document.getElementsByName('agpsperiod');
35+
var url = "https://www.espruino.com/agps/assistnow_1d.base64";
36+
for (var i=0; i<radios.length; i++)
37+
if (radios[i].checked)
38+
url = "https://www.espruino.com/agps/assistnow_"+radios[i].value+".base64";
39+
console.log("Sending...");
40+
//var text = document.getElementById("agpsperiod").value;
41+
get(url, function(b64) {
42+
var js = jsFromBase64(b64);
43+
sendCustomizedApp({
44+
storage:[
45+
{name:"RAM", content:js},
46+
]
47+
});
48+
});
49+
});
50+
51+
function UBX_CMD(cmd) {
52+
var d = [0xB5,0x62]; // sync chars
53+
d = d.concat(cmd);
54+
var a=0,b=0;
55+
for (var i=2;i<d.length;i++) {
56+
a += d[i];
57+
b += a;
58+
}
59+
d.push(a&255,b&255);
60+
return d;
61+
}
62+
function UBX_MGA_INI_TIME_UTC() {
63+
var a = new Uint8Array(4+24);
64+
a.set([0x13,0x40,24,0]);
65+
a.set([ 0x10, // 0: type
66+
0, // 1: version
67+
0, // 2: ref - none
68+
0x80] ); // 3: leapsecs - unknown
69+
var d = new Date();
70+
d.setTime(d.getTime()+d.getTimezoneOffset()*60000); // get as UTC
71+
var dv = new DataView(a.buffer, 4);
72+
dv.setUint16(4, d.getFullYear());
73+
dv.setUint8(6, d.getMonth()+1);
74+
dv.setUint8(7, d.getDate());
75+
dv.setUint8(8, d.getHours());
76+
dv.setUint8(9, d.getMinutes());
77+
dv.setUint8(10, d.getSeconds());
78+
dv.setUint16(16, 10*60); // seconds part of accuracy - 10 minutes
79+
return UBX_CMD([].slice.call(a));
80+
}
81+
82+
function jsFromBase64(b64) {
83+
var bin = atob(b64);
84+
var chunkSize = 128;
85+
var js = "\x10Bangle.setGPSPower(1);\n"; // turn GPS on
86+
//js += `\x10Bangle.on('GPS-raw',function (d) { if (d.startsWith("\\xB5\\x62\\x05\\x01")) Terminal.println("GPS ACK"); else if (d.startsWith("\\xB5\\x62\\x05\\x00")) Terminal.println("GPS NACK"); })\n`;
87+
js += "\x10E.showMessage('Uploading...','AGPS');function p(n) {g.fillRect(0,g.getHeight()-80,g.getWidth()*n,g.getHeight()-60);}";
88+
//js += "\x10var t=getTime()+1;while(t>getTime());\n"; // wait 1 sec
89+
js += `\x10Serial1.write(atob("${btoa(String.fromCharCode.apply(null,UBX_MGA_INI_TIME_UTC()))}"))\n`; // set GPS time
90+
91+
for (var i=0;i<bin.length;i+=chunkSize) {
92+
var chunk = bin.substr(i,chunkSize);
93+
js += `\x10p(${Math.round(100*i/bin.length)/100});Serial1.write(atob("${btoa(chunk)}"))\n`;
94+
}
95+
js += "\x10p(1);\n"; // finish progress bar
96+
return js;
97+
}
98+
99+
function get(url,callback) {
100+
console.log("Loading "+url);
101+
var oReq = new XMLHttpRequest();
102+
oReq.addEventListener("load", function() {
103+
var b64 = this.responseText;
104+
console.log("Response received...");
105+
callback(b64);
106+
});
107+
oReq.open("GET", url);
108+
oReq.send();
109+
}
110+
111+
</script>
112+
</body>
113+
</html>

core

Submodule core updated 1 file

testing/GPS-comms.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function writeGPScmd(cmd) {
1616
a += d[i];
1717
b += a;
1818
}
19-
d.push(a,b);
19+
d.push(a&255,b&255);
2020
Serial1.write(d);
2121
}
2222
function readGPScmd(cmd, callback) {
@@ -131,7 +131,7 @@ function setUBX_MGA_INI_TIME_UTC() {
131131
dv.setUint8(9, d.getMinutes());
132132
dv.setUint8(10, d.getSeconds());
133133
dv.setUint16(16, 10*60); // seconds part of accuracy - 10 minutes
134-
writeGPScmd(a.slice());
134+
writeGPScmd([].slice.call(a));
135135
}
136136

137137
setUBX_MGA_INI_TIME_UTC();

0 commit comments

Comments
 (0)