Jump to content
The simFlight Network Forums

Transponder


Recommended Posts

Anybody who can give me advice how to toggle Mode C / Standby on the Vatsim/IVAO via a hardware toggle?

This is possible via FSUIPC and GoFlight or CP Flight Xponder modules, but I wish dearly to find a stand alone solution.

Is this on FS9 using Squawkbox? If so I believe the method is documented, via FSUIPC offsets, on their website? If so, if it is done by offsets changes, you can assign any button, toggle or keypress to do it in FSUIPC's options.

Get the details from the SB site, check them and then, if you need help in working out what to assign in FSUIPC, show me what you found and I'll help from there.

Regards

Pete

Link to comment
Share on other sites

Hi Pete,

Thanks.

As usual a very fast answer from you.

I have found the offsets (FS9 Squawkbox3) below at the Squawkbox site, but have no clue how to implement them on a joystick button so I appreciate your kind help with what to write in the FSUIPC.ini

(A little computer ilitterate you might say :) )

Best,

Bjorn

post-17555-128689665228_thumb.jpg

Link to comment
Share on other sites

I have found the offsets (FS9 Squawkbox3) below at the Squawkbox site, but have no clue how to implement them on a joystick button so I appreciate your kind help.

Okay, let's see:

Offset is 7B91, and it is 1 byte.

Value 0 means normal, 1 means standby.

So, since you say you have a toggle switch, you want it to write 0 to 7B91 in one position, and 1 in the other. So go to the FSUIPC Buttons and Switches Tab, and assign it as follows:

"Press" (i.e. for a toggle switch = "on"), to "Offset byte set" control in the drop down list. Enter x7B91 for the Offset, and 1 for the parameter.

"Release" (i.e. for a toggle switch = "off"), also to "Offset byte set" control in the drop down list. Enter x7B91 for the Offset as well, but 0 for the parameter.

See? Quite logical. Just apply what you read to what is available!

If you don't really have a toggle switch, only a joystick button as you now intimate (has it changed?), then it will be different. You only assign to the "Press" and you use "Offset byte togglebits" with offset x7B91 and parameter 1. Then pressing the button will toggle between the two modes.

Pete

Link to comment
Share on other sites

The instructions provided here apply for FSX using Squawkbox as well? or this is just for FS9+SB?

Definitely not FSX. SB4 on FSX is a SimConnect client. it doesn't use FSUIPC at all.

This is the ONLY thing stopping me even trying SB. I've repeatedly written to the two authors of SB4 to ask for a method of operating the transponder, possibly via a windows message as is done for PTT. Then I will add the facility as a control to both FSUIPC and WideClient (using both offset and message so as to work on both FS9 and FSX).

They respond and apologise for not getting to it, but nothing continues to happen I'm afraid. I guess there's only me pressing for it so it isn't very important. :-(.

Regards

Pete

Link to comment
Share on other sites

It could be something as simple as sending a KeySend, as long as Squackbox has a shortcut for it! which it does not.. currently, transponder modes can only be set via the Menu using the mouse!

I'm surprised they have not addresed this before...

Link to comment
Share on other sites

It could be something as simple as sending a KeySend, as long as Squackbox has a shortcut for it! which it does not.. currently, transponder modes can only be set via the Menu using the mouse!

Yes, which I cannot tolerate in my nice realistic cockpit! ;-)

All it needs is another Registered Windows message, just like they implemented for PTT (and PVT) -- the mechanism originally adopted by Roger Wilco. It is really easy to program, and I would immediately offer it as an assignable control just like the PTT one is now. It would deal with a local Squawkbox or one running via WideFS.

I'm surprised they have not addresed this before...

Well, I write to them about it every few weeks or so, just so they know at least one person wants it! ;-(

Regards

Pete

Link to comment
Share on other sites

Pete,

Since, no one is willing to cooperate how about this:

The mini transponder gauge provided by SB does set the modes *OVER THE NETWORK* I tried to see if assigning MouseMacros worked, which obviously didn't :) so question is this:

can you 'trap' whatever the mini SB transponder gauge is sending over the network to see 'what it is' and send it over the network yourself via FSUIPC? It would be something like a MouseMacro, but for 'Simconnect' events I guess.. i'm pretty sure it would take you no time to implement and the entire community will love you :0 (they do already) but more love doesn't hurt!! jaja..

take care ;) and thanks

