Files
cheesy-arena-lite/static/js/fta_display.js

70 lines
3.4 KiB
JavaScript
Raw Normal View History

2014-08-23 23:41:15 -07:00
// Copyright 2014 Team 254. All Rights Reserved.
// Author: austin.linux@gmail.com (Austin Schuh)
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Client-side logic for the FTA diagnostic display.
var websocket;
// Handles a websocket message to update the team connection status.
2014-08-23 23:41:15 -07:00
var handleStatus = function(data) {
// Update the team status view.
$.each(data.AllianceStations, function(station, stationStatus) {
if (stationStatus.DsConn) {
$("#status" + station + " .team").text(stationStatus.DsConn.TeamId);
var dsStatus = stationStatus.DsConn.DriverStationStatus;
$("#status" + station + " .ds-status").attr("data-status-ok", dsStatus.DsLinked);
2015-06-20 23:54:14 -07:00
$("#status" + station + " .ds-status").text(dsStatus.MBpsToRobot.toFixed(1) + "/" + dsStatus.MBpsFromRobot.toFixed(1));
2014-08-23 23:41:15 -07:00
$("#status" + station + " .robot-status").attr("data-status-ok", dsStatus.RobotLinked);
if (stationStatus.DsConn.SecondsSinceLastRobotLink > 1 && stationStatus.DsConn.SecondsSinceLastRobotLink < 1000) {
$("#status" + station + " .robot-status").text(stationStatus.DsConn.SecondsSinceLastRobotLink.toFixed());
} else {
$("#status" + station + " .robot-status").text("");
}
var lowBatteryThreshold = 6;
if (matchStates[data.MatchState] == "PRE_MATCH") {
lowBatteryThreshold = 12;
}
2014-08-23 23:41:15 -07:00
$("#status" + station + " .battery-status").attr("data-status-ok",
dsStatus.BatteryVoltage > lowBatteryThreshold && dsStatus.RobotLinked);
2014-08-23 23:41:15 -07:00
$("#status" + station + " .battery-status").text(dsStatus.BatteryVoltage.toFixed(1) + "V");
$("#status" + station + " .trip-time").attr("data-status-ok", true);
$("#status" + station + " .trip-time").text(dsStatus.DsRobotTripTimeMs.toFixed(1) + "ms");
$("#status" + station + " .packet-loss").attr("data-status-ok", true);
2014-08-28 21:20:04 -07:00
$("#status" + station + " .packet-loss").text(dsStatus.MissedPacketCount);
2014-08-23 23:41:15 -07:00
} else {
$("#status" + station + " .ds-status").attr("data-status-ok", "");
2015-06-20 23:54:14 -07:00
$("#status" + station + " .ds-status").text("");
2014-08-23 23:41:15 -07:00
$("#status" + station + " .robot-status").attr("data-status-ok", "");
$("#status" + station + " .robot-status").text("");
$("#status" + station + " .battery-status").attr("data-status-ok", "");
$("#status" + station + " .battery-status").text("");
$("#status" + station + " .trip-time").attr("data-status-ok", "");
$("#status" + station + " .trip-time").text("");
$("#status" + station + " .packet-loss").attr("data-status-ok", "");
$("#status" + station + " .packet-loss").text("");
}
if (stationStatus.EmergencyStop) {
$("#status" + station + " .bypass-status-fta").attr("data-status-ok", false);
$("#status" + station + " .bypass-status-fta").text("ES");
} else if (stationStatus.Bypass) {
$("#status" + station + " .bypass-status-fta").attr("data-status-ok", false);
$("#status" + station + " .bypass-status-fta").text("B");
} else {
$("#status" + station + " .bypass-status-fta").attr("data-status-ok", true);
$("#status" + station + " .bypass-status-fta").text("");
}
});
};
$(function() {
// Activate tooltips above the status headers.
$("[data-toggle=tooltip]").tooltip({"placement": "top"});
// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/match_play/websocket", {
status: function(event) { handleStatus(event.data); }
});
});