private void Send_New_Message_To_Event(Robot_State RobotState)
 {
     if (New_Receive_Message_Event != null)
     {
         New_Receive_Message_Event(RobotState);
     }
 }
 private void Clear_Receive_Data_Cache_Value()
 {
     rdState = 0;
     rdTag   = null;
     rdCache.Clear();
     getRobotState = new Robot_State();
 }
Exemplo n.º 3
0
 public Action_Dialogue(string tag, float w)
 {
     weight      = w;
     data        = GameObject.FindGameObjectWithTag("Robot_Head").GetComponent <Dialogue>();
     audiosource = GameObject.FindGameObjectWithTag("Robot_Head").GetComponent <AudioSource>();
     utility     = GameObject.FindGameObjectWithTag("Robot_Head").GetComponent <Utility>();
     rs          = GameObject.FindGameObjectWithTag("Robot_Head").GetComponent <Robot_State>();
     for (int i = 0; i < data.database.Count; ++i)
     {
         if (data.database[i].Action_tag == tag)
         {
             dialogue[data.database[i].FOF].Add(new Tuple(data.database[i].Sources, 0));
         }
     }
 }
        //感情を示すGameObjectを描画する
        private GameObject generate_gameobject(string state_key, GameObject state_object)
        {
            string path = "";

            if (state_key == "11" || state_key == "20" || state_key == "22" || state_key == "28" || state_key == "29")
            {
                path         = Robot_State.get_state_gameobject(state_key);
                state_object = (GameObject)Resources.Load(path);
                state_object = Instantiate(state_object);
                state_object.transform.parent = Root.transform;
                return(state_object);
            }
            else
            {
                return(null);
            }
        }
    private void Receive_Data(List <byte> rawData, out bool StateValid, out Robot_State newState)
    {
        Robot_State _r = new Robot_State();

        StateValid = false;

        int   _i           = 0;
        float?_value       = null;
        int?  _errState    = null;
        int   _totalLength = 10;

        while (_i < rawData.Count)
        {
            switch (rdState)
            {
            case -50:     // value not match error
                Debug.Log("Receive data error state: " + _errState + ", content value format not match!!");
                rdState = -10;
                break;

            case -40:     // cache leaking error
                Debug.Log("Receive data error state: " + _errState + ", cache leaked!!");
                rdState = -10;
                break;

            case -30:     // tag error
                Debug.Log("Receive data error state: " + _errState + ", tag format not match!!");
                rdState = -10;
                break;

            case -20:     // format not match error
                Debug.Log("Receive data error state: " + _errState + ", format error!!");
                rdState = -10;
                break;

            case -10:     // data error
                _i = rawData.Count + 1;
                _r = new Robot_State();
                Clear_Receive_Data_Cache_Value();       // clear all cache and go back state 0
                break;

            case 0:
                _errState = rdState;       // incase if error occur
                if (rawData[_i] == 40)     // if read (
                {
                    _i++;
                    rdTag  = null;      // clear tag to provent pollution for second cycle comparison
                    _value = null;      // clear to provent pollution
                    rdCache.Clear();    // clear cache for very next using
                    rdState = 10;
                }
                else if (rawData[_i] == 91)     // if read [
                {
                    _i++;
                    rdState = 100;
                }
                else
                {
                    rdState = -20;
                }
                break;

            case 10:
                _errState = rdState;        // incase if error occur

                // if not read ) and value not too long and no error
                while (rawData[_i] != 41 && rdCache.Count < _totalLength && rdState == 10)
                {
                    // if data is a english letter, capital and lower case
                    if ((rawData[_i] >= 65 && rawData[_i] <= 90) || (rawData[_i] >= 97 && rawData[_i] <= 122))
                    {
                        rdCache.Add(rawData[_i]);
                        _i++;
                        if (_i >= rawData.Count)
                        {
                            break;                          // only do next loop if not finish reading the data
                        }
                    }
                    else
                    {
                        rdState = -30;
                    }
                }

                if (rdCache.Count >= _totalLength)
                {
                    rdState = -30;     // if cache value too long
                    break;
                }

                if (_i >= rawData.Count)
                {
                    break;                 // protect next line
                }
                if (rawData[_i] == 41)     // if read )
                {
                    _i++;
                    rdTag = Encoding.ASCII.GetString(rdCache.ToArray());
                    rdCache.Clear();        // clear cache for very next using
                    rdState = 20;
                }
                break;

            case 20:                 // taking content data
                _errState = rdState; // incase if error occur

                // if not read ; and value not too long and no error
                while (rawData[_i] != 59 && rdCache.Count < _totalLength && rdState == 20)
                {
                    // if is reading number and . and -
                    if ((rawData[_i] >= 45 && rawData[_i] <= 46) || (rawData[_i] >= 48 && rawData[_i] <= 57))
                    {
                        rdCache.Add(rawData[_i]);
                        _i++;
                        if (_i >= rawData.Count)
                        {
                            break;                          // only do next loop if not finish reading the data
                        }
                    }
                    else
                    {
                        rdState = -50;
                    }
                }

                if (rdCache.Count >= _totalLength)
                {
                    rdState = -50;     // if cache value too long
                    break;
                }

                if (_i >= rawData.Count)
                {
                    break;                  // protect next line
                }
                if (rawData[_i] == 59)      // if read ;
                {
                    try
                    {
                        _value = float.Parse(Encoding.ASCII.GetString(rdCache.ToArray()));
                    }
                    catch (FormatException _e)
                    {
                        Debug.Log("Receive Data value converting error: " + _e);
                        rdState = -40;
                    }

                    if (rdState == 20)
                    {
                        rdState = 30;                       // if no err go next
                    }
                }
                break;

            case 30:
                _errState = rdState;        // incase if error occur
                if (rdTag == "Gest")        // gesture type
                {
                    _r.Gesture_State = (int)_value;
                    if (_r.Gesture_State < 0 || 1000 < _r.Gesture_State)
                    {
                        rdState = -50;
                    }
                }
                else if (rdTag == "HEnb")       // hand enable
                {
                    if (_value == 1)
                    {
                        _r.Hand_Enabled = true;
                    }
                    else if (_value == 0)
                    {
                        _r.Hand_Enabled = false;
                    }
                    else
                    {
                        rdState = -50;
                    }
                }
                else if (rdTag == "HEnbErr")        // hand enable error
                {
                    if (_value == 1)
                    {
                        _r.Hand_Enb_Err = true;
                    }
                    else if (_value == 0)
                    {
                        _r.Hand_Enb_Err = false;
                    }
                    else
                    {
                        rdState = -50;
                    }
                }
                else if (rdTag == "Grab")       // hand grab state
                {
                    if (_value == 1)
                    {
                        _r.Grab_State = true;
                    }
                    else if (_value == 0)
                    {
                        _r.Grab_State = false;
                    }
                    else
                    {
                        rdState = -50;
                    }
                }
                else if (rdTag == "HMovErr")        // hand move error
                {
                    if (_value == 1)
                    {
                        _r.Hand_Mov_Err = true;
                    }
                    else if (_value == 0)
                    {
                        _r.Hand_Mov_Err = false;
                    }
                    else
                    {
                        rdState = -50;
                    }
                }
                else if (rdTag == "RMovErr")        // robot move error
                {
                    if (_value == 1)
                    {
                        _r.Robot_Mov_Err = true;
                    }
                    else if (_value == 0)
                    {
                        _r.Robot_Mov_Err = false;
                    }
                    else
                    {
                        rdState = -50;
                    }
                }

                if (rdState == 30)
                {
                    _i++;
                    rdState = 0;     // if evey thing fine then turn to start
                }
                break;

            case 100:
                _errState = rdState; // incase if error occur
                if (rawData[_i] == 13)
                {                    // if read CR
                    _i++;
                    rdState = 110;
                }
                else if (rawData[_i] == 10)
                {     // if read LF
                    _i++;
                    rdState = 120;
                }
                else
                {
                    rdState = -20;
                }
                break;

            case 110:
                _errState = rdState; // incase if error occur
                if (rawData[_i] == 93)
                {                    // if read ]
                    _i++;
                    rdState = 0;
                }
                else
                {
                    rdState = -20;
                }
                break;

            case 120:
                _errState = rdState; // incase if error occur
                if (rawData[_i] == 93)
                {                    // if read ]
                    StateValid = true;
                    _i++;
                    rdState = 0;
                }
                else
                {
                    rdState = -20;
                }
                break;
            }
        }
        newState = _r;
    }