NetSim Source Code Help
Loading...
Searching...
No Matches
Building.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2021 *
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#define _NETSIM_MOBILITY_CODE_
25#include "main.h"
26#include "Mobility.h"
27#include "MobilityInterface.h"
28
29typedef struct stru_netsim_office
30{
32 char* name;
33 double X1;
34 double X2;
35 double Y1;
36 double Y2;
38static UINT officeCount = 0;
40
41#define MOBILITY_OFFICE_COUNT_DEFAULT 0
42#define MOBILITY_OFFICE_ID_DEFAULT 0
43#define MOBILITY_OFFICE_NAME_DEFAULT _strdup("Office1")
44#define MOBILITY_OFFICE_X1_DEFAULT 0
45#define MOBILITY_OFFICE_Y1_DEFAULT 0
46#define MOBILITY_OFFICE_X2_DEFAULT 0
47#define MOBILITY_OFFICE_Y2_DEFAULT 0
48
49static void configure_office(void* xmlNode, ptrNETSIM_OFFICE office)
50{
51 getXmlVar(&office->id, ID, xmlNode, 1, _UINT, MOBILITY_OFFICE);
52 getXmlVar(&office->name, NAME, xmlNode, 1, _STRING, MOBILITY_OFFICE);
53 getXmlVar(&office->X1, X1, xmlNode, 1, _DOUBLE, MOBILITY_OFFICE);
54 getXmlVar(&office->X2, X2, xmlNode, 1, _DOUBLE, MOBILITY_OFFICE);
55 getXmlVar(&office->Y1, Y1, xmlNode, 1, _DOUBLE, MOBILITY_OFFICE);
56 getXmlVar(&office->Y2, Y2, xmlNode, 1, _DOUBLE, MOBILITY_OFFICE);
57}
58
59void fn_NetSim_MObility_configureOffice(void* xmlNetSimNode)
60{
61 getXmlVar(&officeCount, OFFICE_COUNT, xmlNetSimNode, 1, _UINT, MOBILITY);
62 if (officeCount)
64 else
65 return;
66
67 UINT i;
68 for (i = 0; i < officeCount; i++)
69 {
70 void* xmlChild = fn_NetSim_xmlGetChildElement(xmlNetSimNode, "OFFICE", i);
71 if (!xmlChild)
72 break;
73
74 officeList[i] = calloc(1, sizeof * officeList[i]);
75 configure_office(xmlChild, officeList[i]);
76 }
77
78}
79
81{
82 if ((pos->X >= officeList[id - 1]->X1 && pos->X <= officeList[id - 1]->X2) &&
83 (pos->Y >= officeList[id - 1]->Y1 && pos->Y <= officeList[id - 1]->Y2))
84 return true;
85 return false;
86}
87
89{
90 UINT i;
91 for (i = 0; i < officeCount; i++)
92 {
93 if (fnMobility_isPosInsideBuilding(pos, i + 1))
94 return i + 1;
95 }
96 return 0;
97}
98
100 UINT id, NetSim_COORDINATES* ret)
101{
102 NetSim_COORDINATES of[4];
103
104 int i;
105 for (i = 0; i < 4; i++)
106 memset(&of[i], 0, sizeof of[i]);
107
108 of[0].X = officeList[id - 1]->X1;
109 of[0].Y = officeList[id - 1]->Y1;
110
111 of[1].X = officeList[id - 1]->X1;
112 of[1].Y = officeList[id - 1]->Y2;
113
114 of[2].X = officeList[id - 1]->X2;
115 of[2].Y = officeList[id - 1]->Y2;
116
117 of[3].X = officeList[id - 1]->X2;
118 of[3].Y = officeList[id - 1]->Y1;
119
120 if (fnMobility_findIntersect(p1, p2, &of[0], &of[1], ret))
121 return true;
122
123 if (fnMobility_findIntersect(p1, p2, &of[1], &of[2], ret))
124 return true;
125
126 if (fnMobility_findIntersect(p1, p2, &of[2], &of[3], ret))
127 return true;
128
129 if (fnMobility_findIntersect(p1, p2, &of[3], &of[0], ret))
130 return true;
131
132 return false;
133}
134
136{
137 UINT id1, id2, id;
138 NetSim_COORDINATES* indoor;
139 NetSim_COORDINATES* outdoor;
140
143
144 if (id1 == 0 && id2 == 0)
145 return 0.0; // Both pos are outdoor
146
147 if (id1 > 0 && id2 > 0)
148 return fn_NetSim_Utilities_CalculateDistance(p1, p2); //Both are indoor
149
150 if (id1 > 0)
151 {
152 indoor = p1;
153 outdoor = p2;
154 id = id1;
155 }
156 else
157 {
158 indoor = p2;
159 outdoor = p1;
160 id = id2;
161 }
162
164 memset(&ret, 0, sizeof ret);
166
167 if (id1 > 0)
169 else
171}
unsigned int NETSIM_ID
Definition: Animation.h:45
static UINT officeCount
Definition: Building.c:38
struct stru_netsim_office NETSIM_OFFICE
bool fnMobility_isPosInsideBuilding(NetSim_COORDINATES *pos, NETSIM_ID id)
Definition: Building.c:80
UINT fnMobility_isPosInsideAnyBuilding(NetSim_COORDINATES *pos)
Definition: Building.c:88
static void configure_office(void *xmlNode, ptrNETSIM_OFFICE office)
Definition: Building.c:49
void fn_NetSim_MObility_configureOffice(void *xmlNetSimNode)
Definition: Building.c:59
double fnMobility_findIndoorDistance(NetSim_COORDINATES *p1, NetSim_COORDINATES *p2)
Definition: Building.c:135
bool fnMobility_findIntersectionPointbyBuilding(NetSim_COORDINATES *p1, NetSim_COORDINATES *p2, UINT id, NetSim_COORDINATES *ret)
Definition: Building.c:99
struct stru_netsim_office * ptrNETSIM_OFFICE
static ptrNETSIM_OFFICE * officeList
Definition: Building.c:39
bool fnMobility_findIntersect(NetSim_COORDINATES *p1, NetSim_COORDINATES *q1, NetSim_COORDINATES *p2, NetSim_COORDINATES *q2, NetSim_COORDINATES *intersect)
Definition: Geometry.c:27
#define UINT
Definition: Linux.h:38
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
#define calloc(c, s)
Definition: Memory.h:29
#define getXmlVar(var, name, xmlNode, flag, type, protocol)
Definition: Stack.h:1046
@ _UINT
Definition: Stack.h:1037
@ _STRING
Definition: Stack.h:1033
@ _DOUBLE
Definition: Stack.h:1031
void * fn_NetSim_xmlGetChildElement(void *xmlNetSimNode, const char *childName, int count)
double fn_NetSim_Utilities_CalculateDistance(NetSim_COORDINATES *coordinate1, NetSim_COORDINATES *coordinates2)