-Jesus

Link to comment
Share on other sites

Since, no one is willing to cooperate how about this

I don't think they are "not willing". I assume it is merely that they have other things to do, and this is obviously unimportant if I'm the only one asking for it.

can you 'trap' whatever the mini SB transponder gauge is sending over the network to see 'what it is' and send it over the network yourself via FSUIPC?

No, sorry. That would be a huge amount of additional code, even if I had the many hours it would take to hack into it. I'm not about to add a whole program's worth of code just for something which should be so ridiculously simple.

Regards

Pete

Link to comment
Share on other sites

If you have ever wondered why this has not been implemented here's your answer:

http://squawkbox.ca/forum/viewtopic.php?p=23447#23447

No, that doesn't explain anything at all. The facility required in Squawkbox would be like the one for PTT, which is a Registered Windows message. The PTT works well and so could the Transponder. This is nothing whatsoever to do with whether anything uses FSUIPC or not! That is a complete misunderstanding.

Pete

Link to comment
Share on other sites

whether anything uses FSUIPC or not! That is a complete misunderstanding.

Pete

Exactly! thats what I meant with my response.. there seems to be a 'complete' misunderstanding!! the fact that SB4 uses SimConnect doesn't have ANYTHING to do with the fact that FSUIPC can still be used to trigger transponder modes the same way PTT works today...

My concern is that the guy who replied in that thread is Norman!! Well Known SB tester, VATSIM VP, Close to the SB developers!!! it would be fantastic if you jump in that thread and 'clarify' this for him.. I'm PRETTY sure he will raise this issue with Joel ASAP.

Link to comment
Share on other sites

My concern is that the guy who replied in that thread is Norman!! Well Known SB tester, VATSIM VP, Close to the SB developers!!! it would be fantastic if you jump in that thread and 'clarify' this for him.. I'm PRETTY sure he will raise this issue with Joel ASAP.

I've raised it directly, starting with Joel in a message on 2nd October 2008, and subsequently with both Joel and Brian Gefrich on 8th and 12th October, exchanges where it was evident that Brian understood exactly the approach I suggested and promised to discuss it with Joel (who never actually answered me). I sent a reminder and asked about progress in December, and again on 11th January this year. I've had no responses to any of my messages after October last. As far as I can tell they've abandoned development of Squawkbox. Is there any sign of any life in the development area?

I've met Joel and he seems a good sort so I'm sure the snubs aren't meant. He's probably either sick or too busy someplace else.

As I said, as soon as they incorporate an accessible facility, I'll provide a route to it from FSUIPC and WideFS. I'm really too busy with my own commitments to go flogging a dead horse. I've decided to continue to use Radar Contact for my ATC instead of trying to go on-line.

Regards

Pete

Link to comment
Share on other sites

  • 1 year later...

Done!

I'll not be sharing the actual DLL, but the source code. feel free to use it/modify it/adapt it anyway you want. This sets the transponder modes correctly when using SB4 and FSX via Menu, evidently the step missing is adding 'shortcut keys' to integrate with your hardware.. but my C++ skills are rusty and I already spent a considerably amount of time trying to understand how to set the modes over the network!

//Copyright (c) Jesus Altuve 2010.  All rights reserved. 
//Sets Transponder modes via menu

#include "stdafx.h"
#include "simconnect.h"

typedef enum
{
	MAIN_MENU = 1,
	SUB_MENU_1= 100,
	MENU_SELECTION_1 = 200,
} EVENT_IDS;

HANDLE  hSimConnect = NULL; 
HANDLE	g_hSimConnect;

bool	stby_mode	= 1;
bool	c_mode		= 0;
int		x_ident		= 2;

