mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Added DS packet logging.
This commit is contained in:
6
arena.go
6
arena.go
@@ -341,8 +341,10 @@ func (arena *Arena) StartMatch() error {
|
||||
// Save the missed packet count to subtract it from the running count.
|
||||
for _, allianceStation := range arena.AllianceStations {
|
||||
if allianceStation.DsConn != nil {
|
||||
allianceStation.DsConn.DriverStationStatus.MissedPacketOffset =
|
||||
allianceStation.DsConn.DriverStationStatus.MissedPacketCount
|
||||
err = allianceStation.DsConn.signalMatchStart(arena.currentMatch)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,19 +20,18 @@ const driverStationProtocolVersion = "11191100"
|
||||
const driverStationLinkTimeoutMs = 500
|
||||
|
||||
type DriverStationStatus struct {
|
||||
TeamId int
|
||||
AllianceStation string
|
||||
DsLinked bool
|
||||
RobotLinked bool
|
||||
Auto bool
|
||||
Enabled bool
|
||||
EmergencyStop bool
|
||||
BatteryVoltage float64
|
||||
DsVersion string
|
||||
PacketCount int
|
||||
MissedPacketCount int
|
||||
MissedPacketOffset int
|
||||
DsRobotTripTimeMs int
|
||||
TeamId int
|
||||
AllianceStation string
|
||||
DsLinked bool
|
||||
RobotLinked bool
|
||||
Auto bool
|
||||
Enabled bool
|
||||
EmergencyStop bool
|
||||
BatteryVoltage float64
|
||||
DsVersion string
|
||||
PacketCount int
|
||||
MissedPacketCount int
|
||||
DsRobotTripTimeMs int
|
||||
}
|
||||
|
||||
type DriverStationConnection struct {
|
||||
@@ -47,6 +46,8 @@ type DriverStationConnection struct {
|
||||
SecondsSinceLastRobotLink float64
|
||||
conn net.Conn
|
||||
packetCount int
|
||||
missedPacketOffset int
|
||||
log *TeamMatchLog
|
||||
}
|
||||
|
||||
// Opens a UDP connection for communicating to the driver station.
|
||||
@@ -76,6 +77,9 @@ func (dsConn *DriverStationConnection) Update() error {
|
||||
}
|
||||
|
||||
func (dsConn *DriverStationConnection) Close() error {
|
||||
if dsConn.log != nil {
|
||||
dsConn.log.Close()
|
||||
}
|
||||
return dsConn.conn.Close()
|
||||
}
|
||||
|
||||
@@ -108,10 +112,24 @@ func ListenForDsPackets(listener *net.UDPConn) {
|
||||
dsConn.LastRobotLinkedTime = time.Now()
|
||||
}
|
||||
dsConn.SecondsSinceLastRobotLink = time.Since(dsConn.LastRobotLinkedTime).Seconds()
|
||||
dsConn.DriverStationStatus.MissedPacketCount -= dsConn.missedPacketOffset
|
||||
|
||||
// Log the packet if the match is in progress.
|
||||
matchTimeSec := mainArena.MatchTimeSec()
|
||||
if matchTimeSec > 0 && dsConn.log != nil {
|
||||
dsConn.log.LogDsStatus(matchTimeSec, dsStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dsConn *DriverStationConnection) signalMatchStart(match *Match) error {
|
||||
dsConn.missedPacketOffset = dsConn.DriverStationStatus.MissedPacketCount
|
||||
var err error
|
||||
dsConn.log, err = NewTeamMatchLog(dsConn.TeamId, match)
|
||||
return err
|
||||
}
|
||||
|
||||
// Serializes the control information into a packet.
|
||||
func (dsConn *DriverStationConnection) encodeControlPacket() [74]byte {
|
||||
var packet [74]byte
|
||||
|
||||
@@ -25,7 +25,7 @@ var handleStatus = function(data) {
|
||||
$("#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);
|
||||
$("#status" + station + " .packet-loss").text(dsStatus.MissedPacketCount - dsStatus.MissedPacketOffset);
|
||||
$("#status" + station + " .packet-loss").text(dsStatus.MissedPacketCount);
|
||||
} else {
|
||||
$("#status" + station + " .ds-status").attr("data-status-ok", "");
|
||||
$("#status" + station + " .robot-status").attr("data-status-ok", "");
|
||||
|
||||
51
team_match_log.go
Normal file
51
team_match_log.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2014 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Utilities for logging packets received from team driver stations during a match.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const logsDir = "static/logs"
|
||||
|
||||
type TeamMatchLog struct {
|
||||
logger *log.Logger
|
||||
logFile *os.File
|
||||
}
|
||||
|
||||
func NewTeamMatchLog(teamId int, match *Match) (*TeamMatchLog, error) {
|
||||
err := os.MkdirAll(logsDir, 0755)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("%s/%s_%s_Match_%s_%d.csv", logsDir, time.Now().Format("20060102150405"),
|
||||
match.CapitalizedType(), match.DisplayName, teamId)
|
||||
logFile, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log := TeamMatchLog{log.New(logFile, "", 0), logFile}
|
||||
log.logger.Println("matchTimeSec,teamId,allianceStation,robotLinked,auto,enabled,emergencyStop," +
|
||||
"batteryVoltage,dsVersion,packetCount,missedPacketCount,dsRobotTripTimeMs")
|
||||
|
||||
return &log, nil
|
||||
}
|
||||
|
||||
func (log *TeamMatchLog) LogDsStatus(matchTimeSec float64, dsStatus *DriverStationStatus) {
|
||||
log.logger.Printf("%f,%d,%s,%v,%v,%v,%v,%f,%s,%d,%d,%d", matchTimeSec, dsStatus.TeamId,
|
||||
dsStatus.AllianceStation, dsStatus.RobotLinked, dsStatus.Auto, dsStatus.Enabled,
|
||||
dsStatus.EmergencyStop, dsStatus.BatteryVoltage, dsStatus.DsVersion, dsStatus.PacketCount,
|
||||
dsStatus.MissedPacketCount, dsStatus.DsRobotTripTimeMs)
|
||||
}
|
||||
|
||||
func (log *TeamMatchLog) Close() {
|
||||
log.logFile.Close()
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="/match_play">Match Play</a></li>
|
||||
<li><a href="/match_review">Match Review</a></li>
|
||||
<li><a href="/static/logs">Match Logs</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="dropdown">
|
||||
|
||||
Reference in New Issue
Block a user