示例#1
0
        public SDBResponse Send(SDBRequest request)
        {
            SDBResponse response = new DebugBridge.SDBResponse();

            if (!this.sdbsocket.Write(request.Request))
            {
                return(response);
            }

            byte[] reply = new byte[4];
            if (!this.sdbsocket.Read(reply))
            {
                return(response);
            }

            response.IOSuccess = true;
            if (IsOkay(reply))
            {
                response.Okay = true;
            }
            else if (IsFail(reply))
            {
                response.Message = GetFailMessage();
                response.Okay    = false;
            }
            else
            {
                response.Okay = false;
            }

            return(response);
        }
示例#2
0
        private static SDBConnection EstablishConnection(string serialNumber)
        {
            SDBConnection sdbConnection = SDBConnection.Create();

            if (sdbConnection == null)
            {
                Debug.WriteLine("Failed to establish SDB connection.");
                return(null);
            }

            string      msgForConnection = "host:transport:" + serialNumber;
            SDBRequest  request          = SDBConnection.MakeRequest(msgForConnection);
            SDBResponse response         = sdbConnection.Send(request);

            if (response.IOSuccess && response.Okay)
            {
                return(sdbConnection);
            }
            else
            {
                Debug.WriteLine($"Failed to get SDB response. {response.Message}");
                sdbConnection.Close();
                return(null);
            }
        }
示例#3
0
        private static bool SendMsg(SDBConnection sdbConnection, string protocol, string cmd, string[] args)
        {
            string msg = protocol + SDBProtocol.delemeter + cmd;

            foreach (string arg in args)
            {
                msg += (SDBProtocol.delemeter + arg);
            }

            SDBRequest  request  = SDBConnection.MakeRequest(msg);
            SDBResponse response = sdbConnection.Send(request);

            if (!response.IOSuccess || !response.Okay)
            {
                Debug.WriteLine($"Failed to get SDB response. {response.Message}");
                sdbConnection.Close();
                return(false);
            }

            return(true);
        }
示例#4
0
        private DeviceMonitorResult DeviceChangeDetectTask()
        {
            DeviceMonitorResult ret = DeviceMonitorResult.CanceledByUser;

            this.sdbconnection = SDBConnection.Create();
            if (this.sdbconnection == null)
            {
                OutputDeviceInfoMsg("Failed to connect to SDB Server. ");
                this.taskCancelSource.Cancel();
                retryConntectServerCount--;
                if (retryConntectServerCount > 0)
                {
                    NotifyConnectServerFailed();
                }
                else
                {
                    OutputDeviceInfoMsg("Too many retries.\n" +
                                        "  Please check Tools option and sdb.exe is installed correctly.\n" +
                                        "  After the problem is fixed, reopen the Solution to start the Device Monitor");
                }

                return(DeviceMonitorResult.SdbEstablishmentError);
            }

            Thread.Sleep(100);

            SDBRequest  request  = SDBConnection.MakeRequest("host:track-devices");
            SDBResponse response = this.sdbconnection.Send(request);

            if (!response.IOSuccess || !response.Okay)
            {
                this.sdbconnection.Close();
                this.sdbconnection = null;

                OutputDeviceInfoMsg("Failed to start device monitor.");
                this.taskCancelSource.Cancel();
                NotifyConnectServerFailed();
                return(DeviceMonitorResult.SdbResponseError);
            }

            OutputDeviceInfoMsg("Device monitor started.");

            CancellationToken cancelToken = this.taskCancelSource.Token;
            bool connectionError          = false;

            while (true)
            {
                if (this.sdbconnection.ConnectionError())
                {
                    connectionError = true;
                    OutputDeviceInfoMsg("SDB Server disconnected.");
                    ret = DeviceMonitorResult.SdbServerKilled;
                    break;
                }

                if (this.sdbconnection.DataAvailable())
                {
                    int length = this.sdbconnection.ReadLength();
                    if (length > 0)
                    {
                        OutputDeviceChangeMsg();

                        byte[] buffer = new byte[length];
                        string result = this.sdbconnection.ReadData(buffer);
                        ProcessDeviceData(result);
                        NotifySubscribers();
                    }
                    else if (length == 0)
                    {
                        if (this.deviceInfoList.Count > 0)
                        {
                            // show message only if there was any device connected
                            // we don't have to show when 0 changed to 0
                            OutputDeviceChangeMsg();
                        }

                        ProcessDeviceData(String.Empty);
                        NotifySubscribers();
                    }
                    else
                    {
                        if (cancelToken.IsCancellationRequested)
                        {
                            ret = DeviceMonitorResult.CanceledByUser;
                            break;
                        }

                        connectionError = true;
                        OutputDeviceInfoMsg("SDB Server disconnected.");
                        ret = DeviceMonitorResult.SdbServerKilled;
                        break;
                    }
                }
                else
                {
#if DEBUG
                    ////OutputDeviceInfoMsg("sdb host:track-devices timeout...", false);
#endif
                    Thread.Sleep(1);
                }

                if (cancelToken.IsCancellationRequested)
                {
                    ret = DeviceMonitorResult.CanceledByUser;
                    break;
                }
            }

            this.sdbconnection.Close();
            this.sdbconnection = null;

            if (connectionError)
            {
                NeedsRestart = true;
            }

            return(ret);
        }