From 449d8725f52d2233a60bbc7eba697d719d961e9b Mon Sep 17 00:00:00 2001 From: Michael McConnell Date: Tue, 5 Apr 2022 08:49:54 -0700 Subject: [PATCH 1/2] Adding fix for https://github.com/usdot-fhwa-stol/carma-platform/issues/1703 --- website/scripts/ros/ros_system_alert.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/website/scripts/ros/ros_system_alert.js b/website/scripts/ros/ros_system_alert.js index dbaaba0..1d1e7b5 100644 --- a/website/scripts/ros/ros_system_alert.js +++ b/website/scripts/ros/ros_system_alert.js @@ -10,12 +10,23 @@ function checkSystemAlerts() { // Subscribing to a Topic - listenerSystemAlert = new ROSLIB.Topic({ - ros: g_ros, - name: T_SYSTEM_ALERT, - messageType: M_SYSTEM_ALERT - }); - let systemAlertQueue = []; + // Check if our global subscription variable is defined already + if (typeof listenerSystemAlert === 'undefined' || listenerSystemAlert === null) + { + // Initialize a topic object + listenerSystemAlert = new ROSLIB.Topic({ + ros: g_ros, + name: T_SYSTEM_ALERT, + messageType: M_SYSTEM_ALERT + }); + + } + else // If it was defined, close the existing subscription so it can be reopened + { + listenerSystemAlert.unsubscribe() + } + + // Then we add a callback to be called every time a message is published on this topic. listenerSystemAlert.subscribe(function (message) { From a99fd8eae315c8271014a229fe55a844350945b2 Mon Sep 17 00:00:00 2001 From: Michael McConnell Date: Tue, 5 Apr 2022 10:29:27 -0700 Subject: [PATCH 2/2] Fix unsubscribe call --- website/scripts/ros/ros_system_alert.js | 190 ++++++++++++------------ 1 file changed, 97 insertions(+), 93 deletions(-) diff --git a/website/scripts/ros/ros_system_alert.js b/website/scripts/ros/ros_system_alert.js index 1d1e7b5..40f2868 100644 --- a/website/scripts/ros/ros_system_alert.js +++ b/website/scripts/ros/ros_system_alert.js @@ -20,105 +20,109 @@ function checkSystemAlerts() { messageType: M_SYSTEM_ALERT }); - } - else // If it was defined, close the existing subscription so it can be reopened - { - listenerSystemAlert.unsubscribe() - } + // Then we add a callback to be called every time a message is published on this topic. + systemAlertCallback = function (message) + { + //Check ROSBridge connection before subscribe a topic + IsROSBridgeConnected(); + var messageTypeFullDescription = 'NA'; + console.log("system alert type" + message.type); + switch (message.type) + { + case SYSTEM_ALERT_CAUTION: + session_isSystemAlert.ready = false; + messageTypeFullDescription = 'System received a CAUTION message. ' + message.description; + MsgPop.open({ + Type: "caution", + Content: message.description, + AutoClose: true, + CloseTimer: 30000, + ClickAnyClose: true, + ShowIcon: true, + HideCloseBtn: false}); + break; + case SYSTEM_ALERT_WARNING: + session_isSystemAlert.ready = false; + messageTypeFullDescription = 'System received a WARNING message. ' + message.description; + MsgPop.open({ + Type: "warning", + Content: message.description, + AutoClose: true, + CloseTimer: 30000, + ClickAnyClose: true, + ShowIcon: true, + HideCloseBtn: false}); + break; - // Then we add a callback to be called every time a message is published on this topic. - listenerSystemAlert.subscribe(function (message) - { - //Check ROSBridge connection before subscribe a topic - IsROSBridgeConnected(); - var messageTypeFullDescription = 'NA'; - console.log("system alert type" + message.type); - switch (message.type) - { - case SYSTEM_ALERT_CAUTION: - session_isSystemAlert.ready = false; - messageTypeFullDescription = 'System received a CAUTION message. ' + message.description; - MsgPop.open({ - Type: "caution", - Content: message.description, - AutoClose: true, - CloseTimer: 30000, - ClickAnyClose: true, - ShowIcon: true, - HideCloseBtn: false}); - break; + case SYSTEM_ALERT_FATAL: + session_isSystemAlert.ready = false; + messageTypeFullDescription = 'System received a CRITICAL message. ' + message.description; + MsgPop.open({ + Type: "error", + Content: message.description, + AutoClose: true, + ClickAnyClose: true, + ShowIcon: true, + HideCloseBtn: false + }); + break; - case SYSTEM_ALERT_WARNING: - session_isSystemAlert.ready = false; - messageTypeFullDescription = 'System received a WARNING message. ' + message.description; - MsgPop.open({ - Type: "warning", - Content: message.description, - AutoClose: true, - CloseTimer: 30000, - ClickAnyClose: true, - ShowIcon: true, - HideCloseBtn: false}); - break; + case SYSTEM_ALERT_NOT_READY: + session_isSystemAlert.ready = false; + messageTypeFullDescription = 'System not ready, please wait and try again. ' + message.description; + break; - case SYSTEM_ALERT_FATAL: - session_isSystemAlert.ready = false; - messageTypeFullDescription = 'System received a CRITICAL message. ' + message.description; - MsgPop.open({ - Type: "error", - Content: message.description, - AutoClose: true, - ClickAnyClose: true, - ShowIcon: true, - HideCloseBtn: false - }); - break; + case SYSTEM_ALERT_DRIVERS_READY: + session_isSystemAlert.ready = true; + messageTypeFullDescription = 'System ready. ' + message.description; + $('#divCapabilitiesSystemAlert').html(''); + break; - case SYSTEM_ALERT_NOT_READY: - session_isSystemAlert.ready = false; - messageTypeFullDescription = 'System not ready, please wait and try again. ' + message.description; - break; + case SYSTEM_ALERT_SHUTDOWN: + session_isSystemAlert.ready = false; + listenerSystemAlert.unsubscribe(); + //Show modal popup for Fatal alerts. + messageTypeFullDescription = 'PLEASE TAKE MANUAL CONTROL OF THE VEHICLE.'; + messageTypeFullDescription += '