void OnRecvOpen (SIMCONNECT_RECV_OPEN *pOpen)
{
	// create menu items
	SimConnect_MenuAddItem(g_hSimConnect, "Bojote's FSX Tools", MAIN_MENU, 0);
	SimConnect_MenuAddSubItem(g_hSimConnect, MAIN_MENU, "SquawkBox Hack", SUB_MENU_1, 0);

	// Shared Client Data (values taken from the simconnect debug output)
	SimConnect_SubscribeToSystemEvent(g_hSimConnect, 0, "1sec");
	SimConnect_MapClientDataNameToID(g_hSimConnect, "SquawkBox Data", 0);

	// Register data structures (values were taken from the simconnect debug output of sbtrans.dll)
	SimConnect_AddToClientDataDefinition(g_hSimConnect, 0, 1, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 1, 2, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 2, 17, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 3, 18, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 4, 19, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 5, 20, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 6, 21, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 7, 22, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 8, 24, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 9, 25, 1, -1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, 10, 26, 1, -1);

	// Sets transponder mode to SBTY (but is not working why?)
	SimConnect_SetClientData(g_hSimConnect, 0, 2, 0, 0, 1, &stby_mode);
}

char szMenuText1[] = "SquawkBox\0Select a transponder mode:\0Charly\0Standby\0IDENT\0Close Window\0";

void OnRecvEvent (SIMCONNECT_RECV_EVENT *pEvent)
{
	switch (pEvent->uEventID)
	{
		// process menu items
		case SUB_MENU_1:
			{
				SimConnect_Text(g_hSimConnect, SIMCONNECT_TEXT_TYPE_MENU, 0.0f, MENU_SELECTION_1, ARRAYSIZE(szMenuText1), szMenuText1);
			}
			break;

		// process item selection from menu
		case MENU_SELECTION_1:
			{
				switch (pEvent->dwData)
				{
					case SIMCONNECT_TEXT_RESULT_MENU_SELECT_1:
						{
							// Set Charlie
							SimConnect_SetClientData(g_hSimConnect, 0, 2, 0, 0, 1, &c_mode);
						}
						break;

					case SIMCONNECT_TEXT_RESULT_MENU_SELECT_2:
						{
							// Set Standby
							SimConnect_SetClientData(g_hSimConnect, 0, 2, 0, 0, 1, &stby_mode);
						}
						break;

					case SIMCONNECT_TEXT_RESULT_MENU_SELECT_3:
						{
							// Send IDENT (probably need to send it more than once?)
							SimConnect_SetClientData(g_hSimConnect, 0, 4, 0, 0, 1, &x_ident);
						}
						break;
				}
			}
			break;
	}
}

// This callback processes all SimConnect related messages
// It is similar to the call in the dispatch handler (message pump) in a windows application
// But the interesting part is that no message pump is required for the dll
void CALLBACK SimConnectProcess(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext)
{
	// process SIMCONNECT_RECV_ID_XXX values here as needed
	switch(pData->dwID)
	{
		case SIMCONNECT_RECV_ID_OPEN:
			OnRecvOpen((SIMCONNECT_RECV_OPEN*)pData);
			break;

		case SIMCONNECT_RECV_ID_EVENT:
			OnRecvEvent((SIMCONNECT_RECV_EVENT*)pData);
			break;
	}
}

void DLLStart(void)
{
	// open connection to local SimConnect server
	SimConnect_Open(&g_hSimConnect, "SquawkBox_Transponder", NULL, 0, NULL, SIMCONNECT_OPEN_CONFIGINDEX_LOCAL);

	// register callback routine for message processing
	SimConnect_CallDispatch(g_hSimConnect, SimConnectProcess, NULL);
}

void DLLStop(void)
{
	// close connection to local SimConnect server
	SimConnect_Close(g_hSimConnect);
}

Link to comment
Share on other sites

feel free to use it/modify it/adapt it anyway you want.

Thanks Jesus! I'll see if I can add something to the assignment facilities in FSUIPC4. I should have looked myself to see if they were using SimConnect client data for this stuff!

