Skip to content

Commit 859b3a8

Browse files
committed
parse version and new style
1 parent 08c4693 commit 859b3a8

File tree

4 files changed

+71
-56
lines changed

4 files changed

+71
-56
lines changed

monitor/.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"idf.pythonInstallPath": "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3"
3+
}

monitor/css/viewer.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#map {
22
resize: vertical;
3-
display:none;
43
height:calc(60vh);
54
border: 2px solid #888;
65
}

monitor/js/viewer.js

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,33 @@ window.onload = function _onload() {
7575
let layerControl;
7676
let config = { places: [], tracks: [] };
7777
mapInit();
78+
placeAddOption('Overview');
7879
trackTableUpdate();
7980
mapUpdateTrackLegend();
80-
urls.forEach(url => {
81-
if (isDef(url) && ('' != url)) {
82-
const name = url.toLowerCase();
83-
if (name.endsWith('.json')) {
84-
configFetchJson(url);
85-
} else if (name.endsWith('.ubx')) {
86-
trackFetchUrl(url);
81+
if (0 < urls.length) {
82+
urls.forEach(url => {
83+
if (isDef(url) && ('' != url)) {
84+
const name = url.toLowerCase();
85+
if (name.endsWith('.json')) {
86+
configFetchJson(url);
87+
} else if (name.endsWith('.ubx')) {
88+
trackFetchUrl(url);
89+
}
8790
}
91+
});
92+
} else {
93+
if (navigator.geolocation && map) {
94+
navigator.geolocation.getCurrentPosition(
95+
96+
(position) => {
97+
map.setView([position.coords.latitude, position.coords.longitude], 14, { animate: false })
98+
mapsContainer.style.display = 'block';
99+
},
100+
(err) => {},
101+
{ timeout: 1000 } // Timeout in ms
102+
);
88103
}
89-
});
104+
}
90105

91106
// -------------------------------------------------------------
92107
// MAP
@@ -101,7 +116,8 @@ window.onload = function _onload() {
101116
}
102117
});
103118
resizeObserver.observe(mapsContainer);
104-
map = L.map(mapsContainer, { zoomControl: true, zoomSnap: 0.1, wheelPxPerZoomLevel: 20, boxZoom: true, selectArea: true });
119+
map = L.map(mapsContainer, { zoomControl: true, zoomSnap: 0.1, wheelPxPerZoomLevel: 20, boxZoom: true });
120+
map.selectArea.enable();
105121
map.selectArea.setControlKey(true);
106122
L.control.scale().addTo(map);
107123
mapSetOpacity(opacitySlider.value);
@@ -257,7 +273,6 @@ window.onload = function _onload() {
257273
const w = parseInt(Math.abs(ne.x - sw.x));
258274
const h = parseInt(Math.abs(ne.y - sw.y));
259275
const place = { name:name, size: [ w, h ], bounds:[sw, ne] };
260-
config.places.push(place);
261276
placeAddOption(place.name, place);
262277
}
263278
}
@@ -269,23 +284,25 @@ window.onload = function _onload() {
269284
option.place = place;
270285
placeSelect.appendChild(option);
271286
if (isDef(place)) {
272-
let bounds = place.bounds;
273-
if (!isDef(bounds) && isDef(place.size) && isDef(place.center) && isDef(place.zoom)) {
287+
if (!isDef(place.bounds) && isDef(place.size) && isDef(place.center) && isDef(place.zoom)) {
274288
const temp = L.map(document.createElement('div'), { center: place.center, zoom: place.zoom });
275289
temp._size = L.point(place.size[0], place.size[1]);
276290
temp._resetView(L.latLng(place.center), place.zoom);
277-
bounds = temp.getBounds();
291+
const sw = temp.getBounds().getSouthWest();
292+
const ne = temp.getBounds().getNorthEast();
293+
place.bounds = [ [sw.lat, sw.lng] , [ne.lat, ne.lng] ];
278294
}
279-
if (isDef(bounds)) {
280-
const marker = L.rectangle(bounds, { dashArray: '5, 5', weight: 2, className: 'place' });
295+
if (isDef(place.bounds)) {
296+
const marker = L.rectangle(place.bounds, { dashArray: '5, 5', weight: 2, className: 'place' });
281297
marker.place = place;
282298
marker.on('click', (e) => {
283299
const isOverview = (place.name == placeSelect.value);
284-
placeChange(isOverview ? null : place, e.originalEvent.ctrlKey);
300+
placeChange(isOverview ? undefined : place, e.originalEvent.ctrlKey);
285301
placeSelect.value = isOverview ? 'Overview' : place.name;
286302
});
287303
placesLayer.addLayer(marker);
288304
}
305+
config.places.push(place);
289306
}
290307
}
291308

@@ -307,7 +324,6 @@ window.onload = function _onload() {
307324
[ Math.min(...tracks.map(item => item.bounds[0][0])), Math.min(...tracks.map(item => item.bounds[0][1])) ],
308325
[ Math.max(...tracks.map(item => item.bounds[1][0])), Math.max(...tracks.map(item => item.bounds[1][1])) ]);
309326
map.fitBounds(bounds, { animate: false } );
310-
map.panTo(bounds.getCenter(), { animate: false } );
311327
mapsContainer.style.display = 'block';
312328
}
313329
}
@@ -320,8 +336,8 @@ window.onload = function _onload() {
320336
placesLayer = L.layerGroup().addTo(map);
321337
layerControl.addOverlay(placesLayer, "Places");
322338
placeSelect.options.length = 0;
323-
config.places = [];
324339
placeAddOption('Overview');
340+
config.places = [];
325341
if (isDef(places)) {
326342
places.forEach((place, idx) => {
327343
placeAddOption(place.name, place);
@@ -387,7 +403,7 @@ window.onload = function _onload() {
387403
function trackFetchUrl(track) {
388404
const groupLayer = trackAdd(track);
389405
if (track.epochs) {
390-
if (!track.bounds) {
406+
if (track.bounds) {
391407
track.bounds = epochsGetBounds(track.epochs);
392408
}
393409
if (track.selected) {
@@ -466,10 +482,11 @@ window.onload = function _onload() {
466482

467483
function trackTableUpdate() {
468484
const table = document.getElementById('table_tracks');
469-
let html = '<tr><th>Track Name</th><th>Color</th><th>Module</th><th>Firmware</th><th>Protocol</th><th>Hardware</th><th>ROM</th></tr>';
485+
let html = '<tr><th>Track Name</th><th>Color</th><th>Epochs</th><th>Module</th><th>Firmware</th><th>Protocol</th><th>Hardware</th><th>ROM</th></tr>';
470486
config.tracks.forEach((track) => {
471487
html += '<tr><td>'+track.name+'</td>';
472488
html += '<td><input type="color" disabled value="'+track.color+'"></input></td>';
489+
html += '<td>' + (isDef(track.epochs) ? track.epochs.length : '') + '</td>';
473490
html += '<td>' + trackGetInfo(track, 'module') + '</td>';
474491
let fwVer = trackGetInfo(track, 'fwVer');
475492
if (fwVer == '') {
@@ -509,21 +526,23 @@ window.onload = function _onload() {
509526
if (messages.length) {
510527
let epoch = { fields: {}, ids: {}, info: [] };
511528
messages.forEach( function(message) {
512-
if ((message.type === 'output') && message.protocol.match(/^NMEA|UBX$/) && isDef(message.fields)) {
513-
if (epochCheck(epoch, message)) {
514-
const colorMap = {
515-
'DR': 'purple', '2D': 'blue',
516-
'2D/3D': 'green', '3D': 'green', 'DGPS': 'green',
517-
'3D+DR': 'purple', 'FIXED': 'green', 'FLOAT': 'green'
518-
};
519-
if (isDef(epoch.fields.lat) && isDef(epoch.fields.lon) && isDef(epoch.fields.fix) && isDef(colorMap[epoch.fields.fix])) {
520-
epochs.push( { color: colorMap[epoch.fields.fix], center: [epoch.fields.lat, epoch.fields.lon], fields: epoch.fields, info: epoch.info } );
521-
epoch.info = [];
529+
if ((message.type === 'output') && message.protocol.match(/^NMEA|UBX$/)) {
530+
if (isDef(message.fields)) {
531+
if (epochCheck(epoch, message)) {
532+
const colorMap = {
533+
'DR': 'purple', '2D': 'blue',
534+
'2D/3D': 'green', '3D': 'green', 'DGPS': 'green',
535+
'3D+DR': 'purple', 'FIXED': 'green', 'FLOAT': 'green'
536+
};
537+
if (isDef(epoch.fields.lat) && isDef(epoch.fields.lon) && isDef(epoch.fields.fix) && isDef(colorMap[epoch.fields.fix])) {
538+
epochs.push( { color: colorMap[epoch.fields.fix], center: [epoch.fields.lat, epoch.fields.lon], fields: epoch.fields, info: epoch.info } );
539+
epoch.info = [];
540+
}
541+
epoch.fields = {};
542+
epoch.ids = {};
522543
}
523-
epoch.fields = {};
524-
epoch.ids = {};
544+
epochFill(epoch.fields, message.fields);
525545
}
526-
epochFill(epoch.fields, message.fields);
527546
convertMessageExtract(track, message);
528547
epoch.ids[message.id] = true;
529548
let m = message.name.match(/^(INF-(ERROR|WARNING|NOTICE)|(G[PN]TXT))$/)
@@ -540,7 +559,7 @@ window.onload = function _onload() {
540559
}
541560

542561
function convertMessageExtract(track, message) {
543-
if (message.protocol === 'UBX') {
562+
if ((message.protocol === 'UBX') && isDef(message.fields)) {
544563
if (message.name === 'MON-VER') {
545564
convertSetInfo(track, 'monFwVer', message.fields.swVer);
546565
convertSetInfo(track, 'monHwVer', message.fields.hwVer);
@@ -551,8 +570,19 @@ window.onload = function _onload() {
551570
} else if (message.name === 'INF-NOTICE') {
552571
convertTextExtract(track, message.fields.infTxt);
553572
}
554-
} if ((message.protocol === 'NMEA') && (message.id === 'TXT')) {
555-
convertTextExtract(track, message.fields.infTxt);
573+
} else if (message.protocol === 'NMEA') {
574+
if ((message.id === 'TXT') && isDef(message.fields)) {
575+
convertTextExtract(track, message.fields.infTxt);
576+
} else {
577+
// $PAIR021,Project,Freq,SWPack,SerVer,SerBuildTime,L1RomVer>,L1ramVer,L5romVer,L5RamVer,KernelVer,KernelBuildTime,KFVersion,KFBuildTime,RTKVersion,RTKBuildTime,...
578+
// $PAIR021,AG3352Q_V2.3.0.AG3352_20230213,S,N,2b31f59,2209141904,2b9,0,,,d32ef91c,2209141902,571d3e7,2209141904,,,-15.48,-15.48,-14.02,-15.48,0,1,##,0,0*6D
579+
const m = message.text.match(/^\$PAIR02[1|0],([^_]*)_([^\,]*)\.([^,]*),(\w)/);
580+
if (m) {
581+
convertSetInfo(track, 'module', m[1]);
582+
convertSetInfo(track, 'fwVer', m[2]);
583+
convertSetInfo(track, 'hwVer', m[3]);
584+
}
585+
}
556586
}
557587
}
558588

@@ -721,23 +751,6 @@ window.onload = function _onload() {
721751
const dd = String(d).padStart(2, '0');
722752
return `${y}-${mm}-${d}`;
723753
}
724-
725-
function fmtValue(value) {
726-
let text = '';
727-
if (isDef(value)) {
728-
if (typeof value === 'object') {
729-
return JSON.stringify(value, null, 2);
730-
} else {
731-
const num = Number(value);
732-
if (!isNaN(num)) {
733-
text = Number(num.toFixed(10));
734-
} else {
735-
text = value
736-
}
737-
}
738-
}
739-
return text;
740-
}
741754

742755
function jsonToTable(json) {
743756
const rows = Object.entries(json).map(([key, value]) => {

monitor/viewer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
<meta charset="UTF-8">
4242
<!-- Third party js & css -->
4343
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/feather.min.js"></script>
44-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script>
4544
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.min.css" />
4645
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet-src.js"></script>
4746
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script>
47+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script>
4848
<!-- My own js & css -->
4949
<script defer src="js/viewer.js"></script>
5050
<script src="js/engine.js"></script>
@@ -112,7 +112,7 @@ <h2>Tracks</h2>
112112
Places: <select id="places"></select>
113113
Opacity: <input type="range" id="opacity" min="0" max="1" step="0.1" value="0.4" style="height: 10px;" />
114114
</p>
115-
<div id="map" style="display:none; height:calc(100vh -80px)"></div>
115+
<div id="map"></div>
116116
<div id="hint">
117117
Zoom by area: area select + Shift, define place: area select + Ctrl, resize map when clicking a place + Ctrl.
118118
Pass drop files or pass urls as search argument '?f=config.json&f=...', none of your data is sent to a server.

0 commit comments

Comments
 (0)