System received a SHUTDOWN message. Please wait for system to shut down.

' + message.description; + listenerSystemAlert.unsubscribe(); + //If this modal does not exist, create one + if( $('#systemAlertModal').length < 1 ) + { + $('#ModalsArea').append(createSystemAlertModal( + '  SYSTEM ALERT', + messageTypeFullDescription, + false,true + )); + } + $('#systemAlertModal').modal({backdrop: 'static', keyboard: false}); + playSound('audioAlert1', false); + break; - case SYSTEM_ALERT_DRIVERS_READY: - session_isSystemAlert.ready = true; - messageTypeFullDescription = 'System ready. ' + message.description; - $('#divCapabilitiesSystemAlert').html(''); - break; + default: + session_isSystemAlert.ready = false; + messageTypeFullDescription = 'System alert type is unknown. Assuming system it not yet ready. ' + message.description; + break; + } + let currentTime = new Date().toLocaleTimeString("en-US", {timeZone: "America/New_York"}); + let eachElement = currentTime+'-'+messageTypeFullDescription + " "; + let eachElementLeight = eachElement.length; + $('#logs-panel-text-system-alert').prepend( eachElement ); + let currnettext = $('#logs-panel-text-system-alert').html(); + if ( (currnettext.length / eachElementLeight) > MAX_LOG_LINES) + { + $('#logs-panel-text-system-alert').html( currnettext.substring(0, (currnettext.length - eachElementLeight)) ); + } + }; - case SYSTEM_ALERT_SHUTDOWN: - session_isSystemAlert.ready = false; - listenerSystemAlert.unsubscribe(); - //Show modal popup for Fatal alerts. - messageTypeFullDescription = 'PLEASE TAKE MANUAL CONTROL OF THE VEHICLE.'; - messageTypeFullDescription += '

System received a SHUTDOWN message. Please wait for system to shut down.

' + message.description; - listenerSystemAlert.unsubscribe(); - //If this modal does not exist, create one - if( $('#systemAlertModal').length < 1 ) - { - $('#ModalsArea').append(createSystemAlertModal( - '  SYSTEM ALERT', - messageTypeFullDescription, - false,true - )); - } - $('#systemAlertModal').modal({backdrop: 'static', keyboard: false}); - playSound('audioAlert1', false); - break; + } + else // If it was defined, close the existing subscription so it can be reopened + { + listenerSystemAlert.unsubscribe(systemAlertCallback) + } - default: - session_isSystemAlert.ready = false; - messageTypeFullDescription = 'System alert type is unknown. Assuming system it not yet ready. ' + message.description; - break; - } - let currentTime = new Date().toLocaleTimeString("en-US", {timeZone: "America/New_York"}); - let eachElement = currentTime+'-'+messageTypeFullDescription + " "; - let eachElementLeight = eachElement.length; - $('#logs-panel-text-system-alert').prepend( eachElement ); - let currnettext = $('#logs-panel-text-system-alert').html(); - if ( (currnettext.length / eachElementLeight) > MAX_LOG_LINES) - { - $('#logs-panel-text-system-alert').html( currnettext.substring(0, (currnettext.length - eachElementLeight)) ); - } - }); + + + + listenerSystemAlert.subscribe(systemAlertCallback); } \ No newline at end of file