-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackrf.go
More file actions
80 lines (69 loc) · 3.13 KB
/
Copy pathhackrf.go
File metadata and controls
80 lines (69 loc) · 3.13 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
package hackrf
/*
#cgo darwin CFLAGS: -I/opt/homebrew/opt/hackrf/include -I/opt/homebrew/include -I/usr/local/include
#cgo darwin LDFLAGS: -L/opt/homebrew/opt/hackrf/lib -L/opt/homebrew/lib -L/usr/local/lib -lhackrf
#cgo linux CFLAGS: -I/usr/include -I/usr/local/include
#cgo linux LDFLAGS: -lhackrf
#include <libhackrf/hackrf.h>
*/
import "C"
// Compile-time constants mirrored from hackrf.h.
const (
// SamplesPerBlock is the number of samples per tuning when sweeping.
SamplesPerBlock = C.SAMPLES_PER_BLOCK
// BytesPerBlock is the number of bytes per tuning for sweeping.
BytesPerBlock = C.BYTES_PER_BLOCK
// MaxSweepRanges is the maximum number of sweep ranges for InitSweep.
MaxSweepRanges = C.MAX_SWEEP_RANGES
// OperacakeAddressInvalid is the placeholder for an unused Opera Cake slot.
OperacakeAddressInvalid = C.HACKRF_OPERACAKE_ADDRESS_INVALID
// OperacakeMaxBoards is the maximum number of connected Opera Cake boards.
OperacakeMaxBoards = C.HACKRF_OPERACAKE_MAX_BOARDS
// OperacakeMaxDwellTimes is the maximum number of Opera Cake dwell times.
OperacakeMaxDwellTimes = C.HACKRF_OPERACAKE_MAX_DWELL_TIMES
// OperacakeMaxFreqRanges is the maximum number of Opera Cake frequency ranges.
OperacakeMaxFreqRanges = C.HACKRF_OPERACAKE_MAX_FREQ_RANGES
// BoardRevGSG is the "made by GSG" bit in a board revision / platform ID.
BoardRevGSG = C.HACKRF_BOARD_REV_GSG
)
// Supported-platform bitfield flags returned by Device.SupportedPlatformRead
// and produced by BoardID.Platform.
const (
PlatformJawbreaker = C.HACKRF_PLATFORM_JAWBREAKER
PlatformHackRF1OG = C.HACKRF_PLATFORM_HACKRF1_OG
PlatformRad1o = C.HACKRF_PLATFORM_RAD1O
PlatformHackRF1R9 = C.HACKRF_PLATFORM_HACKRF1_R9
PlatformPraline = C.HACKRF_PLATFORM_PRALINE
)
// Init initializes libhackrf. It must be called before most other functions.
// It also initializes libusb. It is safe to call multiple times.
func Init() error {
return errorFrom(C.hackrf_init())
}
// Exit releases all libhackrf resources and shuts down libusb. All devices
// must be closed first, otherwise ErrNotLastDevice is returned. It is safe to
// call multiple times.
func Exit() error {
return errorFrom(C.hackrf_exit())
}
// LibraryVersion returns the libhackrf version as a human-readable string.
// It may be called before Init.
func LibraryVersion() string {
return C.GoString(C.hackrf_library_version())
}
// LibraryRelease returns the libhackrf release as a human-readable string.
// It may be called before Init.
func LibraryRelease() string {
return C.GoString(C.hackrf_library_release())
}
// ComputeBasebandFilterBW computes the nearest valid baseband filter bandwidth
// (in Hz) to the requested value. The result can be passed to
// Device.SetBasebandFilterBandwidth.
func ComputeBasebandFilterBW(bandwidthHz uint32) uint32 {
return uint32(C.hackrf_compute_baseband_filter_bw(C.uint32_t(bandwidthHz)))
}
// ComputeBasebandFilterBWRoundDownLt computes the highest valid baseband filter
// bandwidth (in Hz) strictly lower than the requested value.
func ComputeBasebandFilterBWRoundDownLt(bandwidthHz uint32) uint32 {
return uint32(C.hackrf_compute_baseband_filter_bw_round_down_lt(C.uint32_t(bandwidthHz)))
}