Ejemplo n.º 1
0
 void ReceiveCallback(IAsyncResult ar)
 {
     Console.WriteLine("rec:s");
     //受信中止
     System.Net.Sockets.UdpClient localClient = (System.Net.Sockets.UdpClient)ar.AsyncState;
     System.Net.IPEndPoint        remoteEP    = null;
     byte[] recieveData;
     try
     {
         recieveData = localClient.EndReceive(ar, ref remoteEP);
         UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
         dec.Source = recieveData;
         if (dec.get_bool())
         {
             //アクセス要求が来たら返信
             this.MakeNewLocalClient(remoteEP);
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         return;
     }
     //受信再開
     localClient.BeginReceive(ReceiveCallback, localClient);
 }
Ejemplo n.º 2
0
 public ClientHostReceive(byte[] data)
 {
     this.clientstatus = new CIPCServer.ClientStatus();
     UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec =new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
     dec.Source = data;
     if (dec.get_int() == 1)
     {
         this.clientstatus.FPS = dec.get_int();
         switch (dec.get_int())
         {
             case 2:
                 this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.Sender;
                 break;
             case 3:
                 this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.Receiver;
                 break;
             case 4:
                 this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.Both;
                 break;
             case 15:
                 this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.DirectConnect;
                 break;
             default:
                 this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.NoInit;
                 break;
         }
         this.clientstatus.Name = dec.get_string();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="localPort">自分のポート</param>
        public RemoteHost(int localPort, DebugWindow debugwindow, TerminalConnection.TerminalConnection TC)
        {
            try
            {
                this.UP_Cliant  = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(localPort);
                this.UP_Encoder = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.UP_Decoder = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.id         = localPort;

                this.CTS    = new CancellationTokenSource();
                this.mytask = new Task(() => this.Main_Task(), CTS.Token);

                this.mytask.Start();
                this.fpsa = new FPSAdjuster.FPSAdjuster();

                this.debugwindow          = debugwindow;
                this.debugwindow.DebugLog = "[Port:" + localPort.ToString() + "]受信を開始します";

                this.TC = TC;
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        protected override void Close_add()
        {
            this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.serverIP, this.serverPort, this.myPort);
            this.enc        = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc            += SETTINGS.ConnectionCommands.GREETING.END;
            enc            += this.remotePort;
            this.udp_client.Send(this.enc.data);

            dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            while (true)
            {
                if (this.udp_client.Received_Data != null)
                {
                    dec.Source = this.udp_client.Received_Data;
                    break;
                }
            }
            if (dec.get_int() == SETTINGS.ConnectionCommands.GREETING.END)
            {
            }
            else
            {
            }
            this.udp_client.Close();
            this.udp_client = null;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 接続を切断します。
        /// </summary>
        public void disconnect()
        {
            try
            {
                this.debugwindow.DebugLog = "[Port:" + this.ID.ToString() + "]切断します.";
                UP_Cliant.Close();
                this.data = null;
                if (this.connect_host != null)
                {
                    this.connect_host.connect_host = null;
                    this.connect_host = null;
                }

                CTS.Cancel();
                isConnected     = false;
                this.UP_Encoder = null;
                this.UP_Decoder = null;

                this.UP_Cliant = null;

                this.DataReceived = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "接続の切断に失敗しました。");
            }
            finally
            {
            }
        }
Ejemplo n.º 6
0
        public ClientHostReceive(byte[] data)
        {
            this.clientstatus = new CIPCServer.ClientStatus();
            UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = data;
            if (dec.get_int() == 1)
            {
                this.clientstatus.FPS = dec.get_int();
                switch (dec.get_int())
                {
                case 2:
                    this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.Sender;
                    break;

                case 3:
                    this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.Receiver;
                    break;

                case 4:
                    this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.Both;
                    break;

                case 15:
                    this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.DirectConnect;
                    break;

                default:
                    this.clientstatus.Mode = CIPCServer.ClientStatus.MODE.NoInit;
                    break;
                }
                this.clientstatus.Name = dec.get_string();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="localPort">自分のポート</param>
        public RemoteHost(int localPort, DebugWindow debugwindow/*, TerminalConnection.TerminalConnection TC*/)
        {
            try
            {
                this.UP_Cliant = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(localPort);
                this.UP_Encoder = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.UP_Decoder = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.id = localPort;

                this.CTS = new CancellationTokenSource();
                this.mytask = new Task(() => this.Main_Task(), CTS.Token);

                this.mytask.Start();
                this.fpsa = new FPSAdjuster.FPSAdjuster();

                this.debugwindow = debugwindow;
                this.debugwindow.DebugLog = "[Port:" + localPort.ToString() + "]受信を開始します";

                //this.TC = TC;
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
        void DataReceived(object sender, byte[] e)
        {
            Console.WriteLine("recieved1");

            UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();

            dec.Source = e;
            int i = dec.get_int();

            switch (i)
            {
            case 0:
                this.calibMode = Calibration._calibMode.zero; this.IsCalib = true; break;

            case 1:
                this.calibMode = Calibration._calibMode.x; this.IsCalib = true; break;

            case 2:
                this.calibMode = Calibration._calibMode.z; this.IsCalib = true; break;

            case 3: break;

            case 4: break;
            }
            if (i == 0)
            {
                Console.WriteLine("change");
                this.IsCalib = true;
            }

            this.IsCalib = true;
            Console.WriteLine("recieved2");
        }
Ejemplo n.º 9
0
 //アクセス要求
 void AccessReceiveCallback(IAsyncResult ar)
 {
     Console.WriteLine("rec:c");
     //受信中止
     System.Net.Sockets.UdpClient client   = (System.Net.Sockets.UdpClient)ar.AsyncState;
     System.Net.IPEndPoint        remoteEP = null;
     byte[] recieveData;
     try
     {
         recieveData = client.EndReceive(ar, ref remoteEP);
         UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
         dec.Source = recieveData;
         bool state = dec.get_bool();
         if (state)
         {
             //サーバーが返したポートに接続しなおし
             this.MakeNewClient(dec.get_int(), dec.get_int());
             this.IsAccessed = true;
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         return;
     }
     //受信再開
     if (!this.IsAccessed)
     {
         client.BeginReceive(this.AccessReceiveCallback, client);
     }
 }
Ejemplo n.º 10
0
        public MainCommunication(byte[] data)
        {
            this.connection = new Connection();

            UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = data;
            switch (dec.get_int())
            {
            case 1:
                this.connection_command = ConnectionCommand.Demand;
                break;

            case 9:
                this.connection_command = ConnectionCommand.End;
                this.DeletePort         = dec.get_int();
                break;

            case 5:
                this.connection_command    = ConnectionCommand.Connect;
                this.connection.SenderID   = dec.get_int();
                this.connection.ReceiverID = dec.get_int();
                break;

            case 6:
                this.connection_command    = ConnectionCommand.DisConnect;
                this.connection.SenderID   = dec.get_int();
                this.connection.ReceiverID = dec.get_int();
                break;

            case 11:
                this.connection_command    = ConnectionCommand.ConnectByServerPort;
                this.connection.SenderID   = dec.get_int();
                this.connection.ReceiverID = dec.get_int();
                break;

            case 12:
                this.connection_command    = ConnectionCommand.DisconnectByServerPort;
                this.connection.SenderID   = dec.get_int();
                this.connection.ReceiverID = dec.get_int();
                break;

            case 13:
                this.connection_command    = ConnectionCommand.ConnectByUserPort;
                this.connection.SenderID   = dec.get_int();
                this.connection.ReceiverID = dec.get_int();
                break;

            case 14:
                this.connection_command    = ConnectionCommand.DisconnectByUserPort;
                this.connection.SenderID   = dec.get_int();
                this.connection.ReceiverID = dec.get_int();
                break;

            default:
                this.connection_command = ConnectionCommand.error;
                break;
            }
        }
Ejemplo n.º 11
0
        public RemoteHostServer()
        {
            try
            {
                client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }

            try
            {
                this.enc     = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.dec     = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.LstPort = new List <int>();

                mytask = new Task(() => this.MAIN_TASK());
                mytask.Start();
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
            try
            {
                #region create remotehost servers list and one remotehost server
                this.List_remotehost = new List <RemoteHost>();
                #endregion
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        protected override void Connect_Sender_add()
        {
            this.enc  = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            this.enc += SETTINGS.ConnectionCommands.GREETING.DEMANDS;
            this.enc += this.fps;
            this.enc += SETTINGS.ConnectionCommands.MODE.SEND;
            this.enc += this.name;
            this.udp_client.Send(this.enc.data);

            dec        = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = this.udp_client.Recieve();
        }
Ejemplo n.º 13
0
        public MainCommunication(byte[] data)
        {
            this.connection = new Connection();

            UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = data;
            switch(dec.get_int())
            {
                case 1:
                    this.connection_command = ConnectionCommand.Demand;
                    break;
                case 9:
                    this.connection_command = ConnectionCommand.End;
                    this.DeletePort = dec.get_int();
                    break;
                case 5:
                    this.connection_command = ConnectionCommand.Connect;
                    this.connection.SenderID = dec.get_int();
                    this.connection.ReceiverID = dec.get_int();
                    break;
                case 6:
                    this.connection_command = ConnectionCommand.DisConnect;
                    this.connection.SenderID = dec.get_int();
                    this.connection.ReceiverID = dec.get_int();
                    break;
                case 11:
                    this.connection_command = ConnectionCommand.ConnectByServerPort;
                    this.connection.SenderID = dec.get_int();
                    this.connection.ReceiverID = dec.get_int();
                    break;
                case 12:
                    this.connection_command = ConnectionCommand.DisconnectByServerPort;
                    this.connection.SenderID = dec.get_int();
                    this.connection.ReceiverID = dec.get_int();
                    break;
                case 13:
                    this.connection_command = ConnectionCommand.ConnectByUserPort;
                    this.connection.SenderID = dec.get_int();
                    this.connection.ReceiverID = dec.get_int();
                    break;
                case 14:
                    this.connection_command = ConnectionCommand.DisconnectByUserPort;
                    this.connection.SenderID = dec.get_int();
                    this.connection.ReceiverID = dec.get_int();
                    break;
                default:
                    this.connection_command = ConnectionCommand.error;
                    break;
            }
        }
Ejemplo n.º 14
0
        protected override void Connect_add()
        {
            this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc += SETTINGS.ConnectionCommands.GREETING.DEMANDS;
            this.udp_client.Send(enc.data);

            dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = this.udp_client.Recieve();
            if (this.dec.get_int() != SETTINGS.ConnectionCommands.REPLY.OK)
            {
                throw new Exception("接続失敗");
            }
            this.udp_client.Close();
            this.udp_client = null;
            Thread.Sleep(100);
            this.remotePort = dec.get_int();
        }
Ejemplo n.º 15
0
        protected override void Connect_add()
        {
            this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc     += SETTINGS.ConnectionCommands.GREETING.DEMANDS;
            this.udp_client.Send(enc.data);

            dec        = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = this.udp_client.Recieve();
            if (this.dec.get_int() != SETTINGS.ConnectionCommands.REPLY.OK)
            {
                throw new Exception("接続失敗");
            }
            this.udp_client.Close();
            this.udp_client = null;
            Thread.Sleep(100);
            this.remotePort = dec.get_int();
        }
Ejemplo n.º 16
0
        void client_DataReceived(object sender, byte[] e)
        {
            UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = e;
            int id = dec.get_int();

            if (id < this.Datalength / this.DPP - 1)
            {
                byte[] data = dec.get_bytes(this.DPP);
                Array.Copy(data, 0, this.ReceiveData, id * this.DPP, data.Length);
            }
            else
            {
                byte[] data = dec.get_bytes((int)this.Datalength % this.DPP);
                Array.Copy(data, 0, this.ReceiveData, id * this.DPP, data.Length);
            }
        }
Ejemplo n.º 17
0
        protected override void Connect_Sender_add()
        {
            this.enc  = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            this.enc += SETTINGS.ConnectionCommands.GREETING.DEMANDS;
            this.enc += this.fps;
            this.enc += SETTINGS.ConnectionCommands.MODE.SEND;
            this.enc += this.name;
            this.udp_client.Send(this.enc.data);

            dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            while (true)
            {
                if (this.udp_client.Received_Data != null)
                {
                    dec.Source = this.udp_client.Received_Data;
                    break;
                }
            }
        }
Ejemplo n.º 18
0
        protected override void Close_add()
        {
            this.udp_client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(this.remoteIP, this.serverPort, this.myPort);
            this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            enc += SETTINGS.ConnectionCommands.GREETING.END;
            enc += this.remotePort;
            this.udp_client.Send(this.enc.data);

            dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = this.udp_client.Recieve();
            if (dec.get_int() == SETTINGS.ConnectionCommands.GREETING.END)
            {

            }
            else
            {

            }
            this.udp_client.Close();
            this.udp_client = null;
        }
Ejemplo n.º 19
0
        public RemoteHostServer()
        {
            try
            {
                client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }

            try
            {
                this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.LstPort = new List<int>();

                mytask = new Task(() => this.MAIN_TASK());
                mytask.Start();
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
            try
            {
                #region create remotehost servers list and one remotehost server
                this.List_remotehost = new List<RemoteHost>();
                #endregion
            }
            catch(Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 20
0
        //アクセス要求
        void AccessReceiveCallback(IAsyncResult ar)
        {
            Console.WriteLine("rec:c");
            //受信中止
            System.Net.Sockets.UdpClient client = (System.Net.Sockets.UdpClient)ar.AsyncState;
            System.Net.IPEndPoint remoteEP = null;
            byte[] recieveData;
            try
            {
                recieveData = client.EndReceive(ar, ref remoteEP);
                UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                dec.Source = recieveData;
                bool state = dec.get_bool();
                if (state)
                {
                    //サーバーが返したポートに接続しなおし
                    this.MakeNewClient(dec.get_int(), dec.get_int());
                    this.IsAccessed = true;
                }

            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return;
            }
            //受信再開
            if (!this.IsAccessed)
            {
                client.BeginReceive(this.AccessReceiveCallback, client);
            }
        }
Ejemplo n.º 21
0
        private void Button_Main_Click(object sender, RoutedEventArgs e)
        {
            if (this.TextBlock_Main.Text == "")
            {
                return;
            }
            try
            {
                if (!this.TextBlock_Main.Text.Contains("scd"))
                {
                    throw new Exception("\"scd\"ファイルのみ対応しています。");
                }
                var reader = new BinaryReader(File.OpenRead(this.TextBlock_Main.Text));
                var size   = reader.BaseStream.Length;
                var writer = new StreamWriter(this.TextBlock_Main.Text.Replace("scd", "csv"));


                if (size < 8)
                {
                    throw new Exception("ファイルに正常な書き込みが行われていません。");
                }
                //First frame number
                try
                {
                    while (true)
                    {
                        //header
                        var CurrentFrame = reader.ReadUInt32();
                        writer.Write(CurrentFrame);
                        writer.Write(",");

                        var time = reader.ReadInt64();
                        writer.Write(time);
                        writer.Write(",");
                        var data = reader.ReadBytes(reader.ReadInt32());

                        //Decorder
                        var dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                        dec.Source = data;
                        Console.WriteLine(dec.Length);

                        var MoP = (byte)dec.get_byte();//max of person

                        Console.WriteLine(MoP.ToString());
                        writer.Write(MoP);
                        writer.Write(",");
                        var NoP = (byte)dec.get_byte();//number of person]
                        writer.Write(NoP);
                        writer.Write(",");

                        for (int i = 0; i < NoP; i++)
                        {
                            var NoB = (byte)dec.get_byte();//number of person]
                            writer.Write(NoB);
                            writer.Write(",");
                            for (int j = 0; j < NoB; j++)
                            {
                                var Dimension = dec.get_byte();
                                writer.Write(Dimension);
                                writer.Write(",");
                                var Px = dec.get_float();
                                writer.Write(Px);
                                writer.Write(",");
                                var Py = dec.get_float();
                                writer.Write(Py);
                                writer.Write(",");
                                var Pz = dec.get_float();
                                writer.Write(Pz);
                                writer.Write(",");

                                var Rx = dec.get_float();
                                writer.Write(Rx);
                                writer.Write(",");
                                var Ry = dec.get_float();
                                writer.Write(Ry);
                                writer.Write(",");
                                var Rz = dec.get_float();
                                writer.Write(Rz);
                                writer.Write(",");
                                var Rw = dec.get_float();
                                writer.Write(Rw);
                                writer.Write(",");
                                var ts = dec.get_byte();
                                writer.Write(ts);
                                writer.Write(",");
                            }
                        }
                        writer.Write("\n");
                    }
                }
                catch (Exception ex)
                {
                    writer.Write(ex.Message);
                }
                finally
                {
                    reader.Close();
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 22
0
 void client_DataReceived(object sender, byte[] e)
 {
     UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
     dec.Source = e;
     int id = dec.get_int();
     if (id < this.Datalength / this.DPP - 1)
     {
         byte[] data = dec.get_bytes(this.DPP);
         Array.Copy(data, 0, this.ReceiveData, id * this.DPP, data.Length);
     }
     else
     {
         byte[] data = dec.get_bytes((int)this.Datalength % this.DPP);
         Array.Copy(data, 0, this.ReceiveData, id * this.DPP, data.Length);
     }
 }
Ejemplo n.º 23
0
        public RemoteHostServer()
        {
            try
            {
                this.Eventer = new TerminalConnectionSettings.CommandEventer();
                client = new UDP_PACKETS_CLIANT.UDP_PACKETS_CLIANT(myPort);
                this.remoteOperator = new RemoteOperater(client);
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }

            try
            {
                this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
                this.dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                this.LstPort = new List<int>();

            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
            try
            {
                #region create remotehost servers list and one remotehost server
                this.List_remotehost = new List<RemoteHost>();
                #endregion
                client.DataReceived += client_DataReceived;
            }
            catch (Exception ex)
            {
                while (true)
                {
                    myDialog dialog = new myDialog(ex.Message);
                    if (dialog.ShowDialog() == true)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 接続を切断します。
        /// </summary>
        public void disconnect()
        {
            try
            {
                this.debugwindow.DebugLog = "[Port:" + this.ID.ToString() + "]切断します.";
                UP_Cliant.Close();
                this.data = null;
                if (this.connect_host != null)
                {
                    this.connect_host.connect_host = null;
                    this.connect_host = null;
                }

                CTS.Cancel();
                isConnected = false;
                this.UP_Encoder = null;
                this.UP_Decoder = null;

                this.UP_Cliant = null;

                this.DataReceived = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "接続の切断に失敗しました。");
            }
            finally
            {
            }
        }
Ejemplo n.º 25
0
 void CipcSyncClient_DataReceived(object sender, byte[] e)
 {
     UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
     dec.Source = e;
     var str = dec.get_string();
     switch (str)
     {
         case "START":
             this.Button_ALL_REC.Dispatcher.BeginInvoke(new Action(() =>
             {
                 this.Button_ALL_REC_Click(this, new RoutedEventArgs());
                 this.Button_ALL_START_Click(this, new RoutedEventArgs());
             }));
             break;
         case "STOP":
             this.Button_ALL_STOP.Dispatcher.BeginInvoke(new Action(() =>
             {
                 this.Button_ALL_RESET_Click(this, new RoutedEventArgs());
             }));
             break;
         default:
             Console.WriteLine("Invalid operation.");
             break;
     }
 }
Ejemplo n.º 26
0
        protected override void Connect_Sender_add()
        {
            this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            this.enc += SETTINGS.ConnectionCommands.GREETING.DEMANDS;
            this.enc += this.fps;
            this.enc += SETTINGS.ConnectionCommands.MODE.SEND;
            this.enc += this.name;
            this.udp_client.Send(this.enc.data);

            dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            dec.Source = this.udp_client.Recieve();
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ar"></param>
        private void ReceiveCallBack_SKST(IAsyncResult ar)
        {
            try
            {
                if (this.SKST.udplient != null)
                {
                    this.SKST.data = this.SKST.udplient.EndReceive(ar, ref this.SKST.RemoteEP);
                    UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                    dec.Source = this.SKST.data;
                    this.CS.dx = (-1) * dec.get_float();
                    this.CS.dy = dec.get_float();
                    this.CS.dz = dec.get_float();
                    this.CS.ry = dec.get_float() * (float)Math.PI / 180;


                    //Console.WriteLine(dec.get_float().ToString() + dec.get_float().ToString() + dec.get_float().ToString() + dec.get_float().ToString());
                    this.SKST.udplient.BeginReceive(ReceiveCallBack_SKST, this.SKST.udplient);
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                this.SKST.udplient.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 28
0
        protected override void Connect_Sender_add()
        {
            this.enc = new UDP_PACKETS_CODER.UDP_PACKETS_ENCODER();
            this.enc += SETTINGS.ConnectionCommands.GREETING.DEMANDS;
            this.enc += this.fps;
            this.enc += SETTINGS.ConnectionCommands.MODE.SEND;
            this.enc += this.name;
            this.udp_client.Send(this.enc.data);

            dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
            while (true)
            {
                if (this.udp_client.Received_Data != null)
                {
                    dec.Source = this.udp_client.Received_Data;
                    break;
                }
            }
        }
Ejemplo n.º 29
0
        private void DataConvert_SKST_tcp(byte[] data)
        {
            try
            {
                Console.WriteLine(data.Length);
                UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER(data);

                string str = dec.get_string();
                Console.WriteLine(str);
                if (str == "LightCallib_Zero")
                {
                    this.Is_CallibPointZero = true;
                }
                else if (str == "LightCallib_X")
                {
                    this.Is_CallibPointX = true;
                }
                else if (str == "LightCallib_Z")
                {
                    this.Is_CallibPointZ = true;
                }
                else if (str == "LightCallib_Calc")
                {
                    Callibration.CallibrationPallameter cp = new Callibration.CallibrationPallameter();
                    cp = this.callibration.Callcurate();
                    this.CS = cp;
                }
                else if (str == "KinectStop")
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.KinectStop();
                    }));
                }
                else if (str == "KinectStart")
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.KinectLunch();
                    }));
                }
                else if (str == "Capture")
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.Create3DmodelandSendSKST();
                    }));
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 30
0
 void ReceiveCallback(IAsyncResult ar)
 {
     Console.WriteLine("rec:s");
     //受信中止
     System.Net.Sockets.UdpClient localClient = (System.Net.Sockets.UdpClient)ar.AsyncState;
     System.Net.IPEndPoint remoteEP = null;
     byte[] recieveData;
     try
     {
         recieveData = localClient.EndReceive(ar, ref remoteEP);
         UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
         dec.Source = recieveData;
         if (dec.get_bool())
         {
             //アクセス要求が来たら返信
             this.MakeNewLocalClient(remoteEP);
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         return;
     }
     //受信再開
     localClient.BeginReceive(ReceiveCallback, localClient);
 }
        private void Button_Main_Click(object sender, RoutedEventArgs e)
        {
            if (this.TextBlock_Main.Text == "") return;
            try
            {
                if (!this.TextBlock_Main.Text.Contains("scd"))
                {
                    throw new Exception("\"scd\"ファイルのみ対応しています。");
                }
                var reader = new BinaryReader(File.OpenRead(this.TextBlock_Main.Text));
                var size = reader.BaseStream.Length;
                var writer = new StreamWriter(this.TextBlock_Main.Text.Replace("scd", "csv"));

                if (size < 8)
                {
                    throw new Exception("ファイルに正常な書き込みが行われていません。");
                }
                //First frame number
                try
                {
                    while (true)
                    {
                        //header
                        var CurrentFrame = reader.ReadUInt32();
                        writer.Write(CurrentFrame);
                        writer.Write(",");

                        var time = reader.ReadInt64();
                        writer.Write(time);
                        writer.Write(",");
                        var data = reader.ReadBytes(reader.ReadInt32());

                        //Decorder
                        var dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
                        dec.Source = data;
                        Console.WriteLine(dec.Length);

                        var MoP = (byte)dec.get_byte();//max of person

                        Console.WriteLine(MoP.ToString());
                        writer.Write(MoP);
                        writer.Write(",");
                        var NoP = (byte)dec.get_byte();//number of person]
                        writer.Write(NoP);
                        writer.Write(",");

                        for (int i = 0; i < NoP; i++)
                        {
                            var NoB = (byte)dec.get_byte();//number of person]
                            writer.Write(NoB);
                            writer.Write(",");
                            for (int j = 0; j < NoB; j++ )
                            {
                                var Dimension = dec.get_byte();
                                writer.Write(Dimension);
                                writer.Write(",");
                                var Px = dec.get_float();
                                writer.Write(Px);
                                writer.Write(",");
                                var Py = dec.get_float();
                                writer.Write(Py);
                                writer.Write(",");
                                var Pz = dec.get_float();
                                writer.Write(Pz);
                                writer.Write(",");

                                var Rx = dec.get_float();
                                writer.Write(Rx);
                                writer.Write(",");
                                var Ry = dec.get_float();
                                writer.Write(Ry);
                                writer.Write(",");
                                var Rz = dec.get_float();
                                writer.Write(Rz);
                                writer.Write(",");
                                var Rw = dec.get_float();
                                writer.Write(Rw);
                                writer.Write(",");
                                var ts = dec.get_byte();
                                writer.Write(ts);
                                writer.Write(",");
                            }

                        }
                        writer.Write("\n");

                    }
                }
                catch (Exception ex)
                {
                    writer.Write(ex.Message);
                }
                finally
                {
                    reader.Close();
                    writer.Close();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        void DataReceived(object sender, byte[] e)
        {
            Console.WriteLine("recieved1");

            UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();

            dec.Source = e;
            int i = dec.get_int();

            switch (i)
            {
                case 0:
                    this.calibMode = Calibration._calibMode.zero; this.IsCalib = true; break;
                case 1:
                    this.calibMode = Calibration._calibMode.x; this.IsCalib = true; break;
                case 2:
                    this.calibMode = Calibration._calibMode.z; this.IsCalib = true; break;
                case 3: break;
                case 4: break;

            }
            if (i == 0)
            {
                Console.WriteLine("change");
                this.IsCalib = true;

            }

            this.IsCalib = true;
            Console.WriteLine("recieved2");
        }
Ejemplo n.º 33
0
 void client_DataReceived(object sender, byte[] e)
 {
     UDP_PACKETS_CODER.UDP_PACKETS_DECODER dec = new UDP_PACKETS_CODER.UDP_PACKETS_DECODER();
     dec.Source = e;
     this.Eventer.Handle(dec.get_string());
     this.ReceivedTime = System.DateTime.Now;
 }