예제 #1
0
        public bool getAnswer(out byte opcode, out byte[] msg, out int length)
        {
            if (RequestState == eRequestState.eNEW_ANSWER)
            {
                opcode = ReceivedMessage.Opcode;
                length = ReceivedMessage.Length;

                if (ReceivedMessage.Length > 0)
                {
                    msg = new byte[ReceivedMessage.Length];
                    Buffer.BlockCopy(ReceivedMessage.Msg, 0, msg, 0, ReceivedMessage.Length);
                }
                else
                {
                    msg = null;
                }

                RequestState = eRequestState.eSTANDBY;
                MessageState = eMessageState.eSTX;
                RequestTimer.Restart();
                MessageTimer.Restart();
                return(true);
            }

            opcode = 0;
            msg    = null;
            length = 0;

            return(false);
        }
    private IEnumerator ExecuteRequest()
    {
        m_requestCount++;
        m_state         = eRequestState.pending;
        m_result        = null;
        m_failureReason = "";

        Debug.Log("Sending Async Request");
        Debug.Log("url: " + m_requestURL);
        if (m_requestData != null)
        {
            Debug.Log("inputJSONData: " + m_requestData.ToString());
        }

        yield return(m_loader);

        if (m_loader.error != null && m_loader.error.Length > 0)
        {
            m_state         = eRequestState.failed;
            m_failureReason = "loaderError: " + m_loader.error;
            NotifyRequestCompleted();
        }
        else
        {
            LoaderCompleteHandler();
        }
    }
예제 #3
0
 public cTexNET()
 {
     MessageState = eMessageState.eSTX;
     RequestState = eRequestState.eSTANDBY;
     MessageTimer = new Stopwatch();
     RequestTimer = new Stopwatch();
     MessageTimer.Start();
     RequestTimer.Start();
 }
예제 #4
0
        public byte[] getDataToSend()
        {
            byte[] bufferToSend = null;

            if (RequestState == eRequestState.eSENDING_NAK)
            {
                bufferToSend    = new byte[1];
                bufferToSend[0] = NAK;
                RequestState    = eRequestState.eNAK_SENT;
            }
            else if (RequestState == eRequestState.eSENDING_ANSWER)
            {
                bufferToSend    = new byte[1 + 1 + 1 + MessageToSend.Length + 1];
                bufferToSend[0] = STX;
                bufferToSend[1] = MessageToSend.Opcode;
                bufferToSend[2] = MessageToSend.Length;

                if (MessageToSend.Length > 0)
                {
                    Buffer.BlockCopy(MessageToSend.Msg, 0, bufferToSend, 3, MessageToSend.Length);
                }

                bufferToSend[MessageToSend.Length + 3] = MessageToSend.chks();
                RequestTimer.Start();
                RequestTimer.Restart();
                RequestState = eRequestState.eANSWER_SENT;
            }
            else if (RequestState == eRequestState.eSENDING_REQUEST)
            {
                bufferToSend    = new byte[1 + 1 + 1 + MessageToSend.Length + 1];
                bufferToSend[0] = STX;
                bufferToSend[1] = MessageToSend.Opcode;
                bufferToSend[2] = MessageToSend.Length;

                if (MessageToSend.Length > 0)
                {
                    Buffer.BlockCopy(MessageToSend.Msg, 0, bufferToSend, 3, MessageToSend.Length);
                }

                bufferToSend[MessageToSend.Length + 3] = MessageToSend.chks();
                RequestTimer.Start();
                RequestTimer.Restart();
                RequestState = eRequestState.eREQUEST_SENT;
            }

            return(bufferToSend);
        }
    private void LoaderCompleteHandler()
    {
        try
        {
            string jsonString = StripXMLWrapper(m_loader.text);

            m_result = jsonString;
            m_state  = eRequestState.succeded;
        }
        catch (Exception error)
        {
            m_state         = eRequestState.failed;
            m_failureReason = "JSON Parse Error: " + error.Message;
        }

        NotifyRequestCompleted();
    }
예제 #6
0
        public bool sendAnswer(byte opcode, byte[] msg)
        {
            if (RequestState == eRequestState.eNEW_REQUEST)
            {
                MessageToSend.Opcode = opcode;

                if (msg != null)
                {
                    MessageToSend.Length = (byte)msg.Length;
                    Buffer.BlockCopy(msg, 0, MessageToSend.Msg, 0, msg.Length);
                }
                else
                {
                    MessageToSend.Length = 0;
                }

                retry        = MaxRetry;
                RequestState = eRequestState.eSENDING_ANSWER;
                RequestTimer.Restart();
                return(true);
            }

            return(true);
        }
