Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3418e0c95 | ||
|
|
45a0aa43aa | ||
|
|
38e7ea32cc | ||
|
|
bcbffdc7a2 | ||
|
|
2dc1771bb6 |
+2
-2
@@ -1,2 +1,2 @@
|
||||
coverage*
|
||||
*.txt
|
||||
coverage*
|
||||
*.txt
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,25 @@
|
||||
package goirsdk
|
||||
|
||||
import (
|
||||
"github.com/ESilva15/goirsdk/logger"
|
||||
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
// "os"
|
||||
|
||||
"io"
|
||||
// "log"
|
||||
// "time"
|
||||
|
||||
// conv "ibtReader/conversions"
|
||||
"github.com/ESilva15/goirsdk/winutils"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const (
|
||||
ibtFile = "./telemetryFiles/mx5_2016Okayama_full_2024_10_19_22_02_12.ibt"
|
||||
)
|
||||
|
||||
func msToKph(v float32) int {
|
||||
return int((3600 * v) / 1000)
|
||||
}
|
||||
|
||||
// Reader is an interface to represent the readable data that can be either
|
||||
// a .ibt file (or live data, hopefully)
|
||||
type Reader interface {
|
||||
@@ -29,7 +32,8 @@ type Reader interface {
|
||||
// IBT struct will hold the relevant data for a given IBT file
|
||||
type IBT struct {
|
||||
File Reader // Source of the data
|
||||
FileToExport string // If set, it will export the IBT data to the file
|
||||
FileToExport *os.File // If set, it will export the IBT data to the file
|
||||
YAMLExport *os.File // If set, it will export the session YAML to the file
|
||||
Headers *TelemetryHeaders // IBT file Headers
|
||||
SubHeaders *DiskSubHeader // IBT file Sub Headers
|
||||
SessionInfo *SessionInfoYAML // IBT file Session Info
|
||||
@@ -50,28 +54,43 @@ func (i *IBT) IsConnected() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (i *IBT) ExportToIBT(filepath string) {
|
||||
rbuf := make([]byte, fileMapSize)
|
||||
|
||||
_, err := i.File.ReadAt(rbuf, 0)
|
||||
func (i *IBT) exportYAML(path string) error {
|
||||
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return fmt.Errorf("failed to open output file for YAML: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
enc := yaml.NewEncoder(file)
|
||||
|
||||
err = enc.Encode(i.SessionInfo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to write YAML contents to file: %v", err)
|
||||
}
|
||||
|
||||
err = os.WriteFile(filepath, rbuf, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Init serves to initialize and get a hold of a IBT struct
|
||||
func Init(f Reader) (*IBT, error) {
|
||||
func Init(f Reader, exportTelem string, exportYAML string) (*IBT, error) {
|
||||
log := logger.GetInstance()
|
||||
|
||||
// Read the header of the file
|
||||
var err error
|
||||
ibt := IBT{
|
||||
File: f,
|
||||
Vars: &TelemetryVars{},
|
||||
winUtils: nil,
|
||||
File: f,
|
||||
FileToExport: nil,
|
||||
YAMLExport: nil,
|
||||
Vars: &TelemetryVars{},
|
||||
winUtils: nil,
|
||||
}
|
||||
|
||||
// If requested to output to a telemetry file
|
||||
if exportTelem != "" {
|
||||
ibt.FileToExport, err = os.OpenFile(exportTelem, os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open ibt export file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if ibt.File == nil {
|
||||
@@ -112,10 +131,15 @@ func Init(f Reader) (*IBT, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to read headers from file: %v", err)
|
||||
}
|
||||
// Write to the output file
|
||||
_, err = ibt.FileToExport.WriteAt(headerRaw[:], 0)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Read the disk sub headers
|
||||
var subheaderRaw [SubHeaderSize]byte
|
||||
_, err = ibt.File.ReadAt(subheaderRaw[:], 112)
|
||||
_, err = ibt.File.ReadAt(subheaderRaw[:], HeaderSize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to read disk subheaders from file: %v", err)
|
||||
}
|
||||
@@ -123,6 +147,11 @@ func Init(f Reader) (*IBT, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse disk subheaders from file: %v", err)
|
||||
}
|
||||
// Write to the output file
|
||||
_, err = ibt.FileToExport.WriteAt(subheaderRaw[:], HeaderSize)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Read session info string
|
||||
sessionInfoStringRaw := make([]byte, ibt.Headers.SessionInfoLength)
|
||||
@@ -130,10 +159,23 @@ func Init(f Reader) (*IBT, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to read sessionInfoString from file: %v", err)
|
||||
}
|
||||
// Write to the output file
|
||||
_, err = ibt.FileToExport.WriteAt(sessionInfoStringRaw[:], int64(ibt.Headers.SessionInfoOffset))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ibt.SessionInfo, err = parseSessionInfo(sessionInfoStringRaw, ibt.Headers.SessionInfoLength)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse SessionInfoString from file: %v", err)
|
||||
}
|
||||
// Write to YAML output file
|
||||
if exportYAML != "" {
|
||||
err := ibt.exportYAML(exportYAML)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Read the telemetry vars info
|
||||
err = ibt.readVariablerHeaders()
|
||||
@@ -151,69 +193,3 @@ func (i *IBT) Close() {
|
||||
i.winUtils.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// func main() {
|
||||
// fmt.Println("================== IBT FILE PARSER ==================")
|
||||
//
|
||||
// file, err := os.Open(ibtFile)
|
||||
// if err != nil {
|
||||
// log.Fatalf("Failed to open IBT file: %v", err)
|
||||
// }
|
||||
//
|
||||
// ibt, err := Init(file)
|
||||
// if err != nil {
|
||||
// log.Fatalf("Failed to create irsdk instance: %v", err)
|
||||
// }
|
||||
// // fmt.Printf("%s\n", ibt.Headers.ToString())
|
||||
// // fmt.Printf("%s\n", ibt.SubHeaders.ToString())
|
||||
// // fmt.Printf("%s\n", ibt.SessionInfo.ToString())
|
||||
//
|
||||
// // Display the human readable start date
|
||||
// // unixStartDate := time.Unix(ibt.SubHeaders.StartDate, 0)
|
||||
// // startDate := unixStartDate.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// // fmt.Println("StartDate:", startDate)
|
||||
//
|
||||
// // Display the human readable version of start time
|
||||
// // unixStartTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.StartTime), 0)
|
||||
// // startTime := unixStartTime.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// // fmt.Println("StartTime:", startTime)
|
||||
//
|
||||
// // Display the human readable version of end time
|
||||
// // unixEndTime := time.Unix(ibt.SubHeaders.StartDate+int64(ibt.SubHeaders.EndTime), 0)
|
||||
// // endTime := unixEndTime.Format("2006/01/02 15:04:05 -0700 MST")
|
||||
// // fmt.Println("EndTime: ", endTime)
|
||||
//
|
||||
// last := time.Now().UnixMilli()
|
||||
// for {
|
||||
// time.Sleep(time.Second / 60)
|
||||
// res, err := ibt.Update(100 * time.Millisecond)
|
||||
// if res == Unknown {
|
||||
// log.Fatalf("Some unknown error occurred: %v\n", err)
|
||||
// }
|
||||
//
|
||||
// if res == Paused {
|
||||
// fmt.Printf("\r \r")
|
||||
// fmt.Println("GAME IS PAUSED")
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// curTime := time.Now().UnixMilli()
|
||||
//
|
||||
// if curTime-last > 250 {
|
||||
// fmt.Printf(" \r")
|
||||
// if val, ok := ibt.Vars.Vars["Speed"]; ok {
|
||||
// fmt.Printf("\r%d %d", ibt.Vars.Tick/60, conv.MsToKph(val.Value.(float32)))
|
||||
// } else {
|
||||
// fmt.Printf("\r%d %s", ibt.Vars.Tick/60, "KEY DOESN'T EXIST")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if res == Ended {
|
||||
// fmt.Println("\nEnd of file found...")
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// fmt.Printf("%d\n", ibt.Vars.Tick)
|
||||
//
|
||||
// ibt.Close()
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var l *log.Logger
|
||||
var once sync.Once
|
||||
|
||||
func createLogger() {
|
||||
l = log.New(os.Stdout, "[ibtReader] ", log.LstdFlags | log.Lshortfile)
|
||||
}
|
||||
|
||||
func GetInstance() *log.Logger {
|
||||
once.Do(func() {
|
||||
createLogger()
|
||||
})
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
+24
-9
@@ -91,8 +91,9 @@ type varBuffer struct {
|
||||
}
|
||||
|
||||
type TelemetryVars struct {
|
||||
Tick int32
|
||||
Vars map[string]Var
|
||||
Tick int32 // Keeps track of the current data buffer tick
|
||||
RecorderTick int32 // Counts from 0 when creating a telemetry file from a replay or live data
|
||||
Vars map[string]Var // Variables content
|
||||
}
|
||||
|
||||
func (i *IBT) readVariablerHeaders() error {
|
||||
@@ -107,6 +108,11 @@ func (i *IBT) readVariablerHeaders() error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = i.FileToExport.WriteAt(rbuf, int64(i.Headers.VarHeaderOffset+k*VarHeaderSize))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var dst IBTVar
|
||||
err = binary.Read(bytes.NewBuffer(rbuf[:]), binary.LittleEndian, &dst)
|
||||
if err != nil {
|
||||
@@ -197,6 +203,11 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
return Failed, err
|
||||
}
|
||||
|
||||
_, err = i.FileToExport.WriteAt(buf, int64(i.Headers.BufOffset+i.Vars.RecorderTick*i.Headers.BufLen))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to write to file [2]: %v", err)
|
||||
}
|
||||
|
||||
err = i.readData(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
return Unknown, err
|
||||
@@ -205,11 +216,21 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
if err == io.EOF {
|
||||
return Ended, nil
|
||||
}
|
||||
|
||||
i.Vars.RecorderTick++
|
||||
} else {
|
||||
// This will get the dataframe corresponding to a give tick
|
||||
// This will get the dataframe corresponding to a given tick
|
||||
start := i.Headers.BufOffset + i.Vars.Tick*i.Headers.BufLen
|
||||
buf := make([]byte, i.Headers.BufLen)
|
||||
_, err := i.File.ReadAt(buf, int64(start))
|
||||
|
||||
// Make this happen in a different thread, or have this send to a queue that has a thread
|
||||
// writing to a file
|
||||
_, err = i.FileToExport.WriteAt(buf, int64(start))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to write to file [1]: %v\n", err)
|
||||
}
|
||||
|
||||
if err == io.EOF {
|
||||
return Ended, nil
|
||||
}
|
||||
@@ -226,11 +247,5 @@ func (i *IBT) Update(timeout time.Duration) (IRacingState, error) {
|
||||
i.Vars.Tick++
|
||||
}
|
||||
|
||||
// Make this happen in a different thread, or have this send to a queue that has a thread
|
||||
// writing to a file
|
||||
if i.FileToExport != "" {
|
||||
i.ExportToIBT(i.FileToExport)
|
||||
}
|
||||
|
||||
return Running, nil
|
||||
}
|
||||
|
||||
+53
-53
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user