Documentation ¶
Index ¶
- Constants
- Variables
- func Listen(conn net.PacketConn, ch chan Packet) error
- type Client
- type DataStore
- type Packet
- func (p *Packet) Brake() Percentage
- func (p *Packet) CarPosition() *Position
- func (p *Packet) Clutch() Percentage
- func (p *Packet) ElapsedStageTime() (t string)
- func (p *Packet) Handbrake() Percentage
- func (p *Packet) InGameTime() (t string)
- func (p *Packet) Kmph() float32
- func (p *Packet) Mph() float32
- func (p *Packet) StageProgress() Percentage
- func (p *Packet) Throttle() Percentage
- func (p *Packet) ToJSON() ([]byte, error)
- type Percentage
- type Position
- type Timespan
Constants ¶
const ( MpsToMph float32 = 2.237 MpsToKmph float32 = 3.6 )
Conversion values
Variables ¶
var ( // ErrNoData is an error that represents a nil data scenario. ErrNoData = errors.New("data is equal to nil") // ErrStoreEmpty is an error that represents an empty datastore scenario. ErrStoreEmpty = errors.New("the datastore is empty") // ErrStoreUpdate gets returned if there was a problem updating the //internal datastore. ErrStoreUpdate = errors.New("there was an error updating the internal store") // ErrUDPData represents an udp error. ErrUDPData = errors.New("there was an error getting udp data") )
Functions ¶
func Listen ¶
func Listen(conn net.PacketConn, ch chan Packet) error
Listen is a function that listens for incoming packets on a given connection. It reads the packets into a buffer, decodes them into a Packet struct, and sends them on a channel.
go Listen(conn,ch) ch: The channel to send the decoded packets on.
Types ¶
type Client ¶
Client is used to manage incoming UDP data.
func (*Client) AverageFrameTime ¶
AverageFrameTime returns your average frame time based on all 'GameDeltaTime' values in the store.
func (*Client) AverageSpeedKmph ¶
AverageSpeedKmph returns your average speed based on all 'VehicleSpeed' values in the store.
func (*Client) AverageSpeedMph ¶
AverageSpeedMph returns your average speed based on all 'VehicleSpeed' values in the store.
type DataStore ¶
type DataStore struct {
// contains filtered or unexported fields
}
DataStore represents a data store for Wrc packets with thread-safe operations.
func NewWrcDataStore ¶
NewWrcDataStore initializes a new WrcDataStore with the provided packets.
type Packet ¶
type Packet struct { // A rolling unique identifier for the current packet. Can be used to order and drop received packets. PacketUID uint64 `json:"packet_uid"` // Time spent in game since boot. GameTotalTime float32 `json:"game_total_time"` // Time spent since last frame. GameDeltaTime float32 `json:"game_delta_time"` // Frame count in game since boot. GameFrameCount uint64 `json:"game_frame_count"` // For shift lights, from 0 ('vehicle_engine_rpm_current'='shiftlights_rpm_start') to 1 ('vehicle_engine_rpm_current'='shiftlights_rpm_end'). ShiftlightsFraction float32 `json:"shiftlights_fraction"` // Shift lights start at 'vehicle_engine_rpm_current' value. ShiftlightsRpmStart float32 `json:"shiftlights_rpm_start"` // Shift lights end (i.e. optimal shift) at 'vehicle_engine_rpm_current' value. ShiftlightsRpmEnd float32 `json:"shiftlights_rpm_end"` // Are shift lights RPM data valid: 'vehicle_engine_rpm_current', 'shiftlights_rpm_start', 'shiftlights_rpm_end' ShiftlightsRpmValid bool `json:"shiftlights_rpm_valid"` // Gear index or value of 'vehicle_gear_index_neutral' or 'vehicle_gear_index_reverse' VehicleGearIndex uint8 `json:"vehicle_gear_index"` // 'vehicle_gear_index' if gearbox in Neutral. VehicleGearIndexNeutral uint8 `json:"vehicle_gear_index_neutral"` // 'vehicle_gear_index' if gearbox in Reverse. VehicleGearIndexReverse uint8 `json:"vehicle_gear_index_reverse"` // Number of forward gears. VehicleGearMaximum uint8 `json:"vehicle_gear_maximum"` // Car body speed. VehicleSpeed float32 `json:"vehicle_speed"` // Car speed at wheel/road due to transmission (for speedo use). NB. May differ from 'vehicle_speed'. VehicleTransmissionSpeed float32 `json:"vehicle_transmission_speed"` // Car position X component, positive left. VehiclePositionX float32 `json:"vehicle_position_x"` // Car position Y component, positive up. VehiclePositionY float32 `json:"vehicle_position_y"` // Car position Z component, positive forward. VehiclePositionZ float32 `json:"vehicle_position_z"` // Car velocity X component, positive left. VehicleVelocityX float32 `json:"vehicle_velocity_x"` // Car velocity Y component, positive up. VehicleVelocityY float32 `json:"vehicle_velocity_y"` // Car velocity Z component, positive forward. VehicleVelocityZ float32 `json:"vehicle_velocity_z"` // Car acceleration X component, positive left. VehicleAccelerationX float32 `json:"vehicle_acceleration_x"` // Car acceleration Y component, positive up. VehicleAccelerationY float32 `json:"vehicle_acceleration_y"` // Car acceleration Z component, positive forward. VehicleAccelerationZ float32 `json:"vehicle_acceleration_z"` // Car left unit vector X component, positive left. VehicleLeftDirectionX float32 `json:"vehicle_left_direction_x"` // Car left unit vector Y component, positive up. VehicleLeftDirectionY float32 `json:"vehicle_left_direction_y"` // Car left unit vector Z component, positive forward. VehicleLeftDirectionZ float32 `json:"vehicle_left_direction_z"` // Car forward unit vector X component, positive left. VehicleForwardDirectionX float32 `json:"vehicle_forward_direction_x"` // Car forward unit vector Y component, positive up. VehicleForwardDirectionY float32 `json:"vehicle_forward_direction_y"` // Car forward unit vector Z component, positive forward. VehicleForwardDirectionZ float32 `json:"vehicle_forward_direction_z"` // Car up unit vector X component, positive left. VehicleUpDirectionX float32 `json:"vehicle_up_direction_x"` // Car up unit vector Y component, positive up. VehicleUpDirectionY float32 `json:"vehicle_up_direction_y"` // Car up unit vector Z component, positive forward. VehicleUpDirectionZ float32 `json:"vehicle_up_direction_z"` // Wheel hub height displacement, back left, positive up. VehicleHubPositionBL float32 `json:"vehicle_hub_position_bl"` // Wheel hub height displacement, back right, positive up. VehicleHubPositionBR float32 `json:"vehicle_hub_position_br"` // Wheel hub height displacement, front left, positive up. VehicleHubPositionFL float32 `json:"vehicle_hub_position_fl"` // Wheel hub height displacement, front right, positive up. VehicleHubPositionFR float32 `json:"vehicle_hub_position_fr"` // Wheel hub vertical velocity, back left, positive up. VehicleHubVelocityBL float32 `json:"vehicle_hub_velocity_bl"` // Wheel hub vertical velocity, back right, positive up. VehicleHubVelocityBR float32 `json:"vehicle_hub_velocity_br"` // Wheel hub vertical velocity, front left, positive up. VehicleHubVelocityFL float32 `json:"vehicle_hub_velocity_fl"` // Wheel hub vertical velocity, front right, positive up. VehicleHubVelocityFR float32 `json:"vehicle_hub_velocity_fr"` // Contact patch forward speed, back left. VehicleCpForwardSpeedBL float32 `json:"vehicle_cp_forward_speed_bl"` // Contact patch forward speed, back right. VehicleCpForwardSpeedBR float32 `json:"vehicle_cp_forward_speed_br"` // Contact patch forward speed, front left. VehicleCpForwardSpeedFL float32 `json:"vehicle_cp_forward_speed_fl"` // Contact patch forward speed, front right. VehicleCpForwardSpeedFR float32 `json:"vehicle_cp_forward_speed_fr"` // Brake temperature, back left. VehicleBrakeTemperatureBL float32 `json:"vehicle_brake_temperature_bl"` // Brake temperature, back right. VehicleBrakeTemperatureBR float32 `json:"vehicle_brake_temperature_br"` // Brake temperature, front left. VehicleBrakeTemperatureFL float32 `json:"vehicle_brake_temperature_fl"` // Brake temperature, front right. VehicleBrakeTemperatureFR float32 `json:"vehicle_brake_temperature_fr"` // Engine rotation rate, maximum. VehicleEngineRpmMax float32 `json:"vehicle_engine_rpm_max"` // Engine rotation rate, at idle. VehicleEngineRpmIdle float32 `json:"vehicle_engine_rpm_idle"` // Engine rotation rate, current. VehicleEngineRpmCurrent float32 `json:"vehicle_engine_rpm_current"` // Throttle pedal after assists and overrides, 0 (off) to 1 (full). VehicleThrottle float32 `json:"vehicle_throttle"` // Brake pedal after assists and overrides, 0 (off) to 1 (full). VehicleBrake float32 `json:"vehicle_brake"` // Clutch pedal after assists and overrides, 0 (off) to 1 (full). VehicleClutch float32 `json:"vehicle_clutch"` // Steering after assists and overrides, -1 (full left) to 1 (full right). VehicleSteering float32 `json:"vehicle_steering"` // Handbrake after assists and overrides, 0 (off) to 1 (full). VehicleHandbrake float32 `json:"vehicle_handbrake"` // Time spent on current stage. StageCurrentTime float32 `json:"stage_current_time"` // Distance reached on current stage. StageCurrentDistance float64 `json:"stage_current_distance"` // Total length of current stage. StageLength float64 `json:"stage_length"` }
Packet represents the default WRC data packet.
func NewPacket ¶
func NewPacket() *Packet
NewPacket creates a new Packet instance with all fields initialized to their zero values.
func (*Packet) Brake ¶
func (p *Packet) Brake() Percentage
Brake returns the current brake value as a percentage.
func (*Packet) CarPosition ¶
CarPosition returns the current position of the car.
func (*Packet) Clutch ¶
func (p *Packet) Clutch() Percentage
Clutch returns the current clutch value as a percentage. (100 = engaged)
func (*Packet) ElapsedStageTime ¶
ElapsedStageTime returns current stagetime as a formatted string. "03:42.583"
func (*Packet) Handbrake ¶
func (p *Packet) Handbrake() Percentage
Handbrake returns the current handbrake value as a percentage.
func (*Packet) InGameTime ¶
InGameTime returns time spent ingame as a formatted string. "03:42.583"
func (*Packet) StageProgress ¶
func (p *Packet) StageProgress() Percentage
StageProgress returns the current stage's progress as a percentage.
func (*Packet) Throttle ¶
func (p *Packet) Throttle() Percentage
Throttle returns the current throttle value as a percentage.