1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
'use strict';
TABS.gps = {};
TABS.gps.initialize = function (callback) {
if (GUI.active_tab != 'gps') {
GUI.active_tab = 'gps';
googleAnalytics.sendAppView('GPS');
}
function load_html() {
$('#content').load("./tabs/gps.html", process_html);
}
load_html();
let cursorInitialized = false;
let iconStyle;
let mapHandler;
let iconGeometry;
let iconFeature;
function process_html() {
localize();
let mapView = new ol.View({
center: ol.proj.fromLonLat([0, 0]),
zoom: 15
});
let mapLayer;
if (globalSettings.mapProviderType == 'bing') {
mapLayer = new ol.source.BingMaps({
key: globalSettings.mapApiKey,
imagerySet: 'AerialWithLabels',
maxZoom: 19
});
} else if ( globalSettings.mapProviderType == 'mapproxy' ) {
mapLayer = new ol.source.TileWMS({
url: globalSettings.proxyURL,
params: {'LAYERS':globalSettings.proxyLayer}
})
} else {
mapLayer = new ol.source.OSM();
}
mapHandler = new ol.Map({
target: document.getElementById('gps-map'),
layers: [
new ol.layer.Tile({
source: mapLayer
})
],
view: mapView
});
let center = ol.proj.fromLonLat([0, 0]);
mapView.setCenter(center);
mapView.setZoom(2);
function get_raw_gps_data() {
MSP.send_message(MSPCodes.MSP_RAW_GPS, false, false, get_comp_gps_data);
}
function get_comp_gps_data() {
MSP.send_message(MSPCodes.MSP_COMP_GPS, false, false, get_gpsstatistics_data);
}
function get_gpsstatistics_data() {
MSP.send_message(MSPCodes.MSP_GPSSTATISTICS, false, false, update_ui);
}
function update_ui() {
let lat = GPS_DATA.lat / 10000000;
let lon = GPS_DATA.lon / 10000000;
let gpsFixType = chrome.i18n.getMessage('gpsFixNone');
if (GPS_DATA.fix >= 2) {
gpsFixType = chrome.i18n.getMessage('gpsFix3D');
} else if (GPS_DATA.fix >= 1) {
gpsFixType = chrome.i18n.getMessage('gpsFix2D');
}
$('.GPS_info td.fix').html(gpsFixType);
$('.GPS_info td.alt').text(GPS_DATA.alt + ' m');
$('.GPS_info td.lat').text(lat.toFixed(4) + ' deg');
$('.GPS_info td.lon').text(lon.toFixed(4) + ' deg');
$('.GPS_info td.speed').text(GPS_DATA.speed + ' cm/s');
$('.GPS_info td.sats').text(GPS_DATA.numSat);
$('.GPS_info td.distToHome').text(GPS_DATA.distanceToHome + ' m');
let gpsRate = 0;
if (GPS_DATA.messageDt > 0) {
gpsRate = 1000 / GPS_DATA.messageDt;
}
$('.GPS_stat td.messages').text(GPS_DATA.packetCount);
$('.GPS_stat td.rate').text(gpsRate.toFixed(1) + ' Hz');
$('.GPS_stat td.errors').text(GPS_DATA.errors);
$('.GPS_stat td.timeouts').text(GPS_DATA.timeouts);
$('.GPS_stat td.eph').text((GPS_DATA.eph / 100).toFixed(2) + ' m');
$('.GPS_stat td.epv').text((GPS_DATA.epv / 100).toFixed(2) + ' m');
$('.GPS_stat td.hdop').text((GPS_DATA.hdop / 100).toFixed(2));
//Update map
if (GPS_DATA.fix >= 2) {
if (!cursorInitialized) {
cursorInitialized = true;
iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 1],
opacity: 1,
scale: 0.5,
src: '../images/icons/cf_icon_position.png'
}))
});
let currentPositionLayer;
iconGeometry = new ol.geom.Point(ol.proj.fromLonLat([0, 0]));
iconFeature = new ol.Feature({
geometry: iconGeometry
});
iconFeature.setStyle(iconStyle);
let vectorSource = new ol.source.Vector({
features: [iconFeature]
});
currentPositionLayer = new ol.layer.Vector({
source: vectorSource
});
mapHandler.addLayer(currentPositionLayer);
}
let center = ol.proj.fromLonLat([lon, lat]);
mapView.setCenter(center);
mapView.setZoom(14);
iconGeometry.setCoordinates(center);
}
}
/*
* enable data pulling
* GPS is usually refreshed at 5Hz, there is no reason to pull it much more often, really...
*/
helper.mspBalancedInterval.add('gps_pull', 200, 3, function gps_update() {
// avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support.
if (!have_sensor(CONFIG.activeSensors, 'gps')) {
update_ui();
return;
}
if (helper.mspQueue.shouldDrop()) {
return;
}
get_raw_gps_data();
});
GUI.content_ready(callback);
}
};
TABS.gps.cleanup = function (callback) {
if (callback) callback();
};
|