#include stdio.h
#include windows.h
#include string.h
#include conio.h
#include stdlib.h
#define _DLL
#define MAXSIZE 50
#define MAX_MOBILESTATIONS 8
#define SIGNAL_LENGTH 64
#define INTERFERENCE_PATTERN 1
#define DATA_LENGTH 8
#define CODE_LENGTH 8
int g_nMobileStations; To store the Number of Mobile Stations
int g_aanBinaryDatas[MAX_MOBILESTATIONS][DATA_LENGTH];To store the Binary Values in Integer Format
int g_aanCodeValues[MAX_MOBILESTATIONS][CODE_LENGTH]; To store the Code Values in Integer Format
int g_aanEncodeValues[MAX_MOBILESTATIONS][DATA_LENGTH];To store the Encode Values
int g_aanSignals[MAX_MOBILESTATIONS][SIGNAL_LENGTH];To store the Signal Values
int g_aanInterferencePattern[INTERFERENCE_PATTERN][SIGNAL_LENGTH];To Store the Interference Pattern
int g_aanDecodeValues[MAX_MOBILESTATIONS][DATA_LENGTH];To store the Decode Values
void fnReadInput (char );
void fnEncode();
void fnDecode();
void fnWriteOutput(char );
#ifndef _DLL
int main(int argc, char argv[])
#else
int fn_NetSim_Prog_CDMA(char pszAppPath,char pszIOPath)
#endif
{
char szInputPath; To Store the Values from Input.txt
char szOutputPath; To store the Values to Output.txt
Allocation of Memory to store the contents from Input.txt
szInputPath = (char)calloc(sizeof(char), 800);
Copy the Application Path
#ifndef _DLL
strcpy(szInputPath, argv[2]);
#else
strcpy(szInputPath, pszIOPath);
#endif
Concatenate the Values from Input.txt
strcat(szInputPath, Input.txt);
Allocation of Memory to store the contents from Output.txt
szOutputPath = (char)calloc(sizeof(char), 800);
Copy the Application Path
#ifndef _DLL
strcpy(szOutputPath, argv[2]);
strcat(szOutputPath, Output.txt);
#else
strcpy(szOutputPath,pszIOPath);
strcat(szOutputPath, Temp.txt);
#endif
To Get the Values from Input.txt
fnReadInput(szInputPath);
To Find the Values of Encode, Signal, Interference Pattern
fnEncode();
To find the Decode Values and original Data that have been sent by the transmitters
fnDecode();
To write the Values into Output.txt
fnWriteOutput(szOutputPath);
free (szInputPath);
free (szOutputPath);
return 0;
}
void fnReadInput(char szInputPath)
{
FILE fpInput = NULL;
char szToken = NULL; To Tokenize the Values from Input.txt
char szString = NULL;
int nLoop1, nLoop2, nLoop3, nLoop4;
int nCount = 0;
char szBinaryValues[MAXSIZE];
char szCodes[MAXSIZE];
fpInput = fopen(szInputPath, r);
Allocation of Memory
szString = (char ) malloc(100 sizeof(char));
fgets(szString, 100, fpInput);
Separate the Value of Number of Mobile Stations
szToken = strtok(szString, =);
if ( szToken != NULL )
{
szToken = strtok ( NULL, );
Store the Value of the Mobile Stations
g_nMobileStations = atoi(szToken);
}
fgets(szString, 100, fpInput);
while (nCount g_nMobileStations)
{
strtok(szString, =);
strtok(NULL, );
strtok(NULL, =);
szBinaryValues[nCount] = (char)malloc(sizeof(char) MAXSIZE);
strcpy(szBinaryValues[nCount], strtok(NULL, ));
strtok(NULL, =);
szCodes[nCount] = (char)malloc(sizeof(char) MAXSIZE);
strcpy (szCodes[nCount], strtok(NULL, ));
fgets(szString, 100, fpInput);
nCount++;
}
free(szString);
This Loop is used to change the Binary Values from character
data type to Integer data Type
for (nLoop1 = 0, nLoop3 = 0; nLoop1 g_nMobileStations; nLoop1++, nLoop3++)
{
for (nLoop2 = 0, nLoop4 = 0; nLoop2 DATA_LENGTH; nLoop2++, nLoop4++)
g_aanBinaryDatas[nLoop3][nLoop4] = szBinaryValues[nLoop1][nLoop2];
free(szBinaryValues[nLoop1]);
}
for (nLoop3 = 0; nLoop3 g_nMobileStations; nLoop3++)
{
for (nLoop4 = 0; nLoop4 DATA_LENGTH; nLoop4++)
{
if (g_aanBinaryDatas[nLoop3][nLoop4] == 48)
g_aanBinaryDatas[nLoop3][nLoop4] = 0;
else
g_aanBinaryDatas[nLoop3][nLoop4] = 1;
}
}
This Loop is used to change the Code Values from character data type
to Integer Type
for (nLoop1 = 0, nLoop3 = 0; nLoop1 g_nMobileStations; nLoop1++, nLoop3++)
{
for (nLoop2 = 0, nLoop4 = 0; nLoop2 (strlen(szCodes[nLoop1])); nLoop2++)
{
if (szCodes[nLoop1][nLoop2] == '-')
{
g_aanCodeValues[nLoop3][nLoop4] = -1;
nLoop2 += 2;
nLoop4++;
}
if (szCodes[nLoop1][nLoop2] == '1')
{
g_aanCodeValues[nLoop3][nLoop4] = 1;
nLoop4++;
}
}
free (szCodes[nLoop1]);
}
fclose(fpInput);
}
void fnEncode()
{
int nLoop1, nLoop2, nLoop3, nLoop4;
int nRLoop, nCLoop;
int nRow = 1;
This Loop is used to find out the Encode Values of Each Mobile Station
for (nLoop1 = 0; nLoop1 g_nMobileStations; nLoop1++)
{
for (nLoop2 = 0; nLoop2 DATA_LENGTH; nLoop2++)
g_aanEncodeValues[nLoop1][nLoop2] = 2 g_aanBinaryDatas[nLoop1][nLoop2] - 1;
}
This Loop is used to find out the Signal Values of each Mobile Station
for ( nLoop1 = 0, nLoop3 = 0, nRLoop = 0; nLoop1 g_nMobileStations; nLoop1++, nLoop3++, nRLoop++ )
{
for ( nLoop2 = 0, nLoop4 = 0, nCLoop = 0; nLoop4 DATA_LENGTH; nLoop2++ )
{
g_aanSignals[nLoop1][nLoop2] = g_aanEncodeValues[nLoop3][nLoop4] g_aanCodeValues[nRLoop][nCLoop];
nCLoop++;
if (nCLoop == CODE_LENGTH)
{
nLoop4++;
nCLoop = 0;
}
}
}
This Loop is used to find out the Interference Pattern
for ( nRow = 0, nLoop1 = 0, nLoop2 = 0, nLoop3 = 0; nLoop1 SIGNAL_LENGTH; nLoop1++, nLoop3++)
{
g_aanInterferencePattern[nRow][nLoop1] = 0;
while (nLoop2 g_nMobileStations)
{
g_aanInterferencePattern[nRow][nLoop1] += g_aanSignals[nLoop2][nLoop3];
nLoop2++;
}
if (nLoop2 == g_nMobileStations)
nLoop2 = 0;
}
}
void fnDecode()
{
int nLoop1, nLoop2, nLoop3;
int nRLoop, nCLoop;
int nRow;
This Loop is used to find out the Decode Values of each Mobile Station
for ( nRow = 0, nLoop1 = 0, nLoop2 = 0, nRLoop = 0; nLoop1 g_nMobileStations; nLoop1++, nRLoop++ )
{
g_aanDecodeValues[nLoop1][nLoop2] = 0;
for ( nLoop3 = 0, nCLoop = 0; nLoop3 SIGNAL_LENGTH; nLoop3++)
{
g_aanDecodeValues[nLoop1][nLoop2] += g_aanInterferencePattern[nRow][nLoop3] g_aanCodeValues[nRLoop][nCLoop];
nCLoop++;
if ( nCLoop == CODE_LENGTH )
{
nCLoop = 0;
nLoop2++;
g_aanDecodeValues[nLoop1][nLoop2] = 0;
if (nLoop2 == DATA_LENGTH)
nLoop2 = 0;
}
}
}
This Loop is used to get the Original Data from Decode Values
for ( nLoop1 = 0; nLoop1 g_nMobileStations; nLoop1++ )
{
for ( nLoop2 = 0; nLoop2 DATA_LENGTH; nLoop2++ )
{
if ( g_aanDecodeValues[nLoop1][nLoop2] 0 )
g_aanBinaryDatas[nLoop1][nLoop2] = 1;
else
g_aanBinaryDatas[nLoop1][nLoop2] = 0;
}
}
}
void fnWriteOutput(char szOutputPath)
{
FILE fpOutput;
int nLoop1, nLoop2;
fpOutput = fopen(szOutputPath, w);
fprintf(fpOutput, NumberofMobileStations=%dn, g_nMobileStations);
for ( nLoop1 = 0; nLoop1 g_nMobileStations; nLoop1++ )
{
fprintf ( fpOutput, MobileStation=%d, nLoop1 + 1);
Print the Binary Values for each Mobile Station
fprintf(fpOutput, Data=);
for(nLoop2 = 0; nLoop2 DATA_LENGTH; nLoop2++)
fprintf(fpOutput, %d , g_aanBinaryDatas[nLoop1][nLoop2]);
fprintf(fpOutput, );
Print the Code Values of each Mobile Station
fprintf (fpOutput, Code=);
for(nLoop2 = 0; nLoop2 CODE_LENGTH; nLoop2++ )
fprintf(fpOutput, %d , g_aanCodeValues[nLoop1][nLoop2]);
fprintf(fpOutput, );
Print the Encode Values of each Mobile Station
fprintf(fpOutput, Encode=);
for (nLoop2 = 0; nLoop2 DATA_LENGTH; nLoop2++)
fprintf(fpOutput, %d , g_aanEncodeValues[nLoop1][nLoop2]);
fprintf(fpOutput, );
Print the Signal Values of each Mobile Staion
fprintf( fpOutput, Signal=);
for(nLoop2 = 0; nLoop2 SIGNAL_LENGTH; nLoop2++ )
fprintf(fpOutput, %d , g_aanSignals[nLoop1][nLoop2]);
fprintf(fpOutput, n);
}
Print the Interf
cdma.rar_cdma
版权申诉
153 浏览量
2022-09-20
21:35:24
上传
评论
收藏 2KB RAR 举报
JonSco
- 粉丝: 77
- 资源: 1万+