-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleDataReceiver.cpp
More file actions
209 lines (172 loc) · 5.79 KB
/
SimpleDataReceiver.cpp
File metadata and controls
209 lines (172 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//---------------------------------------------------------------------------
#pragma warning ( disable : 4503 )
#ifdef _WIN32
#include <Windows.h>
#include <process.h>
#else
#include <dlfcn.h>
#define GetProcAddress dlsym
#include <thread>
#endif
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <vector>
#include <set>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include "DSimUI.h" // coreDS API UI include
#include "DSimAPI.hpp" // coreDS API main functions
using namespace DSimAPI;
std::string mSelectedConfiguration="-1";
std::map<std::string, std::string> mDSIMParameters;
bool mDebugEnabled = false;
bool mReload = false;
bool mEnabledLogging = false;
bool mEnableScripting = true;
bool mEnableLoggingToWindow = true;
std::string mLogFilePath ="coreDSlog.log";
bool mDisableWord = false;
CDSimAPI mDSimManager;
bool lbRunning = true;
bool lbRunningSim = true;
#ifdef _WIN32
void commandlineparameter_thread(void* lpParameter)
#else
void commandlineparameter_thread()
#endif
{
do
{
string parameter;
if (getline(cin, parameter))
{
if (!parameter.empty())
{
if (parameter == "q") //quit the software
{
lbRunning = false;
lbRunningSim = false;
}
else if (parameter == "s") //stop the current simulation to start a new one
{
lbRunningSim = false;
}
}
}
}
while(lbRunning);
}
void messageReceived(const std::string &iMessageName, const std::map<std::string, std::string > &oDataStruct)
{
std::map<std::string, std::string >::const_iterator iter = oDataStruct.begin();
for (; iter != oDataStruct.end(); iter++)
{
printf("Message: %s\t%s\n", (*iter).first.c_str(), (*iter).second.c_str());
}
}
void objectRemoved(const std::string &objectclassName)
{
printf("Object deleted: %s\n", objectclassName.c_str());
}
void objectDiscovered(const std::string &objecttypeName, const std::string &objectUniqueIdentifier, const std::string &objectName)
{
printf("Object discovered: %s\t%s\t%s\n", objecttypeName.c_str(), objectUniqueIdentifier.c_str(), objectName.c_str());
}
void objectRemoved1(const std::string &objectclassName)
{
printf("Object deleted -- obj1: %s\n", objectclassName.c_str());
}
void objectDiscovered1(const std::string &objecttypeName, const std::string &objectUniqueIdentifier, const std::string &objectName)
{
printf("Object discovered -- obj1: %s\t%s\t%s\n", objecttypeName.c_str(), objectUniqueIdentifier.c_str(), objectName.c_str());
}
void updateAircraftPos(const std::string &oLocalUniqueObjectIdentifier, const std::string &objectType, std::map<std::string, std::string > &oDataStruct)
{
std::map<std::string, std::string >::const_iterator iter = oDataStruct.begin();
for(; iter != oDataStruct.end(); iter++)
{
printf("%s: %s\t%s\n", objectType.c_str(), (*iter).first.c_str(), (*iter).second.c_str());
}
}
int main(int argc, char* argv[])
{
std::string lSelectedLUAEditor = "Unknown Editor";
std::map<std::string, std::set< std::string > > lInputObjectVariables;
lInputObjectVariables["ItemInput"].insert("X");
lInputObjectVariables["ItemInput"].insert("Y");
lInputObjectVariables["ItemInput"].insert("Z");
lInputObjectVariables["ItemInput1"].insert("X");
lInputObjectVariables["ItemInput1"].insert("Y");
lInputObjectVariables["ItemInput1"].insert("Z");
setInputObjectVariables(lInputObjectVariables);
std::map<std::string, std::set< std::string > > linputMessageVariables;
linputMessageVariables["CollisionIn"].insert("CollisionX");
linputMessageVariables["CollisionIn"].insert("CollisionY");
linputMessageVariables["CollisionIn"].insert("CollisionZ");
setInputMessageVariables(linputMessageVariables);
std::cout << "This is a simple testing application that sends a random X value" << std::endl;
std::cout << "Press 'q' to QUIT" << std::endl;
std::cout << "Press 's' to change simulation parameters" << std::endl;
#ifdef _WIN32
_beginthread(&commandlineparameter_thread, 0, NULL);
#else
std::thread t1(commandlineparameter_thread);
#endif
do
{
std::string lSelectedConfig = "";
std::string useless = "";
//the UI share globals states
showUI(lSelectedConfig, useless, mEnableScripting, lSelectedLUAEditor, mDisableWord, mDebugEnabled, mReload,mEnableLoggingToWindow, mEnabledLogging, mLogFilePath, false, false, INT_MAX);
mSelectedConfiguration = std::string(lSelectedConfig);
if (mSelectedConfiguration == "0")
{
mSelectedConfiguration = -1;;
}
else
{
mDSIMParameters["LogError"] = mEnabledLogging ? "1" : "0";
mDSIMParameters["LogErrorWindow"] = mEnableLoggingToWindow ? "1" : "0";
mDSIMParameters["LogErrorPath"] = mLogFilePath;
mDSIMParameters["ReloadScriptEachUse"] = mReload ? "1" : "0";;
mDSIMParameters["EnableScripting"] = mEnableScripting ? "1" : "0";;
mDSIMParameters["EnableDebugging"] = mDebugEnabled ? "1" : "0";;
try
{
mDSimManager.deinit();
mDSimManager.init(mSelectedConfiguration, mDSIMParameters);
mDSimManager.registerObjectUpdateHandler("ItemInput", updateAircraftPos);
mDSimManager.registerNewObjectFoundHandler("ItemInput", objectDiscovered);
mDSimManager.registerObjectRemovedHandler("ItemInput", objectRemoved);
mDSimManager.registerNewObjectFoundHandler("ItemInput1", objectDiscovered1);
mDSimManager.registerObjectRemovedHandler("ItemInput1", objectRemoved1);
mDSimManager.registerObjectUpdateHandler("ItemInput1", updateAircraftPos);
mDSimManager.registerMessageReceivedHandler("CollisionIn", messageReceived);
}
catch(std::exception &e)
{
cout << e.what() << endl;
}
}
lbRunningSim = true;
while(lbRunningSim)
{
try
{
mDSimManager.step();
}
catch (const std::exception &e)
{
cout << e.what() << endl;
}
}
}
while(lbRunning);
}