📄 dbg.cpp
字号:
/*************************************************************************** dbg.cpp - Simple command-line frontend for DBG-interface ------------------- begin : 2005 authors : Linus Gasser emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description 05/01/07 - ineiti- begin 05/01/12 - ineiti - add some status information on stderr **************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************//** * A simple call just prints the available modules, a call with * the module number the stats, a call with the module number * and the stats prints a matlab-file */#include <iostream>#include <qfile.h>#include <math.h>#include "parameter_types.h"#include "swr_types.h"#include "fifocmd.h"using namespace std;FifoCmd *f;int typeSize( int t ) { switch ( t ) { case SIG_U8: return 1; case SIG_SYMBOL_S16: return 2; case SIG_SYMBOL_COMPLEX: return 4; case SIG_SYMBOL_COMPLEX_S32: return 8; case SIG_QUAD_SYMBOL_ICS_AD: return 8 * 4 * 2; case SIG_SYMBOL_MMX: return 8; case SIG_SAMPLE_S12: return 2; case SIG_S32: return 4; case SIG_DOUBLE: return sizeof( double ); case SIG_DOUBLE_COMPLEX: return sizeof( double_complex ); default: return -1; }}int getNumOfSamples( int size, int sig_type ){ switch ( sig_type ){ case SIG_QUAD_SYMBOL_ICS_AD: // There are 4 samples in one QUAD_SYMBOL_ICS_AD return size / typeSize( sig_type ) * 4; default: return size / typeSize( sig_type ); }}void getSample( int sig_type, void *data, uint i, double &re, double &im ){ switch ( sig_type ) { case SIG_U8: im = ( double ) ( ( U8* ) data ) [ i ]; break; case SIG_SYMBOL_S16: im = ( double ) ( ( SYMBOL_S16* ) data ) [ i ]; break; case SIG_DOUBLE: im = ( ( double* ) data ) [ i ]; break; case SIG_DOUBLE_COMPLEX: re = ( ( double_complex* ) data ) [ i ].real; im = ( ( double_complex* ) data ) [ i ].imag; break; case SIG_SYMBOL_COMPLEX: re = ( double ) ( ( SYMBOL_COMPLEX* ) data ) [ i ].real; im = ( double ) ( ( SYMBOL_COMPLEX* ) data ) [ i ].imag; break; case SIG_SYMBOL_COMPLEX_S32: re = ( double ) ( ( SYMBOL_COMPLEX_S32* ) data ) [ i ].real; im = ( double ) ( ( SYMBOL_COMPLEX_S32* ) data ) [ i ].imag; break; case SIG_QUAD_SYMBOL_ICS_AD: // To get the even channel, set this to 1.#define CHANNEL_EVEN 0 // The QUAD_SYMBOL_ICS_AD has 4 samples of the odd channel, then // 4 of the even, and so on. The following formula gives: // 0 1 2 3 8 9 10 11 16 17 18 19 // for CHANNEL_EVEN = 0, which corresponds to the odd samples of the // ICS-554-AD converters... i += i - ( i % 4 ) + CHANNEL_EVEN * 4; re = ( double ) ( ( SYMBOL_COMPLEX_S32* ) data ) [ i ].real; im = ( double ) ( ( SYMBOL_COMPLEX_S32* ) data ) [ i ].imag; break; case SIG_SYMBOL_MMX: re = ( double ) ( ( SYMBOL_MMX* ) data ) [ i ].w[ 0 ]; im = ( double ) ( ( SYMBOL_MMX* ) data ) [ i ].w[ 1 ]; break; case SIG_SAMPLE_S12: im = ( double ) ( ( SAMPLE_S12* ) data ) [ i ]; break; case SIG_S32: im = ( double ) ( ( S32* ) data ) [ i ]; break; default: im = 0; }}void print_modules( ){ QStringList modules = f->getModules(); cout << modules.join( "\n" ) << endl;}void print_stats_blocks( int module ){ QStringList stats = f->getStats( module ); for ( uint i=0; i<stats.count(); i++ ){ QStringList params = QStringList::split( ",", stats[i] ); if ( params[1].toInt() == BLOCK ){ cout << i << ": " << stats[i] << endl; } }}#define BLOCK_SIZE 65536void print_block( int module, int stat ){ QStringList stats = f->getStats( module ); QStringList params = QStringList::split( ",", stats[stat] ); int type_stats = params[1].toInt(); int type_sig = params[3].toInt(); if ( type_stats != BLOCK ){ cout << "Module " << module << ", stat " << stat << " isn't a block...\n"; } else { // Reading in block, but not everything at the same time... f->sendCmd( QString( "get_block %1,%2" ).arg( module ).arg( stat ) ); uint len = f->getReplyLen(), pos; cout << getNumOfSamples( len, type_sig ) << "\n"; for ( pos=0; pos<len; pos+=BLOCK_SIZE ){ cerr << "Working position " << pos << " of " << len << " (" << int( floor( ((double)pos)/len*100.) )<<"%)\r"; QByteArray data = f->getReplyBlock( len, BLOCK_SIZE ); uint samples = getNumOfSamples( data.size(), type_sig ); double re, im; for ( uint i=0; i<samples; i++ ){ getSample( type_sig, data.data(), i, re, im ); cout << re << "\t" << im << "\n"; } } cerr << "Working position " << pos << " of " << len << " (" << int( floor( ((double)pos)/len*100.) )<<"%)\n"; }}int main( int argc, char *argv[] ) { QFile rt_fifo( "/dev/rtf0" ); if ( rt_fifo.open( IO_WriteOnly ) ) { rt_fifo.close(); f = new FifoCmd(); } else { cerr << "Hmm, I think we're not running in real-time mode... stopping\n"; return 1; } switch ( argc ){ case 1: cerr << "Printing all available modules:" << endl; print_modules( ); break; case 2: cerr << "Searching for stats that are blocks:" << endl; print_stats_blocks( QString( argv[1] ).toInt() ); break; case 3: cerr << "Printing block of data" << endl; print_block( QString( argv[1] ).toInt(), QString( argv[2] ).toInt() ); } cout << endl; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -