From 5d0e5cc1b17f25076e0af49b125c11c4e676aea8 Mon Sep 17 00:00:00 2001 From: Wayne Piekarski Date: Wed, 14 Nov 2018 21:17:38 -0800 Subject: [PATCH] Implement the EXTPLANE-VERSION header to allow clients to know what features and bug fixes are available --- README.md | 9 +++++++-- extplane-plugin/xplaneplugin.cpp | 5 ++++- extplane-server/tcpclient.cpp | 4 +++- extplane-server/tcpserver.h | 13 +++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4a7484a..595e969 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ scripts/cross-compile-win64-from-lin.sh for instructions. Launch X-Plane in console and observe the output. You should see something like: `ExtPlane-Plugin: Listening on port 51000`. All console output from Ext-Plane will start with `ExtPlane-Plugin`. Open another console and run `telnet localhost 51000`. -Wait until you see line `EXTPLANE 1`. Then try typing the following commands: +Wait until you see line `EXTPLANE 1` and `EXTPLANE-VERSION NNNNN`. Then try typing the following commands: ``` sub sim/cockpit/electrical/night_vision_on @@ -283,10 +283,15 @@ Supported settings are: ## Protocol Output ## -* **EXTPLANE {version}** Sent when connected. Version number is currently 1. +* **EXTPLANE {protocol}** Sent when connected. Protocol is currently 1. +* **EXTPLANE-VERSION {version}** Sent when connected. Feature version integer, which is incremented with each new bug fix or feature. * **u{type} {dataref} {value}** Dataref has changed in value based on accuracy. * Types may be `i` (int), `f` (float), `d` (double), `ia` (int array), `fa` (float array), or `b` (data). +The value for EXTPLANE-VERSION is defined in extplane-server/tcpserver.h. It is an integer and should be incremented +each time new features are added or bugs are fixed. The client is then able to check if the version is new enough, and can +warn the user if the plugin is out of date. + ### Int/Float/Double Datarefs ### Example output: diff --git a/extplane-plugin/xplaneplugin.cpp b/extplane-plugin/xplaneplugin.cpp index c092734..92c30c6 100644 --- a/extplane-plugin/xplaneplugin.cpp +++ b/extplane-plugin/xplaneplugin.cpp @@ -44,7 +44,7 @@ int XPlanePlugin::pluginStart(char * outName, char * outSig, char *outDesc) { INFO << "Plugin started"; strcpy(outName, "ExtPlane"); strcpy(outSig, "org.vranki.extplaneplugin"); - strcpy(outDesc, "Read and write X-Plane datarefs from external programs using TCP sockets."); + strcpy(outDesc, "Read and write X-Plane datarefs from external programs on TCP port " EXTPLANE_PORT_STR " with protocol " EXTPLANE_PROTOCOL_STR " version " EXTPLANE_VERSION_STR); // Init application and server app = new QCoreApplication(argc, &argv); @@ -53,6 +53,9 @@ int XPlanePlugin::pluginStart(char * outName, char * outSig, char *outDesc) { server = new TcpServer(this, this); connect(server, SIGNAL(setFlightLoopInterval(float)), this, SLOT(setFlightLoopInterval(float))); + // Log that we have started + XPLMDebugString ("ExtPlane listening on TCP port " EXTPLANE_PORT_STR " with protocol " EXTPLANE_PROTOCOL_STR " version " EXTPLANE_VERSION_STR "\n"); + // Register the nav custom data accessors XPLMRegisterDataAccessor("extplane/navdata/5km", xplmType_Data, // The types we support diff --git a/extplane-server/tcpclient.cpp b/extplane-server/tcpclient.cpp index 3667c53..ca1d37b 100644 --- a/extplane-server/tcpclient.cpp +++ b/extplane-server/tcpclient.cpp @@ -1,4 +1,5 @@ #include "tcpclient.h" +#include "tcpserver.h" #include "datarefs/dataref.h" #include "datarefs/floatdataref.h" #include "datarefs/floatarraydataref.h" @@ -23,7 +24,8 @@ TcpClient::TcpClient(QObject *parent, QByteArray block; QTextStream out(&block, QIODevice::WriteOnly); - out << "EXTPLANE 1\n"; + out << "EXTPLANE " << EXTPLANE_PROTOCOL << "\n"; + out << "EXTPLANE-VERSION " << EXTPLANE_VERSION << "\n"; out.flush(); _socket->write(block); } diff --git a/extplane-server/tcpserver.h b/extplane-server/tcpserver.h index bb83196..e461235 100644 --- a/extplane-server/tcpserver.h +++ b/extplane-server/tcpserver.h @@ -9,7 +9,20 @@ /** * Creates the TCP socket and manages client connections */ +// TCP port used to listen for connections #define EXTPLANE_PORT 51000 +// Network protocol, currently always 1 +#define EXTPLANE_PROTOCOL 1 +// Feature revision, every time we add a new feature or bug fix, this should be incremented so that clients can know how old the plugin is +#define EXTPLANE_VERSION 1000 + +#define EXTPLANE_STRINGIFY(s) __EXTPLANE_STRINGIFY(s) +#define __EXTPLANE_STRINGIFY(s) #s + +#define EXTPLANE_PORT_STR EXTPLANE_STRINGIFY(EXTPLANE_PORT) +#define EXTPLANE_PROTOCOL_STR EXTPLANE_STRINGIFY(EXTPLANE_PROTOCOL) +#define EXTPLANE_VERSION_STR EXTPLANE_STRINGIFY(EXTPLANE_VERSION) + class TcpClient; class DataRefProvider;