From 2591eee725c7804799b439a5750290265c589e29 Mon Sep 17 00:00:00 2001 From: 30hours Date: Sun, 19 Nov 2023 14:51:18 +1030 Subject: [PATCH] Fixed range jumping and added mutex to fix seg faults --- config/radar4.yml | 4 ++-- src/blah2.cpp | 8 ++++---- src/capture/rspduo/RspDuo.cpp | 31 +++++++++++++++++++------------ src/data/IqData.cpp | 15 +++++++-------- src/data/IqData.h | 14 +++++++------- 5 files changed, 39 insertions(+), 33 deletions(-) diff --git a/config/radar4.yml b/config/radar4.yml index 07d8d96..5473f12 100644 --- a/config/radar4.yml +++ b/config/radar4.yml @@ -35,6 +35,6 @@ network: save: iq: true - map: true + map: false detection: false - path: "/opt/blah2/" + path: "/blah2/save/" diff --git a/src/blah2.cpp b/src/blah2.cpp index 16d31d0..d221608 100644 --- a/src/blah2.cpp +++ b/src/blah2.cpp @@ -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(t1-t0).count(); std::cout << "Extract data from buffer (ms): " << delta_t1 << std::endl; diff --git a/src/capture/rspduo/RspDuo.cpp b/src/capture/rspduo/RspDuo.cpp index 2d69d14..b9f168a 100644 --- a/src/capture/rspduo/RspDuo.cpp +++ b/src/capture/rspduo/RspDuo.cpp @@ -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,13 +546,19 @@ 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()) - { - 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 gettimeofday(¤t_tm, NULL); diff --git a/src/data/IqData.cpp b/src/data/IqData.cpp index af9703e..99fa92d 100644 --- a/src/data/IqData.cpp +++ b/src/data/IqData.cpp @@ -6,7 +6,6 @@ IqData::IqData(uint32_t _n) { n = _n; - doNotPush = false; data = new std::deque>; } @@ -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> IqData::get_data() diff --git a/src/data/IqData.h b/src/data/IqData.h index 0c020f0..831ff6c 100644 --- a/src/data/IqData.h +++ b/src/data/IqData.h @@ -10,6 +10,7 @@ #include #include #include +#include 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> *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.