Real Name
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
#For TLS
|
||||
#target_compile_definitions(WebSocketServerXPlane PUBLIC
|
||||
#IXWEBSOCKET_USE_TLS
|
||||
#IXWEBSOCKET_USE_OPEN_SSL
|
||||
#)
|
||||
#Link to ssl(requires OpenSLL for macOS and Windows)
|
||||
|
||||
file(GLOB ixwebsocket CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/ixwebsocket/*.cpp)
|
||||
file(GLOB websocket CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/websocket/*.cpp)
|
||||
|
||||
add_library(germanairlinesva_xplugin SHARED
|
||||
${ixwebsocket}
|
||||
${websocket}
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/ixwebsocket/include
|
||||
${CMAKE_SOURCE_DIR}/websocket/include
|
||||
${CMAKE_SOURCE_DIR}/XPSDK/CHeaders
|
||||
${CMAKE_SOURCE_DIR}/nlohmann
|
||||
)
|
||||
|
||||
set_target_properties(germanairlinesva_xplugin PROPERTIES
|
||||
PREFIX ""
|
||||
SUFFIX ".xpl"
|
||||
)
|
||||
target_compile_definitions(germanairlinesva_xplugin PRIVATE
|
||||
XPLM200
|
||||
XPLM210
|
||||
)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-Wall
|
||||
-pedantic
|
||||
-fvisibility=hidden
|
||||
)
|
||||
if(DEBUG)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-g
|
||||
)
|
||||
target_link_options(germanairlinesva_xplugin PRIVATE
|
||||
-g
|
||||
)
|
||||
else()
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-O2
|
||||
)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
message("Building for MacOSX Universal into ${PROJECT_BINARY_DIR}/${PLUGIN_NAME}/${BIT}")
|
||||
|
||||
set_target_properties(germanairlinesva_xplugin PROPERTIES
|
||||
NO_SONAME 1
|
||||
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}
|
||||
OUTPUT_NAME mac
|
||||
)
|
||||
|
||||
target_compile_definitions(germanairlinesva_xplugin PUBLIC
|
||||
APL
|
||||
)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
"SHELL:-arch i386"
|
||||
"SHELL:-arch x86_64"
|
||||
)
|
||||
target_link_options(germanairlinesva_xplugin PRIVATE
|
||||
"SHELL:-arch i386"
|
||||
"SHELL:-arch x86_64"
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/XPSDK/Libraries/Mac/XPLM.framework/XPLM
|
||||
"-framework Security"
|
||||
)
|
||||
elseif(UNIX)
|
||||
message("Building for Linux ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
|
||||
|
||||
set_target_properties(germanairlinesva_xplugin PROPERTIES
|
||||
NO_SONAME 1
|
||||
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}
|
||||
OUTPUT_NAME lin
|
||||
)
|
||||
|
||||
target_compile_definitions(germanairlinesva_xplugin PUBLIC
|
||||
LIN
|
||||
)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-nodefaultlibs
|
||||
)
|
||||
if(BIT STREQUAL "32")
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-m32
|
||||
)
|
||||
target_link_options(germanairlinesva_xplugin PRIVATE
|
||||
-m32
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
crypto
|
||||
pthread
|
||||
)
|
||||
elseif(WIN32)
|
||||
message("Building for Windows ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
|
||||
|
||||
set_target_properties(germanairlinesva_xplugin PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}
|
||||
OUTPUT_NAME win
|
||||
)
|
||||
|
||||
target_compile_definitions(germanairlinesva_xplugin PUBLIC
|
||||
IBM
|
||||
)
|
||||
if(DEBUG)
|
||||
target_compile_options(germanairlinesva_xplugin PRIVATE
|
||||
-gcodeview
|
||||
)
|
||||
target_link_options(germanairlinesva_xplugin PRIVATE
|
||||
-Wl,-pdb=
|
||||
)
|
||||
endif()
|
||||
target_link_options(germanairlinesva_xplugin PRIVATE
|
||||
-static
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
)
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
ws2_32.lib
|
||||
)
|
||||
if(BIT STREQUAL "32")
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/XPSDK/Libraries/Win/XPLM.lib
|
||||
)
|
||||
else()
|
||||
target_link_libraries(germanairlinesva_xplugin PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/XPSDK/Libraries/Win/XPLM_64.lib
|
||||
)
|
||||
endif()
|
||||
target_sources(germanairlinesva_xplugin PRIVATE
|
||||
xPluginWin.cpp
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_MAIN_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_MAIN_H
|
||||
|
||||
#ifdef IBM
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
#define BUFSIZE 1024
|
||||
#define MD5LEN 16
|
||||
|
||||
#include "XPLM/XPLMDataAccess.h"
|
||||
#include "XPLM/XPLMGraphics.h"
|
||||
#include "XPLM/XPLMPlanes.h"
|
||||
#include "XPLM/XPLMPlugin.h"
|
||||
#include "XPLM/XPLMProcessing.h"
|
||||
#include "XPLM/XPLMUtilities.h"
|
||||
|
||||
#include "websocket.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon);
|
||||
void serverWorker();
|
||||
void toLog(const std::string &message);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,202 @@
|
||||
#include "include/main.h"
|
||||
|
||||
std::mutex mutex;
|
||||
std::queue<std::function<void()>> &messageQueue()
|
||||
{
|
||||
static std::queue<std::function<void()>> _messageQueue;
|
||||
return _messageQueue;
|
||||
}
|
||||
std::thread serverThread;
|
||||
std::atomic<bool> wantsExit;
|
||||
|
||||
websocket *connector;
|
||||
|
||||
/* Datarefs */
|
||||
XPLMDataRef pauseIndicator;
|
||||
XPLMDataRef parkingBrake;
|
||||
XPLMDataRef acftOnGrnd;
|
||||
XPLMDataRef totalFuelKgs;
|
||||
XPLMDataRef trueHeading;
|
||||
XPLMDataRef acftAlt;
|
||||
XPLMDataRef acftGS;
|
||||
XPLMDataRef acftIAS;
|
||||
XPLMDataRef acftVS;
|
||||
XPLMDataRef acftLatitude;
|
||||
XPLMDataRef acftLongitude;
|
||||
XPLMDataRef fuelFlow;
|
||||
XPLMDataRef maxSpeed;
|
||||
XPLMDataRef uptime;
|
||||
XPLMDataRef magHeading;
|
||||
XPLMDataRef timeZulu;
|
||||
XPLMDataRef payloadKgs;
|
||||
XPLMDataRef totalWeightKgs;
|
||||
|
||||
XPLMDataRef localX;
|
||||
XPLMDataRef localY;
|
||||
XPLMDataRef localZ;
|
||||
XPLMDataRef elevation;
|
||||
XPLMDataRef pitch;
|
||||
XPLMDataRef roll;
|
||||
XPLMDataRef quaternion;
|
||||
|
||||
data toSend;
|
||||
|
||||
/*
|
||||
* Callbacks
|
||||
*/
|
||||
|
||||
PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
|
||||
{
|
||||
XPLMEnableFeature("XPLM_USE_NATIVE_PATHS", 1);
|
||||
|
||||
wantsExit.store(false);
|
||||
|
||||
/* First we must fill in the passed-in buffers to describe our
|
||||
* plugin to the plugin-system. */
|
||||
|
||||
strcpy(outName, "WebSocketTestXPlane");
|
||||
strcpy(outSig, "de.german-airlines.WebSocketTestXPlane");
|
||||
strcpy(outDesc, "WebSocketTestXPlane");
|
||||
|
||||
/* 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
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Thread for sending data to web socket
|
||||
serverThread = std::thread(&serverWorker);
|
||||
|
||||
toLog("WebSocketTestXPlane initialized and ready");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
PLUGIN_API void XPluginStop(void)
|
||||
{
|
||||
/* Flight Loop */
|
||||
XPLMUnregisterFlightLoopCallback(flightLoop, nullptr);
|
||||
/* End threads */
|
||||
wantsExit = true;
|
||||
delete connector;
|
||||
serverThread.join();
|
||||
}
|
||||
|
||||
PLUGIN_API void XPluginDisable(void) {}
|
||||
|
||||
PLUGIN_API int XPluginEnable(void) { return 1; }
|
||||
|
||||
PLUGIN_API void
|
||||
XPluginReceiveMessage(XPLMPluginID inFromWho, long inMessage, void *inParam)
|
||||
{
|
||||
}
|
||||
|
||||
float flightLoop(float elapsedMe, float elapsedSim, int counter, void *refcon)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
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);
|
||||
|
||||
char *name = (char *)calloc(256, sizeof(char));
|
||||
XPLMGetNthAircraftModel(0, name, toSend.path);
|
||||
free(name);
|
||||
|
||||
toSend.uptime = XPLMGetDataf(uptime);
|
||||
toSend.magHeading = XPLMGetDataf(magHeading);
|
||||
|
||||
toSend.payloadKg = XPLMGetDataf(payloadKgs);
|
||||
toSend.totalWeightKg = XPLMGetDataf(totalWeightKgs);
|
||||
|
||||
if (!messageQueue().empty()) {
|
||||
auto op = std::move(messageQueue().front());
|
||||
messageQueue().pop();
|
||||
op();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void serverWorker()
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
void toLog(const std::string &message)
|
||||
{
|
||||
std::stringstream msg;
|
||||
msg << "German Airlines VA: " << message << std::endl;
|
||||
XPLMDebugString(msg.str().c_str());
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
#pragma warning(suppress : 26440)
|
||||
BOOL APIENTRY DllMain(HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved)
|
||||
{
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
Reference in New Issue
Block a user