somethings happen

This commit is contained in:
Eray Arslan 2020-08-02 17:13:49 +03:00
parent 8b521ae877
commit 939f4e0f23
2 changed files with 65 additions and 12 deletions

View File

@ -164,6 +164,7 @@ type Version struct {
type DevInfo struct {
devInfo *C.struct_bladerf_devinfo
serial string
}
type Range struct {
@ -215,7 +216,6 @@ func LoadFpga(bladeRF BladeRF, imagePath string) {
defer C.free(unsafe.Pointer(path))
C.bladerf_load_fpga(bladeRF.bladeRF, path)
C.bladerf_close(bladeRF.bladeRF)
}
func FreeDeviceList(devInfo DevInfo) {
@ -280,12 +280,45 @@ func CHANNEL_TX(ch int) int {
return (ch << 1) | TX_V
}
func GetDevInfo() DevInfo {
func InitDevInfo() DevInfo {
var devInfo C.struct_bladerf_devinfo
C.bladerf_init_devinfo(&devInfo)
return DevInfo{devInfo: &devInfo}
}
func GetDevInfo(bladeRF *BladeRF) DevInfo {
var devInfo C.struct_bladerf_devinfo
C.bladerf_get_devinfo((*bladeRF).bladeRF, &devInfo)
var fs []rune
for i := range devInfo.serial {
if devInfo.serial[i] != 0 {
fs = append(fs, rune(devInfo.serial[i]))
}
}
info := DevInfo{devInfo: &devInfo, serial: string(fs)}
return info
}
func DevInfoMatches(a DevInfo, b DevInfo) bool {
return bool(C.bladerf_devinfo_matches(a.devInfo, b.devInfo))
}
func DevStrMatches(devstr string, info DevInfo) bool {
val := C.CString(devstr)
defer C.free(unsafe.Pointer(val))
return bool(C.bladerf_devstr_matches(val, info.devInfo))
}
func GetDevInfoFromStr(devstr string) DevInfo {
val := C.CString(devstr)
defer C.free(unsafe.Pointer(val))
var devInfo C.struct_bladerf_devinfo
C.bladerf_get_devinfo_from_str(val, &devInfo)
return DevInfo{devInfo: &devInfo}
}
func OpenWithDevInfo(devInfo DevInfo) BladeRF {
var bladeRF *C.struct_bladerf
C.bladerf_open_with_devinfo(&bladeRF, devInfo.devInfo)

View File

@ -46,25 +46,45 @@ func GetFinalData(input []int16) []complex64 {
}
func TestBladeRF(t *testing.T) {
log.SetVerbosity(log.Critical)
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))
rf := OpenWithDevInfo(devices[0])
LoadFpga(rf, "/Users/erayarslan/Downloads/hostedxA4-latest.rbf")
Close(rf)
rf = Open()
info := GetDevInfo(&rf)
Close(rf)
Close(OpenWithDevInfo(GetDevInfo(&rf)))
Close(Open())
Close(OpenWithDeviceIdentifier("*:serial=" + info.serial))
Close(OpenWithDevInfo(GetDevInfoFromStr("*:serial=" + info.serial)))
result := DevInfoMatches(GetDevInfo(&rf), GetDevInfo(&rf))
fmt.Println("---------")
fmt.Println(result)
fmt.Println("---------")
result = DevStrMatches("*:serial=" + info.serial, GetDevInfo(&rf))
fmt.Println("---------")
fmt.Println(result)
fmt.Println("---------")
rf = Open()
bootloaders := GetBootloaderList()
fmt.Printf("Bootloaders Len: %d\n", len(bootloaders))
rf := Open()
stream := InitStream(&rf, SC16_Q11, 2, 1024, 1, cb)
StartStream(stream, RX_X1)
Close(rf)
err := EnableModule(&rf, RX)
if err != nil {
fmt.Println(err)
}
_ = InitStream(&rf, SC16_Q11, 16, audioBufferSize, 8, cb)
// _ = StartStream(stream, RX_X1)
}
func TestSetGainStage(t *testing.T) {