Draft commit
This commit is contained in:
commit
bebc957e02
|
@ -0,0 +1,52 @@
|
|||
.DS_Store
|
||||
.idea/
|
||||
*.[56789ao]
|
||||
*.a[56789o]
|
||||
*.so
|
||||
*.pyc
|
||||
._*
|
||||
.nfs.*
|
||||
[56789a].out
|
||||
*~
|
||||
*.orig
|
||||
*.rej
|
||||
*.exe
|
||||
.*.swp
|
||||
core
|
||||
*.cgo*.go
|
||||
*.cgo*.c
|
||||
_cgo_*
|
||||
_obj
|
||||
_test
|
||||
_testmain.go
|
||||
|
||||
/VERSION.cache
|
||||
/bin/
|
||||
/build.out
|
||||
/doc/articles/wiki/*.bin
|
||||
/goinstall.log
|
||||
/last-change
|
||||
/misc/cgo/life/run.out
|
||||
/misc/cgo/stdio/run.out
|
||||
/misc/cgo/testso/main
|
||||
/pkg/
|
||||
/src/*.*/
|
||||
/src/cmd/cgo/zdefaultcc.go
|
||||
/src/cmd/dist/dist
|
||||
/src/cmd/go/internal/cfg/zdefaultcc.go
|
||||
/src/cmd/go/internal/cfg/zosarch.go
|
||||
/src/cmd/internal/objabi/zbootstrap.go
|
||||
/src/go/build/zcgo.go
|
||||
/src/go/doc/headscan
|
||||
/src/runtime/internal/sys/zversion.go
|
||||
/src/unicode/maketables
|
||||
/test.out
|
||||
/test/garbage/*.out
|
||||
/test/pass.out
|
||||
/test/run.out
|
||||
/test/times.out
|
||||
|
||||
# This file includes artifacts of Go build that should not be checked in.
|
||||
# For files created by specific development environment (e.g. editor),
|
||||
# use alternative ways to exclude files from git.
|
||||
# For example, set up .git/info/exclude or use a global .gitignore.
|
|
@ -0,0 +1,254 @@
|
|||
package bladerf
|
||||
|
||||
// #cgo darwin CFLAGS: -I/usr/local/include
|
||||
// #cgo darwin LDFLAGS: -L/usr/local/lib
|
||||
// #cgo LDFLAGS: -lbladeRF
|
||||
// #include <libbladeRF.h>
|
||||
import "C"
|
||||
import (
|
||||
error2 "bladerf/error"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type GainMode int
|
||||
type Backend int
|
||||
type Direction int
|
||||
type ChannelLayout int
|
||||
type Correction int
|
||||
type Format int
|
||||
type Loopback int
|
||||
type RXMux int
|
||||
type ClockSelect int
|
||||
type PowerSource int
|
||||
type PMICRegister int
|
||||
|
||||
const (
|
||||
Default GainMode = C.BLADERF_GAIN_DEFAULT
|
||||
Manual GainMode = C.BLADERF_GAIN_MGC
|
||||
FastAttack_AGC GainMode = C.BLADERF_GAIN_FASTATTACK_AGC
|
||||
SlowAttack_AGC GainMode = C.BLADERF_GAIN_SLOWATTACK_AGC
|
||||
Hybrid_AGC GainMode = C.BLADERF_GAIN_HYBRID_AGC
|
||||
)
|
||||
|
||||
const (
|
||||
Any Backend = C.BLADERF_BACKEND_ANY
|
||||
Linux Backend = C.BLADERF_BACKEND_LINUX
|
||||
LibUSB Backend = C.BLADERF_BACKEND_LIBUSB
|
||||
Cypress Backend = C.BLADERF_BACKEND_CYPRESS
|
||||
Dummy Backend = C.BLADERF_BACKEND_DUMMY
|
||||
)
|
||||
|
||||
const (
|
||||
TX Direction = C.BLADERF_TX
|
||||
RX Direction = C.BLADERF_RX
|
||||
)
|
||||
|
||||
const (
|
||||
RX_X1 ChannelLayout = C.BLADERF_RX_X1
|
||||
TX_X1 ChannelLayout = C.BLADERF_TX_X1
|
||||
RX_X2 ChannelLayout = C.BLADERF_RX_X2
|
||||
TX_X2 ChannelLayout = C.BLADERF_TX_X2
|
||||
)
|
||||
|
||||
const (
|
||||
DCOFF_I Correction = C.BLADERF_CORR_DCOFF_I
|
||||
DCOFF_Q Correction = C.BLADERF_CORR_DCOFF_Q
|
||||
PHASE Correction = C.BLADERF_CORR_PHASE
|
||||
GAIN Correction = C.BLADERF_CORR_GAIN
|
||||
)
|
||||
|
||||
const (
|
||||
SC16_Q11 Format = C.BLADERF_FORMAT_SC16_Q11
|
||||
SC16_Q11_META Format = C.BLADERF_FORMAT_SC16_Q11_META
|
||||
)
|
||||
|
||||
const (
|
||||
Disabled Loopback = C.BLADERF_LB_NONE
|
||||
Firmware Loopback = C.BLADERF_LB_FIRMWARE
|
||||
BB_TXLPF_RXVGA2 Loopback = C.BLADERF_LB_BB_TXLPF_RXVGA2
|
||||
BB_TXVGA1_RXVGA2 Loopback = C.BLADERF_LB_BB_TXVGA1_RXVGA2
|
||||
BB_TXLPF_RXLPF Loopback = C.BLADERF_LB_BB_TXLPF_RXLPF
|
||||
BB_TXVGA1_RXLPF Loopback = C.BLADERF_LB_BB_TXVGA1_RXLPF
|
||||
RF_LNA1 Loopback = C.BLADERF_LB_RF_LNA1
|
||||
RF_LNA2 Loopback = C.BLADERF_LB_RF_LNA2
|
||||
RF_LNA3 Loopback = C.BLADERF_LB_RF_LNA3
|
||||
RFIC_BIST Loopback = C.BLADERF_LB_RFIC_BIST
|
||||
)
|
||||
|
||||
const (
|
||||
Invalid RXMux = C.BLADERF_RX_MUX_INVALID
|
||||
Baseband RXMux = C.BLADERF_RX_MUX_BASEBAND
|
||||
Counter_12bit RXMux = C.BLADERF_RX_MUX_12BIT_COUNTER
|
||||
Counter_32bit RXMux = C.BLADERF_RX_MUX_32BIT_COUNTER
|
||||
Digital_Loopback RXMux = C.BLADERF_RX_MUX_DIGITAL_LOOPBACK
|
||||
)
|
||||
const (
|
||||
ClockSelectUnknown ClockSelect = -99
|
||||
ClockSelectVCTCXO ClockSelect = C.CLOCK_SELECT_ONBOARD
|
||||
ClockSelectExternal ClockSelect = C.CLOCK_SELECT_EXTERNAL
|
||||
)
|
||||
|
||||
const (
|
||||
PowerSourceUnknown PowerSource = C.BLADERF_UNKNOWN
|
||||
PowerSourceDC_Barrel PowerSource = C.BLADERF_PS_DC
|
||||
PowerSourceUSB_VBUS PowerSource = C.BLADERF_PS_USB_VBUS
|
||||
)
|
||||
|
||||
const (
|
||||
Configuration PMICRegister = C.BLADERF_PMIC_CONFIGURATION
|
||||
Voltage_shunt PMICRegister = C.BLADERF_PMIC_VOLTAGE_SHUNT
|
||||
Voltage_bus PMICRegister = C.BLADERF_PMIC_VOLTAGE_BUS
|
||||
Power PMICRegister = C.BLADERF_PMIC_POWER
|
||||
Current PMICRegister = C.BLADERF_PMIC_CURRENT
|
||||
Calibration PMICRegister = C.BLADERF_PMIC_CALIBRATION
|
||||
)
|
||||
|
||||
const (
|
||||
RX_V int = 0x0
|
||||
TX_V int = 0x1
|
||||
)
|
||||
|
||||
const (
|
||||
BLADERF_VCTCXO_FREQUENCY = 38.4e6
|
||||
BLADERF_REFIN_DEFAULT = 10.0e6
|
||||
BLADERF_SERIAL_LENGTH = 33
|
||||
)
|
||||
|
||||
func checkError(e error) {
|
||||
if e != nil {
|
||||
fmt.Printf(e.Error())
|
||||
}
|
||||
}
|
||||
|
||||
type Version struct {
|
||||
version *C.struct_bladerf_version
|
||||
major int
|
||||
minor int
|
||||
patch int
|
||||
describe string
|
||||
}
|
||||
|
||||
type DevInfo struct {
|
||||
devInfo *C.struct_bladerf_devinfo
|
||||
}
|
||||
|
||||
type BladeRF struct {
|
||||
bladeRF *C.struct_bladerf
|
||||
}
|
||||
|
||||
func GetVersion() Version {
|
||||
var version C.struct_bladerf_version
|
||||
C.bladerf_version(&version)
|
||||
return Version{version: &version, major: int(version.major), minor: int(version.minor), patch: int(version.patch), describe: C.GoString(version.describe)}
|
||||
}
|
||||
|
||||
func PrintVersion(version Version) {
|
||||
fmt.Printf("v%d.%d.%d (\"%s\")", version.major, version.minor, version.patch, version.describe)
|
||||
}
|
||||
|
||||
func GetError(e C.int) error {
|
||||
if e == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return error2.Error(e)
|
||||
}
|
||||
|
||||
func LoadFpga(bladeRF BladeRF, imagePath string) {
|
||||
path := C.CString(imagePath)
|
||||
defer C.free(unsafe.Pointer(path))
|
||||
|
||||
C.bladerf_load_fpga(bladeRF.bladeRF, path)
|
||||
C.bladerf_close(bladeRF.bladeRF)
|
||||
}
|
||||
|
||||
func FreeDeviceList(devInfo DevInfo) {
|
||||
C.bladerf_free_device_list(devInfo.devInfo)
|
||||
}
|
||||
|
||||
func GetDeviceList() []DevInfo {
|
||||
var devInfo *C.struct_bladerf_devinfo
|
||||
var devices []DevInfo
|
||||
|
||||
count := int(C.bladerf_get_device_list(&devInfo))
|
||||
|
||||
if count < 1 {
|
||||
return devices
|
||||
}
|
||||
|
||||
first := DevInfo{devInfo: devInfo}
|
||||
|
||||
defer FreeDeviceList(first)
|
||||
|
||||
devices = append(devices, first)
|
||||
|
||||
for i := 0; i < count-1; i++ {
|
||||
size := unsafe.Sizeof(*devInfo)
|
||||
devInfo = (*C.struct_bladerf_devinfo)(unsafe.Pointer(uintptr(unsafe.Pointer(devInfo)) + size))
|
||||
devices = append(devices, DevInfo{devInfo: devInfo})
|
||||
}
|
||||
|
||||
return devices
|
||||
}
|
||||
|
||||
func GetBootloaderList() []DevInfo {
|
||||
var devInfo *C.struct_bladerf_devinfo
|
||||
var devices []DevInfo
|
||||
|
||||
count := int(C.bladerf_get_bootloader_list(&devInfo))
|
||||
|
||||
if count < 1 {
|
||||
return devices
|
||||
}
|
||||
|
||||
first := DevInfo{devInfo: devInfo}
|
||||
|
||||
defer FreeDeviceList(first)
|
||||
|
||||
devices = append(devices, first)
|
||||
|
||||
for i := 0; i < count-1; i++ {
|
||||
size := unsafe.Sizeof(*devInfo)
|
||||
devInfo = (*C.struct_bladerf_devinfo)(unsafe.Pointer(uintptr(unsafe.Pointer(devInfo)) + size))
|
||||
devices = append(devices, DevInfo{devInfo: devInfo})
|
||||
}
|
||||
|
||||
return devices
|
||||
}
|
||||
|
||||
func CHANNEL_RX(ch int) int {
|
||||
return (ch << 1) | RX_V
|
||||
}
|
||||
|
||||
func CHANNEL_TX(ch int) int {
|
||||
return (ch << 1) | TX_V
|
||||
}
|
||||
|
||||
func GetDevInfo() DevInfo {
|
||||
var devInfo C.struct_bladerf_devinfo
|
||||
C.bladerf_init_devinfo(&devInfo)
|
||||
return DevInfo{devInfo: &devInfo}
|
||||
}
|
||||
|
||||
func OpenWithDevInfo(devInfo DevInfo) BladeRF {
|
||||
var bladeRF *C.struct_bladerf
|
||||
C.bladerf_open_with_devinfo(&bladeRF, devInfo.devInfo)
|
||||
return BladeRF{bladeRF: bladeRF}
|
||||
}
|
||||
|
||||
func OpenWithDeviceIdentifier(identify string) BladeRF {
|
||||
var bladeRF *C.struct_bladerf
|
||||
C.bladerf_open(&bladeRF, C.CString(identify))
|
||||
return BladeRF{bladeRF: bladeRF}
|
||||
}
|
||||
|
||||
func Open() BladeRF {
|
||||
var bladeRF *C.struct_bladerf
|
||||
C.bladerf_open(&bladeRF, nil)
|
||||
return BladeRF{bladeRF: bladeRF}
|
||||
}
|
||||
|
||||
func Close(bladeRF BladeRF) {
|
||||
C.bladerf_close(bladeRF.bladeRF)
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package bladerf
|
||||
|
||||
import (
|
||||
"bladerf/log"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBladeRF(t *testing.T) {
|
||||
log.SetVerbosity(log.Debug)
|
||||
|
||||
PrintVersion(GetVersion())
|
||||
|
||||
LoadFpga(Open(), "~/test") // Auto Close
|
||||
Close(Open())
|
||||
Close(OpenWithDevInfo(GetDevInfo()))
|
||||
Close(OpenWithDeviceIdentifier("*:serial=NOTFOUND"))
|
||||
|
||||
devices := GetDeviceList()
|
||||
fmt.Printf("Devices Len: %d\n", len(devices))
|
||||
|
||||
bootloaders := GetBootloaderList()
|
||||
fmt.Printf("Bootloaders Len: %d\n", len(bootloaders))
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package device_speed
|
||||
|
||||
// #include <libbladeRF.h>
|
||||
import "C"
|
||||
|
||||
type DeviceSpeed int
|
||||
|
||||
const (
|
||||
Unknown DeviceSpeed = C.BLADERF_DEVICE_SPEED_UNKNOWN
|
||||
High DeviceSpeed = C.BLADERF_DEVICE_SPEED_HIGH
|
||||
Super DeviceSpeed = C.BLADERF_DEVICE_SPEED_SUPER
|
||||
)
|
|
@ -0,0 +1,77 @@
|
|||
package error
|
||||
|
||||
// #include <libbladeRF.h>
|
||||
import "C"
|
||||
|
||||
type Error int
|
||||
|
||||
const (
|
||||
Unexpected Error = -1
|
||||
Range Error = -2
|
||||
Inval Error = -3
|
||||
Mem Error = -4
|
||||
Io Error = -5
|
||||
Timeout Error = -6
|
||||
Nodev Error = -7
|
||||
Unsupported Error = -8
|
||||
Misaligned Error = -9
|
||||
Checksum Error = -10
|
||||
NoFile Error = -11
|
||||
UpdateFpga Error = -12
|
||||
UpdateFw Error = -13
|
||||
TimePast Error = -14
|
||||
QueueFull Error = -15
|
||||
FpgaOp Error = -16
|
||||
Permission Error = -17
|
||||
WouldBlock Error = -18
|
||||
NotInit Error = -19
|
||||
)
|
||||
|
||||
func (err Error) Error() string {
|
||||
return err.String()
|
||||
}
|
||||
|
||||
func (err Error) String() string {
|
||||
switch err {
|
||||
case Unexpected:
|
||||
return "An unexpected failure occurred"
|
||||
case Range:
|
||||
return "Provided parameter is out of range"
|
||||
case Inval:
|
||||
return "Invalid operation/parameter"
|
||||
case Mem:
|
||||
return "Memory allocation error"
|
||||
case Io:
|
||||
return "File/Device I/O error"
|
||||
case Timeout:
|
||||
return "Operation timed out"
|
||||
case Nodev:
|
||||
return "No device(s) available"
|
||||
case Unsupported:
|
||||
return "Operation not supported"
|
||||
case Misaligned:
|
||||
return "Misaligned flash access"
|
||||
case Checksum:
|
||||
return "Invalid checksum"
|
||||
case NoFile:
|
||||
return "File not found"
|
||||
case UpdateFpga:
|
||||
return "An FPGA update is required"
|
||||
case UpdateFw:
|
||||
return "A firmware update is required"
|
||||
case TimePast:
|
||||
return "Requested timestamp is in the past"
|
||||
case QueueFull:
|
||||
return "Could not enqueue data into full queue"
|
||||
case FpgaOp:
|
||||
return "An FPGA operation reported failure"
|
||||
case Permission:
|
||||
return "Insufficient permissions for the requested operation"
|
||||
case WouldBlock:
|
||||
return "Operation would block, but has been requested to be non-blocking. This indicates to a caller that it may need to retry the operation later."
|
||||
case NotInit:
|
||||
return "Device insufficiently initialized for operation"
|
||||
}
|
||||
|
||||
return "InvalidError"
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package log
|
||||
|
||||
// #cgo LDFLAGS: -lbladeRF
|
||||
// #include <libbladeRF.h>
|
||||
import "C"
|
||||
import "errors"
|
||||
|
||||
type Level int
|
||||
|
||||
const (
|
||||
Verbose Level = 0
|
||||
Debug Level = 1
|
||||
Info Level = 2
|
||||
Warning Level = 3
|
||||
Error Level = 4
|
||||
Critical Level = 5
|
||||
Silent Level = 6
|
||||
)
|
||||
|
||||
func SetVerbosity(level Level) {
|
||||
switch level {
|
||||
case Verbose:
|
||||
C.bladerf_log_set_verbosity(C.BLADERF_LOG_LEVEL_VERBOSE)
|
||||
case Debug:
|
||||
C.bladerf_log_set_verbosity(C.BLADERF_LOG_LEVEL_DEBUG)
|
||||
case Info:
|
||||
C.bladerf_log_set_verbosity(C.BLADERF_LOG_LEVEL_INFO)
|
||||
case Warning:
|
||||
C.bladerf_log_set_verbosity(C.BLADERF_LOG_LEVEL_WARNING)
|
||||
case Error:
|
||||
C.bladerf_log_set_verbosity(C.BLADERF_LOG_LEVEL_ERROR)
|
||||
case Critical:
|
||||
C.bladerf_log_set_verbosity(C.BLADERF_LOG_LEVEL_CRITICAL)
|
||||
case Silent:
|
||||
C.bladerf_log_set_verbosity(C.BLADERF_LOG_LEVEL_VERBOSE)
|
||||
default:
|
||||
panic(errors.New("invalid libbladerf_verbosity"))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue