Skip to content

Commit ea9080b

Browse files
authored
Merge pull request #191 from LukePrior/testing
Fully support SondeHub V1 Data
2 parents dc6a7c3 + f1b564c commit ea9080b

File tree

1 file changed

+243
-86
lines changed

1 file changed

+243
-86
lines changed

js/tracker.js

Lines changed: 243 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,63 @@ var Z_CAR = 1000001;
9999
var Z_PAYLOAD = 1000002;
100100
var Z_RECOVERY = 1000003;
101101

102+
// SondeHub V1 types
103+
104+
var v1types = {
105+
"RS41": "RS41",
106+
"RS41-Ozone": "RS41",
107+
"RS41-SGP-Ozone": "RS41-SGP",
108+
"RS41-SG": "RS41-SG",
109+
"RS41-SG-Ozone": "RS41-SG",
110+
"RS41-SGP": "RS41-SGP",
111+
"RS41-SGM": "RS41-SGM",
112+
"RS41-NG": "RS41-NG",
113+
"RS92": "RS92",
114+
"RS92-Ozone": "RS92",
115+
"IMET": "iMet-4",
116+
"iMet": "iMet-4",
117+
"DFM": "DFM",
118+
"DFM06": "DFM06",
119+
"DFM09": "DFM09",
120+
"DFMxB": "DFM",
121+
"DFMxC": "DFM",
122+
"DFMx7": "DFMx7",
123+
"DFMx9": "DFMx9",
124+
"DFM17": "DFM17",
125+
"DFM09P": "DFM09P",
126+
"MK2LMS": "LMS6-1680",
127+
"LMS6": "LMS6-400",
128+
"M10": "M10",
129+
",M10": "M10",
130+
"M10-Ptu": "M10",
131+
"M20": "M20",
132+
"MEISEI": "IMS100",
133+
"IMS100": "IMS100",
134+
"IMET5": "iMet-5x"
135+
}
136+
137+
var v1manufacturers = {
138+
"RS92": "Vaisala",
139+
"RS41": "Vaisala",
140+
"RS41-SG": "Vaisala",
141+
"RS41-SGP": "Vaisala",
142+
"RS41-SGM": "Vaisala",
143+
"RS41-NG": "Vaisala",
144+
"iMet-4": "Intermet Systems",
145+
"iMet-5x": "Intermet Systems",
146+
"DFM": "Graw",
147+
"DFM06": "Graw",
148+
"DFM09": "Graw",
149+
"DFMx7": "Graw",
150+
"DFMx9": "Graw",
151+
"DFM17": "Graw",
152+
"DFM09P": "Graw",
153+
"LMS6-400": "Lockheed Martin",
154+
"LMS6-1680": "Lockheed Martin",
155+
"M10": "Meteomodem",
156+
"M20": "Meteomodem"
157+
}
158+
102159
// localStorage vars
103160
var ls_receivers = false;
104161
var ls_pred = false;
@@ -2105,114 +2162,204 @@ function mapInfoBox_handle_path_fetch(id,vehicle) {
21052162
var date = new Date(parseInt(id)).toISOString()
21062163
var url = newdata_url + "?duration=0&serial=" + vehicle.callsign + "&datetime=" + date;
21072164

2108-
$.getJSON(url, function(data) {
2109-
if (Object.keys(data).length === 0) {
2165+
$.ajax({
2166+
type: "GET",
2167+
url: url,
2168+
dataType: "json",
2169+
success: function(data) {
2170+
mapInfoBox_handle_path_new(data, vehicle)
2171+
},
2172+
error: function() {
2173+
mapInfoBox_handle_path_old(vehicle, id)
2174+
}
2175+
});
2176+
};
2177+
2178+
function mapInfoBox_handle_path_old(vehicle, id) {
2179+
var url = "https://api.v2.sondehub.org/sonde/" + vehicle.callsign;
2180+
var index = vehicle["positions_ids"][vehicle["positions_ts"].indexOf(id)].substring(vehicle.callsign.length + 1);
2181+
2182+
$.ajax({
2183+
type: "GET",
2184+
url: url,
2185+
dataType: "json",
2186+
success: function(data) {
2187+
for (var i = 0; i < data.length; i++) {
2188+
if (data[i]["datetime"] == index) {
2189+
data = data[i];
2190+
div = document.createElement('div');
2191+
2192+
html = "<div style='line-height:16px;position:relative;'>";
2193+
html += "<div>"+data.serial+"<span style=''>("+data.datetime+")</span></div>";
2194+
html += "<hr style='margin:5px 0px'>";
2195+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
2196+
2197+
var imp = offline.get('opt_imperial');
2198+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
2199+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
2200+
2201+
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
2202+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(data.datetime))+"</div>";
2203+
2204+
var value = vehicle.path_length;
2205+
2206+
html += "<div><b>Distance:&nbsp;</b>";
2207+
2208+
if(offline.get('opt_imperial')) {
2209+
html += Math.round(value*0.000621371192) + "&nbsp;mi";
2210+
} else {
2211+
html += Math.round(value/10)/100 + "&nbsp;km";
2212+
}
2213+
2214+
html += "</div>";
2215+
html += "<div><b>Duration:&nbsp;</b>" + format_time_friendly(vehicle.start_time, convert_time(vehicle.curr_position.gps_time)) + "</div>";
2216+
2217+
html += "<hr style='margin:5px 0px'>";
2218+
2219+
if (data.hasOwnProperty("humidity")) {
2220+
html += "<div><b>Relative Humidity:&nbsp;</b>" + data.humidity + " %</div>";
2221+
};
2222+
if (data.hasOwnProperty("temp")) {
2223+
html += "<div><b>Temperature External:&nbsp;</b>" + data.temp + "°C</div>";
2224+
};
2225+
if (data.hasOwnProperty("comment")) {
2226+
html += "<div><b>Comment:&nbsp;</b>" + data.comment + "</div>";
2227+
};
2228+
2229+
html += "<hr style='margin:0px;margin-top:5px'>";
2230+
html += "<div style='font-size:11px;'>"
2231+
2232+
if (data.hasOwnProperty("uploader_callsign")) {
2233+
html += "<div>" + data.uploader_callsign + "</div>";
2234+
};
2235+
2236+
div.innerHTML = html;
2237+
2238+
mapInfoBox.setContent(div);
2239+
mapInfoBox.openOn(map);
2240+
2241+
setTimeout(function() {
2242+
div.parentElement.style.overflow = "";
2243+
div.parentElement.style.overflowWrap = "break-word";
2244+
}, 16);
2245+
}
2246+
}
2247+
},
2248+
error: function() {
21102249
mapInfoBox.setContent("not&nbsp;found");
21112250
mapInfoBox.openOn(map);
21122251
return;
2113-
}
2252+
}
2253+
});
2254+
}
2255+
2256+
function mapInfoBox_handle_path_new(data, vehicle) {
2257+
if (Object.keys(data).length === 0) {
2258+
mapInfoBox.setContent("not&nbsp;found");
2259+
mapInfoBox.openOn(map);
2260+
return;
2261+
}
21142262

2115-
data = data[vehicle.callsign][date];
2263+
data = data[vehicle.callsign][date];
21162264

2117-
div = document.createElement('div');
2265+
div = document.createElement('div');
21182266

2119-
html = "<div style='line-height:16px;position:relative;'>";
2120-
html += "<div>"+data.serial+"<span style=''>("+date+")</span></div>";
2121-
html += "<hr style='margin:5px 0px'>";
2122-
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
2267+
html = "<div style='line-height:16px;position:relative;'>";
2268+
html += "<div>"+data.serial+"<span style=''>("+date+")</span></div>";
2269+
html += "<hr style='margin:5px 0px'>";
2270+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(data.lat, 5) + ',&nbsp;' + roundNumber(data.lon, 5)+"</div>";
21232271

2124-
var imp = offline.get('opt_imperial');
2125-
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
2126-
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
2272+
var imp = offline.get('opt_imperial');
2273+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(data.alt)) : parseInt(data.alt)).toLocaleString("us");
2274+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
21272275

2128-
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
2129-
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(date))+"</div>";
2276+
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
2277+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(date))+"</div>";
21302278

2131-
var value = vehicle.path_length;
2279+
var value = vehicle.path_length;
21322280

2133-
html += "<div><b>Distance:&nbsp;</b>";
2281+
html += "<div><b>Distance:&nbsp;</b>";
21342282

2135-
if(offline.get('opt_imperial')) {
2136-
html += Math.round(value*0.000621371192) + "mi";
2137-
} else {
2138-
html += Math.round(value/10)/100 + "&nbsp;km";
2139-
}
2283+
if(offline.get('opt_imperial')) {
2284+
html += Math.round(value*0.000621371192) + "&nbsp;mi";
2285+
} else {
2286+
html += Math.round(value/10)/100 + "&nbsp;km";
2287+
}
21402288

2141-
html += "</div>";
2142-
html += "<div><b>Duration:&nbsp;</b>" + format_time_friendly(vehicle.start_time, convert_time(vehicle.curr_position.gps_time)) + "</div>";
2289+
html += "</div>";
2290+
html += "<div><b>Duration:&nbsp;</b>" + format_time_friendly(vehicle.start_time, convert_time(vehicle.curr_position.gps_time)) + "</div>";
21432291

2144-
html += "<hr style='margin:5px 0px'>";
2292+
html += "<hr style='margin:5px 0px'>";
21452293

