Remove ixWebSocket
This commit is contained in:
1 parent
fbee417594
commit
a820f7456a
123 files changed
+998
-12947
No files matched your search
+167
-169
@@ -3,8 +3,8 @@
|
||||
std::mutex mutex;
|
||||
std::queue<std::function<void()>> &messageQueue()
|
||||
{
|
||||
static std::queue<std::function<void()>> _messageQueue;
|
||||
return _messageQueue;
|
||||
static std::queue<std::function<void()>> _messageQueue;
|
||||
return _messageQueue;
|
||||
}
|
||||
std::thread serverThread;
|
||||
std::thread recordingThread;
|
||||
@@ -12,7 +12,7 @@ std::atomic<bool> wantsExit;
|
||||
|
||||
std::map<std::string, std::string> configuration;
|
||||
|
||||
Websocket *connector;
|
||||
Socket *connector;
|
||||
|
||||
/* Datarefs */
|
||||
XPLMDataRef pauseIndicator;
|
||||
@@ -51,124 +51,123 @@ Path p;
|
||||
|
||||
PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
{
|
||||
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1);
|
||||
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1);
|
||||
|
||||
wantsExit.store(false);
|
||||
wantsExit.store(false);
|
||||
|
||||
/* First we must fill in the passed-in buffers to describe our
|
||||
* plugin to the plugin-system. */
|
||||
/* First we must fill in the passed-in buffers to describe our
|
||||
* plugin to the plugin-system. */
|
||||
|
||||
strcpy(outName, "GAConnector");
|
||||
strcpy(outSig, "de.german-airlines.GAConnector");
|
||||
strcpy(outDesc, "GAConnector");
|
||||
strcpy(outName, "GAConnector");
|
||||
strcpy(outSig, "de.german-airlines.GAConnector");
|
||||
strcpy(outDesc, "GAConnector");
|
||||
|
||||
/* Flight Loop */
|
||||
XPLMRegisterFlightLoopCallback(flightLoop, -1, nullptr);
|
||||
/* Flight Loop */
|
||||
XPLMRegisterFlightLoopCallback(flightLoop, -1, nullptr);
|
||||
|
||||
/* Setup DataRefs */
|
||||
pauseIndicator = XPLMFindDataRef(
|
||||
"sim/time/sim_speed"); // INT 0=paused, doubles as setting pause(1)
|
||||
parkingBrake =
|
||||
XPLMFindDataRef("sim/flightmodel/controls/parkbrake"); // FLOAT 1=max
|
||||
acftOnGrnd =
|
||||
XPLMFindDataRef("sim/flightmodel/failures/onground_any"); // INT 1=true
|
||||
totalFuelKgs =
|
||||
XPLMFindDataRef("sim/flightmodel/weight/m_fuel_total"); // FLOAT
|
||||
trueHeading = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/true_psi"); // FLOAT degrees north
|
||||
acftAlt =
|
||||
XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE meters
|
||||
acftGS = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/groundspeed"); // FLOAT meters/second
|
||||
acftIAS = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/indicated_airspeed"); // FLOAT kias
|
||||
acftVS = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/vh_ind_fpm"); // FLOAT feet/minute
|
||||
acftLatitude =
|
||||
XPLMFindDataRef("sim/flightmodel/position/latitude"); // DOUBLE degrees
|
||||
acftLongitude =
|
||||
XPLMFindDataRef("sim/flightmodel/position/longitude"); // DOUBLE degrees
|
||||
fuelFlow = XPLMFindDataRef(
|
||||
"sim/flightmodel/engine/ENGN_FF_"); // FLOAT[8] kg/second
|
||||
maxSpeed = XPLMFindDataRef("sim/aircraft/view/acf_Vne"); // FLOAT kias
|
||||
uptime =
|
||||
XPLMFindDataRef("sim/time/total_running_time_sec"); // FLOAT seconds
|
||||
magHeading = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/mag_psi"); // FLOAT degrees north
|
||||
timeZulu = XPLMFindDataRef(
|
||||
"sim/time/zulu_time_sec"); // FLOAT seconds since midnight
|
||||
payloadKgs = XPLMFindDataRef("sim/flightmodel/weight/m_fixed"); // FLOAT
|
||||
totalWeightKgs = XPLMFindDataRef("sim/flightmodel/weight/m_total"); // FLOAT
|
||||
/* Setup DataRefs */
|
||||
pauseIndicator = XPLMFindDataRef(
|
||||
"sim/time/sim_speed"); // INT 0=paused, doubles as setting pause(1)
|
||||
parkingBrake =
|
||||
XPLMFindDataRef("sim/flightmodel/controls/parkbrake"); // FLOAT 1=max
|
||||
acftOnGrnd =
|
||||
XPLMFindDataRef("sim/flightmodel/failures/onground_any"); // INT 1=true
|
||||
totalFuelKgs =
|
||||
XPLMFindDataRef("sim/flightmodel/weight/m_fuel_total"); // FLOAT
|
||||
trueHeading = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/true_psi"); // FLOAT degrees north
|
||||
acftAlt =
|
||||
XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE meters
|
||||
acftGS = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/groundspeed"); // FLOAT meters/second
|
||||
acftIAS = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/indicated_airspeed"); // FLOAT kias
|
||||
acftVS = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/vh_ind_fpm"); // FLOAT feet/minute
|
||||
acftLatitude =
|
||||
XPLMFindDataRef("sim/flightmodel/position/latitude"); // DOUBLE degrees
|
||||
acftLongitude =
|
||||
XPLMFindDataRef("sim/flightmodel/position/longitude"); // DOUBLE degrees
|
||||
fuelFlow =
|
||||
XPLMFindDataRef("sim/flightmodel/engine/ENGN_FF_"); // FLOAT[8] kg/second
|
||||
maxSpeed = XPLMFindDataRef("sim/aircraft/view/acf_Vne"); // FLOAT kias
|
||||
uptime = XPLMFindDataRef("sim/time/total_running_time_sec"); // FLOAT seconds
|
||||
magHeading = XPLMFindDataRef(
|
||||
"sim/flightmodel/position/mag_psi"); // FLOAT degrees north
|
||||
timeZulu =
|
||||
XPLMFindDataRef("sim/time/zulu_time_sec"); // FLOAT seconds since midnight
|
||||
payloadKgs = XPLMFindDataRef("sim/flightmodel/weight/m_fixed"); // FLOAT
|
||||
totalWeightKgs = XPLMFindDataRef("sim/flightmodel/weight/m_total"); // FLOAT
|
||||
|
||||
localX = XPLMFindDataRef("sim/flightmodel/position/local_x"); // DOUBLE
|
||||
localY = XPLMFindDataRef("sim/flightmodel/position/local_y"); // DOUBLE
|
||||
localZ = XPLMFindDataRef("sim/flightmodel/position/local_z"); // DOUBLE
|
||||
elevation = XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE
|
||||
pitch = XPLMFindDataRef("sim/flightmodel/position/theta"); // FLOAT
|
||||
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
|
||||
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
|
||||
localX = XPLMFindDataRef("sim/flightmodel/position/local_x"); // DOUBLE
|
||||
localY = XPLMFindDataRef("sim/flightmodel/position/local_y"); // DOUBLE
|
||||
localZ = XPLMFindDataRef("sim/flightmodel/position/local_z"); // DOUBLE
|
||||
elevation = XPLMFindDataRef("sim/flightmodel/position/elevation"); // DOUBLE
|
||||
pitch = XPLMFindDataRef("sim/flightmodel/position/theta"); // FLOAT
|
||||
roll = XPLMFindDataRef("sim/flightmodel/position/phi"); // FLOAT
|
||||
quaternion = XPLMFindDataRef("sim/flightmodel/position/q"); // FLOAT[4]
|
||||
|
||||
// Initialize connector
|
||||
try {
|
||||
connector = new Websocket(toLog);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
toLog(e.what());
|
||||
return 0;
|
||||
// Initialize connector
|
||||
try {
|
||||
connector =
|
||||
new Socket("https://wsecho.hofmannnet.myhome-server.de/client", toLog);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
toLog(e.what());
|
||||
return 0;
|
||||
}
|
||||
toLog("WebSocket started");
|
||||
|
||||
configuration =
|
||||
config::readConfig("Resources/plugins/GAConnector/config.cfg");
|
||||
toLog("Config loaded");
|
||||
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (util::generateMD5("Custom Scenery/scenery_packs.ini", hash, toLog) == 0) {
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
airports;
|
||||
|
||||
if (strcmp(configuration["scenery"].c_str(), hash) != 0) {
|
||||
scan("Resources/default scenery/default apt dat/Earth nav "
|
||||
"data/apt.dat",
|
||||
"Custom Scenery/scenery_packs.ini",
|
||||
"Resources/plugins/GAConnector/log.txt",
|
||||
airports);
|
||||
simulatorDatabase::toFile(airports,
|
||||
"Resources/plugins/GAConnector/sim.bin");
|
||||
|
||||
configuration["scenery"] = hash;
|
||||
config::writeConfig(configuration,
|
||||
"Resources/plugins/GAConnector/config.cfg");
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
airports =
|
||||
simulatorDatabase::fromFile("Resources/plugins/GAConnector/sim.bin");
|
||||
toLog("Sim Database loaded");
|
||||
}
|
||||
toLog("WebSocket started");
|
||||
}
|
||||
|
||||
configuration =
|
||||
config::readConfig("Resources/plugins/GAConnector/config.cfg");
|
||||
toLog("Config loaded");
|
||||
// Thread for sending data to web socket
|
||||
serverThread = std::thread(&serverWorker);
|
||||
recordingThread = std::thread(&recordingWorker);
|
||||
toLog("Workers started");
|
||||
|
||||
char hash[2 * MD5LEN + 1] = "";
|
||||
if (util::generateMD5("Custom Scenery/scenery_packs.ini", hash, toLog) ==
|
||||
0) {
|
||||
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
|
||||
airports;
|
||||
|
||||
if (strcmp(configuration["scenery"].c_str(), hash) != 0) {
|
||||
scan("Resources/default scenery/default apt dat/Earth nav "
|
||||
"data/apt.dat",
|
||||
"Custom Scenery/scenery_packs.ini",
|
||||
"Resources/plugins/GAConnector/log.txt",
|
||||
airports);
|
||||
simulatorDatabase::toFile(airports,
|
||||
"Resources/plugins/GAConnector/sim.bin");
|
||||
|
||||
configuration["scenery"] = hash;
|
||||
config::writeConfig(configuration,
|
||||
"Resources/plugins/GAConnector/config.cfg");
|
||||
toLog("Sim Database updated");
|
||||
} else {
|
||||
airports = simulatorDatabase::fromFile(
|
||||
"Resources/plugins/GAConnector/sim.bin");
|
||||
toLog("Sim Database loaded");
|
||||
}
|
||||
}
|
||||
|
||||
// Thread for sending data to web socket
|
||||
serverThread = std::thread(&serverWorker);
|
||||
recordingThread = std::thread(&recordingWorker);
|
||||
toLog("Workers started");
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
PLUGIN_API void XPluginStop(void)
|
||||
{
|
||||
/* Flight Loop */
|
||||
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
delete connector;
|
||||
serverThread.join();
|
||||
recordingThread.join();
|
||||
/* Flight Loop */
|
||||
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
delete connector;
|
||||
serverThread.join();
|
||||
recordingThread.join();
|
||||
|
||||
std::ofstream out("Resources/plugins/GAConnector/flight.rec");
|
||||
out.write(reinterpret_cast<const char *>(p.getBinaryData()),
|
||||
(std::streamsize)p.getBinaryLength());
|
||||
out.close();
|
||||
std::ofstream out("Resources/plugins/GAConnector/flight.rec");
|
||||
out.write(reinterpret_cast<const char *>(p.getBinaryData()),
|
||||
(std::streamsize)p.getBinaryLength());
|
||||
out.close();
|
||||
}
|
||||
|
||||
PLUGIN_API void XPluginDisable(void) {}
|
||||
@@ -187,94 +186,93 @@ PLUGIN_API void
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
memset(&toSend, 0, sizeof(data));
|
||||
memset(&toSend, 0, sizeof(data));
|
||||
|
||||
toSend.pause = XPLMGetDatai(pauseIndicator);
|
||||
toSend.pBrake = XPLMGetDataf(parkingBrake);
|
||||
toSend.onGrnd = XPLMGetDatai(acftOnGrnd);
|
||||
toSend.totFuelKg = XPLMGetDataf(totalFuelKgs);
|
||||
toSend.truHdg = XPLMGetDataf(trueHeading);
|
||||
toSend.alt = XPLMGetDatad(acftAlt);
|
||||
toSend.gs = XPLMGetDataf(acftGS);
|
||||
toSend.ias = XPLMGetDataf(acftIAS);
|
||||
toSend.vs = XPLMGetDataf(acftVS);
|
||||
toSend.lat = XPLMGetDatad(acftLatitude);
|
||||
toSend.lon = XPLMGetDatad(acftLongitude);
|
||||
XPLMGetDatavf(fuelFlow, toSend.ff, 0, 8);
|
||||
toSend.maxSpd = XPLMGetDataf(maxSpeed);
|
||||
toSend.pause = XPLMGetDatai(pauseIndicator);
|
||||
toSend.pBrake = XPLMGetDataf(parkingBrake);
|
||||
toSend.onGrnd = XPLMGetDatai(acftOnGrnd);
|
||||
toSend.totFuelKg = XPLMGetDataf(totalFuelKgs);
|
||||
toSend.truHdg = XPLMGetDataf(trueHeading);
|
||||
toSend.alt = XPLMGetDatad(acftAlt);
|
||||
toSend.gs = XPLMGetDataf(acftGS);
|
||||
toSend.ias = XPLMGetDataf(acftIAS);
|
||||
toSend.vs = XPLMGetDataf(acftVS);
|
||||
toSend.lat = XPLMGetDatad(acftLatitude);
|
||||
toSend.lon = XPLMGetDatad(acftLongitude);
|
||||
XPLMGetDatavf(fuelFlow, toSend.ff, 0, 8);
|
||||
toSend.maxSpd = XPLMGetDataf(maxSpeed);
|
||||
|
||||
char *name = (char *)calloc(256, sizeof(char));
|
||||
XPLMGetNthAircraftModel(0, name, toSend.path);
|
||||
free(name);
|
||||
char *name = (char *)calloc(256, sizeof(char));
|
||||
XPLMGetNthAircraftModel(0, name, toSend.path);
|
||||
free(name);
|
||||
|
||||
toSend.uptime = XPLMGetDataf(uptime);
|
||||
toSend.magHeading = XPLMGetDataf(magHeading);
|
||||
toSend.uptime = XPLMGetDataf(uptime);
|
||||
toSend.magHeading = XPLMGetDataf(magHeading);
|
||||
|
||||
toSend.payloadKg = XPLMGetDataf(payloadKgs);
|
||||
toSend.totalWeightKg = XPLMGetDataf(totalWeightKgs);
|
||||
toSend.payloadKg = XPLMGetDataf(payloadKgs);
|
||||
toSend.totalWeightKg = XPLMGetDataf(totalWeightKgs);
|
||||
|
||||
if (!messageQueue().empty()) {
|
||||
auto op = std::move(messageQueue().front());
|
||||
messageQueue().pop();
|
||||
op();
|
||||
}
|
||||
if (!messageQueue().empty()) {
|
||||
auto op = std::move(messageQueue().front());
|
||||
messageQueue().pop();
|
||||
op();
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
void serverWorker()
|
||||
{
|
||||
util::setThreadName("GAServerWorker");
|
||||
util::setThreadName("GAServerWorker");
|
||||
|
||||
while (!wantsExit) {
|
||||
data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
while (!wantsExit) {
|
||||
data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
memcpy(©, &toSend, sizeof(data));
|
||||
}
|
||||
|
||||
connector->sendData(copy);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
memcpy(©, &toSend, sizeof(data));
|
||||
}
|
||||
|
||||
connector->sendData(copy);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
}
|
||||
|
||||
void recordingWorker()
|
||||
{
|
||||
util::setThreadName("GARecordingWorker");
|
||||
util::setThreadName("GARecordingWorker");
|
||||
|
||||
PathSegment lastPath;
|
||||
PathSegment lastPath;
|
||||
|
||||
while (!wantsExit) {
|
||||
data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
while (!wantsExit) {
|
||||
data copy;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
memcpy(©, &toSend, sizeof(data));
|
||||
}
|
||||
|
||||
PathSegment currentPath(static_cast<std::uint16_t>(copy.alt),
|
||||
static_cast<std::uint16_t>(copy.gs),
|
||||
copy.lat,
|
||||
copy.lon);
|
||||
|
||||
if (strcmp(copy.path, "") != 0 && copy.pause &&
|
||||
lastPath != currentPath) {
|
||||
p.addSegment(currentPath);
|
||||
lastPath = currentPath;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
memcpy(©, &toSend, sizeof(data));
|
||||
}
|
||||
|
||||
PathSegment currentPath(static_cast<std::uint16_t>(copy.alt),
|
||||
static_cast<std::uint16_t>(copy.gs),
|
||||
copy.lat,
|
||||
copy.lon);
|
||||
|
||||
if (strcmp(copy.path, "") != 0 && copy.pause && lastPath != currentPath) {
|
||||
p.addSegment(currentPath);
|
||||
lastPath = currentPath;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void toLog(const std::string &message)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "German Airlines VA: " << message << std::endl;
|
||||
XPLMDebugString(msg.str().c_str());
|
||||
std::stringstream msg;
|
||||
msg << "German Airlines VA: " << message << std::endl;
|
||||
XPLMDebugString(msg.str().c_str());
|
||||
}
|
||||
Reference in new issue
Block a user