-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelemetry.go
99 lines (85 loc) · 2.33 KB
/
telemetry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package acctelemetry
import (
"fmt"
"unsafe"
)
const STATIC_FILE_MMAP = "Local\\acpmf_static"
const PHYSICS_FILE_MMAP = "Local\\acpmf_physics"
const GRAPHIS_FILE_MMAP = "Local\\acpmf_graphics"
type AccTelemetry struct {
staticData *accDataHolder[AccStatic]
physicsData *accDataHolder[AccPhysics]
graphicsData *accDataHolder[AccGraphic]
}
type accDataHolder[T AccGraphic | AccPhysics | AccStatic] struct {
mmap *mmap
data *T
}
func (d *accDataHolder[T]) Close() error {
if d.mmap != nil {
d.mmap.Close()
d.mmap = nil
}
d.data = nil
return nil
}
func (t *AccTelemetry) Connect() error {
var accStatic AccStatic
staticMMap, err := mapFile(STATIC_FILE_MMAP, unsafe.Sizeof(accStatic))
if err != nil {
return fmt.Errorf("Failed to create mapping to ACC static file: %w", err)
}
t.staticData = &accDataHolder[AccStatic]{
mmap: staticMMap,
data: (*AccStatic)(staticMMap.pointer()),
}
var accPhysics AccPhysics
physicsMMap, err := mapFile(PHYSICS_FILE_MMAP, unsafe.Sizeof(accPhysics))
if err != nil {
return fmt.Errorf("Failed to create mapping to ACC physics file: %w", err)
}
t.physicsData = &accDataHolder[AccPhysics]{
mmap: physicsMMap,
data: (*AccPhysics)(physicsMMap.pointer()),
}
var accGraphic AccGraphic
graphicsMMap, err := mapFile(GRAPHIS_FILE_MMAP, unsafe.Sizeof(accGraphic))
if err != nil {
return fmt.Errorf("Failed to create mapping to ACC physics file: %w", err)
}
t.graphicsData = &accDataHolder[AccGraphic]{
mmap: graphicsMMap,
data: (*AccGraphic)(graphicsMMap.pointer()),
}
return nil
}
func New() *AccTelemetry {
return &AccTelemetry{}
}
// this returns direct pointer to the memory so underlying struct will change over time
func (t *AccTelemetry) GraphicsPointer() *AccGraphic {
if t.graphicsData != nil {
return t.graphicsData.data
}
return nil
}
// this returns direct pointer to the memory so underlying struct will change over time
func (t *AccTelemetry) StaticPointer() *AccStatic {
if t.staticData != nil {
return t.staticData.data
}
return nil
}
// this returns direct pointer to the memory so underlying struct will change over time
func (t *AccTelemetry) PhysicsPointer() *AccPhysics {
if t.physicsData != nil {
return t.physicsData.data
}
return nil
}
func (t *AccTelemetry) Close() error {
t.graphicsData.Close()
t.staticData.Close()
t.physicsData.Close()
return nil
}