mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2026-04-19 14:52:43 +00:00
Beginning of code for the RSPduo + bugfix for the hackrf
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <dsp/block.h>
|
||||
#include <dsp/buffer.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace dsp {
|
||||
template <class T>
|
||||
@@ -128,4 +129,53 @@ namespace dsp {
|
||||
stream<T>* _in;
|
||||
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class FileSink : public generic_block<FileSink<T>> {
|
||||
public:
|
||||
FileSink() {}
|
||||
|
||||
FileSink(stream<T>* in, std::string path) { init(in, path); }
|
||||
|
||||
~FileSink() {
|
||||
generic_block<FileSink<T>>::stop();
|
||||
if (file.is_open()) { file.close(); }
|
||||
}
|
||||
|
||||
void init(stream<T>* in, std::string path) {
|
||||
_in = in;
|
||||
file = std::ofstream(path, std::ios::binary);
|
||||
generic_block<FileSink<T>>::registerInput(_in);
|
||||
}
|
||||
|
||||
void setInput(stream<T>* in) {
|
||||
std::lock_guard<std::mutex> lck(generic_block<FileSink<T>>::ctrlMtx);
|
||||
generic_block<FileSink<T>>::tempStop();
|
||||
generic_block<FileSink<T>>::unregisterInput(_in);
|
||||
_in = in;
|
||||
generic_block<FileSink<T>>::registerInput(_in);
|
||||
generic_block<FileSink<T>>::tempStart();
|
||||
}
|
||||
|
||||
bool isOpen() {
|
||||
return file.is_open();
|
||||
}
|
||||
|
||||
int run() {
|
||||
int count = _in->read();
|
||||
if (count < 0) { return -1; }
|
||||
|
||||
if (file.is_open()) {
|
||||
file.write((char*)_in->readBuf, count * sizeof(T));
|
||||
}
|
||||
|
||||
_in->flush();
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
stream<T>* _in;
|
||||
std::ofstream file;
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user