123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using LitJson;
- using QFramework;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HttpSocket : MonoSingleton<HttpSocket>
- {
- public bool isOpen = false;
- public int projectid;
- private float times = 0;
- // Start is called before the first frame update
- void Start()
- {
- InvokeRepeating("SendIpToElectric", 0, 60f);
- }
- // Update is called once per frame
- void Update()
- {
- times += Time.deltaTime;
- if (times > 1)
- {
- times = 0;
-
- SendIpToPointPos(Vector3.zero);
- // SendIpToPointTrigger(projectid, "博物馆");
- }
- }
- /// <summary>
- /// 同步当前位置
- /// </summary>
- /// <param name="pos"></param>
- /// <param name="PointionTs"></param>
- public void SendIpToPointPos(Vector3 pos)
- {
- if (!isOpen) return;
- SendNetConnectPointCloud sendNet = new SendNetConnectPointCloud();
- sendNet.sn = DeviceSN.Instance.SendSerialBy16();
- sendNet.projectId = projectid;
- sendNet.position.x = pos.x;
- sendNet.position.y = pos.y;
- sendNet.position.z = pos.z;
- sendNet.positionType = "PointCloud";
- string jsonData = JsonMapper.ToJson(sendNet);
- // HttpTool.Instance.PostTest("/sn/position", jsonData, CallBack);
- }
- /// <summary>
- /// 进入触发区域后向后台发送信息
- /// </summary>
- /// <param name="pointId"></param>
- /// <param name="ts"></param>
- public void SendIpToPointTrigger(string Name)
- {
- if (!isOpen) return;
- SendNetConnectPointTrigger sendNet = new SendNetConnectPointTrigger();
- sendNet.projectId = projectid;
- sendNet.sn = DeviceSN.Instance.SendSerialBy16();
- sendNet.name = Name;
- string jsonData = JsonMapper.ToJson(sendNet);
- // Debug.Log(jsonData);
- //SocketSendPointCloud(jsonData);
- // JFSocket.GetInstance().SendMessage(jsonData);
- HttpTool.Instance.PostTest("/sn/viewpoint", jsonData, CallBack);
- }
- /// <summary>
- /// 向服务器发送眼镜的剩余电量以及电池状态
- /// 在start函数中使用InvokeRepeating60秒调用一次
- /// </summary>
- public void SendIpToElectric()
- {
- if (!isOpen) return;
- int electricity = (int)((SystemInfo.batteryLevel) * 100f);
- BatteryStatus batterystate = SystemInfo.batteryStatus;
- string state = "";
- switch (batterystate)
- {
- case BatteryStatus.Unknown:
- state = "无法确定设备的电池状态";
- break;
- case BatteryStatus.Charging:
- state = "设备已插入并正在充电";
- break;
- case BatteryStatus.Discharging:
- state = "设备已拔出并放电";
- break;
- case BatteryStatus.NotCharging:
- state = "设备已插入,但无法充电";
- break;
- case BatteryStatus.Full:
- state = "设备已插入并且电池已充满";
- break;
- default:
- state = "无法确定设备的电池状态";
- break;
- }
- SendNetConnectElectricity sendNet = new SendNetConnectElectricity();
- sendNet.sn = DeviceSN.Instance.SendSerialBy16();
- sendNet.electricity = electricity;
- sendNet.status = state;
- sendNet.projectId = projectid;
- string jsonData = JsonMapper.ToJson(sendNet);
- // SocketSendPointCloud(jsonData);
- // JFSocket.GetInstance().SendMessage(jsonData);
- HttpTool.Instance.PostTest("/sn/electricity", jsonData, CallBack);
- if(electricity<20)
- {
- SendNetConnectAlert sendAlert = new SendNetConnectAlert();
- sendAlert.sn = DeviceSN.Instance.SendSerialBy16();
- sendAlert.projectId = projectid;
- sendAlert.message = "电量过低";
- string json = JsonMapper.ToJson(sendAlert);
- HttpTool.Instance.PostTest("/alert/create", json, CallBack);
- }
- }
- /// <summary>
- /// Post 回调
- /// </summary>
- /// <param name="str"></param>
- public void CallBack(string str)
- {
- // Debug.Log(str);
- }
- ///// <summary>
- ///// 获取初始Json成功后的回调
- ///// </summary>
- ///// <param name="str"></param>
- //public void AnalysisJson(string str)
- //{
- // GameManage.Instance.AnalysisJson(str);
- //}
- }
|