Example #1
0
 private void OnAcceptCallBack(IAsyncResult IAsyncResult)
 {
     if ((Socket == null) || (IAsyncResult == null) || (!StateIs(SocketStates.IsAccepting)))
     {
         return;
     }
     try
     {
         ASyncSocket AcceptedSocket = new ASyncSocket(Socket.EndAccept(IAsyncResult), true);
         States.Remove(SocketStates.IsAccepting);
         ListenSocket();
         if (OnAccept != null)
         {
             OnAccept(AcceptedSocket);
         }
     }
     catch (Exception Exception)
     {
         States.Remove(SocketStates.IsAccepting);
         if (OnAcceptFailed != null)
         {
             OnAcceptFailed(Exception);
         }
     }
 }
Example #2
0
 void server_OnAccept(ASyncSocket AcceptedSocket)
 {
     if (this.InvokeRequired)
     {
         dserver_OnAccept d    = new dserver_OnAccept(server_OnAccept);
         object[]         args = { AcceptedSocket };
         this.Invoke(d, args);
     }
     else
     {
         AcceptedEmulator               = AcceptedSocket;
         AcceptedSocket.OnAccept       += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
         AcceptedSocket.OnReceive      += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
         AcceptedSocket.OnSend         += new ASyncSocket.OnSendEventHandler(server_OnSend);
         AcceptedSocket.OnListen       += new ASyncSocket.OnListenEventHandler(server_OnListen);
         AcceptedSocket.OnAcceptFailed += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
         //server.OnConnect += new ASyncSocket.OnConnectEventHandler(server_OnConnect);
         //server.OnConnectFailed += new ASyncSocket.OnConnectFailedEventHandler(server_OnConnectFailed);
         //server.OnDisconnect += new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);
         //server.OnDisconnectFailed += new ASyncSocket.OnDisconnectFailedEventHandler(server_OnDisconnectFailed);
         AcceptedSocket.OnListenFailed  += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
         AcceptedSocket.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
         AcceptedSocket.OnSendFailed    += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
         // AcceptedSocket.Send("STEP\n");
         String command = "\n> Emulator Ready to receive order.\n";
         commandtb.AppendText(command);
         commandtb.ScrollToCaret();
     }
 }
Example #3
0
        public DebugManager()
        {
            InitializeComponent();
            BreakPoints             = new List <BreakPoint>();
            Watchs                  = new List <Watch>();
            server                  = new ASyncSocket();
            server.OnAccept        += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
            server.OnReceive       += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
            server.OnSend          += new ASyncSocket.OnSendEventHandler(server_OnSend);
            server.OnListen        += new ASyncSocket.OnListenEventHandler(server_OnListen);
            server.OnAcceptFailed  += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
            server.OnListenFailed  += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
            server.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
            server.OnSendFailed    += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

            server.Listen(8171);
        }
Example #4
0
        public DebugManager()
        {
            InitializeComponent();
            BreakPoints = new List<BreakPoint>();
            Watchs = new List<Watch>();
            server = new ASyncSocket();
            server.OnAccept += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
            server.OnReceive += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
            server.OnSend += new ASyncSocket.OnSendEventHandler(server_OnSend);
            server.OnListen += new ASyncSocket.OnListenEventHandler(server_OnListen);
            server.OnAcceptFailed += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
            server.OnListenFailed += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
            server.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
            server.OnSendFailed += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

            server.Listen(8171);
        }
Example #5
0
 void server_OnDisconnect(ASyncSocket AcceptedSocket)
 {
     if (this.InvokeRequired)
     {
         dserver_OnDisconnect d    = new dserver_OnDisconnect(server_OnDisconnect);
         object[]             args = { AcceptedSocket };
         this.Invoke(d, args);
     }
     else
     {
         String command = "Simulator disconnected";
         outPutTxtBx.AppendText(command);
         outPutTxtBx.ScrollToCaret();
         this.closeDebuggerSession(true);
         //              Console.WriteLine(Stream);
     }
 }
Example #6
0
        public void closeDebuggerSession(bool changeWorkspace)
        {
            if (AcceptedEmulator != null)
            {
                AcceptedEmulator.Send("EXIT\n");
                AcceptedEmulator.Disconnect();

                //AcceptedEmulator.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                //AcceptedEmulator.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);
                //AcceptedEmulator.OnDisconnect -= new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);
                //AcceptedEmulator.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                //AcceptedEmulator.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
            }

            if (server != null)
            {
                server.OnAccept        -= new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                server.OnReceive       -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                server.OnSend          -= new ASyncSocket.OnSendEventHandler(server_OnSend);
                server.OnListen        -= new ASyncSocket.OnListenEventHandler(server_OnListen);
                server.OnAcceptFailed  -= new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                server.OnListenFailed  -= new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                server.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                server.OnSendFailed    -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
                server.StopListenSocket();
            }

            server = null;

            if (changeWorkspace == true)
            {
                this.closeAllTempFilesFromEditor();
                this.mainForm.cgEeditor1.setCurrentMode("EDITOR");
                this.mainForm.setWorkSpace("GLOBAL");
            }

            if (this.mainForm != null)
            {
                this.mainForm.cgEeditor1.SetDebuggerAtLine(-1);
                setHandLostWithSimulator(true);
                this.mainForm.workspaceViewToolStripMenuItem.Enabled = true;
            }
        }
