Exemplo n.º 1
0
// ***************** IAS Button and light ******************
void process_ias_button()
{

    if (loaded737 == 1) {
         if (multires > 0) {
             if (testbit(multibuf, IAS_BUTTON)) {
                 if (xpanelsfnbutton == 1) {
                     XPLMCommandOnce(x737mcp_spd_changeover);
                 }
                 if (xpanelsfnbutton == 0) {
                     XPLMCommandOnce(x737mcp_lvlchange_toggle);
                     lastappos = 1;
                 }
             }
         }

         // Always match x737 glareshield LED
         switch (XPLMGetDatai(x737mcp_lvlchange_led)) {
             case 1:
                 btnleds |= (1<<3);
                 break;
             case 0:
                 btnleds &= ~(1<<3);
                 break;
         }
     } else {
        if (multires > 0) {
          if(testbit(multibuf,IAS_BUTTON)) {
            if(xpanelsfnbutton == 1) {
                 if (XPLMGetDatai(AirspeedIsMach) == 1) {
                     XPLMSetDatai(AirspeedIsMach, 0);
                 } else {
                     XPLMSetDatai(AirspeedIsMach, 1);
                 }
             }
             if(xpanelsfnbutton == 0) {
                 XPLMCommandOnce(ApIasBtn);
                 lastappos = 1;
             }

          }
        }
        switch(XPLMGetDatai(ApIasStat)){
          case 2:
            btnleds |= (1<<3);   // * set bit 3 in btnleds to 1 *
            break;
          case 1:
            if (flashon == 1) {
              btnleds |= (1<<3);   // * set bit 3 in btnleds to 1 *
            }
            if (flashon == 0) {
              btnleds &= ~(1<<3);   // * clear bit 3 in btnleds to 0 *
            }
            break;
          case 0:
            btnleds &= ~(1<<3);   // * clear bit 3 in btnleds to 0 *
            break;
        }
    }
}
Exemplo n.º 2
0
int SwitchPanelCommandHandler(XPLMCommandRef    inCommand,
                             XPLMCommandPhase  inPhase,
                             void *            inRefcon) {
//	XPLMDebugString("-> CP: SwitchPanelCommandHandler: start.\n");
//	char Buffer[256];
//	sprintf(Buffer,"Cmdh handler: 0x%08x, %d, 0x%08x\n", inCommand, inPhase, inRefcon);
//	XPLMDebugString(Buffer);
	int status = CMD_PASS_EVENT;

 switch ((int)(inRefcon)) {
		case SP_CMD_LANDING_GEAR_UP:
		case SP_CMD_LANDING_GEAR_DOWN:
			gSpGearRetract = (XPLMGetDatai(gSpGearRetractDataRef));
			gSpOnGround = (XPLMGetDatai(gSpOnGroundDataRef));
			XPLMGetDatavf(gSpLandingGearStatusDataRef, gSpLandingGearStatus, 0, 10);
			gSpGear1Fail = (XPLMGetDatai(gSpGear1FailDataRef));
			gSpGear2Fail = (XPLMGetDatai(gSpGear2FailDataRef));
			gSpGear3Fail = (XPLMGetDatai(gSpGear3FailDataRef));
			break;
		default:
			break;
 }

 return status;
}
Exemplo n.º 3
0
// ***************** HDG Button and light *******************
void process_hdg_button()
{

    if (loaded737 == 1) {
        if (multires > 0) {
            if (testbit(multibuf, HDG_BUTTON)) {
                XPLMCommandOnce(x737mcp_hdg_toggle);
                lastappos = 1;
            }
        }

        // Always match x737 glareshield LED
        switch (XPLMGetDatai(x737mcp_hdg_led)) {
            case 1:
                btnleds |= (1<<1);
                break;
            case 0:
                btnleds &= ~(1<<1);
                break;
        }
    } else {
        if (multires > 0) {
          if(testbit(multibuf,HDG_BUTTON)) {

            if(xpanelsfnbutton == 1) {
                rhdgf = XPLMGetDataf(MHdg);
                XPLMSetDataf(ApHdg, rhdgf);
            }
            if(xpanelsfnbutton == 0) {
                XPLMCommandOnce(ApHdgBtn);
                lastappos = 1;
            }
          }
        }
        
        switch(XPLMGetDatai(ApHdgStat)){
          case 2:
            btnleds |= (1<<1);   // * set bit 1 in btnleds to 1 *
            break;
          case 1:
            if (flashon == 1) {
              btnleds |= (1<<1);   // * set bit 1 in btnleds to 1 *
	    }else{   
              btnleds &= ~(1<<1);   // * clear bit 1 in btnleds to 0 *
	    }
            break;
          case 0:
            btnleds &= ~(1<<1);   // * clear bit 1 in btnleds to 0 *
            break;
        }
	if (XPLMGetDatai(ApMstrStat) == 0) {
          btnleds &= ~(1<<1);   // * clear bit 1 in btnleds to 0 *
	}
    }
}
Exemplo n.º 4
0
// ***************** Blank Display *******************
void process_multi_blank_display()
{

if (XPLMGetDatai(AvPwrOn) == 0) {
  multiseldis = 5;
}
if (XPLMGetDatai(BatPwrOn) == 0) {
  multiseldis = 5;
}

}
Exemplo n.º 5
0
// ***************** REV Button and light *******************
void process_rev_button()
{
    if (revbuttonremap == 1) {
        if (multires > 0) {
          if(testbit(multibuf,REV_BUTTON)) {
            XPLMCommandOnce(RevButtonRemapableCmd);
            lastappos = 1;
          }
        }
	switch(XPLMGetDatai(ApRevStat)){
	  case 2:
            btnleds |= (1<<7);   // * set bit 7 in btnleds to 1 *
            break;
          case 1:
	    if (flashon == 1) {
              btnleds |= (1<<7);   // * set bit 7 in btnleds to 1 *
	    }else{    
              btnleds &= ~(1<<7);   // * clear bit 7 in btnleds to 0 *
	    }
            break;
          case 0:
            btnleds &= ~(1<<7);   // * clear bit 7 in btnleds to 0 *
            break;
	} 
    } else {

        if (multires > 0) {
          if(testbit(multibuf,REV_BUTTON)) {
            XPLMCommandOnce(ApRevBtn);
            lastappos = 1;
          }
        }
        switch(XPLMGetDatai(ApRevStat)){
          case 2:
            btnleds |= (1<<7);   // * set bit 7 in btnleds to 1 *
            break;
          case 1:
            if (flashon == 1) {
              btnleds |= (1<<7);   // * set bit 7 in btnleds to 1 *
            }else{
              btnleds &= ~(1<<7);   // * clear bit 7 in btnleds to 0 *
            }
            break;
          case 0:
            btnleds &= ~(1<<7);   // * clear bit 7 in btnleds to 0 *
            break;
        }

    }

}
Exemplo n.º 6
0
// ***************** VS Button and light *******************
void process_vs_button()
{

    if (loaded737 == 1) {
        if (multires > 0) {
            if (testbit(multibuf, VS_BUTTON)) {
                XPLMCommandOnce(x737mcp_vs_toggle);
                lastappos = 1;
            }
        }
        switch (XPLMGetDatai(x737mcp_vvi_led)) {
            case 1:
                btnleds |= (1<<5);
                break;
            case 0:
                if (XPLMGetDatai(x737mcp_vvi_armed_led)) {
                    if (flashon == 0) {
                        btnleds |= (1<<5);
                    } else {
                        btnleds &= ~(1<<5);
                    }
                } else {
                    btnleds &= ~(1<<5);
                }
                break;
        }
    } else {
        if (multires > 0) {
          if(testbit(multibuf,VS_BUTTON)) {
            XPLMCommandOnce(ApVsBtn);
            lastappos = 1;
          }
        }
	switch(XPLMGetDatai(ApVsStat)){
	  case 2:
            btnleds |= (1<<5);   // * set bit 5 in btnleds to 1 *
            break;
          case 1:
	    if (flashon == 0) {
              btnleds |= (1<<5);   // * set bit 5 in btnleds to 1 *
	    }else{   
              btnleds &= ~(1<<5);   // * clear bit 5 in btnleds to 0 *
	    }
            break;
          case 0:
            btnleds &= ~(1<<5);   // * clear bit 5 in btnleds to 0 *
            break;
        }
    }
}
int	createGNSWindow()
{
    int res = 0;

    XPLMCreateWindow_t win;
    win.structSize = sizeof(XPLMCreateWindow_t);
    win.left = g_pos_x;
    win.top = g_pos_y + (int)(gpGNSIntf->bezel_height*g_zoom);
    win.right = g_pos_x+(int)(gpGNSIntf->bezel_width*g_zoom);
    win.bottom = g_pos_y;
    win.visible = true;
    win.drawWindowFunc = myDrawWindowCallback;
    win.handleMouseClickFunc = myHandleMouseClickCallback;
    win.handleKeyFunc = myHandleKeyCallback;
    win.handleCursorFunc = myHandleCursorCallback;
    win.handleMouseWheelFunc = myHandleMouseWheelFunc;
    win.refcon = NULL;



    //Register the Draw Window
    // Create a windows for displaying the projection info
    gWindow = XPLMCreateWindowEx(&win);

    logMessageEx("--- GNS Window created");

    initTextures();
    logMessageEx("--- Textures created");

    /// Register so that our gauge is drawing during the Xplane gauge phase
    XPLMRegisterDrawCallback(myDrawGNSCallback, xplm_Phase_Window, 1, NULL); // before window draw
    logMessageEx("--- DrawCallback registered");

    //Register the callback for gUpdateInterval.  Positive intervals
    //are in seconds, negative are the negative of sim frames.  Zero
    //registers but does not schedule a callback for time.
    XPLMRegisterFlightLoopCallback(myFlightLoopCallback, gUpdateInterval, NULL);
    logMessageEx("--- FlightLoopCallback registered");

    //Set the initial values of the COM and NAV
    gGNSx30Proxy.setCOMActiveFrequency(XPLMGetDatai(g_com1_active_ref)*10);
    gGNSx30Proxy.setCOMStandbyFrequency(XPLMGetDatai(g_com1_standby_ref)*10);
    gGNSx30Proxy.setNAVActiveFrequency(XPLMGetDatai(g_nav1_active_ref)*10);
    gGNSx30Proxy.setNAVStandbyFrequency(XPLMGetDatai(g_nav1_standby_ref)*10);


    gnsOpened = true;

    return res;
}
Exemplo n.º 8
0
void sp_update_datarefs() {
    gSpNumberOfBatteries = (XPLMGetDatai(gSpNumberOfBatteriesDataRef));
    gSpNumberOfGenerators = (XPLMGetDatai(gSpNumberOfGeneratorsDataRef));
    gSpNumberOfEngines = (XPLMGetDatai(gSpNumberOfEnginesDataRef));
    gSpBatteryArrayOn = (XPLMGetDatai(gSpBatteryArrayOnDataRef));
    gSpGearRetract = (XPLMGetDatai(gSpGearRetractDataRef));
    gSpOnGround = (XPLMGetDatai(gSpOnGroundDataRef));
    XPLMGetDatavf(gSpLandingGearStatusDataRef, gSpLandingGearStatus, 0, 10);
    gSpGear1Fail = (XPLMGetDatai(gSpGear1FailDataRef));
    gSpGear2Fail = (XPLMGetDatai(gSpGear2FailDataRef));
    gSpGear3Fail = (XPLMGetDatai(gSpGear3FailDataRef));
}
Exemplo n.º 9
0
// ***************** ALT Button and light *******************
void process_alt_button()
{

    if (loaded737 == 1) {
        if (multires > 0) {
            if (testbit(multibuf, ALT_BUTTON)) {
                XPLMCommandOnce(x737mcp_alt_toggle);
                lastappos = 1;
            }
        }

        // Always match x737 glareshield LED
        switch (XPLMGetDatai(x737mcp_alt_led)) {
            case 1:
                btnleds |= (1<<4);
                break;
            case 0:
                btnleds &= ~(1<<4);
                break;
        }
    } else {
        if (multires > 0) {
          if(testbit(multibuf,ALT_BUTTON)) {
           XPLMCommandOnce(ApAltBtn);
           lastappos = 1;
          }
        }
	switch(XPLMGetDatai(ApAltStat)){
	  case 2:
            btnleds |= (1<<4);   // * set bit 4 in btnleds to 1 *
            break;
          case 1:
	    if (flashon == 1) {
              btnleds |= (1<<4);   // * set bit 4 in btnleds to 1 *
	    }else{    
              btnleds &= ~(1<<4);   // * clear bit 4 in btnleds to 0 *
	    }
            break;
          case 0:
            btnleds &= ~(1<<4);   // * clear bit 4 in btnleds to 0 *
            break;
	} 
	
	if (XPLMGetDatai(ApMstrStat) == 0) {
          btnleds &= ~(1<<4);   // * clear bit 4 in btnleds to 0 *
	}
    }
}
Exemplo n.º 10
0
/*
 * MyDrawingWindowCallback
 *
 * This callback does the work of drawing our window once per sim cycle each time
 * it is needed.  It dynamically changes the text depending on the saved mouse
 * status.  Note that we don't have to tell X-Plane to redraw us when our text
 * changes; we are redrawn by the sim continuously.
 *
 */
void MyDrawWindowCallback(
                                   XPLMWindowID         inWindowID,
                                   void *               inRefcon)
{
	int		left, top, right, bottom;
	float	color[] = { 1.0, 1.0, 1.0 }; 	/* RGB White */
    int xpndr_mode;
    float alt_agl, grnd_spd;
    char  buffer[50];

    xpndr_mode  = XPLMGetDatai( ref_xpndr_mode );
    alt_agl     = XPLMGetDataf( ref_alt_agl );
    grnd_spd    = XPLMGetDataf( ref_grnd_spd );

	/* First we get the location of the window passed in to us. */
	XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom);

	/* We now use an XPLMGraphics routine to draw a translucent dark
	 * rectangle that is our window's shape. */
	XPLMDrawTranslucentDarkBox(left, top, right, bottom);

    /* Finally we draw the text into the window, also using XPLMGraphics
	 * routines.  The NULL indicates no word wrapping. */
	sprintf(buffer, "xpndr_mode: %d", xpndr_mode);
    XPLMDrawString(color, left + 5, top - 20, buffer, NULL, xplmFont_Basic);

	sprintf(buffer, "alt_agl: %d", (int)floor(alt_agl));
    XPLMDrawString(color, left + 5, top - 40, buffer, NULL, xplmFont_Basic);

	sprintf(buffer, "grnd_spd: %d", (int)floor(grnd_spd));
    XPLMDrawString(color, left + 5, top - 60, buffer, NULL, xplmFont_Basic);

    XPLMDrawString(color, left + 5, top - 80, debug_string, NULL, xplmFont_Basic);

}
Exemplo n.º 11
0
void IntDataRef::updateValue() {
   int newValue = XPLMGetDatai(_ref);
    if(_value != newValue) {
        _value = newValue;
        emit changed(this);
    }
}
Exemplo n.º 12
0
void initXpndr() {
    int xpndr_mode;

    xpndr_mode  = XPLMGetDatai( ref_xpndr_mode );

    /* Transponder mode (off=0 stdby=1 on=2 test=3) */
    if( !xpndr_mode ) {
        XPLMSetDatai( ref_xpndr_mode, 2 );
        XPLMSetDatai( ref_xpndr_setting, config_default_xpndr_setting );
    }
}
Exemplo n.º 13
0
// ***************** Flaps Switch *******************
void process_flaps_switch()
{
    if (XPLMGetDatai(BatPwrOn) == 1) {

        if (multires > 0) {
	  if(testbit(multibuf,FLAPS_UP_SWITCH)) {
	    XPLMCommandOnce(FlapsUp);	 
          }
	  if(testbit(multibuf,FLAPS_DN_SWITCH)) {
	    XPLMCommandOnce(FlapsDn);	 
	  }
        }
   }
}
Exemplo n.º 14
0
// This routine draws the actual planes.
int	XPMPRenderMultiplayerPlanes(
                                   XPLMDrawingPhase     inPhase,    
                                   int                  inIsBefore,    
                                   void *               inRefcon)
{
	static int is_blend = 0;
	
	static XPLMDataRef wrt = XPLMFindDataRef("sim/graphics/view/world_render_type");
	static XPLMDataRef prt = XPLMFindDataRef("sim/graphics/view/plane_render_type");
	
	int is_shadow = wrt != NULL && XPLMGetDatai(wrt) != 0;
	
	if(prt) 
		is_blend = XPLMGetDatai(prt) == 2;

	if (gRenderer)
		gRenderer(is_shadow ? 0 : is_blend,gRendererRef);
	else
		XPMPDefaultPlaneRenderer(is_shadow ? 0 : is_blend);
	if(!is_shadow)
	is_blend = 1 - is_blend;	
	return 1;
}
Exemplo n.º 15
0
void DataRefInt::update(std::string command) {

	if (ptr == NULL) return;

	int val = XPLMGetDatai(ptr);
	if (val!=last) {
		changed = true;
		last=val;
	}

	if (!command.empty()) {
		if (strncmp(command.c_str(),ser_code.c_str(),ser_code.size()) == 0) {
			std::istringstream is(command.c_str()+ser_code.size());
			is >> val;
			if (val!=last) {
				XPLMSetDatai(ptr,val);
				changed = false;
				last=val;
			}
		}
	}
Exemplo n.º 16
0
bool XPlaneInterface::isMainGearCompressed() {
	int onGround = XPLMGetDatai(findDataRefByCode(ONGROUND_ANY));
	return onGround == 1;
}
Exemplo n.º 17
0
void GetGPSData(void)
{
	union longbbbb Temp4;
	union intbb Temp2;
	
	int LocalDays = XPLMGetDatai(drLocalDays);
	float LocalSecsFloat = XPLMGetDataf(drLocalSecs) * 1000;
	
	LocalDays += 5;
	int Week = (int)(LocalDays / 7) + 1564;
	LocalDays = (LocalDays % 7);
	Week = (Week * 10) + LocalDays;
	int LocalSecsInt = (int)LocalSecsFloat + (LocalDays * 86400000);
	LocalSecsFloat = (LocalSecsFloat - (int)LocalSecsFloat) * 1000000;
	
	Temp2.BB = Week;
	Store2LE(&NAV_SOL[14], Temp2);

	Temp4.WW = LocalSecsInt;
	Store4LE(&NAV_SOL[6], Temp4);
	Store4LE(&NAV_DOP[6], Temp4);
	Store4LE(&NAV_POSLLH[6], Temp4);
	Store4LE(&NAV_VELNED[6], Temp4);

	Temp4.WW = (int)LocalSecsFloat;
	Store4LE(&NAV_SOL[10], Temp4);

	double latitude = XPLMGetDataf(drLat);
	double longitude = XPLMGetDataf(drLon);
	double elevation = XPLMGetDataf(drElev);
	double local_x = XPLMGetDataf(drLocal_x);
	double local_y = XPLMGetDataf(drLocal_y);
	double local_z = XPLMGetDataf(drLocal_z);
	double local_vx = XPLMGetDataf(drLocal_vx);
	double local_vy = XPLMGetDataf(drLocal_vy);
	double local_vz = XPLMGetDataf(drLocal_vz);

	Temp4.WW = (int)(local_vx * 100);
	Store4LE(&NAV_VELNED[14], Temp4);
	
	Temp4.WW = (int)(local_vy * -100);
	Store4LE(&NAV_VELNED[18], Temp4);
	
	Temp4.WW = (int)(local_vz * -100);
	Store4LE(&NAV_VELNED[10], Temp4);

	Temp4.WW = (int)(XPLMGetDataf(drAirSpeedTrue) * 100);
	Store4LE(&NAV_VELNED[22], Temp4);

	Temp4.WW = (int)(XPLMGetDataf(drGroundSpeed) * 100);
	Store4LE(&NAV_VELNED[26], Temp4);

	Temp4.WW = (int)(XPLMGetDataf(drHeading) * 100000);
	Store4LE(&NAV_VELNED[30], Temp4);

	Temp4.WW = (int)(latitude * 10000000);
	Store4LE(&NAV_POSLLH[14], Temp4);

	Temp4.WW = (int)(longitude * 10000000);
	Store4LE(&NAV_POSLLH[10], Temp4);
	
	Temp4.WW = (int)(elevation * 1000);
	Store4LE(&NAV_POSLLH[18], Temp4);
	Store4LE(&NAV_POSLLH[22], Temp4);
	
	double ac_pos_lat, ac_pos_lon, ac_pos_elev;
	double ac_vel_lat, ac_vel_lon, ac_vel_elev;
	
	// Get AC pos in LLA
	XPLMLocalToWorld(	local_x, 
						local_y, 
						local_z, 
						&ac_pos_lat, 
						&ac_pos_lon, 
						&ac_pos_elev	);
	
	// Get AC pos + velocity vector in LLA
	XPLMLocalToWorld(	local_x + local_vx, 
						local_y + local_vy, 
						local_z + local_vz,
						&ac_vel_lat,
						&ac_vel_lon,
						&ac_vel_elev	);
	
	// convert to ECEF
	LLAtoECEF(ac_pos_lat, ac_pos_lon, ac_pos_elev, local_x, local_y, local_z);
	LLAtoECEF(ac_vel_lat, ac_vel_lon, ac_vel_elev, local_vx, local_vy, local_vz);
	
	// AC pos stays as is
	// subtract to get velocity vector in ECEF
	local_vy -= local_y;
	local_vx -= local_x;
	local_vz -= local_z;

	Temp4.WW = (int)(local_x * 100);
	Store4LE(&NAV_SOL[18], Temp4);
	
	Temp4.WW = (int)(local_y * 100);
	Store4LE(&NAV_SOL[22], Temp4);
	
	Temp4.WW = (int)(local_z * 100);
	Store4LE(&NAV_SOL[26], Temp4);

	Temp4.WW = (int)(local_vx * 100);
	Store4LE(&NAV_SOL[34], Temp4);
	
	Temp4.WW = (int)(local_vy * 100);
	Store4LE(&NAV_SOL[38], Temp4);
	
	Temp4.WW = (int)(local_vz * 100);
	Store4LE(&NAV_SOL[42], Temp4);
	
	CalculateChecksum(NAV_SOL);
	SendToComPort(sizeof(NAV_SOL),NAV_SOL);
	CalculateChecksum(NAV_DOP);
	SendToComPort(sizeof(NAV_DOP),NAV_DOP);
	CalculateChecksum(NAV_POSLLH);
	SendToComPort(sizeof(NAV_POSLLH),NAV_POSLLH);
	CalculateChecksum(NAV_VELNED);
	SendToComPort(sizeof(NAV_VELNED),NAV_VELNED);
}
Exemplo n.º 18
0
// ***************** APR Button and light *******************
void process_apr_button()
{

    if (loaded737 == 1) {
        if (multires > 0) {
            if (testbit(multibuf, APR_BUTTON)) {
                XPLMCommandOnce(x737mcp_app_toggle);
                lastappos = 1;
            }
        }

        // Always match x737 glareshield LED
        switch (XPLMGetDatai(x737mcp_app_led)) {
            case 1:
                btnleds |= (1<<6);
                break;
            case 0:
                btnleds &= ~(1<<6);
                break;
        }

    } else if (aprbuttonremap == 1){
        if (multires > 0) {
          if(testbit(multibuf,APR_BUTTON)) {
             XPLMCommandOnce(AprButtonRemapableCmd);
             lastappos = 1;
          }
        }
        switch(XPLMGetDatai(ApAprStat)){
          case 2:
            btnleds |= (1<<6);   // * set bit 6 in btnleds to 1 *
            break;
          case 1:
            if (flashon == 1) {
              btnleds |= (1<<6);   // * set bit 6 in btnleds to 1 *
            }else{
              btnleds &= ~(1<<6);   // * clear bit 6 in btnleds to 0 *
            }
            break;
          case 0:
            btnleds &= ~(1<<6);   // * clear bit 6 in btnleds to 0 *
            break;
        }

    } else {
        if (multires > 0) {
          if(testbit(multibuf,APR_BUTTON)) {
            if(xpanelsfnbutton == 1) {
                rhdgf = XPLMGetDataf(MHdg);
                XPLMSetDataf(ApCrs, rhdgf);
            }
            if(xpanelsfnbutton == 0) {
                XPLMCommandOnce(ApAprBtn);
                lastappos = 1;
            }
          }
        }
	switch(XPLMGetDatai(ApAprStat)){
	  case 2:
            btnleds |= (1<<6);   // * set bit 6 in btnleds to 1 *
            break;
          case 1:
	    if (flashon == 1) {
              btnleds |= (1<<6);   // * set bit 6 in btnleds to 1 *
	    }else{   
              btnleds &= ~(1<<6);   // * clear bit 6 in btnleds to 0 *
	    }
            break;
          case 0:
            btnleds &= ~(1<<6);   // * clear bit 6 in btnleds to 0 *
            break;
        }
    }
}
Exemplo n.º 19
0
int htmlMiscStateXML( char *header, char *html, char *queryString ){



	//prepare GPS nav data.
	
	XPLMNavRef navRef = XPLMGetGPSDestination();
	XPLMNavType navType;// = XPLMGetGPSDestinationType();

	float gpsLat, gpsLon, gpsAlt;
	int gpsFreq;
	float gpsHeading;
	char gpsID[32];
	char gpsName[256];
	char gpsReg[256];

	XPLMGetNavAidInfo(	
						navRef,
						&navType,
						&gpsLat,
						&gpsLon,
						&gpsAlt,
						&gpsFreq,
						&gpsHeading,
						gpsID,
						gpsName,
						gpsReg
						);





	//this function fires as the root(/) url, it relies on /index.xsl for formatting.

		header200OK_XML( header );

		sprintf(html,
						"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
						//"<?xml-stylesheet type=\"text/xsl\" href=\"full-state.xsl\"?>\n"
						"<x-plane_full>\n"
						
							"<query-string value=\"%s\" />"
							
							"<aircraft>\n"

								"<position>\n"
									"<world lat=\"%2.5f\" lon=\"%3.5f\" alt_msl=\"%2.3f\" alt_agl=\"%2.3f\" />\n"
									"<opengl x=\"%2.5f\" y=\"%3.5f\" z=\"%2.3f\"/>\n"
									"<heading true=\"%2.3f\" mag=\"%2.3f\" track=\"%2.3f\" />\n"
									"<speed tas=\"%2.3f\" ias=\"%2.3f\" gs=\"%2.3f\" />\n"									
								"</position>\n"
								"<weather>\n"
									"<wind speed=\"%2.3f\" direction=\"%2.3f\" />\n"
								"</weather>\n"
								"<radios>\n"
									"<nav one=\"%i\" two=\"%i\" />\n"
									"<com one=\"%i\" two=\"%i\" />\n"
								"</radios>\n"
								//"<gps lat=\"%2.5f\" lon=\"%2.5f\" alt=\"%2.5f\" freq=\"%i\" hdg=\"%2.5f\" id=\"%s\" name=\"%s\" reg=\"%s\" />"
								"<gps lat=\"%2.5f\" lon=\"%2.5f\" alt=\"%2.5f\" id=\"%s\" name=\"%s\" />"
							
								"<cockpit>\n"
									"<buttons/>\n"
								"</cockpit>\n"
								
								"<failures/>\n"
								
							"</aircraft>\n"
							"<weather>\n"
								"<wind>\n"
									"<high "
										"alt=\"%1.3f\" "
										"speed=\"%1.3f\" "
										"dir=\"%1.3f\" "
										"sheer-speed=\"%1.3f\" "
										"sheer-direction=\"%1.3f\" "
										"turbulence=\"%1.3f\" />\n"
									"<med "
										"alt=\"%1.3f\" "
										"speed=\"%1.3f\" "
										"dir=\"%1.3f\" "
										"sheer-speed=\"%1.3f\" "
										"sheer-direction=\"%1.3f\" "
										"turbulence=\"%1.3f\" />\n"
									"<low "
										"alt=\"%1.3f\" "
										"speed=\"%1.3f\" "
										"dir=\"%1.3f\" "
										"sheer-speed=\"%1.3f\" "
										"sheer-direction=\"%1.3f\" "
										"turbulence=\"%1.3f\" />\n"
								"</wind>\n"
								"<clouds>\n"
									"\n"
								"</clouds>\n"
								"<misc>\n"
									"\n"
								"</misc>\n"
								"<sea_level_temp c=\"\" />\n"
								"<sea_level_pressure value=\"\" />\n"
							"</weather>\n"
						
						"</x-plane_full>\n"
						,
						queryString,
						//aircraft position and gps/radio state data
						XPLMGetDataf( xpdr_Lat ), XPLMGetDataf( xpdr_Lon ), XPLMGetDataf( xpdr_AltMSL ), XPLMGetDataf( xpdr_AltAGL ),	//world
						XPLMGetDataf( xpdr_X ), XPLMGetDataf( xpdr_Y ), XPLMGetDataf( xpdr_Z ),	//local
						XPLMGetDataf( xpdr_Heading ), XPLMGetDataf( xpdr_HeadingMag ), XPLMGetDataf( xpdr_HeadingTrack ),
						XPLMGetDataf( xpdr_Kias ), XPLMGetDataf( xpdr_Ktas ), XPLMGetDataf( xpdr_Kgs ),
						
						XPLMGetDataf( xpdr_WindSpeed ), XPLMGetDataf( xpdr_WindDirection ),
						
						XPLMGetDatai( xpdr_Nav1 ), XPLMGetDatai( xpdr_Nav1s ),
						XPLMGetDatai( xpdr_Com1 ), XPLMGetDatai( xpdr_Com1s ),
						
						//gpsLat, gpsLon, gpsAlt, gpsFreq, gpsHeading, gpsID, gpsName, gpsReg
						gpsLat, gpsLon, gpsAlt, gpsID, gpsName,

						
						
						//weather wind data
						XPLMGetDataf( xpdr_windAltHigh ), XPLMGetDataf( xpdr_windSpeedHigh ), XPLMGetDataf( xpdr_windDirHigh ), XPLMGetDataf( xpdr_windSheerSpeedHigh ), XPLMGetDataf( xpdr_windSheerDirectionHigh ), XPLMGetDataf( xpdr_windTurbulenceHigh ), 
						XPLMGetDataf( xpdr_windAltMed ), XPLMGetDataf( xpdr_windSpeedMed ), XPLMGetDataf( xpdr_windDirMed ), XPLMGetDataf( xpdr_windSheerSpeedMed ), XPLMGetDataf( xpdr_windSheerDirectionMed ), XPLMGetDataf( xpdr_windTurbulenceMed ), 
						XPLMGetDataf( xpdr_windAltLow ), XPLMGetDataf( xpdr_windSpeedLow ), XPLMGetDataf( xpdr_windDirLow ), XPLMGetDataf( xpdr_windSheerSpeedLow ), XPLMGetDataf( xpdr_windSheerDirectionLow ), XPLMGetDataf( xpdr_windTurbulenceLow )

						
						);
						
						
	return strlen( html );

}
Exemplo n.º 20
0
int htmlStateXML( char *header, char *html ){

	//prepare GPS nav data.
	
	XPLMNavRef navRef = XPLMGetGPSDestination();
	XPLMNavType navType;// = XPLMGetGPSDestinationType();

	float gpsLat, gpsLon, gpsAlt;
	int gpsFreq;
	float gpsHeading;
	char gpsID[32];
	char gpsName[256];
	char gpsReg[256];

	XPLMGetNavAidInfo(	
						navRef,
						&navType,
						&gpsLat,
						&gpsLon,
						&gpsAlt,
						&gpsFreq,
						&gpsHeading,
						gpsID,
						gpsName,
						gpsReg
						);





		header200OK_XML( header );

		sprintf(html,
						"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
						//"<?xml-stylesheet type=\"text/xsl\" href=\"state.xsl\"?>\n"
						"<x-plane>\n"
							"<aircraft>\n"
								"<position>\n"
									"<world lat=\"%2.5f\" lon=\"%3.5f\" alt_msl=\"%2.3f\" alt_agl=\"%2.3f\" />\n"
									"<opengl x=\"%2.5f\" y=\"%3.5f\" z=\"%2.3f\"/>\n"
									"<heading true=\"%2.3f\" mag=\"%2.3f\" track=\"%2.3f\" />\n"
									"<speed tas=\"%2.3f\" ias=\"%2.3f\" gs=\"%2.3f\" />\n"									
								"</position>\n"
								"<weather>\n"
									"<wind speed=\"%2.3f\" direction=\"%2.3f\" />\n"
								"</weather>\n"
								"<radios>\n"
									"<nav one=\"%i\" two=\"%i\" />\n"
									"<com one=\"%i\" two=\"%i\" />\n"
								"</radios>\n"
								//"<gps lat=\"%2.5f\" lon=\"%2.5f\" alt=\"%2.5f\" freq=\"%i\" hdg=\"%2.5f\" id=\"%s\" name=\"%s\" reg=\"%s\" />"
								"<gps lat=\"%2.5f\" lon=\"%2.5f\" alt=\"%2.5f\" id=\"%s\" name=\"%s\" />"
							"</aircraft>\n"
							"<traffic>\n"
								
							"</traffic>\n"
						"</x-plane>\n",
						XPLMGetDataf( xpdr_Lat ), XPLMGetDataf( xpdr_Lon ), XPLMGetDataf( xpdr_AltMSL ), XPLMGetDataf( xpdr_AltAGL ),	//world
						XPLMGetDataf( xpdr_X ), XPLMGetDataf( xpdr_Y ), XPLMGetDataf( xpdr_Z ),	//local
						XPLMGetDataf( xpdr_Heading ), XPLMGetDataf( xpdr_HeadingMag ), XPLMGetDataf( xpdr_HeadingTrack ),
						XPLMGetDataf( xpdr_Kias ), XPLMGetDataf( xpdr_Ktas ), XPLMGetDataf( xpdr_Kgs ),
						
						XPLMGetDataf( xpdr_WindSpeed ), XPLMGetDataf( xpdr_WindDirection ),
						
						XPLMGetDatai( xpdr_Nav1 ), XPLMGetDatai( xpdr_Nav1s ),
						XPLMGetDatai( xpdr_Com1 ), XPLMGetDatai( xpdr_Com1s ),
						
						//gpsLat, gpsLon, gpsAlt, gpsFreq, gpsHeading, gpsID, gpsName, gpsReg
						gpsLat, gpsLon, gpsAlt, gpsID, gpsName
						
						);
						
						
	return strlen( html );

}
Exemplo n.º 21
0
void GetGPSData(void)
{
	union longbbbb Temp4;
	union intbb Temp2;
	float phi, theta, psi;

	phi =   (float)((XPLMGetDataf(drPhi)   / 180) * PI);
	theta = (float)((XPLMGetDataf(drTheta) / 180) * PI);
	psi =   (float)((XPLMGetDataf(drPsi)   / 180) * PI);

	int LocalDays = XPLMGetDatai(drLocalDays);
	float LocalSecsFloat = XPLMGetDataf(drLocalSecs) * 1000;

	LocalDays += 5;
	int Week = (int)(LocalDays / 7) + 1564;
	LocalDays = (LocalDays % 7);
	Week = (Week * 10) + LocalDays;
	int LocalSecsInt = (int)LocalSecsFloat + (LocalDays * 86400000);
	LocalSecsFloat = (LocalSecsFloat - (int)LocalSecsFloat) * 1000000;

	Temp2.BB = Week;
	Store2LE(&NAV_SOL[14], Temp2);
	Temp4.WW = LocalSecsInt;
	Store4LE(&NAV_SOL[6], Temp4);
	Store4LE(&NAV_DOP[6], Temp4);
	Store4LE(&NAV_POSLLH[6], Temp4);
	Store4LE(&NAV_VELNED[6], Temp4);
	Temp4.WW = (int)LocalSecsFloat;
	Store4LE(&NAV_SOL[10], Temp4);

	double latitude  = XPLMGetDataf(drLat);
	double longitude = XPLMGetDataf(drLon);
	double elevation = XPLMGetDataf(drElev);
	double local_x   = XPLMGetDataf(drLocal_x);
	double local_y   = XPLMGetDataf(drLocal_y);
	double local_z   = XPLMGetDataf(drLocal_z);
	double local_vx  = XPLMGetDataf(drLocal_vx);
	double local_vy  = XPLMGetDataf(drLocal_vy);
	double local_vz  = XPLMGetDataf(drLocal_vz);

	Temp4.WW = (int)(local_vx * 100);
	Store4LE(&NAV_VELNED[14], Temp4);
	Temp4.WW = (int)(local_vy * -100);
	Store4LE(&NAV_VELNED[18], Temp4);
	Temp4.WW = (int)(local_vz * -100);
	Store4LE(&NAV_VELNED[10], Temp4);
	Temp4.WW = (int)(XPLMGetDataf(drAirSpeedTrue) * 100);
	Store4LE(&NAV_VELNED[22], Temp4);

	// note: xplane ground speed is not GPS speed over ground,
	// it is 3D ground speed. we need horizontal ground speed for GPS,
	// which is computed from the horizontal local velocity components:
	double speed_over_ground = 100 * sqrt(local_vx*local_vx + local_vz*local_vz);
	Temp4.WW = (int)speed_over_ground;
	Store4LE(&NAV_VELNED[26], Temp4);

	// Compute course over ground, in degrees,
	// from horizontal earth frame velocities,
	// which are in OGL frame of reference.
	// local_vx is east, local_vz is south.
	double course_over_ground = (atan2(local_vx, -local_vz) / PI * 180.0);
	// MatrixPilot is expecting an angle between 0 and 360 degrees.
	if (course_over_ground < 0.0) course_over_ground += 360.0;

	Temp4.WW = (int)(100000.0 * course_over_ground);
	Store4LE(&NAV_VELNED[30], Temp4);
	Temp4.WW = (int)(latitude * 10000000);
	Store4LE(&NAV_POSLLH[14], Temp4);
	Temp4.WW = (int)(longitude * 10000000);
	Store4LE(&NAV_POSLLH[10], Temp4);
	Temp4.WW = (int)(elevation * 1000);
	Store4LE(&NAV_POSLLH[18], Temp4);
	Store4LE(&NAV_POSLLH[22], Temp4);

	double ac_pos_lat, ac_pos_lon, ac_pos_elev;
	double ac_vel_lat, ac_vel_lon, ac_vel_elev;

	// Get AC pos in LLA
	XPLMLocalToWorld(local_x,
	                 local_y,
	                 local_z,
	                 &ac_pos_lat,
	                 &ac_pos_lon,
	                 &ac_pos_elev);

	// Get AC pos + velocity vector in LLA
	XPLMLocalToWorld(local_x + local_vx,
	                 local_y + local_vy,
	                 local_z + local_vz,
	                 &ac_vel_lat,
	                 &ac_vel_lon,
	                 &ac_vel_elev);

	// convert to ECEF
	LLAtoECEF(ac_pos_lat, ac_pos_lon, ac_pos_elev, local_x, local_y, local_z);
	LLAtoECEF(ac_vel_lat, ac_vel_lon, ac_vel_elev, local_vx, local_vy, local_vz);

	// AC pos stays as is
	// subtract to get velocity vector in ECEF
	local_vy -= local_y;
	local_vx -= local_x;
	local_vz -= local_z;

	Temp4.WW = (int)(local_x * 100);
	Store4LE(&NAV_SOL[18], Temp4);
	Temp4.WW = (int)(local_y * 100);
	Store4LE(&NAV_SOL[22], Temp4);
	Temp4.WW = (int)(local_z * 100);
	Store4LE(&NAV_SOL[26], Temp4);
	Temp4.WW = (int)(local_vx * 100);
	Store4LE(&NAV_SOL[34], Temp4);
	Temp4.WW = (int)(local_vy * 100);
	Store4LE(&NAV_SOL[38], Temp4);
	Temp4.WW = (int)(local_vz * 100);
	Store4LE(&NAV_SOL[42], Temp4);

	// simulate the magnetometer, and place in slots 30,32 and 46 of NAV_SOL
	// these slots are used by Ublox, but not by HILSIM
	// computation is based on zero declination, and zero inclination
	float mag_field_x = 0.0;            // earth OGL x mag field (east)
	float mag_field_y = 0.0;            // earth OGL y mag field (up)
	float mag_field_z = -MAG_FIELD;     // earth OGL z mag field (south)
	// note, the "north pole" of the earth is really a south magnetic pole

	// convert to NED body frame
	OGLtoBCBF(mag_field_x, mag_field_y, mag_field_z, phi, theta, psi);

	// convert from NED body to UDB body frame
	double mag_field_body_udb_x = -mag_field_y;
	double mag_field_body_udb_y =  mag_field_x;
	double mag_field_body_udb_z =  mag_field_z;

	// store in unused slots in NAV_SOL message
	Temp2.BB = (int)mag_field_body_udb_x;
	Store2LE(&NAV_SOL[30], Temp2);
	Temp2.BB = (int)mag_field_body_udb_y;
	Store2LE(&NAV_SOL[32], Temp2);
	Temp2.BB = (int)mag_field_body_udb_z;
	Store2LE(&NAV_SOL[46], Temp2);

	CalculateChecksum(NAV_SOL);
	SendToComPort(sizeof(NAV_SOL), NAV_SOL);
	CalculateChecksum(NAV_DOP);
	SendToComPort(sizeof(NAV_DOP), NAV_DOP);
	CalculateChecksum(NAV_POSLLH);
	SendToComPort(sizeof(NAV_POSLLH), NAV_POSLLH);
	CalculateChecksum(NAV_VELNED);
	SendToComPort(sizeof(NAV_VELNED), NAV_VELNED);
}
Exemplo n.º 22
0
// ***************** NAV Button and light *******************
void process_nav_button()
{

    if (loaded737 == 1) {
        if (multires > 0) {
            if (testbit(multibuf, NAV_BUTTON)) {
                switch (XPLMGetDatai(HsiSelector)) {
                    case 0:
                    case 1:
                        XPLMCommandOnce(x737mcp_vorloc_toggle);
                        break;
                    case 2:
                        XPLMCommandOnce(x737mcp_lnav_toggle);
                        break;
                }
                lastappos = 1;
            }
        }

        switch (XPLMGetDatai(HsiSelector)) {
            case 0:
            case 1:
                // Use LED to match power state
                switch (XPLMGetDatai(x737mcp_vorloc_led)) {
                    case 1:
                        btnleds |= (1<<2);
                        break;
                    case 0:
                        // Although x737 LED has no armed status, the PFD does
                        if (XPLMGetDatai(x737mcp_vorloc_armed)) {
                            if (flashon == 1) {
                                btnleds |= (1<<2);
                            } else {
                                btnleds &= ~(1<<2);
                            }
                        } else {
                            btnleds &= ~(1<<2);
                        }
                        break;
                }
                break;
            case 2:
                switch (XPLMGetDatai(x737mcp_lnav)) {
                    case 1:
                        btnleds |= (1<<2);
                        break;
                    case 0:
                        if (XPLMGetDatai(x737mcp_lnav_armed)) {
                            if (flashon == 1) {
                                btnleds |= (1<<2);
                            } else {
                                btnleds &= ~(1<<2);
                            }
                        } else {
                            btnleds &= ~(1<<2);
                        }
                        break;
                }
                break;
        }

    } else if (navbuttonremap == 1){
        if (multires > 0) {
          if(testbit(multibuf,NAV_BUTTON)) {
             XPLMCommandOnce(NavButtonRemapableCmd);
             lastappos = 1;
          }
        }

        switch(XPLMGetDatai(ApNavStat)){
          case 2:
            btnleds |= (1<<2);   // * set bit 2 in btnleds to 1 *
            break;
          case 1:
            if (flashon == 1) {
              btnleds |= (1<<2);   // * set bit 1 in btnleds to 1 *
            }else{
              btnleds &= ~(1<<2);   // * clear bit 2 in btnleds to 0 *
            }
            break;
          case 0:
            btnleds &= ~(1<<2);   // * clear bit 2 in btnleds to 0 *
            break;
        }


    } else {
        if (multires > 0) {
          if(testbit(multibuf,NAV_BUTTON)) {
            if(xpanelsfnbutton == 1) {
                xpanelscrstoggle = !xpanelscrstoggle;
            }
            if(xpanelsfnbutton == 0) {
                XPLMCommandOnce(ApNavBtn);
                lastappos = 1;
            }

          }
        }

	switch(XPLMGetDatai(ApNavStat)){
	  case 2:
            btnleds |= (1<<2);   // * set bit 2 in btnleds to 1 *
            break;
          case 1:
	    if (flashon == 1) {
              btnleds |= (1<<2);   // * set bit 1 in btnleds to 1 *
	    }else{
              btnleds &= ~(1<<2);   // * clear bit 2 in btnleds to 0 *
	    }
	    break;
	  case 0:
            btnleds &= ~(1<<2);   // * clear bit 2 in btnleds to 0 *
	    break;
	}
   }




}
Exemplo n.º 23
0
// ***************** AP Master Button and light *******************
void process_ap_master_switch()
{

    if (loaded737 == 1) {
        if (appushed == 0) {
            if (testbit(multibuf, AP_MASTER_BUTTON)) {
                XPLMCommandOnce(x737mcp_cmd_a_toggle);
                appushed = 1;
                lastappos = 1;
            }
        }

        if (appushed == 1){
           aploop++;
            if (aploop == 50){
               appushed = 0;
               aploop = 0;
            }

        }

        switch (XPLMGetDatai(x737mcp_cmd_a_led)) {
            case 0:
                btnleds &= ~(1<<0);
                break;
            case 1:
                btnleds |= (1<<0);
                break;
        }
    } else {
        if (appushed == 0) {
          switch(XPLMGetDatai(ApMstrStat)){
            case 0:
             if(testbit(multibuf, AP_MASTER_BUTTON)) {
                XPLMSetDatai(ApMstrStat, 1);
                appushed = 1;
                lastappos = 1;
              }
              break;
            case 1:
             if(testbit(multibuf, AP_MASTER_BUTTON)) {
                 if (lastappos == 1){
                   XPLMSetDatai(ApMstrStat, 2);
                   appushed = 1;
                 }
                 if (lastappos == 2){
                     XPLMSetDatai(ApMstrStat, 0);
                     appushed = 1;
                 }
              }
              break;
            case 2:
              if(testbit(multibuf, AP_MASTER_BUTTON)) {
                 XPLMSetDatai(ApMstrStat, 1);
                 appushed = 1;
                 lastappos = 2;
              }
              break;
          }
        }

        if (appushed == 1){
           aploop++;
            if (aploop == 50){
               appushed = 0;
               aploop = 0;
            }

        }
        
        switch(XPLMGetDatai(ApMstrStat)){
          case 0:
            btnleds &= ~(1<<0);   // * clear bit 0 in btnleds to 0 *
            break;
          case 1:
	    if (flashon == 1) {
              btnleds |= (1<<0);   // * set bit 0 in btnleds to 1 *
	    }else{   
              btnleds &= ~(1<<0);   // * clear bit 0 in btnleds to 0 *
	    }
            break;
          case 2:
            btnleds |= (1<<0);   // * set bit 0 in btnleds to 1 *
            break;
        }
    }
}
Exemplo n.º 24
0
// ***************** IAS Switch Position *******************
void process_ias_switch()
{
   if (testbit(multibuf,IAS_SWITCH)) {
      multiseldis = 2;
      upapasf = XPLMGetDataf(ApAs);
      upapas = (int)(upapasf);
      if (testbit(multibuf,ADJUSTMENT_UP)) {
         iasdbncinc++;
         if (iasdbncinc > multispeed) {
            n = multimul;
            if (xpanelsfnbutton == 1) {
               if (loaded737 == 1) {
                  XPLMCommandOnce(x737mcp_spd_up_fast);
               } else {
                  while (n>0) {
                     if (XPLMGetDatai(AirspeedIsMach) == 1) {
                        XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) + 0.01);
                     } else {
                        //XPLMCommandOnce(ApAsUp);
                        upapas = upapas + 1;
                     }
                     --n;
                  }
               }
               iasdbncinc = 0;
            }
            if (xpanelsfnbutton == 0) {
               if (loaded737 == 1) {
                  XPLMCommandOnce(x737mcp_spd_up);
               } else {
                  if (XPLMGetDatai(AirspeedIsMach) == 1) {
                     XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) + 0.01);
                  } else {
                     //XPLMCommandOnce(ApAsUp);
                     upapas = upapas + 1;
                  }
               }
               iasdbncinc = 0;
            }
         }
      }
      if (testbit(multibuf,ADJUSTMENT_DN)) {
         iasdbncdec++;
         if (iasdbncdec > multispeed) {
            n = multimul;
            if (xpanelsfnbutton == 1) {
               if (loaded737 == 1) {
                  XPLMCommandOnce(x737mcp_spd_down_fast);
               } else {
                  while (n>0) {
                     if (XPLMGetDatai(AirspeedIsMach) == 1) {
                        XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) - 0.01);
                     } else {
                        //XPLMCommandOnce(ApAsDn);
                        upapas = upapas - 1;
                     }
                     --n;
                  }
               }
               iasdbncdec = 0;
            }
            if (xpanelsfnbutton == 0) {
               if (loaded737 == 1) {
                  XPLMCommandOnce(x737mcp_spd_down);
               } else {
                  if (XPLMGetDatai(AirspeedIsMach) == 1) {
                     XPLMSetDataf(Airspeed, XPLMGetDataf(Airspeed) - 0.01);
                  } else {
                     //XPLMCommandOnce(ApAsDn);
                     upapas = upapas - 1;
                  }
               }
               iasdbncdec = 0;
            }
         }
      }
      upapasf = upapas;
      XPLMSetDataf(ApAs, upapasf);
      upapasf = XPLMGetDataf(ApAs);
      if (XPLMGetDatai(AirspeedIsMach) == 1) {
         upapasf = (upapasf * 100);
      }
      upapas = (int)(upapasf);
   }
}
Exemplo n.º 25
0
float sendRequestedDataCallback(
                                   float	inElapsedSinceLastCall,
                                   float	inElapsedTimeSinceLastFlightLoop,
                                   int		inCounter,
                                   void *	inRefcon) {

	int i;
	int res;
#if IBM
	char msg[80];
#endif
	struct RequestRecord rr;

	if( DEBUG ) {
		XPLMDebugString("XData: sendRequestedDataCallback called.\n");
	}

	if (xdata_plugin_enabled && xdata_send_enabled && xdata_socket_open) {
	
		if( acf_packet_requested == 1 ) {			
			acf_packet_requested = 0;
			sendAircraftPacket();
		}
	
		// Tried a number of things, but absolute current time in millis just overflows and isn't printable via sprintf, it seems, as a long long.
		// So: initializing a start time, then evaluating time since that, which fits into an int.
		if( t_start.time == 0 ) {
			ftime(&t_start);
			XPLMDebugString("Initialising t_start.\n");
		}


		struct timeb t_current;
		ftime(&t_current);
		int t_diff = (int) (1000.0 * (t_current.time - t_start.time) + (t_current.millitm - t_start.millitm));
		
		// clear the buffer
		memset(response_data, 0, response_max_size);
		
//		sprintf(msg, "Time check: milliseconds since start = %d\n", t_diff);
//		XPLMDebugString(msg);
				
		strncpy(response_data, "REQD", 4);		// first 4 bytes indicate packet type
		response_index = 8;
		number_of_points = 0;
		
		// work out which requests to send
		for( i=0; i<=max_requested_index; i++ ) {
			rr = request_records[i];
			if( rr.enabled && request_records[i].dataref != NULL ) {
				//sprintf(msg, "%d - Checking %s which is scheduled for %d\n", t_diff, rr.dataref_name, rr.time_next_send);
				//XPLMDebugString(msg);
				if( rr.time_next_send == 0 || t_diff > rr.time_next_send ) {
					
					// let's work out the size of the data
					int size = 0;
					
					int nbrArrayValues = 0;
					
					int intValue = 0;
					float floatValue = 0.0f;
					double doubleValue = 0.0;
					int intArrayValues[20];
					float floatArrayValues[20];
					char data[900];
					
					if( request_records[i].datatype == xplmType_Int ) {
						intValue = XPLMGetDatai(request_records[i].dataref);
						size = 4;
					} else
					if( request_records[i].datatype == xplmType_Float ) {
						floatValue = XPLMGetDataf(request_records[i].dataref);
						size = 4;
					} else
					if( request_records[i].datatype == xplmType_Double || request_records[i].datatype == 6 ) {  // hack based on observed values
						doubleValue = XPLMGetDatad(request_records[i].dataref);
						size = 8;
					} else			
					if( request_records[i].datatype == xplmType_FloatArray ) {
						nbrArrayValues = XPLMGetDatavf(request_records[i].dataref, floatArrayValues, 0, 20);
						size = (4 * nbrArrayValues);
					} else
					if( request_records[i].datatype == xplmType_IntArray ) {
						nbrArrayValues = XPLMGetDatavi(request_records[i].dataref, intArrayValues, 0, 20);
						size = (4 * nbrArrayValues);
					} else
					if( request_records[i].datatype == xplmType_Data ) {
						nbrArrayValues = XPLMGetDatab(request_records[i].dataref, data, 0, 900);
						size = nbrArrayValues;
					}
				
					
					// will it fit in the buffer
					int index_after_add = response_index + 4 + 4 + 4 + size;
					if( index_after_add >= response_max_size ) {
						// if not, send it
						// first update response with number of points
						int convertedNum = custom_htonl(number_of_points);
						memcpy(response_data+4, &convertedNum, 4);
						
						if( DEBUG ) {
							sprintf(msg, "Packet ready to go: number_of_points=%d response_index=%d\n", number_of_points, response_index);
							XPLMDebugString(msg);
							XPLMDebugString("Packet data: ");
							int p=0;
							for( p=0; p<response_index; p++ ) {
								sprintf(msg, "%d:%d ", p, (int)response_data[p]);
								XPLMDebugString(msg);
							}
							XPLMDebugString("\n");
						}
						
						// ready to go	
						for (i=0; i<NUM_DEST; i++) {
							if (dest_enable[i]) {
								res = sendto(sockfd, response_data, response_index, 0, (struct sockaddr *)&dest_sockaddr[i], sizeof(struct sockaddr));
				#if IBM
								if ( res == SOCKET_ERROR ) {
									XPLMDebugString("XData: caught error while sending REQD packet! (");
									sprintf(msg, "%d", WSAGetLastError());
									XPLMDebugString(msg);
									XPLMDebugString(")\n");
								}
				#else
								if ( res < 0 ) {
									XPLMDebugString("XData: caught error while sending REQD packet! (");
									XPLMDebugString((char * const) strerror(GET_ERRNO));
									XPLMDebugString(")\n");
								}
				#endif
							}
						}
						
						XPLMDebugString("Sent packet\n");						
						response_index = 8;
						number_of_points = 0;
						
					} else {			
						// otherwise add it to the buffer
						
						// TODO figure out how to either convert each of the above datatypes into char[] data, or
						// simply memcpy from the original dataref into the buffer.
						
						// ID|DATATYPE|LENGTH|DATA....
						int convertedI = custom_htonl(i);
						memcpy(response_data+response_index, &convertedI, 4);
						response_index += 4;
						
						int convertedDatatype = custom_htonl(request_records[i].datatype);
						memcpy(response_data+response_index, &convertedDatatype, 4);
						response_index += 4;
						
						int convertedSize = custom_htonl(size);
						memcpy(response_data+response_index, &convertedSize, 4);
						response_index += 4;

						if( request_records[i].datatype == xplmType_Int ) {
							int convertedInt = custom_htonl(intValue);
							memcpy(response_data+response_index, &convertedInt, 4);
							response_index += 4;
						} else
						if( request_records[i].datatype == xplmType_Float ) {
							// skipping endianness conversion of float too, similar problem to double?
							//float convertedFloat = custom_htonf(floatValue);
							memcpy(response_data+response_index, &floatValue, 4);
							response_index += 4;
							if( DEBUG ) {
								sprintf(msg, "Converted a float: %f\n", floatValue);
								XPLMDebugString(msg);
								sprintf(msg, "%d %d %d %d\n", (int)response_data[response_index-4], (int)response_data[response_index-3], (int)response_data[response_index-2], (int)response_data[response_index-1]);
								XPLMDebugString(msg);								
							}							
						} else
						if( request_records[i].datatype == xplmType_Double || request_records[i].datatype == 6 ) {  // hack based on observed values
						
							// Now this is weird.  Converting the double breaks it somehow.  Even reversing the byte order at the receiving
							// end doesn't work..
							//double convertedDouble = custom_htond(doubleValue);
							memcpy(response_data+response_index, &doubleValue, 8);
							response_index += 8;
						} else			
						if( request_records[i].datatype == xplmType_FloatArray ) {
							int d = 0;
							for( d = 0; d<nbrArrayValues; d++ ) {
								float convertedFloat = custom_htonf(floatArrayValues[d]);
								memcpy(response_data+response_index, &convertedFloat, 4);
								response_index += 4;
							}
						} else
						if( request_records[i].datatype == xplmType_IntArray ) {
							int d = 0;
							for( d = 0; d<nbrArrayValues; d++ ) {
								int convertedInt = custom_htonl(intArrayValues[d]);
								memcpy(response_data+response_index, &convertedInt, 4);
								response_index += 4;
							}
						} else
						if( request_records[i].datatype == xplmType_Data ) {
							memcpy(response_data+response_index, &data, size);
							response_index += size;
						}
						
						
						
						
						
						response_index = index_after_add;
						number_of_points++;	
						
						if( DEBUG ) {
							sprintf(msg, "Packet accumulating: number_of_points=%d response_index=%d\n", number_of_points, response_index);
							XPLMDebugString(msg);						
						}
						
					}

					// schedule next time
					request_records[i].time_next_send = t_diff + rr.every_millis;
//					sprintf(msg, "%d - Would send %s and rescheduled (every %d millis) for %d\n", t_diff, rr.dataref_name, rr.every_millis, rr.time_next_send);
//					XPLMDebugString(msg);
				}
			}
		}
		
		// does the buffer contain any data?
		if( number_of_points > 0 ) {
			// send it
			
			// first update response with number of points
			int convertedNum = custom_htonl(number_of_points);
			memcpy(response_data+4, &convertedNum, 4);
			
			if( DEBUG ) {
				sprintf(msg, "Packet ready to go: number_of_points=%d response_index=%d\n", number_of_points, response_index);
				XPLMDebugString(msg);
				XPLMDebugString("Packet data: ");
				int p=0;
				for( p=0; p<response_index; p++ ) {
					sprintf(msg, "%d:%d ", p, (int)response_data[p]);
					XPLMDebugString(msg);
				}
				XPLMDebugString("\n");
			}
			
			// ready to go		
			for (i=0; i<NUM_DEST; i++) {
				if (dest_enable[i]) {
					res = sendto(sockfd, response_data, response_index, 0, (struct sockaddr *)&dest_sockaddr[i], sizeof(struct sockaddr));
	#if IBM
					if ( res == SOCKET_ERROR ) {
						XPLMDebugString("XData: caught error while sending REQD packet! (");
						sprintf(msg, "%d", WSAGetLastError());
						XPLMDebugString(msg);
						XPLMDebugString(")\n");
					}
	#else
					if ( res < 0 ) {
						XPLMDebugString("XData: caught error while sending REQD packet! (");
						XPLMDebugString((char * const) strerror(GET_ERRNO));
						XPLMDebugString(")\n");
					}
	#endif
				}
			}
			
			if( DEBUG ) {
				XPLMDebugString("Sent packet.\n");				
			}
		}
		
/*
	long		time_last_sent;
	long 		every_millis;
	long		time_next_send;
	
	
every 100 ms, create a buffer (well, reuse it for performance) and start populating it with eligible data.  Keep going until the next ref would overflow the buffer.
 send the packet, then resume from the current ref.  until there are no more eligible refs.  send that last packet, if there's something in it.
 upon adding the data to the packet, update the struct with the calculated next send time.
 
REQD|COUNT|ID|DATATYPE|LENGTH|DATA.....................................|(repeated ID, TYPE, LEN, DATA)..

	
*/	
	
/*
		packet_size = createSituationPacket();

		for (i=0; i<NUM_DEST; i++) {
			if (dest_enable[i]) {
				res = sendto(sockfd, (const char*)&sim_packet, packet_size, 0, (struct sockaddr *)&dest_sockaddr[i], sizeof(struct sockaddr));
#if IBM
				if ( res == SOCKET_ERROR ) {
					XPLMDebugString("XData: caught error while sending REQD packet! (");
                    sprintf(msg, "%d", WSAGetLastError());
					XPLMDebugString(msg);
					XPLMDebugString(")\n");
				}
#else
				if ( res < 0 ) {
					XPLMDebugString("XData: caught error while sending REQD packet! (");
					XPLMDebugString((char * const) strerror(GET_ERRNO));
					XPLMDebugString(")\n");
				}
#endif
			}
		}
*/
		return 0.1;

	} else {

		// print something to allow us to work out what happened.
		XPLMDebugString("XData: plugin enabled:");
		if( xdata_plugin_enabled ) {
			XPLMDebugString("true\n");
		} else {
			XPLMDebugString("false\n");
		}

		XPLMDebugString("XData: send enabled:");
		if( xdata_send_enabled ) {
			XPLMDebugString("true\n");
		} else {
			XPLMDebugString("false\n");
		}

		XPLMDebugString("XData: socket open:");
		if( xdata_socket_open ) {
			XPLMDebugString("true\n");
		} else {
			XPLMDebugString("false\n");
		}
	
		return 0.1f;
	}

}