24#define _NETSIM_MOBILITY_CODE_
27#include "MobilityInterface.h"
37}NETSIM_OFFICE, * ptrNETSIM_OFFICE;
38static UINT officeCount = 0;
39static ptrNETSIM_OFFICE* officeList;
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
49static void configure_office(
void* xmlNode, ptrNETSIM_OFFICE office)
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);
59void fn_NetSim_MObility_configureOffice(
void* xmlNetSimNode)
61 getXmlVar(&officeCount, OFFICE_COUNT, xmlNetSimNode, 1, _UINT, MOBILITY);
63 officeList = calloc(officeCount,
sizeof * officeList);
68 for (i = 0; i < officeCount; i++)
70 void* xmlChild = fn_NetSim_xmlGetChildElement(xmlNetSimNode,
"OFFICE", i);
74 officeList[i] = calloc(1,
sizeof * officeList[i]);
75 configure_office(xmlChild, officeList[i]);
80_declspec(dllexport)
bool fnMobility_isPosInsideBuilding(NetSim_COORDINATES* pos, NETSIM_ID
id)
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))
88_declspec(dllexport) UINT fnMobility_isPosInsideAnyBuilding(NetSim_COORDINATES* pos)
91 for (i = 0; i < officeCount; i++)
93 if (fnMobility_isPosInsideBuilding(pos, i + 1))
99_declspec(dllexport)
bool fnMobility_findIntersectionPointbyBuilding(NetSim_COORDINATES* p1, NetSim_COORDINATES* p2,
100 UINT
id, NetSim_COORDINATES* ret)
102 NetSim_COORDINATES of[4];
105 for (i = 0; i < 4; i++)
106 memset(&of[i], 0,
sizeof of[i]);
108 of[0].X = officeList[
id - 1]->X1;
109 of[0].Y = officeList[
id - 1]->Y1;
111 of[1].X = officeList[
id - 1]->X1;
112 of[1].Y = officeList[
id - 1]->Y2;
114 of[2].X = officeList[
id - 1]->X2;
115 of[2].Y = officeList[
id - 1]->Y2;
117 of[3].X = officeList[
id - 1]->X2;
118 of[3].Y = officeList[
id - 1]->Y1;
120 if (fnMobility_findIntersect(p1, p2, &of[0], &of[1], ret))
123 if (fnMobility_findIntersect(p1, p2, &of[1], &of[2], ret))
126 if (fnMobility_findIntersect(p1, p2, &of[2], &of[3], ret))
129 if (fnMobility_findIntersect(p1, p2, &of[3], &of[0], ret))
135_declspec(dllexport)
double fnMobility_findIndoorDistance(NetSim_COORDINATES* p1, NetSim_COORDINATES* p2)
138 NetSim_COORDINATES* indoor;
139 NetSim_COORDINATES* outdoor;
141 id1 = fnMobility_isPosInsideAnyBuilding(p1);
142 id2 = fnMobility_isPosInsideAnyBuilding(p2);
144 if (id1 == 0 && id2 == 0)
147 if (id1 > 0 && id2 > 0)
148 return fn_NetSim_Utilities_CalculateDistance(p1, p2);
163 NetSim_COORDINATES ret;
164 memset(&ret, 0,
sizeof ret);
165 fnMobility_findIntersectionPointbyBuilding(p1, p2,
id, &ret);
168 return fn_NetSim_Utilities_CalculateDistance(p1, &ret);
170 return fn_NetSim_Utilities_CalculateDistance(p2, &ret);