function LuaExportStart()
	package.path  = package.path..";.\\LuaSocket\\?.lua"
	package.cpath = package.cpath..";.\\LuaSocket\\?.dll"
	socket = require("socket")
	--host = "localhost" 							
	--host = "192.168.1.41" 
	host = "127.0.0.1" 	
	port = 1314 									
	c = socket.try(socket.connect(host, port))		
	c:setoption("tcp-nodelay",true) 
	--c:settimeout(.05)
	socket.try(c:send("DCS World client connected. Go flight."))	
	--socket.try(c:send("Params: altRad;IAS;vrtVel;bank;slipball;Gear;G;Cannon;Name; ; ; ; ;"))
end
------------------------------------------------
--[[function LuaExportActivityNextEvent(t)
	local tNext = t
	tNext = tNext + 20.0
	return tNext
	end
--]]
------------------------------------------------

function LuaExportAfterNextFrame()
	local t = LoGetModelTime()
	
	local navmode = LoGetNavigationInfo()
	local altAsl = LoGetAltitudeAboveSeaLevel()
	local altAgl = LoGetAltitudeAboveGroundLevel()
	local pitch, bank, yaw = LoGetADIPitchBankYaw()
	local indAirSpd = LoGetIndicatedAirSpeed()
	local aoa = LoGetAngleOfAttack()
	local vrtVel = LoGetVerticalVelocity()
	local acceleration = LoGetAccelerationUnits()
	local slipball = LoGetSlipBallPosition()
	local obj = LoGetSelfData()
	local vectorVel = LoGetVectorVelocity()
	----local PlaneID = LoGetPlayerPlaneId()
	----local obj = LoGetObjectById(PlaneID)
       -- --default_output_file:write(string.format("%.2f;%.2f; %.2f; %.2f; %.2f; %.2f; %.2f; %.2f; %.2f; %.2f; %.2f\n", t, 0.1*engine.RPM.left, 0.1*altAsl, 0.036*indAirSpd, 57.3*aoa, vrtVel, 57.3*bank, 57.3*pitch, 0.1*altRad, acceleration.y))	
	----socket.try(c:send(string.format("%.2f;%.2f;%.2f;\n",altAgl*3.28084,3.6*indAirSpd,vrtVel)))
	----socket.try(c:send(string.format("AltR=%.0f=ft;IAS=%.0f=km h;VertV=%.1f=m s;\n",altAgl*3.28084,3.6*indAirSpd,vrtVel)))
	if c then
		if obj.Name == "P-51D" then	
		local CannonShells = LoGetPayloadInfo().Cannon.shells
		-- read from P-51D main panel instruments
		local MainPanel = GetDevice(0)
		--if MainPanel then
	      	MainPanel:update_arguments() -- на всякий случай если мы давно не рисовали кабину например на внешних видах
		--local AirspeedNeedle = MainPanel:get_argument_value(11)*1000
		local AirspeedNeedle = MainPanel:get_argument_value(11)*1000*1.852
		local Altimeter_10000_footPtr = MainPanel:get_argument_value(96)*100000
		local Altimeter_1000_footPtr = MainPanel:get_argument_value(24)*10000
		local Altimeter_100_footPtr = MainPanel:get_argument_value(25)*1000
		--local Variometer = MainPanel:get_argument_value(29)*10000
		local Variometer = MainPanel:get_argument_value(29)
		local TurnNeedle = MainPanel:get_argument_value(27)*math.rad(3)
		local Slipball = MainPanel:get_argument_value(28)
		local CompassHeading = MainPanel:get_argument_value(1) * math.pi * 2.0
		local Landing_Gear_Handle = MainPanel:get_argument_value(150)
		local Manifold_Pressure = MainPanel:get_argument_value(10) * 65 + 10
		local Engine_RPM = MainPanel:get_argument_value(23)*4500
		local AHorizon_Pitch = MainPanel:get_argument_value(15) * math.pi / 3.0
		local AHorizon_Bank = MainPanel:get_argument_value(14) * math.pi
		local AHorizon_PitchShift = MainPanel:get_argument_value(16) * 10.0 * math.pi/180.0
		local GyroHeading = MainPanel:get_argument_value(12) * 2.0 * math.pi
		local Oil_Temperature = MainPanel:get_argument_value(30) * 100
		local Oil_Pressure = MainPanel:get_argument_value(31) * 200
		local Fuel_Pressure = MainPanel:get_argument_value(32) * 25
		socket.try(c:send(string.format("%.3f;%s;%.2f;%.2f;%.2f;%.0f;%.0f;%.2f;%.0f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;dummy;|",t,obj.Name,AirspeedNeedle,Variometer,AHorizon_Bank,100*Slipball,100*Landing_Gear_Handle,acceleration.y,CannonShells,altAgl,vectorVel.x,vectorVel.y,vectorVel.z,Manifold_Pressure,Engine_RPM)))

		elseif obj.Name == "A-10C" then
		local engine = LoGetEngineInfo()
		local CannonShells = LoGetPayloadInfo().Cannon.shells
		socket.try(c:send(string.format("%.3f;%s;0;0;%.2f;0;0;%.2f;%.0f;%.2f;%.2f;%.2f;%.2f;1;1;dummy;|",t,obj.Name,57.3*bank,acceleration.y,CannonShells,altAgl,vectorVel.x,vectorVel.y,vectorVel.z)))
		
		elseif obj.Name == "Mi-8MT" then
		
		else
		local engine = LoGetEngineInfo()
		local CannonShells = LoGetPayloadInfo().Cannon.shells
		local RawGearStatus = LoGetMechInfo().gear.value
		local SpeedBrakeValue = LoGetMechInfo().speedbrakes.value
		local CanopyValue = LoGetMechInfo().canopy.value
		socket.try(c:send(string.format("%.3f;%s;%.2f;%.2f;%.2f;%.0f;%.0f;%.2f;%.0f;%.2f;%.2f;%.2f;%.2f;%.2f;dummy;%.2f;|",t,obj.Name,3.6*indAirSpd,vrtVel,57.3*bank,100*slipball,100*RawGearStatus,acceleration.y,CannonShells,altAgl,vectorVel.x,vectorVel.y,vectorVel.z,SpeedBrakeValue,CanopyValue)))
		end
	end

end

------------------------------------------------
function LuaExportStop()
	socket.try(c:send("DCS World client disconnected. Good luck, pilot.")) 
	c:close()
end