Best Regards

Pete

Link to comment
Share on other sites

whether anything uses FSUIPC or not! That is a complete misunderstanding.

Pete

Exactly! thats what I meant with my response.. there seems to be a 'complete' misunderstanding!! the fact that SB4 uses SimConnect doesn't have ANYTHING to do with the fact that FSUIPC can still be used to trigger transponder modes the same way PTT works today...

My concern is that the guy who replied in that thread is Norman!! Well Known SB tester, VATSIM VP, Close to the SB developers!!! it would be fantastic if you jump in that thread and 'clarify' this for him.. I'm PRETTY sure he will raise this issue with Joel ASAP.

Jesus,

No misunderstanding at all. I personally use both Simconnect and FSUIPC for what I need. On an aside, whilst I dont expect a prompt answer, I'll nudge Joel once again.

Link to comment
Share on other sites

Norman,

I think we are all aware of the efforts (you) and proably others (Pete) trying to get Joel to jump on this issue. I guess the code I posted is my way of taking the matter into our own hands :)

Part of the 'confusion' with SB/FSUIPC is that there are lots of things not documented which makes trying to adapt/integrate SB really hard. Anyway, I guess things look good now :)

Link to comment
Share on other sites

Cockpit builders will be VERY happy if you add the facility ;)

does your code work? I'm concerned that the copy of SB4 I've installed might be faulty, but I can't find another. Here's why:

I enabled the loading of the SB4 transponder DLL with SimConnect logging enabled, and got this:

49.42971 DLL Loaded:  Path="E:\Squawkbox\sbtrans10.dll"  Version=""

> 55.19912 [253, 1]Open: Version=0x00000002  Name="SquawkBox_Transponder"
> 55.19914 [253, 2]SubscribeToSystemEvent:EventID=0, SystemEventName="1sec"
> 55.19915 [253, 3]MapClientDataNameToID:szClientDataName="SquawkBox Data", ClientDataID=0
> 55.19915 [253, 4]AddToClientDataDefinition:DefineID=0, dwOffset=1, dwSize=1, dwReserved=-1
> 55.19916 [253, 5]AddToClientDataDefinition:DefineID=1, dwOffset=2, dwSize=1, dwReserved=-1
> 55.19916 [253, 6]AddToClientDataDefinition:DefineID=2, dwOffset=17, dwSize=1, dwReserved=-1
> 55.19917 [253, 7]AddToClientDataDefinition:DefineID=3, dwOffset=18, dwSize=1, dwReserved=-1
> 55.19917 [253, 8]AddToClientDataDefinition:DefineID=4, dwOffset=19, dwSize=1, dwReserved=-1
> 55.19918 [253, 9]AddToClientDataDefinition:DefineID=5, dwOffset=20, dwSize=1, dwReserved=-1
> 55.19918 [253, 10]AddToClientDataDefinition:DefineID=6, dwOffset=21, dwSize=1, dwReserved=-1
> 55.19919 [253, 11]AddToClientDataDefinition:DefineID=7, dwOffset=22, dwSize=1, dwReserved=-1
> 55.19921 [253, 12]AddToClientDataDefinition:DefineID=8, dwOffset=24, dwSize=1, dwReserved=-1
> 55.19922 [253, 13]AddToClientDataDefinition:DefineID=9, dwOffset=25, dwSize=1, dwReserved=-1
> 55.19922 [253, 14]AddToClientDataDefinition:DefineID=10, dwOffset=26, dwSize=1, dwReserved=-1

So far, so good. But then:

> 55.19923 [253, 15]SetClientData:ClientDataID=0, DefineID=2, Flags=0, dwReserved=1, cbUnitSize=1, pDataSet=177838692
< 55.19924 [253] >>>>>  EXCEPTION=31, SendID=15, Index=5  <<<<<

which error is, I think, "parameter out of bounds", pointing to the dwReserved value of 1 (the SDK says it should be 0).

Then, repeated every 9 or 10 seconds:

