NetSim Source Code Help
Loading...
Searching...
No Matches
UWAN.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "UWAN.h"
16#include "ErrorModel.h"
17
18/**
19UWAN Init function initializes the UWAN parameters.
20*/
22{
23 // return fn_NetSim_UWAN_Init_F();
24 return 0;
25}
26
27/**
28This function is called by NetworkStack.dll, whenever the event gets triggered
29inside the NetworkStack.dll for the UWAN protocol
30*/
32{
33 return 0;
34}
35
36/**
37This function is called by NetworkStack.dll, once simulation end to free the
38allocated memory for the network.
39*/
41{
42 // return fn_NetSim_UWAN_Finish_F();
43 return 0;
44}
45
46/**
47This function is called by NetworkStack.dll, while writing the event trace
48to get the sub event as a string.
49*/
50_declspec (dllexport) char* fn_NetSim_UWAN_Trace(NETSIM_ID nSubEvent)
51{
52 nSubEvent;
53 return "";
54}
55
56/**
57This function is called by NetworkStack.dll, while configuring the device
58for UWAN protocol.
59*/
60_declspec(dllexport) int fn_NetSim_UWAN_Configure(void** var)
61{
62 var;
63 // return fn_NetSim_UWAN_Configure_F(var);
64 return 0;
65}
66
67/**
68This function is called by NetworkStack.dll, to free the UWAN protocol data.
69*/
71{
72 pstruPacket;
73 // return fn_NetSim_UWAN_FreePacket_F(pstruPacket);
74 return 0;
75}
76
77/**
78This function is called by NetworkStack.dll, to copy the UWAN protocol
79details from source packet to destination.
80*/
81_declspec(dllexport) int fn_NetSim_UWAN_CopyPacket(NetSim_PACKET* pstruDestPacket, NetSim_PACKET* pstruSrcPacket)
82{
83 pstruSrcPacket;
84 pstruDestPacket;
85 // return fn_NetSim_UWAN_CopyPacket_F(pstruDestPacket, pstruSrcPacket);
86 return 0;
87}
88
89/**
90This function write the Metrics
91*/
92_declspec(dllexport) int fn_NetSim_UWAN_Metrics(PMETRICSWRITER metricsWriter)
93{
94 metricsWriter;
95 return 0;
96}
97
98/**
99This function will return the string to write packet trace heading.
100*/
102{
103 return "";
104}
105
106/**
107This function will return the string to write packet trace.
108*/
109_declspec(dllexport) char* fn_NetSim_UWAN_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace)
110{
111 pstruPacket;
112 ppszTrace;
113 return "";
114}
115
116
118 NETSIM_ID txi,
119 NETSIM_ID rx,
120 NETSIM_ID rxi,
122{
123 rxi;
124 NetSim_LINKS* link = DEVICE_PHYLAYER(tx, txi)->pstruNetSimLinks;
126 {
128 }
130 {
131 if (!info)
132 {
133 fnNetSimError("Propagation handle is passed as NULL in function %s\n",
134 __FUNCTION__);
135 return 0.0;
136 }
138 }
139 else
140 {
141 fnNetSimError("Unknown propagation medium for link %d\n",
142 link->nConfigLinkId);
143 return 0.0;
144 }
145}
146
148{
149 switch (modulation)
150 {
151 case Modulation_8_QAM:
152 return 8.0;
154 return 16.0;
156 return 32.0;
158 return 64.0;
160 return 128.0;
162 return 256.0;
163 default:
164 fnNetSimError("Unknown modulation technique %s.\n",
165 strPHY_MODULATION[modulation]);
166 return 0.0;
167 }
168}
169
171 NETSIM_ID tx,
172 NETSIM_ID rx)
173{
177}
178
179static double UWAN_CalculateSNR(double power,
180 double noise)
181{
182 return power - noise;
183}
185 NETSIM_ID rx,
187 double rxPower,
188 PHY_MODULATION modulation,
189 double dataRate /* In kbps */,
190 double bandwidth /* In kHz */)
191{
192 if (modulation <= Modulation_Zero ||
193 modulation >= Modulation_LAST)
194 {
195 fnNetSimError("Unknown modulation %d.\n", modulation);
196 return 0.0;
197 }
198
199 NetSim_LINKS* link = DEVICE_PHYLAYER(tx, 1)->pstruNetSimLinks;
201 {
202 return calculate_BER(modulation,
203 rxPower, NEGATIVE_DBM,
204 bandwidth/1000);
205 }
206
207 double noise = UWAN_CalculateNoise(info, tx, rx);
208 double snr = UWAN_CalculateSNR(rxPower, noise);
209 double EbNo = pow(10.0, snr / 10.0);
210 double BER = 1.0;
211
212 switch (modulation)
213 {
214 case Modulation_BPSK:
215 BER = 0.5 * erfc(sqrt(EbNo));
216 break;
217 case Modulation_QPSK:
218 BER = 0.5 * erfc(sqrt(0.5 * EbNo));
219 break;
225 {
226 // taken from Ronell B. Sicat, "Bit Error Probability Computations for M-ary Quadrature Amplitude Modulation",
227 // EE 242 Digital Communications and Codings, 2009
228 // generic EbNo
229 EbNo *= (dataRate * 1000) / (bandwidth * 1000);
230
231 double M = UWAN_getConstellationSize(modulation);
232
233 // standard squared quantized QAM, even number of bits per symbol supported
234 int log2sqrtM = (int)log2(sqrt(M));
235
236 double log2M = log2(M);
237
238 if ((int)log2M % 2)
239 {
240 fnNetSimError("constellation %d is not supported for QAM.", (int)M);
241 return 0.0;
242 }
243
244 double sqrtM = sqrt(M);
245
246 BER = 0.0;
247
248 // Eq (75)
249 for (int k = 0; k < log2sqrtM; k++)
250 {
251 int sum_items = (int)((1.0 - pow(2.0, (-1.0) * (double)k)) * sqrt(M) - 1.0);
252 double pow2k = pow(2.0, (double)k - 1.0);
253
254 double PbK = 0;
255
256 // Eq (74)
257 for (int j = 0; j < sum_items; ++j)
258 {
259 PbK += pow(-1.0, floor((double)j * pow2k / sqrtM))
260 * (pow2k - floor((double)(j * pow2k / sqrtM) - 0.5))
261 * erfc((2.0 * (double)j + 1.0) * sqrt(3.0 * (log2M * EbNo) / (2.0 * (M - 1.0))));
262
263 }
264 PbK *= 1.0 / sqrtM;
265
266 BER += PbK;
267 }
268
269 BER *= 1.0 / (double)log2sqrtM;
270 }
271 break;
272 case Modulation_FSK:
273 BER = 0.5 * erfc(sqrt(0.5 * EbNo));
274 break;
275 default:
276 fnNetSimError("Modulation %s is not supported.",
277 strPHY_MODULATION[modulation]);
278 break;
279 }
280 return BER;
281}
unsigned int NETSIM_ID
Definition: Animation.h:45
double calculate_BER(PHY_MODULATION modulation, double dReceivedPower_dBm, double dInterferencePower_dBm, double dBandwidth_MHz)
struct stru_ber BER
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
#define fnNetSimError(x,...)
Definition: Linux.h:56
void * PMETRICSWRITER
Definition: MetricsWriter.h:27
double propagation_acoutics_calculate_noise(double frequency_kHz, double shipping, double windSpeed)
double propagation_acoutics_calculate_propagationDelay(NETSIM_ID tx, NETSIM_ID rx, PPROPAGATION propagation)
double propagation_air_calculate_propagationDelay(NETSIM_ID tx, NETSIM_ID rx, PPROPAGATION propagation)
#define NEGATIVE_DBM
@ PROPMEDIUM_ACOUSTICS
@ PROPMEDIUM_AIR
#define DEVICE_PHYLAYER(DeviceId, InterfaceId)
Definition: Stack.h:788
int fn_NetSim_UWAN_Init()
Definition: UWAN.c:21
int fn_NetSim_UWAN_CopyPacket(NetSim_PACKET *pstruDestPacket, NetSim_PACKET *pstruSrcPacket)
Definition: UWAN.c:81
int fn_NetSim_UWAN_Finish()
Definition: UWAN.c:40
double UWAN_Calculate_ber(NETSIM_ID tx, NETSIM_ID rx, PPROPAGATION_INFO info, double rxPower, PHY_MODULATION modulation, double dataRate, double bandwidth)
Definition: UWAN.c:184
int fn_NetSim_UWAN_Run()
Definition: UWAN.c:31
static double UWAN_CalculateSNR(double power, double noise)
Definition: UWAN.c:179
double UWAN_calculate_propagation_delay(NETSIM_ID tx, NETSIM_ID txi, NETSIM_ID rx, NETSIM_ID rxi, PPROPAGATION_INFO info)
Definition: UWAN.c:117
static double UWAN_getConstellationSize(PHY_MODULATION modulation)
Definition: UWAN.c:147
int fn_NetSim_UWAN_Configure(void **var)
Definition: UWAN.c:60
static double UWAN_CalculateNoise(PPROPAGATION_INFO info, NETSIM_ID tx, NETSIM_ID rx)
Definition: UWAN.c:170
int fn_NetSim_UWAN_FreePacket(NetSim_PACKET *pstruPacket)
Definition: UWAN.c:70
int fn_NetSim_UWAN_Metrics(PMETRICSWRITER metricsWriter)
Definition: UWAN.c:92
char * fn_NetSim_UWAN_ConfigPacketTrace()
Definition: UWAN.c:101
char * fn_NetSim_UWAN_Trace(NETSIM_ID nSubEvent)
Definition: UWAN.c:50
char * fn_NetSim_UWAN_WritePacketTrace(NetSim_PACKET *pstruPacket, char **ppszTrace)
Definition: UWAN.c:109
static const char * strPHY_MODULATION[]
Definition: Wireless.h:50
enum enum_Modulation PHY_MODULATION
@ Modulation_LAST
Definition: Wireless.h:48
@ Modulation_Zero
Definition: Wireless.h:30
@ Modulation_BPSK
Definition: Wireless.h:35
@ Modulation_64_QAM
Definition: Wireless.h:40
@ Modulation_QPSK
Definition: Wireless.h:36
@ Modulation_FSK
Definition: Wireless.h:44
@ Modulation_8_QAM
Definition: Wireless.h:37
@ Modulation_32_QAM
Definition: Wireless.h:39
@ Modulation_128_QAM
Definition: Wireless.h:41
@ Modulation_16_QAM
Definition: Wireless.h:38
@ Modulation_256_QAM
Definition: Wireless.h:42
ptrACOUTICSPROPVAR acouticsPropVar
double dCentralFrequency