-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogReader.go
More file actions
157 lines (141 loc) · 3.59 KB
/
logReader.go
File metadata and controls
157 lines (141 loc) · 3.59 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"encoding/binary"
"fmt"
"os"
"time"
)
type LogHeader struct {
NextPageAddress uint32
PagesPerTick uint16
TickDuration uint16
StartTime int64
}
type BaroConfig struct {
PressureOversampleCount uint8
TemperatureOversampleCount uint8
AltitudeScaleFactor float32
SeaLevelPressure float32
}
type IMUConfig struct {
FifoODR uint16
GyroODR uint16
AccelerometerODR uint16
GyroDecimation uint8
AccelerometerDecimation uint8
TemperatureSensorDecimation uint8
GyroFullRangeScale uint16
AccelerometerFullRangeScale uint16
}
type TickData struct {
TimeSinceBoot int64
RocketState uint32
AltitudeRelSeaLevel float32
AltitudeRelGround float32
Pressure float32
Temperature float32
IMUData IMUData
}
type IMUData struct {
TemperatureAtTickStart int16
AngularVelocity [3]int16
Acceleration [3]int16
Alignment uint16
FifoPatternIndex uint16
FifoValueSampleCount uint16
FifoValues []int16
}
func read() {
file, err := os.Open("logfile.bin")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
fmt.Println("Error closing file:", err)
}
}(file)
var header LogHeader
err = binary.Read(file, binary.LittleEndian, &header)
if err != nil {
fmt.Println("Error reading header:", err)
return
}
var baroConfig BaroConfig
err = binary.Read(file, binary.LittleEndian, &baroConfig)
if err != nil {
fmt.Println("Error reading baro config:", err)
return
}
var imuConfig IMUConfig
err = binary.Read(file, binary.LittleEndian, &imuConfig)
if err != nil {
fmt.Println("Error reading IMU config:", err)
return
}
fmt.Printf("Log Start Time: %s\n", time.Unix(0, header.StartTime*int64(time.Millisecond)).Format(time.RFC3339))
fmt.Printf("Tick Duration: %d ms\n", header.TickDuration)
fmt.Printf("Baro Config: %+v\n", baroConfig)
fmt.Printf("IMU Config: %+v\n", imuConfig)
for {
var tickData TickData
err = binary.Read(file, binary.LittleEndian, &tickData.TimeSinceBoot)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &tickData.RocketState)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &tickData.AltitudeRelSeaLevel)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &tickData.AltitudeRelGround)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &tickData.Pressure)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &tickData.Temperature)
if err != nil {
break
}
var imuData IMUData
err = binary.Read(file, binary.LittleEndian, &imuData.TemperatureAtTickStart)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &imuData.AngularVelocity)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &imuData.Acceleration)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &imuData.Alignment)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &imuData.FifoPatternIndex)
if err != nil {
break
}
err = binary.Read(file, binary.LittleEndian, &imuData.FifoValueSampleCount)
if err != nil {
break
}
imuData.FifoValues = make([]int16, imuData.FifoValueSampleCount)
err = binary.Read(file, binary.LittleEndian, &imuData.FifoValues)
if err != nil {
break
}
tickData.IMUData = imuData
fmt.Printf("Tick Data: %+v\n", tickData)
}
}