> 75.76645 [253, 16]RequestClientData:ClientDataID=0, RequestID=0, DefineID=0, dwReserved1=-1, dwReserved2=0
< 75.76647 [253] >>>>>  EXCEPTION=25, SendID=16, Index=-1  <<<<<
> 75.76647 [253, 17]RequestClientData:ClientDataID=0, RequestID=1, DefineID=1, dwReserved1=-1, dwReserved2=0
< 75.76648 [253] >>>>>  EXCEPTION=25, SendID=17, Index=-1  <<<<<
> 75.76648 [253, 18]RequestClientData:ClientDataID=0, RequestID=2, DefineID=2, dwReserved1=-1, dwReserved2=0
< 75.76649 [253] >>>>>  EXCEPTION=25, SendID=18, Index=-1  <<<<<
> 75.76649 [252, 5]RequestClientData:ClientDataID=0, RequestID=0, DefineID=0, dwReserved1=-1, dwReserved2=0
< 75.76650 [252] >>>>>  EXCEPTION=25, SendID=5, Index=-1  <<<<<
> 75.76651 [253, 19]RequestClientData:ClientDataID=0, RequestID=3, DefineID=3, dwReserved1=-1, dwReserved2=0
< 75.76651 [253] >>>>>  EXCEPTION=25, SendID=19, Index=-1  <<<<<
> 75.76652 [253, 20]RequestClientData:ClientDataID=0, RequestID=5, DefineID=5, dwReserved1=-1, dwReserved2=0
< 75.76653 [253] >>>>>  EXCEPTION=25, SendID=20, Index=-1  <<<<<
> 75.76653 [253, 21]RequestClientData:ClientDataID=0, RequestID=6, DefineID=6, dwReserved1=-1, dwReserved2=0
< 75.76654 [253] >>>>>  EXCEPTION=25, SendID=21, Index=-1  <<<<<
> 75.76654 [253, 22]RequestClientData:ClientDataID=0, RequestID=7, DefineID=7, dwReserved1=-1, dwReserved2=0
< 75.76655 [253] >>>>>  EXCEPTION=25, SendID=22, Index=-1  <<<<<
> 75.76655 [253, 23]RequestClientData:ClientDataID=0, RequestID=8, DefineID=8, dwReserved1=-1, dwReserved2=0
< 75.76656 [253] >>>>>  EXCEPTION=25, SendID=23, Index=-1  <<<<<
> 75.76656 [253, 24]RequestClientData:ClientDataID=0, RequestID=9, DefineID=9, dwReserved1=-1, dwReserved2=0
< 75.76657 [253] >>>>>  EXCEPTION=25, SendID=24, Index=-1  <<<<<
> 75.76657 [253, 25]RequestClientData:ClientDataID=0, RequestID=10, DefineID=10, dwReserved1=-1, dwReserved2=0
< 75.76658 [253] >>>>>  EXCEPTION=25, SendID=25, Index=-1  <<<<<

where error 25 means "illegal operation"!

It does not bode well for any code I might add to FSUIPC if the module itself cannot set or read its own ClientData, does it?

Do you get these results? If not could you possibly ZIP and email me your SBtrans10.dll so I can see why there's a difference?

petedowson@btconnect.com

[LATER]

I think I may have found the answer to my questions, but I could do with confirmation. There's no call to "CreateClientData" in my SimConnect log. I assume this is because I haven't run the main SB4 program? It probably explains at least the Error 25's, though the error on the SetClientData looks like a real one.

Thanks!

Pete

Link to comment
Share on other sites

I completely re-wrote, cleaned and optimized everything :)

intead of using the 1sec event to write to the client area waiting until SB is up I decided to use SimConnect_RequestClientData and On a detected change I write the data, no more 1sec events, clean code now, also included custom private events for the shortcuts, but my choice of keys is not the best :)

Also, you don't see CreateClientArea because I do not write one, thats up to the SB4 main program, I simply hook to it using its name (which is Squackwbox Data) and mapping it via SimConnect_MapClientDataNameToID then I just need that ID to Set or Request data from the client area (the main SB program)

