mirror of
https://github.com/30hours/blah2.git
synced 2024-11-18 12:33:58 +00:00
Fixed range jumping and added mutex to fix seg faults
This commit is contained in:
parent
a5a07f0f34
commit
2591eee725
5 changed files with 39 additions and 33 deletions
|
@ -35,6 +35,6 @@ network:
|
|||
|
||||
save:
|
||||
iq: true
|
||||
map: true
|
||||
map: false
|
||||
detection: false
|
||||
path: "/opt/blah2/"
|
||||
path: "/blah2/save/"
|
||||
|
|
|
@ -169,15 +169,15 @@ int main(int argc, char **argv)
|
|||
auto t0 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// extract data from buffer
|
||||
buffer1->set_doNotPush(true);
|
||||
buffer2->set_doNotPush(true);
|
||||
buffer1->lock();
|
||||
buffer2->lock();
|
||||
for (int i = 0; i < nSamples; i++)
|
||||
{
|
||||
x->push_back(buffer1->pop_front());
|
||||
y->push_back(buffer2->pop_front());
|
||||
}
|
||||
buffer1->set_doNotPush(false);
|
||||
buffer2->set_doNotPush(false);
|
||||
buffer1->unlock();
|
||||
buffer2->unlock();
|
||||
auto t1 = std::chrono::high_resolution_clock::now();
|
||||
double delta_t1 = std::chrono::duration<double, std::milli>(t1-t0).count();
|
||||
std::cout << "Extract data from buffer (ms): " << delta_t1 << std::endl;
|
||||
|
|
|
@ -131,11 +131,18 @@ void RspDuo::replay(IqData *_buffer1, IqData *_buffer2, std::string _file, bool
|
|||
rv = fread(&i2, 1, sizeof(short), file_replay);
|
||||
rv = fread(&q2, 1, sizeof(short), file_replay);
|
||||
|
||||
if (!buffer1->get_doNotPush() & buffer1->get_length() < buffer1->get_n())
|
||||
buffer1->lock();
|
||||
buffer2->lock();
|
||||
|
||||
if (buffer1->get_length() < buffer1->get_n())
|
||||
{
|
||||
buffer1->push_back({(double)i1, (double)q1});
|
||||
buffer2->push_back({(double)i2, (double)q2});
|
||||
}
|
||||
|
||||
buffer1->unlock();
|
||||
buffer2->unlock();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -508,12 +515,6 @@ void RspDuo::stream_a_callback(short *xi, short *xq, sdrplay_api_StreamCbParamsT
|
|||
// skip tuner B data
|
||||
j++;
|
||||
j++;
|
||||
|
||||
if (!buffer1->get_doNotPush())
|
||||
{
|
||||
buffer1->push_back({(double)xi[i], (double)xq[i]});
|
||||
//buffer2->push_back({(double)xi[i], (double)xq[i]});
|
||||
}
|
||||
}
|
||||
|
||||
// find max for stats
|
||||
|
@ -545,12 +546,18 @@ void RspDuo::stream_b_callback(short *xi, short *xq, sdrplay_api_StreamCbParamsT
|
|||
// add tuner B data
|
||||
buffer_16_ar[j++] = xi[i];
|
||||
buffer_16_ar[j++] = xq[i];
|
||||
}
|
||||
|
||||
if (!buffer2->get_doNotPush())
|
||||
// write data to IqData
|
||||
buffer1->lock();
|
||||
buffer2->lock();
|
||||
for (int i = 0; i < numSamples*4; i+=4)
|
||||
{
|
||||
buffer2->push_back({(double)xi[i], (double)xq[i]});
|
||||
}
|
||||
buffer1->push_back({(double)buffer_16_ar[i], (double)buffer_16_ar[i+1]});
|
||||
buffer2->push_back({(double)buffer_16_ar[i+2], (double)buffer_16_ar[i+3]});
|
||||
}
|
||||
buffer1->unlock();
|
||||
buffer2->unlock();
|
||||
|
||||
// decide if to write data
|
||||
gettimeofday(¤t_tm, NULL);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
IqData::IqData(uint32_t _n)
|
||||
{
|
||||
n = _n;
|
||||
doNotPush = false;
|
||||
data = new std::deque<std::complex<double>>;
|
||||
}
|
||||
|
||||
|
@ -15,19 +14,19 @@ uint32_t IqData::get_n()
|
|||
return n;
|
||||
}
|
||||
|
||||
void IqData::set_doNotPush(bool _doNotPush)
|
||||
{
|
||||
doNotPush = _doNotPush;
|
||||
}
|
||||
|
||||
uint32_t IqData::get_length()
|
||||
{
|
||||
return data->size();
|
||||
}
|
||||
|
||||
bool IqData::get_doNotPush()
|
||||
void IqData::lock()
|
||||
{
|
||||
return doNotPush;
|
||||
mutex_lock.lock();
|
||||
}
|
||||
|
||||
void IqData::unlock()
|
||||
{
|
||||
mutex_lock.unlock();
|
||||
}
|
||||
|
||||
std::deque<std::complex<double>> IqData::get_data()
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdint.h>
|
||||
#include <deque>
|
||||
#include <complex>
|
||||
#include <mutex>
|
||||
|
||||
class IqData
|
||||
{
|
||||
|
@ -18,7 +19,7 @@ private:
|
|||
uint32_t n;
|
||||
|
||||
/// @brief True if should not push to buffer (mutex).
|
||||
bool doNotPush;
|
||||
std::mutex mutex_lock;
|
||||
|
||||
/// @brief Pointer to IQ data.
|
||||
std::deque<std::complex<double>> *data;
|
||||
|
@ -37,14 +38,13 @@ public:
|
|||
/// @return Number of samples currently in data.
|
||||
uint32_t get_length();
|
||||
|
||||
/// @brief Setter for mutex.
|
||||
/// @param doNotPush True if should not push to buffer (mutex).
|
||||
/// @brief Locker for mutex.
|
||||
/// @return Void.
|
||||
void set_doNotPush(bool doNotPush);
|
||||
void lock();
|
||||
|
||||
/// @brief Getter for mutex.
|
||||
/// @return True if should not push to buffer (mutex).
|
||||
bool get_doNotPush();
|
||||
/// @brief Unlocker for mutex.
|
||||
/// @return Void.
|
||||
void unlock();
|
||||
|
||||
/// @brief Getter for data.
|
||||
/// @return IQ data.
|
||||
|
|
Loading…
Reference in a new issue