-
Notifications
You must be signed in to change notification settings - Fork 4
/
structs.go
195 lines (154 loc) · 4.32 KB
/
structs.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package bladerf
// #include <libbladeRF.h>
import "C"
type Timestamp uint64
type DeviceInfo struct {
ref *C.struct_bladerf_devinfo
Backend Backend
Serial string
UsbBus int8
UsbAddr int8
Instance uint
Manufacturer string
Product string
}
func NewDeviceInfo(ref *C.struct_bladerf_devinfo) DeviceInfo {
deviceInfo := DeviceInfo{ref: ref}
var serial []rune
var manufacturer []rune
var product []rune
for i := range deviceInfo.ref.serial {
if deviceInfo.ref.serial[i] != 0 {
serial = append(serial, rune(deviceInfo.ref.serial[i]))
}
}
for i := range deviceInfo.ref.manufacturer {
if deviceInfo.ref.manufacturer[i] != 0 {
manufacturer = append(manufacturer, rune(deviceInfo.ref.manufacturer[i]))
}
}
for i := range deviceInfo.ref.product {
if deviceInfo.ref.product[i] != 0 {
product = append(product, rune(deviceInfo.ref.product[i]))
}
}
deviceInfo.Backend = Backend(deviceInfo.ref.backend)
deviceInfo.Serial = string(serial)
deviceInfo.UsbBus = int8(deviceInfo.ref.usb_bus)
deviceInfo.UsbAddr = int8(deviceInfo.ref.usb_addr)
deviceInfo.Instance = uint(deviceInfo.ref.instance)
deviceInfo.Manufacturer = string(manufacturer)
deviceInfo.Product = string(product)
return deviceInfo
}
type Version struct {
ref *C.struct_bladerf_version
Major uint16
Minor uint16
Patch uint16
Describe string
}
func NewVersion(ref *C.struct_bladerf_version) Version {
version := Version{ref: ref}
version.Major = uint16((*ref).major)
version.Minor = uint16((*ref).minor)
version.Patch = uint16((*ref).patch)
version.Describe = C.GoString((*ref).describe)
return version
}
type RationalRate struct {
ref *C.struct_bladerf_rational_rate
Integer uint64
Num uint64
Den uint64
}
func NewRationalRate(ref *C.struct_bladerf_rational_rate) RationalRate {
return RationalRate{ref: ref, Integer: uint64((*ref).integer), Num: uint64((*ref).num), Den: uint64((*ref).den)}
}
type Range struct {
ref *C.struct_bladerf_range
Min int64
Max int64
Step int64
Scale float64
}
func NewRange(ref *C.struct_bladerf_range) Range {
return Range{ref: ref, Min: int64((*ref).min), Max: int64((*ref).max), Step: int64((*ref).step), Scale: float64((*ref).scale)}
}
type BladeRF struct {
ref *C.struct_bladerf
}
type QuickTune struct {
ref *C.struct_bladerf_quick_tune
}
type Serial struct {
ref *C.struct_bladerf_serial
Serial string
}
func NewSerial(ref *C.struct_bladerf_serial) Serial {
var serial []rune
for i := range (*ref).serial {
if (*ref).serial[i] != 0 {
serial = append(serial, rune((*ref).serial[i]))
}
}
return Serial{ref: ref, Serial: string(serial)}
}
type Stream struct {
ref *C.struct_bladerf_stream
}
type Trigger struct {
ref *C.struct_bladerf_trigger
}
type LoopbackModes struct {
ref *C.struct_bladerf_loopback_modes
Name string
Mode Loopback
}
func NewLoopbackModes(ref *C.struct_bladerf_loopback_modes) LoopbackModes {
loopbackModes := LoopbackModes{ref: ref}
loopbackModes.Name = C.GoString(loopbackModes.ref.name)
loopbackModes.Mode = Loopback(loopbackModes.ref.mode)
return loopbackModes
}
type GainModes struct {
ref *C.struct_bladerf_gain_modes
Name string
Mode GainMode
}
func NewGainModes(ref *C.struct_bladerf_gain_modes) GainModes {
gainModes := GainModes{ref: ref}
gainModes.Name = C.GoString(gainModes.ref.name)
gainModes.Mode = GainMode(gainModes.ref.mode)
return gainModes
}
type Metadata struct {
ref *C.struct_bladerf_metadata
Timestamp Timestamp
Flags uint32
Status uint32
ActualCount uint
}
func LoadMetadata(ref *C.struct_bladerf_metadata) Metadata {
metadata := Metadata{ref: ref}
metadata.Timestamp = Timestamp(metadata.ref.timestamp)
metadata.Flags = uint32(metadata.ref.flags)
metadata.Status = uint32(metadata.ref.status)
metadata.ActualCount = uint(metadata.ref.actual_count)
return metadata
}
func NewMetadata(timestamp Timestamp, flags uint32) Metadata {
ref := C.struct_bladerf_metadata{
timestamp: C.uint64_t(timestamp),
flags: C.uint32_t(flags),
}
return LoadMetadata(&ref)
}
type UserData struct {
callback func(data []int16) GoStream
results []int16
bufferSize int
}
func NewUserData(callback func(data []int16) GoStream, bufferSize int) UserData {
return UserData{callback: callback, results: make([]int16, bufferSize), bufferSize: bufferSize}
}