Пример #1
0
        protected override void onComRead(ComData raw)
        {
            switch (raw.getDataType())
            {
            case ComData.REQUEST:
                Console.WriteLine("Requst: " + raw.GetRequest().ToString());
                break;

            case ComData.STRING:
                Console.WriteLine("String : " + raw.getMessage());
                break;

            case "KeyFrame":
                KeyFrame f = new KeyFrame();
                if (!raw.TryParse(ref f))
                {
                    Console.WriteLine("failed keyframe");
                    return;
                }
                driver.SetTarget(f.cursor);
                break;

            case "JSONableArray":
                JSONableArray <float> a = new JSONableArray <float>(float.Parse);
                if (!raw.TryParse(ref a))
                {
                    Console.WriteLine("failed array");
                    return;
                }

                Angle[] angles = new Angle[6];
                float[] rawF   = a.getArray();
                Array.Copy(Array.ConvertAll(rawF, (x) => { return(new Angle(x)); }),
                           2, angles, 0, angles.Length); // first 2 is time and gripper

                //Console.WriteLine("array: {0}", string.Join<Angle>(", ", angles));
                driver.SetTarget(angles);
                break;

            default:
                Console.WriteLine("defaulted with: " + raw.getDataType());
                break;
            }
        }
Пример #2
0
        public bool Run()
        {
            // Cursor and Keyframes
            // too - move to unit tests
            //ArmCursor ac = new ArmCursor(Vector3.UnitX, Quaternion.Identity);
            //KeyFrame kf = new KeyFrame(ac, (float)Math.PI);
            //JSONBuilder jkf = new JSONBuilder();
            //ComData cd1 = new ComData(kf);
            //cd1.addToJSON(jkf);
            //Console.WriteLine(jkf.ToString());

            //ComData cd1b = new ComData("");
            //cd1b.fillFromJSON(new JSONDecoder(jkf.ToString()));
            //KeyFrame kf2 = new KeyFrame();
            //Console.WriteLine(cd1b.TryParse(ref kf2));

            Angle[] a =
            {
                new Angle(0.1f),
                new Angle(0.2f),
                new Angle(0.3f),
                new Angle(0.4f)
            };
            JSONBuilder           ja = new JSONBuilder();
            JSONableArray <Angle> aa = new JSONableArray <Angle>(a, (str) => { return(new Angle(float.Parse(str))); });
            ComData cd2 = new ComData(aa);

            cd2.addToJSON(ja);
            Console.WriteLine(ja.ToString());

            ComData cd2b = new ComData("");

            cd2b.fillFromJSON(new JSONDecoder(ja.ToString()));
            JSONableArray <Angle> aa2 = new JSONableArray <Angle>((str) => { return(new Angle(float.Parse(str))); });

            Console.WriteLine(cd2b.TryParse(ref aa2));

            return(true);
        }