Skip to content

Commit

Permalink
Cache discovered HackRF results for claimed devices
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofquality committed Jun 3, 2017
1 parent 5c121c5 commit 2a0e547
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changelog.txt
@@ -1,3 +1,8 @@
Release 0.3.1 (pending)
==========================

- Cache discovered HackRF results for claimed devices

Release 0.3.0 (2017-04-29)
==========================

Expand Down
11 changes: 10 additions & 1 deletion HackRF_Registation.cpp
Expand Up @@ -23,7 +23,7 @@
#include "SoapyHackRF.hpp"
#include <SoapySDR/Registry.hpp>


static std::map<std::string, SoapySDR::Kwargs> _cachedResults;

static std::vector<SoapySDR::Kwargs> find_HackRF(const SoapySDR::Kwargs &args)
{
Expand Down Expand Up @@ -86,6 +86,7 @@ static std::vector<SoapySDR::Kwargs> find_HackRF(const SoapySDR::Kwargs &args)
if (serialMatch and idxMatch)
{
results.push_back(options);
_cachedResults[serial_str] = options;
}

hackrf_close(device);
Expand All @@ -97,6 +98,14 @@ static std::vector<SoapySDR::Kwargs> find_HackRF(const SoapySDR::Kwargs &args)

hackrf_device_list_free(list);

//fill in the cached results for claimed handles
for (const auto &serial : HackRF_getClaimedSerials())
{
if (_cachedResults.count(serial) == 0) continue;
if (args.count("serial") != 0 and args.at("serial") != serial) continue;
results.push_back(_cachedResults.at(serial));
}

return results;
}

Expand Down
9 changes: 9 additions & 0 deletions HackRF_Settings.cpp
Expand Up @@ -23,6 +23,11 @@

#include "SoapyHackRF.hpp"

std::set<std::string> &HackRF_getClaimedSerials(void)
{
static std::set<std::string> serials;
return serials;
}

SoapyHackRF::SoapyHackRF( const SoapySDR::Kwargs &args )
{
Expand Down Expand Up @@ -70,11 +75,15 @@ SoapyHackRF::SoapyHackRF( const SoapySDR::Kwargs &args )
SoapySDR_logf( SOAPY_SDR_INFO, "Could not Open HackRF Device" );
throw std::runtime_error("hackrf open failed");
}

HackRF_getClaimedSerials().insert(_serial);
}


SoapyHackRF::~SoapyHackRF( void )
{
HackRF_getClaimedSerials().erase(_serial);

if ( _dev )
{
hackrf_close( _dev );
Expand Down
2 changes: 2 additions & 0 deletions SoapyHackRF.hpp
Expand Up @@ -28,6 +28,7 @@
#include <condition_variable>
#include <SoapySDR/Device.hpp>
#include <SoapySDR/Logger.hpp>
#include <set>

#define BUF_LEN 262144
#define BUF_NUM 15
Expand All @@ -50,6 +51,7 @@ typedef enum {
HACKRF_TRANSCEIVER_MODE_TX = 2,
} HackRF_transceiver_mode_t;

std::set<std::string> &HackRF_getClaimedSerials(void);

/*!
* The session object manages hackrf_init/exit
Expand Down

5 comments on commit 2a0e547

@guruofquality
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ly2ss You may want to try this branch "discover_claimed": https://github.com/pothosware/SoapyHackRF/tree/discover_claimed I think it resolves the issue, gave a quick test in python

@ly2ss
Copy link

@ly2ss ly2ss commented on 2a0e547 Jun 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Some progress now:
flowgraph immediately goes into TX state even if I connect hackrf sink to null source.
And btw shouldn't be "[INFO] Opening HackRF One" shown one more time once sink is opened ?

gr-osmosdr v0.1.4-91-gcf954948 (0.1.5git) gnuradio 3.7.12git-119-g0e32fcaf
built-in source types: file fcd rtl rtl_tcp hackrf rfspace soapy redpitaya
[INFO] Opening HackRF One #0 406464c82332614b...
gr-osmosdr v0.1.4-91-gcf954948 (0.1.5git) gnuradio 3.7.12git-119-g0e32fcaf
built-in sink types: hackrf soapy redpitaya file
gr::log :INFO: audio source - Audio sink arch: alsa
len(audio_taps) = 1687

@ly2ss
Copy link

@ly2ss ly2ss commented on 2a0e547 Jun 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried another RX/TX grc flow graph (which uses selector) - that one seems to work, So I guess everything is OK now, Thank you!

@guruofquality
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool

flowgraph immediately goes into TX state even if I connect hackrf sink to null source.

FYI, the null source is always outputting zeros. You might need a block like NOP so its connected but not streaming,

@eejake52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ly2ss
I'm trying to get hackrf working with TX/RX. Can you please share your flow graph?
Thanks,
Jake

Please sign in to comment.