NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
MobilityLogs.c
1/************************************************************************************
2* Copyright (C) 2022 *
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: Yugank Goyal *
22* *
23* ----------------------------------------------------------------------------------*/
24
25#include "main.h"
26#include "Mobility.h"
27#include "Animation.h"
28
29static FILE* Mobilitylog = NULL;
30
31UINT DEVICE_ID_LIST[] = { 0 };//When { 0 } log is written for all ZigBee Devices. Specific ZigBee Device ID's can be defined
32//for example {1,2,3} log will be written only for ZigBee Device ID's 1, 2 and 3 as transmitter/receiver
33
34static bool validate_log(NETSIM_ID nDevID)
35{
36 int count = sizeof(DEVICE_ID_LIST) / sizeof(int);
37 if (count == 1 && DEVICE_ID_LIST[0] == 0) return true;
38 else
39 {
40 for (int i = 0; i < count; i++)
41 {
42 if (DEVICE_ID_LIST[i] == DEVICE_CONFIGID(nDevID))
43 return true;
44 }
45 }
46 return false;
47}
48
49void init_mobility_log()
50{
51 if (get_protocol_log_status("MOBILITY_LOG"))
52 {
53 char s[BUFSIZ];
54 sprintf(s, "%s\\%s", pszIOLogPath, "Mobility_log.csv");
55 Mobilitylog = fopen(s, "w");
56 if (!Mobilitylog)
57 {
58 fnSystemError("Unable to open %s file", s);
59 perror(s);
60 }
61 else
62 {
63 fprintf(Mobilitylog, "%s,%s,%s,%s,%s,%s,",
64 "Time(ms)", "Device Name", "Device Id", "Position X(m)", "Position Y(m)", "Position Z(m)");
65
66 }
67 fprintf(Mobilitylog, "\n");
68 if (nDbgFlag) fflush(Mobilitylog);
69 }
70}
71
72void close_mobility_logs()
73{
74 if (Mobilitylog)
75 fclose(Mobilitylog);
76}
77void log_mobility(MOVENODE mob_log)
78{
79 if (Mobilitylog == NULL || !validate_log(mob_log.d))
80 {
81 return;
82 }
83
84 fprintf(Mobilitylog, "%lf,%s,%d,%lf,%lf,%lf,", mob_log.time / MILLISECOND, DEVICE_NAME(fn_NetSim_GetDeviceIdByConfigId(mob_log.d)),
85 mob_log.d, mob_log.x, mob_log.y, mob_log.z);
86 fprintf(Mobilitylog, "\n");
87
88 if (nDbgFlag) fflush(Mobilitylog);
89}
90
91bool get_protocol_log_status(char* logname)
92{
93 FILE* fp;
94 char str[BUFSIZ];
95 sprintf(str, "%s/%s", pszIOPath, "ProtocolLogsConfig.txt");
96 fp = fopen(str, "r");
97 if (!fp)
98 return false;
99
100 char data[BUFSIZ];
101 while (fgets(data, BUFSIZ, fp))
102 {
103 lskip(data);
104 sprintf(str, "%s=true", logname);
105 if (!strnicmp(data, str, strlen(str)))
106 {
107 fclose(fp);
108 return true;
109 }
110 }
111 fclose(fp);
112
113 return false;
114}
115
116
117