headers

package
v0.0.0-...-5f50fa1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package headers provides the utilities for parsing and interacting with the ibt header objects.

Index

Constants

View Source
const (
	VAR_BUFFER_HEADER_BASE_OFFSET int = 48
	VAR_BUFFER_INCREMENT          int = 16
)
View Source
const (
	DISK_HEADER_BYTES_SIZE int = 32
)
View Source
const (
	TELEMETRY_HEADER_BYTES_SIZE int = 112
)
View Source
const (
	VAR_HEADER_BYTES_SIZE int = 144
)

Variables

This section is empty.

Functions

func AvailableVars

func AvailableVars(varHeaders map[string]VarHeader) []string

AvailableVars for each tick of telemetry data.

This is useful when determining which variables are available for a specific car.

func ReadVarHeader

func ReadVarHeader(reader Reader, numVars, offset int) (map[string]VarHeader, error)

ReadVarHeader populates the the VarHeader with the necessary metadata.

This function will not populate the value field, but rather provides a template for retrieving values during telemetry processing.

Validation is performed by ensuring all variable names conform the UTF-8.

Types

type CameraInfo

type CameraInfo struct {
	Groups []Groups `yaml:"Groups"`
}

CameraInfo contains all available.

type Cameras

type Cameras struct {
	CameraName string `yaml:"CameraName"`
	CameraNum  int    `yaml:"CameraNum"`
}

Cameras available for the a given camera group.

type DiskHeader

type DiskHeader struct {
	// Unix timestamp indicating the start date and time of the file
	StartDate int64
	// Start time of file relative to the seconds since start of the session
	StartTime float64
	// End time of file relative to the seconds since start of the session
	EndTime float64
	// Number of laps telemetry exists for
	LapCount int
	// Number of telemetry variable records
	RecordCount int
}

DiskHeader is the ibt file header indicating start, end, and amount of records

func ReadDiskHeader

func ReadDiskHeader(reader Reader) (*DiskHeader, error)

ReadDiskHeader attempts to parse the Disk SubHeader from the given Reader (a loaded .ibt file)

This function assumes that the reader is already seeked to the current offset in the buffer. If the call was not preceded by headers.ReadTelemetryHeader(), you can seek to the current offset with:

_, err := reader.Seek(int64(TELEMETRY_HEADER_BYTES_SIZE), 0)

Validation will be performed to ensure that the values are as expected

type DriverInfo

type DriverInfo struct {
	DriverCarEngCylinderCount int       `yaml:"DriverCarEngCylinderCount"`
	DriverCarEstLapTime       float64   `yaml:"DriverCarEstLapTime"`
	DriverCarFuelKgPerLtr     float64   `yaml:"DriverCarFuelKgPerLtr"`
	DriverCarFuelMaxLtr       int       `yaml:"DriverCarFuelMaxLtr"`
	DriverCarGearNeutral      int       `yaml:"DriverCarGearNeutral"`
	DriverCarGearNumForward   int       `yaml:"DriverCarGearNumForward"`
	DriverCarGearReverse      int       `yaml:"DriverCarGearReverse"`
	DriverCarIdleRPM          int       `yaml:"DriverCarIdleRPM"`
	DriverCarIdx              int       `yaml:"DriverCarIdx"`
	DriverCarIsElectric       int       `yaml:"DriverCarIsElectric"`
	DriverCarMaxFuelPct       int       `yaml:"DriverCarMaxFuelPct"`
	DriverCarRedLine          int       `yaml:"DriverCarRedLine"`
	DriverCarSLBlinkRPM       int       `yaml:"DriverCarSLBlinkRPM"`
	DriverCarSLFirstRPM       int       `yaml:"DriverCarSLFirstRPM"`
	DriverCarSLLastRPM        int       `yaml:"DriverCarSLLastRPM"`
	DriverCarSLShiftRPM       int       `yaml:"DriverCarSLShiftRPM"`
	DriverCarVersion          string    `yaml:"DriverCarVersion"`
	DriverHeadPosX            float64   `yaml:"DriverHeadPosX"`
	DriverHeadPosY            float64   `yaml:"DriverHeadPosY"`
	DriverHeadPosZ            float64   `yaml:"DriverHeadPosZ"`
	DriverIncidentCount       int       `yaml:"DriverIncidentCount"`
	DriverPitTrkPct           float64   `yaml:"DriverPitTrkPct"`
	DriverSetupIsModified     int       `yaml:"DriverSetupIsModified"`
	DriverSetupLoadTypeName   string    `yaml:"DriverSetupLoadTypeName"`
	DriverSetupName           string    `yaml:"DriverSetupName"`
	DriverSetupPassedTech     int       `yaml:"DriverSetupPassedTech"`
	DriverUserID              int       `yaml:"DriverUserID"`
	Drivers                   []Drivers `yaml:"Drivers"`
	PaceCarIdx                int       `yaml:"PaceCarIdx"`
}

