NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Component 11/Satellite/Satellite.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 "NetSim_utility.h"
26#include "SATELLITE.h"
27#include "Satellite_MAC.h"
28#include "Satellite_PHY.h"
29
30#include "AdvancedPlots.h"
31#pragma comment(lib,"AdvancedPlots.lib")
32
33//Function prototype
34static void satellite_ut_init(NETSIM_ID d, NETSIM_ID in);
35static void satellite_gw_init(NETSIM_ID d, NETSIM_ID in);
36static void satellite_init(NETSIM_ID d, NETSIM_ID in);
37static void satellite_handle_timer();
38void init_satellite_log();
39void close_satellite_log();
40
41_declspec(dllexport) int fn_NetSim_SATELLITE_Init()
42{
43 init_linkpacketlog();
44 init_satellite_log();
45 Satellite_RadioMeasurements_Init();
46 NETSIM_ID i;
47 NETSIM_ID j;
48 for (i = 0; i < NETWORK->nDeviceCount; i++)
49 {
50 for (j = 0; j < DEVICE(i + 1)->nNumOfInterface; j++)
51 {
52 if (!isSatelliteInterface(i + 1, j + 1))
53 continue;
54
55 switch (SATELLITE_DEVICETYPE_GET(i + 1, j + 1))
56 {
57 case SATELLITE_DEVICETYPE_SATELLITE:
58 satellite_init(i + 1, j + 1);
59 break;
60 case SATELLITE_DEVICETYPE_SATELLITE_GATEWAY:
61 satellite_gw_init(i + 1, j + 1);
62 break;
63 case SATELLITE_DEVICETYPE_USER_TERMINAL:
64 satellite_ut_init(i + 1, j + 1);
65 break;
66 default:
67 fnNetSimError("Unknown device type in function %s\n", __FUNCTION__);
68 break;
69 }
70 }
71 }
72 return 0;
73}
74
75_declspec(dllexport) int fn_NetSim_SATELLITE_Run()
76{
77 switch (pstruEventDetails->nEventType)
78 {
79 case MAC_OUT_EVENT:
80 satellite_handle_mac_out();
81 break;
82 case MAC_IN_EVENT:
83 satellite_handle_mac_in();
84 break;
85 case PHYSICAL_OUT_EVENT:
86 satellite_handle_phy_out();
87 break;
88 case PHYSICAL_IN_EVENT:
89 satellite_handle_phy_in();
90 break;
91 case TIMER_EVENT:
92 satellite_handle_timer();
93 break;
94 default:
95 fnNetSimError("Unknown event type %d in function %s\n",
96 pstruEventDetails->nEventType, __FUNCTION__);
97 break;
98 }
99 return 0;
100}
101
102_declspec(dllexport) char* fn_NetSim_SATELLITE_Trace(NETSIM_ID id)
103{
104 UINT i = id % (MAC_PROTOCOL_SATELLITE * 100);
105 return (char*)strSATELLITE_SUBEVENT[i];
106}
107
108_declspec(dllexport) int fn_NetSim_SATELLITE_FreePacket(NetSim_PACKET* packet)
109{
110 packet;
111 return 0;
112}
113
114_declspec(dllexport) int fn_NetSim_SATELLITE_CopyPacket(NetSim_PACKET* destPacket, const NetSim_PACKET* srcPacket)
115{
116 destPacket;
117 srcPacket;
118 return 0;
119}
120
121_declspec(dllexport) int fn_NetSim_SATELLITE_Metrics(PMETRICSWRITER file)
122{
123 file;
124 return 0;
125}
126
127_declspec(dllexport) int fn_NetSim_SATELLITE_Configure(void** var)
128{
129 fn_NetSim_SATELLITE_Configure_F(var);
130 return 0;
131}
132
133_declspec(dllexport) char* fn_NetSim_SATELLITE_ConfigPacketTrace(void* xmlNetSimNode)
134{
135 xmlNetSimNode;
136 return "";
137}
138
139_declspec(dllexport) int fn_NetSim_SATELLITE_Finish()
140{
141 close_satellite_log();
142 LinkPacketLog_close();
143 Satellite_RadioMeasurements_Finish();
144 return 0;
145}
146
147_declspec(dllexport) int fn_NetSim_SATELLITE_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace)
148{
149 pstruPacket;
150 ppszTrace;
151 return 0;
152}
153
154static void satellite_ut_init(NETSIM_ID d, NETSIM_ID in)
155{
156 satellite_UT_MAC_init(d, in);
157 satellite_ut_phy_init(d, in);
158}
159
160static void satellite_gw_init(NETSIM_ID d, NETSIM_ID in)
161{
162 satellite_GW_MAC_init(d, in);
163 satellite_gw_phy_init(d, in);
164}
165
166static void satellite_init(NETSIM_ID d, NETSIM_ID in)
167{
168 satellite_mac_init(d, in);
169}
170
171static void satellite_handle_timer()
172{
173 switch (pstruEventDetails->nSubEventType)
174 {
175 case SUBEVENT_SUPERFRAME_START:
176 satellite_superframe_start();
177 break;
178 case SUBEVENT_FRAME_START:
179 satellite_frame_start();
180 break;
181 default:
182 fnNetSimError("Unknown subevnet %d in function %s\n",
183 pstruEventDetails->nSubEventType, __FUNCTION__);
184 break;
185 }
186}
187
188bool get_protocol_log_status(char* logname)
189{
190 FILE* fp;
191 char str[BUFSIZ];
192 char data[BUFSIZ];
193
194 sprintf(str, "%s/%s", pszIOPath, "ProtocolLogsConfig.txt");
195 fp = fopen(str, "r");
196 if (!fp)
197 return false;
198
199 sprintf(str, "%s=true", logname);
200
201 while (fgets(data, BUFSIZ, fp))
202 {
203 lskip(data);
204 if (!_strnicmp(data, str, strlen(str)))
205 {
206 fclose(fp);
207 return true;
208 }
209 }
210 fclose(fp);
211
212 return false;
213}