
In this posting, we will connect the now modified VHF COMM Radio to the X-Plan software. This will close out this avionics bending project for my Lockheed L-1011 project. In the last posting we looked at the firmware code that we loaded on the AT90USB on on the backside of the original flight hardware.
A device driver that I wrote receives the USB data on the computer and puts it into a shared memory segment. I am not showing that code today, but if you are interested to see it, you can drop me a line and I e-mail it to you.
The image below is an output of the USB device driver (it does that in debug mode only).

My X-Plane plug-in does not directly interface with the USB software, it takes a good amount of processing and I don't want to slow down the simulator over time by loading it up with compute intensive attachments, hence, the X-Plane software simple reads the shared memory segment and inserts the code in the the simulator using an XREF. Below, you can see a screen shot that shows the frequency that we selected on the original flight hardware ... except for now it is shown on the COMM radio in X-Plane.

Here is the X-Plane plug-in code that does the magic:
/*
* RadioControl.c
* L1011_SimWare
*
* Created by Curd Zechmeister on 3/29/10.
* Copyright 2010 Area145 Corporation. All rights reserved.
*
*/
#include
#include
#include
#include
#include
#include
#include "XPLMUtilities.h"
#include "XPLMProcessing.h"
#include "XPLMDataAccess.h"
#define ECHOMAX 96
/*
* Simulator Dataword
*/
struct xplnDataWord {
int digit1;
int digit2;
int digit3;
int digit4;
int digit5;
} xplnDataInput, *xplnDataInputPtr;
/*
* X-Plane DataRefs for the L1011 Overhead Panel
*/
/* APU Control */
XPLMDataRef gCockpitRadios;
/* ********************************************************************************************
* * CALLBACK REGISTRATION
* ********************************************************************************************/
float MyFlightLoopCallback(
float inElapsedSinceLastCall,
float inElapsedTimeSinceLastFlightLoop,
int inCounter,
void * inRefcon);
/* ********************************************************************************************
* * PLUGIN STARTUP
* ********************************************************************************************/
PLUGIN_API int XPluginStart(
char * outName,
char * outSig,
char * outDesc)
{
strcpy(outName, "L1011 COM Radio Controller");
strcpy(outSig, "l1011.vhf.com1");
strcpy(outDesc, "Control the Lockheed L1011 Fight Engineer Panels");
/* Engine Start PanelData Refs */
gCockpitRadios = XPLMFindDataRef("sim/cockpit2/radios/actuators/com1_frequency_hz");
/* Register our callback for once a second. Positive intervals
* are in seconds, negative are the negative of sim frames. Zero
* registers but does not schedule a callback for time. */
XPLMRegisterFlightLoopCallback(
MyFlightLoopCallback, /* Callback */
0.3, /* Interval */
NULL); /* refcon not used. */
/* Connect to the shared memory segemtn */
/* Variables */
int iSegmentID;
// Create the shared memory segment
iSegmentID = shmget( 1234, sizeof(xplnDataInput), 0666 | IPC_CREAT );
// attach to the shared memory segment
xplnDataInputPtr = shmat( iSegmentID, 0, 0 );
return 1;
}
/* ********************************************************************************************
* * PLUGIN PAUSE/STOP
* ********************************************************************************************/
PLUGIN_API void XPluginStop(void)
{
/* Unregister the callback */
XPLMUnregisterFlightLoopCallback(MyFlightLoopCallback, NULL);
}
/* ********************************************************************************************
* * PLUGIN DISABLE
* ********************************************************************************************/
PLUGIN_API void XPluginDisable(void)
{
}
/* ********************************************************************************************
* * PLUGIN ENABLE
* ********************************************************************************************/
PLUGIN_API int XPluginEnable(void)
{
return 1;
}
/* ********************************************************************************************
* * PLUGIN RECEIVE MESSAGE
* ********************************************************************************************/
PLUGIN_API void XPluginReceiveMessage(
XPLMPluginID inFromWho,
long inMessage,
void * inParam)
{
}
/* ********************************************************************************************
* * CALLBACK LOOP
* ********************************************************************************************/
float MyFlightLoopCallback(
float inElapsedSinceLastCall,
float inElapsedTimeSinceLastFlightLoop,
int inCounter,
void * inRefcon)
{
int comFrequency;
comFrequency = 0;
/* ********************************************************
* * L1011 COM Panel -- Data Input
* ********************************************************/
comFrequency = ( xplnDataInputPtr->digit1 * 10000 +
xplnDataInputPtr->digit2 * 1000 +
xplnDataInputPtr->digit3 * 100 +
xplnDataInputPtr->digit4 * 10 +
xplnDataInputPtr->digit5 );
XPLMSetDatai( gCockpitRadios, comFrequency );
/* ********************************************************
* * L1011 COM Panel -- Data Output
* ********************************************************/
/* Return 1.0 to indicate that we want to be called again in 1 second. */
return 1.0;
}
No comments:
Post a Comment