• 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.

Frequencies again!

  • Thread starter Thread starter mgh
  • Start date Start date

mgh

Messages
1,413
Country
unitedkingdom
Why?

This code returns FreqMhz = 128.30 which is correct:

Code:
double FreqMHz;
.
.
.
struct AIRCRAFT_RADIO
{
double FreqCom1A;
};
.
.
.
SimConnect_AddToDataDefinition(hSimConnect,
                               DATA_AIRCRAFT_RADIO,
                               "COM ACTIVE FREQUENCY:1",
                               "MHz");
.
.
.
switch (pObjData->dwRequestID)
    {
 case REQ_AIRCRAFT_RADIO:
        {                                                           
        // Cast void pointer to point to new data structure
        AIRCRAFT_RADIO *pS = (AIRCRAFT_RADIO *)&pObjData->dwData;

        // Extract data from structure
        FreqMHz = pS->FreqCom1A;
.
.
.

Changing to this (with changes highlighted in red) returns FreqBCD = 0

Code:
[COLOR="Red"]short int FreqBCD;
.[/COLOR].
.
.
.
.struct AIRCRAFT_RADIO
{
[COLOR="red"]short int FreqCom1A;[/COLOR]
};
.
.
.
SimConnect_AddToDataDefinition(hSimConnect,
                               DATA_AIRCRAFT_RADIO,
                               "COM ACTIVE FREQUENCY:1",
                               [COLOR="red"]"Frequency BCD16");[/COLOR]
.
.
.
switch (pObjData->dwRequestID)
    {
    case REQ_AIRCRAFT_RADIO:
        {                                                           
        // Cast void pointer to point to new data structure
        AIRCRAFT_RADIO *pS = (AIRCRAFT_RADIO *)&pObjData->dwData;

        // Extract data from structure
       [COLOR="red"] FreqBCD = pS->FreqCom1A;[/COLOR]
.
.
.
 
Last edited:
Why?

This code returns FreqMhz = 128.30 which is correct:

Changing to this (with changes highlighted in red) returns FreqBCD = 0

Code:
SimConnect_AddToDataDefinition(hSimConnect,
                               DATA_AIRCRAFT_RADIO,
                               "COM ACTIVE FREQUENCY:1",
                               [COLOR="red"]"Frequency BCD16");[/COLOR]

Try:
SimConnect_AddToDataDefinition(hSimConnect,DATA_AIRCRAFT_RADIO,"COM ACTIVE FREQUENCY:1","Frequency BCD16", SIMCONNECT_CLIENTDATATYPE_INT16);

SimConnect_AddToDataDefinition defaults to requesting information in a FLOAT64 format if you don't ask it to do otherwise.

Doug
 
Thanks. I tried that without success. It results in pObjData->dwRequestID always being equal to zero so it never now goes beyond the switch statement. The following snippet shows the revised statements in red adjacent to the initial, working statements in green now commented out.
Code:
[COLOR="SeaGreen"]]//double FreqMHz;[/COLOR]
[COLOR="Red"]unsigned short FreqBCD;[/COLOR]

struct AIRCRAFT_RADIO
{
[COLOR="seagreen"]//double FreqCom1A;[/COLOR]
[COLOR="Red"]unsigned short FreqCom1A;[/COLOR]
};



SimConnect_AddToDataDefinition(hSimConnect,
                               DATA_AIRCRAFT_RADIO,
                               "COM ACTIVE FREQUENCY:1",
                               [COLOR="seagreen"]//"MHz");[/COLOR]
                             [COLOR="red"]  "Frequency BCD16",
                               SIMCONNECT_CLIENTDATATYPE_INT16);[/COLOR]

SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData =  (SIMCONNECT_RECV_SIMOBJECT_DATA *) pData;

// Get object ID
//DWORD ObjectID = pObjData->dwObjectID;

// Switch based on Request ID
switch (pObjData->dwRequestID)
    {
    case REQ_AIRCRAFT_RADIO:
        {                                                           
        // Cast void pointer to point to new data structure
        AIRCRAFT_RADIO *pS = (AIRCRAFT_RADIO *)&pObjData->dwData;

        // Extract data from structure
       [COLOR="seagreen"] // FreqMHz = pS->FreqCom1A;[/COLOR]
      [COLOR="red"] FreqBCD = pS->FreqCom1A;[/COLOR]
 
Gerry,

This is working:

Code:
short int iFreq;

static enum DATA_DEFINE_ID {
  DATA_DEFINITION_PLANE_POSITION=128,
  DATA_DEFINITION_AIRCRAFT_RADIO
};

static enum DATA_REQUEST_ID{
  DATA_REQUEST_PLANE_POSITION=192,
  DATA_REQUEST_AIRCRAFT_RADIO,
};

void OnRecvOpen (SIMCONNECT_RECV_OPEN *pOpen)
{
SimConnect_AddToDataDefinition(hSimConnect,DATA_DEFINITION_AIRCRAFT_RADIO,"COM ACTIVE FREQUENCY:1","Frequency BCD16",SIMCONNECT_DATATYPE_INT32);
SimConnect_RequestDataOnSimObject(hSimConnect, DATA_REQUEST_AIRCRAFT_RADIO, DATA_DEFINITION_AIRCRAFT_RADIO, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SIM_FRAME, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED);
}

void OnRecvSimobjectData(SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData, DWORD cbData)
{
switch( pObjData->dwRequestID )
  {
  case DATA_REQUEST_AIRCRAFT_RADIO:
  iFreq = *(short int*)&pObjData->dwData;
  break;
  }
}
 
Thanks. It has to be SIMCONNECT_DATATYPE_INT32 even though unsigned short is 16 bits.

EDIT

It's now become a bit academic because I've just realised I can extract the digits more easily from a double FreqMHz.

Code:
String s = FloatToStrF(FreqMHz, ffFixed, 6, 2);

char Digit1 = s[1];
char Digit2 = s[2];
...
 
Last edited:
Back
Top