Example #7
0
        void server_OnReceive(string Stream, ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnReceive d    = new dserver_OnReceive(server_OnReceive);
                object[]          args = { Stream, AcceptedSocket };
                this.Invoke(d, args);
            }
            else
            {
                this.CurrentCommandReceive = "";

                if (!this.CurrentCommandSend.Contains("RUN"))
                {
                    this.setHandLostWithSimulator(true);

                    //Receive All waiting message from the sockets.
                    this.CurrentCommandReceive = new String(Stream.ToCharArray());

                    //Analyse Receive Message
                    AnalyzeStatus(CurrentCommandReceive);

                    //Sync Watch and BreakPoints inside debugState
                    SyncDebuggerState();

                    //Print Receive Message
                    PrintReceiveMessageToConsole(CurrentCommandReceive);

                    //Send LOCALS AND BACKTRACE COMMANDS
                    SendAutomaticBackTraceAndLocalsCommand();
                }
                else
                {
                    this.CurrentCommandSend = "";

                    this.listCommands.Add("LOCALS");
                    this.listCommands.Add("BACKTRACE");
                    //Send LOCALS AND BACKTRACE COMMANDS
                    SendAutomaticBackTraceAndLocalsCommand();
                }
            }
        }
Example #8
0
 private void OnReceiveCallBack(IAsyncResult IAsyncResult)
 {
     if ((!(bool)IsConnected) || (Socket == null) || (IAsyncResult == null) || (!StateIs(SocketStates.IsReceving)))
     {
         return;
     }
     try
     {
         int Bytes = Socket.EndReceive(IAsyncResult);
         States.Remove(SocketStates.IsReceving);
         if (Bytes > 0)
         {
             string Stream = Encoding.Default.GetString(Buffer);
             Array.Clear(Buffer, 0, Buffer.Length - 1);
             if (OnReceive != null)
             {
                 OnReceive(Stream, this);
             }
         }
         else
         {
             Socket sSocket = (Socket)IAsyncResult.AsyncState;
             if (sSocket != null)
             {
                 ASyncSocket AsyncSocket = new ASyncSocket(sSocket, true);
                 AsyncSocket.Disconnect();
             }
         }
         ListenData();
     }
     catch (Exception Exception)
     {
         States.Remove(SocketStates.IsReceving);
         if (OnReceiveFailed != null)
         {
             OnReceiveFailed(Exception);
         }
     }
 }
Example #9
0
        void server_OnAccept(ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnAccept d    = new dserver_OnAccept(server_OnAccept);
                object[]         args = { AcceptedSocket };
                this.Invoke(d, args);
            }
            else
            {
                AcceptedEmulator = AcceptedSocket;

                AcceptedSocket.OnReceive       += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                AcceptedSocket.OnSend          += new ASyncSocket.OnSendEventHandler(server_OnSend);
                AcceptedSocket.OnDisconnect    += new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);
                AcceptedSocket.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                AcceptedSocket.OnSendFailed    += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                String command = "\n> Emulator Ready to receive order.\n";
                outPutTxtBx.AppendText(command);
                outPutTxtBx.ScrollToCaret();


                foreach (DocumentForm doc in this.mainForm.cgEeditor1.dockPanel.Documents)
                {
                    //--- Get all breakPoints
                    foreach (Line line in doc.Scintilla.Lines)
                    {
                        int mask = doc.Scintilla.Markers.GetMarkerMask(line);
                        if (mask != 0)
                        {
                            BreakPoint breakpoint = new BreakPoint(doc.Text, (line.Number + 1).ToString());
                            this.sendAddBreakPointCommand(breakpoint);
                        }
                    }
                }
            }
        }
Example #10
0
        public void initServer()
        {
            if (server == null)
            {
                BreakPoints             = new List <BreakPoint>();
                Watchs                  = new List <Watch>();
                server                  = new ASyncSocket();
                server.OnAccept        += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                server.OnReceive       += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                server.OnSend          += new ASyncSocket.OnSendEventHandler(server_OnSend);
                server.OnListen        += new ASyncSocket.OnListenEventHandler(server_OnListen);
                server.OnAcceptFailed  += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                server.OnListenFailed  += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                server.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                server.OnSendFailed    += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                server.Listen(8171);
            }

            BreakPoints.Clear();
            Watchs.Clear();

            DocumentForm doc = this.mainForm.cgEeditor1.ActiveDocument;

            if (doc != null)
            {
                foreach (Line line in doc.Scintilla.Lines)
                {
                    int mask = doc.Scintilla.Markers.GetMarkerMask(line);
                    if (mask != 0)
                    {
                        BreakPoints.Add(new BreakPoint(doc.Text, line.Number.ToString()));
                    }
                }
            }
        }
Example #11
0
        public void closeDebuggerSession()
        {
            if (this.gpsTimer.Enabled == true) this.gpsTimer.Stop();

            for (int i = 0; i < this.AcceptedClients.Count; i++)
            {
                ASyncSocket client = this.AcceptedClients[i];
                if (client != null)
                {

                    client.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                    client.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);

                    client.OnDisconnect -= new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);

                    client.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                    client.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                    client.Send("EXIT");
                    client.Disconnect();
                }
            }

            this.AcceptedClients.Clear();

            if (server != null)
            {
                server.OnAccept -= new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                server.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                server.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);
                server.OnListen -= new ASyncSocket.OnListenEventHandler(server_OnListen);
                server.OnAcceptFailed -= new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                server.OnListenFailed -= new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                server.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                server.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                server.StopListenSocket();

            }

            server = null;
        }
Example #12
0
        void server_OnDisconnect(ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnDisconnect d = new dserver_OnDisconnect(server_OnDisconnect);
                object[] args = { AcceptedSocket };
                this.Invoke(d);
            }
            else
            {
                String command = "Remote Disconnected";

                //              Console.WriteLine(Stream);
            }
        }
Example #13
0
        void server_OnAccept(ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnAccept d = new dserver_OnAccept(server_OnAccept);
                object[] args = { AcceptedSocket };
                this.Invoke(d, args);
            }
            else
            {
                ASyncSocket newClient = AcceptedSocket;

                this.AcceptedClients.Add(newClient);

                AcceptedSocket.OnReceive += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                AcceptedSocket.OnSend += new ASyncSocket.OnSendEventHandler(server_OnSend);

                AcceptedSocket.OnDisconnect += new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);

                AcceptedSocket.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                AcceptedSocket.OnSendFailed += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                String command = "\n> Emulator Ready to send order.\n";

            }
        }
Example #14
0
        //////////////////////////////////////////
        /// INIT METHODS
        //////////////////////////////////////////
        public void initServer()
        {
            if (this.project != null)
            {
                this.setHandLostWithSimulator(true);
                this.mainForm.workspaceViewToolStripMenuItem.Enabled = false;
                if (server == null)
                {
                    LastCommandReceive      = "";
                    CurrentCommandSend      = "";
                    BreakPoints             = new List <BreakPoint>();
                    Watchs                  = new List <Watch>();
                    server                  = new ASyncSocket();
                    server.OnAccept        += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                    server.OnReceive       += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                    server.OnSend          += new ASyncSocket.OnSendEventHandler(server_OnSend);
                    server.OnListen        += new ASyncSocket.OnListenEventHandler(server_OnListen);
                    server.OnAcceptFailed  += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                    server.OnListenFailed  += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                    server.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                    server.OnSendFailed    += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                    server.Listen("127.0.0.1", 8171);
                }

                BreakPoints.Clear();
                Watchs.Clear();
                this.outPutTxtBx.Clear();
                this.watchesListView.Items.Clear();
                this.localsListView.Items.Clear();
                this.backtraceListView.Items.Clear();

                try
                {
                    this.closeAllTempFilesFromEditor();

                    //Create a debug temp directory
                    string tempFolderPath = this.project.BuildFolderPath + "\\..\\DebugTemp";
                    if (Directory.Exists(tempFolderPath))
                    {
                        Directory.Delete(tempFolderPath, true);
                    }

                    DirectoryInfo info = Directory.CreateDirectory(tempFolderPath);
                    //Copy all Lua source of the build directory
                    foreach (String filePath in Directory.GetFiles(this.project.BuildFolderPath, "*.lua"))
                    {
                        string name = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                        File.Copy(filePath, info.FullName + "\\" + name, true);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error during creation of debug temp files\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                DocumentForm doc = this.mainForm.cgEeditor1.ActiveDocument;
                if (doc != null)
                {
                    foreach (Line line in doc.Scintilla.Lines)
                    {
                        int mask = doc.Scintilla.Markers.GetMarkerMask(line);
                        if (mask != 0)
                        {
                            BreakPoints.Add(new BreakPoint(doc.Text, (line.Number + 1).ToString()));
                        }
                    }
                }
            }
        }
Example #15
0
        //---------------------------------------------------
        //-------------------Methods------------------------
        //---------------------------------------------------
        public void initServer(string ip, int port, RemoteControllerForm remoteControllerForm)
        {
            this.remoteControllerForm = remoteControllerForm;
            if (server != null)
            {
                server.Disconnect();
                server.StopListenSocket();
                server = null;

            }

            if (server == null)
            {
                LastCommandReceive = "";
                CurrentCommandSend = "";

                server = new ASyncSocket();
                server.OnAccept += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                server.OnReceive += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                server.OnSend += new ASyncSocket.OnSendEventHandler(server_OnSend);
                server.OnListen += new ASyncSocket.OnListenEventHandler(server_OnListen);
                server.OnAcceptFailed += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                server.OnListenFailed += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                server.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                server.OnSendFailed += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                server.Listen(ip, port);
            }

            currentBuffer = "";

            // config map
            //this.gMapControl1.MapProvider = GMapProviders.GoogleMap;
            //this.gMapControl1.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
            //this.gMapControl1.MinZoom = 0;
            //this.gMapControl1.MaxZoom = 24;
            //this.gMapControl1.Zoom = 9;

            //this.gMapControl1.Overlays.Add(routes);
            //this.gMapControl1.Overlays.Add(markers);
        }
Example #16
0
        public void closeDebuggerSession(bool changeWorkspace)
        {
            if (AcceptedEmulator != null)
            {

                AcceptedEmulator.Send("EXIT\n");
                AcceptedEmulator.Disconnect();

                //AcceptedEmulator.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                //AcceptedEmulator.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);
                //AcceptedEmulator.OnDisconnect -= new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);
                //AcceptedEmulator.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                //AcceptedEmulator.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

            }

            if (server != null)
            {
                server.OnAccept -= new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                server.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                server.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);
                server.OnListen -= new ASyncSocket.OnListenEventHandler(server_OnListen);
                server.OnAcceptFailed -= new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                server.OnListenFailed -= new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                server.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                server.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
                server.StopListenSocket();
            }

            server = null;

            if (changeWorkspace == true)
            {
                this.closeAllTempFilesFromEditor();
                this.mainForm.cgEeditor1.setCurrentMode("EDITOR");
                this.mainForm.setWorkSpace("GLOBAL");
            }

            if (this.mainForm != null)
            {
                this.mainForm.cgEeditor1.SetDebuggerAtLine(-1);
                setHandLostWithSimulator(true);
                this.mainForm.workspaceViewToolStripMenuItem.Enabled = true;
            }
        }
Example #17
0
        private void analyseReceivedMessage(string stream, ASyncSocket AcceptedSocket)
        {
            if (this.CurrentCommandReceive.StartsWith("EXIT"))
            {
                this.AcceptedClients.Remove(AcceptedSocket);
                AcceptedSocket.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                AcceptedSocket.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);

                AcceptedSocket.OnDisconnect -= new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);

                AcceptedSocket.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                AcceptedSocket.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
                AcceptedSocket.Disconnect();
                AcceptedSocket = null;

                return;
            }

            this.currentBuffer += stream;

            //SPlit the message
            string[] messages = currentBuffer.Split('|');
            for (int i = 0; i < messages.Length; i++)
            {
                string message = messages[i].Replace("\0", "");

                if (message.StartsWith("[EXIT]"))
                {
                    this.AcceptedClients.Remove(AcceptedSocket);
                    AcceptedSocket.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                    AcceptedSocket.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);

                    AcceptedSocket.OnDisconnect -= new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);

                    AcceptedSocket.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                    AcceptedSocket.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
                    AcceptedSocket.Disconnect();
                    AcceptedSocket = null;

                    deserializer = null;
                    return;
                }

                else if(message.StartsWith("[DEVICE]") && message.EndsWith("[END]"))
                {
                    AcceptedSocket.isSimulator = false;

                    int indexMessage = this.currentBuffer.IndexOf(message);
                    if (indexMessage > -1)
                    {
                        this.currentBuffer = this.currentBuffer.Remove(indexMessage, message.Length);
                    }

                    this.currentBuffer.Replace("||", "|");
                    message = message.Replace("[DEVICE]", "").Replace("[END]", "");

                }
                else if (message.StartsWith("[SIMULATOR]") && message.EndsWith("[END]"))
                {
                    AcceptedSocket.isSimulator = true;
                    int indexMessage = this.currentBuffer.IndexOf(message);
                    if (indexMessage > -1)
                    {
                        this.currentBuffer = this.currentBuffer.Remove(indexMessage, message.Length);
                    }

                    this.currentBuffer.Replace("||", "|");
                    message = message.Replace("[SIMULATOR]", "").Replace("[END]", "");

                }
                else
                {
                    continue;
                }

                this.sendEvent(message);
                if (!message.Equals(""))
                {
                    try
                    {
                        Dictionary<string, object> dico = deserializer.Deserialize<Dictionary<string, object>>(message);

                        object eventNameOBJ = null;
                        if (dico.TryGetValue("name", out eventNameOBJ) == true)
                        {
                            string eventNameSTR = eventNameOBJ.ToString();
                            //------------------------------------------------------------------------------------------------------------------------
                            //---------------------------------------------ACCELEROMETER -------------------------------------------------------------
                            //------------------------------------------------------------------------------------------------------------------------
                            if (eventNameSTR.Equals("accelerometer"))
                            {
                                object xGravityOBJ = null;
                                if(dico.TryGetValue("xGravity", out xGravityOBJ) ==true)
                                {
                                    double value = Convert.ToDouble(xGravityOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.acceleromterXTrackBar.Maximum) intValue = this.acceleromterXTrackBar.Maximum;
                                    if (intValue < this.acceleromterXTrackBar.Minimum) intValue = this.acceleromterXTrackBar.Minimum;
                                    this.acceleromterXTrackBar.Value = intValue;

                                }

                                object yGravityOBJ = null;
                                if (dico.TryGetValue("yGravity", out yGravityOBJ) == true)
                                {
                                    double value = Convert.ToDouble(yGravityOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.acceleromterYTrackBar.Maximum) intValue = this.acceleromterYTrackBar.Maximum;
                                    if (intValue < this.acceleromterYTrackBar.Minimum) intValue = this.acceleromterYTrackBar.Minimum;
                                    this.acceleromterYTrackBar.Value = intValue;

                                }

                                object zGravityOBJ = null;
                                if (dico.TryGetValue("zGravity", out zGravityOBJ) == true)
                                {
                                    double value = Convert.ToDouble(zGravityOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.acceleromterZTrackBar.Maximum) intValue = this.acceleromterZTrackBar.Maximum;
                                    if (intValue < this.acceleromterZTrackBar.Minimum) intValue = this.acceleromterZTrackBar.Minimum;
                                    this.acceleromterZTrackBar.Value = intValue;

                                }

                                object xInstantOBJ = null;
                                if (dico.TryGetValue("xInstant", out xInstantOBJ) == true)
                                {
                                    double value = Convert.ToDouble(xInstantOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.accelerometerXInstantTrackBar.Maximum) intValue = this.accelerometerXInstantTrackBar.Maximum;
                                    if (intValue < this.accelerometerXInstantTrackBar.Minimum) intValue = this.accelerometerXInstantTrackBar.Minimum;
                                    this.accelerometerXInstantTrackBar.Value = intValue;

                                }

                                object yInstantOBJ = null;
                                if (dico.TryGetValue("yInstant", out yInstantOBJ) == true)
                                {
                                    double value = Convert.ToDouble(yInstantOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.accelerometerYInstantTrackBar.Maximum) intValue = this.accelerometerYInstantTrackBar.Maximum;
                                    if (intValue < this.accelerometerYInstantTrackBar.Minimum) intValue = this.accelerometerYInstantTrackBar.Minimum;
                                    this.accelerometerYInstantTrackBar.Value = intValue;

                                }

                                object zInstantOBJ = null;
                                if (dico.TryGetValue("zInstant", out zInstantOBJ) == true)
                                {
                                    double value = Convert.ToDouble(zInstantOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.accelerometerZInstantTrackBar.Maximum) intValue = this.accelerometerZInstantTrackBar.Maximum;
                                    if (intValue < this.accelerometerZInstantTrackBar.Minimum) intValue = this.accelerometerZInstantTrackBar.Minimum;
                                    this.accelerometerZInstantTrackBar.Value = intValue;

                                }

                            }

                            //------------------------------------------------------------------------------------------------------------------------
                            //---------------------------------------------COMPASS -------------------------------------------------------------
                            //------------------------------------------------------------------------------------------------------------------------
                            else if (eventNameSTR.Equals("heading"))
                            {
                                object geographicOBJ = null;
                                if (dico.TryGetValue("geographic", out geographicOBJ) == true)
                                {
                                    float value = (float)Convert.ToDouble(geographicOBJ);
                                    this.geographicCompassView.applyAngleFromCompassValues(value);
                                    this.geographicCompassView.refreshGUI();
                                }

                                object magneticOBJ = null;
                                if (dico.TryGetValue("magnetic", out magneticOBJ) == true)
                                {
                                    float value = (float)Convert.ToDouble(magneticOBJ);
                                    this.magneticCompassView.applyAngleFromCompassValues(value);
                                    this.magneticCompassView.refreshGUI();

                                }

                            }

                            //------------------------------------------------------------------------------------------------------------------------
                            //---------------------------------------------GYROSCOPE -------------------------------------------------------------
                            //------------------------------------------------------------------------------------------------------------------------
                            else if (eventNameSTR.Equals("gyroscope"))
                            {
                                object xRotationOBJ = null;
                                if (dico.TryGetValue("xRotation", out xRotationOBJ) == true)
                                {
                                    double value = Convert.ToDouble(xRotationOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.gyroscopeXAxisTrackBar.Maximum) intValue = this.gyroscopeXAxisTrackBar.Maximum;
                                    if (intValue < this.gyroscopeXAxisTrackBar.Minimum) intValue = this.gyroscopeXAxisTrackBar.Minimum;
                                    this.gyroscopeXAxisTrackBar.Value = intValue;

                                }

                                object yRotationOBJ = null;
                                if (dico.TryGetValue("yRotation", out yRotationOBJ) == true)
                                {
                                    double value = Convert.ToDouble(yRotationOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.gyroscopeYAxisTrackBar.Maximum) intValue = this.gyroscopeYAxisTrackBar.Maximum;
                                    if (intValue < this.gyroscopeYAxisTrackBar.Minimum) intValue = this.gyroscopeYAxisTrackBar.Minimum;
                                    this.gyroscopeYAxisTrackBar.Value = intValue;

                                }

                                object zRotationOBJ = null;
                                if (dico.TryGetValue("zRotation", out zRotationOBJ) == true)
                                {
                                    double value = Convert.ToDouble(zRotationOBJ);
                                    int intValue = Convert.ToInt32(value * (float)1000);
                                    if (intValue > this.gyroscopeZAxisTrackBar.Maximum) intValue = this.gyroscopeZAxisTrackBar.Maximum;
                                    if (intValue < this.gyroscopeZAxisTrackBar.Minimum) intValue = this.gyroscopeZAxisTrackBar.Minimum;
                                    this.gyroscopeZAxisTrackBar.Value = intValue;

                                }
                            }

                            //------------------------------------------------------------------------------------------------------------------------
                            //---------------------------------------------KEY -------------------------------------------------------------
                            //------------------------------------------------------------------------------------------------------------------------
                            else if (eventNameSTR.Equals("key"))
                            {
                                //Recuperer le nom du bouton
                                object keyNameOBJ = null;
                                if(dico.TryGetValue("keyName",out keyNameOBJ) == true)
                                {
                                    string keyNameSTR = keyNameOBJ.ToString();

                                    object phaseOBJ = null;
                                    if(dico.TryGetValue("phase",out phaseOBJ) == true)
                                    {
                                        string phaseSTR = phaseOBJ.ToString();
                                        this.keyView1.refreshButtonStateFromRemote(keyNameSTR, phaseSTR);
                                    }

                                }
                            }

                            //------------------------------------------------------------------------------------------------------------------------
                            //---------------------------------------------GPS -------------------------------------------------------------
                            //------------------------------------------------------------------------------------------------------------------------
                            else if (eventNameSTR.Equals("location"))
                            {
                                PointLatLng location = new PointLatLng();
                                 object latitudeOBJ = null;

                                 if (dico.TryGetValue("latitude", out latitudeOBJ) == true)
                                 {
                                     location.Lat= Convert.ToDouble(latitudeOBJ);
                                 }

                                 object longitudeOBJ = null;

                                 if (dico.TryGetValue("longitude", out longitudeOBJ) == true)
                                 {
                                     location.Lng = Convert.ToDouble(longitudeOBJ);
                                 }
                                 if (this.gpsTimer.Enabled == true)
                                     this.stopRouteBt_Click(null, null);

                                 this.googleMapControl1.setRemoteGGPSMarkerLocation(location);

                                 object speedOBJ = null;
                                 if (dico.TryGetValue("speed", out speedOBJ) == true)
                                 {
                                     this.speedTxtBx.Text = Convert.ToDouble(speedOBJ).ToString();
                                 }

                                 object accuracyOBJ = null;
                                 if (dico.TryGetValue("accuracy", out accuracyOBJ) == true)
                                 {
                                     this.accuracyTxtBx.Text = Convert.ToDouble(accuracyOBJ).ToString();
                                 }

                                 object altitudeOBJ = null;
                                 if (dico.TryGetValue("altitude", out altitudeOBJ) == true)
                                 {
                                     this.altitudeTxtBx.Text = Convert.ToDouble(altitudeOBJ).ToString();
                                 }

                                 object timeOBJ = null;
                                 if (dico.TryGetValue("time", out timeOBJ) == true)
                                 {
                                     this.timeTxtBx.Text = Convert.ToDouble(timeOBJ).ToString();
                                 }

                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error MESSAGE : " + ex.Message);
                    }

                }

            }
        }
