示例#1
0
        private void SocketServer_DatagramProcessed(object sender, SessionEventArgs e)
        {
            #region 指令成功解析事件

            RobotSession s = (RobotSession) e.SessionBaseInfo;

            #endregion
        }
示例#2
0
 void Start(){
     initialPosition = transform.position;
     //Pepper
     if(!string.IsNullOrEmpty(pepperIP)){
         _session = QiSession.Create(tcpPrefix + pepperIP + portSuffix);
         if (!_session.IsConnected){
             Debug.Log("Failed to establish connection");
             return;
         }
     //another robot (estimated)
     }else if(!string.IsNullOrEmpty(robotIP)){
         session_robot = RobotSession.Create(tcpPrefix + robotIP + portSuffix);
         if (!_session.IsConnected){
             Debug.Log("Failed to establish connection");
             return;
         }
     }
 }
示例#3
0
        private void SocketServer_ClientLogged(object sender, SessionEventArgs e)
        {
            #region 设备登录成功
            try
            {
                RobotSession s = (RobotSession)e.SessionBaseInfo;

                lock (this)
                {

                    //LogHelper.Write(LogType.Info, "设备登录成功:ID:{0} IP:{1} User:{2}", s.ID, s.IP, s.UserName);
                    int oldSessionID = -1; // 与本设备名称相同的会话ID

                }
            }
            catch (System.Exception ex)
            {
                //LogHelper.Write(LogType.Error, "设备登录异常" + ex.Message + ex.StackTrace);
            }
            #endregion
        }
示例#4
0
        internal async Task <Boolean> Connect()
        {
            Boolean flag;

            Debug.WriteLine(String.Concat("Connecting: ", _info.DisplayName));
            try
            {
                if (_info == null)
                {
                    Debug.WriteLine(String.Concat("Unable to build Service for ", this));
                    flag = false;
                    return(flag);
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1; Debug.WriteLine(String.Concat("Exception looking up service ", _info.DisplayName, " ", exception.Message));
                flag = false;
                return(flag);
            }
            var dispatcher = Deployment.Current.Dispatcher;

            _session = new RobotSession(_info, this, dispatcher);
            if (!await _session.Initialize())
            {
                flag = false;
            }
            else
            {
                InternalSetConnectionState(ConnectionState.Connected);
                Debug.WriteLine(String.Concat("Connected: ", ToString()));
                _sensorControl             = new SensorControl(_session);
                _collisionControl          = new CollisionControl(_session);
                _session._responseDelegate = new RobotSession.RobotResponseDelegate(OnResponseReceived);
                flag = true;
            }
            return(flag);
        }
示例#5
0
        public override void OnXboxInputUpdate(XboxControllerEventData eventData){
            if (string.IsNullOrEmpty(GamePadName)){
                Debug.LogFormat("Joystick {0} with id: \"{1}\" Connected", eventData.GamePadName, eventData.SourceId);
            }

            base.OnXboxInputUpdate(eventData);

            /*get information from xbox controller*/

            if(_session.IsConnected){
                if (eventData.XboxLeftStickHorizontalAxis != 0 || eventData.XboxLeftStickVerticalAxis != 0){
                    var motion = _session.GetService("ALMotion");
                    motion["moveTo"].Call(eventData.XboxLeftStickHorizontalAxis * move_scalefactor, eventData.XboxLeftStickVerticalAxis * (-1) * move_scalefactor, 0f);
                }
                if (eventData.XboxLeftBumper_Pressed){
                    var motion = _session.GetService("ALMotion");
                    motion["moveTo"].Call(0f, 0f, rotation_scalefactor);
                }
                else if (eventData.XboxRightBumper_Pressed){
                    var motion = _session.GetService("ALMotion");
                    motion["moveTo"].Call(0f, 0f, (-1) * rotation_scalefactor);
                }
                if (eventData.XboxB_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        var motion = _session.GetService("ALMotion");
                        motion["setAngles"].Call("HeadYaw", angle, 0f);
                    }
                    first_buttonpressed = Time.time;
                }
                if (eventData.XboxX_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        if (pepperIP == "192.168.10.51"){
                            _session.Close();
                            _session.Destroy();
                            pepperIP = "192.168.10.48"
                            _session = QiSession.Create(tcpPrefix + pepperIP + portSuffix);
                        }else{
                            _session.Close();
                            _session.Destroy();
                            pepperIP = "192.168.10.51"
                            _session = QiSession.Create(tcpPrefix + pepperIP + portSuffix);
                        } 
                    }
                    first_buttonpressed = Time.time;
                }
            
            //another robot (estimated)
            }else if(session_robot.isConnected){
                if (eventData.XboxLeftStickHorizontalAxis != 0 || eventData.XboxLeftStickVerticalAxis != 0){
                    CallRobotsAPI_move(eventData.XboxLeftStickHorizontalAxis * move_scalefactor_robot, eventData.XboxLeftStickVerticalAxis * (-1) * move_scalefactor_robot, 0f);
                }
                if (eventData.XboxLeftBumper_Pressed){
                    CallRobotsAPI_rotate(0f, 0f, rotation_scalefactor);
                }
                else if (eventData.XboxRightBumper_Pressed){
                    CallRobotsAPI_rotate(0f, 0f, (-1) * rotation_scalefactor);
                }
                if (eventData.XboxB_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        CallRobotsAPI_rotate(0f, 0f, 0f);
                    }
                    first_buttonpressed = Time.time;
                }
                if (eventData.XboxX_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        if (robotIP == "192.168.10.53"){
                            session_robot.Close();
                            session_robot.Destroy();
                            robotIP = "192.168.10.54"
                            session_robot = RobotSession.Create(tcpPrefix + robotIP + portSuffix);
                        }else{
                            session_robot.Close();
                            session_robot.Destroy();
                            robotIP = "192.168.10.53"
                            session_robot = RobotSession.Create(tcpPrefix + robotIP + portSuffix);
                        } 
                    }
                    first_buttonpressed = Time.time;
            }
        }
    }
