NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
MatlabLossModel.c
1/************************************************************************************
2* Copyright (C) 2023 *
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* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi kant suman *
22* ----------------------------------------------------------------------------------*/
23
24#include "main.h"
25#include "stdafx.h"
26#include "LTENR_PHY.h"
27#include "LTENR_PropagationModel.h"
28#include "MobilityInterface.h"
29#include "NetSim_utility.h"
30
31#define LTENR_MATLAB_MODEL_DEFAULT _strdup("NONE")
32
33//Rain
34#define MATLAB_LOSS_RAIN_RAINRATE_DEFAULT 16
35#define MATLAB_LOSS_RAIN_TILTANGLE_DEFAULT 0
36#define MATLAB_LOSS_RAIN_ELEVATIONANGLE_DEFAULT 0
37#define MATLAB_LOSS_RAIN_EXCEEDANCEPERCENTAGEOFRAINFALL_DEFAULT 0
38
39//Fog
40#define MATLAB_LOSS_FOG_TEMPERATURE_DEFAULT 15
41#define MATLAB_LOSS_FOG_WATERDENSITY_DEFAULT 7.5
42
43//GAS
44#define MATLAB_LOSS_GAS_TEMPERATURE_DEFAULT 15
45#define MATLAB_LOSS_GAS_WATERDENSITY_DEFAULT 7.5
46#define MATLAB_LOSS_GAS_AIRPRESSURE_DEFAULT 10300
47
48void netsim_matlab_configure_loss_model(ptrLTENR_PROPAGATIONCONFIG config, void* xmlNetSimNode)
49{
50 char* szVal;
51 getXmlVar(&szVal, MATLAB_MODEL, xmlNetSimNode, 1, _STRING, LTENR);
52 config->matlabLossModel = LTENR_ConvertStrToEnum(MATLAB_LOSSMODEL, szVal);
53 free(szVal);
54
55 switch(config->matlabLossModel)
56 {
57 case MATLAB_LOSSMODEL_NONE:
58 //No configuration reqd
59 break;
60 case MATLAB_LOSSMODEL_RAIN:
61 getXmlVar(&config->rainRate, RAINRATE, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_RAIN);
62 getXmlVar(&config->tiltAngle, TILTANGLE, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_RAIN);
63 getXmlVar(&config->elevationAngle, ELEVATIONANGLE, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_RAIN);
64 getXmlVar(&config->exceedancePercentageOfRainfall, EXCEEDANCEPERCENTAGEOFRAINFALL, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_RAIN);
65 break;
66 case MATLAB_LOSSMODEL_FOG:
67 getXmlVar(&config->temperature, TEMPERATURE, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_FOG);
68 getXmlVar(&config->waterDensity, WATERDENSITY, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_FOG);
69 break;
70 case MATLAB_LOSSMODEL_GAS:
71 getXmlVar(&config->temperature, TEMPERATURE, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_GAS);
72 getXmlVar(&config->airPressure, AIRPRESSURE, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_GAS);
73 getXmlVar(&config->waterDensity, WATERDENSITY, xmlNetSimNode, 1, _DOUBLE, MATLAB_LOSS_GAS);
74 break;
75 default:
76 fnNetSimError("Unknown MATLAB loss model - %s\n", strMATLAB_LOSSMODEL[config->matlabLossModel]);
77 break;
78 }
79}
80
81static double netsim_matlab_get_fspl(ptrLTENR_PROPAGATIONINFO info)
82{
83 netsim_matlab_send_ascii_command("pathloss=netsim_matlab_free_space_pathloss(%lf,%lf,%lf,%lf,%lf,%lf,%lf)",
84 info->centralFrequency_MHz * MHZ,
85 info->gnbPos.X, info->gnbPos.Y, info->gnbPos.Z,
86 info->uePos.X, info->uePos.Y, info->uePos.Z);
87 char s[BUFSIZ];
88 netsim_matlab_get_value(s, BUFSIZ, "pathloss", "double");
89 return atof(s);
90}
91
92static double netsim_matlab_get_rainLoss(ptrLTENR_PROPAGATIONINFO info)
93{
94 netsim_matlab_send_ascii_command("loss=rainpl(%lf,%lf,%lf,%lf,%lf,%lf)",
95 info->dist3D,
96 info->centralFrequency_MHz * MHZ,
97 info->propagationConfig->rainRate,
98 info->propagationConfig->elevationAngle,
99 info->propagationConfig->tiltAngle,
100 info->propagationConfig->exceedancePercentageOfRainfall);
101 char s[BUFSIZ];
102 netsim_matlab_get_value(s, BUFSIZ, "loss", "double");
103 return atof(s);
104}
105
106static double netsim_matlab_get_gasLoss(ptrLTENR_PROPAGATIONINFO info)
107{
108 if (info->centralFrequency_MHz * MHZ < 1 * GHZ)
109 {
110 fnNetSimError("MATLAB GAS loss model is only avaiable for frequency above than 1GHz\n");
111 return 0;
112 }
113
114 netsim_matlab_send_ascii_command("loss=gaspl(%lf,%lf,%lf,%lf,%lf)",
115 info->dist3D,
116 info->centralFrequency_MHz * MHZ,
117 info->propagationConfig->temperature,
118 info->propagationConfig->airPressure,
119 info->propagationConfig->waterDensity);
120 char s[BUFSIZ];
121 netsim_matlab_get_value(s, BUFSIZ, "loss", "double");
122 return atof(s);
123}
124
125static double netsim_matlab_get_fogLoss(ptrLTENR_PROPAGATIONINFO info)
126{
127 if (info->centralFrequency_MHz * MHZ < 10 * GHZ)
128 {
129 fnNetSimError("MATLAB Fog loss model is only avaiable for frequency above than 10GHz\n");
130 return 0;
131 }
132
133 netsim_matlab_send_ascii_command("loss=fogpl(%lf,%lf,%lf,%lf)",
134 info->dist3D,
135 info->centralFrequency_MHz * MHZ,
136 info->propagationConfig->temperature,
137 info->propagationConfig->waterDensity);
138 char s[BUFSIZ];
139 netsim_matlab_get_value(s, BUFSIZ, "loss", "double");
140 return atof(s);
141}
142
143double netsim_matlab_calculate_loss(ptrLTENR_PROPAGATIONINFO info)
144{
145 switch (info->propagationConfig->matlabLossModel)
146 {
147 case MATLAB_LOSSMODEL_NONE:
148 return 0;
149 case MATLAB_LOSSMODEL_RAIN:
150 return netsim_matlab_get_rainLoss(info);
151 case MATLAB_LOSSMODEL_FOG:
152 return netsim_matlab_get_fogLoss(info);
153 case MATLAB_LOSSMODEL_GAS:
154 return netsim_matlab_get_gasLoss(info);
155 default:
156 fnNetSimError("Unknown MATLAB loss model - %s\n", strMATLAB_LOSSMODEL[info->propagationConfig->matlabLossModel]);
157 break;
158 }
159 return 0;
160}
MATLAB_LOSSMODEL matlabLossModel
In Case of Matlab model.