From 9185424daa5dd82c5ec9cd4acebab22a44d5b055 Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 10:06:42 -0700 Subject: [PATCH 1/9] Added sendPOST function combining sendPOSI and getTERR --- C/src/xplaneConnect.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/C/src/xplaneConnect.h b/C/src/xplaneConnect.h index 67eafba..f3c8675 100644 --- a/C/src/xplaneConnect.h +++ b/C/src/xplaneConnect.h @@ -234,6 +234,23 @@ int sendPOSI(XPCSocket sock, double values[], int size, char ac); /// \returns 0 if successful, otherwise a negative value. int getTERR(XPCSocket sock, double posi[3], double values[11], char ac); +/// Sets the position and orientation and gets the terrain information of the specified aircraft. +/// +/// \param sock The socket to use to send the command. +/// \param posi A double array representing position data about the aircraft. The format of values is +/// [Lat, Lon, Alt, Pitch, Roll, Yaw, Gear]. If less than 7 values are specified, +/// the unspecified values will be left unchanged. +/// \param size The number of elements in posi. +/// \param values A double array with the information for the terrain output. The format of values is +/// [Lat, Lon, Alt, Nx, Ny, Nz, Vx, Vy, Vz, wet, result]. The first three are for output of +/// the Lat and Lon of the aircraft with the terrain height directly below. The next three +/// represent the terrain normal. The next three represent the velocity of the terrain. +/// The wet variable is 0.0 if the terrain is dry and 1.0 if wet. +/// The last output is the terrain probe result parameter. +/// \param ac The aircraft number to set the position of. 0 for the main/user's aircraft. +/// \returns 0 if successful, otherwise a negative value. +int sendPOST(XPCSocket sock, double posi[], int size, double values[11], char ac); + // Controls /// Gets the control surface information for the specified aircraft. From 0a50735ebcdb0c93e0432bba6a0807c4406bff8b Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 10:13:14 -0700 Subject: [PATCH 2/9] Added sendPOST function combining sendPOSI and getTERR --- C/src/xplaneConnect.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index fdcba8e..81bfded 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -713,6 +713,63 @@ int getTERR(XPCSocket sock, double posi[3], double values[11], char ac) } return 0; } + +int sendPOST(XPCSocket sock, double posi[], int size, double values[11], char ac) +{ + // Validate input + if (ac < 0 || ac > 20) + { + printError("sendPOST", "aircraft should be a value between 0 and 20."); + return -1; + } + if (size < 1 || size > 7) + { + printError("sendPOST", "size should be a value between 1 and 7."); + return -2; + } + + // Setup command + char buffer[46] = "POST"; + buffer[4] = 0xff; //Placeholder for message length + buffer[5] = ac; + int i; // iterator + + for (i = 0; i < 7; i++) // double for lat/lon/h + { + double val = -998; + + if (i < size) + { + val = posi[i]; + } + if (i < 3) /* lat/lon/h */ + { + memcpy(&buffer[6 + i*8], &val, sizeof(double)); + } + else /* attitude and gear */ + { + float f = (float)val; + memcpy(&buffer[18 + i*4], &f, sizeof(float)); + } + } + + // Send Command + if (sendUDP(sock, buffer, 46) < 0) + { + printError("sendPOST", "Failed to send command"); + return -3; + } + + // Read Response + int result = getTERRResponse(sock, values, ac); + if (result < 0) + { + // A error ocurred while reading the response. + // getTERRResponse will print an error message, so just return. + return result; + } + return 0; +} /*****************************************************************************/ /**** End TERR functions ****/ /*****************************************************************************/ From 0473b5ea231f8cf6a9a97db5787fdfb805852c2b Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 13:58:50 -0700 Subject: [PATCH 3/9] Added HandlePosT function --- xpcPlugin/MessageHandlers.h | 1 + 1 file changed, 1 insertion(+) diff --git a/xpcPlugin/MessageHandlers.h b/xpcPlugin/MessageHandlers.h index 76c8468..d360286 100644 --- a/xpcPlugin/MessageHandlers.h +++ b/xpcPlugin/MessageHandlers.h @@ -76,6 +76,7 @@ namespace XPC static void HandleWypt(const Message& msg); static void HandleView(const Message& msg); static void HandleGetT(const Message& msg); + static void HandlePosT(const Message& msg); static void HandleXPlaneData(const Message& msg); static void HandleUnknown(const Message& msg); From 9869a448d8c90f263b378d4343617dc27786ec4a Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 14:07:10 -0700 Subject: [PATCH 4/9] Added HandlePosT function that combines HandlePosi with HandleGetT --- xpcPlugin/MessageHandlers.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index 43e90af..0008f8f 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -70,6 +70,7 @@ namespace XPC handlers.insert(std::make_pair("GETC", MessageHandlers::HandleGetC)); handlers.insert(std::make_pair("GETP", MessageHandlers::HandleGetP)); handlers.insert(std::make_pair("GETT", MessageHandlers::HandleGetT)); + handlers.insert(std::make_pair("POST", MessageHandlers::HandlePosT)); // X-Plane data messages handlers.insert(std::make_pair("DSEL", MessageHandlers::HandleXPlaneData)); handlers.insert(std::make_pair("USEL", MessageHandlers::HandleXPlaneData)); @@ -630,6 +631,21 @@ namespace XPC } } + void MessageHandlers::HandlePosT(const Message& msg) + { + MessageHandlers::HandlePosi(msg); + + const unsigned char* buffer = msg.GetBuffer(); + char aircraftNumber = buffer[5]; + Log::FormatLine(LOG_TRACE, "POST", "Getting terrain information for aircraft %u", aircraftNumber); + + double pos[3]; + pos[0] = DataManager::GetDouble(DREF_Latitude, aircraftNumber); + pos[1] = DataManager::GetDouble(DREF_Longitude, aircraftNumber); + pos[2] = 0.0; + MessageHandlers::SendTerr(pos, aircraftNumber); + } + void MessageHandlers::HandleGetT(const Message& msg) { const unsigned char* buffer = msg.GetBuffer(); From 2d3e9ccc243357f30f76c417f3e9fbaeb2ea457a Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 14:10:37 -0700 Subject: [PATCH 5/9] Added handling of the POST message --- xpcPlugin/Message.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xpcPlugin/Message.cpp b/xpcPlugin/Message.cpp index c1eb448..3dcaf3b 100644 --- a/xpcPlugin/Message.cpp +++ b/xpcPlugin/Message.cpp @@ -138,7 +138,7 @@ namespace XPC cur += 1 + buffer[cur]; } } - else if (head == "POSI") + else if (head == "POSI" || head == "POST") { char aircraft = buffer[5]; float gear; From 9b6d0986be7fab9c967d0105de09b6c903a44a65 Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 14:33:21 -0700 Subject: [PATCH 6/9] Added sendPOST function combining functions of sendPOSI and getTERR --- C/src/xplaneConnect.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/C/src/xplaneConnect.h b/C/src/xplaneConnect.h index f3c8675..842a215 100644 --- a/C/src/xplaneConnect.h +++ b/C/src/xplaneConnect.h @@ -159,7 +159,7 @@ int sendDREF(XPCSocket sock, const char* dref, float values[], int size); /// the type described on the wiki. This doesn't cause any data loss for most datarefs. /// \param sock The socket to use to send the command. /// \param drefs The names of the datarefs to set. -/// \param values A 2D array array containing the values for each dataref to set. +/// \param values A 2D array containing the values for each dataref to set. /// \param sizes The number of elements in each array in values /// \param count The number of datarefs being set. /// \returns 0 if successful, otherwise a negative value. @@ -208,7 +208,7 @@ int getPOSI(XPCSocket sock, double values[7], char ac); /// Sets the position and orientation of the specified aircraft. /// /// \param sock The socket to use to send the command. -/// \param values An array representing position data about the aircraft. The format of values is +/// \param values A double array representing position data about the aircraft. The format of values is /// [Lat, Lon, Alt, Pitch, Roll, Yaw, Gear]. If less than 7 values are specified, /// the unspecified values will be left unchanged. /// \param size The number of elements in values. @@ -218,22 +218,6 @@ int sendPOSI(XPCSocket sock, double values[], int size, char ac); // Terrain -/// Gets the terrain information of the specified aircraft. -/// -/// \param sock The socket to use to send the command. -/// \param posi A double array representing position data about the aircraft. The format of values is -/// [Lat, Lon, Alt]. -/// -998 used for [Lat, Lon, Alt] to request terrain info at the current aircraft position. -/// \param values A double array with the information for the terrain output. The format of values is -/// [Lat, Lon, Alt, Nx, Ny, Nz, Vx, Vy, Vz, wet, result]. The first three are for output of -/// the Lat and Lon of the aircraft with the terrain height directly below. The next three -/// represent the terrain normal. The next three represent the velocity of the terrain. -/// The wet variable is 0.0 if the terrain is dry and 1.0 if wet. -/// The last output is the terrain probe result parameter. -/// \param ac The aircraft number to get the terrain data of. 0 for the main/user's aircraft. -/// \returns 0 if successful, otherwise a negative value. -int getTERR(XPCSocket sock, double posi[3], double values[11], char ac); - /// Sets the position and orientation and gets the terrain information of the specified aircraft. /// /// \param sock The socket to use to send the command. @@ -251,6 +235,22 @@ int getTERR(XPCSocket sock, double posi[3], double values[11], char ac); /// \returns 0 if successful, otherwise a negative value. int sendPOST(XPCSocket sock, double posi[], int size, double values[11], char ac); +/// Gets the terrain information of the specified aircraft. +/// +/// \param sock The socket to use to send the command. +/// \param posi A double array representing position data about the aircraft. The format of values is +/// [Lat, Lon, Alt]. +/// -998 used for [Lat, Lon, Alt] to request terrain info at the current aircraft position. +/// \param values A double array with the information for the terrain output. The format of values is +/// [Lat, Lon, Alt, Nx, Ny, Nz, Vx, Vy, Vz, wet, result]. The first three are for output of +/// the Lat and Lon of the aircraft with the terrain height directly below. The next three +/// represent the terrain normal. The next three represent the velocity of the terrain. +/// The wet variable is 0.0 if the terrain is dry and 1.0 if wet. +/// The last output is the terrain probe result parameter. +/// \param ac The aircraft number to get the terrain data of. 0 for the main/user's aircraft. +/// \returns 0 if successful, otherwise a negative value. +int getTERR(XPCSocket sock, double posi[3], double values[11], char ac); + // Controls /// Gets the control surface information for the specified aircraft. From be4e799f8df5c1da27c0ded206455a4ec4e32901 Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 14:38:48 -0700 Subject: [PATCH 7/9] Added sendPOST function combining functions of sendPOSI and getTERR --- C/src/xplaneConnect.c | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 81bfded..d48ac02 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -692,28 +692,6 @@ int getTERRResponse(XPCSocket sock, double values[11], char ac) return 0; } -int getTERR(XPCSocket sock, double posi[3], double values[11], char ac) -{ - // Send Command - int result = sendTERRRequest(sock, posi, ac); - if (result < 0) - { - // An error ocurred while sending. - // sendTERRRequest will print an error message, so just return. - return result; - } - - // Read Response - result = getTERRResponse(sock, values, ac); - if (result < 0) - { - // An error ocurred while reading the response. - // getTERRResponse will print an error message, so just return. - return result; - } - return 0; -} - int sendPOST(XPCSocket sock, double posi[], int size, double values[11], char ac) { // Validate input @@ -770,6 +748,28 @@ int sendPOST(XPCSocket sock, double posi[], int size, double values[11], char ac } return 0; } + +int getTERR(XPCSocket sock, double posi[3], double values[11], char ac) +{ + // Send Command + int result = sendTERRRequest(sock, posi, ac); + if (result < 0) + { + // An error ocurred while sending. + // sendTERRRequest will print an error message, so just return. + return result; + } + + // Read Response + result = getTERRResponse(sock, values, ac); + if (result < 0) + { + // An error ocurred while reading the response. + // getTERRResponse will print an error message, so just return. + return result; + } + return 0; +} /*****************************************************************************/ /**** End TERR functions ****/ /*****************************************************************************/ From 26d85f755f65fdb9d6949c132fc62b2c43a7b06f Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 14:45:15 -0700 Subject: [PATCH 8/9] Added HandlePosT function that combines functions of HandlePosi with HandleGetT --- xpcPlugin/MessageHandlers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index 0008f8f..9e5c799 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -63,6 +63,7 @@ namespace XPC handlers.insert(std::make_pair("DREF", MessageHandlers::HandleDref)); handlers.insert(std::make_pair("GETD", MessageHandlers::HandleGetD)); handlers.insert(std::make_pair("POSI", MessageHandlers::HandlePosi)); + handlers.insert(std::make_pair("POST", MessageHandlers::HandlePosT)); handlers.insert(std::make_pair("SIMU", MessageHandlers::HandleSimu)); handlers.insert(std::make_pair("TEXT", MessageHandlers::HandleText)); handlers.insert(std::make_pair("WYPT", MessageHandlers::HandleWypt)); @@ -70,7 +71,6 @@ namespace XPC handlers.insert(std::make_pair("GETC", MessageHandlers::HandleGetC)); handlers.insert(std::make_pair("GETP", MessageHandlers::HandleGetP)); handlers.insert(std::make_pair("GETT", MessageHandlers::HandleGetT)); - handlers.insert(std::make_pair("POST", MessageHandlers::HandlePosT)); // X-Plane data messages handlers.insert(std::make_pair("DSEL", MessageHandlers::HandleXPlaneData)); handlers.insert(std::make_pair("USEL", MessageHandlers::HandleXPlaneData)); From 6120869c2ce867e99321c2167dbd4324de150d27 Mon Sep 17 00:00:00 2001 From: Norman Princen <63923352+NPrincen@users.noreply.github.com> Date: Sat, 2 May 2020 14:46:46 -0700 Subject: [PATCH 9/9] Added HandlePosT function that combines functions of HandlePosi with HandleGetT --- xpcPlugin/MessageHandlers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xpcPlugin/MessageHandlers.h b/xpcPlugin/MessageHandlers.h index d360286..ee39492 100644 --- a/xpcPlugin/MessageHandlers.h +++ b/xpcPlugin/MessageHandlers.h @@ -70,13 +70,13 @@ namespace XPC static void HandleGetC(const Message& msg); static void HandleGetD(const Message& msg); static void HandleGetP(const Message& msg); + static void HandleGetT(const Message& msg); static void HandlePosi(const Message& msg); + static void HandlePosT(const Message& msg); static void HandleSimu(const Message& msg); static void HandleText(const Message& msg); static void HandleWypt(const Message& msg); static void HandleView(const Message& msg); - static void HandleGetT(const Message& msg); - static void HandlePosT(const Message& msg); static void HandleXPlaneData(const Message& msg); static void HandleUnknown(const Message& msg);