Linux can now read from a shared memory map and the sdk can create it
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ESilva15/goirsdk/logger"
|
"github.com/ESilva15/goirsdk/logger"
|
||||||
|
"github.com/ESilva15/goirsdk/mmaputils"
|
||||||
"github.com/ESilva15/goirsdk/sharedMem"
|
"github.com/ESilva15/goirsdk/sharedMem"
|
||||||
"github.com/ESilva15/goirsdk/winutils"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ type IBT struct {
|
|||||||
// IBTExportPath string // Path for IBT export
|
// IBTExportPath string // Path for IBT export
|
||||||
// YAMLExport *os.File // If set, it will export the session YAML to the file
|
// YAMLExport *os.File // If set, it will export the session YAML to the file
|
||||||
// YAMLExportPath string // Path for YAML export
|
// YAMLExportPath string // Path for YAML export
|
||||||
winUtils *winutils.IRacingWinUtils // WinUtils gives access to the system utilities
|
winUtils *mmaputils.IRacingWinUtils // WinUtils gives access to the system utilities
|
||||||
|
|
||||||
// TODO: fragment this struct a little bit, for now I want to actually get
|
// TODO: fragment this struct a little bit, for now I want to actually get
|
||||||
// stuff done so its enough to work as is
|
// stuff done so its enough to work as is
|
||||||
@@ -117,30 +117,31 @@ func (i *IBT) openSource() error {
|
|||||||
switch i.Opts.SourceType {
|
switch i.Opts.SourceType {
|
||||||
case SharedMemoryFile:
|
case SharedMemoryFile:
|
||||||
// User is requesting us to read live data - present in the mem map file
|
// User is requesting us to read live data - present in the mem map file
|
||||||
i.File, err = winutils.OpenMemMap(IRSDK_MEMMAPFILENAME, fileMapSize)
|
i.File, err = mmaputils.OpenMemMap(MEMMAPFILENAME, fileMapSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open memory mapped file: %v", err)
|
return fmt.Errorf("failed to open memory mapped file: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// To use our windows interface we need to initialize it first
|
// To use our windows interface we need to initialize it first
|
||||||
// it will return a struct with a pointer to the windows handles
|
// it will return a struct with a pointer to the windows handles
|
||||||
// if, for some reason, we need to stub out this to run in on Linux its easier
|
// if, for some reason, we need to stub out this to run in on Linux its easier
|
||||||
i.winUtils, err = winutils.Init()
|
i.winUtils, err = mmaputils.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// I don't believe we need this on windows either, but I'll have to check
|
||||||
// We need to open the windows event thing
|
// We need to open the windows event thing
|
||||||
err = i.winUtils.OpenWinEvent(IRSDK_DATAVALIDEVENTNAME)
|
// err = i.winUtils.OpenWinEvent(IRSDK_DATAVALIDEVENTNAME)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
// We need to open the broadcast channel
|
// We need to open the broadcast channel
|
||||||
err = i.winUtils.OpenBroadcastChannel(IRSDK_BROADCASTMSGNAME)
|
// err = i.winUtils.OpenBroadcastChannel(IRSDK_BROADCASTMSGNAME)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
case IBTFile:
|
case IBTFile:
|
||||||
i.File, err = os.Open(i.Opts.SourcePath)
|
i.File, err = os.Open(i.Opts.SourcePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
// is interface some windows stuff that we need for the:
|
// is interface some windows stuff that we need for the:
|
||||||
// - Broadcast Channel
|
// - Broadcast Channel
|
||||||
// - Valid Data Event windows thing
|
// - Valid Data Event windows thing
|
||||||
package winutils
|
package mmaputils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ESilva15/goirsdk/sharedMem"
|
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -32,23 +31,12 @@ func (u *IRacingWinUtils) Close() {
|
|||||||
u.Utils.Close()
|
u.Utils.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenMemMap returns a Reader interface that can be used to read the data
|
|
||||||
// No need to encapsulate it
|
|
||||||
func OpenMemMap(path string, size uint32) (Reader, error) {
|
|
||||||
file, err := sharedMem.Open(path, size)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return file, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenWinEvent will open the named windows event
|
// OpenWinEvent will open the named windows event
|
||||||
func (u *IRacingWinUtils) OpenWinEvent(name string) error {
|
func (u *IRacingWinUtils) OpenWinEvent(name string) error {
|
||||||
return u.Utils.OpenEvent(name)
|
return u.Utils.OpenEvent(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenWinEvent will open the broadcast channel
|
// OpenBroadcastChannel will open the broadcast channel
|
||||||
func (u *IRacingWinUtils) OpenBroadcastChannel(name string) error {
|
func (u *IRacingWinUtils) OpenBroadcastChannel(name string) error {
|
||||||
return u.Utils.OpenBroadcastChannel(name)
|
return u.Utils.OpenBroadcastChannel(name)
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
//go:build (linux && cgo) || (darwin && cgo)
|
//go:build (linux && cgo) || (darwin && cgo)
|
||||||
|
|
||||||
package winutils
|
package mmaputils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ESilva15/goirsdk/sharedMem"
|
||||||
)
|
)
|
||||||
|
|
||||||
type utils struct {
|
type utils struct {
|
||||||
@@ -25,6 +27,17 @@ func (u *utils) Close() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpenMemMap returns a Reader interface that can be used to read the data
|
||||||
|
// No need to encapsulate it
|
||||||
|
func OpenMemMap(name string, size uint32) (Reader, error) {
|
||||||
|
file, err := sharedMem.Open(name, size)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to open `%s` with err: %+v", name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
// OpenEvent creates or connects to a Unix socket for event signaling on Linux
|
// OpenEvent creates or connects to a Unix socket for event signaling on Linux
|
||||||
func (u *utils) OpenEvent(eventName string) error {
|
func (u *utils) OpenEvent(eventName string) error {
|
||||||
u.socketPath = fmt.Sprintf("/tmp/iracing_%s.sock", eventName)
|
u.socketPath = fmt.Sprintf("/tmp/iracing_%s.sock", eventName)
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
// go:build windows
|
// go:build windows
|
||||||
|
|
||||||
package winutils
|
package mmaputils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/ESilva15/goirsdk/sharedMem"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,6 +37,17 @@ func (u *utils) Close() {
|
|||||||
// Do we need to close the broadcast channel ???
|
// Do we need to close the broadcast channel ???
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpenMemMap returns a Reader interface that can be used to read the data
|
||||||
|
// No need to encapsulate it
|
||||||
|
func OpenMemMap(name string, size uint32) (Reader, error) {
|
||||||
|
file, err := sharedMem.Open("Local\\"+name, size)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 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 {
|
||||||
name, err := windows.UTF16PtrFromString(eventName)
|
name, err := windows.UTF16PtrFromString(eventName)
|
||||||
Reference in New Issue
Block a user