Example #18
0
        //////////////////////////////////////////
        /// INIT METHODS
        //////////////////////////////////////////
        public void initServer()
        {
            if (this.project != null)
            {
                this.setHandLostWithSimulator(true);
                this.mainForm.workspaceViewToolStripMenuItem.Enabled = false;
                if (server == null)
                {
                    LastCommandReceive = "";
                    CurrentCommandSend = "";
                    BreakPoints = new List<BreakPoint>();
                    Watchs = new List<Watch>();
                    server = new ASyncSocket();
                    server.OnAccept += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                    server.OnReceive += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                    server.OnSend += new ASyncSocket.OnSendEventHandler(server_OnSend);
                    server.OnListen += new ASyncSocket.OnListenEventHandler(server_OnListen);
                    server.OnAcceptFailed += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                    server.OnListenFailed += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                    server.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                    server.OnSendFailed += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                    server.Listen("127.0.0.1", 8171);
                }

                BreakPoints.Clear();
                Watchs.Clear();
                this.outPutTxtBx.Clear();
                this.watchesListView.Items.Clear();
                this.localsListView.Items.Clear();
                this.backtraceListView.Items.Clear();

                try
                {

                    this.closeAllTempFilesFromEditor();

                    //Create a debug temp directory
                    string tempFolderPath = this.project.BuildFolderPath + "\\..\\DebugTemp";
                    if (Directory.Exists(tempFolderPath))
                        Directory.Delete(tempFolderPath, true);

                    DirectoryInfo info = Directory.CreateDirectory(tempFolderPath);
                    //Copy all Lua source of the build directory
                    foreach (String filePath in Directory.GetFiles(this.project.BuildFolderPath, "*.lua"))
                    {
                        string name = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                        File.Copy(filePath, info.FullName + "\\" + name, true);

                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error during creation of debug temp files\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

                DocumentForm doc = this.mainForm.cgEeditor1.ActiveDocument;
                if (doc != null)
                {
                    foreach (Line line in doc.Scintilla.Lines)
                    {
                        int mask = doc.Scintilla.Markers.GetMarkerMask(line);
                        if (mask != 0)
                        {
                            BreakPoints.Add(new BreakPoint(doc.Text, (line.Number + 1).ToString()));
                        }

                    }
                }

            }
        }
Example #19
0
 private void OnAcceptCallBack(IAsyncResult IAsyncResult)
 {
     if ((Socket == null) || (IAsyncResult == null) || (!StateIs(SocketStates.IsAccepting))) return;
     try
     {
         ASyncSocket AcceptedSocket = new ASyncSocket(Socket.EndAccept(IAsyncResult), true);
         States.Remove(SocketStates.IsAccepting);
         ListenSocket();
         if (OnAccept != null)
         {
             OnAccept(AcceptedSocket);
         }
     }
     catch (Exception Exception)
     {
         States.Remove(SocketStates.IsAccepting);
         if (OnAcceptFailed != null)
         {
             OnAcceptFailed(Exception);
         }
     }
 }
Example #20
0
        void server_OnReceive(string Stream,ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnReceive d = new dserver_OnReceive(server_OnReceive);
                object[] args = { Stream, AcceptedSocket };
                this.Invoke(d, args);
            }
            else
            {

                    //Receive All waiting message from the sockets.
                    this.CurrentCommandReceive = new String(Stream.ToCharArray());
                    this.analyseReceivedMessage(this.CurrentCommandReceive, AcceptedSocket);

            }
        }
Example #21
0
        void server_OnReceive(string Stream, ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnReceive d = new dserver_OnReceive(server_OnReceive);
                object[] args = { Stream, AcceptedSocket };
                this.Invoke(d, args);
            }
            else
            {
                this.CurrentCommandReceive = "";

                if (!this.CurrentCommandSend.Contains("RUN"))
                {
                    this.setHandLostWithSimulator(true);

                    //Receive All waiting message from the sockets.
                    this.CurrentCommandReceive = new String(Stream.ToCharArray());

                    //Analyse Receive Message
                    AnalyzeStatus(CurrentCommandReceive);

                    //Sync Watch and BreakPoints inside debugState
                    SyncDebuggerState();

                    //Print Receive Message
                    PrintReceiveMessageToConsole(CurrentCommandReceive);

                    //Send LOCALS AND BACKTRACE COMMANDS
                    SendAutomaticBackTraceAndLocalsCommand();
                }
                else
                {
                    this.CurrentCommandSend = "";

                    this.listCommands.Add("LOCALS");
                    this.listCommands.Add("BACKTRACE");
                    //Send LOCALS AND BACKTRACE COMMANDS
                    SendAutomaticBackTraceAndLocalsCommand();

                }
            }
        }
