Fixed range jumping and added mutex to fix seg faults

This commit is contained in:
30hours 2023-11-19 14:51:18 +10:30
parent a5a07f0f34
commit 2591eee725
5 changed files with 39 additions and 33 deletions

View file

@ -35,6 +35,6 @@ network:
save: save:
iq: true iq: true
map: true map: false
detection: false detection: false
path: "/opt/blah2/" path: "/blah2/save/"

View file

@ -169,15 +169,15 @@ int main(int argc, char **argv)
auto t0 = std::chrono::high_resolution_clock::now(); auto t0 = std::chrono::high_resolution_clock::now();
// extract data from buffer // extract data from buffer
buffer1->set_doNotPush(true); buffer1->lock();
buffer2->set_doNotPush(true); buffer2->lock();
for (int i = 0; i < nSamples; i++) for (int i = 0; i < nSamples; i++)
{ {
x->push_back(buffer1->pop_front()); x->push_back(buffer1->pop_front());
y->push_back(buffer2->pop_front()); y->push_back(buffer2->pop_front());
} }
buffer1->set_doNotPush(false); buffer1->unlock();
buffer2->set_doNotPush(false); buffer2->unlock();
auto t1 = std::chrono::high_resolution_clock::now(); auto t1 = std::chrono::high_resolution_clock::now();
double delta_t1 = std::chrono::duration<double, std::milli>(t1-t0).count(); double delta_t1 = std::chrono::duration<double, std::milli>(t1-t0).count();
std::cout << "Extract data from buffer (ms): " << delta_t1 << std::endl; std::cout << "Extract data from buffer (ms): " << delta_t1 << std::endl;

View file

@ -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(&i2, 1, sizeof(short), file_replay);
rv = fread(&q2, 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}); buffer1->push_back({(double)i1, (double)q1});
buffer2->push_back({(double)i2, (double)q2}); 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 // skip tuner B data
j++; j++;
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 // find max for stats
@ -545,13 +546,19 @@ void RspDuo::stream_b_callback(short *xi, short *xq, sdrplay_api_StreamCbParamsT
// add tuner B data // add tuner B data
buffer_16_ar[j++] = xi[i]; buffer_16_ar[j++] = xi[i];
buffer_16_ar[j++] = xq[i]; buffer_16_ar[j++] = xq[i];
if (!buffer2->get_doNotPush())
{
buffer2->push_back({(double)xi[i], (double)xq[i]});
}
} }
// write data to IqData
buffer1->lock();
buffer2->lock();
for (int i = 0; i < numSamples*4; i+=4)
{
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 // decide if to write data
gettimeofday(&current_tm, NULL); gettimeofday(&current_tm, NULL);

View file

@ -6,7 +6,6 @@
IqData::IqData(uint32_t _n) IqData::IqData(uint32_t _n)
{ {
n = _n; n = _n;
doNotPush = false;
data = new std::deque<std::complex<double>>; data = new std::deque<std::complex<double>>;
} }
@ -15,19 +14,19 @@ uint32_t IqData::get_n()
return n; return n;
} }
void IqData::set_doNotPush(bool _doNotPush)
{
doNotPush = _doNotPush;
}
uint32_t IqData::get_length() uint32_t IqData::get_length()
{ {
return data->size(); 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() std::deque<std::complex<double>> IqData::get_data()

View file

@ -10,6 +10,7 @@
#include <stdint.h> #include <stdint.h>
#include <deque> #include <deque>
#include <complex> #include <complex>
#include <mutex>
class IqData class IqData
{ {
@ -18,7 +19,7 @@ private:
uint32_t n; uint32_t n;
/// @brief True if should not push to buffer (mutex). /// @brief True if should not push to buffer (mutex).
bool doNotPush; std::mutex mutex_lock;
/// @brief Pointer to IQ data. /// @brief Pointer to IQ data.
std::deque<std::complex<double>> *data; std::deque<std::complex<double>> *data;
@ -37,14 +38,13 @@ public:
/// @return Number of samples currently in data. /// @return Number of samples currently in data.
uint32_t get_length(); uint32_t get_length();
/// @brief Setter for mutex. /// @brief Locker for mutex.
/// @param doNotPush True if should not push to buffer (mutex).
/// @return Void. /// @return Void.
void set_doNotPush(bool doNotPush); void lock();
/// @brief Getter for mutex. /// @brief Unlocker for mutex.
/// @return True if should not push to buffer (mutex). /// @return Void.
bool get_doNotPush(); void unlock();
/// @brief Getter for data. /// @brief Getter for data.
/// @return IQ data. /// @return IQ data.