• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS Connection between Microsoft Flight Simulator and external simulation engine.

Messages
8
Country
russia
I am porting the Tu-154B-2 from X-Plane, for which I write an engine that can simulate "directly rewritten to C" LUA scripts, and executed it as a QT application.

And at the moment I have:
-Completely rewritten Datarefs;
-The "core" of the engine itself, which executes the logic of the systems in separate threads;
-10 rewritten systems, including a time period counting system.

_Uylvdx3gjs (1).jpg


Now the most difficult part has come - data exchange via SimConnect.

Actually, I would like to know how to better ensure data exchange and work with SimConnect.
Now I have an idea that Time Logic is called only after updating the SimConnect survey, which can be set to a period in the form of sending data every frame, and in the same function immediately read the current time and period, but is this a good option, and how can it be written in code?

Сравнение.png


And current Time Logic:

скрин.png

SIM_TIME.total_running_time_sec - is what I want from Simulator.
 
Text of code:

CORE:
while (OTCA_INIT_SIM_RUN == 1) {
//Подготовка отсчета времени цикла
clock_t cycle_start = clock();


CYCLE.current_opperation = 0;


fprintf(stdout, "### Sim Cycle Started ###\n\n");


//Set permission to execute the algorithm
//TIME LOGIC
time_logic_run();
time_logic_passed(); //Waiting for the Time Logic simulation assurance
//MAIN PANEL
//acs
main_panel_acs_run();
//clock24
main_panel_clock24_run();
//mech_aneroid
main_panel_mech_aneroid_run();
//svs
main_panel_svs_run();
//termo
main_panel_termo_run();
//uvid_15fk
main_panel_uvid_15fk_run();
//mach_meters
main_panel_mach_meters_run();
//uap14
main_panel_uap14_run();
//eup53
main_panel_eup53_run();


//Ожидание завершения симуляции
sem_wait(&CYCLE.core_semaphore);


//Подсчет времени обработки симуляции
OTCA_CORE_DATA->cycle_time = (double)(clock() - cycle_start);
fprintf(stdout, "------------\nCycle time = %f\n", OTCA_CORE_DATA->cycle_time);
//Ожидание конца симуляции
Sleep((uint32_t)((OTCA_INIT_SIM_PERIOD - OTCA_CORE_DATA->cycle_time) * 1000));
fprintf(stdout, "\n### Sim Cycle Passed ###\n\n");


}


TIME LOGIC:
void * time_logic_update(void * opaque) {
PROP_CYCLE *CYCLE = (PROP_CYCLE*)opaque;

double time_last = SIM_TIME.total_running_time_sec; // time for previous frame
double last_m = FLIGHTMODEL_POSITION.M;

while (OTCA_INIT_SIM_RUN) {
sem_wait(&time_logic_work);

//time calculations
double time_now = SIM_TIME.total_running_time_sec;
double passed = fabs(time_now - time_last);
double curent_m = FLIGHTMODEL_POSITION.M;
//print(passed)
if (curent_m - last_m == 0) {
passed = 0;
}
if (passed > 0.1) {
passed = 0.1;
}

TIME.frame_time = passed;

//last variables
time_last = time_now;
//last_m = curent_m

fprintf(stdout, "Time logic Passed\n");
pthread_mutex_lock(&CYCLE->cycle_mutex);
CYCLE->current_opperation = CYCLE->current_opperation + 1;
if (CYCLE->current_opperation == CYCLE->all_operations) {
sem_post(&CYCLE->core_semaphore);
}
pthread_mutex_unlock(&CYCLE->cycle_mutex);
sem_post(&time_logic_wait);
}
return NULL;
}

Or can I make function, that is executed before starting the engine core and creates all the necessary data requests via SimConnect, and then I can access requested data from the structure, or my Dataref Vars ?
 
I'm not sure I understand what you're asking for, but here are some basic considerations that might help (from someone who developed for xplane and now for MSFS)

