Ejemplo n.º 1
0
 public InputControl()
 {
     serial = GameObject.FindObjectOfType(typeof(SerialParser)) as SerialParser;
     tiltOffset = serial.groundRotation;
     Debug.Log("tiltOffset");
     Debug.Log(tiltOffset);
 }
Ejemplo n.º 2
0
    static void Main(string[] args)
    {
        // Parse command line arguments
        Arguments ar = new Arguments(args);

        if (ar["p1"] == null && ar["p2"] == null)
        {
            Console.WriteLine("Application monitors up to 2 serial ports and sends received data");
            Console.WriteLine("To the Wireshark via named pipe");
            Console.WriteLine();
            Console.WriteLine("Parameters: ");
            Console.WriteLine("   -p1 Serial port #1");
            Console.WriteLine("   -p1b Serial port #1 baudrate (default 19200)");
            Console.WriteLine("   -p1m Serial port #1 match sequence (hex, optional)");
            Console.WriteLine("   -p1t Serial port #1 timeout in us (default 1ms)");
            Console.WriteLine("   -p2 Serial port #2");
            Console.WriteLine("   -p2b Serial port #2 baudrate (default 19200)");
            Console.WriteLine("   -p2m Serial port #2 match sequence (hex, optional)");
            Console.WriteLine("   -p2t Serial port #2 timeout in us (default 1ms)");
            Console.WriteLine("Note: at least one serial port is required, other parameters are optional");

            return;
        }

        // Create serial parsers
        if (ar["p1"] != null)
        {
            int baudrate;
            if (ar["p1b"] == null || !int.TryParse(ar["p1b"], out baudrate))
            {
                baudrate = 19200;
            }

            int timeout_us;
            if (ar["p1t"] == null || !int.TryParse(ar["p1t"], out timeout_us))
            {
                // 1ms default timeout
                timeout_us = 1000;
            }

            List <byte> match = null;
            if (ar["p1m"] != null)
            {
                match = HexStringToList(ar["p1m"]);
            }

            SerialParser sp = new SerialParser(match, ar["p1"], baudrate, timeout_us, _fifo);
            _ser_par.Add(sp);
        }

        if (ar["p2"] != null)
        {
            int baudrate;
            if (ar["p2b"] == null || !int.TryParse(ar["p2b"], out baudrate))
            {
                baudrate = 19200;
            }

            int timeout_us;
            if (ar["p2t"] == null || !int.TryParse(ar["p2t"], out timeout_us))
            {
                // 1ms default timeout
                timeout_us = 1000;
            }

            List <byte> match = null;
            if (ar["p2m"] != null)
            {
                match = HexStringToList(ar["p2m"]);
            }

            SerialParser sp = new SerialParser(match, ar["p2"], baudrate, timeout_us, _fifo);
            _ser_par.Add(sp);
        }

        // Run till ESC
        Console.WriteLine("Press ESC to exit");
        do
        {
            while (!Console.KeyAvailable)
            {
                if (bPipeOpend == false)
                {
                    // create pipe
                    try
                    {
                        _pipe = new NamedPipeServerStream("wireshark", PipeDirection.Out);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Error creating pipe : " + ex.Message);
                        return;
                    }

                    // wait for wireshark to connect to pipe
                    Console.WriteLine("Waiting for connection to wireshark");
                    Console.Write(@"Open wireshark and connect to interface: \\.\pipe\wireshark");
                    _pipe.WaitForConnection();
                    bPipeOpend = true;
                    Console.WriteLine("Wireshark is connected");

                    // connect binary writer to pipe to write binary data into it
                    _writer = new BinaryWriter(_pipe);

                    // Write global header
                    WriteToPipe(BitConverter.GetBytes((UInt32)0xa1b2c3d4)); // Magic number
                    WriteToPipe(BitConverter.GetBytes((UInt16)2));          // Major version
                    WriteToPipe(BitConverter.GetBytes((UInt16)4));          // Minor version
                    WriteToPipe(BitConverter.GetBytes((Int32)0));           // Timezone 0 - UTC
                    WriteToPipe(BitConverter.GetBytes((UInt32)0));          // Timestamp accuracy - unused
                    WriteToPipe(BitConverter.GetBytes((UInt32)65535));      // Maximum lenght of captured packets
                    WriteToPipe(BitConverter.GetBytes((UInt32)147));        // Data Link Type (DLT) - reserved
                    foreach (SerialParser sp in _ser_par)
                    {
                        sp.Open();
                    }
                }
                if (_fifo.Count > 0)
                {
                    Buffer bf = _fifo.Dequeue();
                    WritePacket(bf);
                }
                else
                {
                    Thread.Sleep(1);
                }

                foreach (SerialParser sp in _ser_par)
                {
                    sp.Run();
                }
            }
        } while (Console.ReadKey(true).Key != ConsoleKey.Escape);

        // Closing pipe
        Console.WriteLine();
        Console.Write("Exiting application ..");
        foreach (SerialParser sp in _ser_par)
        {
            sp.Close();
        }
        _writer.Close();
        _pipe.Close();
        Console.WriteLine(".Ok");
    }
Ejemplo n.º 3
0
 void Start()
 {
     serial = GameObject.FindObjectOfType(typeof(SerialParser)) as SerialParser;
     groundRotation = serial.groundRotation;
     StartCoroutine(Calibration());
 }