This zip includes, source, dll and readme.txt. feel free to use it anyway you want.

http://www.venetubo.com/XPND.zip

//Copyright (c) Jesus Altuve 2010.  All rights reserved. 
// Set Transponder modes via menu or shortcuts

#include "stdafx.h"
#include "simconnect.h"

// Define our global handle
HANDLE	g_hSimConnect;

// Our shortcut keys (you can use any combination eg. ctrl+shft+a) use the actual keystroke
char setCharly[]	= "F8\0";		// Sets Transponder mode Charly by pressing the F8 key
char setStby[]		= "F9\0";		// Sets Transponder mode Stby by pressing the F9 key
char sendIdnt[]		= "F3\0";		// Send IDENT by pressing the F3 key

// Transponder modes
bool	c_mode		= false;
bool	stby_mode	= true;
int		x_ident		= 2;

// Menu Array for our menu selections.
char szMenuText1[]	= "SquawkBox Transponder\0Select a transponder action/mode:\0Charly (or press the 'F8' key)\0Standby (or press the 'F9' key)\0IDENT (or press the 'F3' key)\0Close Window\0";

// Menu confirmation/responses
char charly_set[]	= "SquawkBox mode has been set to Charly\0";
char stby_set[]		= "SquawkBox mode has been set to StandBy\0";
char ident_sent[]	= "Ident sent\0";

// My Client Area ID's 
typedef enum
{
	SQUAWKBOX_CLIENT_ID,
} CLIENT_ID;

// My Data definition ID's 
typedef enum
{
	DATA_DEFINITION_0,
	DATA_DEFINITION_1,
	DATA_DEFINITION_2,
	DATA_DEFINITION_3,
	DATA_DEFINITION_4,
	DATA_DEFINITION_5,
	DATA_DEFINITION_6,
	DATA_DEFINITION_7,
	DATA_DEFINITION_8,
	DATA_DEFINITION_9,
	DATA_DEFINITION_10,
} DATA_DEFINITION_ID;

// A basic structure for a single item of returned data (used to request SB data)
struct StructOne { 
    bool    xpnd_mode; 
}; 

// My Request ID's
typedef enum
{
	SB_DATA_REQUEST_ID,
} REQUEST_ID;

// My System Event ID's
typedef enum
{
	KEY_1					= 100,
	KEY_2,
	KEY_3,
	MENU_SELECTION_1		= 500,
	MAIN_MENU				= 600,
} EVENT_ID;

// My Input group ID's
typedef enum
{
	GROUP_0,
} GROUP_ID;

// My Input ID's
typedef enum
{
	INPUT_1,
} INPUT_ID;

// My functions

// Map all my system events (the ones that require keyboard/controller input)
void mapMyEvents() {

	// Shortcuts (define the actual client event) leave the EventName blank for private client events or enter the event name for FSX events
	SimConnect_MapClientEventToSimEvent(g_hSimConnect, KEY_1);
	SimConnect_MapClientEventToSimEvent(g_hSimConnect, KEY_2);
	SimConnect_MapClientEventToSimEvent(g_hSimConnect, KEY_3);

	// Add all the defined client events to a notification group so we are notified of the actual keystroke 
	SimConnect_AddClientEventToNotificationGroup(g_hSimConnect, GROUP_0, KEY_1);
	SimConnect_AddClientEventToNotificationGroup(g_hSimConnect, GROUP_0, KEY_2);
	SimConnect_AddClientEventToNotificationGroup(g_hSimConnect, GROUP_0, KEY_3);

	// now, an input ID, the actual key stroke and the event they are associated with
	SimConnect_MapInputEventToClientEvent(g_hSimConnect, INPUT_1, setCharly, KEY_1);
	SimConnect_MapInputEventToClientEvent(g_hSimConnect, INPUT_1, setStby, KEY_2);
	SimConnect_MapInputEventToClientEvent(g_hSimConnect, INPUT_1, sendIdnt, KEY_3);

	// now turn ON simconnect for all events on the INPUT_1 group.
	SimConnect_SetInputGroupState(g_hSimConnect, INPUT_1, SIMCONNECT_STATE_ON);
}

