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

📄 sch_rcv.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/*************************************************************************** *    sch_rcv.c  -  Receive the System CHannel and act *                           ------------------- *   begin                :  2003-03-19 *   authors              :  ineiti *   emails               :  linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** *                                Changes *                                ------- * date - name - description * 04/03/05 - 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.                                   * *                                                                         * ***************************************************************************//** * This is used for one or more clients to connect to the master-radio. * It uses an id and checks against the structures sent from the master * in order to pick the right configuration for this client. *  If the client radio sets a valid antenna-id, sending and receiving * gain-control will be done. */#include "spc.h"#include "sch.h"#include "std.h"#include "antenna.h"#define DBG_LVL 1typedef struct {  // if valid, the tx/rx gain of this antenna will be updated  int antenna; // -1  // contains the data that has been sent along  void *data_usr; // NULL  // the length of the allocated memory-block  int len_usr; // 0  // has to be set so that the SCh module knows which array to decode  int id; // -1}config_t;typedef struct {  // the desired tx-gain  double gain;  // valid is 1 (OK), 0 (SCh OK, but no ID) or <0 (CRC-error)  int valid;  // a bit-field for the downlinks allocated  int downlinks;  // a bit-field for the uplinks allocated  int uplinks;  // how many bytes are valid in data_usr  int len_usr;  // a possible new id that could be used  int free_id;}stats_t;typedef struct {  struct sch_data_t data;}private_t;/* * The initialisation function, or constructor,  * is called the first time this module is instantiated. */int rcv_init( swr_sdb_t *context ) {  // Begin system-definitions {  config_t *config;  stats_t *stats;  int i;  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->antenna = -1;  config->data_usr = NULL;  config->len_usr = 0;  config->id = -2;  stats->downlinks = 0;  stats->uplinks = 0;  stats->gain = 0.;  stats->len_usr = 0;  stats->free_id = -1;  for ( i=0; i < MAX_CLIENTS; i++ ) {    private->data.client[i].id = -1;  }  // 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}/* * Every time modules from the outside change the value of a configuration parameter, * this function is called. */int rcv_reconfig( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  swr_sdb_get_config_struct( context->id, (void**)&config );  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}/* * This is the function that implements the `main method' of the class * Every class has got just ONE method/working-mode. */int rcv_pdata( swr_sdb_t *context ) {  // Definition of variables - don't touch  stats_t *stats;  config_t *config;  int new_id = 0;  U8 *in;  U32 crc;  int i, size_data = sizeof( struct sch_data_t ),                     len_usr;  // Check for correct size  if ( size_in(0) < size_data ) {    PR_DBG( 0, "Not big enough! %i versus %i\n", size_in(0), size_data);    return -1;  }  in = buffer_in(0);  // Check for the CRC  crc = *((U32*)in);  in += sizeof( U32 );  memcpy( &private->data, in, size_data );  in += size_data;  swr_sdb_get_stats_struct( context->id, (void**)&stats );  swr_sdb_get_config_struct( context->id, (void**)&config );  if ( crc == swr_crc32( (void*)&private->data, size_data ) ) {    // if everything is correct, we can update the stuff    PR_DBG( 4, "System-CRC is OK\n" );    stats->valid = 0;    for ( i=0; i<MAX_CLIENTS; i++ ) {      new_id += abs( private->data.client[i].id );      if ( private->data.client[i].id == config->id ) {        PR_DBG( 4, "Found valid id %i for client %i\n",                config->id, i );        // The id is correct, so we copy the parameters        stats->downlinks = private->data.client[i].downlinks;        stats->uplinks = private->data.client[i].uplinks;        stats->gain = private->data.client[i].gain;        stats->valid = 1;        if ( config->antenna >= 0 ) {          // An antenna is defined, so set the new gain          swr_ant_set_gain_tx( config->antenna, stats->gain );        }      }    }    // Aargh, this is a mess. The user-part has to be taken fully    // into account when it comes to the CRC, but the user may only    // want part of it, so we can't copy the whole user-block to the    // pointer...    crc = *((U32*)in);    in += sizeof( U32 );    stats->len_usr = private->data.len_usr;    len_usr = min( config->len_usr, private->data.len_usr );    if ( crc == swr_crc32( in, stats->len_usr ) ) {      memcpy( config->data_usr, in, len_usr );    }  } else {    stats->valid--;  }  stats->free_id = abs( new_id + 1 );  swr_sdb_free_config_struct( context->id, (void**)&config );  swr_sdb_free_stats_struct( context->id, (void**)&stats );  return(0);}/* * This is the `destructor'. */int rcv_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 rcv_id;int rcv_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, 0, 4, 6 );  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,POINTER}( "name" );   * UM_STATS_{INT,DOUBLE,STRING128,POINTER,BLOCK}( "name" );   */  UM_CONFIG_INT( "antenna" );  UM_CONFIG_POINTER( "data_usr" );  UM_CONFIG_INT( "len_usr" );  UM_CONFIG_INT( "id" );  UM_STATS_DOUBLE( "gain" );  UM_STATS_INT( "valid" );  UM_STATS_INT( "downlinks" );  UM_STATS_INT( "uplinks" );  UM_STATS_INT( "len_usr" );  UM_STATS_INT( "free_id" );  /**   * 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 );  // Initialise the callback-functions. Delete the ones you don't use  desc->fn_init              = rcv_init;  desc->fn_reconfigure       = rcv_reconfig;  desc->fn_process_data      = rcv_pdata;  desc->fn_finalize          = rcv_finalize;  // And register the module in the SPM. Change the name!  rcv_id = swr_cdb_register_spc( &desc, "sch_rcv" );  if ( rcv_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 rcv_module_exit( void ) {  PR_DBG( 4, "Freeing id: %i\n", rcv_id );  if ( swr_cdb_unregister_spc( rcv_id ) < 0 ) {    PR_DBG( 0, "Still in use somewhere\n" );  }}

⌨️ 快捷键说明

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