2146-
if (data.hasOwnProperty("batt")) {
2147-
html += "<div><b>Battery Voltage:&nbsp;</b>" + data.batt + " V</div>";
2148-
};
2149-
if (data.hasOwnProperty("tx_frequency")) {
2150-
html += "<div><b>TX Frequency:&nbsp;</b>" + data.tx_frequency + " MHz</div>";
2151-
} else if (data.hasOwnProperty("frequency")) {
2152-
html += "<div><b>Frequency:&nbsp;</b>" + data.frequency + " MHz</div>";
2153-
};
2154-
if (data.hasOwnProperty("humidity")) {
2155-
html += "<div><b>Relative Humidity:&nbsp;</b>" + data.humidity + " %</div>";
2156-
};
2157-
if (data.hasOwnProperty("manufacturer")) {
2158-
html += "<div><b>Manufacturer:&nbsp;</b>" + data.manufacturer + "</div>";
2159-
};
2160-
if (data.hasOwnProperty("sats")) {
2161-
html += "<div><b>Satellites:&nbsp;</b>" + data.sats + "</div>";
2162-
};
2163-
if (data.hasOwnProperty("temp")) {
2164-
html += "<div><b>Temperature External:&nbsp;</b>" + data.temp + "°C</div>";
2165-
};
2166-
if (data.hasOwnProperty("subtype")) {
2167-
html += "<div><b>Sonde Type:&nbsp;</b>" + data.subtype + "</div>";
2168-
} else if (data.hasOwnProperty("type")) {
2169-
html += "<div><b>Sonde Type:&nbsp;</b>" + data.type + "</div>";
2170-
};
2171-
if (data.hasOwnProperty("pressure")) {
2172-
html += "<div><b>Pressure:&nbsp;</b>" + data.pressure + " Pa</div>";
2173-
};
2174-
if (data.hasOwnProperty("xdata")) {
2175-
html += "<div><b>XDATA:&nbsp;</b>" + data.xdata + "</div>";
2176-
};
2294+
if (data.hasOwnProperty("batt")) {
2295+
html += "<div><b>Battery Voltage:&nbsp;</b>" + data.batt + " V</div>";
2296+
};
2297+
if (data.hasOwnProperty("tx_frequency")) {
2298+
html += "<div><b>TX Frequency:&nbsp;</b>" + data.tx_frequency + " MHz</div>";
2299+
} else if (data.hasOwnProperty("frequency")) {
2300+
html += "<div><b>Frequency:&nbsp;</b>" + data.frequency + " MHz</div>";
2301+
};
2302+
if (data.hasOwnProperty("humidity")) {
2303+
html += "<div><b>Relative Humidity:&nbsp;</b>" + data.humidity + " %</div>";
2304+
};
2305+
if (data.hasOwnProperty("manufacturer")) {
2306+
html += "<div><b>Manufacturer:&nbsp;</b>" + data.manufacturer + "</div>";
2307+
};
2308+
if (data.hasOwnProperty("sats")) {
2309+
html += "<div><b>Satellites:&nbsp;</b>" + data.sats + "</div>";
2310+
};
2311+
if (data.hasOwnProperty("temp")) {
2312+
html += "<div><b>Temperature External:&nbsp;</b>" + data.temp + "°C</div>";
2313+
};
2314+
if (data.hasOwnProperty("subtype")) {
2315+
html += "<div><b>Sonde Type:&nbsp;</b>" + data.subtype + "</div>";
2316+
} else if (data.hasOwnProperty("type")) {
2317+
html += "<div><b>Sonde Type:&nbsp;</b>" + data.type + "</div>";
2318+
};
2319+
if (data.hasOwnProperty("pressure")) {
2320+
html += "<div><b>Pressure:&nbsp;</b>" + data.pressure + " Pa</div>";
2321+
};
2322+
if (data.hasOwnProperty("xdata")) {
2323+
html += "<div><b>XDATA:&nbsp;</b>" + data.xdata + "</div>";
2324+
};
21772325

