Some Go updates to the code and docstrings
Like replacing interface{} with any and adding docstrings
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Package bngsdk defines an API to interact with the BeamNG outgauge data in
|
||||
// Go
|
||||
package bngsdk
|
||||
|
||||
import (
|
||||
@@ -8,8 +10,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
UDP_IP = "127.0.0.1"
|
||||
UDP_PORT = 4444
|
||||
// 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
|
||||
)
|
||||
|
||||
type BNGSDK struct {
|
||||
@@ -17,7 +21,7 @@ type BNGSDK struct {
|
||||
Conn *net.UDPConn
|
||||
Buffer []byte
|
||||
Data *Outgauge
|
||||
DataDict map[string]interface{}
|
||||
DataDict map[string]any
|
||||
}
|
||||
|
||||
func createUDPConnection(ip string, port int) (*net.UDPConn, *net.UDPAddr, error) {
|
||||
@@ -66,7 +70,7 @@ func (sdk *BNGSDK) ReadData() error {
|
||||
}
|
||||
|
||||
func (sdk *BNGSDK) Close() {
|
||||
sdk.Conn.Close()
|
||||
_ = sdk.Conn.Close()
|
||||
}
|
||||
|
||||
// Init initializes a BeamNG SDK struct
|
||||
|
||||
+6
-3
@@ -1,11 +1,13 @@
|
||||
package bngsdk
|
||||
|
||||
// More documentation at https://go.beamng.com/protocols.
|
||||
|
||||
/* TODO
|
||||
- OG_x Flags
|
||||
- DL_x Flags
|
||||
*/
|
||||
|
||||
// More documentation at https://go.beamng.com/protocols
|
||||
// Outgauge describes the data served by the BeamNG outgauge server
|
||||
type Outgauge struct {
|
||||
Time uint32 // time in milliseconds (to check order)
|
||||
Car [4]byte // Car name
|
||||
@@ -29,8 +31,9 @@ type Outgauge struct {
|
||||
ID int32 // optional - only if OutGauge ID is specified
|
||||
}
|
||||
|
||||
func (o *Outgauge) ToMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
// ToMap creates a map with the data in the Outgauge struct
|
||||
func (o *Outgauge) ToMap() map[string]any {
|
||||
return map[string]any{
|
||||
"Time": o.Time, // time in milliseconds (to check order)
|
||||
"Car": o.Car, // Car name
|
||||
"Flags": o.Flags, // Info (see OG_x below)
|
||||
|
||||
Reference in New Issue
Block a user