go-bladerf/structs.go

196 lines
4.3 KiB
Go
Raw Permalink Normal View History

2020-08-03 19:00:12 +00:00
package bladerf
// #include <libbladeRF.h>
import "C"
type Timestamp uint64
2021-05-19 22:16:00 +00:00
type DeviceInfo struct {
2020-08-06 19:57:09 +00:00
ref *C.struct_bladerf_devinfo
2021-05-23 20:09:47 +00:00
Backend Backend
Serial string
UsbBus int8
UsbAddr int8
Instance uint
Manufacturer string
Product string
2020-08-03 19:00:12 +00:00
}
2021-05-19 22:16:00 +00:00
func NewDeviceInfo(ref *C.struct_bladerf_devinfo) DeviceInfo {
deviceInfo := DeviceInfo{ref: ref}
2020-08-06 19:57:09 +00:00
var serial []rune
var manufacturer []rune
var product []rune
2021-05-19 22:16:00 +00:00
for i := range deviceInfo.ref.serial {
if deviceInfo.ref.serial[i] != 0 {
serial = append(serial, rune(deviceInfo.ref.serial[i]))
2020-08-06 19:57:09 +00:00
}
}
2021-05-19 22:16:00 +00:00
for i := range deviceInfo.ref.manufacturer {
if deviceInfo.ref.manufacturer[i] != 0 {
manufacturer = append(manufacturer, rune(deviceInfo.ref.manufacturer[i]))
2020-08-06 19:57:09 +00:00
}
}
2021-05-19 22:16:00 +00:00
for i := range deviceInfo.ref.product {
if deviceInfo.ref.product[i] != 0 {
product = append(product, rune(deviceInfo.ref.product[i]))
2020-08-06 19:57:09 +00:00
}
}
2021-05-23 20:09:47 +00:00
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)
2020-08-06 19:57:09 +00:00
2021-05-19 22:16:00 +00:00
return deviceInfo
2020-08-06 19:57:09 +00:00
}
type Version struct {
ref *C.struct_bladerf_version
2021-05-23 20:09:47 +00:00
Major uint16
Minor uint16
Patch uint16
Describe string
2020-08-03 19:00:12 +00:00
}
2020-08-22 18:08:42 +00:00
func NewVersion(ref *C.struct_bladerf_version) Version {
version := Version{ref: ref}
2021-05-23 20:09:47 +00:00
version.Major = uint16((*ref).major)
version.Minor = uint16((*ref).minor)
version.Patch = uint16((*ref).patch)
version.Describe = C.GoString((*ref).describe)
2020-08-22 18:08:42 +00:00
return version
}
2021-05-19 17:20:06 +00:00
type RationalRate struct {
ref *C.struct_bladerf_rational_rate
2021-05-23 20:09:47 +00:00
Integer uint64
Num uint64
Den uint64
2021-05-19 17:20:06 +00:00
}
func NewRationalRate(ref *C.struct_bladerf_rational_rate) RationalRate {
2021-05-23 20:09:47 +00:00
return RationalRate{ref: ref, Integer: uint64((*ref).integer), Num: uint64((*ref).num), Den: uint64((*ref).den)}
2021-05-19 17:20:06 +00:00
}
2020-08-03 19:00:12 +00:00
type Range struct {
2020-08-06 19:57:09 +00:00
ref *C.struct_bladerf_range
2021-05-23 20:09:47 +00:00
Min int64
Max int64
Step int64
Scale float64
2020-08-03 19:00:12 +00:00
}
2021-05-20 13:08:45 +00:00
func NewRange(ref *C.struct_bladerf_range) Range {
2021-05-23 20:09:47 +00:00
return Range{ref: ref, Min: int64((*ref).min), Max: int64((*ref).max), Step: int64((*ref).step), Scale: float64((*ref).scale)}
2021-05-20 13:08:45 +00:00
}
2020-08-03 19:00:12 +00:00
type BladeRF struct {
2020-08-06 19:57:09 +00:00
ref *C.struct_bladerf
2020-08-03 19:00:12 +00:00
}
2021-05-20 19:53:40 +00:00
type QuickTune struct {
ref *C.struct_bladerf_quick_tune
}
2021-05-19 17:20:06 +00:00
type Serial struct {
ref *C.struct_bladerf_serial
2021-05-23 20:09:47 +00:00
Serial string
2021-05-19 17:20:06 +00:00
}
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]))
}
}
2021-05-23 20:09:47 +00:00
return Serial{ref: ref, Serial: string(serial)}
2021-05-19 17:20:06 +00:00
}
2020-08-03 19:00:12 +00:00
type Stream struct {
2020-08-06 19:57:09 +00:00
ref *C.struct_bladerf_stream
2020-08-03 19:00:12 +00:00
}
2021-05-20 18:49:10 +00:00
type Trigger struct {
ref *C.struct_bladerf_trigger
}
type LoopbackModes struct {
ref *C.struct_bladerf_loopback_modes
2021-05-23 20:09:47 +00:00
Name string
Mode Loopback
2021-05-20 18:49:10 +00:00
}
func NewLoopbackModes(ref *C.struct_bladerf_loopback_modes) LoopbackModes {
loopbackModes := LoopbackModes{ref: ref}
2021-05-23 20:09:47 +00:00
loopbackModes.Name = C.GoString(loopbackModes.ref.name)
loopbackModes.Mode = Loopback(loopbackModes.ref.mode)
2021-05-20 18:49:10 +00:00
return loopbackModes
}
2020-08-03 19:00:12 +00:00
type GainModes struct {
2020-08-06 19:57:09 +00:00
ref *C.struct_bladerf_gain_modes
2021-05-23 20:09:47 +00:00
Name string
Mode GainMode
2020-08-06 19:57:09 +00:00
}
func NewGainModes(ref *C.struct_bladerf_gain_modes) GainModes {
gainModes := GainModes{ref: ref}
2021-05-23 20:09:47 +00:00
gainModes.Name = C.GoString(gainModes.ref.name)
gainModes.Mode = GainMode(gainModes.ref.mode)
2020-08-06 19:57:09 +00:00
return gainModes
}
2021-05-26 15:36:46 +00:00
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)
}
2020-08-06 19:57:09 +00:00
type UserData struct {
2021-05-26 15:36:46 +00:00
callback func(data []int16) GoStream
2020-08-06 19:57:09 +00:00
results []int16
bufferSize int
}
2021-05-26 15:36:46 +00:00
func NewUserData(callback func(data []int16) GoStream, bufferSize int) UserData {
2020-08-06 19:57:09 +00:00
return UserData{callback: callback, results: make([]int16, bufferSize), bufferSize: bufferSize}
2020-08-03 19:00:12 +00:00
}