2178-
html += "<hr style='margin:0px;margin-top:5px'>";
2179-
html += "<div style='font-size:11px;'>"
2326+
html += "<hr style='margin:0px;margin-top:5px'>";
2327+
html += "<div style='font-size:11px;'>"
21802328

2181-
var callsign_list = [];
2329+
var callsign_list = [];
21822330

2183-
for (var i = 0; i < data.uploaders.length; i++) {
2184-
_new_call = data.uploaders[i].uploader_callsign;
2185-
tempFields = [];
2186-
if(data.uploaders[i].hasOwnProperty('snr')) {
2187-
tempFields.push(data.uploaders[i].snr.toFixed(0) + " dB");
2188-
}
2189-
if(data.uploaders[i].hasOwnProperty('rssi')) {
2190-
tempFields.push(data.uploaders[i].rssi.toFixed(0) + " dBm");
2191-
}
2192-
if(data.uploaders[i].hasOwnProperty('frequency')) {
2193-
tempFields.push(data.uploaders[i].frequency + " MHz");
2194-
}
2195-
if(tempFields.length > 0) {
2196-
_new_call += " (" + tempFields.join(", ") + ")";
2197-
}
2198-
callsign_list.push(_new_call); // catch cases where there are no fields
2331+
for (var i = 0; i < data.uploaders.length; i++) {
2332+
_new_call = data.uploaders[i].uploader_callsign;
2333+
tempFields = [];
2334+
if(data.uploaders[i].hasOwnProperty('snr')) {
2335+
tempFields.push(data.uploaders[i].snr.toFixed(0) + " dB");
2336+
}
2337+
if(data.uploaders[i].hasOwnProperty('rssi')) {
2338+
tempFields.push(data.uploaders[i].rssi.toFixed(0) + " dBm");
2339+
}
2340+
if(data.uploaders[i].hasOwnProperty('frequency')) {
2341+
tempFields.push(data.uploaders[i].frequency + " MHz");
21992342
}
2343+
if(tempFields.length > 0) {
2344+
_new_call += " (" + tempFields.join(", ") + ")";
2345+
}
2346+
callsign_list.push(_new_call); // catch cases where there are no fields
2347+
}
22002348

2201-
callsign_list = callsign_list.join("<br /> ");
2349+
callsign_list = callsign_list.join("<br /> ");
22022350

2203-
html += callsign_list + "</div>";
2351+
html += callsign_list + "</div>";
22042352

2205-
div.innerHTML = html;
2353+
div.innerHTML = html;
22062354

2207-
mapInfoBox.setContent(div);
2208-
mapInfoBox.openOn(map);
2355+
mapInfoBox.setContent(div);
2356+
mapInfoBox.openOn(map);
22092357

2210-
setTimeout(function() {
2211-
div.parentElement.style.overflow = "";
2212-
div.parentElement.style.overflowWrap = "break-word";
2213-
}, 16);
2214-
});
2215-
};
2358+
setTimeout(function() {
2359+
div.parentElement.style.overflow = "";
2360+
div.parentElement.style.overflowWrap = "break-word";
2361+
}, 16);
2362+
}
22162363

22172364
function mapInfoBox_handle_prediction(event) {
22182365
var data = event.target.pdata;
@@ -3464,7 +3611,17 @@ function formatData(data, live) {
34643611
if (data[i].temp) {
34653612
dataTempEntry.data.temperature_external = data[i].temp;
34663613
}
3467-
if (data[i].type) {
3614+
if (data[i].type && data[i].type == "payload_telemetry") { // SondeHub V1 data
3615+
var comment = data[i].comment.split(" ");
3616+
if (v1types.hasOwnProperty(comment[0])) {
3617+
dataTempEntry.data.type = v1types[comment[0]];
3618+
dataTempEntry.type = v1types[comment[0]];
3619+
if (v1manufacturers.hasOwnProperty(dataTempEntry.type)) {
3620+
dataTempEntry.data.manufacturer = v1manufacturers[dataTempEntry.type];
3621+
}
3622+
}
3623+
dataTempEntry.data.frequency = comment[2];
3624+
} else if (data[i].type) {
34683625
dataTempEntry.data.type = data[i].type;
34693626
dataTempEntry.type = data[i].type;
34703627
}

0 commit comments

Comments
 (0)