添加校时
This commit is contained in:
parent
6dcf9b82fa
commit
255a87096d
@ -6,6 +6,7 @@
|
|||||||
<!--数据库连接信息-->
|
<!--数据库连接信息-->
|
||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<add name="db" connectionString="server=127.0.0.1;port=3306;user=root;password=zttZTT1234;database=monitoringtechnology;Allow User Variables=True;" />
|
<add name="db" connectionString="server=127.0.0.1;port=3306;user=root;password=zttZTT1234;database=monitoringtechnology;Allow User Variables=True;" />
|
||||||
|
<!--<add name="db" connectionString="server=81.68.201.26;port=3306;user=root;password=123456;database=monitoringtechnology;Allow User Variables=True;" />-->
|
||||||
</connectionStrings>
|
</connectionStrings>
|
||||||
<runtime>
|
<runtime>
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
|||||||
@ -43,8 +43,11 @@ namespace MonitoringTechnology.Ble
|
|||||||
private readonly CharacteristicDictionary GattCharacteristics = new CharacteristicDictionary();
|
private readonly CharacteristicDictionary GattCharacteristics = new CharacteristicDictionary();
|
||||||
public static FileModel FileModel { get; set; } = new FileModel();
|
public static FileModel FileModel { get; set; } = new FileModel();
|
||||||
|
|
||||||
public event TypedEventHandler<GattCharacteristic, byte[]> CharacteristicValueChanged;
|
public event TypedEventHandler<GattCharacteristic, byte[]> CharacteristicValueChanged;//数据解析 -- 报文返回
|
||||||
public event TypedEventHandler<BleDevice, bool> ConnectionStateChanged;
|
|
||||||
|
public event TypedEventHandler<GattCharacteristic, string> ReceiveValueChanged; //数据解析 --自定义数据返回
|
||||||
|
|
||||||
|
public event TypedEventHandler<BleDevice, bool> ConnectionStateChanged;//连接状态变化
|
||||||
|
|
||||||
public static MonitoringSensorModel monitoringSensorModel { get; set; } = new MonitoringSensorModel();
|
public static MonitoringSensorModel monitoringSensorModel { get; set; } = new MonitoringSensorModel();
|
||||||
static LocalDataAccess localDataAccess = new LocalDataAccess();
|
static LocalDataAccess localDataAccess = new LocalDataAccess();
|
||||||
@ -272,7 +275,7 @@ namespace MonitoringTechnology.Ble
|
|||||||
|
|
||||||
private static string _localtime => $"{DateTime.Now: yyyy-MM-dd HH:mm:ss.fff}";
|
private static string _localtime => $"{DateTime.Now: yyyy-MM-dd HH:mm:ss.fff}";
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 收到数据
|
/// 收到数据 ----报文fanhui
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
@ -286,12 +289,21 @@ namespace MonitoringTechnology.Ble
|
|||||||
ParsingData(data.ToList());
|
ParsingData(data.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义数据接收--数据解析
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
private void ReceiveValueChangedChanged(GattCharacteristic sender, string data)
|
||||||
|
{
|
||||||
|
ReceiveValueChanged?.Invoke(sender, data);
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 定义一个委托,用于传值老的版本号
|
/// 定义一个委托,用于传值老的版本号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Action<byte[]> func = new Action<byte[]>(SystemOperationView.Setbbh);
|
Action<byte[]> func = new Action<byte[]>(SystemOperationView.Setbbh);
|
||||||
|
|
||||||
string _message = "";
|
|
||||||
byte[] bbh = new byte[4] { 0x00, 0x00, 0x00, 0x00 };
|
byte[] bbh = new byte[4] { 0x00, 0x00, 0x00, 0x00 };
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 解析数据
|
/// 解析数据
|
||||||
@ -299,6 +311,8 @@ namespace MonitoringTechnology.Ble
|
|||||||
/// <param name="byteList"></param>
|
/// <param name="byteList"></param>
|
||||||
private void ParsingData(List<byte> byteList)
|
private void ParsingData(List<byte> byteList)
|
||||||
{
|
{
|
||||||
|
string _message = "";
|
||||||
|
|
||||||
//校验当前List是否为空或者长度
|
//校验当前List是否为空或者长度
|
||||||
if (byteList == null || byteList.Count == 0)
|
if (byteList == null || byteList.Count == 0)
|
||||||
return;
|
return;
|
||||||
@ -364,7 +378,7 @@ namespace MonitoringTechnology.Ble
|
|||||||
|
|
||||||
switch (_fun_code)
|
switch (_fun_code)
|
||||||
{
|
{
|
||||||
//数据解析
|
//数据解析 ---实时数据
|
||||||
case 0x02:
|
case 0x02:
|
||||||
switch (_kind)
|
switch (_kind)
|
||||||
{
|
{
|
||||||
@ -467,6 +481,9 @@ namespace MonitoringTechnology.Ble
|
|||||||
AttitudeDisplayView.monitoringSensor.F_DegreesZ = monitoringSensorModel.degrees_z;
|
AttitudeDisplayView.monitoringSensor.F_DegreesZ = monitoringSensorModel.degrees_z;
|
||||||
|
|
||||||
localDataAccess.write("INSERT INTO monitoringsensormodel(F_CreateDate,F_DatetimeSensor,F_Tem,F_Hum,F_Pressure,F_AccelerationX,F_AccelerationY,F_AccelerationZ,F_AngularVelocityX,F_AngularVelocityY,F_AngularVelocityZ,F_DegreesX,F_DegreesY,F_DegreesZ) VALUES('" + monitoringSensorModel.f_CreateDate + "','" + monitoringSensorModel._datetime_Sensor + "','" + monitoringSensorModel._Tem + "','" + monitoringSensorModel._Hum + "','" + monitoringSensorModel._pressure + "','" + monitoringSensorModel._acceleration_X + "','" + monitoringSensorModel._acceleration_Y + "','" + monitoringSensorModel._acceleration_Z + "','" + monitoringSensorModel._angularVelocity_X + "','" + monitoringSensorModel._angularVelocity_Y + "','" + monitoringSensorModel._angularVelocity_Z + "','" + monitoringSensorModel.degrees_x + "','" + monitoringSensorModel.degrees_y + "','" + monitoringSensorModel.degrees_z + "');");
|
localDataAccess.write("INSERT INTO monitoringsensormodel(F_CreateDate,F_DatetimeSensor,F_Tem,F_Hum,F_Pressure,F_AccelerationX,F_AccelerationY,F_AccelerationZ,F_AngularVelocityX,F_AngularVelocityY,F_AngularVelocityZ,F_DegreesX,F_DegreesY,F_DegreesZ) VALUES('" + monitoringSensorModel.f_CreateDate + "','" + monitoringSensorModel._datetime_Sensor + "','" + monitoringSensorModel._Tem + "','" + monitoringSensorModel._Hum + "','" + monitoringSensorModel._pressure + "','" + monitoringSensorModel._acceleration_X + "','" + monitoringSensorModel._acceleration_Y + "','" + monitoringSensorModel._acceleration_Z + "','" + monitoringSensorModel._angularVelocity_X + "','" + monitoringSensorModel._angularVelocity_Y + "','" + monitoringSensorModel._angularVelocity_Z + "','" + monitoringSensorModel.degrees_x + "','" + monitoringSensorModel.degrees_y + "','" + monitoringSensorModel.degrees_z + "');");
|
||||||
|
|
||||||
|
_message = "状态数据获取成功: 温度:"+ monitoringSensorModel._Tem + "℃ 湿度:" + monitoringSensorModel._Hum + "% 气压:" + monitoringSensorModel._pressure + "KPa 俯仰角:" + monitoringSensorModel._acceleration_X + "° 横滚角:"+ monitoringSensorModel._acceleration_Y + "° 偏航角:" + monitoringSensorModel._acceleration_Z + "° 角速度X:" + monitoringSensorModel._angularVelocity_X + "m/s² 角速度Y:" + monitoringSensorModel._angularVelocity_Y + "m/s² 角速度Z:" + monitoringSensorModel._angularVelocity_Z + "m/s² 角度X:" + monitoringSensorModel.degrees_x + "rad/s 角度Y:" + monitoringSensorModel.degrees_y + "rad/s 角度Z:" + monitoringSensorModel.degrees_z + "rad/s" ;
|
||||||
|
ReceiveValueChangedChanged(null, _message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//主系统数据
|
//主系统数据
|
||||||
@ -508,27 +525,47 @@ namespace MonitoringTechnology.Ble
|
|||||||
switch (byteList[11])
|
switch (byteList[11])
|
||||||
{
|
{
|
||||||
case 0x00:
|
case 0x00:
|
||||||
_message += "获取成功";
|
_message += "版本查询:获取成功";
|
||||||
break;
|
break;
|
||||||
case 0x01:
|
case 0x01:
|
||||||
_message += "空";
|
_message += "版本查询:空";
|
||||||
|
ReceiveValueChangedChanged(null, _message);
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
_message += "设备忙";
|
_message += "版本查询:设备忙";
|
||||||
|
ReceiveValueChangedChanged(null, _message);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//显示版本号
|
//显示版本号
|
||||||
SystemOperationView.systemOperationViewModel.VersionQueryData = ((int)bbh[0]).ToString() + "." + ((int)bbh[1]).ToString() + "." + ((int)bbh[2]).ToString() + "." + ((int)bbh[3]).ToString();
|
SystemOperationView.systemOperationViewModel.VersionQueryData = ((int)bbh[0]).ToString() + "." + ((int)bbh[1]).ToString() + "." + ((int)bbh[2]).ToString() + "." + ((int)bbh[3]).ToString();
|
||||||
|
_message += " 版本号:" + SystemOperationView.systemOperationViewModel.VersionQueryData;
|
||||||
|
ReceiveValueChangedChanged(null, _message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//设备回复文件数据指令
|
//设备回复文件数据指令
|
||||||
case 0x66:
|
case 0x66:
|
||||||
int _start = Convert.ToInt32(byteList[6].ToString("X2") + byteList[7].ToString("X2") + byteList[8].ToString("X2") + byteList[9].ToString("X2"), 16);
|
int _start = Convert.ToInt32(byteList[6].ToString("X2") + byteList[7].ToString("X2") + byteList[8].ToString("X2") + byteList[9].ToString("X2"), 16);
|
||||||
int _Length = Convert.ToInt32(byteList[10].ToString("X2") + byteList[11].ToString("X2"), 16);
|
int _Length = Convert.ToInt32(byteList[10].ToString("X2") + byteList[11].ToString("X2"), 16);
|
||||||
systemOperationView._send(_start, _Length);
|
systemOperationView._send(_start, _Length);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//校时
|
||||||
|
case 0x06:
|
||||||
|
//UTC时间
|
||||||
|
dt = startTime.AddSeconds(Convert.ToInt32(byteList[6].ToString("X2") + byteList[7].ToString("X2") + byteList[8].ToString("X2") + byteList[9].ToString("X2"), 16));
|
||||||
|
if ((time_DataBase - dt).TotalMinutes < 60)
|
||||||
|
{
|
||||||
|
_message = "系统校时成功";
|
||||||
|
ReceiveValueChangedChanged(null, _message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_message = "系统校时失败";
|
||||||
|
ReceiveValueChangedChanged(null, _message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -230,6 +230,28 @@ namespace MonitoringTechnology.Common
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
/// 16进制原码字符串转字节数组
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hexString">"AABBCC"或"AA BB CC"格式的字符串</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static byte[] ConvertHexStringToBytes(string hexString)
|
||||||
|
{
|
||||||
|
hexString = hexString.Replace(" ", "");
|
||||||
|
if (hexString.Length % 2 != 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("参数长度不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] returnBytes = new byte[hexString.Length / 2];
|
||||||
|
for (int i = 0; i < returnBytes.Length; i++)
|
||||||
|
{
|
||||||
|
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<bool> O_C(string o_c)
|
public static List<bool> O_C(string o_c)
|
||||||
{
|
{
|
||||||
List<bool> result = new List<bool>();
|
List<bool> result = new List<bool>();
|
||||||
|
|||||||
@ -104,6 +104,8 @@
|
|||||||
Click="buttonSend_Click" Template="{StaticResource ButtonTemplate}"/>
|
Click="buttonSend_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||||
<Button Grid.Column="7" x:Name="buttonRead" Content="读取名称" Width="90" Height="30" Margin="10,-2,10,6"
|
<Button Grid.Column="7" x:Name="buttonRead" Content="读取名称" Width="90" Height="30" Margin="10,-2,10,6"
|
||||||
Click="buttonRead_Click" Template="{StaticResource ButtonTemplate}"/>
|
Click="buttonRead_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||||
|
<Button Grid.Column="8" x:Name="TimeCheck" Content="系统校时" Width="90" Height="30" Margin="10,-2,10,6"
|
||||||
|
Click="TimeCheck_Click" Template="{StaticResource ButtonTemplate}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Label Grid.Row="1" Content="日志记录" Foreground="White"/>
|
<Label Grid.Row="1" Content="日志记录" Foreground="White"/>
|
||||||
<!-- Log区,禁止 ListBox 横向滚动 TextBlock 才能实现自动换行 -->
|
<!-- Log区,禁止 ListBox 横向滚动 TextBlock 才能实现自动换行 -->
|
||||||
|
|||||||
@ -141,6 +141,17 @@ namespace MonitoringTechnology.Views
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 系统校时
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void TimeCheck_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||||
|
send_port_time(Convert.ToInt64(ts.TotalSeconds).ToString("X2"));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 收数据
|
/// 收数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -151,6 +162,16 @@ namespace MonitoringTechnology.Views
|
|||||||
AddLog($"收到数据 <<< {args.ToHex()}");
|
AddLog($"收到数据 <<< {args.ToHex()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义数据显示功能 --数据解析
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
private void BleDevice_ReceiveValueChanged(GattCharacteristic sender, string data)
|
||||||
|
{
|
||||||
|
AddLog($"{data}");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连接按钮
|
/// 连接按钮
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -322,7 +343,7 @@ namespace MonitoringTechnology.Views
|
|||||||
bool success = await systemOperationViewModel.BleDevice.Write(_send);
|
bool success = await systemOperationViewModel.BleDevice.Write(_send);
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
AddLog("版本查询指令发送成功");
|
AddLog("已发送版本查询指令,请稍等!");
|
||||||
PreservationData(_send.ToList(), "版本查询指令");
|
PreservationData(_send.ToList(), "版本查询指令");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -406,7 +427,7 @@ namespace MonitoringTechnology.Views
|
|||||||
bool success = await systemOperationViewModel.BleDevice.Write(_send);
|
bool success = await systemOperationViewModel.BleDevice.Write(_send);
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
AddLog("版本升级指令发送成功");
|
AddLog("已发送版本升级指令,请稍等!");
|
||||||
PreservationData(_send.ToList(), "版本升级指令");
|
PreservationData(_send.ToList(), "版本升级指令");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -423,8 +444,9 @@ namespace MonitoringTechnology.Views
|
|||||||
public SystemOperationView(BleDevice device) : this()
|
public SystemOperationView(BleDevice device) : this()
|
||||||
{
|
{
|
||||||
systemOperationViewModel.BleDevice = device;
|
systemOperationViewModel.BleDevice = device;
|
||||||
systemOperationViewModel.BleDevice.CharacteristicValueChanged += BleDevice_CharacteristicValueChanged;
|
systemOperationViewModel.BleDevice.CharacteristicValueChanged += BleDevice_CharacteristicValueChanged;//收数据
|
||||||
systemOperationViewModel.BleDevice.ConnectionStateChanged += BleDevice_ConnectionStateChanged;
|
systemOperationViewModel.BleDevice.ConnectionStateChanged += BleDevice_ConnectionStateChanged;//连接变化
|
||||||
|
systemOperationViewModel.BleDevice.ReceiveValueChanged += BleDevice_ReceiveValueChanged;//自定义数据显示功能
|
||||||
DataContext = systemOperationViewModel;
|
DataContext = systemOperationViewModel;
|
||||||
isSelect = true;//已选择蓝牙设备
|
isSelect = true;//已选择蓝牙设备
|
||||||
if (device.IsConnected == true)
|
if (device.IsConnected == true)
|
||||||
@ -461,6 +483,37 @@ namespace MonitoringTechnology.Views
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时间同步
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time"></param>
|
||||||
|
public async void send_port_time(string time)
|
||||||
|
{
|
||||||
|
if (isConnection)
|
||||||
|
{
|
||||||
|
byte[] time_byte = tools.ConvertHexStringToBytes(time);
|
||||||
|
int a = 0xFE + 0xEF + 0x00 + 0x08 + 0x00 + 0x06;
|
||||||
|
for (int i = 0; i < time_byte.Length; i++)
|
||||||
|
{
|
||||||
|
a += time_byte[i];
|
||||||
|
}
|
||||||
|
//取十六进制最低两位
|
||||||
|
a = a & 0xFF;
|
||||||
|
string send_mes = "FEEF00080006" + time + a.ToString("X2") + "16";
|
||||||
|
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||||||
|
//调用发送的那个方法
|
||||||
|
bool success = await systemOperationViewModel.BleDevice.Write(bytea);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
AddLog("时间正在同步中,请稍等!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddLog("请搜索附近蓝牙设备并连接后重试!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// int数组转化为byte数组
|
/// int数组转化为byte数组
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -587,5 +640,7 @@ namespace MonitoringTechnology.Views
|
|||||||
tools.AddLgoToTXT(FileModel.File_Name + FileModel.File_Time.ToString("yyyy-MM-dd") + "日志" + ".txt", FileModel.File_Path + FileModel.File_Time.ToString("yyyy-MM-dd") + @"\", _localtime + " " + type + ": " + rec_16 + "\r\n");
|
tools.AddLgoToTXT(FileModel.File_Name + FileModel.File_Time.ToString("yyyy-MM-dd") + "日志" + ".txt", FileModel.File_Path + FileModel.File_Time.ToString("yyyy-MM-dd") + @"\", _localtime + " " + type + ": " + rec_16 + "\r\n");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user