Some miscellanious stuff
This commit is contained in:
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
coverage*
|
coverage*
|
||||||
*.txt
|
*.txt
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
test:
|
test:
|
||||||
go test -coverprofile=coverage.out ./... -cover -bench=
|
go test -coverprofile=coverage.out ./... -cover -bench=
|
||||||
go tool cover -html=coverage.out -o coverage.html
|
go tool cover -html=coverage.out -o coverage.html
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
# About
|
# About
|
||||||
This project will be able to parse `.ibt` files, read live data from races and
|
This project will be able to parse `.ibt` files, read live data from races and
|
||||||
broadcast messages to the service. Its still not very mature at all, but after
|
broadcast messages to the service. Its still not very mature at all, but after
|
||||||
this commit I will turn it into a package instead and give it a stable API.
|
this commit I will turn it into a package instead and give it a stable API.
|
||||||
Will also put some examples then.
|
Will also put some examples then.
|
||||||
|
|
||||||
|
|
||||||
## The SDK
|
## The SDK
|
||||||
I used various sources to develop and understand how `iRacing` works, and learn
|
I used various sources to develop and understand how `iRacing` works, and learn
|
||||||
a lot with it. Once I have matured this project a bit I will document its
|
a lot with it. Once I have matured this project a bit I will document its
|
||||||
inner workings too.
|
inner workings too.
|
||||||
|
|
||||||
|
|
||||||
## SharedMem
|
## SharedMem
|
||||||
I vendored in the code from [hidez8891/shm](https://github.com/hidez8891/shm)
|
I vendored in the code from [hidez8891/shm](https://github.com/hidez8891/shm)
|
||||||
since the repo has been archived. I took the opportunity to update some of its
|
since the repo has been archived. I took the opportunity to update some of its
|
||||||
code.
|
code.
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
package goirsdk
|
package goirsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestParseTelemetrySubHeader_WithGoodBuffer
|
// TestParseTelemetrySubHeader_WithGoodBuffer
|
||||||
// Given a well structured buffer it will output the expected
|
// Given a well structured buffer it will output the expected
|
||||||
// DiskSubHeader struct
|
// DiskSubHeader struct
|
||||||
func TestParseTelemetrySubHeader_WithGoodBuffer(t *testing.T) {
|
func TestParseTelemetrySubHeader_WithGoodBuffer(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
header := [32]byte{
|
header := [32]byte{
|
||||||
0x54, 0x1e, 0x14, 0x67, 0x00, 0x00, 0x00, 0x00, 0x54, 0x09, 0x00, 0xf0,
|
0x54, 0x1e, 0x14, 0x67, 0x00, 0x00, 0x00, 0x00, 0x54, 0x09, 0x00, 0xf0,
|
||||||
0xee, 0x7e, 0x6b, 0x40, 0x53, 0x74, 0x88, 0x44, 0x44, 0x86, 0x8f, 0x40,
|
0xee, 0x7e, 0x6b, 0x40, 0x53, 0x74, 0x88, 0x44, 0x44, 0x86, 0x8f, 0x40,
|
||||||
0x08, 0x00, 0x00, 0x00, 0xe1, 0xb8, 0x00, 0x00,
|
0x08, 0x00, 0x00, 0x00, 0xe1, 0xb8, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedHeader := DiskSubHeader{
|
expectedHeader := DiskSubHeader{
|
||||||
StartDate: 1729371732,
|
StartDate: 1729371732,
|
||||||
StartTime: 219.96666717536084,
|
StartTime: 219.96666717536084,
|
||||||
EndTime: 1008.7833338413715,
|
EndTime: 1008.7833338413715,
|
||||||
LapCount: 8,
|
LapCount: 8,
|
||||||
RecordCount: 47329,
|
RecordCount: 47329,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
headers, err := parseTelemetrySubHeader(header)
|
headers, err := parseTelemetrySubHeader(header)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error parsing buffer: %v", err)
|
t.Fatalf("Error parsing buffer: %v", err)
|
||||||
}
|
}
|
||||||
if !cmp.Equal(&expectedHeader, headers) {
|
if !cmp.Equal(&expectedHeader, headers) {
|
||||||
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
module github.com/ESilva15/goirsdk
|
module github.com/ESilva15/goirsdk
|
||||||
|
|
||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/go-cmp v0.6.0
|
github.com/google/go-cmp v0.6.0
|
||||||
golang.org/x/sys v0.26.0
|
golang.org/x/sys v0.26.0
|
||||||
golang.org/x/text v0.19.0
|
golang.org/x/text v0.19.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
+52
-52
@@ -1,52 +1,52 @@
|
|||||||
package goirsdk
|
package goirsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestParseTelemetryHeader_WithGoodBuffer
|
// TestParseTelemetryHeader_WithGoodBuffer
|
||||||
// Given a well structured buffer it will output the expected
|
// Given a well structured buffer it will output the expected
|
||||||
// TelemetryHeaders struct
|
// TelemetryHeaders struct
|
||||||
func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) {
|
func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
header := [112]byte{
|
header := [112]byte{
|
||||||
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x00, 0x90, 0x99, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x00, 0x90, 0x99, 0x00, 0x00,
|
||||||
0x10, 0x01, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
0x10, 0x01, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x60, 0x2b, 0x00, 0x00, 0x95, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x60, 0x2b, 0x00, 0x00, 0x95, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedHeader := TelemetryHeaders{
|
expectedHeader := TelemetryHeaders{
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Status: 1,
|
Status: 1,
|
||||||
TickRate: 60,
|
TickRate: 60,
|
||||||
SessionInfoUpdate: 0,
|
SessionInfoUpdate: 0,
|
||||||
SessionInfoLength: 16133,
|
SessionInfoLength: 16133,
|
||||||
SessionInfoOffset: 39312,
|
SessionInfoOffset: 39312,
|
||||||
NumVars: 272,
|
NumVars: 272,
|
||||||
VarHeaderOffset: 144,
|
VarHeaderOffset: 144,
|
||||||
NumBuf: 1,
|
NumBuf: 1,
|
||||||
BufLen: 1053,
|
BufLen: 1053,
|
||||||
Padding: [12]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x2b, 0x0, 0x0},
|
Padding: [12]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x2b, 0x0, 0x0},
|
||||||
BufOffset: 55445,
|
BufOffset: 55445,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
headers, err := parseTelemetryHeader(header)
|
headers, err := parseTelemetryHeader(header)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error parsing buffer: %v", err)
|
t.Fatalf("Error parsing buffer: %v", err)
|
||||||
}
|
}
|
||||||
if !cmp.Equal(&expectedHeader, headers) {
|
if !cmp.Equal(&expectedHeader, headers) {
|
||||||
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+53
-53
@@ -1,53 +1,53 @@
|
|||||||
//go:build (linux && cgo) || (darwin && cgo)
|
//go:build (linux && cgo) || (darwin && cgo)
|
||||||
// +build linux,cgo darwin,cgo
|
// +build linux,cgo darwin,cgo
|
||||||
|
|
||||||
package winutils
|
package winutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WAIT_OBJECT_0 = 0
|
WAIT_OBJECT_0 = 0
|
||||||
WAIT_TIMEOUT = 258
|
WAIT_TIMEOUT = 258
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
once sync.Once
|
once sync.Once
|
||||||
ErrUnsupportedOS = errors.New("not found")
|
ErrUnsupportedOS = errors.New("not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
type utils struct {
|
type utils struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// INITIALIZATION
|
// INITIALIZATION
|
||||||
func newUtils() (*utils, error) {
|
func newUtils() (*utils, error) {
|
||||||
return nil, ErrUnsupportedOS
|
return nil, ErrUnsupportedOS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *utils) Close() {
|
func (u *utils) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// openEvent opens a windows.Handle for a given event
|
// openEvent opens a windows.Handle for a given event
|
||||||
func (u *utils) OpenEvent(eventName string) error {
|
func (u *utils) OpenEvent(eventName string) error {
|
||||||
return ErrUnsupportedOS
|
return ErrUnsupportedOS
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
|
// OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
|
||||||
func (u *utils) OpenBroadcastChannel(name string) error {
|
func (u *utils) OpenBroadcastChannel(name string) error {
|
||||||
return ErrUnsupportedOS
|
return ErrUnsupportedOS
|
||||||
}
|
}
|
||||||
|
|
||||||
// INITIALIZATION
|
// INITIALIZATION
|
||||||
|
|
||||||
// openEvent waits for a good response for some given time
|
// openEvent waits for a good response for some given time
|
||||||
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
|
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendBroadcastMessage sends a message trough the broadcast channel
|
// SendBroadcastMessage sends a message trough the broadcast channel
|
||||||
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
|
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
|
||||||
return ErrUnsupportedOS
|
return ErrUnsupportedOS
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user