mirror of
https://github.com/30hours/blah2.git
synced 2024-11-08 12:25:42 +00:00
Fix file saving for RspDuo/Usrp with ofstream
This commit is contained in:
parent
703560e683
commit
82ec0546b4
6 changed files with 38 additions and 46 deletions
|
@ -15,19 +15,19 @@ process:
|
|||
overlap: 0
|
||||
ambiguity:
|
||||
delayMin: -10
|
||||
delayMax: 300
|
||||
dopplerMin: -300
|
||||
dopplerMax: 300
|
||||
delayMax: 400
|
||||
dopplerMin: -200
|
||||
dopplerMax: 200
|
||||
clutter:
|
||||
delayMin: -10
|
||||
delayMax: 300
|
||||
delayMax: 400
|
||||
detection:
|
||||
pfa: 0.00001
|
||||
nGuard: 10
|
||||
nTrain: 20
|
||||
nGuard: 2
|
||||
nTrain: 6
|
||||
minDelay: 5
|
||||
minDoppler: 15
|
||||
nCentroid: 10
|
||||
nCentroid: 6
|
||||
tracker:
|
||||
initiate:
|
||||
M: 3
|
||||
|
|
|
@ -5,7 +5,7 @@ capture:
|
|||
type: "RspDuo"
|
||||
replay:
|
||||
state: false
|
||||
loop: true
|
||||
loop: true
|
||||
file: '/opt/blah2/replay/file.rspduo'
|
||||
|
||||
process:
|
||||
|
|
|
@ -20,7 +20,6 @@ Source::Source(std::string _type, uint32_t _fc, uint32_t _fs,
|
|||
fs = _fs;
|
||||
path = _path;
|
||||
saveIq = _saveIq;
|
||||
saveIqFile = NULL;
|
||||
}
|
||||
|
||||
std::string Source::open_file()
|
||||
|
@ -39,9 +38,9 @@ std::string Source::open_file()
|
|||
typeLower.begin(), ::tolower);
|
||||
std::string file = path + timestamp + "." + typeLower + ".iq";
|
||||
|
||||
saveIqFile = fopen(file.c_str(), "wb");
|
||||
saveIqFile.open(file, std::ios::binary);
|
||||
|
||||
if (saveIqFile == NULL)
|
||||
if (!saveIqFile.is_open())
|
||||
{
|
||||
std::cerr << "Error: Can not open file: " << file << std::endl;
|
||||
exit(1);
|
||||
|
@ -53,12 +52,12 @@ std::string Source::open_file()
|
|||
|
||||
void Source::close_file()
|
||||
{
|
||||
if (saveIqFile != NULL)
|
||||
if (!saveIqFile.is_open())
|
||||
{
|
||||
fclose(saveIqFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: Can not close file pointer." << std::endl;
|
||||
saveIqFile.close();
|
||||
}
|
||||
|
||||
// switch member with blank file stream
|
||||
std::ofstream blankFile;
|
||||
std::swap(saveIqFile, blankFile);
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <fstream>
|
||||
#include "data/IqData.h"
|
||||
|
||||
class Source
|
||||
|
@ -29,8 +30,8 @@ protected:
|
|||
/// @brief True if IQ data to be saved.
|
||||
bool *saveIq;
|
||||
|
||||
/// @brief File pointer to IQ data to be saved.
|
||||
FILE *saveIqFile;
|
||||
/// @brief File stream to save IQ data.
|
||||
std::ofstream saveIqFile;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
// class static constants
|
||||
|
@ -36,7 +37,7 @@ sdrplay_api_CallbackFnsT cbFns;
|
|||
sdrplay_api_RxChannelParamsT *chParams;
|
||||
|
||||
// global variables
|
||||
FILE *out_file_fp = NULL;
|
||||
//FILE *out_file_fp = NULL;
|
||||
FILE *file_replay = NULL;
|
||||
short *buffer_16_ar = NULL;
|
||||
struct timeval current_tm = {0, 0};
|
||||
|
@ -50,7 +51,8 @@ short max_b_nr = 0;
|
|||
bool run_fg = true;
|
||||
bool stats_fg = true;
|
||||
bool write_fg = true;
|
||||
bool capture_fg = false;
|
||||
bool *capture_fg;
|
||||
std::ofstream* saveIqFileLocal;
|
||||
int wait_time_nr = 2;
|
||||
IqData *buffer1;
|
||||
IqData *buffer2;
|
||||
|
@ -72,8 +74,9 @@ RspDuo::RspDuo(std::string _type, uint32_t _fc, uint32_t _fs,
|
|||
dab_notch_fg = false;
|
||||
chunk_time_nr = DEF_CHUNK_TIME_NR;
|
||||
|
||||
out_file_fp = saveIqFile;
|
||||
capture_fg = &saveIq;
|
||||
//out_file_fp = saveIqFile;
|
||||
capture_fg = saveIq;
|
||||
saveIqFileLocal = &saveIqFile;
|
||||
}
|
||||
|
||||
void RspDuo::start()
|
||||
|
@ -526,29 +529,13 @@ void RspDuo::stream_b_callback(short *xi, short *xq, sdrplay_api_StreamCbParamsT
|
|||
write_fg = true;
|
||||
}
|
||||
|
||||
// init file open
|
||||
// if (capture_fg && write_fg && run_fg && chunk_tm.tv_sec <= current_tm.tv_sec)
|
||||
// {
|
||||
// if (out_file_fp != NULL)
|
||||
// {
|
||||
// fclose(out_file_fp);
|
||||
// }
|
||||
// out_file_fp = fopen(file.c_str(), "ab");
|
||||
// if (out_file_fp == NULL)
|
||||
// {
|
||||
// std::cerr << "Error - stream_b_callback - opening output file " + file << std::endl;
|
||||
// free(buffer_16_ar);
|
||||
// run_fg = false;
|
||||
// exit(1);
|
||||
// }
|
||||
|
||||
// chunk_tm = current_tm;
|
||||
// }
|
||||
|
||||
// write data to file
|
||||
if (capture_fg && write_fg)
|
||||
if (*capture_fg && write_fg)
|
||||
{
|
||||
if (fwrite(buffer_16_ar, sizeof(short), numSamples * 4, out_file_fp) != (size_t)numSamples * 4)
|
||||
saveIqFileLocal->write(reinterpret_cast<char*>(buffer_16_ar),
|
||||
sizeof(short) * numSamples * 4);
|
||||
|
||||
if (!(*saveIqFileLocal))
|
||||
{
|
||||
std::cerr << "Error - stream_b_callback - not enough samples received" << std::endl;
|
||||
free(buffer_16_ar);
|
||||
|
|
|
@ -93,9 +93,14 @@ void Usrp::process(IqData *buffer1, IqData *buffer2)
|
|||
buffer2->unlock();
|
||||
|
||||
// save IQ data to file
|
||||
if (saveIq)
|
||||
if (*saveIq)
|
||||
{
|
||||
|
||||
for (const auto& bufferPtr : buff_ptrs)
|
||||
{
|
||||
// Write the buffer data to the file
|
||||
saveIqFile.write(reinterpret_cast<const char*>(
|
||||
bufferPtr), samps_per_buff * sizeof(std::complex<float>));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue