SessionInfo parsing and another stuff
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"ibtReader/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,6 +24,8 @@ type DiskSubHeader struct {
|
||||
// or nil if an error occurs. In which case the error return value is more
|
||||
// valuable
|
||||
func parseTelemetrySubHeader(buf [SubHeaderSize]byte) (*DiskSubHeader, error) {
|
||||
utils.HexDump(buf[:])
|
||||
|
||||
dst := DiskSubHeader{}
|
||||
err := binary.Read(bytes.NewBuffer(buf[:]), binary.LittleEndian, &dst)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,5 +4,6 @@ go 1.23.2
|
||||
|
||||
require (
|
||||
golang.org/x/sys v0.26.0
|
||||
golang.org/x/text v0.19.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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=
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"ibtReader/sharedMem"
|
||||
@@ -62,6 +63,7 @@ func Init(f Reader) (*IBT, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to read headers from file: %v", err)
|
||||
}
|
||||
fmt.Println(ibt.Headers.ToString())
|
||||
|
||||
// Read the disk sub headers
|
||||
var subheaderRaw [SubHeaderSize]byte
|
||||
@@ -73,6 +75,7 @@ func Init(f Reader) (*IBT, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse disk subheaders from file: %v", err)
|
||||
}
|
||||
fmt.Println(ibt.SubHeaders.ToString())
|
||||
|
||||
// Read session info string
|
||||
sessionInfoStringRaw := make([]byte, ibt.Headers.SessionInfoLength)
|
||||
@@ -80,7 +83,7 @@ func Init(f Reader) (*IBT, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to read sessionInfoString from file: %v", err)
|
||||
}
|
||||
ibt.SessionInfo, err = parseSessionInfo(sessionInfoStringRaw)
|
||||
ibt.SessionInfo, err = parseSessionInfo(sessionInfoStringRaw, ibt.Headers.SessionInfoLength)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse SessionInfoString from file: %v", err)
|
||||
}
|
||||
@@ -101,17 +104,18 @@ func msToKph(v float32) int {
|
||||
func main() {
|
||||
fmt.Println("================== IBT FILE PARSER ==================")
|
||||
|
||||
// file, err := os.Open(ibtFile)
|
||||
// if err != nil {
|
||||
// log.Fatalf("Failed to open IBT file: %v", err)
|
||||
// }
|
||||
file, err := os.Open(ibtFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open IBT file: %v", err)
|
||||
}
|
||||
|
||||
ibt, err := Init(nil)
|
||||
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)
|
||||
|
||||
+19
-2
@@ -2,7 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -306,9 +309,23 @@ type Driver struct {
|
||||
|
||||
// parseSessionInfo will parse the sessionInfo buffer into the SessionInfoYAML
|
||||
// struct
|
||||
func parseSessionInfo(data []byte) (*SessionInfoYAML, error) {
|
||||
func parseSessionInfo(buf []byte, len int32) (*SessionInfoYAML, error) {
|
||||
// this seems not to work on windows
|
||||
// windows := true
|
||||
var sessionInfo SessionInfoYAML
|
||||
err := yaml.Unmarshal(data, &sessionInfo)
|
||||
dataBuffer := buf
|
||||
|
||||
// FOR WINDOWS
|
||||
// if windows {
|
||||
decoder := charmap.Windows1252.NewDecoder()
|
||||
buf, err := decoder.Bytes(buf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
dataBuffer = []byte(strings.TrimRight(string(buf[:len]), "\x00"))
|
||||
// }
|
||||
|
||||
err = yaml.Unmarshal(dataBuffer, &sessionInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package utils
|
||||
|
||||
import "fmt"
|
||||
|
||||
func HexDump(buf []byte) {
|
||||
fmt.Printf("\n============ HEX DUMP ============\n")
|
||||
for k := 0; k < len(buf); k++ {
|
||||
if k%4 == 0 && k > 0 {
|
||||
fmt.Printf(" ")
|
||||
}
|
||||
|
||||
if k%16 == 0 && k > 0 {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
fmt.Printf("%02X", buf[k])
|
||||
}
|
||||
fmt.Printf("\n============ HEX DUMP ============\n")
|
||||
}
|
||||
Reference in New Issue
Block a user