Example #22
0
 void server_OnDisconnect(ASyncSocket AcceptedSocket)
 {
     if (this.InvokeRequired)
     {
         dserver_OnDisconnect d = new dserver_OnDisconnect(server_OnDisconnect);
         object[] args = {AcceptedSocket };
         this.Invoke(d, args);
     }
     else
     {
         String command = "Simulator disconnected";
         outPutTxtBx.AppendText(command);
         outPutTxtBx.ScrollToCaret();
         this.closeDebuggerSession(true);
         //              Console.WriteLine(Stream);
     }
 }
Example #23
0
        void server_OnAccept(ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnAccept d = new dserver_OnAccept(server_OnAccept);
                object[] args = { AcceptedSocket };
                this.Invoke(d, args);
            }
            else
            {
                AcceptedEmulator = AcceptedSocket;

                AcceptedSocket.OnReceive += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                AcceptedSocket.OnSend += new ASyncSocket.OnSendEventHandler(server_OnSend);
                AcceptedSocket.OnDisconnect += new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);
                AcceptedSocket.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                AcceptedSocket.OnSendFailed += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                String command = "\n> Emulator Ready to receive order.\n";
                outPutTxtBx.AppendText(command);
                outPutTxtBx.ScrollToCaret();

                foreach (DocumentForm doc in this.mainForm.cgEeditor1.dockPanel.Documents)
                {
                    //--- Get all breakPoints
                    foreach (Line line in doc.Scintilla.Lines)
                    {
                        int mask = doc.Scintilla.Markers.GetMarkerMask(line);
                        if (mask != 0)
                        {
                            BreakPoint breakpoint = new BreakPoint(doc.Text, (line.Number + 1).ToString());
                            this.sendAddBreakPointCommand(breakpoint);
                        }

                    }
                }

            }
        }
