Пример #1
0
    void Update()
    {
        //from database
        //StartCoroutine(GetRequest("http://localhost:3000/api/simulation/state"));
        //from file
        string tele_in = File.ReadAllText(Application.dataPath + "/Test_1.json");

        info = JsonUtility.FromJson <Teleinfo>(tele_in);
        Debug.Log(info.timer.ToString());
        counttext.text = tele_in;
        if (info.heart_bpm < 60 || info.heart_bpm > 100)
        {
            Debug.Log("Emergency");

            super_but.GetComponent <Image>().color = Color.red;
            warn_pan.SetActive(false);
            e_pan.SetActive(true);
        }

        /*if (timeLeft >= -4)
         * {
         *  timeLeft -= Time.deltaTime;
         *  //Debug.Log(timeLeft);
         *  if (timeLeft < 24)
         *  {
         *      Debug.Log("warning");
         *      warn_pan.SetActive(true);
         *      super_but.GetComponent<Image>().color = Color.yellow;
         *  }
         *  if (timeLeft < 10)
         *  {
         *      Debug.Log("emergency");
         *
         *      super_but.GetComponent<Image>().color = Color.red;
         *      warn_pan.SetActive(false);
         *      e_pan.SetActive(true);
         *  }
         *
         * }else {
         *  e_pan.SetActive(false);
         *  warn_pan.SetActive(false);
         * }*/
    }
Пример #2
0
    //get touch with database
    IEnumerator GetRequest(string uri)
    {
        using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
        {
            // Request and wait for the desired page.
            yield return(webRequest.SendWebRequest());

            string[] pages = uri.Split('/');
            int      page  = pages.Length - 1;

            if (webRequest.isNetworkError)
            {
                Debug.Log(pages[page] + ": Error: " + webRequest.error);
                counttext.text = webRequest.error;
            }
            else
            {
                //Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
                counttext.text = webRequest.downloadHandler.text;
                //JSONObject json = new JSONObject(www.text);
                string response = System.Text.Encoding.UTF8.GetString(webRequest.downloadHandler.data);
                //Teleinfo player= JsonUtility.ToJson(response);
                //Teleinfo player = JsonConvert.DeserializeObject<Teleinfo>(response);
                // Teleinfo t = new Teleinfo();
                //Teleinfo json = new Teleinfo(webRequest.downloadHandler.text);
                info = JsonUtility.FromJson <Teleinfo>(webRequest.downloadHandler.text);
                Debug.Log(info.timer.ToString());

                /*if (info.heart_bpm < 60 || info.heart_bpm > 100)
                 * {
                 *
                 *  Debug.Log("Emergency");
                 *
                 *  super_but.GetComponent<Image>().color = Color.red;
                 *  warn_pan.SetActive(false);
                 *  e_pan.SetActive(true);
                 *
                 *
                 * }*/
            }
        }
    }
Пример #3
0
    //get touch with database
    IEnumerator GetRequest(string uri)
    {
        using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
        {
            // Request and wait for the desired page.
            yield return(webRequest.SendWebRequest());

            string[] pages = uri.Split('/');
            int      page  = pages.Length - 1;

            if (webRequest.isNetworkError)
            {
                Debug.Log(pages[page] + ": Error: " + webRequest.error);
                counttext.text = webRequest.error;
            }
            else
            {
                //Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
                counttext.text = webRequest.downloadHandler.text;
                //JSONObject json = new JSONObject(www.text);
                string response = System.Text.Encoding.UTF8.GetString(webRequest.downloadHandler.data);
                //Teleinfo player= JsonUtility.ToJson(response);
                //Teleinfo player = JsonConvert.DeserializeObject<Teleinfo>(response);
                // Teleinfo t = new Teleinfo();
                //Teleinfo json = new Teleinfo(webRequest.downloadHandler.text);
                if (webRequest.downloadHandler.text == null)
                {
                    Debug.Log("No connection");
                }
                info = JsonUtility.FromJson <Teleinfo>(webRequest.downloadHandler.text);
                //Debug.Log(info.timer.ToString());
                time_text.text  = "EVA time:     " + info.timer.ToString().ToString();
                bat_text.text   = "Battery left: " + info.t_battery.ToString();
                o2_text.text    = "02 left:       " + info.t_oxygen.ToString();
                h20_text.text   = "H20 left:      " + info.t_water.ToString();
                temp_text.text  = "Temp:" + info.t_sub + "F";
                subp_text.text  = "Press:" + info.p_sub + "psia";
                heart_text.text = "Heart:" + info.heart_bpm + "bmp";
                fan_text.text   = "Fan:" + info.v_fan + "rpm";
                if (System.Convert.ToInt32(info.v_fan) < 10000)
                {
                    Debug.Log("Emergency");

                    super_but.GetComponent <Image>().color = Color.red;
                    //color_bt.GetComponent<Image>().color= Color.red;
                    warn_pan.SetActive(false);
                    e_pan.SetActive(true);
                }
                else if (System.Convert.ToInt32(info.v_fan) < 15000 || System.Convert.ToInt32(info.v_fan) > 40000)
                {
                    Debug.Log("Warning");

                    super_but.GetComponent <Image>().color = Color.yellow;
                    //color_bt.GetComponent<Image>().color = Color.yellow;
                    warn_pan.SetActive(true);
                    e_pan.SetActive(false);
                }
                else
                {
                    super_but.GetComponent <Image>().color = Color.green;
                    //Color c = new Color32(19, 210, 241, 255);
                    //color_bt.GetComponent<Image>().color = Color.blue;
                    warn_pan.SetActive(false);
                    e_pan.SetActive(false);
                }
            }
        }
    }
Пример #4
0
    void Update()
    {
        //from database
        //StartCoroutine(GetRequest("http://localhost:3000/api/simulation/state"));
        //StartCoroutine(GetRequest("http://gooabcgle.com"));
        // StartCoroutine(GetRequest(" http://192.168.2.2:3000/api/simulation/state"));

        //from file
        //string path = string.Format("{0}/mydata/{1}.json", Application.persistentDataPath, filename);

        o2timeLeft  -= Time.deltaTime;
        h20imeLeft  -= Time.deltaTime;
        battimeLeft -= Time.deltaTime;
        evatime     += Time.deltaTime;

        //Application.dataPath
        //Application.persistentDataPath
        //string tele_in = File.ReadAllText(Application.persistentDataPath + "/Test_1.json");
        //info = JsonUtility.FromJson<Teleinfo>(tele_in);
        //Debug.Log(info.timer.ToString());
        Teleinfo t = new Teleinfo();

        t._id             = "5eb45106a2e9745e38d1d8c6";
        t.time            = 8525.543000000038;
        t.timer           = "02:22:05";
        t.started_at      = "2020-05-07T18:18:46.191Z";
        t.heart_bpm       = 90;
        t.p_sub           = "3.93";
        t.p_suit          = "3.95";
        t.t_sub           = "31.7";
        t.v_fan           = "39986";
        t.p_o2            = "775.02";
        t.rate_o2         = "0.6";
        t.batteryPercent  = 40.79484027777724;
        t.battery_out     = 40;
        t.cap_battery     = 29;
        t.t_battery       = "01:37:54";
        t.p_h2o_g         = "15.18";
        t.p_h2o_l         = "15.89";
        t.p_sop           = "882";
        t.rate_sop        = "1.0";
        t.t_oxygenPrimary = "21.05978703703501";
        t.t_oxygenSec     = "100";
        t.ox_primary      = "21";
        t.ox_secondary    = "100";
        t.t_oxygen        = "03:37:54";
        t.cap_water       = 56.94170202020222;
        t.t_water         = "03:07:54";
        t.__v             = 0;
        //counttext.text = tele_in;
        string tjson = JsonUtility.ToJson(t);

        Debug.Log(tjson.ToString());
        counttext.text = tjson.ToString();
        // time_text.text="EVA time: "+t.timer.ToString();
        time_text.text = "EVA time:     " + System.TimeSpan.FromSeconds(evatime).ToString();
        //bat_text.text = "Battery left: " + t.t_battery.ToString();
        bat_text.text = "Battery left: " + System.TimeSpan.FromSeconds(battimeLeft).ToString();
        //o2_text.text = "02 left: " + t.t_oxygen.ToString();
        o2_text.text = "02 left:       " + System.TimeSpan.FromSeconds(o2timeLeft).ToString();
        // h20_text.text = "H20 left: " + t.t_oxygen.ToString();
        h20_text.text   = "H20 left:      " + System.TimeSpan.FromSeconds(h20imeLeft).ToString();
        temp_text.text  = "Temp:" + t.t_sub + "F";
        subp_text.text  = "Press:" + t.p_sub + "psia";
        heart_text.text = "Heart:" + t.heart_bpm + "bmp";
        fan_text.text   = "Fan:" + t.v_fan + "rpm";
        if (t.heart_bpm < 60 || t.heart_bpm > 100 || System.Convert.ToInt32(t.v_fan) < 10000)
        {
            Debug.Log("Emergency");

            super_but.GetComponent <Image>().color = Color.red;
            warn_pan.SetActive(false);
            e_pan.SetActive(true);
        }
        if (timeLeft >= -4)
        {
            timeLeft -= Time.deltaTime;
            //Debug.Log(timeLeft);
            if (timeLeft < 24)
            {
                Debug.Log("warning");
                warn_pan.SetActive(true);
                super_but.GetComponent <Image>().color = Color.yellow;
            }
            if (timeLeft < 10)
            {
                Debug.Log("emergency");

                super_but.GetComponent <Image>().color = Color.red;
                warn_pan.SetActive(false);
                e_pan.SetActive(true);
            }
        }
        else
        {
            e_pan.SetActive(false);
            warn_pan.SetActive(false);
        }
    }