// Sends Simconnect client data with a true/false switch for xpndr modes.
void setTransponderMode(bool toggle)
{
	SimConnect_SetClientData(g_hSimConnect, SQUAWKBOX_CLIENT_ID, DATA_DEFINITION_2, NULL, 0, 1, &toggle);
}

// Sends ident
void transponderIdent(int ident)
{
	SimConnect_SetClientData(g_hSimConnect, SQUAWKBOX_CLIENT_ID, DATA_DEFINITION_4, NULL, 0, 1, &ident);
}

void OnRecvOpen (SIMCONNECT_RECV_OPEN *pOpen)
{
	HRESULT hr;

	// create menu title
	SimConnect_MenuAddItem(g_hSimConnect, "SquawkBox Transponder", MAIN_MENU, 0);

	// We need to know the client area 'name' and map it to a client ID
	SimConnect_MapClientDataNameToID(g_hSimConnect, "SquawkBox Data", SQUAWKBOX_CLIENT_ID);

	// Let's register the data structures we plan on using (values were taken from the simconnect debug output of sbtrans10.dll) Offset and size are defined here.
	SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_0, 1, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_1, 2, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_2, 17, 1);	// Transponder Modes
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_3, 18, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_4, 19, 1);	// Ident toggle
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_5, 20, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_6, 21, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_7, 22, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_8, 24, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_9, 25, 1);
    SimConnect_AddToClientDataDefinition(g_hSimConnect, DATA_DEFINITION_10, 26, 1);

	// Map all my custom client events
	mapMyEvents();

	// Request the data from SB only when its changed and only ONCE so we don't have to run a 1sec event to get/set this info ;)
	hr = SimConnect_RequestClientData(g_hSimConnect, SQUAWKBOX_CLIENT_ID, SB_DATA_REQUEST_ID, DATA_DEFINITION_2, SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED, 0, 0, 1);
}

// This will proccess al the received data structures
void OnRecvClientData (SIMCONNECT_RECV_CLIENT_DATA *pData)
{
		switch(pData->dwRequestID) 
            { 
                case SB_DATA_REQUEST_ID: 
                { 
                    StructOne *pS = (StructOne*)&pData->dwData; 

					// Now, process the simple data structure we defined earlier.

					// assign the xpnd_mode variable we defined in the simple struct above and the confirmation message.
                    bool current = pS->xpnd_mode; 
					char init_msg[] = "When connecting to VATSIM your transponder will automatically be set to STBY mode.";

					// If the transponder is set to CHARLY mode, we set it to STBY, but only if this is the first time a 
					// simconnect session has been established, that way if SB crashes and we open it again is will be set to 
					// CHARLY and controllers won't bug us. Also NOTIFY the user of this mode change.
					if (current == false) {
						setTransponderMode(stby_mode);
						SimConnect_Text(g_hSimConnect, SIMCONNECT_TEXT_TYPE_SCROLL_WHITE, 8.0f, 0, sizeof(init_msg), init_msg);
					}
                }
				break;
			}
}

