Skip to content

Commit

Permalink
Fix unsubscribe call
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael McConnell authored and Michael McConnell committed Apr 5, 2022
1 parent 449d872 commit a99fd8e
Showing 1 changed file with 97 additions and 93 deletions.
190 changes: 97 additions & 93 deletions website/scripts/ros/ros_system_alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <strong>MANUAL</strong> CONTROL OF THE VEHICLE.';
messageTypeFullDescription += '<br/><br/>System received a SHUTDOWN message. Please wait for system to shut down. <br/><br/>' + message.description;
listenerSystemAlert.unsubscribe();
//If this modal does not exist, create one
if( $('#systemAlertModal').length < 1 )
{
$('#ModalsArea').append(createSystemAlertModal(
'<span style="color:red"><i class="fas fa-exclamation-triangle"></i></span>&nbsp;&nbsp;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 + "&#13;&#10;";
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 <strong>MANUAL</strong> CONTROL OF THE VEHICLE.';
messageTypeFullDescription += '<br/><br/>System received a SHUTDOWN message. Please wait for system to shut down. <br/><br/>' + message.description;
listenerSystemAlert.unsubscribe();
//If this modal does not exist, create one
if( $('#systemAlertModal').length < 1 )
{
$('#ModalsArea').append(createSystemAlertModal(
'<span style="color:red"><i class="fas fa-exclamation-triangle"></i></span>&nbsp;&nbsp;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 + "&#13;&#10;";
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);
}

0 comments on commit a99fd8e

Please sign in to comment.