Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88f50218a4 | ||
|
|
4251348c15 |
@@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// UDPIP is the IP of the UDP outgauge server
|
||||
UDPIP = "127.0.0.1"
|
||||
// UDPPort is the port of the UDP outgauge server
|
||||
UDPPort = 4444
|
||||
// DefaultUDPIP is the IP of the UDP outgauge server
|
||||
DefaultUDPIP = "127.0.0.1"
|
||||
// DefaultUDPPort is the port of the UDP outgauge server
|
||||
DefaultUDPPort = 4444
|
||||
)
|
||||
|
||||
type BeamNGSDK struct {
|
||||
@@ -56,6 +56,8 @@ func (sdk *BeamNGSDK) ReadData() error {
|
||||
}
|
||||
|
||||
// Read the binary data into the struct
|
||||
// NOTE: create a reader for this struct and then reset it with the data from here
|
||||
// instead of creating this one everytime
|
||||
reader := bytes.NewReader(sdk.Buffer[:n])
|
||||
if err := binary.Read(reader, binary.LittleEndian, sdk.Data); err != nil {
|
||||
fmt.Println("Error decoding UDP packet:", err)
|
||||
@@ -63,6 +65,8 @@ func (sdk *BeamNGSDK) ReadData() error {
|
||||
}
|
||||
|
||||
// Update the local map
|
||||
// NOTE: maybe stop doing this here and make the user request this when he
|
||||
// explicitly wants it
|
||||
sdk.DataDict = sdk.Data.ToMap()
|
||||
|
||||
// this means there's new data
|
||||
@@ -74,6 +78,7 @@ func (sdk *BeamNGSDK) Close() error {
|
||||
}
|
||||
|
||||
// Init initializes a BeamNG SDK struct
|
||||
// NOTE: Change this to output a *BeamNGSDK
|
||||
func Init(ip string, port int) (BeamNGSDK, error) {
|
||||
var err error
|
||||
sdk := BeamNGSDK{}
|
||||
@@ -91,3 +96,169 @@ func Init(ip string, port int) (BeamNGSDK, error) {
|
||||
|
||||
return sdk, nil
|
||||
}
|
||||
|
||||
// SDK utilities
|
||||
|
||||
// ShowLights - functions to check if a given dash light is on [START]
|
||||
|
||||
// ShiftLight returns:
|
||||
// true if the shift light is on
|
||||
// false if the shift light is off
|
||||
func (sdk *BeamNGSDK) ShiftLight() bool {
|
||||
return sdk.Data.ShowLights&DL_SHIFT != 0
|
||||
}
|
||||
|
||||
// HighBeam returns:
|
||||
// true if the high beams are on
|
||||
// false if the high beams are off
|
||||
func (sdk *BeamNGSDK) HighBeam() bool {
|
||||
return sdk.Data.ShowLights&DL_FULLBEAM != 0
|
||||
}
|
||||
|
||||
// Handbrake returns:
|
||||
// true if the handbrake is pulled
|
||||
// false if the handbrake is down
|
||||
func (sdk *BeamNGSDK) Handbrake() bool {
|
||||
return sdk.Data.ShowLights&DL_HANDBRAKE != 0
|
||||
}
|
||||
|
||||
// Pitspeed returns:
|
||||
// true if the pit speed limiter is on
|
||||
// false if the pit speed limiter is off
|
||||
// NOTE: this may not be used in BeamNG.drive, haven't checked yet
|
||||
func (sdk *BeamNGSDK) Pitspeed() bool {
|
||||
return sdk.Data.ShowLights&DL_HANDBRAKE != 0
|
||||
}
|
||||
|
||||
// TractionControl returns:
|
||||
// true if traction control is on
|
||||
// false if traction control is off
|
||||
func (sdk *BeamNGSDK) TractionControl() bool {
|
||||
return sdk.Data.ShowLights&DL_TC != 0
|
||||
}
|
||||
|
||||
// LeftIndicator returns:
|
||||
// true if the left indicator is on
|
||||
// false if the left indicator is off
|
||||
func (sdk *BeamNGSDK) LeftIndicator() bool {
|
||||
return sdk.Data.ShowLights&DL_SIGNAL_L != 0
|
||||
}
|
||||
|
||||
// RightIndicator returns:
|
||||
// true if the right indicator is on
|
||||
// false if the right indicator is off
|
||||
func (sdk *BeamNGSDK) RightIndicator() bool {
|
||||
return sdk.Data.ShowLights&DL_SIGNAL_R != 0
|
||||
}
|
||||
|
||||
// AnyIndicator returns:
|
||||
// true if the any indicator is on
|
||||
// false if the all indicators are off
|
||||
func (sdk *BeamNGSDK) AnyIndicator() bool {
|
||||
return sdk.Data.ShowLights&DL_SIGNAL_ANY != 0
|
||||
}
|
||||
|
||||
// OilLight returns
|
||||
// true if the oil light is on
|
||||
// false if the oil light is off
|
||||
func (sdk *BeamNGSDK) OilLight() bool {
|
||||
return sdk.Data.ShowLights&DL_OILWARN != 0
|
||||
}
|
||||
|
||||
// BatteryLight returns
|
||||
// true if the battery light is on
|
||||
// false if the battery light is off
|
||||
func (sdk *BeamNGSDK) BatteryLight() bool {
|
||||
return sdk.Data.ShowLights&DL_BATTERY != 0
|
||||
}
|
||||
|
||||
// ABS returns
|
||||
// true if the ABS is engaged
|
||||
// false if the ABS isn't engaged
|
||||
func (sdk *BeamNGSDK) ABS() bool {
|
||||
return sdk.Data.ShowLights&DL_ABS != 0
|
||||
}
|
||||
|
||||
// ShowLights - functions to check if a given dash light is on [END]
|
||||
|
||||
// DashLights - functions to check if a given dash light is provided [START]
|
||||
|
||||
// HasShiftLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasShiftLight() bool {
|
||||
return sdk.Data.DashLights&DL_SHIFT != 0
|
||||
}
|
||||
|
||||
// HasHighBeamLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasHighBeamLight() bool {
|
||||
return sdk.Data.DashLights&DL_FULLBEAM != 0
|
||||
}
|
||||
|
||||
// HasHandbrakeLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasHandbrakeLight() bool {
|
||||
return sdk.Data.DashLights&DL_HANDBRAKE != 0
|
||||
}
|
||||
|
||||
// HasPitspeed returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
// NOTE: this may not be used in BeamNG.drive, haven't checked yet
|
||||
func (sdk *BeamNGSDK) HasPitspeed() bool {
|
||||
return sdk.Data.DashLights&DL_HANDBRAKE != 0
|
||||
}
|
||||
|
||||
// HasTractionControlLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasTractionControlLight() bool {
|
||||
return sdk.Data.DashLights&DL_TC != 0
|
||||
}
|
||||
|
||||
// HasLeftIndicatorLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasLeftIndicatorLight() bool {
|
||||
return sdk.Data.DashLights&DL_SIGNAL_L != 0
|
||||
}
|
||||
|
||||
// HasRightIndicatorLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasRightIndicatorLight() bool {
|
||||
return sdk.Data.DashLights&DL_SIGNAL_R != 0
|
||||
}
|
||||
|
||||
// HasAnyIndicatorLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasAnyIndicatorLight() bool {
|
||||
return sdk.Data.DashLights&DL_SIGNAL_ANY != 0
|
||||
}
|
||||
|
||||
// HasOilLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasOilLight() bool {
|
||||
return sdk.Data.DashLights&DL_OILWARN != 0
|
||||
}
|
||||
|
||||
// HasBatteryLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasBatteryLight() bool {
|
||||
return sdk.Data.DashLights&DL_BATTERY != 0
|
||||
}
|
||||
|
||||
// HasABSLight returns:
|
||||
// true if its available
|
||||
// false if its unavailable
|
||||
func (sdk *BeamNGSDK) HasABSLight() bool {
|
||||
return sdk.Data.DashLights&DL_ABS != 0
|
||||
}
|
||||
|
||||
// DashLights - functions to check if a given dash light is provided [END]
|
||||
|
||||
+12
-12
@@ -13,18 +13,18 @@ const (
|
||||
|
||||
// DL_x Flags
|
||||
const (
|
||||
DL_SHIFT = 2 ^ 0 // shift light
|
||||
DL_FULLBEAM = 2 ^ 1 // full beam
|
||||
DL_HANDBRAKE = 2 ^ 2 // handbrake
|
||||
DL_PITSPEED = 2 ^ 3 // pit speed limiter // N/A
|
||||
DL_TC = 2 ^ 4 // tc active or switched off
|
||||
DL_SIGNAL_L = 2 ^ 5 // left turn signal
|
||||
DL_SIGNAL_R = 2 ^ 6 // right turn signal
|
||||
DL_SIGNAL_ANY = 2 ^ 7 // shared turn signal // N/A
|
||||
DL_OILWARN = 2 ^ 8 // oil pressure warning
|
||||
DL_BATTERY = 2 ^ 9 // battery warning
|
||||
DL_ABS = 2 ^ 10 // abs active or switched off
|
||||
DL_SPARE = 2 ^ 11 // N/A
|
||||
DL_SHIFT = 1 << 0 // shift light
|
||||
DL_FULLBEAM = 1 << 1 // full beam
|
||||
DL_HANDBRAKE = 1 << 2 // handbrake
|
||||
DL_PITSPEED = 1 << 3 // pit speed limiter // N/A
|
||||
DL_TC = 1 << 4 // tc active or switched off
|
||||
DL_SIGNAL_L = 1 << 5 // left turn signal
|
||||
DL_SIGNAL_R = 1 << 6 // right turn signal
|
||||
DL_SIGNAL_ANY = 1 << 7 // shared turn signal // N/A
|
||||
DL_OILWARN = 1 << 8 // oil pressure warning
|
||||
DL_BATTERY = 1 << 9 // battery warning
|
||||
DL_ABS = 1 << 10 // abs active or switched off
|
||||
DL_SPARE = 1 << 11 // N/A
|
||||
)
|
||||
|
||||
// Outgauge describes the data served by the BeamNG outgauge server
|
||||
|
||||
Reference in New Issue
Block a user