diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index 1a94bf3..37c7e71 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -1,10 +1,26 @@ //Copyright (c) 2013-2015 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. +// +//X-Plane API +//Copyright(c) 2008, Sandy Barbour and Ben Supnik All rights reserved. +//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +//associated documentation files(the "Software"), to deal in the Software without restriction, +//including without limitation the rights to use, copy, modify, merge, publish, distribute, +//sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is +//furnished to do so, subject to the following conditions : +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Neither the names of the authors nor that of X - Plane or Laminar Research +// may be used to endorse or promote products derived from this software +// without specific prior written permission from the authors or +// Laminar Research, respectively. #include "MessageHandlers.h" #include "DataManager.h" #include "Drawing.h" #include "Log.h" +#include "XPLMUtilities.h" + #include #include @@ -36,8 +52,7 @@ namespace XPC handlers.insert(std::make_pair("SIMU", MessageHandlers::HandleSimu)); handlers.insert(std::make_pair("TEXT", MessageHandlers::HandleText)); handlers.insert(std::make_pair("WYPT", MessageHandlers::HandleWypt)); - // Not implemented messages - handlers.insert(std::make_pair("VIEW", MessageHandlers::HandleUnknown)); + handlers.insert(std::make_pair("VIEW", MessageHandlers::HandleView)); // X-Plane data messages handlers.insert(std::make_pair("DSEL", MessageHandlers::HandleXPlaneData)); handlers.insert(std::make_pair("USEL", MessageHandlers::HandleXPlaneData)); @@ -623,6 +638,26 @@ namespace XPC } } + void MessageHandlers::HandleView(Message& msg) + { + // Update Log +#if LOG_VERBOSITY > 0 + Log::FormatLine("[VIEW] Message Received (Conn %i)", connection.id); +#endif + + const std::size_t size = msg.GetSize(); + if (size != 9) + { +#if LOG_VERBOSITY > 1 + Log::FormatLine("[VIEW] Error: Unexpected length. Message was %d bytes, expected 9.", size); +#endif + return; + } + const unsigned char* buffer = msg.GetBuffer(); + int type = *((int*)(buffer + 5)); + XPLMCommandKeyStroke(type); + } + void MessageHandlers::HandleWypt(Message& msg) { // Update Log diff --git a/xpcPlugin/MessageHandlers.h b/xpcPlugin/MessageHandlers.h index b7cfd25..123c39a 100644 --- a/xpcPlugin/MessageHandlers.h +++ b/xpcPlugin/MessageHandlers.h @@ -46,6 +46,7 @@ namespace XPC static void HandleSimu(Message& msg); static void HandleText(Message& msg); static void HandleWypt(Message& msg); + static void HandleView(Message& msg); static void HandleXPlaneData(Message& msg); static void HandleUnknown(Message& msg);