Allow non-blocking stdin for leandvbtx real-time mode.

master
pabr 2018-03-27 12:29:37 +02:00
rodzic 2e8fe2cb18
commit fe8771b8ec
3 zmienionych plików z 31 dodań i 0 usunięć

Wyświetl plik

@ -1,4 +1,8 @@
HEAD HEAD
* leandvbtx: Added real-time mode (-fill).
* leansdrserv: Network access to leansdr command pipelines.
* leaniio{rx,tx}: PlutoSDR support via libiio.
* leanmlmrx: Multi-channel FM demodulator.
* leandvb: Spectrum output, JSON syntax. * leandvb: Spectrum output, JSON syntax.
* leandvb, leandvbtx: DVB-S with non-standard constellations (with --viterbi). * leandvb, leandvbtx: DVB-S with non-standard constellations (with --viterbi).
* leandvb: Support all DVB-S code rates with --viterbi. * leandvb: Support all DVB-S code rates with --viterbi.

Wyświetl plik

@ -50,12 +50,14 @@ struct config {
float rolloff; float rolloff;
float rrc_rej; float rrc_rej;
enum { OUTPUT_F32, OUTPUT_S16 } output_format; enum { OUTPUT_F32, OUTPUT_S16 } output_format;
bool fill;
bool verbose, debug; bool verbose, debug;
config() config()
: constellation(cstln_lut<256>::QPSK), fec(FEC12), : constellation(cstln_lut<256>::QPSK), fec(FEC12),
amp(1.0), agc(false), amp(1.0), agc(false),
interp(2), decim(1), rolloff(0.35), rrc_rej(10), interp(2), decim(1), rolloff(0.35), rrc_rej(10),
output_format(OUTPUT_F32), output_format(OUTPUT_F32),
fill(false),
verbose(false), debug(false) verbose(false), debug(false)
{ } { }
}; };
@ -167,6 +169,14 @@ void run(config &cfg) {
fail("Output format not implemented"); fail("Output format not implemented");
} }
if ( cfg.fill ) {
if ( cfg.verbose ) fprintf(stderr, "Realtime mode\n");
tspacket blank;
memset(blank.data, 0, 188);
blank.data[0] = 0x47;
r_stdin.set_realtime(blank);
}
sch.run(); sch.run();
sch.shutdown(); sch.shutdown();
if ( sch.verbose ) sch.dump(); if ( sch.verbose ) sch.dump();
@ -192,6 +202,7 @@ void usage(const char *name, FILE *f, int c, const char *info=NULL) {
" --agc Better regulation of output power\n" " --agc Better regulation of output power\n"
" --f32 Output 32-bit floats, range +-1.0 (default)\n" " --f32 Output 32-bit floats, range +-1.0 (default)\n"
" --s16 Output 16-bit ints\n" " --s16 Output 16-bit ints\n"
" --fill Insert blank packets\n"
" -v Output debugging info at startup and exit\n" " -v Output debugging info at startup and exit\n"
" -d Output debugging info during operation\n" " -d Output debugging info during operation\n"
" --version Display version and exit\n" " --version Display version and exit\n"
@ -272,6 +283,8 @@ int main(int argc, char *argv[]) {
cfg.output_format = config::OUTPUT_F32; cfg.output_format = config::OUTPUT_F32;
else if ( ! strcmp(argv[i], "--s16") ) else if ( ! strcmp(argv[i], "--s16") )
cfg.output_format = config::OUTPUT_S16; cfg.output_format = config::OUTPUT_S16;
else if ( ! strcmp(argv[i], "--fill") )
cfg.fill = true;
else else
usage(argv[0], stderr, 1, argv[i]); usage(argv[0], stderr, 1, argv[i]);
} }

Wyświetl plik

@ -3,6 +3,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "leansdr/math.h" #include "leansdr/math.h"
@ -20,6 +22,7 @@ struct file_reader : runnable {
file_reader(scheduler *sch, int _fdin, pipebuf<T> &_out) file_reader(scheduler *sch, int _fdin, pipebuf<T> &_out)
: runnable(sch, _out.name), : runnable(sch, _out.name),
loop(false), loop(false),
filler(NULL),
fdin(_fdin), out(_out) fdin(_fdin), out(_out)
{ {
} }
@ -29,6 +32,11 @@ struct file_reader : runnable {
again: again:
ssize_t nr = read(fdin, out.wr(), size); ssize_t nr = read(fdin, out.wr(), size);
if ( nr<0 && errno==EWOULDBLOCK && filler ) {
if ( sch->debug ) fprintf(stderr, "U");
out.write(*filler);
return;
}
if ( nr < 0 ) fatal("read"); if ( nr < 0 ) fatal("read");
if ( ! nr ) { if ( ! nr ) {
if ( ! loop ) return; if ( ! loop ) return;
@ -52,7 +60,13 @@ struct file_reader : runnable {
out.written(nr / sizeof(T)); out.written(nr / sizeof(T));
} }
bool loop; bool loop;
void set_realtime(T &_filler) {
int flags = fcntl(fdin, F_GETFL);
if ( fcntl(fdin, F_SETFL, flags|O_NONBLOCK) ) fatal("fcntl");
filler = new T(_filler);
}
private: private:
T *filler;
int fdin; int fdin;
pipewriter<T> out; pipewriter<T> out;
}; };