DriverInfo provides information regarding the driver in the car.

type Drivers

type Drivers struct {
	AbbrevName              interface{} `yaml:"AbbrevName"`
	CarClassColor           int         `yaml:"CarClassColor"`
	CarClassDryTireSetLimit string      `yaml:"CarClassDryTireSetLimit"`
	CarClassEstLapTime      float64     `yaml:"CarClassEstLapTime"`
	CarClassID              int         `yaml:"CarClassID"`
	CarClassLicenseLevel    int         `yaml:"CarClassLicenseLevel"`
	CarClassMaxFuelPct      string      `yaml:"CarClassMaxFuelPct"`
	CarClassPowerAdjust     string      `yaml:"CarClassPowerAdjust"`
	CarClassRelSpeed        int         `yaml:"CarClassRelSpeed"`
	CarClassShortName       interface{} `yaml:"CarClassShortName"`
	CarClassWeightPenalty   string      `yaml:"CarClassWeightPenalty"`
	CarDesignStr            string      `yaml:"CarDesignStr"`
	CarID                   int         `yaml:"CarID"`
	CarIdx                  int         `yaml:"CarIdx"`
	CarIsAI                 int         `yaml:"CarIsAI"`
	CarIsElectric           int         `yaml:"CarIsElectric"`
	CarIsPaceCar            int         `yaml:"CarIsPaceCar"`
	CarNumber               string      `yaml:"CarNumber"`
	CarNumberDesignStr      string      `yaml:"CarNumberDesignStr"`
	CarNumberRaw            int         `yaml:"CarNumberRaw"`
	CarPath                 string      `yaml:"CarPath"`
	CarScreenName           string      `yaml:"CarScreenName"`
	CarScreenNameShort      string      `yaml:"CarScreenNameShort"`
	CarSponsor1             int         `yaml:"CarSponsor_1"`
	CarSponsor2             int         `yaml:"CarSponsor_2"`
	CurDriverIncidentCount  int         `yaml:"CurDriverIncidentCount"`
	HelmetDesignStr         string      `yaml:"HelmetDesignStr"`
	IRating                 int         `yaml:"IRating"`
	Initials                interface{} `yaml:"Initials"`
	IsSpectator             int         `yaml:"IsSpectator"`
	LicColor                string      `yaml:"LicColor"`
	LicLevel                int         `yaml:"LicLevel"`
	LicString               string      `yaml:"LicString"`
	LicSubLevel             int         `yaml:"LicSubLevel"`
	SuitDesignStr           string      `yaml:"SuitDesignStr"`
	TeamID                  int         `yaml:"TeamID"`
	TeamIncidentCount       int         `yaml:"TeamIncidentCount"`
	TeamName                string      `yaml:"TeamName"`
	UserID                  int         `yaml:"UserID"`
	UserName                string      `yaml:"UserName"`
}

Drivers provides information on a driver present in the session.

type Frequencies

type Frequencies struct {
	CanScan       int    `yaml:"CanScan"`
	CanSquawk     int    `yaml:"CanSquawk"`
	CarIdx        int    `yaml:"CarIdx"`
	ClubID        int    `yaml:"ClubID"`
	EntryIdx      int    `yaml:"EntryIdx"`
	FrequencyName string `yaml:"FrequencyName"`
	FrequencyNum  int    `yaml:"FrequencyNum"`
	IsDeletable   int    `yaml:"IsDeletable"`
	IsMutable     int    `yaml:"IsMutable"`
	Muted         int    `yaml:"Muted"`
	Priority      int    `yaml:"Priority"`
}

Frequencies provide information of of the given radio channel.

type Groups

type Groups struct {
	Cameras   []Cameras `yaml:"Cameras"`
	GroupName string    `yaml:"GroupName"`
	GroupNum  int       `yaml:"GroupNum"`
	IsScenic  bool      `yaml:"IsScenic,omitempty"`
}

Groups of cameras available for spectating.

For example: TV1 and it's related cameras.

type Header struct {
	TelemetryHeader *TelemetryHeader
	DiskHeader      *DiskHeader
	VarHeader       map[string]VarHeader
	SessionInfo     *Session
	VarBuffers      []VarBuffer
}

Header contains all sub-headers present in the ibt file.

func ParseHeaders

func ParseHeaders(r Reader) (*Header, error)

ParseHeader parses each of the required sub-headers of the ibt file in sequence.

func (*Header) UpdateVarBuffer

func (h *Header) UpdateVarBuffer(r Reader) error

type RadioInfo

type RadioInfo struct {
	Radios           []Radios `yaml:"Radios"`
	SelectedRadioNum int      `yaml:"SelectedRadioNum"`
}

RadioInfo contains all available radios and the currently selected radio.

type Radios

type Radios struct {
	Frequencies         []Frequencies `yaml:"Frequencies"`
	HopCount            int           `yaml:"HopCount"`
	NumFrequencies      int           `yaml:"NumFrequencies"`
	RadioNum            int           `yaml:"RadioNum"`
	ScanningIsOn        int           `yaml:"ScanningIsOn"`
	TunedToFrequencyNum int           `yaml:"TunedToFrequencyNum"`
}

Radios is a single available radio channel and its related frequencies.

type Reader

type Reader interface {
	io.Reader
	io.ReaderAt
	io.Closer
}

Reader provides all IO functions necessary for parsing ibt files.

type ResultsFastestLap

type ResultsFastestLap struct {
	CarIdx      int `yaml:"CarIdx"`
	FastestLap  int `yaml:"FastestLap"`
	FastestTime int `yaml:"FastestTime"`
}

ResultsFastestLap provides information regarding the session's fastest lap.

type Sectors

type Sectors struct {
	SectorNum      int     `yaml:"SectorNum"`
	SectorStartPct float64 `yaml:"SectorStartPct"`
}

Sectors provide details for a single track sector.

type Session

type Session struct {
	CameraInfo    CameraInfo             `yaml:"CameraInfo"`
	CarSetup      map[string]interface{} `yaml:"CarSetup"`
	DriverInfo    DriverInfo             `yaml:"DriverInfo"`
	RadioInfo     RadioInfo              `yaml:"RadioInfo"`
	SessionInfo   SessionInfo            `yaml:"SessionInfo"`
	SplitTimeInfo SplitTimeInfo          `yaml:"SplitTimeInfo"`
	WeekendInfo   WeekendInfo            `yaml:"WeekendInfo"`
}

Session in which the ibt file occurred. This represents an actual iRacing session and not just information for a single ibt file.

func ReadSessionInfo

func ReadSessionInfo(reader Reader, offset, size int) (*Session, error)

ReadSessionInfo extracts and parses the SessionInfo YAML from the given ibt file.

Additional cleaning (mostly trimming some trailing bytes and spaces) is needed to ensure the YAML is correctly parsed.

func (*Session) GetDriver

func (s *Session) GetDriver() *Drivers

GetDriver attempts to find the current driver's information from the SessionInfo object.

If the driver is not found (possibly spectating), it will return nil.

type SessionInfo

type SessionInfo struct {
	Sessions []Sessions `yaml:"Sessions"`
}

SessionInfo is simply a collection of sub-sessions.

type Sessions

type Sessions struct {
	ResultsAverageLapTime            int                 `yaml:"ResultsAverageLapTime"`
	ResultsFastestLap                []ResultsFastestLap `yaml:"ResultsFastestLap"`
	ResultsLapsComplete              int                 `yaml:"ResultsLapsComplete"`
	ResultsNumCautionFlags           int                 `yaml:"ResultsNumCautionFlags"`
	ResultsNumCautionLaps            int                 `yaml:"ResultsNumCautionLaps"`
	ResultsNumLeadChanges            int                 `yaml:"ResultsNumLeadChanges"`
	ResultsOfficial                  int                 `yaml:"ResultsOfficial"`
	ResultsPositions                 interface{}         `yaml:"ResultsPositions"`
	SessionEnforceTireCompoundChange int                 `yaml:"SessionEnforceTireCompoundChange"`
	SessionLaps                      string              `yaml:"SessionLaps"`
	SessionName                      string              `yaml:"SessionName"`
	SessionNum                       int                 `yaml:"SessionNum"`
	SessionNumLapsToAvg              int                 `yaml:"SessionNumLapsToAvg"`
	SessionRunGroupsUsed             int                 `yaml:"SessionRunGroupsUsed"`
	SessionSkipped                   int                 `yaml:"SessionSkipped"`
	SessionSubType                   interface{}         `yaml:"SessionSubType"`
	SessionTime                      string              `yaml:"SessionTime"`
	SessionTrackRubberState          string              `yaml:"SessionTrackRubberState"`
	SessionType                      string              `yaml:"SessionType"`
}

