Exemplo n.º 1
0
        /// <summary>
        /// This method is used to store in a list all TLE parameters for each epoch time
        ///
        /// Each entry of the return list is a TLE_Sat variable with its parameters defined except for the name (which is not necessary as every entry is related to the same satellite)
        /// </summary>
        /// <param name="data_raw">List of array of bytes with every TLE (its two lines) for each entry</param>
        /// <returns>List of TLE_Sat containing processed data</returns>
        public static List <TLE_Sat> TLE_Lines_DataExtractor(List <byte[]> data_raw)
        {
            try
            {
                List <TLE_Sat> TLE_individualSat_List = new List <TLE_Sat>();

                foreach (byte[] byte_arr in data_raw)
                {
                    TLE_Sat  _TLE_sat = new TLE_Sat();
                    DateTime epoch    = new DateTime();

                    // First row
                    _TLE_sat.Sat_Number             = Convert.ToUInt32((System.Text.Encoding.Default.GetString(byte_arr)).Substring(2, 5));
                    _TLE_sat.Sat_Classification     = (System.Text.Encoding.Default.GetString(byte_arr)).Substring(7, 1);
                    _TLE_sat.Sat_IntDesignator      = (System.Text.Encoding.Default.GetString(byte_arr)).Substring(9, 8);
                    _TLE_sat.Sat_ElementSetEpoch    = (System.Text.Encoding.Default.GetString(byte_arr)).Substring(18, 14);
                    _TLE_sat.Sat_FirstMeanMotionDer = Convert.ToDouble((System.Text.Encoding.Default.GetString(byte_arr)).Substring(33, 10), System.Globalization.CultureInfo.InvariantCulture);
                    _TLE_sat.Sat_SecMeanMotionDer   = TLE_Data_AuxMethods.GetDoubleFromScientificNotation((System.Text.Encoding.Default.GetString(byte_arr)).Substring(44, 8));
                    _TLE_sat.Sat_BSTARDrag          = TLE_Data_AuxMethods.GetDoubleFromScientificNotation((System.Text.Encoding.Default.GetString(byte_arr)).Substring(53, 8));
                    _TLE_sat.Sat_SetType            = (System.Text.Encoding.Default.GetString(byte_arr)).Substring(62, 1);
                    _TLE_sat.Sat_SetNumber          = (System.Text.Encoding.Default.GetString(byte_arr)).Substring(64, 4);

                    _TLE_sat.Sat_LaunchYear   = TLE_Data_AuxMethods.GetLaunchYearFromDesignator(_TLE_sat.Sat_IntDesignator);
                    _TLE_sat.Sat_LaunchNumber = TLE_Data_AuxMethods.GetLaunchNumberFromDesignator(_TLE_sat.Sat_IntDesignator);
                    _TLE_sat.Sat_LaunchPiece  = TLE_Data_AuxMethods.GetLaunchPieceFromDesignator(_TLE_sat.Sat_IntDesignator);
                    _TLE_sat.Sat_EpochYear    = TLE_Data_AuxMethods.GetYearFromEpoch(_TLE_sat.Sat_ElementSetEpoch);
                    _TLE_sat.Sat_EpochDay     = TLE_Data_AuxMethods.GetDayFromEpoch(_TLE_sat.Sat_ElementSetEpoch);
                    if (TLE_Data_AuxMethods.GetDateTimeFromEpoch(_TLE_sat.Sat_ElementSetEpoch, out epoch))
                    {
                        _TLE_sat.Sat_EpochDateTime = epoch;
                    }

                    // Second row
                    _TLE_sat.Sat_Inclination     = Convert.ToDouble((System.Text.Encoding.Default.GetString(byte_arr)).Substring(79, 8), System.Globalization.CultureInfo.InvariantCulture);
                    _TLE_sat.Sat_RightAscension  = Convert.ToDouble((System.Text.Encoding.Default.GetString(byte_arr)).Substring(88, 8), System.Globalization.CultureInfo.InvariantCulture);
                    _TLE_sat.Sat_Eccentricity    = Convert.ToDouble(("0." + (System.Text.Encoding.Default.GetString(byte_arr)).Substring(97, 7)), System.Globalization.CultureInfo.InvariantCulture);
                    _TLE_sat.Sat_ArgumentPerigee = Convert.ToDouble((System.Text.Encoding.Default.GetString(byte_arr)).Substring(105, 8), System.Globalization.CultureInfo.InvariantCulture);
                    _TLE_sat.Sat_MeanAnomaly     = Convert.ToDouble((System.Text.Encoding.Default.GetString(byte_arr)).Substring(114, 8), System.Globalization.CultureInfo.InvariantCulture);
                    _TLE_sat.Sat_MeanMotion      = Convert.ToDouble((System.Text.Encoding.Default.GetString(byte_arr)).Substring(123, 11), System.Globalization.CultureInfo.InvariantCulture);
                    _TLE_sat.Sat_RevNumber       = Convert.ToUInt32((System.Text.Encoding.Default.GetString(byte_arr)).Substring(134, 5));

                    // Post-processed data
                    _TLE_sat.Sat_SemiAxis = TLE_Data_AuxMethods.GetSemiAxisFromPeriod(_TLE_sat.Sat_MeanMotion);
                    _TLE_sat.Sat_Perigee  = TLE_Data_AuxMethods.GetPerigee(_TLE_sat.Sat_SemiAxis, _TLE_sat.Sat_Eccentricity);
                    _TLE_sat.Sat_Apogee   = TLE_Data_AuxMethods.GetApogee(_TLE_sat.Sat_SemiAxis, _TLE_sat.Sat_Eccentricity);

                    TLE_individualSat_List.Add(_TLE_sat);
                }

                return(TLE_individualSat_List);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(null);
            }
        }
