Fixed tabs vs spaces indentations (#157)
This commit is contained in:
committed by
Jason Watkins
parent
50335c4a5c
commit
90ccec0d07
@@ -173,7 +173,7 @@ namespace XPC
|
|||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
for (size_t i = 0; i < numWaypoints; ++i)
|
for (size_t i = 0; i < numWaypoints; ++i)
|
||||||
{
|
{
|
||||||
LocalPoint* l = &localPoints[i];
|
LocalPoint* l = &localPoints[i];
|
||||||
glVertex3f((float)l->x, (float)l->y, (float)l->z);
|
glVertex3f((float)l->x, (float)l->y, (float)l->z);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
@@ -226,7 +226,7 @@ namespace XPC
|
|||||||
// Enable drawing if necessary
|
// Enable drawing if necessary
|
||||||
if (!msgEnabled)
|
if (!msgEnabled)
|
||||||
{
|
{
|
||||||
XPLMRegisterDrawCallback(MessageDrawCallback, xplm_Phase_Window, 0, NULL);
|
XPLMRegisterDrawCallback(MessageDrawCallback, xplm_Phase_Window, 0, NULL);
|
||||||
msgEnabled = true;
|
msgEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace XPC
|
namespace XPC
|
||||||
{
|
{
|
||||||
Message::Message() {}
|
Message::Message() {}
|
||||||
|
|
||||||
Message Message::ReadFrom(const UDPSocket& sock)
|
Message Message::ReadFrom(const UDPSocket& sock)
|
||||||
{
|
{
|
||||||
@@ -110,17 +110,17 @@ namespace XPC
|
|||||||
else if (head == "DREF")
|
else if (head == "DREF")
|
||||||
{
|
{
|
||||||
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
||||||
string dref((char*)buffer + 6, buffer[5]);
|
string dref((char*)buffer + 6, buffer[5]);
|
||||||
Log::FormatLine(LOG_DEBUG, "DBUG", " DREF (size %i) = %s", dref.length(), dref.c_str());
|
Log::FormatLine(LOG_DEBUG, "DBUG", " DREF (size %i) = %s", dref.length(), dref.c_str());
|
||||||
ss.str("");
|
ss.str("");
|
||||||
int values = buffer[6 + buffer[5]];
|
int values = buffer[6 + buffer[5]];
|
||||||
ss << " Values(size " << values << ") =";
|
ss << " Values(size " << values << ") =";
|
||||||
for (int i = 0; i < values; ++i)
|
for (int i = 0; i < values; ++i)
|
||||||
{
|
{
|
||||||
ss << " " << *((float*)(buffer + values + 1 + sizeof(float) * i));
|
ss << " " << *((float*)(buffer + values + 1 + sizeof(float) * i));
|
||||||
}
|
}
|
||||||
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
||||||
}
|
}
|
||||||
else if (head == "GETC" || head == "GETP")
|
else if (head == "GETC" || head == "GETP")
|
||||||
{
|
{
|
||||||
ss << " Aircraft:" << (int)buffer[5];
|
ss << " Aircraft:" << (int)buffer[5];
|
||||||
@@ -129,15 +129,15 @@ namespace XPC
|
|||||||
else if (head == "GETD")
|
else if (head == "GETD")
|
||||||
{
|
{
|
||||||
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
||||||
int cur = 6;
|
int cur = 6;
|
||||||
for (int i = 0; i < buffer[5]; ++i)
|
for (int i = 0; i < buffer[5]; ++i)
|
||||||
{
|
{
|
||||||
string dref((char*)buffer + cur + 1, buffer[cur]);
|
string dref((char*)buffer + cur + 1, buffer[cur]);
|
||||||
Log::FormatLine(LOG_DEBUG, "DBUG", " #%i/%i (size:%i) %s",
|
Log::FormatLine(LOG_DEBUG, "DBUG", " #%i/%i (size:%i) %s",
|
||||||
i + 1, buffer[5], dref.length(), dref.c_str());
|
i + 1, buffer[5], dref.length(), dref.c_str());
|
||||||
cur += 1 + buffer[cur];
|
cur += 1 + buffer[cur];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (head == "POSI")
|
else if (head == "POSI")
|
||||||
{
|
{
|
||||||
char aircraft = buffer[5];
|
char aircraft = buffer[5];
|
||||||
@@ -146,14 +146,14 @@ namespace XPC
|
|||||||
float orient[3];
|
float orient[3];
|
||||||
memcpy(pos, buffer + 6, 12);
|
memcpy(pos, buffer + 6, 12);
|
||||||
memcpy(orient, buffer + 18, 12);
|
memcpy(orient, buffer + 18, 12);
|
||||||
ss << " AC:" << (int)aircraft;
|
ss << " AC:" << (int)aircraft;
|
||||||
ss << " Pos:(" << pos[0] << ' ' << pos[1] << ' ' << pos[2] << ") Orient:(";
|
ss << " Pos:(" << pos[0] << ' ' << pos[1] << ' ' << pos[2] << ") Orient:(";
|
||||||
ss << orient[0] << ' ' << orient[1] << ' ' << orient[2] << ") Gear:";
|
ss << orient[0] << ' ' << orient[1] << ' ' << orient[2] << ") Gear:";
|
||||||
ss << gear;
|
ss << gear;
|
||||||
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
||||||
}
|
}
|
||||||
else if (head == "SIMU")
|
else if (head == "SIMU")
|
||||||
{
|
{
|
||||||
ss << ' ' << (int)buffer[5];
|
ss << ' ' << (int)buffer[5];
|
||||||
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
||||||
}
|
}
|
||||||
@@ -163,9 +163,9 @@ namespace XPC
|
|||||||
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ss << " UNKNOWN HEADER ";
|
ss << " UNKNOWN HEADER ";
|
||||||
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace XPC
|
|||||||
MessageHandlers::ConnectionInfo MessageHandlers::connection;
|
MessageHandlers::ConnectionInfo MessageHandlers::connection;
|
||||||
UDPSocket* MessageHandlers::sock;
|
UDPSocket* MessageHandlers::sock;
|
||||||
|
|
||||||
static sockaddr multicast_address = UDPSocket::GetAddr(MULTICAST_GROUP, MULITCAST_PORT);
|
static sockaddr multicast_address = UDPSocket::GetAddr(MULTICAST_GROUP, MULITCAST_PORT);
|
||||||
|
|
||||||
void MessageHandlers::SetSocket(UDPSocket* socket)
|
void MessageHandlers::SetSocket(UDPSocket* socket)
|
||||||
{
|
{
|
||||||
@@ -136,27 +136,27 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::SendBeacon(const std::string& pluginVersion, unsigned short pluginReceivePort, int xplaneVersion) {
|
void MessageHandlers::SendBeacon(const std::string& pluginVersion, unsigned short pluginReceivePort, int xplaneVersion) {
|
||||||
|
|
||||||
unsigned char response[128] = "BECN";
|
unsigned char response[128] = "BECN";
|
||||||
|
|
||||||
std::size_t cur = 5;
|
std::size_t cur = 5;
|
||||||
|
|
||||||
// 2 bytes plugin port
|
// 2 bytes plugin port
|
||||||
*((uint16_t *)(response + cur)) = pluginReceivePort;
|
*((uint16_t *)(response + cur)) = pluginReceivePort;
|
||||||
cur += sizeof(uint16_t);
|
cur += sizeof(uint16_t);
|
||||||
|
|
||||||
// 4 bytes xplane version
|
// 4 bytes xplane version
|
||||||
*((uint32_t*)(response + cur)) = xplaneVersion;
|
*((uint32_t*)(response + cur)) = xplaneVersion;
|
||||||
cur += sizeof(uint32_t);
|
cur += sizeof(uint32_t);
|
||||||
|
|
||||||
// plugin version
|
// plugin version
|
||||||
int len = pluginVersion.length();
|
int len = pluginVersion.length();
|
||||||
memcpy(response + cur, pluginVersion.c_str(), len);
|
memcpy(response + cur, pluginVersion.c_str(), len);
|
||||||
cur += strlen(pluginVersion.c_str()) + len;
|
cur += strlen(pluginVersion.c_str()) + len;
|
||||||
|
|
||||||
sock->SendTo(response, cur, &multicast_address);
|
sock->SendTo(response, cur, &multicast_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleConn(const Message& msg)
|
void MessageHandlers::HandleConn(const Message& msg)
|
||||||
{
|
{
|
||||||
@@ -372,7 +372,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
case 20: // Position
|
case 20: // Position
|
||||||
{
|
{
|
||||||
// TODO: loss of precision here
|
// TODO: loss of precision here
|
||||||
double pos[3];
|
double pos[3];
|
||||||
pos[0] = (double)values[i][2];
|
pos[0] = (double)values[i][2];
|
||||||
pos[1] = (double)values[i][3];
|
pos[1] = (double)values[i][3];
|
||||||
@@ -555,7 +555,7 @@ namespace XPC
|
|||||||
|
|
||||||
unsigned char response[34] = "POSI";
|
unsigned char response[34] = "POSI";
|
||||||
response[5] = (char)DataManager::GetInt(DREF_GearHandle, aircraft);
|
response[5] = (char)DataManager::GetInt(DREF_GearHandle, aircraft);
|
||||||
// TODO change lat/lon/h to double?
|
// TODO change lat/lon/h to double?
|
||||||
*((float*)(response + 6)) = (float)DataManager::GetDouble(DREF_Latitude, aircraft);
|
*((float*)(response + 6)) = (float)DataManager::GetDouble(DREF_Latitude, aircraft);
|
||||||
*((float*)(response + 10)) = (float)DataManager::GetDouble(DREF_Longitude, aircraft);
|
*((float*)(response + 10)) = (float)DataManager::GetDouble(DREF_Longitude, aircraft);
|
||||||
*((float*)(response + 14)) = (float)DataManager::GetDouble(DREF_Elevation, aircraft);
|
*((float*)(response + 14)) = (float)DataManager::GetDouble(DREF_Elevation, aircraft);
|
||||||
@@ -584,22 +584,22 @@ namespace XPC
|
|||||||
float orient[3];
|
float orient[3];
|
||||||
|
|
||||||
if (size == 34) /* lat/lon/h as 32-bit float */
|
if (size == 34) /* lat/lon/h as 32-bit float */
|
||||||
{
|
|
||||||
posd[0] = *((float*)&buffer[6]);
|
|
||||||
posd[1] = *((float*)&buffer[10]);
|
|
||||||
posd[2] = *((float*)&buffer[14]);
|
|
||||||
memcpy(orient, buffer + 18, 12);
|
|
||||||
}
|
|
||||||
else if (size == 46) /* lat/lon/h as 64-bit double */
|
|
||||||
{
|
{
|
||||||
memcpy(posd, buffer + 6, 3*8);
|
posd[0] = *((float*)&buffer[6]);
|
||||||
memcpy(orient, buffer + 30, 12);
|
posd[1] = *((float*)&buffer[10]);
|
||||||
|
posd[2] = *((float*)&buffer[14]);
|
||||||
|
memcpy(orient, buffer + 18, 12);
|
||||||
}
|
}
|
||||||
else
|
else if (size == 46) /* lat/lon/h as 64-bit double */
|
||||||
{
|
{
|
||||||
|
memcpy(posd, buffer + 6, 3*8);
|
||||||
|
memcpy(orient, buffer + 30, 12);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Log::FormatLine(LOG_ERROR, "POSI", "ERROR: Unexpected size: %i (Expected 34 or 46)", size);
|
Log::FormatLine(LOG_ERROR, "POSI", "ERROR: Unexpected size: %i (Expected 34 or 46)", size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert float to double */
|
/* convert float to double */
|
||||||
DataManager::SetPosition(posd, aircraftNumber);
|
DataManager::SetPosition(posd, aircraftNumber);
|
||||||
@@ -750,9 +750,9 @@ namespace XPC
|
|||||||
campos.loc[0] = *(double*)(buffer+9);
|
campos.loc[0] = *(double*)(buffer+9);
|
||||||
campos.loc[1] = *(double*)(buffer+17);
|
campos.loc[1] = *(double*)(buffer+17);
|
||||||
campos.loc[2] = *(double*)(buffer+25);
|
campos.loc[2] = *(double*)(buffer+25);
|
||||||
campos.direction[0] = -998;
|
campos.direction[0] = -998;
|
||||||
campos.direction[1] = -998;
|
campos.direction[1] = -998;
|
||||||
campos.direction[2] = -998;
|
campos.direction[2] = -998;
|
||||||
campos.zoom = *(float*)(buffer+33);
|
campos.zoom = *(float*)(buffer+33);
|
||||||
|
|
||||||
Log::FormatLine(LOG_TRACE, "VIEW", "Cam pos %f %f %f zoom %f", campos.loc[0], campos.loc[1], campos.loc[2],campos.zoom);
|
Log::FormatLine(LOG_TRACE, "VIEW", "Cam pos %f %f %f zoom %f", campos.loc[0], campos.loc[1], campos.loc[2],campos.zoom);
|
||||||
@@ -781,41 +781,41 @@ namespace XPC
|
|||||||
|
|
||||||
// Log::FormatLine(LOG_TRACE, "CAM", "Cam pos %f %f %f", clat, clon, calt);
|
// Log::FormatLine(LOG_TRACE, "CAM", "Cam pos %f %f %f", clat, clon, calt);
|
||||||
|
|
||||||
if(campos->direction[0] == -998) // calculate camera direction
|
if(campos->direction[0] == -998) // calculate camera direction
|
||||||
{
|
{
|
||||||
// aircraft position
|
// aircraft position
|
||||||
double x = XPC::DataManager::GetDouble(XPC::DREF_LocalX, 0);
|
double x = XPC::DataManager::GetDouble(XPC::DREF_LocalX, 0);
|
||||||
double y = XPC::DataManager::GetDouble(XPC::DREF_LocalY, 0);
|
double y = XPC::DataManager::GetDouble(XPC::DREF_LocalY, 0);
|
||||||
double z = XPC::DataManager::GetDouble(XPC::DREF_LocalZ, 0);
|
double z = XPC::DataManager::GetDouble(XPC::DREF_LocalZ, 0);
|
||||||
|
|
||||||
// relative position vector cam to plane
|
// relative position vector cam to plane
|
||||||
double dx = x - cX;
|
double dx = x - cX;
|
||||||
double dy = y - cY;
|
double dy = y - cY;
|
||||||
double dz = z - cZ;
|
double dz = z - cZ;
|
||||||
|
|
||||||
// Log::FormatLine(LOG_TRACE, "CAM", "Cam vect %f %f %f", dx, dy, dz);
|
// Log::FormatLine(LOG_TRACE, "CAM", "Cam vect %f %f %f", dx, dy, dz);
|
||||||
|
|
||||||
double pi = 3.141592653589793;
|
double pi = 3.141592653589793;
|
||||||
|
|
||||||
// horizontal distance
|
// horizontal distance
|
||||||
double dist = sqrt(dx*dx + dz*dz);
|
double dist = sqrt(dx*dx + dz*dz);
|
||||||
|
|
||||||
outCameraPosition->pitch = atan2(dy, dist) * 180.0/pi;
|
outCameraPosition->pitch = atan2(dy, dist) * 180.0/pi;
|
||||||
|
|
||||||
double angle = atan2(dz, dx) * 180.0/pi; // rel to pos right (pos X)
|
double angle = atan2(dz, dx) * 180.0/pi; // rel to pos right (pos X)
|
||||||
|
|
||||||
outCameraPosition->heading = 90 + angle; // rel to north
|
outCameraPosition->heading = 90 + angle; // rel to north
|
||||||
|
|
||||||
// Log::FormatLine(LOG_TRACE, "CAM", "Cam p %f hdg %f ", outCameraPosition->pitch, outCameraPosition->heading);
|
// Log::FormatLine(LOG_TRACE, "CAM", "Cam p %f hdg %f ", outCameraPosition->pitch, outCameraPosition->heading);
|
||||||
|
|
||||||
outCameraPosition->roll = 0;
|
outCameraPosition->roll = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outCameraPosition->roll = campos->direction[0];
|
outCameraPosition->roll = campos->direction[0];
|
||||||
outCameraPosition->pitch = campos->direction[1];
|
outCameraPosition->pitch = campos->direction[1];
|
||||||
outCameraPosition->heading = campos->direction[2];
|
outCameraPosition->heading = campos->direction[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
outCameraPosition->zoom = campos->zoom;
|
outCameraPosition->zoom = campos->zoom;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace XPC
|
|||||||
/// Sets the socket that message handlers use to send responses.
|
/// Sets the socket that message handlers use to send responses.
|
||||||
static void SetSocket(UDPSocket* socket);
|
static void SetSocket(UDPSocket* socket);
|
||||||
|
|
||||||
static void SendBeacon(const std::string& pluginVersion, unsigned short pluginReceivePort, int xplaneVersion);
|
static void SendBeacon(const std::string& pluginVersion, unsigned short pluginReceivePort, int xplaneVersion);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// One handler per message type. Message types are descripbed on the
|
// One handler per message type. Message types are descripbed on the
|
||||||
|
|||||||
@@ -5,23 +5,23 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace XPC {
|
namespace XPC {
|
||||||
void Timer::start(const chrono::milliseconds interval, const Callback &callback) {
|
void Timer::start(const chrono::milliseconds interval, const Callback &callback) {
|
||||||
{
|
{
|
||||||
running.test_and_set();
|
running.test_and_set();
|
||||||
th = thread([=]()
|
th = thread([=]()
|
||||||
{
|
{
|
||||||
while (running.test_and_set()) {
|
while (running.test_and_set()) {
|
||||||
this_thread::sleep_for(interval);
|
this_thread::sleep_for(interval);
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::stop() {
|
void Timer::stop() {
|
||||||
running.clear();
|
running.clear();
|
||||||
if(th.joinable()) {
|
if(th.joinable()) {
|
||||||
th.join();
|
th.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,19 +11,19 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace XPC {
|
namespace XPC {
|
||||||
class Timer
|
class Timer
|
||||||
{
|
{
|
||||||
std::atomic_flag running;
|
std::atomic_flag running;
|
||||||
std::thread th;
|
std::thread th;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Callback = std::function<void(void)>;
|
using Callback = std::function<void(void)>;
|
||||||
|
|
||||||
void start(const std::chrono::milliseconds, const Callback &callback);
|
void start(const std::chrono::milliseconds, const Callback &callback);
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* Timer_hpp */
|
#endif /* Timer_hpp */
|
||||||
|
|||||||
@@ -139,17 +139,17 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sockaddr UDPSocket::GetAddr(std::string address, unsigned short port)
|
sockaddr UDPSocket::GetAddr(std::string address, unsigned short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = inet_addr(address.c_str());
|
addr.sin_addr.s_addr = inet_addr(address.c_str());
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
sockaddr* sa = reinterpret_cast<sockaddr*>(&addr);
|
sockaddr* sa = reinterpret_cast<sockaddr*>(&addr);
|
||||||
return *sa;
|
return *sa;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UDPSocket::GetHost(sockaddr* sa)
|
std::string UDPSocket::GetHost(sockaddr* sa)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace XPC
|
|||||||
/// \returns A string representation of the socket address.
|
/// \returns A string representation of the socket address.
|
||||||
static std::string GetHost(sockaddr* addr);
|
static std::string GetHost(sockaddr* addr);
|
||||||
|
|
||||||
static sockaddr GetAddr(std::string address, unsigned short port);
|
static sockaddr GetAddr(std::string address, unsigned short port);
|
||||||
private:
|
private:
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
SOCKET sock;
|
SOCKET sock;
|
||||||
|
|||||||
Reference in New Issue
Block a user