📄 modulegenerator.cpp
字号:
/*******************************************************************************//* Project: SOFTWARE RADIO - LCM Laboratoire de Communications Mobiles *//* -------------------------------------------------------------------------- *//* Filename: modulegenerator.cpp *//* Description: The modulegenerator's task is to read the filesystem and *//* to create the modules. It puts them into a list belonging *//* to a Mapper object. *//* -------------------------------------------------------------------------- *//* Date: January 09 2003 *//* Version: v1.0 *//* Author: Braure Jerome, Ferreiro Jose *//* Communication Systems (9th semester) - EPFL *//* Changelog: ineiti - 04/03/01 - replaced MODULE_MIN_HEIGHT with modules->height*//*******************************************************************************//*******************************************************************************//* 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. *//*******************************************************************************/#include <qdir.h>#include <qstringlist.h>#include <qstring.h>#include <string>#include <unistd.h>#include <iostream>#include "parameter_types.h"#include "parameters.h"#include "modulegenerator.h"#include "module.h"#include "iolink.h"#include "mapper.h"#include "defines.h"#include "global.h"using namespace std;#define FILE_INPUTS "inputs"#define FILE_NAME "name"#define FILE_OUTPUTS "outputs"#define FILE_STATS "stats"#define FILE_CONFIG "config"#define BASE_NAMES 7const char base_names[BASE_NAMES][32] = { "stfa", "block", "block_mimo", "block_complex", "stfa_complex", "block_4by4_complex", "stfa_ics" };#define FILTER_DIR 1/*******************************************************************************//* Function: ModuleGenerator() - (constuctor) *//* Description: Constructs an instance of class Module. *//* Inputs: mapper: pointer to the Mapper that contains the module vector *//* into which the modulegenerator adds the modules. *//*******************************************************************************/ModuleGenerator::ModuleGenerator( FifoCmd *c, Mapper* m, QCanvas *ca ) : radio( c ), mapper( m ), canvas( ca ){ mapper->stfaChosen=0; if ( mapper == NULL ) return ; if ( getAllModules() ) { mapper->map( canvas ); canvas->update(); } else { exit( 0 ); }}/*******************************************************************************//* Function: readFileSystem() *//* Description: Reads the filesystem, creates the modules and puts them in the *//* mapper's module vector *//* Inputs: none. *//* Returns: false if the given data path doesn't exist or some file could *//* not be found. *//*******************************************************************************/bool ModuleGenerator::getAllModules() { QDir dir; QStringList modList( radio->getModules() ); int nbrOfMod = modList.count(); int stfaNbr = 0; int currentStfa = -1; int currentModule; // for each module, read all information available for ( currentModule = 0; currentModule < nbrOfMod; currentModule++ ) { bool ok = FALSE; QStringList nameNum( QStringList::split( ",", modList[ currentModule ] ) ); QString sCurrentModuleNumber( nameNum[ 0 ] ); QString currentModuleName( nameNum[ 1 ] ); if( ( currentModuleName == base_names[0] ) || ( currentModuleName == base_names[4] ) || ( currentModuleName == base_names[6] ) ){ stfaNbr++; } mapper->stfaNbr=stfaNbr; int iCurrentModuleNumber = sCurrentModuleNumber.toInt( &ok ); if ( !ok ) { cout << "invalid module name " << nameNum[ 0 ] << "," << nameNum[1] << "#" << currentModule << endl; return false; } // Build module Module* module = new Module( radio, canvas, iCurrentModuleNumber ); // Try to find the base module, from which all other modules are calculated. // A bit clumsy if there is no STFA, as block has 1 IN/OUT and block_mimo // 2 IN/OUT (for the moment) int isBaseModule = 0; for ( int base_counter = 0; base_counter < BASE_NAMES; base_counter++ ){ if( !( module->name ).compare( base_names[ base_counter ] ) ){ int len = 1; isBaseModule = 1; currentStfa++; switch ( base_counter ){ case 0: case 4: case 6: // For a real STFA, we can get the slot-number for ( unsigned int i = 0; i < module->statsList.count(); i++ ){ Stats *stats = module->statsList.at(i); if ( stats->getName() == "slots_per_frame" ){ len = stats->value.toInt(); } } break; case 1: // Block is assumed to have 1 IN/OUT len = 1; break; case 2: // Block_Mimo is assumed to have 2 IN/OUTs len = 2; break; case 3: // Block_Complex is assumed to have 2 IN/OUTs len = 2; break; case 5: // Block_4by4_Complex has 4 IN/OUTs len = 4; break; } module->numberIn = len; module->greatestPortUsed = len; module->numberOut = len; module->setThin( true ); } } // add current module to the vector // check if it is the STFA // If there is no STFA, take the last module as STFA if( isBaseModule || ( currentStfa < 0 && currentModule == nbrOfMod - 1 ) ){ if ( currentStfa < 0 ){ cout << "Taking last module as STFA" << endl; currentStfa = 0; } int width = 2 * LEG_LEFT_OFFSET + MAXIMUM(module->numberIn, module->numberOut) * LEG_WIDTH + (MAXIMUM(module->numberIn, module->numberOut) - 1) * STFA_LEG_INTERVAL; int x = CANVAS_WIDTH / 2; module->height = 10; int y = CANVAS_HEIGHT / 2 - module->height / 2; module->setX( x ); module->width = max( width, 100 ); module->setY( y ); module->legInterval = STFA_LEG_INTERVAL; mapper->stfas[currentStfa] = module; } else { mapper->addModule( module ); } } return true;}bool ModuleGenerator::updateModules(){ QStringList modList( radio->getNewModules() ); uint currentModule; // for each module, read all information available for ( currentModule = 0; currentModule < modList.count(); currentModule++ ) { QStringList nameNum( QStringList::split( ",", modList[ currentModule ] ) ); // Build module Module* module = new Module( radio, canvas, nameNum[0].toInt() ); // add current module to the vector mapper->addModule( module ); } return modList.count() > 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -