Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usdot-fhwa-stol/carma-platform#1703 #136

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 107 additions & 92 deletions website/scripts/ros/ros_system_alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,104 +10,119 @@
function checkSystemAlerts() {

// Subscribing to a Topic
listenerSystemAlert = new ROSLIB.Topic({
ros: g_ros,
name: T_SYSTEM_ALERT,
messageType: M_SYSTEM_ALERT
});
let systemAlertQueue = [];
// Then we add a callback to be called every time a message is published on this topic.
listenerSystemAlert.subscribe(function (message)
// Check if our global subscription variable is defined already
if (typeof listenerSystemAlert === 'undefined' || listenerSystemAlert === null)
{
//Check ROSBridge connection before subscribe a topic
IsROSBridgeConnected();
var messageTypeFullDescription = 'NA';
console.log("system alert type" + message.type);
switch (message.type)
// Initialize a topic object
listenerSystemAlert = new ROSLIB.Topic({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type check after definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite following what you are asking here.
What are you asking to type check?

ros: g_ros,
name: T_SYSTEM_ALERT,
messageType: M_SYSTEM_ALERT
});

// Then we add a callback to be called every time a message is published on this topic.
systemAlertCallback = function (message)
{
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;
//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;
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_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_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_NOT_READY:
session_isSystemAlert.ready = false;
messageTypeFullDescription = 'System not ready, please wait and try again. ' + message.description;
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_DRIVERS_READY:
session_isSystemAlert.ready = true;
messageTypeFullDescription = 'System ready. ' + message.description;
$('#divCapabilitiesSystemAlert').html('');
break;
case SYSTEM_ALERT_DRIVERS_READY:
session_isSystemAlert.ready = true;
messageTypeFullDescription = 'System ready. ' + message.description;
$('#divCapabilitiesSystemAlert').html('');
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_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;

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)) );
}
});
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)) );
}
};

}
else // If it was defined, close the existing subscription so it can be reopened
{
listenerSystemAlert.unsubscribe(systemAlertCallback)
}




listenerSystemAlert.subscribe(systemAlertCallback);
}