コード例 #1
0
 public virtual ProsthesisStateBase OnDisconnection(TCP.ConnectionState state)
 {
     if (state == mContext.AuthorizedConnection)
     {
         //return new Shutdown(mContext);
     }
     return(this);
 }
コード例 #2
0
        private void OnSocketMessageAvailable(ProsthesisMessage message, TCP.ConnectionState state)
        {
            //Only one message allowed in at a time
            lock (this)
            {
                ProsthesisStateBase newState = mCurrentState;
                //Capture handshakes and send appropriate events
                if (message is ProsthesisHandshakeRequest)
                {
                    ProsthesisHandshakeRequest hsReq = message as ProsthesisHandshakeRequest;
                    if (hsReq.VersionId == ProsthesisCore.ProsthesisConstants.OSVersion)
                    {
                        newState = mCurrentState.OnClientAuthorization(state, true);
                        mAuthorizedConnection = state;
                    }
                    else
                    {
                        newState = mCurrentState.OnClientAuthorization(state, false);
                    }
                }
                else if (state == mAuthorizedConnection)
                {
                    //Capture commands and send appropriate events
                    if (message is ProsthesisCommand)
                    {
                        ProsthesisCommand command = message as ProsthesisCommand;
                        mLogger.LogMessage(Logger.LoggerChannels.Events, string.Format("Received command {0} from {1}", command.Command, state.RemoteEndPoint));


                        ProsthesisCommandAck ack = new ProsthesisCommandAck();
                        ack.Command   = command.Command;
                        ack.Timestamp = System.DateTime.Now.Ticks;
                        ProsthesisDataPacket pack = ProsthesisDataPacket.BoxMessage <ProsthesisCommandAck>(ack);

                        state._conn.Send(pack.Bytes, pack.Bytes.Length, System.Net.Sockets.SocketFlags.None);

                        if (command.Command == ProsthesisConstants.ProsthesisCommand.EmergencyStop)
                        {
                            Terminate(string.Format("Emergency stop from {0}", state.RemoteEndPoint));
                        }
                        else
                        {
                            newState = mCurrentState.OnProsthesisCommand(command.Command, state);
                        }
                    }
                    else
                    {
                        newState = mCurrentState.OnSocketMessage(message, state);
                    }
                }
                else
                {
                    state._server.DropConnection(state);
                }

                ChangeState(newState);
            }
        }
コード例 #3
0
 public override ProsthesisStateBase OnProsthesisCommand(ProsthesisCore.ProsthesisConstants.ProsthesisCommand command, TCP.ConnectionState from)
 {
     switch (command)
     {
     case ProsthesisCore.ProsthesisConstants.ProsthesisCommand.Resume:
         return(new ProsthesisActive(mContext, mArduinos));
     }
     return(base.OnProsthesisCommand(command, from));
 }
コード例 #4
0
 public virtual ProsthesisStateBase OnSocketMessage(ProsthesisCore.Messages.ProsthesisMessage message, TCP.ConnectionState state)
 {
     return(this);
 }
コード例 #5
0
        public virtual ProsthesisStateBase OnProsthesisCommand(ProsthesisCore.ProsthesisConstants.ProsthesisCommand command, TCP.ConnectionState from)
        {
            switch (command)
            {
            case ProsthesisCore.ProsthesisConstants.ProsthesisCommand.Shutdown:
                return(new Shutdown(mContext));

            default:
                return(this);
            }
        }
コード例 #6
0
 public virtual ProsthesisStateBase OnClientAuthorization(TCP.ConnectionState authedClient, bool isAuthorized)
 {
     return(this);
 }
コード例 #7
0
 public virtual ProsthesisStateBase OnConnection(TCP.ConnectionState state)
 {
     return(this);
 }
コード例 #8
0
        public override ProsthesisStateBase OnProsthesisCommand(ProsthesisCore.ProsthesisConstants.ProsthesisCommand command, TCP.ConnectionState from)
        {
            switch (command)
            {
            case ProsthesisCore.ProsthesisConstants.ProsthesisCommand.Initialize:
                return(new RunSelfTest(mContext, mArduinos));

            case ProsthesisCore.ProsthesisConstants.ProsthesisCommand.Shutdown:
                return(new Shutdown(mContext));
            }
            return(this);
        }
コード例 #9
0
        public override ProsthesisStateBase OnProsthesisCommand(ProsthesisCore.ProsthesisConstants.ProsthesisCommand command, TCP.ConnectionState from)
        {
            switch (command)
            {
            case ProsthesisCore.ProsthesisConstants.ProsthesisCommand.Shutdown:
                return(new Shutdown(this));

            default:
            {
                ProsthesisStateBase newState = mCurrentState.OnProsthesisCommand(command, from);
                if (newState != mCurrentState)
                {
                    ChangeState(newState);
                }
            }
            break;
            }

            return(this);
        }
コード例 #10
0
        public override ProsthesisStateBase OnSocketMessage(ProsthesisCore.Messages.ProsthesisMessage message, TCP.ConnectionState state)
        {
            ProsthesisStateBase newState = mCurrentState.OnSocketMessage(message, state);

            if (newState != mCurrentState)
            {
                ChangeState(newState);
            }
            return(this);
        }
コード例 #11
0
        private void OnDisconnection(TCP.ConnectionState state)
        {
            ProsthesisStateBase newState = mCurrentState.OnDisconnection(state);

            ChangeState(newState);
        }
コード例 #12
0
 public override ProsthesisStateBase OnConnection(TCP.ConnectionState state)
 {
     return(new AwaitingAuth(mContext));
 }