예제 #7
0
 public void dataSent()
 {
     if (RequestState == eRequestState.eNAK_SENT)
     {
         RequestState = RequestStateBeforeNAK;
         MessageState = eMessageState.eSTX;
         RequestTimer.Restart();
         MessageTimer.Restart();
     }
     else if (RequestState == eRequestState.eANSWER_SENT)
     {
         RequestState = eRequestState.eSTANDBY;
         MessageState = eMessageState.eSTX;
         RequestTimer.Restart();
         MessageTimer.Restart();
     }
     else if (RequestState == eRequestState.eREQUEST_SENT)
     {
         RequestState = eRequestState.eWAITTING_ANSWER;
         MessageState = eMessageState.eSTX;
         RequestTimer.Restart();
         MessageTimer.Restart();
     }
 }
예제 #8
0
        public void process()
        {
            if (MessageState == eMessageState.eNAK_TO_SEND)
            {
                if ((RequestState == eRequestState.eSTANDBY) ||
                    (RequestState == eRequestState.eWAITTING_ANSWER))
                {
                    RequestStateBeforeNAK = RequestState;
                    RequestState          = eRequestState.eSENDING_NAK;
                    RequestTimer.Start();
                    RequestTimer.Restart();
                }
            }

            switch (RequestState)
            {
            case eRequestState.eSTANDBY:
            {
                if (MessageState == eMessageState.eNEW_MSG)
                {
                    RequestState = eRequestState.eNEW_REQUEST;
                    RequestTimer.Restart();
                }
                else if (MessageState == eMessageState.eNAK_RECEIVED)
                {
                    if (retry > 0)
                    {
                        RequestState = eRequestState.eSENDING_ANSWER;
                        RequestTimer.Restart();

                        retry--;
                    }
                    else
                    {
                        MessageState = eMessageState.eSTX;
                        MessageTimer.Restart();
                    }
                }
                break;
            }

            case eRequestState.eNEW_REQUEST:
            {
                if (RequestTimer.ElapsedMilliseconds > Timeout)
                {
                    RequestState = eRequestState.eSTANDBY;
                    MessageState = eMessageState.eSTX;
                    RequestTimer.Restart();
                    MessageTimer.Restart();
                }

                break;
            }

            case eRequestState.eSENDING_ANSWER:
            case eRequestState.eANSWER_SENT:
            {
                if (RequestTimer.ElapsedMilliseconds > Timeout)
                {
                    RequestState = eRequestState.eSTANDBY;
                    MessageState = eMessageState.eSTX;
                    RequestTimer.Restart();
                    MessageTimer.Restart();
                }

                break;
            }

            case eRequestState.eSENDING_NAK:
            case eRequestState.eNAK_SENT:
            {
                if (RequestTimer.ElapsedMilliseconds > Timeout)
                {
                    RequestState = RequestStateBeforeNAK;
                    MessageState = eMessageState.eSTX;
                    RequestTimer.Restart();
                    MessageTimer.Restart();
                }

                break;
            }

            case eRequestState.eWAITTING_ANSWER:
            {
                if (MessageState == eMessageState.eNEW_MSG)
                {
                    RequestTimer.Start();
                    RequestTimer.Restart();
                    RequestState = eRequestState.eNEW_ANSWER;
                }
                else
                {
                    if (RequestTimer.ElapsedMilliseconds > Timeout)
                    {
                        if (retry > 0)
                        {
                            RequestState = eRequestState.eSENDING_REQUEST;
                            MessageState = eMessageState.eSTX;
                            RequestTimer.Restart();
                            MessageTimer.Restart();
                            retry--;
                        }
                        else
                        {
                            RequestState = eRequestState.eSTANDBY;
                            MessageState = eMessageState.eSTX;
                            RequestTimer.Restart();
                            MessageTimer.Restart();
                        }
                    }
                }
                break;
            }

            case eRequestState.eNEW_ANSWER:
            {
                if (RequestTimer.ElapsedMilliseconds > Timeout)
                {
                    RequestState = eRequestState.eSTANDBY;
                    MessageState = eMessageState.eSTX;
                    RequestTimer.Restart();
                    MessageTimer.Restart();
                }

                break;
            }
            }
        }