⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapper_send.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/*************************************************************************** *    mapper.c  - Modulate bits to symbols *                           ------------------- *   begin                :  02/10/30 *   authors              :  Linus Gasser *   emails               :  linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** *                                Changes *                                ------- * date - name - description * 02/10/30 - ineiti - begin * 03/02/12 - ineiti - added symbol-look-up tables for PSK and QAM * 03/05/12 - ineiti - Cleanup the checks on the config and adjust mapper.h *                     so that no symbol has an energy of more than 256 * 04/03/06 - ineiti - adjusted description * **************************************************************************//*************************************************************************** *                                                                         * *   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 mapper-class for demodulator and mapper.  * It supports different PSK and QAM symbols */#include "spc.h"#include "mapper.h"#define DBG_LVL 0typedef struct {  // The amplitude of the symbols  int amplitude; // 32767  // The bits per symbol  int bits_per_symbol; // 2  // Which table to take: 0-PSK   1-QAM  int symbol_type; // 0}config_t;typedef struct {}stats_t;typedef struct {  int bits_per_symbol;  SYMBOL_COMPLEX table[16];}private_t;/* * The initialisation function, or constructor,  * is called the first time this module is instantiated. */int send_init( swr_sdb_t *context ) {  // Begin system-definitions {  config_t *config;  stats_t *stats;  MOD_INC_USE_COUNT;  if ( sizeof( private_t ) > 0 )    context->private_data = swr_malloc( sizeof( private_t ) );  swr_sdb_get_config_struct( context->id, (void**)&config );  swr_sdb_get_stats_struct( context->id, (void**)&stats );  // } End of system-definitions  // Usually we have symbols in the 'coins', that is the total energy =  // sqrt( re^2 + im^2 ) = sqrt( amp^2/2 + amp^2/2 ) = amp  config->amplitude = 32767;  config->bits_per_symbol = 2;  config->symbol_type = 0;  // Begin system-definitions  swr_sdb_free_stats_struct( context->id, (void**)&stats );  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;  // End system-definitions}/* * To configure the inputs * this is called when the output-sizes change. */int send_configure_inputs( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  swr_sdb_get_config_struct( context->id, (void**)&config );  size_in(0) = size_out(0) * private->bits_per_symbol / 8;  PR_DBG( 3, "size_in: %i\n", size_in(0) );  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}/* * To configure the outputs * this is called when the input-sizes change */int send_configure_outputs( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  int size;  swr_sdb_get_config_struct( context->id, (void**)&config );  // Only resize if we have really something more. If not it may  // be some aliasing of the port-sizes.  size = ceil( size_in(0) * 8. / private->bits_per_symbol );  if ( ( size_out(0) - size ) * private->bits_per_symbol / 8 ) {    size_out(0) = size;  }  PR_DBG( 3, "size_out: %i\n", size_out(0) );  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}/* * Every time modules from the outside change the value of a configuration parameter, * this function is called. */int send_reconfig( swr_sdb_t *context ) {  // Definition of variables - don't touch  int i, j;  config_t *config;  swr_sdb_get_config_struct( context->id, (void**)&config );  if ( ( config->bits_per_symbol <= MAX_BITS ) &&       ( config->symbol_type <= 1 ) &&       ( config->bits_per_symbol > 0 ) ) {    private->bits_per_symbol = config->bits_per_symbol;    size_in(0) = floor( size_out(0) * private->bits_per_symbol / 8. );    j = private->bits_per_symbol;    for ( i=0; i<(1<<j); i++ ) {      switch( config->symbol_type ) {      case 0:        private->table[i].real = (short)((int)config->amplitude *                                         Symbols_PSK[j-1][i].real / 256 );        private->table[i].imag = (short)((int)config->amplitude *                                         Symbols_PSK[j-1][i].imag / 256 );        break;      case 1:        private->table[i].real = (short)((int)config->amplitude *                                         Symbols_QAM[j-1][i].real / 256 );        private->table[i].imag = (short)((int)config->amplitude *                                         Symbols_QAM[j-1][i].imag / 256 );        break;      }      PR_DBG( 4, "Symbol %i: (%i,%i)\n", i,              private->table[i].real, private->table[i].imag );    }  }  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}/* * This is function that impements the `main method' of the class * Every calss has got just ONE method/working-mode. */int send_pdata( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  stats_t *stats;  U8 *in;  SYMBOL_COMPLEX *out;  int i, index = 0, j, k;  swr_sdb_get_config_struct( context->id, (void**)&config );  swr_sdb_free_config_struct( context->id, (void**)&config );  in = buffer_in( 0 );  out = buffer_out( 0 );  PR_DBG( 4, "Got buffer-in at %p for %i len\n", in, size_out(0) );  j = private->bits_per_symbol;  k = 0;  for ( i=0; i < size_out(0); i++ ) {    if ( k < private->bits_per_symbol ) {      index += *in << k;      in++;      k += 8;    }    out[i] = private->table[ index & ( ( 1 << j ) - 1 ) ];        if( i<10) {      PR_DBG( 4, "sent: (%5i, %5i)\n", 	      private->table[ index & ( ( 1 << j ) - 1 ) ].real, 	      private->table[ index & ( ( 1 << j ) - 1 ) ].imag );    }    index = index >> j;    k -= private->bits_per_symbol;  }  swr_sdb_get_stats_struct( context->id, (void**)&stats );  swr_sdb_free_stats_struct( context->id, (void**)&stats );  return(0);}/** *  * User messages *   */int send_custom_msg( swr_sdb_t *context, swr_usr_msg_t *data, swr_msgq ret ) {  send_pdata( context );  return 0;}/* * This is the `destructor'. */int send_finalize( swr_sdb_t *context ) {  if ( sizeof( private_t ) > 0 )    swr_free( private );  MOD_DEC_USE_COUNT;  return 0;}/* * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */swr_spc_id_t send_id;int send_module_init(void) {  swr_spc_desc_t *desc;  /**   * Get a description-part from SPM   * Give the following parameters:   * Input-ports, output-ports, config-params, stat-params   */  desc = swr_spc_get_new_desc( 1, 1, 3, 0 );  if ( !desc ) {    PR_DBG( 0, "Can't initialise the module. This is BAD!\n" );    return -1;  }  /**   * Define the different parts of config and stats. You have to define   * them in the same order as they appear in the structures. The names   * can be freely chosen.   *   * UM_CONFIG_{INT,DOUBLE,STRING128}( "name" );   * UM_STATS_{INT,DOUBLE,STRING128}( "name" );   */  UM_CONFIG_INT( "amplitude" );  UM_CONFIG_INT( "bits_per_symbol" );  UM_CONFIG_INT( "symbol_type" );  /**   * The in- and outputs have also to be defined in the right order. First   * port first. The additional flag is not used yet, but it will...   *   * UM_INPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 );   * UM_OUTPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 );   */  UM_INPUT( SIG_U8, 0 );  UM_OUTPUT( SIG_SYMBOL_COMPLEX, 0 );  // Initialise the callback-functions. Delete the ones you don't use  desc->fn_init              = send_init;  desc->fn_reconfigure       = send_reconfig;  desc->fn_process_data      = send_pdata;  desc->fn_custom_msg	     = send_custom_msg;  desc->fn_configure_inputs  = send_configure_inputs;  desc->fn_configure_outputs = send_configure_outputs;  desc->fn_finalize          = send_finalize;  // And register the module in the SPM. Change the name!  send_id = swr_cdb_register_spc( &desc, "mapper" );  if ( send_id == SWR_SPM_INVALID_ID ) {    swr_spc_free_desc( desc );    PR_DBG( 0, "Couldn't register the module!\n" );    return 1;  }  PR_DBG( 4, "Ready\n" );  return 0;}/* * This is called upon rmmod */void send_module_exit( void ) {  PR_DBG( 4, "Freeing id: %i\n", send_id );  if ( swr_cdb_unregister_spc( send_id ) < 0 ) {    PR_DBG( 0, "Still in use somewhere\n" );  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -