Exemplo n.º 1
0
Arquivo: Test.cs Projeto: sjmeijer/sdk
        static void test_Client(String host, int port)
        {
            try
              {
            Client client = new Client(host, port);

            Console.WriteLine("Connected to " + host + ":" + port);

            // The Configurable data service requires that we specify a list of channels
            // that we would like to receive.
            if (PortConfigurable == port)
            {
              // Access the global quaternion and calibrated accelerometer streams.
              String xml_definition =
              "<?xml version=\"1.0\"?>" +
              "<configurable>" +
              "<preview><Gq/></preview>" +
              "<sensor><a/></sensor>" +
              "</configurable>";

              if (client.writeData(xml_definition))
              {
            Console.WriteLine("Sent active channel definition to Configurable service");
              }
            }

            if (client.waitForData())
            {
              int sample_count = 0;
              while (true)
              {
            byte[] data = client.readData();
            if ((null == data) || (sample_count++ >= NSample))
            {
              break;
            }

            if (PortPreview == port)
            {
              IDictionary<int, Format.PreviewElement> container = Format.Preview(data);
              foreach (KeyValuePair<int, Format.PreviewElement> itr in container)
              {
                float[] q = itr.Value.getQuaternion(false);
                Console.WriteLine("q(" + itr.Key + ") = (" + q[0] + ", " + q[1] + "i, " + q[2] + "j, " + q[3] + "k)");
              }
            }

            if (PortSensor == port)
            {
              IDictionary<int, Format.SensorElement> container = Format.Sensor(data);
              foreach (KeyValuePair<int, Format.SensorElement> itr in container)
              {
                float[] a = itr.Value.getAccelerometer();
                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
              }
            }

            if (PortRaw == port)
            {
              IDictionary<int, Format.RawElement> container = Format.Raw(data);
              foreach (KeyValuePair<int, Format.RawElement> itr in container)
              {
                short[] a = itr.Value.getAccelerometer();
                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
              }
            }

            if (PortConfigurable == port)
            {
              IDictionary<int, Format.ConfigurableElement> container = Format.Configurable(data);
              foreach (KeyValuePair<int, Format.ConfigurableElement> itr in container)
              {
                Console.Write("data(" + itr.Key + ") = (");
                for (int i=0; i<itr.Value.size(); i++)
                {
                  if (i > 0)
                  {
                    Console.Write(", ");
                  }
                  Console.Write(itr.Value.value(i));
                }
                Console.WriteLine(")");
              }
            }

              }
            }
              }
              catch (Exception e)
              {
            Console.WriteLine(e.ToString());
              }
        }
Exemplo n.º 2
0
        static void test_Client(String host, int port)
        {
            try {
                Client client = new Client(host, port);

                Console.WriteLine("Connected to " + host + ":" + port);

                // The Configurable data service requires that we specify a list of channels
                // that we would like to receive.
                if (PortConfigurable == port)
                {
                    // Access the global quaternion and calibrated accelerometer streams.
                    String xml_definition =
                        "<?xml version=\"1.0\"?>" +
                        "<configurable>" +
                        "<preview><Gq/></preview>" +
                        "<sensor><a/></sensor>" +
                        "</configurable>";

                    if (client.writeData(xml_definition))
                    {
                        Console.WriteLine("Sent active channel definition to Configurable service");
                    }
                }

                if (client.waitForData())
                {
                    int sample_count = 0;
                    while (true)
                    {
                        byte[] data = client.readData();
                        if ((null == data) || (sample_count++ >= NSample))
                        {
                            break;
                        }

                        if (PortPreview == port)
                        {
                            IDictionary <int, Format.PreviewElement> container = Format.Preview(data);
                            foreach (KeyValuePair <int, Format.PreviewElement> itr in container)
                            {
                                float[] q = itr.Value.getQuaternion(false);
                                Console.WriteLine("q(" + itr.Key + ") = (" + q[0] + ", " + q[1] + "i, " + q[2] + "j, " + q[3] + "k)");
                            }
                        }

                        if (PortSensor == port)
                        {
                            IDictionary <int, Format.SensorElement> container = Format.Sensor(data);
                            foreach (KeyValuePair <int, Format.SensorElement> itr in container)
                            {
                                float[] a = itr.Value.getAccelerometer();
                                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
                            }
                        }

                        if (PortRaw == port)
                        {
                            IDictionary <int, Format.RawElement> container = Format.Raw(data);
                            foreach (KeyValuePair <int, Format.RawElement> itr in container)
                            {
                                short[] a = itr.Value.getAccelerometer();
                                Console.WriteLine("a(" + itr.Key + ") = (" + a[0] + ", " + a[1] + ", " + a[2] + ") g");
                            }
                        }

                        if (PortConfigurable == port)
                        {
                            IDictionary <int, Format.ConfigurableElement> container = Format.Configurable(data);
                            foreach (KeyValuePair <int, Format.ConfigurableElement> itr in container)
                            {
                                Console.Write("data(" + itr.Key + ") = (");
                                for (int i = 0; i < itr.Value.size(); i++)
                                {
                                    if (i > 0)
                                    {
                                        Console.Write(", ");
                                    }
                                    Console.Write(itr.Value.value(i));
                                }
                                Console.WriteLine(")");
                            }
                        }
                    }
                }

                client.close();
                client = null;
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }