k_berctr.cpp
上传用户:jtjnyq9001
上传日期:2014-11-21
资源大小:3974k
文件大小:3k
源码类别:

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = k_berctr.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <fstream>
  6. #include "parmfile.h"
  7. #include "k_berctr.h"
  8. #include "typedefs.h"
  9. #include "model_graph.h"
  10. #include "syst_graph.h"
  11. extern ParmFile *ParmInput;
  12. extern ofstream *DebugFile;
  13. extern SystemGraph CommSystemGraph;
  14. extern int PassNumber;
  15. extern int MaxPassNumber;
  16. //======================================================
  17. // constructor - parms read from ParmFile
  18. k_BerCounter::k_BerCounter( char* instance_name )
  19. {
  20.   Instance_Name = new char[strlen(instance_name)];
  21.   strcpy(Instance_Name, instance_name);
  22.   OPEN_PARM_BLOCK;
  23.   GET_INT_PARM(Num_Holdoff_Passes);
  24.   GET_INT_PARM(Report_Intvl_In_Blocks);
  25.   Bit_Count = 0;
  26.   Bit_0_Count = 0;
  27.   Bit_1_Count = 0;
  28.   Error_Count = 0;
  29.   Error_0_Count = 0;
  30.   Error_1_Count = 0;
  31. }
  32. //==============================================
  33. k_BerCounter::k_BerCounter( char* instance_name,
  34.                             int num_holdoff_passes,
  35.                             int report_intvl_in_blocks)
  36. {
  37.   Instance_Name = new char[strlen(instance_name)];
  38.   strcpy(Instance_Name, instance_name);
  39.   Num_Holdoff_Passes = num_holdoff_passes;
  40.   Report_Intvl_In_Blocks = report_intvl_in_blocks;
  41.   Bit_Count = 0;
  42.   Bit_0_Count = 0;
  43.   Bit_1_Count = 0;
  44.   Error_Count = 0;
  45.   Error_0_Count = 0;
  46.   Error_1_Count = 0;
  47. }
  48. //==============================================
  49. k_BerCounter::~k_BerCounter( void ){ };
  50. //==============================================
  51. void k_BerCounter::Initialize(void)
  52. {
  53. };
  54. //==============================================
  55. int k_BerCounter::Execute( bit_t *in_sig_ptr,
  56.                             bit_t *ref_sig_ptr,
  57.                             int block_size )
  58. {
  59.   bit_t bit_val, ref_val;
  60.   int bit_count, error_count;
  61.   int bit_0_count, bit_1_count;
  62.   int error_0_count, error_1_count;
  63.   bit_t *symbs_in;
  64.   bit_t *symbs_ref;
  65.   int is;
  66.   if(PassNumber <= Num_Holdoff_Passes ) return(_MES_AOK);
  67.   symbs_in = in_sig_ptr;
  68.   symbs_ref = ref_sig_ptr;
  69.   bit_count = Bit_Count;
  70.   bit_0_count = Bit_0_Count;
  71.   bit_1_count = Bit_1_Count;
  72.   error_count = Error_Count;
  73.   error_0_count = Error_0_Count;
  74.   error_1_count = Error_1_Count;
  75.   bool error_found = false;
  76.   for (is=0; is < block_size; is++)
  77.     {
  78.     bit_val = *symbs_in++;
  79.     ref_val = *symbs_ref++;
  80.     bit_count++;
  81.     if(ref_val == 0)
  82.       bit_0_count++;
  83.     else
  84.       bit_1_count++;
  85.     if(bit_val != ref_val) 
  86.       {
  87.       error_found = true;
  88.       error_count++;
  89.       if(ref_val == 0)
  90.         error_0_count++;
  91.       else
  92.         error_1_count++;
  93.       }
  94.     }
  95. //  if(PassNumber == MaxPassNumber)
  96.   if( ((PassNumber - Num_Holdoff_Passes) % Report_Intvl_In_Blocks) == 0)
  97.     {
  98.     BasicResults << Instance_Name << ": "
  99.               << PassNumber << "  BER = " << (float(error_count)/float(bit_count)) << " -- "
  100.               << error_count << " errors in " << bit_count << " bits" << endl;
  101.     BasicResults << "space errors = " << error_0_count
  102.                  << "   mark errors = " << error_1_count << endl;
  103.     }
  104.   Bit_Count = bit_count;
  105.   Bit_0_Count = bit_0_count;
  106.   Bit_1_Count = bit_1_count;
  107.   Error_Count = error_count;
  108.   Error_0_Count = error_0_count;
  109.   Error_1_Count = error_1_count;
  110.   return(_MES_AOK);
  111. }