Add support for sendCOMM method

Credits go to user @angelsware, I just did a copy/paste from #120
This commit is contained in:
Sander Datema
2020-06-27 21:14:42 +02:00
parent 76f7d28ac8
commit 388329b218
10 changed files with 211 additions and 53 deletions

View File

@@ -19,6 +19,7 @@
#include "XPLMDataAccess.h"
#include "XPLMGraphics.h"
#include "XPLMUtilities.h"
#include <algorithm>
#include <cmath>
@@ -791,6 +792,21 @@ namespace XPC
Set(DREF_FlapActual, value);
}
void DataManager::Execute(const std::string& comm)
{
Log::FormatLine(LOG_INFO, "DMAN", "Executing command (value:%s)", comm.c_str());
XPLMCommandRef xcref = XPLMFindCommand(comm.c_str());
if (!xcref)
{
// COMM does not exist
Log::FormatLine(LOG_ERROR, "DMAN", "ERROR: invalid COMM %s", comm.c_str());
return;
}
XPLMCommandOnce(xcref);
}
float DataManager::GetDefaultValue()
{
return -998.0F;

View File

@@ -410,6 +410,11 @@ namespace XPC
/// \param value The flaps settings. Should be between 0.0 (no flaps) and 1.0 (full flaps).
static void SetFlaps(float value);
/// Executes a command
///
/// \param comm The name of the command to execute.
static void Execute(const std::string& comm);
/// Gets a default value that indicates that a dataref should not be changed.
static float GetDefaultValue();

View File

@@ -176,6 +176,11 @@ namespace XPC
ss << "Type:" << *((unsigned long*)(buffer + 5));
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
}
else if (head == "COMM")
{
ss << "Type:" << *((unsigned long*)(buffer + 5));
Log::WriteLine(LOG_DEBUG, "DBUG", ss.str());
}
else
{
ss << " UNKNOWN HEADER ";

View File

@@ -70,6 +70,7 @@ namespace XPC
handlers.insert(std::make_pair("VIEW", MessageHandlers::HandleView));
handlers.insert(std::make_pair("GETC", MessageHandlers::HandleGetC));
handlers.insert(std::make_pair("GETP", MessageHandlers::HandleGetP));
handlers.insert(std::make_pair("COMM", MessageHandlers::HandleComm));
handlers.insert(std::make_pair("GETT", MessageHandlers::HandleGetT));
// X-Plane data messages
handlers.insert(std::make_pair("DSEL", MessageHandlers::HandleXPlaneData));
@@ -916,6 +917,31 @@ namespace XPC
}
}
void MessageHandlers::HandleComm(const Message& msg)
{
Log::FormatLine(LOG_TRACE, "COMM", "Request to execute COMM command received (Conn %i)", connection.id);
const unsigned char* buffer = msg.GetBuffer();
std::size_t size = msg.GetSize();
std::size_t pos = 5;
while (pos < size)
{
unsigned char len = buffer[pos++];
if (pos + len > size)
{
break;
}
std::string comm = std::string((char*)buffer + pos, len);
pos += len;
DataManager::Execute(comm);
Log::FormatLine(LOG_DEBUG, "COMM", "Execute command %s", comm.c_str());
}
if (pos != size)
{
Log::WriteLine(LOG_ERROR, "COMM", "ERROR: Command did not terminate at the expected position.");
}
}
void MessageHandlers::HandleWypt(const Message& msg)
{
// Update Log

View File

@@ -77,6 +77,7 @@ namespace XPC
static void HandleText(const Message& msg);
static void HandleWypt(const Message& msg);
static void HandleView(const Message& msg);
static void HandleComm(const Message& msg);
static void HandleXPlaneData(const Message& msg);
static void HandleUnknown(const Message& msg);

View File

@@ -221,6 +221,7 @@
"APL=1",
"IBM=0",
"LIN=0",
XPLM200,
);
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
GCC_VERSION = "";
@@ -274,6 +275,7 @@
"APL=1",
"IBM=0",
"LIN=0",
XPLM200,
);
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
GCC_VERSION = "";