From 462ecf249366ed36a46c501328f5971b137da02b Mon Sep 17 00:00:00 2001 From: Sebastian Delmont Date: Tue, 6 Apr 2021 17:28:40 -0400 Subject: [PATCH] Capture exceptions while drawing spot arcs Certain spots can trigger exceptions such as "could not calculate great circle between [] and []" which can hang GT. We now capture those, dump error info to the console, and move on --- package.nw/lib/gt.js | 485 +++++++++++++++++++++------------------ package.nw/lib/roster.js | 3 +- 2 files changed, 266 insertions(+), 222 deletions(-) diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index 11751882..913728b6 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -1923,115 +1923,122 @@ function splitNoParen(s) function createSpotTipTable(toolElement) { - var now = timeNowSec(); - var myTooltip = document.getElementById("myTooltip"); - var worker = ""; - if (toolElement.spot in g_receptionReports.spots) + try { - g_layerSources["psk-hop"].clear(); - var report = g_receptionReports.spots[toolElement.spot]; - - var LL = squareToLatLongAll(myRawGrid); - var Lat = LL.la2 - (LL.la2 - LL.la1) / 2; - var Lon = LL.lo2 - (LL.lo2 - LL.lo1) / 2; - var fromPoint = ol.proj.fromLonLat([Lon, Lat]); - - worker = - ""; - worker += - ""; - worker += - ""; - worker += - ""; - - if (report.dxcc > 0) + var now = timeNowSec(); + var myTooltip = document.getElementById("myTooltip"); + var worker = ""; + if (toolElement.spot in g_receptionReports.spots) { + g_layerSources["psk-hop"].clear(); + var report = g_receptionReports.spots[toolElement.spot]; + + var LL = squareToLatLongAll(myRawGrid); + var Lat = LL.la2 - (LL.la2 - LL.la1) / 2; + var Lon = LL.lo2 - (LL.lo2 - LL.lo1) / 2; + var fromPoint = ol.proj.fromLonLat([Lon, Lat]); + + worker = + "
Rx Spot
Age" + - Number(now - report.when).toDHMS() + - "
dB" + - Number(report.snr).formatSignalReport() + - "
Call" + - report.call.formatCallsign() + - "
"; worker += - ""; - } + ""; + worker += + ""; + worker += + ""; - worker += - ""; - worker += - ""; - worker += - ""; + if (report.dxcc > 0) + { + worker += + ""; + } - LL = squareToLatLongAll(report.grid); + worker += + ""; + worker += + ""; + worker += + ""; - report.bearing = parseInt( - MyCircle.bearing( - g_myLat, - g_myLon, - LL.la2 - (LL.la2 - LL.la1) / 2, - LL.lo2 - (LL.lo2 - LL.lo1) / 2 - ) - ); - worker += - ""; - worker += - ""; + LL.lo2 - (LL.lo2 - LL.lo1) / 2 + ) + ); + worker += + ""; + worker += + ""; - worker += - ""; + worker += + ""; - worker += "
Rx Spot
DXCC" + - g_dxccToAltName[report.dxcc] + - " (" + - g_worldGeoData[g_dxccToGeoData[report.dxcc]].pp + - ")
Age" + + Number(now - report.when).toDHMS() + + "
dB" + + Number(report.snr).formatSignalReport() + + "
Call" + + report.call.formatCallsign() + + "
Grid" + - report.grid + - "
Freq" + - report.freq.formatMhz() + - " (" + - report.band + - ")
Mode" + - report.mode + - "
DXCC" + + g_dxccToAltName[report.dxcc] + + " (" + + g_worldGeoData[g_dxccToGeoData[report.dxcc]].pp + + ")
Grid" + + report.grid + + "
Freq" + + report.freq.formatMhz() + + " (" + + report.band + + ")
Mode" + + report.mode + + "
Dist" + - parseInt( - MyCircle.distance( + LL = squareToLatLongAll(report.grid); + + report.bearing = parseInt( + MyCircle.bearing( g_myLat, g_myLon, LL.la2 - (LL.la2 - LL.la1) / 2, - LL.lo2 - (LL.lo2 - LL.lo1) / 2, - distanceUnit.value - ) * MyCircle.validateRadius(distanceUnit.value) - ) + - distanceUnit.value.toLowerCase() + - "
Azim" + - report.bearing + - "°
Dist" + + parseInt( + MyCircle.distance( + g_myLat, + g_myLon, + LL.la2 - (LL.la2 - LL.la1) / 2, + LL.lo2 - (LL.lo2 - LL.lo1) / 2, + distanceUnit.value + ) * MyCircle.validateRadius(distanceUnit.value) + ) + + distanceUnit.value.toLowerCase() + + "
Azim" + + report.bearing + + "°
Time" + - userTimeString(report.when * 1000) + - "
Time" + + userTimeString(report.when * 1000) + + "
"; + worker += ""; - var strokeWeight = pathWidthValue.value; + var strokeWeight = pathWidthValue.value; - Lat = LL.la2 - (LL.la2 - LL.la1) / 2; - Lon = LL.lo2 - (LL.lo2 - LL.lo1) / 2; + Lat = LL.la2 - (LL.la2 - LL.la1) / 2; + Lon = LL.lo2 - (LL.lo2 - LL.lo1) / 2; - var toPoint = ol.proj.fromLonLat([Lon, Lat]); + var toPoint = ol.proj.fromLonLat([Lon, Lat]); - var feature = flightFeature( - [fromPoint, toPoint], - { - weight: strokeWeight, - color: getQrzPathColor(), - steps: 75 - }, - "psk-hop", - false - ); + var feature = flightFeature( + [fromPoint, toPoint], + { + weight: strokeWeight, + color: getQrzPathColor(), + steps: 75 + }, + "psk-hop", + false + ); + } + myTooltip.innerHTML = worker; + g_passingToolTipTableString = worker; + return 10; + } + catch (err) + { + console.log("Unexpected error at createSpotTipTable", toolElement, err) } - myTooltip.innerHTML = worker; - g_passingToolTipTableString = worker; - return 10; } function createTooltTipTable(toolElement) @@ -6818,17 +6825,24 @@ function handleWsjtxStatus(newMessage) if (toPoint) { - g_transmitFlightPath = flightFeature( - [fromPoint, toPoint], - { - weight: strokeWeight, - color: strokeColor, - steps: 75, - zIndex: 90 - }, - "transmit", - true - ); + try + { + g_transmitFlightPath = flightFeature( + [fromPoint, toPoint], + { + weight: strokeWeight, + color: strokeColor, + steps: 75, + zIndex: 90 + }, + "transmit", + true + ); + } + catch (err) + { + console.log("Unexpected error inside handleWsjtxStatus", err) + } } } g_weAreDecoding = false; @@ -7309,23 +7323,30 @@ function handleWsjtxDecode(newMessage) var fromPoint = getPoint(callsign.grid); var toPoint = getPoint(DEcallsign.grid); - flightPath = flightFeature( - [fromPoint, toPoint], - { - weight: strokeWeight, - color: strokeColor, - steps: 75, - zIndex: 90 - }, - "flight", - true - ); + try + { + flightPath = flightFeature( + [fromPoint, toPoint], + { + weight: strokeWeight, + color: strokeColor, + steps: 75, + zIndex: 90 + }, + "flight", + true + ); - flightPath.age = g_timeNow + g_flightDuration; - flightPath.isShapeFlight = 0; - flightPath.isQRZ = isQRZ; + flightPath.age = g_timeNow + g_flightDuration; + flightPath.isShapeFlight = 0; + flightPath.isQRZ = isQRZ; - g_flightPaths.push(flightPath); + g_flightPaths.push(flightPath); + } + catch (err) + { + console.log("Unexpected error inside handleWsjtxDecode 1", err) + } } } } @@ -7350,23 +7371,30 @@ function handleWsjtxDecode(newMessage) var Lon = g_worldGeoData[g_dxccToGeoData[callsign.dxcc]].lon; var fromPoint = ol.proj.fromLonLat([Lon, Lat]); - flightPath = flightFeature( - [fromPoint, toPoint], - { - weight: strokeWeight, - color: strokeColor, - steps: 75, - zIndex: 90 - }, - "flight", - true - ); + try + { + flightPath = flightFeature( + [fromPoint, toPoint], + { + weight: strokeWeight, + color: strokeColor, + steps: 75, + zIndex: 90 + }, + "flight", + true + ); - flightPath.age = g_timeNow + g_flightDuration; - flightPath.isShapeFlight = 0; - flightPath.isQRZ = isQRZ; + flightPath.age = g_timeNow + g_flightDuration; + flightPath.isShapeFlight = 0; + flightPath.isQRZ = isQRZ; - g_flightPaths.push(flightPath); + g_flightPaths.push(flightPath); + } + catch (err) + { + console.log("Unexpected error inside handleWsjtxDecode 2", err) + } var feature = shapeFeature( "qrz", @@ -7445,22 +7473,29 @@ function handleWsjtxDecode(newMessage) var fromPoint = getPoint(callsign.grid); var toPoint = ol.proj.fromLonLat(locality.properties.center); - flightPath = flightFeature( - [fromPoint, toPoint], - { - weight: strokeWeight, - color: strokeColor, - steps: 75, - zIndex: 90 - }, - "flight", - true - ); + try + { + flightPath = flightFeature( + [fromPoint, toPoint], + { + weight: strokeWeight, + color: strokeColor, + steps: 75, + zIndex: 90 + }, + "flight", + true + ); - flightPath.age = g_timeNow + g_flightDuration; - flightPath.isShapeFlight = 0; - flightPath.isQRZ = false; - g_flightPaths.push(flightPath); + flightPath.age = g_timeNow + g_flightDuration; + flightPath.isShapeFlight = 0; + flightPath.isQRZ = false; + g_flightPaths.push(flightPath); + } + catch (err) + { + console.log("Unexpected error inside handleWsjtxDecode 3", err) + } } } } @@ -16115,83 +16150,91 @@ var g_spotTotalCount = 0; function createSpot(report, key, fromPoint, addToLayer = true) { - var LL = squareToLatLongAll(report.grid); - - var Lat = LL.la2 - (LL.la2 - LL.la1) / 2; - var Lon = LL.lo2 - (LL.lo2 - LL.lo1) / 2; - - var spot = spotFeature([Lon, Lat]); - - var colorNoAlpha = "#" + g_bandToColor[report.band]; - var colorAlpha = intAlphaToRGB(colorNoAlpha, report.color); - var spotColor = colorAlpha; - - var workingColor = - g_mapSettings.nightMapEnable && g_nightTime - ? g_receptionSettings.pathNightColor - : g_receptionSettings.pathColor; - - if (workingColor != -1) + try { - var testColor = - workingColor < 1 - ? "#0000000" - : workingColor == 361 - ? "#FFFFFF" - : "hsla(" + workingColor + ", 100%, 50%," + report.color / 255 + ")"; - if (workingColor < 1 || workingColor == 361) - { spotColor = intAlphaToRGB(testColor.substr(0, 7), report.color); } - else spotColor = testColor; + var LL = squareToLatLongAll(report.grid); + + var Lat = LL.la2 - (LL.la2 - LL.la1) / 2; + var Lon = LL.lo2 - (LL.lo2 - LL.lo1) / 2; + + var spot = spotFeature([Lon, Lat]); + + var colorNoAlpha = "#" + g_bandToColor[report.band]; + var colorAlpha = intAlphaToRGB(colorNoAlpha, report.color); + var spotColor = colorAlpha; + + var workingColor = + g_mapSettings.nightMapEnable && g_nightTime + ? g_receptionSettings.pathNightColor + : g_receptionSettings.pathColor; + + if (workingColor != -1) + { + var testColor = + workingColor < 1 + ? "#0000000" + : workingColor == 361 + ? "#FFFFFF" + : "hsla(" + workingColor + ", 100%, 50%," + report.color / 255 + ")"; + if (workingColor < 1 || workingColor == 361) + { spotColor = intAlphaToRGB(testColor.substr(0, 7), report.color); } + else spotColor = testColor; + } + + featureStyle = new ol.style.Style({ + fill: new ol.style.Fill({ + color: spotColor + }), + stroke: new ol.style.Stroke({ + color: "#000000FF", + width: 0.25 + }) + }); + spot.setStyle(featureStyle); + spot.spot = key; + spot.size = 6; // Mouseover detection + g_layerSources["psk-spots"].addFeature(spot); + + var toPoint = ol.proj.fromLonLat([Lon, Lat]); + + var lonLat = new ol.geom.Point(toPoint); + + var pointFeature = new ol.Feature({ + geometry: lonLat, + weight: report.color / 255 // e.g. temperature + }); + + g_layerSources["psk-heat"].addFeature(pointFeature); + + if (g_receptionSettings.viewPaths && g_receptionSettings.spotWidth > 0) + { + var strokeWeight = g_receptionSettings.spotWidth; + + var flightColor = + workingColor == -1 + ? colorNoAlpha + "BB" + : g_mapSettings.nightMapEnable && g_nightTime + ? g_spotNightFlightColor + : g_spotFlightColor; + + var feature = flightFeature( + [fromPoint, toPoint], + { + weight: strokeWeight, + color: flightColor, + steps: 75 + }, + "psk-flights", + false + ); + } } - - featureStyle = new ol.style.Style({ - fill: new ol.style.Fill({ - color: spotColor - }), - stroke: new ol.style.Stroke({ - color: "#000000FF", - width: 0.25 - }) - }); - spot.setStyle(featureStyle); - spot.spot = key; - spot.size = 6; // Mouseover detection - g_layerSources["psk-spots"].addFeature(spot); - - var toPoint = ol.proj.fromLonLat([Lon, Lat]); - - var lonLat = new ol.geom.Point(toPoint); - - var pointFeature = new ol.Feature({ - geometry: lonLat, - weight: report.color / 255 // e.g. temperature - }); - - g_layerSources["psk-heat"].addFeature(pointFeature); - - if (g_receptionSettings.viewPaths && g_receptionSettings.spotWidth > 0) + catch (err) { - var strokeWeight = g_receptionSettings.spotWidth; - - var flightColor = - workingColor == -1 - ? colorNoAlpha + "BB" - : g_mapSettings.nightMapEnable && g_nightTime - ? g_spotNightFlightColor - : g_spotFlightColor; - - var feature = flightFeature( - [fromPoint, toPoint], - { - weight: strokeWeight, - color: flightColor, - steps: 75 - }, - "psk-flights", - false - ); + console.log("Unexpected error inside createSpot", report, err) } } + function redrawSpots() { let shouldSave = false; diff --git a/package.nw/lib/roster.js b/package.nw/lib/roster.js index 92615c54..9239b928 100644 --- a/package.nw/lib/roster.js +++ b/package.nw/lib/roster.js @@ -2412,7 +2412,8 @@ function updateInstances() instancesDiv.innerHTML = worker; instancesWrapper.style.display = ""; } - else { + else + { instancesDiv.innerHTML = ""; instancesWrapper.style.display = "none"; }