Exemplo n.º 2
0
        public bool GetSelectedSat_fromDataRow(DataRow input_dataRow)
        {
            try
            {
                TLE_Sat result = new TLE_Sat();

                result.Sat_Name               = input_dataRow.ItemArray[1].ToString();
                result.Sat_Number             = Convert.ToUInt32(input_dataRow.ItemArray[2]);
                result.Sat_Classification     = input_dataRow.ItemArray[3].ToString();
                result.Sat_IntDesignator      = input_dataRow.ItemArray[4].ToString();
                result.Sat_ElementSetEpoch    = input_dataRow.ItemArray[5].ToString();
                result.Sat_FirstMeanMotionDer = Convert.ToDouble(input_dataRow.ItemArray[6]);
                result.Sat_SecMeanMotionDer   = Convert.ToDouble(input_dataRow.ItemArray[7]);
                result.Sat_BSTARDrag          = Convert.ToDouble(input_dataRow.ItemArray[8]);
                result.Sat_SetType            = input_dataRow.ItemArray[9].ToString();
                result.Sat_SetNumber          = input_dataRow.ItemArray[10].ToString();
                result.Sat_Inclination        = Convert.ToDouble(input_dataRow.ItemArray[11]);
                result.Sat_RightAscension     = Convert.ToDouble(input_dataRow.ItemArray[12]);
                result.Sat_Eccentricity       = Convert.ToDouble(input_dataRow.ItemArray[13]);
                result.Sat_ArgumentPerigee    = Convert.ToDouble(input_dataRow.ItemArray[14]);
                result.Sat_MeanAnomaly        = Convert.ToDouble(input_dataRow.ItemArray[15]);
                result.Sat_MeanMotion         = Convert.ToDouble(input_dataRow.ItemArray[16]);
                result.Sat_RevNumber          = Convert.ToUInt32(input_dataRow.ItemArray[17]);
                result.Sat_LaunchYear         = Convert.ToUInt32(input_dataRow.ItemArray[18]);
                result.Sat_LaunchNumber       = Convert.ToUInt32(input_dataRow.ItemArray[19]);
                result.Sat_LaunchPiece        = input_dataRow.ItemArray[20].ToString();
                result.Sat_EpochYear          = Convert.ToUInt32(input_dataRow.ItemArray[21]);
                result.Sat_EpochDay           = Convert.ToDouble(input_dataRow.ItemArray[22]);
                result.Sat_EpochDateTime      = Convert.ToDateTime(input_dataRow.ItemArray[23]);

                result.Sat_SemiAxis = TLE_Data_AuxMethods.GetSemiAxisFromPeriod(result.Sat_MeanMotion);
                result.Sat_Perigee  = TLE_Data_AuxMethods.GetPerigee(result.Sat_SemiAxis, result.Sat_Eccentricity);
                result.Sat_Apogee   = TLE_Data_AuxMethods.GetApogee(result.Sat_SemiAxis, result.Sat_Eccentricity);

                _TLE_Sat_Selected = result;

                _SAT_SELECTED = true;
                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(false);
            }
        }
