diff --git a/src/capture/kraken/Kraken.cpp b/src/capture/kraken/Kraken.cpp index 93bf901..06c9def 100644 --- a/src/capture/kraken/Kraken.cpp +++ b/src/capture/kraken/Kraken.cpp @@ -11,7 +11,7 @@ Kraken::Kraken(std::string _type, uint32_t _fc, uint32_t _fs, : Source(_type, _fc, _fs, _path, _saveIq) { // convert gain to tenths of dB - for (int i = 0; i <= _gain.size(); i++) + for (int i = 0; i < _gain.size(); i++) { gain.push_back(static_cast(_gain[i]*10)); channelIndex.push_back(i); @@ -33,7 +33,7 @@ Kraken::Kraken(std::string _type, uint32_t _fc, uint32_t _fs, check_status(status, "Failed to close device for available gains."); // update gains to next value if invalid - for (int i = 0; i <= _gain.size(); i++) + for (int i = 0; i < _gain.size(); i++) { int adjustedGain = static_cast(_gain[i] * 10); auto it = std::lower_bound(validGains.begin(), @@ -54,10 +54,10 @@ void Kraken::start() for (size_t i = 0; i < channelIndex.size(); i++) { std::cout << "[Kraken] Setting up channel " << i << "." << std::endl; - rtlsdr_dev_t* dev; - status = rtlsdr_open(&dev, i); + + status = rtlsdr_open(&devs[i], i); check_status(status, "Failed to open device."); - devs.push_back(dev); + status = rtlsdr_set_center_freq(devs[i], fc); check_status(status, "Failed to set center frequency."); status = rtlsdr_set_sample_rate(devs[i], fs); @@ -86,11 +86,8 @@ void Kraken::stop() void Kraken::process(IqData *buffer1, IqData *buffer2) { std::vector threads; - for (size_t i = 0; i < channelIndex.size(); i++) - { - threads.emplace_back(rtlsdr_read_async, devs[i], callback, &channelIndex, 0, 16 * 16384); - } - + threads.emplace_back(rtlsdr_read_async, devs[0], callback, buffer1, 0, 16 * 16384); + threads.emplace_back(rtlsdr_read_async, devs[1], callback, buffer2, 0, 16 * 16384); // join threads for (auto& thread : threads) { thread.join(); @@ -99,13 +96,19 @@ void Kraken::process(IqData *buffer1, IqData *buffer2) void Kraken::callback(unsigned char *buf, uint32_t len, void *ctx) { - int deviceIndex = *reinterpret_cast(ctx); - // buffers[i]->lock(); - // for (size_t j = 0; j < n_read; j++) - // { - // buffers[i]->push_back({buffer[j].real(), buffer[j].imag()}); - // } - // buffers[i]->unlock(); + IqData* buffer_blah2 = (IqData*)ctx; + int8_t* buffer_kraken = (int8_t*)buf; + + buffer_blah2->lock(); + + for (size_t i = 0; i < len; i += 2) { + double iqi = static_cast(buffer_kraken[i]); + double iqq = static_cast(buffer_kraken[i + 1]); + + buffer_blah2->push_back({iqi, iqq}); + } + + buffer_blah2->unlock(); } void Kraken::replay(IqData *buffer1, IqData *buffer2, std::string _file, bool _loop) @@ -120,4 +123,3 @@ void Kraken::check_status(int status, std::string message) throw std::runtime_error("[Kraken] " + message); } } - diff --git a/src/capture/kraken/Kraken.h b/src/capture/kraken/Kraken.h index 405dad2..d56570f 100644 --- a/src/capture/kraken/Kraken.h +++ b/src/capture/kraken/Kraken.h @@ -10,7 +10,7 @@ /// The original steve-m/librtlsdr does not include this method. /// This is included in librtlsdr/librtlsdr or krakenrf/librtlsdr. /// Also works using 2 RTL-SDRs which have been clock synchronised. -/// @author 30hours, Michael Brock +/// @author 30hours, Michael Brock, sdn-ninja /// @todo Add support for multiple surveillance channels. /// @todo Replay support. @@ -30,7 +30,7 @@ class Kraken : public Source private: /// @brief Individual RTL-SDR devices. - std::vector devs; + rtlsdr_dev_t* devs[5]; /// @brief Device indices for Kraken. std::vector channelIndex;