diff --git a/db/migrations/20140524160241_CreateEventSettings.sql b/db/migrations/20140524160241_CreateEventSettings.sql index 1ca267c..fa1248f 100644 --- a/db/migrations/20140524160241_CreateEventSettings.sql +++ b/db/migrations/20140524160241_CreateEventSettings.sql @@ -20,7 +20,6 @@ CREATE TABLE event_settings ( apadminwpakey VARCHAR(255), switchaddress VARCHAR(255), switchpassword VARCHAR(255), - bandwidthmonitoringenabled bool, plcaddress VARCHAR(255), tbadownloadenabled bool, adminpassword VARCHAR(255), diff --git a/field/arena.go b/field/arena.go index 40afc83..9b5a6ca 100644 --- a/field/arena.go +++ b/field/arena.go @@ -507,7 +507,6 @@ func (arena *Arena) Run() { // Start other loops in goroutines. go arena.listenForDriverStations() go arena.listenForDsUdpPackets() - go arena.monitorBandwidth() go arena.Plc.Run() for { diff --git a/field/bandwidth_monitor.go b/field/bandwidth_monitor.go deleted file mode 100644 index 65ed0b2..0000000 --- a/field/bandwidth_monitor.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2015 Team 254. All Rights Reserved. -// Author: pat@patfairbank.com (Patrick Fairbank) -// -// Methods for monitoring team bandwidth usage across a managed switch. - -package field - -import ( - "fmt" - "github.com/cdevr/WapSNMP" - "log" - "time" -) - -const ( - monitoringIntervalMs = 1000 - toRobotBytesOid = ".1.3.6.1.2.1.2.2.1.10" - fromRobotBytesOid = ".1.3.6.1.2.1.2.2.1.16" - red1Port = 6 - red2Port = 8 - red3Port = 10 - blue1Port = 12 - blue2Port = 14 - blue3Port = 16 -) - -type BandwidthMonitor struct { - allianceStations *map[string]*AllianceStation - snmpClient *wapsnmp.WapSNMP - toRobotOids []wapsnmp.Oid - fromRobotOids []wapsnmp.Oid - lastToRobotBytes map[string]interface{} - lastFromRobotBytes map[string]interface{} - lastBytesTime time.Time -} - -// Loops indefinitely to query the managed switch via SNMP (Simple Network Management Protocol). -func (arena *Arena) monitorBandwidth() { - monitor := BandwidthMonitor{allianceStations: &arena.AllianceStations} - - for _, port := range []int{red1Port, red2Port, red3Port, blue1Port, blue2Port, blue3Port} { - toOid := fmt.Sprintf("%s.%d", toRobotBytesOid, 10100+port) - fromOid := fmt.Sprintf("%s.%d", fromRobotBytesOid, 10100+port) - monitor.toRobotOids = append(monitor.toRobotOids, wapsnmp.MustParseOid(toOid)) - monitor.fromRobotOids = append(monitor.fromRobotOids, wapsnmp.MustParseOid(fromOid)) - } - - for { - if monitor.snmpClient != nil && monitor.snmpClient.Target != arena.EventSettings.SwitchAddress { - // Switch address has changed; must re-create the SNMP client. - monitor.snmpClient.Close() - monitor.snmpClient = nil - } - - if monitor.snmpClient == nil { - var err error - monitor.snmpClient, err = wapsnmp.NewWapSNMP(arena.EventSettings.SwitchAddress, - arena.EventSettings.SwitchPassword, wapsnmp.SNMPv2c, 2*time.Second, 0) - if err != nil { - log.Printf("Error starting bandwidth monitoring: %v", err) - continue - } - } - - if arena.EventSettings.NetworkSecurityEnabled && arena.EventSettings.BandwidthMonitoringEnabled { - err := monitor.updateBandwidth() - if err != nil { - log.Printf("Bandwidth monitoring error: %v", err) - } - } - time.Sleep(time.Millisecond * monitoringIntervalMs) - } -} - -func (monitor *BandwidthMonitor) updateBandwidth() error { - // Retrieve total number of bytes sent/received per port. - toRobotBytes, err := monitor.snmpClient.GetMultiple(monitor.toRobotOids) - if err != nil { - return err - } - fromRobotBytes, err := monitor.snmpClient.GetMultiple(monitor.fromRobotOids) - if err != nil { - return err - } - - // Calculate the bandwidth usage over time. - monitor.updateStationBandwidth("R1", 0, toRobotBytes, fromRobotBytes) - monitor.updateStationBandwidth("R2", 1, toRobotBytes, fromRobotBytes) - monitor.updateStationBandwidth("R3", 2, toRobotBytes, fromRobotBytes) - monitor.updateStationBandwidth("B1", 3, toRobotBytes, fromRobotBytes) - monitor.updateStationBandwidth("B2", 4, toRobotBytes, fromRobotBytes) - monitor.updateStationBandwidth("B3", 5, toRobotBytes, fromRobotBytes) - - monitor.lastToRobotBytes = toRobotBytes - monitor.lastFromRobotBytes = fromRobotBytes - monitor.lastBytesTime = time.Now() - return nil -} - -func (monitor *BandwidthMonitor) updateStationBandwidth(station string, oidIndex int, toRobotBytes map[string]interface{}, - fromRobotBytes map[string]interface{}) { - dsConn := (*monitor.allianceStations)[station].DsConn - if dsConn == nil { - // No team assigned; just skip it. - return - } - secondsSinceLast := time.Now().Sub(monitor.lastBytesTime).Seconds() - - toOid := monitor.toRobotOids[oidIndex].String() - if _, ok := toRobotBytes[toOid]; !ok { - log.Printf("Error: OID %s not present in new to-robot stats %v.", toOid, toRobotBytes) - return - } - toRobotBytesForPort := uint32(toRobotBytes[toOid].(wapsnmp.Counter)) - if _, ok := monitor.lastToRobotBytes[toOid]; !ok { - // This may be the first time reading. - return - } - lastToRobotBytesForPort := uint32(monitor.lastToRobotBytes[toOid].(wapsnmp.Counter)) - dsConn.MBpsToRobot = float64(toRobotBytesForPort-lastToRobotBytesForPort) / 1024 / 128 / secondsSinceLast - - fromOid := monitor.fromRobotOids[oidIndex].String() - if _, ok := fromRobotBytes[fromOid]; !ok { - log.Printf("Error: OID %s not present in new from-robot stats %v.", fromOid, fromRobotBytes) - return - } - fromRobotBytesForPort := uint32(fromRobotBytes[fromOid].(wapsnmp.Counter)) - if _, ok := monitor.lastFromRobotBytes[fromOid]; !ok { - // This may be the first time reading. - return - } - lastFromRobotBytesForPort := uint32(monitor.lastFromRobotBytes[fromOid].(wapsnmp.Counter)) - dsConn.MBpsFromRobot = float64(fromRobotBytesForPort-lastFromRobotBytesForPort) / 1024 / 128 / secondsSinceLast -} diff --git a/field/driver_station_connection.go b/field/driver_station_connection.go index 5f3eebc..3765488 100644 --- a/field/driver_station_connection.go +++ b/field/driver_station_connection.go @@ -39,8 +39,6 @@ type DriverStationConnection struct { BatteryVoltage float64 DsRobotTripTimeMs int MissedPacketCount int - MBpsToRobot float64 - MBpsFromRobot float64 SecondsSinceLastRobotLink float64 lastPacketTime time.Time lastRobotLinkedTime time.Time @@ -120,8 +118,6 @@ func (dsConn *DriverStationConnection) update(arena *Arena) error { dsConn.RadioLinked = false dsConn.RobotLinked = false dsConn.BatteryVoltage = 0 - dsConn.MBpsToRobot = 0 - dsConn.MBpsFromRobot = 0 } dsConn.SecondsSinceLastRobotLink = time.Since(dsConn.lastRobotLinkedTime).Seconds() diff --git a/model/event_settings.go b/model/event_settings.go index 8476a02..7950c13 100644 --- a/model/event_settings.go +++ b/model/event_settings.go @@ -6,37 +6,36 @@ package model type EventSettings struct { - Id int - Name string - DisplayBackgroundColor string - NumElimAlliances int - SelectionRound2Order string - SelectionRound3Order string - TBADownloadEnabled bool - TbaPublishingEnabled bool - TbaEventCode string - TbaSecretId string - TbaSecret string - NetworkSecurityEnabled bool - ApAddress string - ApUsername string - ApPassword string - ApTeamChannel int - ApAdminChannel int - ApAdminWpaKey string - SwitchAddress string - SwitchPassword string - BandwidthMonitoringEnabled bool - PlcAddress string - AdminPassword string - ReaderPassword string - StemTvPublishingEnabled bool - StemTvEventCode string - ScaleLedAddress string - RedSwitchLedAddress string - BlueSwitchLedAddress string - RedVaultLedAddress string - BlueVaultLedAddress string + Id int + Name string + DisplayBackgroundColor string + NumElimAlliances int + SelectionRound2Order string + SelectionRound3Order string + TBADownloadEnabled bool + TbaPublishingEnabled bool + TbaEventCode string + TbaSecretId string + TbaSecret string + NetworkSecurityEnabled bool + ApAddress string + ApUsername string + ApPassword string + ApTeamChannel int + ApAdminChannel int + ApAdminWpaKey string + SwitchAddress string + SwitchPassword string + PlcAddress string + AdminPassword string + ReaderPassword string + StemTvPublishingEnabled bool + StemTvEventCode string + ScaleLedAddress string + RedSwitchLedAddress string + BlueSwitchLedAddress string + RedVaultLedAddress string + BlueVaultLedAddress string } const eventSettingsId = 0 diff --git a/static/js/fta_display.js b/static/js/fta_display.js index 20ba4c5..c989cb2 100644 --- a/static/js/fta_display.js +++ b/static/js/fta_display.js @@ -19,7 +19,6 @@ var handleArenaStatus = function(data) { if (stationStatus.DsConn) { var dsConn = stationStatus.DsConn; $("#status" + station + " .ds-status").attr("data-status-ok", dsConn.DsLinked); - $("#status" + station + " .ds-status").text(dsConn.MBpsToRobot.toFixed(1) + "/" + dsConn.MBpsFromRobot.toFixed(1)); $("#status" + station + " .radio-status").attr("data-status-ok", dsConn.RadioLinked); $("#status" + station + " .robot-status").attr("data-status-ok", dsConn.RobotLinked); if (stationStatus.DsConn.SecondsSinceLastRobotLink > 1 && stationStatus.DsConn.SecondsSinceLastRobotLink < 1000) { diff --git a/static/js/match_play.js b/static/js/match_play.js index 15842c4..7277dff 100644 --- a/static/js/match_play.js +++ b/static/js/match_play.js @@ -65,7 +65,6 @@ var handleArenaStatus = function(data) { if (stationStatus.DsConn) { var dsConn = stationStatus.DsConn; $("#status" + station + " .ds-status").attr("data-status-ok", dsConn.DsLinked); - $("#status" + station + " .ds-status").text(dsConn.MBpsToRobot.toFixed(1) + "/" + dsConn.MBpsFromRobot.toFixed(1)); $("#status" + station + " .robot-status").attr("data-status-ok", dsConn.RobotLinked); if (stationStatus.DsConn.SecondsSinceLastRobotLink > 1 && stationStatus.DsConn.SecondsSinceLastRobotLink < 1000) { $("#status" + station + " .robot-status").text(stationStatus.DsConn.SecondsSinceLastRobotLink.toFixed()); diff --git a/templates/setup_settings.html b/templates/setup_settings.html index e0fc9eb..54f3700 100644 --- a/templates/setup_settings.html +++ b/templates/setup_settings.html @@ -223,12 +223,6 @@ -