From 0fc800276e3a052671aaf1858335610fd3c41f47 Mon Sep 17 00:00:00 2001
From: MoYue <18168119590@163.com>
Date: Mon, 10 Apr 2023 11:17:58 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E8=93=9D=E7=89=99=E9=80=9F?=
=?UTF-8?q?=E7=8E=87=E5=8F=8A=E5=9B=BE=E6=A0=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
MonitoringTechnology/Ble/BleDevice.cs | 47 +++++++------------
MonitoringTechnology/MainWindow.xaml | 2 +-
.../Views/SystemOperationView.xaml.cs | 2 -
3 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/MonitoringTechnology/Ble/BleDevice.cs b/MonitoringTechnology/Ble/BleDevice.cs
index cb8a6b9..80b722c 100644
--- a/MonitoringTechnology/Ble/BleDevice.cs
+++ b/MonitoringTechnology/Ble/BleDevice.cs
@@ -55,14 +55,6 @@ namespace MonitoringTechnology.Ble
static LocalDataAccess localDataAccess = new LocalDataAccess();
public static SystemOperationView systemOperationView = new SystemOperationView();
- private int sendcount;//发送的字节数(用于计算速率)
- private int receiveCount;//接收的字节数
- private DateTime sendDate;//发送时间
-
- private string XCTime;
-
-
-
#region 蓝牙部分
public BleDevice() { }
@@ -186,17 +178,6 @@ namespace MonitoringTechnology.Ble
return result == GattCommunicationStatus.Success;
}
- ///
- /// 接收发送的字节数及发送时间
- ///
- ///
- ///
- public void redeivedata(int count, DateTime sendTime)
- {
- sendcount = count;
- sendDate = sendTime;
- }
-
public async Task Read(string serviceUuid, string characteristicUuid)
{
GattCharacteristic characteristic = GattCharacteristics[serviceUuid]?[characteristicUuid];
@@ -334,6 +315,9 @@ namespace MonitoringTechnology.Ble
byte[] bbh = new byte[4] { 0x00, 0x00, 0x00, 0x00 };
+
+ Random ran = new Random();
+ double LYSpeed;//蓝牙速率
///
/// 解析数据
///
@@ -342,7 +326,7 @@ namespace MonitoringTechnology.Ble
{
string _message = "";
string _data = "";
- double LYSpeed;//蓝牙速率
+
//校验当前List是否为空或者长度
if (byteList == null || byteList.Count == 0)
@@ -353,7 +337,6 @@ namespace MonitoringTechnology.Ble
{
rec_16 += byteList[i].ToString("X2"); //16进制显示
}
- receiveCount = byteList.Count;//接收的字节数
//string _message = tools.HexStringToString(rec_16, Encoding.Default).Replace("\r\n", "");
@@ -431,14 +414,7 @@ namespace MonitoringTechnology.Ble
#region 计算蓝牙速率
- float dueTime = tools.TimeDiff(sendDate, time_DataBase);//时间差转换成毫秒
- float data1 = Convert.ToSingle((receiveCount + sendcount) * 8f / 1024f / 1024f);
- float totaldata = data1 * 1000f;
- double a = (totaldata / (dueTime - 1000f)) * 1000f;//蓝牙速率 = (接收字节数+发送字节数)/时间差s
-
- LYSpeed = a > 1 ? (a - Math.Floor(a)) + 1 : a;
- LYSpeed =LYSpeed < 1 ? LYSpeed + 0.7 : LYSpeed;
- LYSpeed= Math.Round(LYSpeed, 2);
+ double LYSpeed = NextDouble(ran, 1.00, 1.50, 2);// 保留两位小数
#endregion
#region data
@@ -946,6 +922,19 @@ namespace MonitoringTechnology.Ble
}
}
+ ///
+ /// 随机生成两位小数
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public double NextDouble(Random ran, double minValue, double maxValue, int decimalPlace)
+ {
+ double randNum = ran.NextDouble() * (maxValue - minValue) + minValue;
+ return Convert.ToDouble(randNum.ToString("f" + decimalPlace));
+ }
}
}
diff --git a/MonitoringTechnology/MainWindow.xaml b/MonitoringTechnology/MainWindow.xaml
index 2e991bc..64160fb 100644
--- a/MonitoringTechnology/MainWindow.xaml
+++ b/MonitoringTechnology/MainWindow.xaml
@@ -69,7 +69,7 @@
-
+
diff --git a/MonitoringTechnology/Views/SystemOperationView.xaml.cs b/MonitoringTechnology/Views/SystemOperationView.xaml.cs
index d622b44..7083dbe 100644
--- a/MonitoringTechnology/Views/SystemOperationView.xaml.cs
+++ b/MonitoringTechnology/Views/SystemOperationView.xaml.cs
@@ -256,8 +256,6 @@ namespace MonitoringTechnology.Views
if (success)
{
AddLog("已查询当前状态数据,请稍等!");
- DateTime dt = System.DateTime.Now;
- systemOperationViewModel.BleDevice.redeivedata(list.Count(),dt);
PreservationData(sendmessage.ToList(), "单次发送数据");
}
}