Exemplo n.º 3
0
        public List <TLE_Sat> ParseTLEString(byte[] TLE_data)
        {
            try
            {
                // POR AHORA SE PIERDE EL ULTIMO SATELITE, POR COMO ESTA PENSADA LA RECUPERACION
                int      counter           = 0;
                int      _internal_counter = 0;
                TLE_Sat  tle_sat           = new TLE_Sat();
                byte[]   buffer            = new byte[250];
                DateTime epoch;
                //List<TLE_Sat> final_list = new List<TLE_Sat>();
                while (counter < (TLE_data.Length - 1))
                {
                    if (TLE_data[counter] == 10 && TLE_data[counter + 1] == 49)
                    {
                        tle_sat.Sat_Name = System.Text.Encoding.Default.GetString(buffer).Substring(2, 24).Replace("\0", String.Empty).Replace("\r", String.Empty);

                        Array.Clear(buffer, 0, buffer.Length);
                        _internal_counter = 0;
                    }
                    else if (TLE_data[counter] == 10 && TLE_data[counter + 1] == 50)
                    {
                        tle_sat.Sat_Number             = Convert.ToUInt32((System.Text.Encoding.Default.GetString(buffer)).Substring(2, 5));
                        tle_sat.Sat_Classification     = (System.Text.Encoding.Default.GetString(buffer)).Substring(7, 1);
                        tle_sat.Sat_IntDesignator      = (System.Text.Encoding.Default.GetString(buffer)).Substring(9, 8);
                        tle_sat.Sat_ElementSetEpoch    = (System.Text.Encoding.Default.GetString(buffer)).Substring(18, 14);
                        tle_sat.Sat_FirstMeanMotionDer = Convert.ToDouble((System.Text.Encoding.Default.GetString(buffer)).Substring(33, 10), System.Globalization.CultureInfo.InvariantCulture);
                        tle_sat.Sat_SecMeanMotionDer   = TLE_Data_AuxMethods.GetDoubleFromScientificNotation((System.Text.Encoding.Default.GetString(buffer)).Substring(44, 8));
                        tle_sat.Sat_BSTARDrag          = TLE_Data_AuxMethods.GetDoubleFromScientificNotation((System.Text.Encoding.Default.GetString(buffer)).Substring(53, 8));
                        tle_sat.Sat_SetType            = (System.Text.Encoding.Default.GetString(buffer)).Substring(62, 1);
                        tle_sat.Sat_SetNumber          = (System.Text.Encoding.Default.GetString(buffer)).Substring(64, 4);

                        // Processed items
                        tle_sat.Sat_LaunchYear   = TLE_Data_AuxMethods.GetLaunchYearFromDesignator(tle_sat.Sat_IntDesignator);
                        tle_sat.Sat_LaunchNumber = TLE_Data_AuxMethods.GetLaunchNumberFromDesignator(tle_sat.Sat_IntDesignator);
                        tle_sat.Sat_LaunchPiece  = TLE_Data_AuxMethods.GetLaunchPieceFromDesignator(tle_sat.Sat_IntDesignator);
                        tle_sat.Sat_EpochYear    = TLE_Data_AuxMethods.GetYearFromEpoch(tle_sat.Sat_ElementSetEpoch);
                        tle_sat.Sat_EpochDay     = TLE_Data_AuxMethods.GetDayFromEpoch(tle_sat.Sat_ElementSetEpoch);
                        if (TLE_Data_AuxMethods.GetDateTimeFromEpoch(tle_sat.Sat_ElementSetEpoch, out epoch))
                        {
                            tle_sat.Sat_EpochDateTime = epoch;
                        }

                        Array.Clear(buffer, 0, buffer.Length);
                        _internal_counter = 0;
                    }
                    else if (TLE_data[counter] == 10 && TLE_data[counter + 1] == 48)
                    {
                        tle_sat.Sat_Inclination     = Convert.ToDouble((System.Text.Encoding.Default.GetString(buffer)).Substring(8, 8), System.Globalization.CultureInfo.InvariantCulture);
                        tle_sat.Sat_RightAscension  = Convert.ToDouble((System.Text.Encoding.Default.GetString(buffer)).Substring(17, 8), System.Globalization.CultureInfo.InvariantCulture);
                        tle_sat.Sat_Eccentricity    = Convert.ToDouble(("0." + (System.Text.Encoding.Default.GetString(buffer)).Substring(26, 7)), System.Globalization.CultureInfo.InvariantCulture);
                        tle_sat.Sat_ArgumentPerigee = Convert.ToDouble((System.Text.Encoding.Default.GetString(buffer)).Substring(34, 8), System.Globalization.CultureInfo.InvariantCulture);
                        tle_sat.Sat_MeanAnomaly     = Convert.ToDouble((System.Text.Encoding.Default.GetString(buffer)).Substring(43, 8), System.Globalization.CultureInfo.InvariantCulture);
                        tle_sat.Sat_MeanMotion      = Convert.ToDouble((System.Text.Encoding.Default.GetString(buffer)).Substring(52, 11), System.Globalization.CultureInfo.InvariantCulture);
                        tle_sat.Sat_RevNumber       = Convert.ToUInt32((System.Text.Encoding.Default.GetString(buffer)).Substring(63, 5));

                        Array.Clear(buffer, 0, buffer.Length);
                        _internal_counter = 0;
                        _TLE_Sat_List.Add(tle_sat);
                        tle_sat = new TLE_Sat();
                    }
                    else
                    {
                        buffer[_internal_counter] = TLE_data[counter];
                        _internal_counter++;
                    }
                    counter++;
                }
                // Parse ROWS

                /*string[] raw_rows = TLE_data.Split('\n');
                 * List<string> final_rows = new List<string>();
                 * string _row = "";
                 *
                 * for (int i = 0; i < raw_rows.Count(); i++)
                 * {
                 *      _row += " " + raw_rows[i];
                 *      if ((i + 1) % 3 == 0)
                 *      {
                 *              final_rows.Add(_row);
                 *              _row = "";
                 *      }
                 * }
                 *
                 * // Parse COLUMNS
                 * List<string[]> final_list = new List<string[]>();
                 * char[] delimiters = new char[] { ' ', '\r' };
                 *
                 * foreach(var item in final_rows)
                 * {
                 *      string[] raw_final_row = item.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                 *      final_list.Add(raw_final_row);
                 *      //Debug.WriteLine("Count: " + final_list.Count + "; Elements: " + raw_final_row.Length);
                 * }*/

                return(_TLE_Sat_List);
                //return null;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method is needed to promediate raw data
        ///
        /// In case there is only one entry in the input list, it will not change data except datetime epoch
        /// </summary>
        /// <param name="TLE_buffer_list">Raw TLE list data input</param>
        /// <returns>TLE instance with promediated data</returns>
        private static TLE_Sat TLE_PromediateList_Processed(List <TLE_Sat> TLE_buffer_list)
        {
            try
            {
                TLE_Sat result = new TLE_Sat();

                // Get datetime epoch. In this case hours, minutes and seconds will be 0. As it doesnt matter which entry is used, we get the first one
                int      day;
                int      month = TLE_Data_AuxMethods.GetMonthAndDayFromEpoch(TLE_buffer_list[0].Sat_ElementSetEpoch, out day);
                DateTime _TLE_epochDatetime;
                if (TLE_buffer_list.Count != 1)
                {
                    _TLE_epochDatetime = new DateTime((int)TLE_buffer_list[0].Sat_EpochYear, month, day, 0, 0, 0);
                }
                else
                {
                    _TLE_epochDatetime = TLE_buffer_list[0].Sat_EpochDateTime;
                }

                // Promediate certain parameters
                double _Sat_ElementSetEpoch_double = 0;
                double _Sat_FirstMeanMotionDer     = 0;
                double _Sat_SecMeanMotionDer       = 0;
                double _Sat_BSTARDrag       = 0;
                double _Sat_Inclination     = 0;
                double _Sat_RightAscension  = 0;
                double _Sat_Eccentricity    = 0;
                double _Sat_ArgumentPerigee = 0;
                double _Sat_MeanAnomaly     = 0;
                double _Sat_MeanMotion      = 0;
                uint   _Sat_RevNumber       = 0;
                double _Sat_Semiaxis        = 0;
                double _Sat_Perigee         = 0;
                double _Sat_Apogee          = 0;

                for (int i = 0; i < TLE_buffer_list.Count; i++)
                {
                    _Sat_ElementSetEpoch_double += Convert.ToDouble(TLE_buffer_list[i].Sat_ElementSetEpoch, System.Globalization.CultureInfo.InvariantCulture);
                    _Sat_FirstMeanMotionDer     += TLE_buffer_list[i].Sat_FirstMeanMotionDer;
                    _Sat_SecMeanMotionDer       += TLE_buffer_list[i].Sat_SecMeanMotionDer;
                    _Sat_BSTARDrag       += TLE_buffer_list[i].Sat_BSTARDrag;
                    _Sat_Inclination     += TLE_buffer_list[i].Sat_Inclination;
                    _Sat_RightAscension  += TLE_buffer_list[i].Sat_RightAscension;
                    _Sat_Eccentricity    += TLE_buffer_list[i].Sat_Eccentricity;
                    _Sat_ArgumentPerigee += TLE_buffer_list[i].Sat_ArgumentPerigee;
                    _Sat_MeanAnomaly     += TLE_buffer_list[i].Sat_MeanAnomaly;
                    _Sat_MeanMotion      += TLE_buffer_list[i].Sat_MeanMotion;
                    _Sat_RevNumber       += TLE_buffer_list[i].Sat_RevNumber;
                    _Sat_Semiaxis        += TLE_buffer_list[i].Sat_SemiAxis;
                    _Sat_Perigee         += TLE_buffer_list[i].Sat_Perigee;
                    _Sat_Apogee          += TLE_buffer_list[i].Sat_Apogee;
                }

                _Sat_ElementSetEpoch_double = _Sat_ElementSetEpoch_double / TLE_buffer_list.Count;
                _Sat_FirstMeanMotionDer     = _Sat_FirstMeanMotionDer / TLE_buffer_list.Count;
                _Sat_SecMeanMotionDer       = _Sat_SecMeanMotionDer / TLE_buffer_list.Count;
                _Sat_BSTARDrag       = _Sat_BSTARDrag / TLE_buffer_list.Count;
                _Sat_Inclination     = _Sat_Inclination / TLE_buffer_list.Count;
                _Sat_RightAscension  = _Sat_RightAscension / TLE_buffer_list.Count;
                _Sat_Eccentricity    = _Sat_Eccentricity / TLE_buffer_list.Count;
                _Sat_ArgumentPerigee = _Sat_ArgumentPerigee / TLE_buffer_list.Count;
                _Sat_MeanAnomaly     = _Sat_MeanAnomaly / TLE_buffer_list.Count;
                _Sat_MeanMotion      = _Sat_MeanMotion / TLE_buffer_list.Count;
                _Sat_RevNumber       = _Sat_RevNumber / (uint)TLE_buffer_list.Count;
                _Sat_Semiaxis        = _Sat_Semiaxis / TLE_buffer_list.Count;
                _Sat_Perigee         = _Sat_Perigee / TLE_buffer_list.Count;
                _Sat_Apogee          = _Sat_Apogee / TLE_buffer_list.Count;

                // Fill all TLE_Sat output. All data not promediated will be the first entry
                result.Sat_Number             = TLE_buffer_list[0].Sat_Number;
                result.Sat_Classification     = TLE_buffer_list[0].Sat_Classification;
                result.Sat_IntDesignator      = TLE_buffer_list[0].Sat_IntDesignator;
                result.Sat_ElementSetEpoch    = string.Format("{0:0.00000000}", _Sat_ElementSetEpoch_double);
                result.Sat_FirstMeanMotionDer = _Sat_FirstMeanMotionDer;
                result.Sat_SecMeanMotionDer   = _Sat_SecMeanMotionDer;
                result.Sat_BSTARDrag          = _Sat_BSTARDrag;
                result.Sat_SetType            = TLE_buffer_list[0].Sat_SetType;
                result.Sat_SetNumber          = TLE_buffer_list[0].Sat_SetNumber;
                result.Sat_Inclination        = _Sat_Inclination;
                result.Sat_RightAscension     = _Sat_RightAscension;
                result.Sat_Eccentricity       = _Sat_Eccentricity;
                result.Sat_ArgumentPerigee    = _Sat_ArgumentPerigee;
                result.Sat_MeanAnomaly        = _Sat_MeanAnomaly;
                result.Sat_MeanMotion         = _Sat_MeanMotion;
                result.Sat_RevNumber          = _Sat_RevNumber;
                result.Sat_LaunchYear         = TLE_Data_AuxMethods.GetLaunchYearFromDesignator(result.Sat_IntDesignator);
                result.Sat_LaunchNumber       = TLE_Data_AuxMethods.GetLaunchNumberFromDesignator(result.Sat_IntDesignator);
                result.Sat_LaunchPiece        = TLE_Data_AuxMethods.GetLaunchPieceFromDesignator(result.Sat_IntDesignator);
                result.Sat_EpochYear          = TLE_Data_AuxMethods.GetYearFromEpoch(result.Sat_ElementSetEpoch);
                result.Sat_EpochDay           = TLE_Data_AuxMethods.GetDayFromEpoch(result.Sat_ElementSetEpoch);
                result.Sat_EpochDateTime      = _TLE_epochDatetime;
                result.Sat_SemiAxis           = _Sat_Semiaxis;
                result.Sat_Perigee            = _Sat_Apogee;
                result.Sat_Apogee             = _Sat_Apogee;

                return(result);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(null);
            }
        }