Jump to content

Recommended Posts

Posted

Hi all.

 

Can anyone tell me if it is possible to establish the FSX installation folder from a remote SimConnect client?

 

I want to drop a hand crafted .flt file on to the server from my client app and use the SimConnect_FlightLoad() function to load it up. Whilst I happen to know the server name and can map a network drive for my development environment, I'd like to abstract things if possible such that all I have "hard coded" on the client is the SimConnect.cfg file location. However, this only gives me an IP address and port of the SimConnect server and I don't think that that is enough to build code to put my .flt file somewhere that FSX will be able to see.

 

As far as I have found out so far, FSX was written at a point when it was fashionable to put these kind of environment variables in the Registry. I don't know where to start having my client query the registry of a remote machine.

 

Help!!!!!! (please) :help: :smile:

 

Z

Posted

As a bit of an answer to my own question, it may be that establishing the FSX folder from the client is irrelevant. If I ever get to the point of "productionising" my code (I made that word up), I suppose that I'll need to run a setup on both the client and the server. The server setup could create a folder to use for my temporary flight files and the client setup could specify a path to my server location which I could test at that point. If the network is subsequently reconfigured then I can just have my code do a Gallic Shrug and say "Whoops! You've changed your network or somefink. Sort it out or re-run Setup".

 

It just seemed elegant to try and leverage off a working SimConnect connection to load a flight file - though I appreciate it opens up a can of worms regarding user context and permissions. Your thoughts on the matter are welcome...

 

Z

Posted

Oops! Too hasty.

 

I can prepare my flight file on the client from a local template and copy it across to the server by specifying a path. However, this path to the server is NOT the same as the SimConnect_FlightLoad() needs to see. An example in pseudo code:

//Work out where the Server is and build a path to an administrative share
ServerIP = GetSectionEntry("SimConnect", "Address", SCConfigPath)
ServerPath = "\\" & ServerIP & "E$\FSX\ClientAppTemplate.flt"

//Get a temporary file name and copy a known template flight file to it
myFlightFile = GetTempFile()
CopyFile LocalTemplate, myFlightFile

//Edit it to write my desired position etc
myFlightFile.WriteSectionEntry("Simvars.1","Latitude","N51d0m11.6s")
myFlightFile.WriteSectionEntry("Simvars.1","Longitude","W0d32m3.8s")
myFlightFile.WriteSectionEntry("Simvars.1","Altitude","180")

//Copy the file across to the FSX machine
CopyFile myFlightFile, ServerPath

//Load it
hr=SimConnect_FlightLoad(hSimConnect, ServerPath)

//Tidy up
Kill myFlightFile

...

Alas this cannot work. Whilst the ServerPath is indeed the path to my new flight file, the FlightLoad fails because it is looking for an absolute or relative path from the perspective of the server machine. For now I can hard code path references and get my new file to load (yay!) though I have more debugging to do.

 

Note that I'm not actually writing Lat and Lon values as those strings in the pseudo code but radian values that come from elsewhere. This may be the cause of one of my bugs but we'll see.

 

 

Thanks for looking in.

 

Z

 

  • 2 weeks later...
Posted

Just by way of an update:
 
This general model is proving quite successful. Editing .flt files dynamically provides a straightforward way to load a desired configuration programmatically without having to do lots of work issuing SetDataOnSimObject and TransmitClientEvent commands. For my purposes there are also advantages to loading everything I'm interested in as a single transaction.
 
However, the fact that my client code is expected to be on a remote machine causes fairly ugly issues with moving things around the file system. I've realised that the reason I can't find information about the FSX installation on the remote machine is probably by design. There's a security implication of letting any old remote application have information that might allow that application to transfer files/code to or from the machine. I suppose I'd like to operate in a way similar to how a Windows Service works such that my application can be trusted within bounds. I guess that whatever happens, there is going to need to be some authentication going on before I can establish where to place my "code-crafted" .flt file and how to reference it when I want to load.
 
I do have another issue regarding setting Communications Radio frequencies. From what I've read, I ought to be sending BCD values but I can't get this to work e.g. If I send:

Dim myNewFreq as Long, hr as Long

myNewFreq = 2855

hr = SimConnect_TransmitClientEvent(hSimConnect, SIMCONNECT_OBJECT_ID_USER, EVENT_COMM1FREQ_SET, myNewFreq, GROUP1, 0)

 
If I send a string that looks hexadecimal, then FSX duly changes frequency - e.g.:
 

Dim myNewFreq as String, hr as Long

myNewFreq = "&H" & "128550"

hr = SimConnect_TransmitClientEvent(hSimConnect, SIMCONNECT_OBJECT_ID_USER, EVENT_COMM1FREQ_SET, myNewFreq, GROUP1, 0)

 
I can't figure out why this works as it looks to me like I've declared a function to expect a Long then sent it a String. Anyone with a large shovel that can fill a big hole in my understanding will be most welcome. :D
 
Likewise, any thoughts on how best to handle the security issue in the first part?
 
Thanks in advance,
 
Z

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
  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...