Sessions provides information for a sub-session, such as Practice or Qualifying or Race.

type SplitTimeInfo

type SplitTimeInfo struct {
	Sectors []Sectors `yaml:"Sectors"`
}

SplitTimeInfo contains all track sector information.

type TelemetryHeader

type TelemetryHeader struct {
	// Version of ibt file
	Version int
	// Status indicates whether session is live (0) or completed (1)
	Status int
	// Tickrate indicates the frequency of telemetry data written to the file.
	// A value of 60 indicates 60 times per second
	TickRate int
	// Indicates the number of times SessionInfo was updated for the current file.
	// The value will be 0 for completed sessions and >1 for active sessions
	SessionInfoUpdate int
	// Buffer offset for SessionInfo data
	SessionInfoOffset int
	// Length of the SessionInfo buffer
	SessionInfoLength int
	// Number of available telemetry vars that will be written at the Tickrate frequency
	NumVars int
	// Buffer offset for VarHeader
	VarHeaderOffset int
	// Specifies the number of telemetry data buffers available.
	// This will be 1 for ibt files and 3 for memory-mapped live telemetry
	NumBuf int
	// Length of the buffer for parsing VarHeader telemetry values
	BufLen int
	// Buffer offset for the VarHeader telemetry values
	BufOffset int
}

func ReadTelemetryHeader

func ReadTelemetryHeader(reader Reader) (*TelemetryHeader, error)

ReadTelemetryHeader attempts to parse the TelemetryHeader from the given Reader (a loaded .ibt file)

Validation will be performed to ensure that the values are as expected

type TelemetryOptions

type TelemetryOptions struct {
	TelemetryDiskFile string `yaml:"TelemetryDiskFile"`
}

type VarBuffer

type VarBuffer struct {
	TickCount int
	BufOffset int
}

VarBuffer is a header providing information on each of the available live data buffers

func ReadVarBufferHeaders

func ReadVarBufferHeaders(r Reader, numBuf int) ([]VarBuffer, error)

ParseVarBufferHeader retrieves the metadata of available live data buffers.

type VarHeader

type VarHeader struct {
	// Rtype is the variable value type.
	//
	// Possible values:
	// 0: Uint8
	// 1: Boolean
	// 2: Int
	// 3: String
	// 4: Float32
	// 5: Float64
	Rtype int `json:"rtype,omitempty"`
	// Offset in the buffer where the value can be found
	Offset int `json:"offset,omitempty"`
	// Number of items the value consists of. >1 means it is an array.
	Count int `json:"count,omitempty"`
	// Indicates if the value is time based
	CountAsTime bool `json:"count_as_time,omitempty"`
	// Description of the variable
	Description string `json:"description,omitempty"`
	Name        string `json:"name,omitempty"`
	// Unit of measurement for the variable value
	Unit string `json:"unit,omitempty"`

	// Value of the variable. The is parsed during iteration of telemetry data.
	Value interface{} `json:"value"`
}

VarHeader provides the available telemetry variable information and values.

type WeekendInfo