示例#6
0
        public CachedSite(string siteUrl, string parentHolderDir = null)
        {
            Uri createdUri;

            if (Uri.TryCreate(siteUrl, UriKind.Absolute, out createdUri))
            {
                this.BaseUrl = createdUri;
            }
            else
            {
                throw new Exception($"Невозможно создание абсолютного URL из {siteUrl}");
            }

            this.pages = new HashSet <Page>();
            this.robot = new Robot(this.BaseUrl.AbsoluteUri);

            string siteName = this.GetSiteName(this.BaseUrl);

            if (string.IsNullOrEmpty(parentHolderDir))
            {
                this.OwnDir = $@"{siteName}_pages";
            }
            else
            {
                this.OwnDir = $@"{parentHolderDir}\{siteName}_pages";
            }
            this.robotSessionPath = $@"{this.OwnDir}\Session.xml";

            this.InitOwnDir();
            this.sessionSerializer = new XmlSerializer(typeof(RobotSession));

            if (PreviosSessionExists())
            {
                using (StreamReader sr = File.OpenText(this.robotSessionPath))
                {
                    RobotSession lastRobotSession = (RobotSession)sessionSerializer.Deserialize(sr);
                    this.IsValidPageCache = lastRobotSession.IsFinished;

                    foreach (Page foundPage in lastRobotSession.FoundPages)
                    {
                        this.pages.Add(foundPage);
                    }
                }
            }
            else
            {
                this.IsValidPageCache = false;
            }

            /*if (File.Exists(this.holderFile))
             *  using (StreamReader sr = File.OpenText(this.holderFile))
             *  {
             *      string[] strUrls = (string[])serializer.Deserialize(sr);
             *      foreach (string url in strUrls)
             *          this.urls.Add(new Uri(url, UriKind.Absolute));
             *  }*/

            /*string[] foundUrls = File.ReadAllLines(this.holderFile);
             * foreach (string foundUrl in foundUrls)
             *  this.urls.Add(new Uri(foundUrl, UriKind.Absolute));*/
        }
示例#7
0
        public void UpdatePageCache(bool continueSession = false)
        {
            if (continueSession && this.IsValidPageCache)
            {
                return;
            }

            this.currentSession  = new RobotSession();
            this.downloadCounter = 0;

            // Если нужно продолжить прошлую сессию, то дополняем текущую сессию данными
            if (continueSession && File.Exists(this.robotSessionPath))
            {
                using (StreamReader sr = File.OpenText(this.robotSessionPath))
                {
                    RobotSession lastSession = (RobotSession)sessionSerializer.Deserialize(sr);

                    foreach (Page urlResponse in lastSession.FoundPages)
                    {
                        this.currentSession.FoundPages.Add(urlResponse);
                        this.robot.AddSpottedUrl(urlResponse.Url);
                    }

                    foreach (Uri notDequeuedUrl in lastSession.NotDequeuedUrls)
                    {
                        robot.UrlQueue.Enqueue(notDequeuedUrl);
                    }
                }
            }
            else
            {
                this.Delete();
                this.InitOwnDir();
            }

            robot.Subscribe(this);

            /*EventHandler<Robot.RobotEvtArgs> downloadHandler = null;
             * EventHandler<Robot.RobotEvtArgs> cleaner = null;
             *
             * downloadHandler = (obj, args) =>
             * {
             *  this.CachePage(args.Url, args.Document, false);
             *
             *  currentSession.FoundUrls.Add(args.Url);
             *  currentSession.NotDequeuedUrls.Clear();
             *
             *  Uri[] notDequeuedUrls = robot.UrlQueue.ToArray();
             *
             *  foreach (Uri url in notDequeuedUrls)
             *      currentSession.NotDequeuedUrls.Enqueue(url);
             *
             *  File.Delete(this.robotSessionPath);
             *
             *  using (FileStream fs = File.OpenWrite(this.robotSessionPath))
             *      sessionSerializer.Serialize(fs, currentSession);
             * };
             * robot.OnPageResponse += downloadHandler;
             *
             * cleaner = (obj, args) =>
             * {
             *  robot.OnPageResponse -= downloadHandler;
             *  robot.OnFinish -= cleaner;
             * };
             * robot.OnFinish += cleaner;*/

            robot.Run();
        }
示例#8
0
        private void UserLogin(RobotSession s, ref int oldSessionIDr)
        {

        }
示例#9
0
 public CollisionControl(RobotSession robotSession)
 {
     _robotSession = robotSession;
 }
示例#10
0
 public SensorControl(RobotSession robotSession)
 {
     _robotSession = robotSession;
 }