%addpath('../lib/xplane');
% run Constants
ip='127.0.0.1';%'158.42.41.147';
port_Xplane=49000; % Port we send to X-plane. MANDATORY. You cannot change it!. 
                   % Configure it in Xplane as "Port we receive on".
port_Matlab=49010; % Port we receive from X-plane
                   % Anyone will do. You do not need to configure it in Xplane

% Select datarefs to read--------------------------------------------------
dataref_r = {...
    'sim/flightmodel/position/true_airspeed',... % TAS (m/s)
    'sim/flightmodel/position/true_theta',... % Pitch (deg)
    'sim/flightmodel/position/Q',... % Pitch rate (deg/sec)
    'sim/flightmodel/position/vpath',... % Vpath (deg) (vpath+alpha=theta)
    'sim/flightmodel/position/vh_ind_fpm',... % VS (fpm)
    'sim/flightmodel/position/alpha',... % Angle of Attack (deg)
    ...
    'sim/flightmodel/position/P',... % Roll rate (deg/sec)
    'sim/flightmodel/position/R',... % Yaw rate (deg/sec)
    'sim/flightmodel/position/true_phi',... % Roll (deg)
    'sim/flightmodel/position/beta',... % Sideslip (deg)
    'sim/flightmodel/position/true_psi',... % Heading (deg) The (true) heading of the aircraft relative to the earth
    'sim/flightmodel/position/hpath',... % Track angle (deg) (hpath+beta=psi)
    ...    
    'sim/flightmodel/position/latitude',... %Latitude (dec deg)
    'sim/flightmodel/position/longitude',... %Longitude (dec deg)
    'sim/flightmodel/position/elevation',... % Altitude (m AMSL)
    ...
    'sim/aircraft/parts/acf_gear_deploy'...% Landing Gear
    ...
    'sim/time/paused'... %Is the sim paused? (bool)
    
    };

% Request datarefs to read-------------------------------------------------
dref_requestXPLANE(ip,port_Xplane,port_Matlab,1/Ts,dataref_r);
%--------------------------------------------------------------------------

% Override datarefs
dataref_w = {...
    'sim/operation/override/override_joystick',...
    'sim/operation/override/override_airstab' ...
    };
dref_writeXPLANE(ip,port_Xplane,dataref_w,ones(1,length(dataref_w)) );

% Select datarefs to write ------------------------------------------------
dataref_w = {...
    'sim/joystick/yoke_pitch_ratio',...
    'sim/joystick/yoke_roll_ratio',...
    'sim/joystick/yoke_heading_ratio',...
    'sim/flightmodel/engine/ENGN_thro[0]' ...
    'sim/flightmodel/controls/flaprqst'...
    'sim/cockpit2/controls/gear_handle_down'...
    'sim/flightmodel/controls/parkbrake'...
    };
%--------------------------------------------------------------------------
