Fix incorrect gear read in HandlePosi
This commit is contained in:
@@ -141,11 +141,25 @@ namespace XPC
|
|||||||
else if (head == "POSI")
|
else if (head == "POSI")
|
||||||
{
|
{
|
||||||
char aircraft = buffer[5];
|
char aircraft = buffer[5];
|
||||||
float gear = *((float*)(buffer + 30));
|
float gear;
|
||||||
float pos[3];
|
double pos[3];
|
||||||
float orient[3];
|
float orient[3];
|
||||||
memcpy(pos, buffer + 6, 12);
|
if (size == 34) /* lat/lon/h as 32-bit float */
|
||||||
memcpy(orient, buffer + 18, 12);
|
{
|
||||||
|
float posd_32[3];
|
||||||
|
memcpy(posd_32, buffer + 6, 12);
|
||||||
|
pos[0] = posd_32[0];
|
||||||
|
pos[1] = posd_32[1];
|
||||||
|
pos[2] = posd_32[2];
|
||||||
|
memcpy(orient, buffer + 18, 12);
|
||||||
|
memcpy(&gear, buffer + 30, 4);
|
||||||
|
}
|
||||||
|
else if (size == 46) /* lat/lon/h as 64-bit double */
|
||||||
|
{
|
||||||
|
memcpy(pos, buffer + 6, 24);
|
||||||
|
memcpy(orient, buffer + 30, 12);
|
||||||
|
memcpy(&gear, buffer + 42, 4);
|
||||||
|
}
|
||||||
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:";
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace XPC
|
|||||||
std::string MessageHandlers::connectionKey;
|
std::string MessageHandlers::connectionKey;
|
||||||
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,11 +136,11 @@ namespace XPC
|
|||||||
MessageHandlers::HandleUnknown(msg);
|
MessageHandlers::HandleUnknown(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -150,12 +150,12 @@ namespace XPC
|
|||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,21 +580,25 @@ namespace XPC
|
|||||||
const std::size_t size = msg.GetSize();
|
const std::size_t size = msg.GetSize();
|
||||||
|
|
||||||
char aircraftNumber = buffer[5];
|
char aircraftNumber = buffer[5];
|
||||||
float gear = *((float*)(buffer + 42));
|
float gear;
|
||||||
double posd[3];
|
double posd[3];
|
||||||
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]);
|
float posd_32[3];
|
||||||
posd[1] = *((float*)&buffer[10]);
|
memcpy(posd_32, buffer + 6, 12);
|
||||||
posd[2] = *((float*)&buffer[14]);
|
posd[0] = posd_32[0];
|
||||||
|
posd[1] = posd_32[1];
|
||||||
|
posd[2] = posd_32[2];
|
||||||
memcpy(orient, buffer + 18, 12);
|
memcpy(orient, buffer + 18, 12);
|
||||||
|
memcpy(&gear, buffer + 30, 4);
|
||||||
}
|
}
|
||||||
else if (size == 46) /* lat/lon/h as 64-bit double */
|
else if (size == 46) /* lat/lon/h as 64-bit double */
|
||||||
{
|
{
|
||||||
memcpy(posd, buffer + 6, 3*8);
|
memcpy(posd, buffer + 6, 24);
|
||||||
memcpy(orient, buffer + 30, 12);
|
memcpy(orient, buffer + 30, 12);
|
||||||
|
memcpy(&gear, buffer + 42, 4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -717,14 +721,14 @@ namespace XPC
|
|||||||
Log::WriteLine(LOG_INFO, "TEXT", "[TEXT] Text set");
|
Log::WriteLine(LOG_INFO, "TEXT", "[TEXT] Text set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandlers::HandleView(const Message& msg)
|
void MessageHandlers::HandleView(const Message& msg)
|
||||||
{
|
{
|
||||||
// Update Log
|
// Update Log
|
||||||
Log::FormatLine(LOG_TRACE, "VIEW", "Message Received(Conn %i)", connection.id);
|
Log::FormatLine(LOG_TRACE, "VIEW", "Message Received(Conn %i)", connection.id);
|
||||||
|
|
||||||
int enable_camera_location = 0;
|
int enable_camera_location = 0;
|
||||||
|
|
||||||
const std::size_t size = msg.GetSize();
|
const std::size_t size = msg.GetSize();
|
||||||
if (size == 9)
|
if (size == 9)
|
||||||
{
|
{
|
||||||
@@ -743,11 +747,11 @@ namespace XPC
|
|||||||
const unsigned char* buffer = msg.GetBuffer();
|
const unsigned char* buffer = msg.GetBuffer();
|
||||||
int type = *((int*)(buffer + 5));
|
int type = *((int*)(buffer + 5));
|
||||||
XPLMCommandKeyStroke(type);
|
XPLMCommandKeyStroke(type);
|
||||||
|
|
||||||
if(type == 79 && enable_camera_location == 1) // runway camera view
|
if(type == 79 && enable_camera_location == 1) // runway camera view
|
||||||
{
|
{
|
||||||
static struct CameraProperties campos;
|
static struct CameraProperties campos;
|
||||||
|
|
||||||
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);
|
||||||
@@ -755,60 +759,60 @@ namespace XPC
|
|||||||
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);
|
||||||
|
|
||||||
XPLMControlCamera(xplm_ControlCameraUntilViewChanges, CamFunc, &campos);
|
XPLMControlCamera(xplm_ControlCameraUntilViewChanges, CamFunc, &campos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessageHandlers::CamFunc( XPLMCameraPosition_t * outCameraPosition, int inIsLosingControl, void *inRefcon)
|
int MessageHandlers::CamFunc( XPLMCameraPosition_t * outCameraPosition, int inIsLosingControl, void *inRefcon)
|
||||||
{
|
{
|
||||||
if (outCameraPosition && !inIsLosingControl)
|
if (outCameraPosition && !inIsLosingControl)
|
||||||
{
|
{
|
||||||
struct CameraProperties* campos = (struct CameraProperties*)inRefcon;
|
struct CameraProperties* campos = (struct CameraProperties*)inRefcon;
|
||||||
|
|
||||||
// camera position
|
// camera position
|
||||||
double clat = campos->loc[0];
|
double clat = campos->loc[0];
|
||||||
double clon = campos->loc[1];
|
double clon = campos->loc[1];
|
||||||
double calt = campos->loc[2];
|
double calt = campos->loc[2];
|
||||||
|
|
||||||
double cX, cY, cZ;
|
double cX, cY, cZ;
|
||||||
XPLMWorldToLocal(clat, clon, calt, &cX, &cY, &cZ);
|
XPLMWorldToLocal(clat, clon, calt, &cX, &cY, &cZ);
|
||||||
|
|
||||||
outCameraPosition->x = cX;
|
outCameraPosition->x = cX;
|
||||||
outCameraPosition->y = cY;
|
outCameraPosition->y = cY;
|
||||||
outCameraPosition->z = cZ;
|
outCameraPosition->z = cZ;
|
||||||
|
|
||||||
// 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
|
||||||
@@ -817,10 +821,10 @@ namespace XPC
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user