📄 midamble_send.c
字号:
/*************************************************************************** * send.c - Software Radio midamble * ------------------- * begin : 02/10/24 * authors : Linus Gasser * emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** * Changes * ------- * date - name - description * 02/10/24 - ineiti - begin * 03/01/23 - ineiti - cut 100 symbols at beginning and end * 03/03/13 - ineiti - cut is not needed anymore * 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 3GPP midamble is implemented with a length of 256 symbols. It is * inserted in the middle of the received signal, so that it should reflect * most accuratly the changes from the channel. */#include "spc.h"#include "midamble.h"#define DBG_LVL 0typedef struct { // Type of the midamble. The following indexes are available: // 1 - 3GPP type 1 (192+64 = 256) // 2 - User Def (512+32 = 544) // 3 - Midamble defined in Chinese WCDMA 128+16 = 144 int type; // 3 // The index of the user. Different users can send in the same // timeslot using different indexes. int index; // 0 // Amplitude of the midamble int amplitude; // 32767}config_t;typedef struct {}stats_t;typedef struct {}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 config->type = 3; config->index = 0; config->amplitude = 32767; // Begin system-definitions swr_sdb_free_config_struct( context->id, (void**)&config ); swr_sdb_free_stats_struct( context->id, (void**)&stats ); 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 ); port_in(0).size = port_out(0).size - midamble_get_length( config->type ); // 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; swr_sdb_get_config_struct( context->id, (void**)&config ); port_out(0).size = port_in(0).size + midamble_get_length( config->type ); // 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 config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); if ( ( config->type >= NUM_MIDAMBLE_DEF ) || ( config->type < 1 ) ) { PR_DBG( 0, "Midamble-type %i not available, only 1..%i are valuable types.\n", config->type, NUM_MIDAMBLE_DEF - 1 ); config->type = NUM_MIDAMBLE_DEF - 1; } if ( config->index >= midamble_get_nbr_channels( config->type ) ) { PR_DBG( 0, "No midamble-index %i for midamble-type %i.\n", config->index, config->type ); config->index = midamble_get_nbr_channels( config->type ) - 1; } if ( ( config->amplitude > 32767 ) || ( config->amplitude < 0 ) ) { PR_DBG( 0, "Amplitude out of range...\n" ); config->amplitude = 32767; } // 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; SYMBOL_COMPLEX *in, *out, *mid; //void *t; int type, index, amp; int i, j; //Selva - Counter in = buffer_in(0); out = buffer_out(0); swr_sdb_get_config_struct( context->id, (void**)&config ); type = config->type; index = config->index; amp = config->amplitude; swr_sdb_free_config_struct( context->id, (void**)&config ); // Copy the first half of the data memcpy( out, in, port_in(0).size / 2 * sizeof( SYMBOL_COMPLEX ) ); // Copy the second half of the data memcpy( out + port_out(0).size - port_in(0).size / 2, in + port_in(0).size / 2, port_in(0).size / 2 * sizeof( SYMBOL_COMPLEX ) ); mid = out + port_in(0).size / 2; midamble_write( type, mid, amp, index ); //-------------------------------------------------------------// /* Added by Selvan*/ /* Picks the midamble from the stream for display */ /* Midamble to be used in MIMO */ PR_DBG( 4, "Midamble-length: %i\n", midamble_get_length(type)); for (i = 0; i < midamble_get_length(type) / 8; i++) { for ( j=0; j<8; j++ ) { PR_DBG_CL( 4, "%i,%i,", mid[ 8 * i + j ].real, mid[ 8 * i + j ].imag ); } PR_DBG_CL( 4, "\n" ); } swr_sdb_get_stats_struct( context->id, (void**)&stats ); swr_sdb_free_stats_struct( context->id, (void**)&stats ); return 0;}/* * This is the `destructor'. */int send_finalize( swr_sdb_t *context ) { if ( sizeof( private_t ) > 0 ) { swr_free( context->private_data ); } 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( "type", PARAMETER_DEBUG ); UM_CONFIG_INT( "index" ); UM_CONFIG_INT( "amplitude" ); /** * 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_SYMBOL_COMPLEX, 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_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, "midamble" ); 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 + -