更换蓝牙速率及图标

This commit is contained in:
MoYue 2023-04-10 11:17:58 +08:00
parent 98c50804b6
commit 0fc800276e
3 changed files with 19 additions and 32 deletions

View File

@ -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;
}
/// <summary>
/// 接收发送的字节数及发送时间
/// </summary>
/// <param name="count"></param>
/// <param name="sendTime"></param>
public void redeivedata(int count, DateTime sendTime)
{
sendcount = count;
sendDate = sendTime;
}
public async Task<byte[]> 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;//蓝牙速率
/// <summary>
/// 解析数据
/// </summary>
@ -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
}
}
/// <summary>
/// 随机生成两位小数
/// </summary>
/// <param name="ran"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="decimalPlace"></param>
/// <returns></returns>
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));
}
}
}

View File

@ -69,7 +69,7 @@
<Grid MouseLeftButtonDown="Border_MouseLeftButtonDown">
<Border Width="55" Height="50" Margin="10,0,20,0" HorizontalAlignment="Left" >
<Border.Background>
<ImageBrush ImageSource="Assets/Images/浮式风电.png"/>
<ImageBrush ImageSource="Assets/Images/bitbug_favicon.ico"/>
</Border.Background>
</Border>
<StackPanel VerticalAlignment="Center">

View File

@ -256,8 +256,6 @@ namespace MonitoringTechnology.Views
if (success)
{
AddLog("已查询当前状态数据,请稍等!");
DateTime dt = System.DateTime.Now;
systemOperationViewModel.BleDevice.redeivedata(list.Count(),dt);
PreservationData(sendmessage.ToList(), "单次发送数据");
}
}