Example #1
0
        public virtual bool TryParse(string xiRawData, out object xoData)
        {
            Assert.NonEmptyString(xiRawData, "xiRawData");

            xoData = null;

            bool result = false;

            if (xiRawData.IndexOf('%') < 0 && xiRawData.IndexOf('#') < 0)
            {
                string [] vals = xiRawData.Split(Text.kComma, StringSplitOptions.RemoveEmptyEntries);

                if (vals.Length > 7) // truth,2,fields|run_number, target_number, time, x_pos, x_vel, x_acc, y_pos, x_acc, y_acc|<EOL>
                {
                    xoData = new Data.Truth();

                    Data.Truth truth = xoData as Data.Truth;

                    truth.timestamp = DateTime.Now;

                    long timestamp;

                    if (long.TryParse(vals[2], out timestamp))
                    {
                        truth.rawTimestamp = timestamp;
                    }

                    double val;

                    if (double.TryParse(vals[1], out val))
                    {
                        truth.targetNumber = (int)val;
                    }

                    if (double.TryParse(vals[3], out val))
                    {
                        truth.xPos = val;
                    }

                    if (double.TryParse(vals[6], out val))
                    {
                        truth.yPos = val;
                    }

                    result = true;
                }
            }

            return(result);
        }
Example #2
0
        public virtual bool TryParse(string xiRawData, out object xoData)
        {
            Assert.NonEmptyString(xiRawData, "xiRawData");

            xoData = null;

            bool result = false;

            //   0      1       2    3    4        5        6         7         8            9
            // % MCR    Time    x    y    x_dot    y_dot    x_ddot    y_ddot    Target_ID    Leg_ID
            if (xiRawData.IndexOf('%') < 0 && xiRawData.IndexOf('#') < 0)
            {
                string [] vals = xiRawData.Split(Text.kWhiteSpace, StringSplitOptions.RemoveEmptyEntries);

                if (vals.Length == 10)
                {
                    xoData = new Data.Truth();

                    Data.Truth truth = xoData as Data.Truth;

                    truth.timestamp = DateTime.Now;

                    double run;

                    if (double.TryParse(vals[0], out run))
                    {
                        truth.run = (int)run;
                    }

                    double time;

                    if (double.TryParse(vals[1], out time))
                    {
                        truth.time = time;
                    }

                    double val;

                    if (double.TryParse(vals[2], out val))
                    {
                        truth.xPos = val;
                    }

                    if (double.TryParse(vals[3], out val))
                    {
                        truth.yPos = val;
                    }

                    if (double.TryParse(vals[4], out val))
                    {
                        truth.xVel = val;
                    }

                    if (double.TryParse(vals[5], out val))
                    {
                        truth.yVel = val;
                    }

                    int targetId;

                    if (int.TryParse(vals[8], out targetId))
                    {
                        truth.targetNumber = targetId;
                    }

                    result = true;
                }
            }

            return(result);
        }
        // 0      1  2  3  4           5          6  7  8         9  10 11
        // truth, 2, 1, 1, 1294751680, -68728.72, 0, 0, -54752.3, 0, 0, <EOL>
        // 0      1  2           3              4     5      6      7      8      9      10     11
        // truth, 2, run_number, target_number, time, x_pos, x_vel, x_acc, y_pos, x_acc, y_acc, <EOL>
        // truth, 2, fields, run_number, target_number, time, x_pos, x_vel, x_acc, y_pos, x_acc, y_acc, <EOL>
        // truth,2,...,<EOT>
        // truth,2,...,<EOS>
        public virtual bool TryParse(string xiRawData, out object xoData)
        {
            Assert.NonEmptyString(xiRawData, "xiRawData");

            xoData = null;

            bool result = false;

            string [] values = xiRawData.Split(new char [] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (values.Length > 0 && values[0].Trim().CompareTo("truth") == 0)
            {
                bool eol = false;
                bool eot = false;
                bool eos = false;

                bool hasFields = values.Length > 2 && values[2].Trim().CompareTo("fields") == 0;

                if (!hasFields)
                {
                    eol = values[values.Length - 1].CompareTo(DataProvider.kEol) == 0;

                    if (!eol)
                    {
                        eot = values[values.Length - 1].CompareTo(DataProvider.kEot) == 0;

                        if (!eot)
                        {
                            eos = values[values.Length - 1].CompareTo(DataProvider.kEos) == 0;
                        }
                    }
                }

                if (eol || eot || eos || hasFields)
                {
                    Data.Truth truth = new Data.Truth();

                    truth.timestamp = DateTime.Now;

                    if (eol || eot)
                    {
                        if (values.Length > 10)
                        {
                            int targetNumber;

                            if (int.TryParse(values[3], out targetNumber))
                            {
                                truth.targetNumber = targetNumber;
                            }

                            if (eol)
                            {
                                long timestamp;

                                if (long.TryParse(values[4], out timestamp))
                                {
                                    truth.rawTimestamp = timestamp;
                                }

                                double value;

                                if (double.TryParse(values[5], out value))
                                {
                                    truth.xPos = value;
                                }

                                if (double.TryParse(values[8], out value))
                                {
                                    truth.yPos = value;
                                }

                                truth.operation = EDataOperation.eUpdateData;
                            }
                            else
                            {
                                truth.operation = EDataOperation.eRemoveData;
                            }

                            xoData = truth;

                            result = true;
                        }
                    }
                    else if (hasFields)
                    {
                        truth.operation = EDataOperation.eAddData;

                        xoData = truth;

                        result = true;
                    }
                    else if (eos)
                    {
                        truth.operation = EDataOperation.eClearData;

                        xoData = truth;

                        result = true;
                    }
                }
            }

            return(result);
        }