// This will proccess al the received events
void OnRecvEvent (SIMCONNECT_RECV_EVENT *pEvent)
{

	switch (pEvent->uEventID)
	{
	// process menu key events

		case KEY_1:
			{
				setTransponderMode(c_mode);
			}
			break;

		case KEY_2:
			{
				setTransponderMode(stby_mode);
			}
			break;

		case KEY_3:
			{
				transponderIdent(x_ident);
			}
		break;		

		case MAIN_MENU:
			{
				SimConnect_Text(g_hSimConnect, SIMCONNECT_TEXT_TYPE_MENU, 0.0f, MENU_SELECTION_1, ARRAYSIZE(szMenuText1), szMenuText1);
			}
		break;

		// process item selection from menu #1
		case MENU_SELECTION_1:
			{
				switch (pEvent->dwData)
				{
					case SIMCONNECT_TEXT_RESULT_MENU_SELECT_1:
						{
							// Set Charlie
							setTransponderMode(c_mode);
							SimConnect_Text(g_hSimConnect, SIMCONNECT_TEXT_TYPE_SCROLL_WHITE, 3.0f, 0, sizeof(charly_set), charly_set);
						}
						break;

					case SIMCONNECT_TEXT_RESULT_MENU_SELECT_2:
						{
							// Set Standby
							setTransponderMode(stby_mode);
							SimConnect_Text(g_hSimConnect, SIMCONNECT_TEXT_TYPE_SCROLL_WHITE, 3.0f, 0, sizeof(stby_set), stby_set);
						}
						break;

					case SIMCONNECT_TEXT_RESULT_MENU_SELECT_3:
						{
							// Send IDENT (probably need to send it more than once? test test test!)
							transponderIdent(x_ident);
							SimConnect_Text(g_hSimConnect, SIMCONNECT_TEXT_TYPE_SCROLL_WHITE, 3.0f, 0, sizeof(ident_sent), ident_sent);
						}
						break;
				}
			}
			break;
	}
}

// This callback processes all SimConnect related messages
// It is similar to the call in the dispatch handler (message pump) in a windows application
// But the interesting part is that no message pump is required for the dll
void CALLBACK SimConnectProcess(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext)
{

	// process SIMCONNECT_RECV_ID_XXX values here as needed
	switch(pData->dwID)
	{
		// Process HRESULT return structure when opening connection for the first time
		case SIMCONNECT_RECV_ID_OPEN:
			OnRecvOpen((SIMCONNECT_RECV_OPEN*)pData);
			break;

		// Process HRESULT return structures for Events
		case SIMCONNECT_RECV_ID_EVENT:
			OnRecvEvent((SIMCONNECT_RECV_EVENT*)pData);
			break;

		// Process HRESULT return structures for data
		case SIMCONNECT_RECV_ID_CLIENT_DATA:
			OnRecvClientData((SIMCONNECT_RECV_CLIENT_DATA*)pData);
			break;
	}
}

void DLLStart(void)
{
	// open connection to local SimConnect server
	SimConnect_Open(&g_hSimConnect, "SquawkBox Alternative Transponder", NULL, 0, NULL, SIMCONNECT_OPEN_CONFIGINDEX_LOCAL);

	// register callback routine for message processing
	SimConnect_CallDispatch(g_hSimConnect, SimConnectProcess, NULL);

}

void DLLStop(void)
{
	// close connection to local SimConnect server
	SimConnect_Close(g_hSimConnect);
}

Cheers,

Link to comment
Share on other sites

I completely re-wrote, cleaned and optimized everything :)

Thanks! I'll certainly take a look! Meanwhile I have been working on it too, and interim version 4.611 or FSUIPC contains the code to drive the SB4 Transponder too.

http://fsuipc.simflight.com/beta/FSUIPC4611.zip

I've tested it insofar as it does what I think it should do, but I've not tested it "live" with SB4 running because, to be honest, it's been several years since I tried using it and I've completely forgotten everything about it. I've not got time to do any revision at present, but if you are a regular SB4 user (or anyone else reading this), please do test it for me and let me know.

This is what I've done:

1. Used the SB3 offset method (7B91 for mode, 7B93 for ident) to determine when to send the Client Data changes to SB4. This basically should make any program or assignment which worked with SB3 on FSUIPC3 also now work with SB4 and FSUIPC4. This applies, for instance, to the hardware transponder driver in my PFCFSX.DLL driver for the PFC centre console that I use in my cockpit.

2. Added assignable controls to operate those offsets. This is "icing on the cake" really, but it makes it easier and more obvious. I've also added them to FSUIPC3 for SB3 (with the appropriate control name change of course):

Xpndr stby (sb4)

Xpndr on/mode c (sb4)

Xpndr toggle (sb4)

Xpndr ident (sb4)

I hope all these workthey should do!

Thanks for your help!

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.