Example #24
0
        public void initServer()
        {
            if (server == null)
            {
                BreakPoints = new List<BreakPoint>();
                Watchs = new List<Watch>();
                server = new ASyncSocket();
                server.OnAccept += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                server.OnReceive += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                server.OnSend += new ASyncSocket.OnSendEventHandler(server_OnSend);
                server.OnListen += new ASyncSocket.OnListenEventHandler(server_OnListen);
                server.OnAcceptFailed += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                server.OnListenFailed += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                server.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                server.OnSendFailed += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);

                server.Listen(8171);
            }

            BreakPoints.Clear();
            Watchs.Clear();

            DocumentForm doc = this.mainForm.cgEeditor1.ActiveDocument;
            if (doc != null)
            {
                foreach (Line line in doc.Scintilla.Lines)
                {
                    int mask = doc.Scintilla.Markers.GetMarkerMask(line);
                    if (mask != 0)
                    {
                        BreakPoints.Add(new BreakPoint(doc.Text, line.Number.ToString()));
                    }

                }
            }
        }
Example #25
0
        void server_OnAccept(ASyncSocket AcceptedSocket)
        {
            if (this.InvokeRequired)
            {
                dserver_OnAccept d = new dserver_OnAccept(server_OnAccept);
                object[] args = { AcceptedSocket };
                this.Invoke(d, args);
            }
            else
            {

                AcceptedEmulator = AcceptedSocket;
                AcceptedSocket.OnAccept += new ASyncSocket.OnAcceptEventHandler(server_OnAccept);
                AcceptedSocket.OnReceive += new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                AcceptedSocket.OnSend += new ASyncSocket.OnSendEventHandler(server_OnSend);
                AcceptedSocket.OnListen += new ASyncSocket.OnListenEventHandler(server_OnListen);
                AcceptedSocket.OnAcceptFailed += new ASyncSocket.OnAcceptFailedEventHandler(server_OnAcceptFailed);
                //server.OnConnect += new ASyncSocket.OnConnectEventHandler(server_OnConnect);
                //server.OnConnectFailed += new ASyncSocket.OnConnectFailedEventHandler(server_OnConnectFailed);
                //server.OnDisconnect += new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);
                //server.OnDisconnectFailed += new ASyncSocket.OnDisconnectFailedEventHandler(server_OnDisconnectFailed);
                AcceptedSocket.OnListenFailed += new ASyncSocket.OnListenFailedEventHandler(server_OnListenFailed);
                AcceptedSocket.OnReceiveFailed += new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                AcceptedSocket.OnSendFailed += new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
               // AcceptedSocket.Send("STEP\n");
                String command = "\n> Emulator Ready to receive order.\n";
                commandtb.AppendText(command);
                commandtb.ScrollToCaret();
            }
        }
Example #26
0
    private void OnReceiveCallBack(IAsyncResult IAsyncResult)
    {
        if ((!(bool)IsConnected) || (Socket == null) || (IAsyncResult == null) || (!StateIs(SocketStates.IsReceving))) return;
        try
        {
            int Bytes = Socket.EndReceive(IAsyncResult);
            States.Remove(SocketStates.IsReceving);
            if (Bytes > 0)
            {

                string Stream = Encoding.Default.GetString(Buffer);
                Array.Clear(Buffer, 0, Buffer.Length - 1);
                if (OnReceive != null)
                {
                    OnReceive(Stream, this);
                }
            }
            else
            {

                Socket sSocket = (Socket)IAsyncResult.AsyncState;
                if (sSocket != null)
                {
                    ASyncSocket AsyncSocket = new ASyncSocket(sSocket, true);
                    AsyncSocket.Disconnect();

                }

            }
            ListenData();
        }
        catch (Exception Exception)
        {
            States.Remove(SocketStates.IsReceving);
            if (OnReceiveFailed != null)
            {
                OnReceiveFailed(Exception);
            }
        }
    }
Example #27
0
        private void analyseMessage(string stream, ASyncSocket AcceptedSocket)
        {
            if (this.CurrentCommandReceive.Contains("EXIT"))
            {
                this.AcceptedClients.Remove(AcceptedSocket);
                AcceptedSocket.OnReceive -= new ASyncSocket.OnReceiveEventHandler(server_OnReceive);
                AcceptedSocket.OnSend -= new ASyncSocket.OnSendEventHandler(server_OnSend);

                AcceptedSocket.OnDisconnect -= new ASyncSocket.OnDisconnectEventHandler(server_OnDisconnect);

                AcceptedSocket.OnReceiveFailed -= new ASyncSocket.OnReceiveFailedEventHandler(server_OnReceiveFailed);
                AcceptedSocket.OnSendFailed -= new ASyncSocket.OnSendFailedEventHandler(server_OnSendFailed);
                AcceptedSocket.Disconnect();
                AcceptedSocket = null;

                return;
            }

            bool hasFoundAccelerometerValues = false;
            bool hasFoundCompassValues = false;
            bool hasFoundGyroscopeValues = false;
            bool hasFoundGPSValues = false;

            //SPlit the message
            string[] messages = stream.Split('|');
            for (int i = 0; i < messages.Length; i++)
            {
                string message = messages[i];
                string[] commands = message.Split(',');
                for (int j = 0; j < commands.Length; j++)
                {
                    string currentCommand = commands[j];
                    if (currentCommand.Equals("DEVICE"))
                        AcceptedSocket.isSimulator = false;
                    else if (currentCommand.Equals("SIMULATOR"))
                        AcceptedSocket.isSimulator = true;
                    else if (currentCommand.Contains("ACCELEROMETER_XGRAVITY"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        if (keyValue.Length < 2) continue;

                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * (float)1000);
                            if (intValue > this.acceleromterXTrackBar.Maximum) intValue = this.acceleromterXTrackBar.Maximum;
                            if (intValue < this.acceleromterXTrackBar.Minimum) intValue = this.acceleromterXTrackBar.Minimum;
                            this.acceleromterXTrackBar.Value = intValue;
                            hasFoundAccelerometerValues = true;
                        }
                    }
                    else if (currentCommand.Contains("ACCELEROMETER_YGRAVITY"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * (float)1000);
                            if (intValue > this.acceleromterYTrackBar.Maximum) intValue = this.acceleromterYTrackBar.Maximum;
                            if (intValue < this.acceleromterYTrackBar.Minimum) intValue = this.acceleromterYTrackBar.Minimum;
                            this.acceleromterYTrackBar.Value = intValue;
                            hasFoundAccelerometerValues = true;

                        }
                    }
                    else if (currentCommand.Contains("ACCELEROMETER_ZGRAVITY"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * (float)1000);
                            if (intValue > this.acceleromterZTrackBar.Maximum) intValue = this.acceleromterZTrackBar.Maximum;
                            if (intValue < this.acceleromterZTrackBar.Minimum) intValue = this.acceleromterZTrackBar.Minimum;
                            this.acceleromterZTrackBar.Value = intValue;
                            hasFoundAccelerometerValues = true;

                        }
                    }
                    else if (currentCommand.Contains("ACCELEROMETER_XINSTANT"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        if (keyValue.Length < 2) continue;

                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * (float)1000);
                            if (intValue > this.accelerometerXInstantTrackBar.Maximum) intValue = this.accelerometerXInstantTrackBar.Maximum;
                            if (intValue < this.accelerometerXInstantTrackBar.Minimum) intValue = this.accelerometerXInstantTrackBar.Minimum;
                            this.accelerometerXInstantTrackBar.Value = intValue;
                            hasFoundAccelerometerValues = true;
                        }
                    }
                    else if (currentCommand.Contains("ACCELEROMETER_YINSTANT"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * (float)1000);
                            if (intValue > this.accelerometerYInstantTrackBar.Maximum) intValue = this.accelerometerYInstantTrackBar.Maximum;
                            if (intValue < this.accelerometerYInstantTrackBar.Minimum) intValue = this.accelerometerYInstantTrackBar.Minimum;
                            this.accelerometerYInstantTrackBar.Value = intValue;
                            hasFoundAccelerometerValues = true;
                        }
                    }
                    else if (currentCommand.Contains("ACCELEROMETER_ZINSTANT"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * (float)1000);
                            if (intValue > this.accelerometerZInstantTrackBar.Maximum) intValue = this.accelerometerZInstantTrackBar.Maximum;
                            if (intValue < this.accelerometerZInstantTrackBar.Minimum) intValue = this.accelerometerZInstantTrackBar.Minimum;
                            this.accelerometerZInstantTrackBar.Value = intValue;
                            hasFoundAccelerometerValues = true;
                        }
                    }
                    //------------------------COMPASS------------------------------------------------------------------------------------------------------------
                    else if (currentCommand.Contains("COMPASS_GEOGRAPHIC"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            this.geographicCompassView.applyAngleFromCompassValues(value);
                            hasFoundCompassValues = true;
                        }
                    }
                    else if (currentCommand.Contains("COMPASS_MAGNETIC"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            this.magneticCompassView.applyAngleFromCompassValues(value);
                            hasFoundCompassValues = true;
                        }
                    }
                    //------------------------GYROSCOPE------------------------------------------------------------------------------------------------------------
                    else if (currentCommand.Contains("GYROSCOPE_DELTATIME"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            hasFoundGyroscopeValues = true;
                        }
                    }

                    else if (currentCommand.Contains("GYROSCOPE_XROTATION"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value *10);
                            if (intValue > this.gyroscopeXAxisTrackBar.Maximum) intValue = this.gyroscopeXAxisTrackBar.Maximum;
                            if (intValue < this.gyroscopeXAxisTrackBar.Minimum) intValue = this.gyroscopeXAxisTrackBar.Minimum;
                            this.gyroscopeXAxisTrackBar.Value = intValue;
                            hasFoundGyroscopeValues = true;
                        }
                    }

                    else if (currentCommand.Contains("GYROSCOPE_YROTATION"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * 10);
                            if (intValue > this.gyroscopeYAxisTrackBar.Maximum) intValue = this.gyroscopeYAxisTrackBar.Maximum;
                            if (intValue < this.gyroscopeYAxisTrackBar.Minimum) intValue = this.gyroscopeYAxisTrackBar.Minimum;
                            this.gyroscopeYAxisTrackBar.Value = intValue;
                            hasFoundGyroscopeValues = true;
                        }
                    }

                    else if (currentCommand.Contains("GYROSCOPE_ZROTATION"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * 10);
                            if (intValue > this.gyroscopeZAxisTrackBar.Maximum) intValue = this.gyroscopeZAxisTrackBar.Maximum;
                            if (intValue < this.gyroscopeZAxisTrackBar.Minimum) intValue = this.gyroscopeZAxisTrackBar.Minimum;
                            this.gyroscopeZAxisTrackBar.Value = intValue;
                            hasFoundGyroscopeValues = true;
                        }
                    }
                    //------------------------GPS------------------------------------------------------------------------------------------------------------
                    else if (currentCommand.Contains("GYROSCOPE_ZROTATION"))
                    {
                        string[] keyValue = currentCommand.Split('=');
                        float value = -1;
                        if (keyValue.Length < 2) continue;
                        bool res = float.TryParse(keyValue[1].Replace(".", ","), out value);
                        if (res == true)
                        {
                            int intValue = Convert.ToInt32(value * 10);
                            if (intValue > this.gyroscopeZAxisTrackBar.Maximum) intValue = this.gyroscopeZAxisTrackBar.Maximum;
                            if (intValue < this.gyroscopeZAxisTrackBar.Minimum) intValue = this.gyroscopeZAxisTrackBar.Minimum;
                            this.gyroscopeZAxisTrackBar.Value = intValue;
                            hasFoundGyroscopeValues = true;
                        }
                    }
                }

                if (hasFoundAccelerometerValues == true)
                {
                    this.sendAccelerometerEvent();
                    hasFoundAccelerometerValues = false;
                }

                if (hasFoundCompassValues == true)
                {
                    this.sendCompassEvent();
                    hasFoundCompassValues = false;
                    this.magneticCompassView.refreshGUI();
                    this.geographicCompassView.refreshGUI();
                }

                if (hasFoundGyroscopeValues == true)
                {
                    this.sendGyroscopeEvent();
                    hasFoundGyroscopeValues = false;

                }

            }
        }