void simconnect_OnRecvSimobjectDataBytype(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data) { switch ((FsDataObjects.DATA_REQUESTS)data.dwRequestID) { case FsDataObjects.DATA_REQUESTS.REQUEST_1: FsDataObjects.AircraftDataStructure acData = (FsDataObjects.AircraftDataStructure)data.dwData[0]; lblX.Text = String.Format("{0,0:N5} deg", acData.longitude); lblY.Text = String.Format("{0,0:N5} deg", acData.latitude); lblAlt.Text = String.Format("{0,0:N2} ft", acData.altitude); lblU.Text = String.Format("{0,0:N3} ft/s", acData.u); lblV.Text = String.Format("{0,0:N3} ft/s", acData.v); lblW.Text = String.Format("{0,0:N3} ft/s", -acData.w_neg); lblYaw.Text = String.Format("{0,0:N3} deg", acData.yaw); lblPitch.Text = String.Format("{0,0:N3} deg", -acData.pitch_neg); lblRoll.Text = String.Format("{0,0:N3} deg", -acData.roll_neg); lblP.Text = String.Format("{0,0:N3} rad/s", -acData.p_neg); lblQ.Text = String.Format("{0,0:N3} rad/s", -acData.q_neg); lblR.Text = String.Format("{0,0:N3} rad/s", acData.r); lblMach.Text = String.Format("{0,0:N5}", acData.mach); lblElevator.Text = String.Format("{0,0:N3}%", ControlsLatest.elevator * 100); lblThrottle.Text = String.Format("{0,0:N3}%", ControlsLatest.throttle1); lblAileron.Text = String.Format("{0,0:N3}%", ControlsLatest.aileron * 100); lblRudder.Text = String.Format("{0,0:N3}%", ControlsLatest.rudder * 100); lblGear.Text = (gear_last == 0) ? "Down" : "Up"; lblFlaps.Text = String.Format("{0,0:N0}% Down", (flaps_last / 2.0) * 100.0); lblBeta.Text = String.Format("{0,0:N3} deg", acData.beta * 180.0 / Math.PI); String udpSend = NetworkParser.UdpStringFromAC(acData); Byte[] sendBytes = Encoding.ASCII.GetBytes(udpSend); DateTime CurrentTime = DateTime.Now; if ((CurrentTime - LastSendTime).Milliseconds > 250) { udpSendingSocket.BeginSend(sendBytes, sendBytes.Length, endpointSending, null, udpSendingSocket); LastSendTime = DateTime.Now; } break; default: WriteToLog("Unknown request ID: " + data.dwRequestID); break; } }
/// <summary> /// Fully receive the simconnect data object /// </summary> /// <param name="sender"></param> /// <param name="data"></param> void simconnect_OnRecvSimobjectDataBytype( SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data) { // Switch by message data types switch ((FsDataObjects.DATA_REQUESTS)data.dwRequestID) { case FsDataObjects.DATA_REQUESTS.REQUEST_1: // Receive the aircraft data FsDataObjects.AircraftDataStructure acData = (FsDataObjects.AircraftDataStructure)data.dwData[0]; // Set display parameters lblX.Text = String.Format("{0,0:N5} deg", acData.longitude); lblY.Text = String.Format("{0,0:N5} deg", acData.latitude); lblAlt.Text = String.Format("{0,0:N2} ft", acData.altitude); lblU.Text = String.Format("{0,0:N3} ft/s", acData.u); lblV.Text = String.Format("{0,0:N3} ft/s", acData.v); lblW.Text = String.Format("{0,0:N3} ft/s", -acData.w_neg); lblYaw.Text = String.Format("{0,0:N3} deg", acData.yaw); lblPitch.Text = String.Format("{0,0:N3} deg", -acData.pitch_neg); lblRoll.Text = String.Format("{0,0:N3} deg", -acData.roll_neg); lblP.Text = String.Format("{0,0:N3} rad/s", -acData.p_neg); lblQ.Text = String.Format("{0,0:N3} rad/s", -acData.q_neg); lblR.Text = String.Format("{0,0:N3} rad/s", acData.r); lblMach.Text = String.Format("{0,0:N5}", acData.mach); lblElevator.Text = String.Format("{0,0:N3}%", ControlsLatest.elevator * 100); lblThrottle.Text = String.Format("{0,0:N3}%", ControlsLatest.throttle1); lblAileron.Text = String.Format("{0,0:N3}%", ControlsLatest.aileron * 100); lblRudder.Text = String.Format("{0,0:N3}%", ControlsLatest.rudder * 100); lblGear.Text = (gear_last == 0) ? "Down" : "Up"; lblFlaps.Text = String.Format("{0,0:N0}% Down", (flaps_last / 2.0) * 100.0); lblBeta.Text = String.Format("{0,0:N3} deg", acData.beta * 180.0 / Math.PI); // Get the current time DateTime CurrentTime = DateTime.Now; // Only send if the time interval since the last send has been great enough if ((CurrentTime - LastSendTime).Milliseconds > 100) { // Create the UDP sending string packet String udpSend = NetworkParser.UdpStringFromAC(acData); Byte[] sendBytes = Encoding.ASCII.GetBytes(udpSend); // Send the packets and update the last send time udpSocket.BeginSend( sendBytes, sendBytes.Length, endpointSending, null, null); LastSendTime = CurrentTime; } break; default: WriteToLog("Unknown request ID: " + data.dwRequestID); break; } }