type WeekendInfo struct {
	BuildTarget            string           `yaml:"BuildTarget"`
	BuildType              string           `yaml:"BuildType"`
	BuildVersion           string           `yaml:"BuildVersion"`
	Category               string           `yaml:"Category"`
	DCRuleSet              string           `yaml:"DCRuleSet"`
	EventType              string           `yaml:"EventType"`
	HeatRacing             int              `yaml:"HeatRacing"`
	LeagueID               int              `yaml:"LeagueID"`
	MaxDrivers             int              `yaml:"MaxDrivers"`
	MinDrivers             int              `yaml:"MinDrivers"`
	NumCarClasses          int              `yaml:"NumCarClasses"`
	NumCarTypes            int              `yaml:"NumCarTypes"`
	Official               int              `yaml:"Official"`
	QualifierMustStartRace int              `yaml:"QualifierMustStartRace"`
	RaceWeek               int              `yaml:"RaceWeek"`
	SeasonID               int              `yaml:"SeasonID"`
	SeriesID               int              `yaml:"SeriesID"`
	SessionID              int              `yaml:"SessionID"`
	SimMode                string           `yaml:"SimMode"`
	SubSessionID           int              `yaml:"SubSessionID"`
	TeamRacing             int              `yaml:"TeamRacing"`
	TelemetryOptions       TelemetryOptions `yaml:"TelemetryOptions"`
	TrackAirPressure       string           `yaml:"TrackAirPressure"`
	TrackAirTemp           string           `yaml:"TrackAirTemp"`
	TrackAltitude          string           `yaml:"TrackAltitude"`
	TrackCity              string           `yaml:"TrackCity"`
	TrackCleanup           int              `yaml:"TrackCleanup"`
	TrackConfigName        string           `yaml:"TrackConfigName"`
	TrackCountry           string           `yaml:"TrackCountry"`
	TrackDirection         string           `yaml:"TrackDirection"`
	TrackDisplayName       string           `yaml:"TrackDisplayName"`
	TrackDisplayShortName  string           `yaml:"TrackDisplayShortName"`
	TrackDynamicTrack      int              `yaml:"TrackDynamicTrack"`
	TrackFogLevel          string           `yaml:"TrackFogLevel"`
	TrackID                int              `yaml:"TrackID"`
	TrackLatitude          string           `yaml:"TrackLatitude"`
	TrackLength            string           `yaml:"TrackLength"`
	TrackLengthOfficial    string           `yaml:"TrackLengthOfficial"`
	TrackLongitude         string           `yaml:"TrackLongitude"`
	TrackName              string           `yaml:"TrackName"`
	TrackNorthOffset       string           `yaml:"TrackNorthOffset"`
	TrackNumTurns          int              `yaml:"TrackNumTurns"`
	TrackPitSpeedLimit     string           `yaml:"TrackPitSpeedLimit"`
	TrackRelativeHumidity  string           `yaml:"TrackRelativeHumidity"`
	TrackSkies             string           `yaml:"TrackSkies"`
	TrackSurfaceTemp       string           `yaml:"TrackSurfaceTemp"`
	TrackType              string           `yaml:"TrackType"`
	TrackVersion           string           `yaml:"TrackVersion"`
	TrackWeatherType       string           `yaml:"TrackWeatherType"`
	TrackWindDir           string           `yaml:"TrackWindDir"`
	TrackWindVel           string           `yaml:"TrackWindVel"`
	WeekendOptions         WeekendOptions   `yaml:"WeekendOptions"`
}

WeekendInfo contains all session metadata.

type WeekendOptions

type WeekendOptions struct {
	CommercialMode             string `yaml:"CommercialMode"`
	CourseCautions             string `yaml:"CourseCautions"`
	Date                       string `yaml:"Date"`
	EarthRotationSpeedupFactor int    `yaml:"EarthRotationSpeedupFactor"`
	FastRepairsLimit           string `yaml:"FastRepairsLimit"`
	FogLevel                   string `yaml:"FogLevel"`
	GreenWhiteCheckeredLimit   int    `yaml:"GreenWhiteCheckeredLimit"`
	HardcoreLevel              int    `yaml:"HardcoreLevel"`
	HasOpenRegistration        int    `yaml:"HasOpenRegistration"`
	IncidentLimit              string `yaml:"IncidentLimit"`
	IsFixedSetup               int    `yaml:"IsFixedSetup"`
	NightMode                  string `yaml:"NightMode"`
	NumJokerLaps               int    `yaml:"NumJokerLaps"`
	NumStarters                int    `yaml:"NumStarters"`
	QualifyScoring             string `yaml:"QualifyScoring"`
	RelativeHumidity           string `yaml:"RelativeHumidity"`
	Restarts                   string `yaml:"Restarts"`
	ShortParadeLap             int    `yaml:"ShortParadeLap"`
	Skies                      string `yaml:"Skies"`
	StandingStart              int    `yaml:"StandingStart"`
	StartingGrid               string `yaml:"StartingGrid"`
	StrictLapsChecking         string `yaml:"StrictLapsChecking"`
	TimeOfDay                  string `yaml:"TimeOfDay"`
	Unofficial                 int    `yaml:"Unofficial"`
	WeatherTemp                string `yaml:"WeatherTemp"`
	WeatherType                string `yaml:"WeatherType"`
	WindDirection              string `yaml:"WindDirection"`
	WindSpeed                  string `yaml:"WindSpeed"`
}

WeekendOptions contains session rules, physics, environment, and weather information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL