Some miscellanious stuff

This commit is contained in:
2025-01-06 17:52:12 +00:00
parent 2dc1771bb6
commit bcbffdc7a2
8 changed files with 185 additions and 185 deletions
+2 -2
View File
@@ -1,2 +1,2 @@
coverage*
*.txt
coverage*
*.txt
+3 -3
View File
@@ -1,3 +1,3 @@
test:
go test -coverprofile=coverage.out ./... -cover -bench=
go tool cover -html=coverage.out -o coverage.html
test:
go test -coverprofile=coverage.out ./... -cover -bench=
go tool cover -html=coverage.out -o coverage.html
+17 -17
View File
@@ -1,17 +1,17 @@
# About
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
this commit I will turn it into a package instead and give it a stable API.
Will also put some examples then.
## The SDK
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
inner workings too.
## SharedMem
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
code.
# About
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
this commit I will turn it into a package instead and give it a stable API.
Will also put some examples then.
## The SDK
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
inner workings too.
## SharedMem
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
code.
+38 -38
View File
@@ -1,38 +1,38 @@
package goirsdk
import (
"testing"
"github.com/google/go-cmp/cmp"
)
// TestParseTelemetrySubHeader_WithGoodBuffer
// Given a well structured buffer it will output the expected
// DiskSubHeader struct
func TestParseTelemetrySubHeader_WithGoodBuffer(t *testing.T) {
// Arrange
header := [32]byte{
0x54, 0x1e, 0x14, 0x67, 0x00, 0x00, 0x00, 0x00, 0x54, 0x09, 0x00, 0xf0,
0xee, 0x7e, 0x6b, 0x40, 0x53, 0x74, 0x88, 0x44, 0x44, 0x86, 0x8f, 0x40,
0x08, 0x00, 0x00, 0x00, 0xe1, 0xb8, 0x00, 0x00,
}
expectedHeader := DiskSubHeader{
StartDate: 1729371732,
StartTime: 219.96666717536084,
EndTime: 1008.7833338413715,
LapCount: 8,
RecordCount: 47329,
}
// Act
headers, err := parseTelemetrySubHeader(header)
// Assert
if err != nil {
t.Fatalf("Error parsing buffer: %v", err)
}
if !cmp.Equal(&expectedHeader, headers) {
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
}
}
package goirsdk
import (
"testing"
"github.com/google/go-cmp/cmp"
)
// TestParseTelemetrySubHeader_WithGoodBuffer
// Given a well structured buffer it will output the expected
// DiskSubHeader struct
func TestParseTelemetrySubHeader_WithGoodBuffer(t *testing.T) {
// Arrange
header := [32]byte{
0x54, 0x1e, 0x14, 0x67, 0x00, 0x00, 0x00, 0x00, 0x54, 0x09, 0x00, 0xf0,
0xee, 0x7e, 0x6b, 0x40, 0x53, 0x74, 0x88, 0x44, 0x44, 0x86, 0x8f, 0x40,
0x08, 0x00, 0x00, 0x00, 0xe1, 0xb8, 0x00, 0x00,
}
expectedHeader := DiskSubHeader{
StartDate: 1729371732,
StartTime: 219.96666717536084,
EndTime: 1008.7833338413715,
LapCount: 8,
RecordCount: 47329,
}
// Act
headers, err := parseTelemetrySubHeader(header)
// Assert
if err != nil {
t.Fatalf("Error parsing buffer: %v", err)
}
if !cmp.Equal(&expectedHeader, headers) {
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
}
}
+10 -10
View File
@@ -1,10 +1,10 @@
module github.com/ESilva15/goirsdk
go 1.23.2
require (
github.com/google/go-cmp v0.6.0
golang.org/x/sys v0.26.0
golang.org/x/text v0.19.0
gopkg.in/yaml.v3 v3.0.1
)
module github.com/ESilva15/goirsdk
go 1.23.2
require (
github.com/google/go-cmp v0.6.0
golang.org/x/sys v0.26.0
golang.org/x/text v0.19.0
gopkg.in/yaml.v3 v3.0.1
)
+10 -10
View File
@@ -1,10 +1,10 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
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/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
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/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+52 -52
View File
@@ -1,52 +1,52 @@
package goirsdk
import (
"testing"
"github.com/google/go-cmp/cmp"
)
// TestParseTelemetryHeader_WithGoodBuffer
// Given a well structured buffer it will output the expected
// TelemetryHeaders struct
func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) {
// Arrange
header := [112]byte{
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 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,
0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 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,
}
expectedHeader := TelemetryHeaders{
Version: 2,
Status: 1,
TickRate: 60,
SessionInfoUpdate: 0,
SessionInfoLength: 16133,
SessionInfoOffset: 39312,
NumVars: 272,
VarHeaderOffset: 144,
NumBuf: 1,
BufLen: 1053,
Padding: [12]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x2b, 0x0, 0x0},
BufOffset: 55445,
}
// Act
headers, err := parseTelemetryHeader(header)
// Assert
if err != nil {
t.Fatalf("Error parsing buffer: %v", err)
}
if !cmp.Equal(&expectedHeader, headers) {
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
}
}
package goirsdk
import (
"testing"
"github.com/google/go-cmp/cmp"
)
// TestParseTelemetryHeader_WithGoodBuffer
// Given a well structured buffer it will output the expected
// TelemetryHeaders struct
func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) {
// Arrange
header := [112]byte{
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 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,
0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 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,
}
expectedHeader := TelemetryHeaders{
Version: 2,
Status: 1,
TickRate: 60,
SessionInfoUpdate: 0,
SessionInfoLength: 16133,
SessionInfoOffset: 39312,
NumVars: 272,
VarHeaderOffset: 144,
NumBuf: 1,
BufLen: 1053,
Padding: [12]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x2b, 0x0, 0x0},
BufOffset: 55445,
}
// Act
headers, err := parseTelemetryHeader(header)
// Assert
if err != nil {
t.Fatalf("Error parsing buffer: %v", err)
}
if !cmp.Equal(&expectedHeader, headers) {
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
}
}
+53 -53
View File
@@ -1,53 +1,53 @@
//go:build (linux && cgo) || (darwin && cgo)
// +build linux,cgo darwin,cgo
package winutils
import (
"errors"
"sync"
"time"
)
const (
WAIT_OBJECT_0 = 0
WAIT_TIMEOUT = 258
)
var (
once sync.Once
ErrUnsupportedOS = errors.New("not found")
)
type utils struct {
}
// INITIALIZATION
func newUtils() (*utils, error) {
return nil, ErrUnsupportedOS
}
func (u *utils) Close() {
}
// openEvent opens a windows.Handle for a given event
func (u *utils) OpenEvent(eventName string) error {
return ErrUnsupportedOS
}
// OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
func (u *utils) OpenBroadcastChannel(name string) error {
return ErrUnsupportedOS
}
// INITIALIZATION
// openEvent waits for a good response for some given time
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
return false
}
// SendBroadcastMessage sends a message trough the broadcast channel
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
return ErrUnsupportedOS
}
//go:build (linux && cgo) || (darwin && cgo)
// +build linux,cgo darwin,cgo
package winutils
import (
"errors"
"sync"
"time"
)
const (
WAIT_OBJECT_0 = 0
WAIT_TIMEOUT = 258
)
var (
once sync.Once
ErrUnsupportedOS = errors.New("not found")
)
type utils struct {
}
// INITIALIZATION
func newUtils() (*utils, error) {
return nil, ErrUnsupportedOS
}
func (u *utils) Close() {
}
// openEvent opens a windows.Handle for a given event
func (u *utils) OpenEvent(eventName string) error {
return ErrUnsupportedOS
}
// OpenBroadcastChannel opens up a broadcast channel to send commands to iracing
func (u *utils) OpenBroadcastChannel(name string) error {
return ErrUnsupportedOS
}
// INITIALIZATION
// openEvent waits for a good response for some given time
func (u *utils) CheckValidDataEvent(timeout time.Duration) bool {
return false
}
// SendBroadcastMessage sends a message trough the broadcast channel
func (u *utils) SendBroadcastMessage(id, p1, p2 uintptr) error {
return ErrUnsupportedOS
}