Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Initial public release
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann committed Jul 27, 2020
0 parents commit 03311e7
Show file tree
Hide file tree
Showing 135 changed files with 25,499 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/vendor
/dist
*.exe
telemetry
/packrd
/cmd/cmd-packr.go
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": ["-v"],
"buildFlags": ""
}
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Philipp Trulson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Go F1 Telemetry

A telemetry server for F1 2020 to display it on a second screen. I started it
as a side project to learn about UDP packets and JavaScript, but it turned
out pretty useful and my friends liked it, so I made it public. So don't be
surprised by small bugs or missing features as I am a lousy web developer.

It doesn't make you any faster (unfortunately), but it does provide some
useful information when you take a quick peek on your second screen. Some
example features:
- Colored tyre wear to quickly see it
- Remaining session time in practice and qualifying
- Weather forecast
- ...

![](screenshot_firefox.png)


## Build

To build you need [Go](https://golang.org/) and
[packr2](https://github.com/gobuffalo/packr/tree/master/v2) installed and on
Linux also the following packages for systray support (depends on your distro,
these are for Fedora 32):
- gtk3-devel
- libappindicator-gtk3-devel

To build the project just execute
```sh
$ packr2
$ go build
```

## Run

To actually make it work you need to enable telemetry in your game. To do that,
go to the settings menu, telemetry settings and enable UDP telemetry. You
should stay with the 20 Hz frequency as I haven't tested higher ones.

Double-click the telemetry.exe to start, it will then sit in your lower-right
tray bar. Right-click to open the UI in your web browser.
You can also run this on another PC, just change the IP address and make
sure port 20777 is allowed in your firewall.

## Components & Libraries

Used 3rd party components:
- Flags: https://github.com/lipis/flag-icon-css
- Weather icons: https://github.com/erikflowers/weather-icons
- Moment.js: https://github.com/moment/moment
- Vue.js: https://github.com/vuejs/vue
42 changes: 42 additions & 0 deletions buildutil
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

set -euo pipefail

cd $(dirname "$0")

VERSION="v2.4.0"

get_arch() {
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
armv7*) ARCH="armv7";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
echo "$ARCH"
}

get_os() {
echo $(uname) | tr '[:upper:]' '[:lower:]'
}

fname="buildutil-${VERSION}-$(get_os)-$(get_arch)"
cachedir="${HOME}/.rebuy/cache"
fpath="${cachedir}/${fname}"

encoded=$(echo $fname | sed "s/+/%2B/g")
url="https://rebuy-github-releases.s3-eu-west-1.amazonaws.com/rebuy-go-sdk/${encoded}"

if ! [ -f ${fpath} ]
then
mkdir -p ${cachedir}
curl --fail -sS -o ${fpath} ${url} || exit 1
chmod +x ${fpath}
fi

exec ${fpath} "$@"
243 changes: 243 additions & 0 deletions cmd/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
package cmd

import (
"bytes"
"context"
"encoding/binary"
"fmt"
"math/rand"
"net"
"time"

"github.com/der-eismann/telemetry/pkg/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func (app *App) DummyPacket(ctx context.Context, cmd *cobra.Command, args []string) {

type SessionPacket struct {
Header util.PacketHeader
Session util.PacketSessionData
}

type LapDataPacket struct {
Header util.PacketHeader
LapData util.PacketLapData
}

type ParticipantDataPacket struct {
Header util.PacketHeader
ParticipantsData util.PacketParticipantsData
}

type ClassificationDataPacket struct {
Header util.PacketHeader
FinalClassificationData util.PacketFinalClassificationData
}

header := util.PacketHeader{
PacketFormat: 2020,
GameMajorVersion: 1,
GameMinorVersion: 10,
PacketVersion: 1,
PacketID: 0,
SessionUID: 123536456,
SessionTime: 1.23436,
FrameIdentifier: 1231251325,
PlayerCarIndex: 5,
SecondaryPlayerCarIndex: 6,
}

sessionHeader := header
sessionHeader.PacketID = SESSION

lapdataHeader := header
lapdataHeader.PacketID = LAPDATA

participantsdataHeader := header
participantsdataHeader.PacketID = PARTICIPANTS

// classificationDataHeader := header
// classificationDataHeader.PacketID = CLASSIFICATION

// classification := util.PacketFinalClassificationData{}
// classification.NumCars = 20
// for i := uint8(0); i < 21; i++ {
// classification.ClassificationData[i].Position = i + 1
// classification.ClassificationData[i].NumLaps = 32
// classification.ClassificationData[i].GridPosition = 20 - i
// classification.ClassificationData[i].Points = i
// classification.ClassificationData[i].NumPitStops = uint8(rand.Intn(5))
// classification.ClassificationData[i].ResultStatus = 3
// classification.ClassificationData[i].BestLapTime = rand.Float32() + 1
// classification.ClassificationData[i].TotalRaceTime = rand.Float64() + float64(i)
// classification.ClassificationData[i].PenaltiesTime = (i + 1) * 2
// classification.ClassificationData[i].NumPenalties = i
// classification.ClassificationData[i].NumTyreStints = 3
// classification.ClassificationData[i].TyreStintsActual = [8]uint8{7, 8, 16}
// classification.ClassificationData[i].TyreStintsVisual = [8]uint8{7, 8, 16}
// }

// classificationPacket := ClassificationDataPacket{
// Header: classificationDataHeader,
// FinalClassificationData: classification,
// }

packet := SessionPacket{
Header: sessionHeader,
Session: util.PacketSessionData{
Weather: 1,
TrackTemperature: 34,
AirTemperature: 20,
TotalLaps: 16,
TrackLength: 5234,
SessionType: 1,
TrackID: 4,
Formula: 0,
SessionTimeLeft: 4500,
SessionDuration: 9000,
PitSpeedLimit: 60,
GamePaused: 0,
IsSpectating: 0,
SpectatorCarIndex: 0,
SLIProNativeSupport: 0,
NumMarshalZones: 16,
MarshalZones: [21]util.MarshalZone{},
SafetyCarStatus: 1,
NetworkGame: 1,
NumWeatherForecastSample: 4,
WeatherForecastSamples: [20]util.WeatherForecastSample{
{
Weather: 0,
TimeOffset: 0,
SessionType: 1,
},
{
Weather: 1,
TimeOffset: 5,
SessionType: 2,
},
{
Weather: 2,
TimeOffset: 10,
SessionType: 5,
},
{
Weather: 4,
TimeOffset: 15,
SessionType: 10,
},
},
},
}
participantsData := util.PacketParticipantsData{}
participantsData.NumActiveCars = 21
lapdata := util.PacketLapData{}
for i := uint8(0); i < participantsData.NumActiveCars; i++ {
lapdata.LapData[i].LastLapTime = rand.Float32()
lapdata.LapData[i].CurrentLapTime = rand.Float32()
lapdata.LapData[i].BestLapTime = rand.Float32()
lapdata.LapData[i].LapDistance = rand.Float32()
lapdata.LapData[i].TotalDistance = rand.Float32()
lapdata.LapData[i].SafetyCarDelta = rand.Float32()
lapdata.LapData[i].CarPosition = i + 1
lapdata.LapData[i].CurrentLapNum = uint8(rand.Intn(30))
lapdata.LapData[i].PitStatus = uint8(rand.Intn(2))
lapdata.LapData[i].Sector = uint8(rand.Intn(2))
lapdata.LapData[i].CurrentLapInvalid = uint8(rand.Intn(1))
lapdata.LapData[i].Penalties = uint8(rand.Intn(3) * 3)
lapdata.LapData[i].GridPosition = i + 1
lapdata.LapData[i].DriverStatus = uint8(rand.Intn(4))
lapdata.LapData[i].ResultStatus = uint8(rand.Intn(6))

}

lapdataPacket := LapDataPacket{
Header: lapdataHeader,
LapData: lapdata,
}

for i := uint8(0); i < participantsData.NumActiveCars; i++ {
participantsData.Participants[i].AiControlled = 1
participantsData.Participants[i].DriverID = i + 19
participantsData.Participants[i].TeamID = uint8(rand.Intn(10))
participantsData.Participants[i].RaceNumber = uint8(rand.Intn(100))
participantsData.Participants[i].Nationality = uint8(rand.Intn(60))
participantsData.Participants[i].Name = [48]byte{}
participantsData.Participants[i].YourTelemetry = 1
}

participantsDataPacket := ParticipantDataPacket{
Header: participantsdataHeader,
ParticipantsData: participantsData,
}

buf := new(bytes.Buffer)
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:20777")
if err != nil {
logrus.Error(err)
}
pc, err := net.DialUDP("udp", nil, addr)
if err != nil {
logrus.Error(err)
}

for {
select {
case <-ticker.C:
packet.Session.SessionTimeLeft = packet.Session.SessionTimeLeft - 1
err := binary.Write(buf, binary.LittleEndian, packet)
if err != nil {
fmt.Println("binary.Write failed:", err)
}

n, err := pc.Write(buf.Bytes()[:bufferSizes[SESSION]])
if err != nil {
logrus.Error(err)
}
buf.Reset()
logrus.Printf("%d bytes sent", n)

err = binary.Write(buf, binary.LittleEndian, lapdataPacket)
if err != nil {
fmt.Println("binary.Write failed:", err)
}

n, err = pc.Write(buf.Bytes()[:bufferSizes[LAPDATA]])
if err != nil {
logrus.Error(err)
}
buf.Reset()
logrus.Printf("%d bytes sent", n)

err = binary.Write(buf, binary.LittleEndian, participantsDataPacket)
if err != nil {
fmt.Println("binary.Write failed:", err)
}

n, err = pc.Write(buf.Bytes()[:bufferSizes[PARTICIPANTS]])
if err != nil {
logrus.Error(err)
}
buf.Reset()
logrus.Printf("%d bytes sent", n)

// err = binary.Write(buf, binary.LittleEndian, classificationPacket)
// if err != nil {
// fmt.Println("binary.Write failed:", err)
// }

// n, err = pc.Write(buf.Bytes()[:bufferSizes[CLASSIFICATION]])
// if err != nil {
// logrus.Error(err)
// }
// buf.Reset()
// logrus.Printf("%d bytes sent", n)
}
}

}
Loading

0 comments on commit 03311e7

Please sign in to comment.