00001 
00002 
00003 #ifndef _MUX_H_
00004 #define _MUX_H_
00005 
00006 #include "al_sending.h"
00007 #include "al_receiving.h"
00008 #include "channel.h"
00009 #include "mux.h"
00010 #include "med.h"
00011 #include "bch.h"
00012 
00013 
00014 
00015 
00016 #define MUX_TABLE_SIZE  16
00017 
00018 #define DEF_MUX_HEADER 1
00019 #define DEF_MUX_SYNC_FLAG 32
00020 #define DEF_MUX_SYNC_THRESH 28
00021 
00022 #define DEF_MUX_LEVEL 1
00023 
00024 
00025 #define DEF_PAYLOAD_MIN 1
00026 #define DEF_PAYLOAD_MAX 128
00027 
00028 #define DEF_HEADER_CODE BCH15_5
00029 #define DEF_USE_MPL 0
00030 #define DEF_MPL_CODE BCH15_11
00031 
00032 #define DEF_INFO_FIELD_LENGTH  128    
00033 
00034 
00035 #define NO_INTERLEAVING   0 
00036 #define BIT_INTERLEAVING  1
00037 #define BYTE_INTERLEAVING 2
00038 
00039 #define DEF_HEADER_MC_LENGTH    4
00040 #define DEF_HEADER_CRC_LENGTH   3
00041 
00042 #define MAX_AL_SENDERS 10
00043 #define MAX_AL_RECEIVERS 10
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 typedef struct {
00052   
00053 
00054 
00055   int sync_flag_length;    
00056 
00057   int use_double_flag;     
00058 
00059   int sync_threshold;      
00060 
00061   int mpl_sync_threshold;  
00062   bch_type header_code;
00063 
00064   int use_mpl;
00065   bch_type mpl_code;
00066 
00067   int payload_min;
00068   int payload_max;
00069 
00070   int info_field_length;                         
00071 
00072   
00073 
00074  
00075   mux_table_entry mux_table[MUX_TABLE_SIZE];         
00076   int mux_table_size;                 
00077 
00078   float **mt_ratios;                  
00079 
00080 
00081   int **mt_bytes;                     
00082 
00083 
00084   char stat_file[MAX_FILENAME_LENGTH];  
00085 
00086   int level;                          
00087   
00088   int mpl_t;                          
00089   int head_t;                         
00090 } mux_parameters;
00091 
00092 
00093 typedef struct {
00094   char name[41];        
00095 
00096   
00097   mux_parameters *params;
00098 
00099   
00100 
00101 
00102 
00103   al_sending_entity *al_senders[MAX_AL_SENDERS]; 
00104 
00105   int num_al_senders;
00106 
00107   channel *output;                       
00108 
00109   int wait_time;                    
00110 
00111   int packetsSent;                  
00112 } mux;
00113 
00114 
00115 
00116 
00117 mux_parameters *new_mux_parameters(char *name);
00118 
00119 
00120 
00121 
00122 mux *new_mux(char *name);
00123 
00124 
00125 
00126 
00127 static int bytes_ok(int mt_bytes[], int buffer_bytes[], int d, mux *m);
00128      
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 float ratio_difference(float a[], float b[], int d);
00141      
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 static void print_int(int x);
00151 
00152 
00153 
00154 
00155 static void set_payload_size(mux *m);
00156 
00157 
00158 
00159 
00160 void multiplex(mux *m, int num_channels);
00161 
00162 
00163 
00164 
00165 
00166 
00167 void close_mux(mux *m);
00168 
00169 
00170 
00171 
00172 #endif