/// <summary> /// Add incoming data. If averaging is turned on, /// the data will be added to the list and the average /// output. If averaging is turned off, the value /// will just be set. /// </summary> /// <param name="heading">Heading in degrees.</param> /// <param name="pitch">Pitch in degrees.</param> /// <param name="roll">Roll in degrees.</param> public void AddIncomingData(float heading, float pitch, float roll) { // If the data is not good, do not add anything if (heading == 0.0f && pitch == 0.0f && roll == 0.0f) { return; } HPR hpr = new HPR(); hpr.Heading = heading; hpr.Pitch = pitch; hpr.Roll = roll; // Buffer the data _buffer.Enqueue(hpr); if ((++_displayCounter % 5) == 0) { // Wake up the thread to process data if (!_eventWaitData.SafeWaitHandle.IsClosed) { _eventWaitData.Set(); } _displayCounter = 0; } }
/// <summary> /// Get the heading, pitch and roll value. /// </summary> /// <param name="reader">Reader of the database.</param> /// <returns>Heading, pitch and roll value.</returns> public static HPR GetHPR(DbDataReader reader) { string jsonAncillary = reader["AncillaryDS"].ToString(); string jsonBt = reader["BottomTrackDS"].ToString(); // Verify we have all the data if (string.IsNullOrEmpty(jsonAncillary) || string.IsNullOrEmpty(jsonBt)) { // No values found return(new HPR() { Heading = 0.0, Pitch = 0.0, Roll = 0.0 }); } // Convert to JSON objects JObject ancData = JObject.Parse(jsonAncillary); JObject btData = JObject.Parse(jsonBt); if (ancData != null && ancData.HasValues) { HPR hpr = new HPR(); hpr.Heading = ancData["Heading"].ToObject <double>(); hpr.Pitch = ancData["Pitch"].ToObject <double>(); hpr.Roll = ancData["Roll"].ToObject <double>(); return(hpr); } else if (btData != null && btData.HasValues) { HPR hpr = new HPR(); hpr.Heading = btData["Heading"].ToObject <double>(); hpr.Pitch = btData["Pitch"].ToObject <double>(); hpr.Roll = btData["Roll"].ToObject <double>(); return(hpr); } // No values found return(new HPR() { Heading = 0.0, Pitch = 0.0, Roll = 0.0 }); }