From f2674671173b5bd905078047cfb7d8bacd292d29 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Fri, 12 May 2023 10:49:14 +0200 Subject: [PATCH 1/5] sensortools - Format README and add emulated routes as gpx --- apps/sensortools/README.md | 64 ++++++++------ apps/sensortools/square.gpx | 33 +++++++ apps/sensortools/squareFuzzy.gpx | 144 +++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+), 24 deletions(-) create mode 100644 apps/sensortools/square.gpx create mode 100644 apps/sensortools/squareFuzzy.gpx diff --git a/apps/sensortools/README.md b/apps/sensortools/README.md index 8b89add7c..f44a89090 100644 --- a/apps/sensortools/README.md +++ b/apps/sensortools/README.md @@ -5,40 +5,56 @@ This allows to simulate sensor behaviour for development purposes ## Per Sensor settings: -enabled: - true or false -mode: - emulate: Completely craft events for this sensor - modify: Take existing events from real sensor and modify their data -name: - name of the emulation or modification mode -power: - emulate: Simulate Bangle._PWR changes, but do not call real power function - nop: Do nothing, ignore all power calls for this sensor but return true - passthrough: Just pass all power calls unmodified - on: Do not allow switching the sensor off, all calls are switching the real sensor on +Enabled: +* **true** +* **false** + +Mode: +* **emulate**: Completely craft events for this sensor +* **modify**: Take existing events from real sensor and modify their data + +Name: +* name of the emulation or modification mode + +Power: +* **emulate**: Simulate Bangle._PWR changes, but do not call real power function +* **nop**: Do nothing, ignore all power calls for this sensor but return true +* **passthrough**: Just pass all power calls unmodified +* **on**: Do not allow switching the sensor off, all calls are switching the real sensor on ### HRM -Modes: modify, emulate +Modes: +* **modify**: Modify the original events from this sensor +* **emulate**: Create events simulating sensor activity + Modification: - bpmtrippled: Multiply the bpm value of the original HRM values with 3 +* **bpmtrippled**: Multiply the bpm value of the original HRM values with 3 + Emulation: - sin: Calculate bpm changes by using sin +* **sin**: Calculate bpm changes by using sin ### GPS -Modes: emulate +Modes: +* **emulate** + Emulation: - staticfix: static complete fix with all values - route: A square route starting in the SW corner and moving SW->NW->NO->SW... - routeFuzzy: Roughly the same square as route, but with 100m seqments with some variaton in course - nofix: All values NaN but time,sattelites,fix and fix == 0 - changingfix: A fix with randomly changing values +* **staticfix**: static complete fix with all values +* **route**: A square route starting in the SW corner and moving SW->NW->NO->SW... [Download as gpx](square.gpx) +* **routeFuzzy**: Roughly the same square as route, but with 100m seqments with some variaton in course [Download as gpx](squareFuzzy.gpx) +* **nofix**: All values NaN but time,sattelites,fix and fix == 0 +* **changingfix**: A fix with randomly changing values ### Compass -Modes: emulate +Modes: +* **emulate** + Emulation: - static: All values but heading are 1, heading == 0 - rotate: All values but heading are 1, heading rotates 360° +* **static**: All values but heading are 1, heading == 0 +* **rotate**: All values but heading are 1, heading rotates 360° + +# Creator + +[halemmerich](https://github.com/halemmerich) \ No newline at end of file diff --git a/apps/sensortools/square.gpx b/apps/sensortools/square.gpx new file mode 100644 index 000000000..0220b4261 --- /dev/null +++ b/apps/sensortools/square.gpx @@ -0,0 +1,33 @@ + + + + 1kmsquare + Export from GpsPrune + + + 1kmsquare + 1 + + + 2273 + Lower left + + + 2166 + Top left + + + 2245 + Top right + + + 1994 + Lower right + + + 2273 + Destination + + + + diff --git a/apps/sensortools/squareFuzzy.gpx b/apps/sensortools/squareFuzzy.gpx new file mode 100644 index 000000000..8f73cc72b --- /dev/null +++ b/apps/sensortools/squareFuzzy.gpx @@ -0,0 +1,144 @@ + + + + 1kmsquare100 + Export from GpsPrune + + + 1kmsquare100 + 1 + + + 2265 + Lower left + + + 2256 + + + 2230 + + + 2219 + + + 2199 + + + 2182 + + + 2189 + + + 2180 + + + 2191 + + + 2185 + + + 2186 + + + 2166 + Top left + + + 2171 + + + 2194 + + + 2207 + + + 2212 + + + 2262 + + + 2278 + + + 2297 + + + 2303 + + + 2251 + + + 2245 + Top right + + + 2195 + + + 2163 + + + 2131 + + + 2095 + + + 2066 + + + 2037 + + + 1993 + + + 1967 + + + 1949 + + + 1972 + + + 2011 + Lower right + + + 2044 + + + 2061 + + + 2065 + + + 2071 + + + 2102 + + + 2147 + + + 2197 + + + 2228 + + + 2265 + Destination + + + + From 560e39b900b55c6c67d9a4e5b463a8a1d98a323b Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Thu, 25 May 2023 22:38:21 +0200 Subject: [PATCH 2/5] sensortools - Fix interpolation and speed for route simulation --- apps/sensortools/lib.js | 135 +++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 71 deletions(-) diff --git a/apps/sensortools/lib.js b/apps/sensortools/lib.js index 7dfc6307d..85ed3be60 100644 --- a/apps/sensortools/lib.js +++ b/apps/sensortools/lib.js @@ -138,63 +138,63 @@ exports.enable = () => { function interpolate(a,b,progress){ return { - lat: a.lat * progress + b.lat * (1-progress), - lon: a.lon * progress + b.lon * (1-progress), - ele: a.ele * progress + b.ele * (1-progress) + lat: b.lat * progress + a.lat * (1-progress), + lon: b.lon * progress + a.lon * (1-progress), + alt: b.alt * progress + a.alt * (1-progress) } } function getSquareRoute(){ return [ - {lat:"47.2577411",lon:"11.9927442",ele:2273}, - {lat:"47.266761",lon:"11.9926673",ele:2166}, - {lat:"47.2667605",lon:"12.0059511",ele:2245}, - {lat:"47.2577516",lon:"12.0059925",ele:1994} + {lat:47.2577411,lon:11.9927442,alt:2273}, + {lat:47.266761,lon:11.9926673,alt:2166}, + {lat:47.2667605,lon:12.0059511,alt:2245}, + {lat:47.2577516,lon:12.0059925,alt:1994} ]; } function getSquareRouteFuzzy(){ return [ - {lat:"47.2578455",lon:"11.9929891",ele:2265}, - {lat:"47.258592",lon:"11.9923341",ele:2256}, - {lat:"47.2594506",lon:"11.9927412",ele:2230}, - {lat:"47.2603323",lon:"11.9924949",ele:2219}, - {lat:"47.2612056",lon:"11.9928175",ele:2199}, - {lat:"47.2621002",lon:"11.9929817",ele:2182}, - {lat:"47.2629025",lon:"11.9923915",ele:2189}, - {lat:"47.2637828",lon:"11.9926486",ele:2180}, - {lat:"47.2646733",lon:"11.9928167",ele:2191}, - {lat:"47.2655617",lon:"11.9930357",ele:2185}, - {lat:"47.2662862",lon:"11.992252",ele:2186}, - {lat:"47.2669305",lon:"11.993173",ele:2166}, - {lat:"47.266666",lon:"11.9944419",ele:2171}, - {lat:"47.2667579",lon:"11.99576",ele:2194}, - {lat:"47.2669409",lon:"11.9970579",ele:2207}, - {lat:"47.2666562",lon:"11.9983128",ele:2212}, - {lat:"47.2666027",lon:"11.9996335",ele:2262}, - {lat:"47.2667245",lon:"12.0009395",ele:2278}, - {lat:"47.2668457",lon:"12.002256",ele:2297}, - {lat:"47.2666126",lon:"12.0035373",ele:2303}, - {lat:"47.2664554",lon:"12.004841",ele:2251}, - {lat:"47.2669461",lon:"12.005948",ele:2245}, - {lat:"47.2660877",lon:"12.006323",ele:2195}, - {lat:"47.2652729",lon:"12.0057552",ele:2163}, - {lat:"47.2643926",lon:"12.0060123",ele:2131}, - {lat:"47.2634978",lon:"12.0058302",ele:2095}, - {lat:"47.2626129",lon:"12.0060759",ele:2066}, - {lat:"47.2617325",lon:"12.0058188",ele:2037}, - {lat:"47.2608668",lon:"12.0061784",ele:1993}, - {lat:"47.2600155",lon:"12.0057392",ele:1967}, - {lat:"47.2591203",lon:"12.0058233",ele:1949}, - {lat:"47.2582307",lon:"12.0059718",ele:1972}, - {lat:"47.2578014",lon:"12.004804",ele:2011}, - {lat:"47.2577232",lon:"12.0034834",ele:2044}, - {lat:"47.257745",lon:"12.0021656",ele:2061}, - {lat:"47.2578682",lon:"12.0008597",ele:2065}, - {lat:"47.2577082",lon:"11.9995526",ele:2071}, - {lat:"47.2575917",lon:"11.9982348",ele:2102}, - {lat:"47.2577401",lon:"11.996924",ele:2147}, - {lat:"47.257715",lon:"11.9956061",ele:2197}, - {lat:"47.2578996",lon:"11.9943081",ele:2228} + {lat:47.2578455,lon:11.9929891,alt:2265}, + {lat:47.258592,lon:11.9923341,alt:2256}, + {lat:47.2594506,lon:11.9927412,alt:2230}, + {lat:47.2603323,lon:11.9924949,alt:2219}, + {lat:47.2612056,lon:11.9928175,alt:2199}, + {lat:47.2621002,lon:11.9929817,alt:2182}, + {lat:47.2629025,lon:11.9923915,alt:2189}, + {lat:47.2637828,lon:11.9926486,alt:2180}, + {lat:47.2646733,lon:11.9928167,alt:2191}, + {lat:47.2655617,lon:11.9930357,alt:2185}, + {lat:47.2662862,lon:11.992252,alt:2186}, + {lat:47.2669305,lon:11.993173,alt:2166}, + {lat:47.266666,lon:11.9944419,alt:2171}, + {lat:47.2667579,lon:11.99576,alt:2194}, + {lat:47.2669409,lon:11.9970579,alt:2207}, + {lat:47.2666562,lon:11.9983128,alt:2212}, + {lat:47.2666027,lon:11.9996335,alt:2262}, + {lat:47.2667245,lon:12.0009395,alt:2278}, + {lat:47.2668457,lon:12.002256,alt:2297}, + {lat:47.2666126,lon:12.0035373,alt:2303}, + {lat:47.2664554,lon:12.004841,alt:2251}, + {lat:47.2669461,lon:12.005948,alt:2245}, + {lat:47.2660877,lon:12.006323,alt:2195}, + {lat:47.2652729,lon:12.0057552,alt:2163}, + {lat:47.2643926,lon:12.0060123,alt:2131}, + {lat:47.2634978,lon:12.0058302,alt:2095}, + {lat:47.2626129,lon:12.0060759,alt:2066}, + {lat:47.2617325,lon:12.0058188,alt:2037}, + {lat:47.2608668,lon:12.0061784,alt:1993}, + {lat:47.2600155,lon:12.0057392,alt:1967}, + {lat:47.2591203,lon:12.0058233,alt:1949}, + {lat:47.2582307,lon:12.0059718,alt:1972}, + {lat:47.2578014,lon:12.004804,alt:2011}, + {lat:47.2577232,lon:12.0034834,alt:2044}, + {lat:47.257745,lon:12.0021656,alt:2061}, + {lat:47.2578682,lon:12.0008597,alt:2065}, + {lat:47.2577082,lon:11.9995526,alt:2071}, + {lat:47.2575917,lon:11.9982348,alt:2102}, + {lat:47.2577401,lon:11.996924,alt:2147}, + {lat:47.257715,lon:11.9956061,alt:2197}, + {lat:47.2578996,lon:11.9943081,alt:2228} ]; } @@ -215,51 +215,43 @@ exports.enable = () => { let interpSteps; if (settings.gps.name == "routeFuzzy"){ route = getSquareRouteFuzzy(); - interpSteps = 5; + interpSteps = 74; } else { route = getSquareRoute(); - interpSteps = 50; + interpSteps = 740; } let step = 0; let routeIndex = 0; modGps(() => { let newIndex = (routeIndex + 1)%route.length; - + let followingIndex = (routeIndex + 2)%route.length; + let result = { - "speed": Math.random() * 3 + 2, + "speed": Math.random()*1 + 4.5, "time": new Date(), "satellites": Math.floor(Math.random()*5)+3, "fix": 1, "hdop": Math.floor(Math.random(30)+1) }; - + let oldPos = route[routeIndex]; - if (step != 0){ - oldPos = interpolate(route[routeIndex], route[newIndex], E.clip(0,1,step/interpSteps)); - } let newPos = route[newIndex]; - if (step < interpSteps - 1){ - newPos = interpolate(route[routeIndex], route[newIndex], E.clip(0,1,(step+1)%interpSteps/interpSteps)); + let followingPos = route[followingIndex]; + let interpPos = interpolate(oldPos, newPos, E.clip(0,1,step/interpSteps)); + + if (step > 0.5* interpSteps) { + result.course = bearing(interpPos, interpolate(newPos, followingPos, E.clip(0,1,(step-0.5*interpSteps)/interpSteps))); + } else { + result.course = bearing(oldPos, newPos); } - if (step == interpSteps - 1){ - let followingIndex = (routeIndex + 2)%route.length; - newPos = interpolate(route[newIndex], route[followingIndex], E.clip(0,1,1/interpSteps)); - } - - result.lat = oldPos.lat; - result.lon = oldPos.lon; - result.alt = oldPos.ele; - - result.course = bearing(oldPos,newPos); - step++; if (step == interpSteps){ routeIndex = (routeIndex + 1) % route.length; step = 0; } - return result; + return Object.assign(result, interpPos); }); } else if (settings.gps.name == "nofix") { modGps(() => { return { @@ -281,7 +273,8 @@ exports.enable = () => { let currentDir=1000; let currentAlt=500; let currentSats=5; - modGps(() => { + + (() => { currentLat += 0.01; if (currentLat > 50) currentLat = 20; currentLon += 0.01; From d884e21a8ec6d0ed55b67ef63198a00a8d428da6 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sun, 28 May 2023 22:13:30 +0200 Subject: [PATCH 3/5] sensortools - Add setting for log --- apps/sensortools/default.json | 1 + apps/sensortools/lib.js | 1 + apps/sensortools/settings.js | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/apps/sensortools/default.json b/apps/sensortools/default.json index a85e1ddeb..0e0d0a9af 100644 --- a/apps/sensortools/default.json +++ b/apps/sensortools/default.json @@ -1,5 +1,6 @@ { "enabled": false, + "log": false, "mag": { "enabled": false, "mode": "emulate", diff --git a/apps/sensortools/lib.js b/apps/sensortools/lib.js index 85ed3be60..f0155d289 100644 --- a/apps/sensortools/lib.js +++ b/apps/sensortools/lib.js @@ -5,6 +5,7 @@ exports.enable = () => { ); let log = function(text, param) { + if (!settings.log) return; let logline = new Date().toISOString() + " - " + "Sensortools - " + text; if (param) logline += ": " + JSON.stringify(param); print(logline); diff --git a/apps/sensortools/settings.js b/apps/sensortools/settings.js index 231ab8467..ae631e60c 100644 --- a/apps/sensortools/settings.js +++ b/apps/sensortools/settings.js @@ -88,6 +88,12 @@ writeSettings("enabled",v); }, }, + 'Log': { + value: !!settings.log, + onchange: v => { + writeSettings("log",v); + }, + }, 'GPS': ()=>{showSubMenu("GPS","gps",["nop", "staticfix", "nofix", "changingfix", "route", "routeFuzzy"],[]);}, 'Compass': ()=>{showSubMenu("Compass","mag",["nop", "static", "rotate"],[]);}, 'HRM': ()=>{showSubMenu("HRM","hrm",["nop", "static"],["bpmtrippled"],["sin"]);} From 9642b546e28fced5728ac7e330ad3798175f2316 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sun, 11 Jun 2023 20:35:12 +0200 Subject: [PATCH 4/5] sensortools - Bump version --- apps/sensortools/ChangeLog | 2 ++ apps/sensortools/metadata.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/sensortools/ChangeLog b/apps/sensortools/ChangeLog index 7d9bdd6a8..6d2f5d2b4 100644 --- a/apps/sensortools/ChangeLog +++ b/apps/sensortools/ChangeLog @@ -2,3 +2,5 @@ 0.02: Less time used during boot if disabled 0.03: Fixed some test data 0.04: Correct type of time attribute in gps to Date +0.05: Fix gps emulation interpolation + Add setting for log output diff --git a/apps/sensortools/metadata.json b/apps/sensortools/metadata.json index f5bace383..48b146617 100644 --- a/apps/sensortools/metadata.json +++ b/apps/sensortools/metadata.json @@ -2,7 +2,7 @@ "id": "sensortools", "name": "Sensor tools", "shortName": "Sensor tools", - "version": "0.04", + "version": "0.05", "description": "Tools for testing and debugging apps that use sensor input", "icon": "icon.png", "type": "bootloader", From c8070a7d1446ddead245162032b9b286d43af40c Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Sun, 11 Jun 2023 20:43:56 +0200 Subject: [PATCH 5/5] sensortools - Fix changingfix emulation --- apps/sensortools/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sensortools/lib.js b/apps/sensortools/lib.js index f0155d289..5e1c199c2 100644 --- a/apps/sensortools/lib.js +++ b/apps/sensortools/lib.js @@ -275,7 +275,7 @@ exports.enable = () => { let currentAlt=500; let currentSats=5; - (() => { + modGps(() => { currentLat += 0.01; if (currentLat > 50) currentLat = 20; currentLon += 0.01;