Changed types from fixed width types in stdint to language primitive types guaranteed to be at least as big.
This commit is contained in:
@@ -251,7 +251,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double DataManager::GetDouble(DREF dref, std::uint8_t aircraft)
|
double DataManager::GetDouble(DREF dref, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
double value = XPLMGetDatad(xdref);
|
double value = XPLMGetDatad(xdref);
|
||||||
@@ -261,7 +261,7 @@ namespace XPC
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DataManager::GetFloat(DREF dref, std::uint8_t aircraft)
|
float DataManager::GetFloat(DREF dref, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
float value = XPLMGetDataf(xdref);
|
float value = XPLMGetDataf(xdref);
|
||||||
@@ -271,7 +271,7 @@ namespace XPC
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DataManager::GetInt(DREF dref, std::uint8_t aircraft)
|
int DataManager::GetInt(DREF dref, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
int value = XPLMGetDatai(xdref);
|
int value = XPLMGetDatai(xdref);
|
||||||
@@ -281,7 +281,7 @@ namespace XPC
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DataManager::GetFloatArray(DREF dref, float values[], int size, std::uint8_t aircraft)
|
int DataManager::GetFloatArray(DREF dref, float values[], int size, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
int resultSize = XPLMGetDatavf(xdref, values, 0, size);
|
int resultSize = XPLMGetDatavf(xdref, values, 0, size);
|
||||||
@@ -291,7 +291,7 @@ namespace XPC
|
|||||||
return resultSize;
|
return resultSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DataManager::GetIntArray(DREF dref, int values[], int size, std::uint8_t aircraft)
|
int DataManager::GetIntArray(DREF dref, int values[], int size, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
int resultSize = XPLMGetDatavi(xdref, values, 0, size);
|
int resultSize = XPLMGetDatavi(xdref, values, 0, size);
|
||||||
@@ -301,7 +301,7 @@ namespace XPC
|
|||||||
return resultSize;
|
return resultSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::Set(DREF dref, double value, std::uint8_t aircraft)
|
void DataManager::Set(DREF dref, double value, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
@@ -310,7 +310,7 @@ namespace XPC
|
|||||||
XPLMSetDatad(xdref, value);
|
XPLMSetDatad(xdref, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::Set(DREF dref, float value, std::uint8_t aircraft)
|
void DataManager::Set(DREF dref, float value, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
@@ -319,7 +319,7 @@ namespace XPC
|
|||||||
XPLMSetDataf(xdref, value);
|
XPLMSetDataf(xdref, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::Set(DREF dref, int value, std::uint8_t aircraft)
|
void DataManager::Set(DREF dref, int value, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
@@ -328,7 +328,7 @@ namespace XPC
|
|||||||
XPLMSetDatai(xdref, value);
|
XPLMSetDatai(xdref, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::Set(DREF dref, float values[], int size, std::uint8_t aircraft)
|
void DataManager::Set(DREF dref, float values[], int size, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
@@ -339,7 +339,7 @@ namespace XPC
|
|||||||
XPLMSetDatavf(xdref, values, 0, drefSize);
|
XPLMSetDatavf(xdref, values, 0, drefSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::Set(DREF dref, int values[], int size, std::uint8_t aircraft)
|
void DataManager::Set(DREF dref, int values[], int size, char aircraft)
|
||||||
{
|
{
|
||||||
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
@@ -417,7 +417,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::SetGear(float gear, bool immediate, std::uint8_t aircraft)
|
void DataManager::SetGear(float gear, bool immediate, char aircraft)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 3
|
#if LOG_VERBOSITY > 3
|
||||||
Log::FormatLine("[DMAN] Setting gear (value:%f, immediate:%i) for aircraft %i", gear, immediate, aircraft);
|
Log::FormatLine("[DMAN] Setting gear (value:%f, immediate:%i) for aircraft %i", gear, immediate, aircraft);
|
||||||
@@ -453,7 +453,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::SetPosition(float pos[3], std::uint8_t aircraft)
|
void DataManager::SetPosition(float pos[3], char aircraft)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 3
|
#if LOG_VERBOSITY > 3
|
||||||
Log::FormatLine("[DMAN] Setting position (%f, %f, %f) for aircraft %i", pos[0], pos[1], pos[2], aircraft);
|
Log::FormatLine("[DMAN] Setting position (%f, %f, %f) for aircraft %i", pos[0], pos[1], pos[2], aircraft);
|
||||||
@@ -488,7 +488,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::SetOrientation(float orient[3], std::uint8_t aircraft)
|
void DataManager::SetOrientation(float orient[3], char aircraft)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 3
|
#if LOG_VERBOSITY > 3
|
||||||
Log::FormatLine("[DMAN] Setting orientation (%f, %f, %f) for aircraft %i",
|
Log::FormatLine("[DMAN] Setting orientation (%f, %f, %f) for aircraft %i",
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#ifndef XPC_DATAMANAGER_H
|
#ifndef XPC_DATAMANAGER_H
|
||||||
#define XPC_DATAMANAGER_H
|
#define XPC_DATAMANAGER_H
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace XPC
|
namespace XPC
|
||||||
@@ -189,7 +188,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static double GetDouble(DREF dref, std::uint8_t aircraft = 0);
|
static double GetDouble(DREF dref, char aircraft = 0);
|
||||||
|
|
||||||
/// Gets the value of a float dataref.
|
/// Gets the value of a float dataref.
|
||||||
///
|
///
|
||||||
@@ -208,7 +207,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static float GetFloat(DREF dref, std::uint8_t aircraft = 0);
|
static float GetFloat(DREF dref, char aircraft = 0);
|
||||||
|
|
||||||
/// Gets the value of an integer dataref.
|
/// Gets the value of an integer dataref.
|
||||||
///
|
///
|
||||||
@@ -227,7 +226,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static int GetInt(DREF dref, std::uint8_t aircraft = 0);
|
static int GetInt(DREF dref, char aircraft = 0);
|
||||||
|
|
||||||
/// Gets the value of a float array dataref.
|
/// Gets the value of a float array dataref.
|
||||||
///
|
///
|
||||||
@@ -248,7 +247,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static int GetFloatArray(DREF dref, float values[], int size, std::uint8_t aircraft = 0);
|
static int GetFloatArray(DREF dref, float values[], int size, char aircraft = 0);
|
||||||
|
|
||||||
|
|
||||||
/// Gets the value of an int array dataref.
|
/// Gets the value of an int array dataref.
|
||||||
@@ -270,7 +269,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static int GetIntArray(DREF dref, int values[], int size, std::uint8_t aircraft = 0);
|
static int GetIntArray(DREF dref, int values[], int size, char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the value of a dataref
|
/// Sets the value of a dataref
|
||||||
///
|
///
|
||||||
@@ -307,7 +306,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static void Set(DREF dref, double value, std::uint8_t aircraft = 0);
|
static void Set(DREF dref, double value, char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the value of a float dataref.
|
/// Sets the value of a float dataref.
|
||||||
///
|
///
|
||||||
@@ -324,7 +323,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static void Set(DREF dref, float value, std::uint8_t aircraft = 0);
|
static void Set(DREF dref, float value, char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the value of an integer dataref.
|
/// Sets the value of an integer dataref.
|
||||||
///
|
///
|
||||||
@@ -341,7 +340,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static void Set(DREF dref, int value, std::uint8_t aircraft = 0);
|
static void Set(DREF dref, int value, char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the value of a float array dataref.
|
/// Sets the value of a float array dataref.
|
||||||
///
|
///
|
||||||
@@ -359,7 +358,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static void Set(DREF dref, float values[], int size, std::uint8_t aircraft = 0);
|
static void Set(DREF dref, float values[], int size, char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the value of an integer array dataref.
|
/// Sets the value of an integer array dataref.
|
||||||
///
|
///
|
||||||
@@ -377,7 +376,7 @@ namespace XPC
|
|||||||
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
/// method, most drefs are not valid for multiplayer aircraft. All drefs
|
||||||
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
/// that are not prefixed with 'MP' are valid for the player aircraft.
|
||||||
/// 'MP' drefs should be called with aircraft 0.
|
/// 'MP' drefs should be called with aircraft 0.
|
||||||
static void Set(DREF dref, int values[], int size, std::uint8_t aircraft = 0);
|
static void Set(DREF dref, int values[], int size, char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the landing gear for the specified airplane.
|
/// Sets the landing gear for the specified airplane.
|
||||||
///
|
///
|
||||||
@@ -385,21 +384,21 @@ namespace XPC
|
|||||||
/// \param immediate Whether the gear should be forced to the specified position.
|
/// \param immediate Whether the gear should be forced to the specified position.
|
||||||
/// If immediate is false, only the gear handle dref will be set.
|
/// If immediate is false, only the gear handle dref will be set.
|
||||||
/// \param aircraft The aircraft to set the landing gear status on.
|
/// \param aircraft The aircraft to set the landing gear status on.
|
||||||
static void SetGear(float gear, bool immediate, std::uint8_t aircraft = 0);
|
static void SetGear(float gear, bool immediate, char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the position of the specified aircraft on the Earth.
|
/// Sets the position of the specified aircraft on the Earth.
|
||||||
///
|
///
|
||||||
/// \param pos An array containing latitude, longitude and altitude in
|
/// \param pos An array containing latitude, longitude and altitude in
|
||||||
/// fractional degrees and meters above sea level.
|
/// fractional degrees and meters above sea level.
|
||||||
/// \param aircraft The aircraft to set the position of.
|
/// \param aircraft The aircraft to set the position of.
|
||||||
static void SetPosition(float pos[3], std::uint8_t aircraft = 0);
|
static void SetPosition(float pos[3], char aircraft = 0);
|
||||||
|
|
||||||
/// Sets the orientation of the specified aircraft.
|
/// Sets the orientation of the specified aircraft.
|
||||||
///
|
///
|
||||||
/// \param orient An array containing the pitch, roll, and yaw orientations
|
/// \param orient An array containing the pitch, roll, and yaw orientations
|
||||||
/// to set, all in fractional degrees.
|
/// to set, all in fractional degrees.
|
||||||
/// \param aircraft The aircraft to set the orientation of.
|
/// \param aircraft The aircraft to set the orientation of.
|
||||||
static void SetOrientation(float orient[3], std::uint8_t aircraft = 0);
|
static void SetOrientation(float orient[3], char aircraft = 0);
|
||||||
|
|
||||||
/// Sets flaps on the the player aircraft.
|
/// Sets flaps on the the player aircraft.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ namespace XPC
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t Message::GetMagicNumber()
|
unsigned long Message::GetMagicNumber()
|
||||||
{
|
{
|
||||||
if (size < 4)
|
if (size < 4)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return *((std::uint32_t*)buffer);
|
return *((unsigned long*)buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Message::GetHead()
|
std::string Message::GetHead()
|
||||||
@@ -38,7 +38,7 @@ namespace XPC
|
|||||||
return std::string((char*)buffer, 4);
|
return std::string((char*)buffer, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::uint8_t* Message::GetBuffer()
|
const unsigned char* Message::GetBuffer()
|
||||||
{
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ namespace XPC
|
|||||||
static Message ReadFrom(UDPSocket& sock);
|
static Message ReadFrom(UDPSocket& sock);
|
||||||
|
|
||||||
/// Gets the message header in binary form.
|
/// Gets the message header in binary form.
|
||||||
std::uint32_t GetMagicNumber();
|
unsigned long GetMagicNumber();
|
||||||
|
|
||||||
/// Gets the message header.
|
/// Gets the message header.
|
||||||
std::string GetHead();
|
std::string GetHead();
|
||||||
|
|
||||||
/// Gets the buffer underlying the message.
|
/// Gets the buffer underlying the message.
|
||||||
const std::uint8_t* GetBuffer();
|
const unsigned char* GetBuffer();
|
||||||
|
|
||||||
/// Gets the size of the message in bytes.
|
/// Gets the size of the message in bytes.
|
||||||
std::size_t GetSize();
|
std::size_t GetSize();
|
||||||
@@ -48,7 +48,7 @@ namespace XPC
|
|||||||
Message();
|
Message();
|
||||||
|
|
||||||
static const std::size_t bufferSize = 4096;
|
static const std::size_t bufferSize = 4096;
|
||||||
std::uint8_t buffer[bufferSize];
|
unsigned char buffer[bufferSize];
|
||||||
std::size_t size;
|
std::size_t size;
|
||||||
struct sockaddr source;
|
struct sockaddr source;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace XPC
|
|||||||
return std::string(ip);
|
return std::string(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::uint16_t getPort(sockaddr* sa)
|
static unsigned short getPort(sockaddr* sa)
|
||||||
{
|
{
|
||||||
switch (sa->sa_family)
|
switch (sa->sa_family)
|
||||||
{
|
{
|
||||||
@@ -110,7 +110,7 @@ namespace XPC
|
|||||||
// Set current connection
|
// Set current connection
|
||||||
sockaddr sourceaddr = msg.GetSource();
|
sockaddr sourceaddr = msg.GetSource();
|
||||||
std::string ip = getIP(&sourceaddr);
|
std::string ip = getIP(&sourceaddr);
|
||||||
std::uint16_t port = getPort(&sourceaddr);
|
unsigned short port = getPort(&sourceaddr);
|
||||||
connectionKey = ip + ":" + std::to_string(port);
|
connectionKey = ip + ":" + std::to_string(port);
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
Log::FormatLine("[MSGH] Handling message from %s", connectionKey.c_str());
|
Log::FormatLine("[MSGH] Handling message from %s", connectionKey.c_str());
|
||||||
@@ -159,14 +159,14 @@ namespace XPC
|
|||||||
|
|
||||||
void MessageHandlers::HandleConn(Message& msg)
|
void MessageHandlers::HandleConn(Message& msg)
|
||||||
{
|
{
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
|
|
||||||
// Store new port
|
// Store new port
|
||||||
connection.dstPort = *((std::uint16_t*)(buffer + 5));
|
connection.dstPort = *((unsigned short*)(buffer + 5));
|
||||||
connections[connectionKey] = connection;
|
connections[connectionKey] = connection;
|
||||||
|
|
||||||
// Create response
|
// Create response
|
||||||
std::uint8_t response[6] = "CONF";
|
unsigned char response[6] = "CONF";
|
||||||
response[5] = connection.id;
|
response[5] = connection.id;
|
||||||
|
|
||||||
// Update log
|
// Update log
|
||||||
@@ -186,7 +186,7 @@ namespace XPC
|
|||||||
Log::FormatLine("[CTRL] Message Received (Conn %i)", connection.id);
|
Log::FormatLine("[CTRL] Message Received (Conn %i)", connection.id);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
std::size_t size = msg.GetSize();
|
std::size_t size = msg.GetSize();
|
||||||
//Legacy packets that don't specify an aircraft number should be 26 bytes long.
|
//Legacy packets that don't specify an aircraft number should be 26 bytes long.
|
||||||
//Packets specifying an A/C num should be 27 bytes.
|
//Packets specifying an A/C num should be 27 bytes.
|
||||||
@@ -203,9 +203,9 @@ namespace XPC
|
|||||||
float roll = *((float*)(buffer + 9));
|
float roll = *((float*)(buffer + 9));
|
||||||
float yaw = *((float*)(buffer + 13));
|
float yaw = *((float*)(buffer + 13));
|
||||||
float thr = *((float*)(buffer + 17));
|
float thr = *((float*)(buffer + 17));
|
||||||
std::int8_t gear = buffer[21];
|
char gear = buffer[21];
|
||||||
float flaps = *((float*)(buffer + 22));
|
float flaps = *((float*)(buffer + 22));
|
||||||
std::uint8_t aircraft = 0;
|
unsigned char aircraft = 0;
|
||||||
if (size == 27)
|
if (size == 27)
|
||||||
{
|
{
|
||||||
aircraft = buffer[26];
|
aircraft = buffer[26];
|
||||||
@@ -239,7 +239,7 @@ namespace XPC
|
|||||||
void MessageHandlers::HandleData(Message& msg)
|
void MessageHandlers::HandleData(Message& msg)
|
||||||
{
|
{
|
||||||
// Parse data
|
// Parse data
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
std::size_t size = msg.GetSize();
|
std::size_t size = msg.GetSize();
|
||||||
std::size_t numCols = (size - 5) / 36;
|
std::size_t numCols = (size - 5) / 36;
|
||||||
if (numCols > 0)
|
if (numCols > 0)
|
||||||
@@ -275,7 +275,7 @@ namespace XPC
|
|||||||
float savedHPath = -998;
|
float savedHPath = -998;
|
||||||
for (int i = 0; i < numCols; ++i)
|
for (int i = 0; i < numCols; ++i)
|
||||||
{
|
{
|
||||||
std::uint8_t dataRef = (std::uint8_t)values[i][0];
|
unsigned char dataRef = (unsigned char)values[i][0];
|
||||||
if (dataRef > 134)
|
if (dataRef > 134)
|
||||||
{
|
{
|
||||||
Log::FormatLine("[DATA] ERROR: DataRef # must be between 0 - 134 (Received: %hi)", (int)dataRef);
|
Log::FormatLine("[DATA] ERROR: DataRef # must be between 0 - 134 (Received: %hi)", (int)dataRef);
|
||||||
@@ -400,11 +400,11 @@ namespace XPC
|
|||||||
|
|
||||||
void MessageHandlers::HandleDref(Message& msg)
|
void MessageHandlers::HandleDref(Message& msg)
|
||||||
{
|
{
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
std::uint8_t len = buffer[5];
|
unsigned char len = buffer[5];
|
||||||
std::string dref = std::string((char*)buffer + 6, len);
|
std::string dref = std::string((char*)buffer + 6, len);
|
||||||
|
|
||||||
std::uint8_t valueCount = buffer[6 + len];
|
unsigned char valueCount = buffer[6 + len];
|
||||||
float values[40];
|
float values[40];
|
||||||
memcpy(values, buffer + len + 7, valueCount * sizeof(float));
|
memcpy(values, buffer + len + 7, valueCount * sizeof(float));
|
||||||
|
|
||||||
@@ -417,8 +417,8 @@ namespace XPC
|
|||||||
|
|
||||||
void MessageHandlers::HandleGetD(Message& msg)
|
void MessageHandlers::HandleGetD(Message& msg)
|
||||||
{
|
{
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
std::uint8_t drefCount = buffer[5];
|
unsigned char drefCount = buffer[5];
|
||||||
if (drefCount == 0) // Use last request
|
if (drefCount == 0) // Use last request
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
@@ -442,7 +442,7 @@ namespace XPC
|
|||||||
std::size_t ptr = 6;
|
std::size_t ptr = 6;
|
||||||
for (int i = 0; i < drefCount; ++i)
|
for (int i = 0; i < drefCount; ++i)
|
||||||
{
|
{
|
||||||
std::uint8_t len = buffer[ptr];
|
unsigned char len = buffer[ptr];
|
||||||
connection.getdRequest[i] = std::string((char*)buffer + 1 + ptr, len);
|
connection.getdRequest[i] = std::string((char*)buffer + 1 + ptr, len);
|
||||||
ptr += 1 + len;
|
ptr += 1 + len;
|
||||||
}
|
}
|
||||||
@@ -450,7 +450,7 @@ namespace XPC
|
|||||||
connections[connectionKey] = connection;
|
connections[connectionKey] = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint8_t response[4096] = "RESP";
|
unsigned char response[4096] = "RESP";
|
||||||
response[5] = drefCount;
|
response[5] = drefCount;
|
||||||
std::size_t cur = 6;
|
std::size_t cur = 6;
|
||||||
for (int i = 0; i < drefCount; ++i)
|
for (int i = 0; i < drefCount; ++i)
|
||||||
@@ -472,7 +472,7 @@ namespace XPC
|
|||||||
Log::FormatLine("[POSI] Message Received (Conn %i)", connection.id);
|
Log::FormatLine("[POSI] Message Received (Conn %i)", connection.id);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
const std::size_t size = msg.GetSize();
|
const std::size_t size = msg.GetSize();
|
||||||
if (size < 34)
|
if (size < 34)
|
||||||
{
|
{
|
||||||
@@ -482,7 +482,7 @@ namespace XPC
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int8_t aircraft = buffer[5];
|
char aircraft = buffer[5];
|
||||||
float gear = *((float*)(buffer + 30));
|
float gear = *((float*)(buffer + 30));
|
||||||
float pos[3];
|
float pos[3];
|
||||||
float orient[3];
|
float orient[3];
|
||||||
@@ -516,7 +516,7 @@ namespace XPC
|
|||||||
Log::FormatLine("[SIMU] Message Received (Conn %i)", connection.id);
|
Log::FormatLine("[SIMU] Message Received (Conn %i)", connection.id);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
|
|
||||||
// Set DREF
|
// Set DREF
|
||||||
int value = buffer[5];
|
int value = buffer[5];
|
||||||
@@ -542,7 +542,7 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::size_t len = msg.GetSize();
|
std::size_t len = msg.GetSize();
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
|
|
||||||
char text[256] = { 0 };
|
char text[256] = { 0 };
|
||||||
if (len < 14)
|
if (len < 14)
|
||||||
@@ -580,11 +580,11 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Parse data
|
// Parse data
|
||||||
const std::uint8_t* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
std::uint8_t op = buffer[5];
|
unsigned char op = buffer[5];
|
||||||
std::uint8_t count = buffer[6];
|
unsigned char count = buffer[6];
|
||||||
Waypoint points[255];
|
Waypoint points[255];
|
||||||
const std::uint8_t* ptr = buffer + 7;
|
const unsigned char* ptr = buffer + 7;
|
||||||
for (size_t i = 0; i < count; ++i)
|
for (size_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
points[i].latitude = *((float*)ptr);
|
points[i].latitude = *((float*)ptr);
|
||||||
@@ -621,7 +621,7 @@ namespace XPC
|
|||||||
#if LOG_VERBOSITY > 1
|
#if LOG_VERBOSITY > 1
|
||||||
Log::WriteLine("[MSGH] Sending raw data to X-Plane");
|
Log::WriteLine("[MSGH] Sending raw data to X-Plane");
|
||||||
#endif
|
#endif
|
||||||
sock->SendTo((std::uint8_t*)msg.GetBuffer(), msg.GetSize(), "127.0.0.1", 49000);
|
sock->SendTo((unsigned char*)msg.GetBuffer(), msg.GetSize(), "127.0.0.1", 49000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleUnknown(Message& msg)
|
void MessageHandlers::HandleUnknown(Message& msg)
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ namespace XPC
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
std::uint8_t id;
|
unsigned char id;
|
||||||
std::string ip;
|
std::string ip;
|
||||||
std::uint16_t dstPort;
|
unsigned short dstPort;
|
||||||
std::uint16_t srcPort;
|
unsigned short srcPort;
|
||||||
std::uint8_t getdCount;
|
unsigned char getdCount;
|
||||||
std::string getdRequest[255];
|
std::string getdRequest[255];
|
||||||
} ConnectionInfo;
|
} ConnectionInfo;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
namespace XPC
|
namespace XPC
|
||||||
{
|
{
|
||||||
UDPSocket::UDPSocket(std::uint16_t recvPort)
|
UDPSocket::UDPSocket(unsigned short recvPort)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 1
|
#if LOG_VERBOSITY > 1
|
||||||
Log::FormatLine("[SOCK] Opening socket (port:%d)", recvPort);
|
Log::FormatLine("[SOCK] Opening socket (port:%d)", recvPort);
|
||||||
@@ -86,7 +86,7 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPSocket::Read(std::uint8_t* dst, int maxLen, sockaddr* recvAddr)
|
int UDPSocket::Read(unsigned char* dst, int maxLen, sockaddr* recvAddr)
|
||||||
{
|
{
|
||||||
socklen_t recvaddrlen = sizeof(*recvAddr);
|
socklen_t recvaddrlen = sizeof(*recvAddr);
|
||||||
int status = 0;
|
int status = 0;
|
||||||
@@ -132,7 +132,7 @@ namespace XPC
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add IPV6 support
|
// TODO: Add IPV6 support
|
||||||
void UDPSocket::SendTo(std::uint8_t* buffer, std::size_t len, std::string remoteHost, std::uint16_t remotePort)
|
void UDPSocket::SendTo(unsigned char* buffer, std::size_t len, std::string remoteHost, unsigned short remotePort)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 4
|
#if LOG_VERBOSITY > 4
|
||||||
Log::FormatLine("[SOCK] Sending message to %s:%u (length=%u)", remoteHost.c_str(), remotePort, len);
|
Log::FormatLine("[SOCK] Sending message to %s:%u (length=%u)", remoteHost.c_str(), remotePort, len);
|
||||||
@@ -141,12 +141,12 @@ namespace XPC
|
|||||||
{
|
{
|
||||||
remoteHost = "127.0.0.1";
|
remoteHost = "127.0.0.1";
|
||||||
}
|
}
|
||||||
std::uint32_t ip;
|
unsigned long ip;
|
||||||
inet_pton(AF_INET, remoteHost.c_str(), &ip);
|
inet_pton(AF_INET, remoteHost.c_str(), &ip);
|
||||||
SendTo(buffer, len, ip, remotePort);
|
SendTo(buffer, len, ip, remotePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDPSocket::SendTo(std::uint8_t* buffer, std::size_t len, std::uint32_t remoteIP, std::uint16_t remotePort)
|
void UDPSocket::SendTo(unsigned char* buffer, std::size_t len, unsigned long remoteIP, unsigned short remotePort)
|
||||||
{
|
{
|
||||||
struct sockaddr_in remoteAddr;
|
struct sockaddr_in remoteAddr;
|
||||||
remoteAddr.sin_family = AF_INET;
|
remoteAddr.sin_family = AF_INET;
|
||||||
@@ -160,7 +160,7 @@ namespace XPC
|
|||||||
#endif
|
#endif
|
||||||
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
|
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
|
||||||
|
|
||||||
buffer[4] = (std::uint8_t)len;
|
buffer[4] = (unsigned char)len;
|
||||||
if (sendto(sock, (char*)buffer, (int)len, 0, (const struct sockaddr *) &remoteAddr, sizeof(remoteAddr)) < 0)
|
if (sendto(sock, (char*)buffer, (int)len, 0, (const struct sockaddr *) &remoteAddr, sizeof(remoteAddr)) < 0)
|
||||||
{
|
{
|
||||||
#if LOG_VERBOSITY > 0
|
#if LOG_VERBOSITY > 0
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#ifndef XPC_SOCKET_H
|
#ifndef XPC_SOCKET_H
|
||||||
#define XPC_SOCKET_H
|
#define XPC_SOCKET_H
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -35,7 +34,7 @@ namespace XPC
|
|||||||
/// specified receive port.
|
/// specified receive port.
|
||||||
///
|
///
|
||||||
/// \param recvPort The port on which this instance will receive data.
|
/// \param recvPort The port on which this instance will receive data.
|
||||||
UDPSocket(std::uint16_t recvPort);
|
UDPSocket(unsigned short recvPort);
|
||||||
|
|
||||||
/// Closes the underlying socket for this instance.
|
/// Closes the underlying socket for this instance.
|
||||||
~UDPSocket();
|
~UDPSocket();
|
||||||
@@ -49,7 +48,7 @@ namespace XPC
|
|||||||
/// of the remote host.
|
/// of the remote host.
|
||||||
/// \returns The number of bytes read, or a negative number if
|
/// \returns The number of bytes read, or a negative number if
|
||||||
/// an error occurs.
|
/// an error occurs.
|
||||||
int Read(std::uint8_t* buffer, int size, sockaddr* remoteAddr);
|
int Read(unsigned char* buffer, int size, sockaddr* remoteAddr);
|
||||||
|
|
||||||
/// Sends data to the specified remote endpoint.
|
/// Sends data to the specified remote endpoint.
|
||||||
///
|
///
|
||||||
@@ -57,7 +56,7 @@ namespace XPC
|
|||||||
/// \param len The number of bytes to send.
|
/// \param len The number of bytes to send.
|
||||||
/// \param remoteHost The hostname of the destination client.
|
/// \param remoteHost The hostname of the destination client.
|
||||||
/// \param remotePort The port of the destination client.
|
/// \param remotePort The port of the destination client.
|
||||||
void SendTo(std::uint8_t* buffer, std::size_t len, std::string remoteHost, std::uint16_t remotePort);
|
void SendTo(unsigned char* buffer, std::size_t len, std::string remoteHost, unsigned short remotePort);
|
||||||
|
|
||||||
/// Sends data to the specified remote endpoint.
|
/// Sends data to the specified remote endpoint.
|
||||||
///
|
///
|
||||||
@@ -65,7 +64,7 @@ namespace XPC
|
|||||||
/// \param len The number of bytes to send.
|
/// \param len The number of bytes to send.
|
||||||
/// \param remoteHost The hostname of the destination client.
|
/// \param remoteHost The hostname of the destination client.
|
||||||
/// \param remotePort The port of the destination client.
|
/// \param remotePort The port of the destination client.
|
||||||
void UDPSocket::SendTo(std::uint8_t* buffer, std::size_t len, std::uint32_t remoteIP, std::uint16_t remotePort);
|
void UDPSocket::SendTo(unsigned char* buffer, std::size_t len, unsigned long remoteIP, unsigned short remotePort);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|||||||
Reference in New Issue
Block a user