Beispiel #1
0
        void Update()
        {
            //Grab the newest data from the parser
            DataPoint newdata = Parser.grabData();

            //If some new data is present, modify our distances as needed - otherwise ignore
            if (newdata != null)
            {
                /*//Debug.Log("Non-null data found with tags "+newdata.getFirstId()+" and "+newdata.getSecondId());
                 * //One of the two tags should be the tracked object
                 * if(newdata.getFirstId() != TAG_ID && newdata.getSecondId() != TAG_ID){
                 *      return;
                 * }
                 * //The other tag should be an anchor - find which anchor, and set its distance
                 * for(int i=0;i<rangers.Length;i++){
                 *      if(newdata.getFirstId() == rangers[i].id || newdata.getSecondId() == rangers[i].id){
                 *              rangers[i].setDist(newdata.getDistance());
                 *              break;
                 *      }
                 * }*/
                Ranger firstRanger  = null;
                Ranger secondRanger = null;
                foreach (Ranger ranger in rangers)
                {
                    if (ranger.ID == newdata.getFirstId())
                    {
                        firstRanger = ranger;
                    }
                    else if (ranger.ID == newdata.getSecondId())
                    {
                        secondRanger = ranger;
                    }
                }
                if (firstRanger != null && secondRanger != null)
                {
                    if (firstRanger.anchor && secondRanger.anchor)
                    {
                        firstRanger.setDist(newdata.getSecondId(), newdata.getDistance(), true);
                        secondRanger.setDist(newdata.getFirstId(), newdata.getDistance(), true);
                    }
                    else
                    {
                        if (!firstRanger.anchor)
                        {
                            firstRanger.setDist(newdata.getSecondId(), newdata.getDistance(), false);
                        }
                        if (!secondRanger.anchor)
                        {
                            secondRanger.setDist(newdata.getFirstId(), newdata.getDistance(), false);
                        }
                    }
                }
            }
            //Run one lateration step (handles lack of new data inside)
            runStep();
        }
Beispiel #2
0
        void Update()
        {
            //Grab the newest data from the parser
            DataPoint newdata = Parser.grabData();

            //If some new data is present, modify our distances as needed - otherwise ignore
            if (newdata != null)
            {
                //Debug.Log("Non-null data found with tags "+newdata.getFirstId()+" and "+newdata.getSecondId());
                //One of the two tags should be the tracked object
                if (newdata.getFirstId() != TAG_ID && newdata.getSecondId() != TAG_ID)
                {
                    return;
                }
                //The other tag should be an anchor - find which anchor, and set its distance
                for (int i = 0; i < ancs.Length; i++)
                {
                    if (newdata.getFirstId() == ancs[i].id || newdata.getSecondId() == ancs[i].id)
                    {
                        ancs[i].setDist(newdata.getDistance());
                        break;
                    }
                }
            }
            //Run one lateration step (handles lack of new data inside)
            runStep();
        }
Beispiel #3
0
        private void readString(string datastring)
        {
            //Create a new datapoint
            DataPoint dp = new DataPoint();

            //split string into words array
            string[] term = datastring.Split(new char[] { ',', ':' }, StringSplitOptions.RemoveEmptyEntries);
            for (int j = 0; j < term.Length; j++)
            {
                //Debug.Log(term[j]);
                switch (term[j])
                {
                case TAG_SOURCE_ID:
                    string tag1 = term[j + 2].Trim(new Char[] { '\"', '}' });
                    dp.setFirstId(tag1);
                    break;

                case TAG_DEST_ID:
                    string tag2 = term[j + 2].Trim(new Char[] { '\"', '}' });
                    dp.setSecondId(tag2);
                    break;

                case DIST_VAL_ID:
                    string distStr = term[j + 2].Trim(new Char[] { '}' });
                    //float distNum = float.Parse(distStr);
                    dp.setDistance(distStr, SCALING_FACTOR);
                    break;
                }
            }

            //If we have all four necessary pieces of data
            if (dp.hasAllExceptTime())
            {
                //Log this distance to the log file.
                LogLine(dp.getDistance().ToString());
                //Add this DataPoint to the queue
                dataQueue.Enqueue(dp);
            }
        }