📄 allocation.c
字号:
#include <stdio.h>#include "allocation.h"extern dlfusc_setcarriers(char cs[], int slotnum, int idcell) ;extern dlpusc_setcarriers(char cs[], int slotnum, int idcell) ;int debug=0 ;#define DEF_SLOTS 2/********************************************************************** * General instructions: * All functions are passed the list of channels cs and they enter the * allocations for each sub-channel in this list. Sub-channels are mark * 0-9a-zA-Z. Other markings are * _ : unallocated * # : DC carrier * @ : constant pilot (for FUSC), pilot for other allocations * % : variable pilot (for FUSC) * ^ : guard bands * *******************************************************************/int main(int argc, char ** argv){ int symnum = DEF_SLOTS; int idcell=0; int alloc = PUSC ; int i; user_t U = { 0, 12.3 } ; char cs[OFDMA_NC] ; int dir = DLINK; int status;#define USAGE "--sym=<num symbol> --cell=<idcell> --alloc=(FUSC|PUSC|AMC|fusc|pusc|amc) --dir=(UP|DOWN)" for (i=1; i<argc; i++) { char *nextarg; nextarg=argv[i] ; if (strncmp(nextarg,"--help",6)==0) { printf("%s: %s\n",argv[0], USAGE) ; exit(1) ; } if (strncmp(nextarg,"--sym=",6)==0) { nextarg += 6; symnum = atoi(nextarg) ; } else if (strncmp(nextarg,"--dir=",6)==0) { nextarg += 6; if (strncmp(nextarg,"UP",2) == 0) dir = ULINK; else dir = DLINK ; } else if (strncmp(nextarg,"--cell=",7)==0) { nextarg += 7; idcell = atoi(nextarg) ; } else if (strncmp(nextarg, "--alloc=",8) == 0) { nextarg += 8 ; if ((strncmp(nextarg,"FUSC",4)==0) || (strncmp(nextarg,"fusc",4) == 0)) alloc=FUSC ; if ((strncmp(nextarg,"PUSC",4)==0) || (strncmp(nextarg,"pusc",4) == 0)) alloc=PUSC ; if ((strncmp(nextarg,"AMC",3)==0) || (strncmp(nextarg,"amc",3) == 0)) alloc=AMC ; } } init_allocation(cs,OFDMA_NC) ; status=0 ; switch(alloc) { case FUSC: { if (dir == DLINK) status = dlfusc_setcarriers(cs,symnum,idcell) ; else printf("This is an invalid combination, uplink with fusc\n") ; break ; } case PUSC: { if (dir == DLINK) status = dlpusc_setcarriers(cs,symnum,idcell) ;// else status = ulpusc_setcarriers(cs,symnum,idcell) ; break ; } case AMC: { if (dir == DLINK) status = dlamc_setcarriers(cs,symnum,idcell) ;// else status = ulamc_setcarriers(cs,symnum,idcell) ; break ; } default: { printf("This allocation %d is not supported\n", alloc) ; exit(1) ; } } if (status) print_allocation(cs,OFDMA_NC) ; return 0 ;}int init_allocation(char *cs, int num){ int j; for (j=0; j<num; j++) cs[j] = UNALLOC_MARK ; cs[1024] = DC_MARK ; return j;}/********************************************************************** * Function: Print the allocation on the screen, using runlength coding * to compress the output. Pilots are shown with C,V for FUSC and P with * PUSC. Guard bands are shown with G. Subchannels in FUSC/PUSC are shown * with a-z0-9. Thus, only 36 subchannels can be shown. * ********************************************************************/int print_allocation(char *cs, int num, int marker){ int j, type=cs[0],cnt=0 ; int cpilot, vpilot, unalloc, guard; int newtype; cpilot = vpilot = unalloc = guard = 0 ; for (j=0; j<num; j++) { switch(cs[j]) { case PILOT_MARK: cpilot++ ; break ; case VARPILOT_MARK: vpilot++ ; break ; case UNALLOC_MARK: unalloc++ ; break ; case GUARD_MARK: guard++ ; break ; default: break ; } newtype = cs[j] ; if (cs[j] == type) { cnt++ ; continue ; } else { if (cnt > 1) printf("%c(%d)",type,cnt) ; else { printf("%c",type) ; } type = cs[j] ; cnt = 0 ; } } if (cnt > 1) printf("%c(%d)",type,cnt) ; else { printf("%c",type) ; } printf("\n #constpilots=%d, varpilots=%d, unalloc=%d, guard=%d\n", cpilot, vpilot, unalloc, guard) ; return type;}/********************************************************************** * Function: Assign sub-carriers to sub-channels. * Description: This is a common function for the entire downlink, it * is reused for the PUSC. * Parameters: * - sub-channel number * - total number of sub-channels * - total number of sub-carriers per sub-channel * - permutation base * - size of permuation base * - idcell * Returns: * - list of allocated sub-carriers for this sub-channel * *********************************************************************/int dl_subchannel_assign( int scn, int tscn, int tscr, int * alloc_scr, int * perm_base, int perm_base_sz, int idcell){ int j; if (debug==1) printf("#scn=%d tscn=%d tscr=%d\n",scn,tscn,tscr) ; for (j=0; j<tscr; j++) { int x1,x2,x3; int n_k = (j+13*scn)%tscr ; alloc_scr[j] = n_k*tscn ; x1 = n_k % tscn ; x2 = x1 - scn ; while (x2 < 0) x2 += perm_base_sz ; while (x2 > perm_base_sz) x2 -= perm_base_sz ; x3 = perm_base[x2] + idcell ; x3 %= tscn ; alloc_scr[j] += x3 ; if (alloc_scr[j] > 1536 || debug==1) printf("#n_k=%d, x1=%d, x2=%d, x3=%d, j=%d val=%d\n",n_k,x1,x2,x3,j, alloc_scr[j]) ; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -