断线重连取数据逻辑

This commit is contained in:
CaiYanPeng 2022-05-31 18:40:32 +08:00
parent 167a424505
commit 3f8c189ad4
3 changed files with 25 additions and 8 deletions

View File

@ -118,7 +118,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
if (characteristic.MatchGuid(ServiceUuids.Characteristics.RowerData))
{
var c = base.Characteristics.SingleOrDefault(x => x.Uuid == ServiceUuids.Characteristics.RowerData);
if (c != null)
if (c != null && !C2RowerData.IsEnabled)
{
c.HandleAttributeReceived(response.Data);
}

View File

@ -39,7 +39,7 @@ public class RowerHomeScript : PFUIPanel
{
get
{
return Rower != null ? (C2RowerData.IsEnabled == true ? (IRowerCommonData)Rower.c2RowerData : (IRowerCommonData)Rower.rowerData) : null;
return Rower != null ? (C2RowerData.IsEnabled == true ? Rower.c2RowerData : Rower.rowerData) : null;
//var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
//if (device != null)
//{
@ -420,7 +420,7 @@ public class RowerHomeScript : PFUIPanel
{
startTime = UIManager.Now.GetDateTime();
createTime = null;
truelyTime = 0;
truelyTime = historyTime;
//TimerTicks();
openTimer = true;
timer = 1.0f;
@ -626,7 +626,10 @@ public class RowerHomeScript : PFUIPanel
leftLine.localPosition = new Vector3(-207.5f+43, leftLine.localPosition.y, leftLine.localPosition.z);
rightLine.localPosition = new Vector3(164.5f+43, rightLine.localPosition.y, rightLine.localPosition.z);
finishLine.localPosition = new Vector3(-237.5f+43, finishLine.localPosition.y, finishLine.localPosition.z);
historyStrokeCount = 0;
historyDistance = 0;
historyTime = 0;
historyEnergy = 0;
Resources.UnloadUnusedAssets();
GC.Collect();
@ -702,9 +705,11 @@ public class RowerHomeScript : PFUIPanel
#endif
var heartRate = HeartRate ?? 0;
bottom.Find("BPM/Value").GetComponent<Text>().text = heartRate.ToString();
var distance = (int)RowerData.TotalDistance;
var energy = RowerData.TotalEnergy;
var strokeCount = RowerData.StrokeCount;
//断线重连继续
var distance = (int)RowerData.TotalDistance + historyDistance;
var energy = RowerData.TotalEnergy + historyEnergy;
var strokeCount = RowerData.StrokeCount + historyStrokeCount;
var power = RowerData.InstantaneousPower;
var rate = RowerData.StrokeRate;
truelyTime++;
@ -858,6 +863,8 @@ public class RowerHomeScript : PFUIPanel
}
}
//检查本地数据
int historyDistance = 0,historyStrokeCount = 0,historyEnergy = 0;
public int historyTime = 0;
private void CheckLocalData()
{
try
@ -876,6 +883,16 @@ public class RowerHomeScript : PFUIPanel
{
records.Add(item);
}
//records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{power},{pace},{rate},{RowerData.ResistanceLevel},{heartRate},{energy},{RowerData.AveragePower},{truelyTime}");
var _re = records.LastOrDefault();
if (!string.IsNullOrEmpty(_re))
{
var datas = _re.Split(',');
historyStrokeCount = int.Parse(datas[0]);
historyDistance = int.Parse(datas[2]);
historyTime = int.Parse(datas[10]);
historyEnergy = int.Parse(datas[8]);
}
}
UIManager.CloseConfirm();
}, 2,

View File

@ -201,7 +201,7 @@ public class RowerMultiModeScript : MonoBehaviour
public async void GetShadowList(RowerTaskPanel.RowerType rowerType, RowerResultModel reRowData)
{
this.rowerType = rowerType;
currentSecond = -1;
currentSecond = GetComponent<RowerHomeScript>().historyTime - 1;
//if(Application.internetReachability == NetworkReachability.NotReachable)
var res = reRowData ==null? await ConfigHelper.rowerApi.GetShadowList(rowerType): await ConfigHelper.rowerApi.GetReRowShadowList(reRowData.Id);
shadowList = res.data;