dataref (in xplane) = simvars (in MSFS) but, in MSFS there are many types of vars, most importants:
-simvars (native vars in MSFS, https://docs.flightsimulator.com/html/Programming_Tools/SimVars/Simulation_Variables.htm)
-lvars (custom vars that you can add to the aircraft/sim)

with Simconnect you can create an external app to read/write ONLY simvars
basic steps:
-define a sim connection
-define the simvars you want to read/write
-define period of time you want MSFS to send you simvars values for your app to read them (similar to xplane callbacks, but no so flexible, periods availabe: every change, every second, every frame)
-for writing a simvar you can do it whenever you want

for read/write LVARS, you need an in-game wasm module.
a wasm module can use Simconnect in the same way that in an external app
but, a wasm module can us the gauge API to read/write LVARs

If you are looking to code complex aircraft systems, you will need to go to a wasm module.

Also there are html/js gauges but I dont know nothing about them.

D.
 
Yes, I wrote everything too spontaneously.

In general, I added all the variables that related to Custom Avionics in X-Plane to my external engine.
The problem is that I don't understand how the data request works, the documentation is written very crookedly, and for the most part in two stages.
There is no question about writing data to the simulator, because only after SU12 it will be possible to write LVars via SimConnect.

For clarity, I need a C++ function that would return the current time in the simulator in seconds, I understood a little how it works, but I didn't really manage to write it.

Actually, the fact that you can set the variable name, data type and polling period, and then what to where, is no longer clear.
 
Do you try SDK simconnect examples?

and what do you mean with "the current time in the simulator"?

I apologize but I am not understanding what is the problem with time, are you trying to create a timer dependent on the simulator?
 
Actually, I can still try to understand code from examples.

But which variable do I need to get the absolute time? I haven't found it anywhere in the documentation.
are you trying to create a timer dependent on the simulator ?
...So, yes..
 
Last edited:
As far as I remember there is no simvar with the absolute time of the sim (I understand this would be a continuous counter started when loading the sim, correct?)
 
I would like to get at least some time from the simulator, like UTC time in the Simulator, well, or the time from the counter.
Although I understand that you can suggest me to create a counter in WASM ?

It is also necessary to make a clock on the plane)
 
I have remembered that there are legacy simvars not documented on the MSFS2020 page, in this link you will find several that may be useful (see the section Environment Data), although they are not documented they still exist in the simulator engine.


ABSOLUTE TIMETime, as referenced from 12:00 AM January 1, 0000SecondsN-
ZULU TIMEGreenwich Mean Time (GMT)SecondsN-
ZULU DAY OF WEEKGMT day of weekNumberN-
ZULU DAY OF MONTHGMT day of monthNumberN-
ZULU MONTH OF YEARGMT month of yearNumberN-
ZULU DAY OF YEARGMT day of yearNumberN-
ZULU YEARGMT yearNumberN-
LOCAL TIMELocal timeSecondsN-
LOCAL DAY OF WEEKLocal day of weekNumberN-
LOCAL DAY OF MONTHLocal day of monthNumberN-
LOCAL MONTH OF YEARLocal month of yearNumberN-
LOCAL DAY OF YEARLocal day of yearNumberN-
LOCAL YEARLocal yearNumberN-
TIME ZONE OFFSETLocal time difference from GMTSecondsN-
TIME OF DAYGeneral time of day:
1 = Day
2 = Dusk/Dawn
3 = Night
Enum
 
I have remembered that there are legacy simvars not documented on the MSFS2020 page, in this link you will find several that may be useful (see the section Environment Data), although they are not documented they still exist in the simulator engine.


ABSOLUTE TIMETime, as referenced from 12:00 AM January 1, 0000SecondsN-
ZULU TIMEGreenwich Mean Time (GMT)SecondsN-
ZULU DAY OF WEEKGMT day of weekNumberN-
ZULU DAY OF MONTHGMT day of monthNumberN-
ZULU MONTH OF YEARGMT month of yearNumberN-
ZULU DAY OF YEARGMT day of yearNumberN-
ZULU YEARGMT yearNumberN-
LOCAL TIMELocal timeSecondsN-
LOCAL DAY OF WEEKLocal day of weekNumberN-
LOCAL DAY OF MONTHLocal day of monthNumberN-
LOCAL MONTH OF YEARLocal month of yearNumberN-
LOCAL DAY OF YEARLocal day of yearNumberN-
LOCAL YEARLocal yearNumberN-
TIME ZONE OFFSETLocal time difference from GMTSecondsN-
TIME OF DAYGeneral time of day:
1 = Day
2 = Dusk/Dawn
3 = Night
Enum
Thanks))
I didn't know about it, and I already started writing a counter in nanoseconds in the engine))
 
Back
Top