1640 lines
63 KiB
VB.net
1640 lines
63 KiB
VB.net
|
|
Imports System.Reflection
|
|||
|
|
Imports System.Threading
|
|||
|
|
|
|||
|
|
Public Class Form1
|
|||
|
|
|
|||
|
|
Private Shared Log_Data_Len_Max As Int16 = 512
|
|||
|
|
Dim Log_Data As New List(Of Parsing_Data_List) '用于保存文件打开后数据校验通过的日志
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 文件内容中的数据格式
|
|||
|
|
''' </summary>
|
|||
|
|
Enum LOG_DATA_FORMAT
|
|||
|
|
Hand = 0
|
|||
|
|
SN '日志每条数据增加序列号
|
|||
|
|
Len
|
|||
|
|
Len_8 '新增
|
|||
|
|
Check
|
|||
|
|
Date_H '年:5bit 月:5bit 日:5bit
|
|||
|
|
Date_L
|
|||
|
|
Type
|
|||
|
|
Time8B '小时时间戳
|
|||
|
|
Time16B
|
|||
|
|
Time24B
|
|||
|
|
Time32B
|
|||
|
|
Data
|
|||
|
|
End Enum
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 日志数据类型
|
|||
|
|
''' </summary>
|
|||
|
|
Enum log_type
|
|||
|
|
''' <summary>
|
|||
|
|
''' Launcher信息记录
|
|||
|
|
''' </summary>
|
|||
|
|
Launcher = 1
|
|||
|
|
''' <summary>
|
|||
|
|
''' 系统运行信息记录
|
|||
|
|
''' </summary>
|
|||
|
|
SYS_Record
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备通讯记录
|
|||
|
|
''' </summary>
|
|||
|
|
Device_COMM
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备通讯状态记录
|
|||
|
|
''' </summary>
|
|||
|
|
Device_Online
|
|||
|
|
''' <summary>
|
|||
|
|
''' 所有设备状态定期记录 - 暂时还没用
|
|||
|
|
''' </summary>
|
|||
|
|
Global_Parameters
|
|||
|
|
''' <summary>
|
|||
|
|
''' 网络通讯记录 - 暂时还没定
|
|||
|
|
''' </summary>
|
|||
|
|
Net_COMM
|
|||
|
|
''' <summary>
|
|||
|
|
''' 逻辑处理记录 - 暂时还没定
|
|||
|
|
''' </summary>
|
|||
|
|
Logic_Record
|
|||
|
|
|
|||
|
|
End Enum
|
|||
|
|
''' <summary>
|
|||
|
|
''' 日志数据 - Launcher记录信息
|
|||
|
|
''' </summary>
|
|||
|
|
Enum LLauncher
|
|||
|
|
''' <summary>
|
|||
|
|
''' 校验APP
|
|||
|
|
''' </summary>
|
|||
|
|
App_Check = 1
|
|||
|
|
''' <summary>
|
|||
|
|
''' 读取APP
|
|||
|
|
''' </summary>
|
|||
|
|
Read_App
|
|||
|
|
''' <summary>
|
|||
|
|
''' 写Flash
|
|||
|
|
''' </summary>
|
|||
|
|
Write_Flash
|
|||
|
|
''' <summary>
|
|||
|
|
''' 恢复出厂设置
|
|||
|
|
''' </summary>
|
|||
|
|
Factory_Reset
|
|||
|
|
''' <summary>
|
|||
|
|
''' 复位信号源
|
|||
|
|
''' 0x00:软件复位
|
|||
|
|
''' 0x01:上电复位
|
|||
|
|
''' 0x02:看门狗复位
|
|||
|
|
''' 0x03:外部手动复位
|
|||
|
|
''' 0x05:从下电模式唤醒时的复位 - 通过WCHISPTool烧录后的复位
|
|||
|
|
''' </summary>
|
|||
|
|
Reset_Source
|
|||
|
|
''' <summary>
|
|||
|
|
''' Launcher中RCU按键事件
|
|||
|
|
''' 0x01:点按
|
|||
|
|
''' 0x02:长按
|
|||
|
|
''' 0x03:长按松开
|
|||
|
|
''' 0x04:达到恢复出厂设置
|
|||
|
|
''' </summary>
|
|||
|
|
RCUKey_State
|
|||
|
|
End Enum
|
|||
|
|
''' <summary>
|
|||
|
|
''' 日志数据 - 系统运行信息
|
|||
|
|
''' </summary>
|
|||
|
|
Enum LSYS
|
|||
|
|
''' <summary>
|
|||
|
|
''' PHY状态变化记录
|
|||
|
|
''' </summary>
|
|||
|
|
PHY_Change = 1
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备链表信息错误
|
|||
|
|
''' </summary>
|
|||
|
|
DevInfo_Error
|
|||
|
|
''' <summary>
|
|||
|
|
''' 升级状态
|
|||
|
|
''' </summary>
|
|||
|
|
API_State
|
|||
|
|
''' <summary>
|
|||
|
|
''' 网络初始化参数
|
|||
|
|
''' </summary>
|
|||
|
|
NET_ARGC
|
|||
|
|
''' <summary>
|
|||
|
|
''' MQTT参数
|
|||
|
|
''' </summary>
|
|||
|
|
MQTT_ARGC
|
|||
|
|
''' <summary>
|
|||
|
|
''' 网络通讯状态
|
|||
|
|
''' </summary>
|
|||
|
|
NetComm_State
|
|||
|
|
''' <summary>
|
|||
|
|
''' 网络默认参数
|
|||
|
|
''' </summary>
|
|||
|
|
NET_DafaultARGC
|
|||
|
|
''' <summary>
|
|||
|
|
''' APP中RCU按键事件
|
|||
|
|
''' </summary>
|
|||
|
|
RCUKey_State
|
|||
|
|
End Enum
|
|||
|
|
''' <summary>
|
|||
|
|
''' 日志数据 - 设备通讯信息
|
|||
|
|
''' </summary>
|
|||
|
|
Enum LCOMM
|
|||
|
|
''' <summary>
|
|||
|
|
''' 轮询回复数据
|
|||
|
|
''' </summary>
|
|||
|
|
ASK_TO_Reply = 1
|
|||
|
|
''' <summary>
|
|||
|
|
''' RCU下发控制数据
|
|||
|
|
''' </summary>
|
|||
|
|
Send_Control
|
|||
|
|
''' <summary>
|
|||
|
|
''' RCU控制回复数据
|
|||
|
|
''' </summary>
|
|||
|
|
Control_Reply
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备调整波特率
|
|||
|
|
''' </summary>
|
|||
|
|
Adjust_Baud
|
|||
|
|
End Enum
|
|||
|
|
''' <summary>
|
|||
|
|
''' 日志数据 - 所有设备状态信息
|
|||
|
|
''' </summary>
|
|||
|
|
Enum LGlobal
|
|||
|
|
''' <summary>
|
|||
|
|
''' 参数数据
|
|||
|
|
''' </summary>
|
|||
|
|
G_Para = 1
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备数据
|
|||
|
|
''' </summary>
|
|||
|
|
G_Dev
|
|||
|
|
End Enum
|
|||
|
|
|
|||
|
|
Enum LNetComm
|
|||
|
|
N_Send = 1 '网络发送数据
|
|||
|
|
N_Recv '网络接收数据
|
|||
|
|
End Enum
|
|||
|
|
|
|||
|
|
Enum LLogic
|
|||
|
|
L_DebugString = 1 'Debug调试日志
|
|||
|
|
End Enum
|
|||
|
|
|
|||
|
|
|
|||
|
|
Enum LOG_DEV_State
|
|||
|
|
Online = &H1
|
|||
|
|
Offline = &H2
|
|||
|
|
End Enum
|
|||
|
|
''' <summary>
|
|||
|
|
''' BLV设备类型
|
|||
|
|
''' </summary>
|
|||
|
|
Enum BLV_DEVICE_TYPE
|
|||
|
|
|
|||
|
|
RS485_Switch = &H6 'T1开关
|
|||
|
|
RS485_Temp = &H7 'T1温控器
|
|||
|
|
RS485_Card = &HA 'T1插卡取电
|
|||
|
|
RS485_IR_SEND = &HF '红外转发
|
|||
|
|
RS485_RGB_Light = &H12 'RGB灯带
|
|||
|
|
RS485_XiaoBao = &H13 '小宝语音
|
|||
|
|
RS485_Time = &H23 '时间同步
|
|||
|
|
|
|||
|
|
C12Dimming = &H12 'BLV_Cx Dimming设备
|
|||
|
|
C5Music = &H15 'BLV_Cx MUSIC设备
|
|||
|
|
C5IO = &HF1 'BLV_Cx IO设备
|
|||
|
|
PC_TEST = &HF2 'BLV_Cx PC测试
|
|||
|
|
End Enum
|
|||
|
|
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 解析表格排序
|
|||
|
|
''' </summary>
|
|||
|
|
Enum form_grid1
|
|||
|
|
type
|
|||
|
|
sn
|
|||
|
|
data_date
|
|||
|
|
data_time
|
|||
|
|
data_interval_time
|
|||
|
|
data_len
|
|||
|
|
data_content
|
|||
|
|
data_parsing
|
|||
|
|
End Enum
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 数据时间结构
|
|||
|
|
''' </summary>
|
|||
|
|
Class LOG_DATE
|
|||
|
|
Public year As Int32
|
|||
|
|
Public month As Int32
|
|||
|
|
Public day As Int32
|
|||
|
|
Public hour As Int32
|
|||
|
|
Public minute As Int32
|
|||
|
|
Public second As Int32
|
|||
|
|
Public milliscond As Int32
|
|||
|
|
End Class
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 温控器设备数据结构
|
|||
|
|
''' </summary>
|
|||
|
|
Class Device_Temp
|
|||
|
|
Public on_off As Byte '开关机
|
|||
|
|
Public mode As Byte '模式
|
|||
|
|
Public fan As Byte '风速
|
|||
|
|
Public valve As Byte '阀门
|
|||
|
|
Public set_temp As Byte '设置温度
|
|||
|
|
Public indoor_temp As Byte '室内温度
|
|||
|
|
End Class
|
|||
|
|
|
|||
|
|
|
|||
|
|
Class Parsing_Data_List
|
|||
|
|
Public original_data() As Byte
|
|||
|
|
Public type As Byte
|
|||
|
|
Public sn As Byte
|
|||
|
|
Public tick As New LOG_DATE
|
|||
|
|
Public len As Int32
|
|||
|
|
Public interval_time As Int64
|
|||
|
|
Public data() As Byte
|
|||
|
|
Public parsing As String
|
|||
|
|
|
|||
|
|
End Class
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 延时函数
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="Interval">单位:ms</param>
|
|||
|
|
Public Sub delay(ByRef Interval As Double)
|
|||
|
|
Dim time As DateTime = DateTime.Now
|
|||
|
|
Dim Span As Double = Interval * 10000 '因为时间是以100纳秒为单位。
|
|||
|
|
While ((DateTime.Now.Ticks - time.Ticks) < Span)
|
|||
|
|
Application.DoEvents()
|
|||
|
|
End While
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
Public Sub delay_us(ByRef Interval As Double)
|
|||
|
|
Dim time As DateTime = DateTime.Now
|
|||
|
|
Dim Span As Double = Interval * 10 '因为时间是以100纳秒为单位。
|
|||
|
|
While ((DateTime.Now.Ticks - time.Ticks) < Span)
|
|||
|
|
Application.DoEvents()
|
|||
|
|
End While
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 获取设备类型
|
|||
|
|
''' </summary>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Obtaining_The_Device_Type(data As Byte) As String
|
|||
|
|
Dim data_parsing As String
|
|||
|
|
|
|||
|
|
Select Case data
|
|||
|
|
Case BLV_DEVICE_TYPE.C12Dimming
|
|||
|
|
data_parsing = "C12调光设备"
|
|||
|
|
Case BLV_DEVICE_TYPE.C5IO
|
|||
|
|
data_parsing = "C5IO设备"
|
|||
|
|
Case BLV_DEVICE_TYPE.C5Music
|
|||
|
|
data_parsing = "C5Music设备"
|
|||
|
|
Case BLV_DEVICE_TYPE.PC_TEST
|
|||
|
|
data_parsing = "BLV PC TEST"
|
|||
|
|
Case BLV_DEVICE_TYPE.RS485_Card
|
|||
|
|
data_parsing = "RS485 插卡取电"
|
|||
|
|
Case BLV_DEVICE_TYPE.RS485_IR_SEND
|
|||
|
|
data_parsing = "RS485 红外转发"
|
|||
|
|
Case BLV_DEVICE_TYPE.RS485_RGB_Light
|
|||
|
|
data_parsing = "RS485 RGB灯带"
|
|||
|
|
Case BLV_DEVICE_TYPE.RS485_Switch
|
|||
|
|
data_parsing = "RS485 开关"
|
|||
|
|
Case BLV_DEVICE_TYPE.RS485_Temp
|
|||
|
|
data_parsing = "RS485 温控器"
|
|||
|
|
Case BLV_DEVICE_TYPE.RS485_Time
|
|||
|
|
data_parsing = "时间同步"
|
|||
|
|
Case BLV_DEVICE_TYPE.RS485_XiaoBao
|
|||
|
|
data_parsing = "RS485 小宝语音"
|
|||
|
|
Case Else
|
|||
|
|
data_parsing = $"未知设备:{data}"
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
|||
|
|
Using xml As New OpenFileDialog
|
|||
|
|
|
|||
|
|
Dim Myfso() As Byte
|
|||
|
|
xml.Filter = $"流程文件(*.dat)|*.dat"
|
|||
|
|
|
|||
|
|
|
|||
|
|
If xml.ShowDialog() = DialogResult.OK Then
|
|||
|
|
TextBox1.Text = xml.FileName
|
|||
|
|
Console.WriteLine(xml.FileName)
|
|||
|
|
|
|||
|
|
RichTextBox1.Clear()
|
|||
|
|
|
|||
|
|
Grid1.NewFile() '重新新建空间
|
|||
|
|
Grid_Format_initial()
|
|||
|
|
Grid1.AutoRedraw = False
|
|||
|
|
Log_Data.Clear()
|
|||
|
|
|
|||
|
|
|
|||
|
|
'DataGridView1.Rows.Clear()
|
|||
|
|
|
|||
|
|
Myfso = My.Computer.FileSystem.ReadAllBytes(TextBox1.Text)
|
|||
|
|
'Data_string = BitConverter.ToString(Myfso)
|
|||
|
|
'Data_string = Data_string.Replace("-", " ")
|
|||
|
|
'TextBox2.Text = Data_string
|
|||
|
|
|
|||
|
|
Dim file_data As New List(Of Byte())
|
|||
|
|
|
|||
|
|
'MsgBox("I am ok")
|
|||
|
|
|
|||
|
|
file_data = File_Data_Processed(Myfso, RichTextBox1)
|
|||
|
|
|
|||
|
|
'MsgBox("File Open Succ")
|
|||
|
|
|
|||
|
|
Grid1.AutoRedraw = False '禁止刷
|
|||
|
|
File_Data_Parsing_To_List(file_data)
|
|||
|
|
Grid1.AutoRedraw = True
|
|||
|
|
Grid1.Refresh() '加载数据
|
|||
|
|
'MsgBox(BitConverter.ToString(Myfso)) '弹框显示内容
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
End Using
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
Dim g_DataTotalLen As ULong = 0
|
|||
|
|
Dim g_DataProcessingIdx As ULong = 0
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 文件数据处理函数 - 分包,校验
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="file_data"></param>
|
|||
|
|
''' <param name="show_form"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Private Function File_Data_Processed(file_data As Byte(), show_form As RichTextBox) As List(Of Byte())
|
|||
|
|
'Dim sampleArr As String()
|
|||
|
|
|
|||
|
|
Dim data_list As New List(Of Byte())
|
|||
|
|
Dim sampleArr_len As UInt32 = 0
|
|||
|
|
Dim sampleArr_showlen As UInt32 = 0
|
|||
|
|
|
|||
|
|
|
|||
|
|
Dim data_len As UInt16
|
|||
|
|
Dim data_end As Byte
|
|||
|
|
|
|||
|
|
sampleArr_len = file_data.Length
|
|||
|
|
|
|||
|
|
Console.WriteLine("File Data Len:" & sampleArr_len)
|
|||
|
|
|
|||
|
|
' Dim wacth As New Stopwatch
|
|||
|
|
' wacth.Restart() '开启计时
|
|||
|
|
|
|||
|
|
g_DataTotalLen = sampleArr_len
|
|||
|
|
|
|||
|
|
While sampleArr_showlen < sampleArr_len
|
|||
|
|
|
|||
|
|
g_DataProcessingIdx = sampleArr_showlen
|
|||
|
|
|
|||
|
|
|
|||
|
|
If file_data(sampleArr_showlen) = &HA5 And sampleArr_showlen + 3 < sampleArr_len Then '判断文件头
|
|||
|
|
|
|||
|
|
data_len = file_data(sampleArr_showlen + LOG_DATA_FORMAT.Len) Or (file_data(sampleArr_showlen + LOG_DATA_FORMAT.Len_8) << 8) '读取数据长度
|
|||
|
|
|
|||
|
|
If data_len < Log_Data_Len_Max And sampleArr_showlen + data_len - 1 < file_data.Length Then
|
|||
|
|
data_end = file_data(sampleArr_showlen + data_len - 1)
|
|||
|
|
|
|||
|
|
Console.WriteLine($"Data Len :{data_len:d} Data :{data_end:X}")
|
|||
|
|
|
|||
|
|
If sampleArr_showlen + data_len <= sampleArr_len AndAlso file_data(sampleArr_showlen + data_len - 1) = &H5A Then '判断文件尾
|
|||
|
|
|
|||
|
|
Dim data_buff(data_len - 1) As Byte
|
|||
|
|
Dim data_string As String
|
|||
|
|
|
|||
|
|
Array.Copy(file_data, sampleArr_showlen, data_buff, 0, data_len)
|
|||
|
|
|
|||
|
|
If GetSumCheckMod(data_buff, data_len) = &H0 Then
|
|||
|
|
Console.WriteLine("Data Check Succ !\r\n")
|
|||
|
|
|
|||
|
|
'Parsing_a_piece_of_data(data_buff, show_form, DataGridView1)
|
|||
|
|
|
|||
|
|
data_list.Add(data_buff) '保存一份数据,添加到列表中
|
|||
|
|
sampleArr_showlen += data_len '数据偏移
|
|||
|
|
|
|||
|
|
data_string = BitConverter.ToString(data_buff)
|
|||
|
|
data_string = data_string.Replace("-", " ")
|
|||
|
|
Console.WriteLine(data_string)
|
|||
|
|
Else
|
|||
|
|
Console.WriteLine("Data Check Fail !\r\n")
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Else
|
|||
|
|
sampleArr_showlen += 1
|
|||
|
|
Console.WriteLine("Data Len Fail!!! Now Len:" & sampleArr_showlen)
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
'delay_us(1)
|
|||
|
|
|
|||
|
|
Else
|
|||
|
|
sampleArr_showlen += 1
|
|||
|
|
Console.WriteLine("Data Len Error!!! " & sampleArr_showlen)
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Else
|
|||
|
|
sampleArr_showlen += 1
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
End While
|
|||
|
|
|
|||
|
|
' wacth.Stop() '计时结束
|
|||
|
|
' Console.WriteLine($"time span:{wacth.ElapsedMilliseconds}")
|
|||
|
|
|
|||
|
|
|
|||
|
|
Return data_list
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 和校验取余数
|
|||
|
|
''' 求Byte数组的和校验取余数
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="dataPacket">Byte数组</param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function GetSumCheckMod(dataPacket As Byte(), datalen As Byte) As Byte
|
|||
|
|
Dim sum As Integer
|
|||
|
|
For idx = 0 To datalen - 1
|
|||
|
|
sum += dataPacket(idx)
|
|||
|
|
sum = sum And &HFF
|
|||
|
|
Next
|
|||
|
|
Dim sumMod As Byte = &HFF - sum
|
|||
|
|
Return sumMod
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 解析数据格式和内容
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="file_data"></param>
|
|||
|
|
''' <param name="show_form"></param>
|
|||
|
|
Public Sub Parsing_a_piece_of_data(file_data As Byte(), show_form As RichTextBox, show_grid As DataGridView)
|
|||
|
|
|
|||
|
|
Dim data_date As Int32
|
|||
|
|
Dim hour_tick As Int32
|
|||
|
|
Dim hour_temp As Int32
|
|||
|
|
|
|||
|
|
Dim show_string As String
|
|||
|
|
Dim grid As Integer
|
|||
|
|
Dim save_data As New Parsing_Data_List
|
|||
|
|
|
|||
|
|
'添加新行
|
|||
|
|
grid = show_grid.Rows.Add()
|
|||
|
|
grid = show_grid.Rows.Count
|
|||
|
|
grid = grid - 1
|
|||
|
|
|
|||
|
|
save_data.original_data = file_data '保存原始数据
|
|||
|
|
save_data.sn = file_data(LOG_DATA_FORMAT.SN) '数据序列号
|
|||
|
|
save_data.type = file_data(LOG_DATA_FORMAT.Type) '数据类型
|
|||
|
|
hour_temp = file_data(LOG_DATA_FORMAT.Len_8)
|
|||
|
|
save_data.len = (file_data(LOG_DATA_FORMAT.Len) Or (hour_temp << 8)) - LOG_DATA_FORMAT.Data '数据长度
|
|||
|
|
|
|||
|
|
If save_data.len > Log_Data_Len_Max Then
|
|||
|
|
'save_data.len = Log_Data_Len_Max
|
|||
|
|
Return
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
data_date = (file_data(LOG_DATA_FORMAT.Date_L) And &HFF) '记录时间
|
|||
|
|
hour_temp = file_data(LOG_DATA_FORMAT.Date_H)
|
|||
|
|
data_date = data_date Or (hour_temp << 8)
|
|||
|
|
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.sn).Value = save_data.sn
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.type).Value = Parsing_Data_Type(save_data.type)
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.data_len).Value = save_data.len
|
|||
|
|
|
|||
|
|
'错误跳过
|
|||
|
|
Try
|
|||
|
|
'dRow.Cells(form_grid1.sn).Value = data_sn
|
|||
|
|
Catch ex As Exception
|
|||
|
|
' Console.WriteLine($"Error:{ ex.Message}")
|
|||
|
|
End Try
|
|||
|
|
|
|||
|
|
hour_tick = file_data(LOG_DATA_FORMAT.Time8B)
|
|||
|
|
hour_temp = file_data(LOG_DATA_FORMAT.Time16B)
|
|||
|
|
hour_tick = hour_tick Or (hour_temp << 8)
|
|||
|
|
hour_temp = file_data(LOG_DATA_FORMAT.Time24B)
|
|||
|
|
hour_tick = hour_tick Or (hour_temp << 16)
|
|||
|
|
hour_temp = file_data(LOG_DATA_FORMAT.Time32B)
|
|||
|
|
hour_tick = hour_tick Or (hour_temp << 24)
|
|||
|
|
'日期换算
|
|||
|
|
save_data.tick.year = (data_date >> 10) And &H1F
|
|||
|
|
save_data.tick.month = (data_date >> 5) And &H1F
|
|||
|
|
save_data.tick.day = (data_date) And &H1F
|
|||
|
|
|
|||
|
|
|
|||
|
|
save_data.tick.hour = hour_tick \ 3600000
|
|||
|
|
hour_temp = hour_tick Mod 3600000
|
|||
|
|
save_data.tick.minute = hour_temp \ 60000
|
|||
|
|
hour_temp = hour_temp Mod 60000
|
|||
|
|
save_data.tick.second = hour_temp \ 1000
|
|||
|
|
save_data.tick.milliscond = hour_temp Mod 1000
|
|||
|
|
|
|||
|
|
Console.WriteLine($"Data SN:{save_data.sn:d} TYPE:{save_data.type:d} Len:{save_data.len:d} data_date:{data_date:X} hour_tick:{hour_tick:X}")
|
|||
|
|
show_string = $"Data SN:{save_data.sn,-3} TYPE:{save_data.type:d} Len:{save_data.len,-3} data_date:{data_date:X} hour_tick:{hour_tick:X}" & vbCrLf
|
|||
|
|
show_form.SelectionStart = show_form.TextLength
|
|||
|
|
show_form.SelectionColor = Color.Blue
|
|||
|
|
show_form.AppendText(show_string)
|
|||
|
|
|
|||
|
|
show_string = $"20{save_data.tick.year:00}-{save_data.tick.month}-{save_data.tick.day}"
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.data_date).Value = show_string
|
|||
|
|
show_string = $"{save_data.tick.hour:00}:{save_data.tick.minute:00}:{save_data.tick.second:00}.{save_data.tick.milliscond:00}"
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.data_time).Value = show_string
|
|||
|
|
|
|||
|
|
Console.WriteLine($"20{save_data.tick.year:00}-{save_data.tick.month}-{save_data.tick.day} {save_data.tick.hour}:{save_data.tick.minute}:{save_data.tick.second:00} {save_data.tick.milliscond}")
|
|||
|
|
show_string = $"20{save_data.tick.year:00}-{save_data.tick.month}-{save_data.tick.day} {save_data.tick.hour}:{save_data.tick.minute}:{save_data.tick.second:00} [{save_data.tick.milliscond,-4}] :"
|
|||
|
|
show_form.SelectionStart = show_form.TextLength
|
|||
|
|
show_form.SelectionColor = Color.Red
|
|||
|
|
show_form.AppendText(show_string)
|
|||
|
|
|
|||
|
|
Dim copy As UInt16 = save_data.len - 1
|
|||
|
|
Dim parsing_data(copy - 1) As Byte
|
|||
|
|
Dim parsing_string As String
|
|||
|
|
Array.Copy(file_data, LOG_DATA_FORMAT.Data, parsing_data, 0, copy)
|
|||
|
|
|
|||
|
|
save_data.data = parsing_data
|
|||
|
|
parsing_string = BitConverter.ToString(parsing_data)
|
|||
|
|
parsing_string = parsing_string.Replace("-", " ")
|
|||
|
|
|
|||
|
|
Console.WriteLine($"parsing_string:{parsing_string}")
|
|||
|
|
show_string = $"{parsing_string}" & vbCrLf
|
|||
|
|
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.data_content).Value = show_string
|
|||
|
|
|
|||
|
|
'Console.WriteLine(parsing_data.ToString)
|
|||
|
|
'show_string = parsing_data.ToString & vbCrLf
|
|||
|
|
|
|||
|
|
show_form.SelectionStart = show_form.TextLength
|
|||
|
|
show_form.SelectionColor = Color.Black
|
|||
|
|
show_form.AppendText(show_string)
|
|||
|
|
|
|||
|
|
save_data.parsing = Parsing_Data_Content(save_data.type, parsing_data) '解析数据
|
|||
|
|
Console.WriteLine(save_data.parsing)
|
|||
|
|
|
|||
|
|
show_form.SelectionStart = show_form.TextLength
|
|||
|
|
show_form.SelectionColor = Color.Gray
|
|||
|
|
show_form.AppendText(save_data.parsing)
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.data_parsing).Value = save_data.parsing
|
|||
|
|
|
|||
|
|
'将解析后的数据添加到列表中
|
|||
|
|
Log_Data.Add(save_data)
|
|||
|
|
|
|||
|
|
Grid_ADD_LOG_Data(Log_Data, Grid1)
|
|||
|
|
|
|||
|
|
'数据解析完毕,计算时间差
|
|||
|
|
show_grid.Rows(grid).Cells(form_grid1.data_interval_time).Value = Get_Data_Time_Difference(Log_Data)
|
|||
|
|
|
|||
|
|
'DataGridView1.Rows.Add(Parsing_Data_Type(data_type), data_sn.ToString) '添加数据到表格中
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 计算当前数据与上次时间差值,单位:ms
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_list"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Get_Data_Time_Difference(data_list As List(Of Parsing_Data_List)) As Int64
|
|||
|
|
Dim temp_tick As Int64 = 0
|
|||
|
|
Dim temp_time As New LOG_DATE
|
|||
|
|
Dim temp_time2 As New LOG_DATE
|
|||
|
|
Dim temp_num As Int32
|
|||
|
|
|
|||
|
|
temp_num = data_list.Count '获取当前数据列表中有多少条数据
|
|||
|
|
Console.WriteLine($"now list num:{temp_num:00}")
|
|||
|
|
|
|||
|
|
If temp_num >= 2 Then
|
|||
|
|
|
|||
|
|
temp_time.year = data_list(temp_num - 1).tick.year + 2000
|
|||
|
|
|
|||
|
|
If data_list(temp_num - 1).tick.month = 0 Then
|
|||
|
|
temp_time.month = data_list(temp_num - 1).tick.month + 1
|
|||
|
|
Else
|
|||
|
|
temp_time.month = data_list(temp_num - 1).tick.month
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If data_list(temp_num - 1).tick.day = 0 Then
|
|||
|
|
temp_time.day = data_list(temp_num - 1).tick.day + 1
|
|||
|
|
Else
|
|||
|
|
temp_time.day = data_list(temp_num - 1).tick.day
|
|||
|
|
End If
|
|||
|
|
temp_time.hour = data_list(temp_num - 1).tick.hour
|
|||
|
|
temp_time.minute = data_list(temp_num - 1).tick.minute
|
|||
|
|
temp_time.second = data_list(temp_num - 1).tick.second
|
|||
|
|
temp_time.milliscond = data_list(temp_num - 1).tick.milliscond
|
|||
|
|
|
|||
|
|
temp_time2.year = data_list(temp_num - 2).tick.year + 2000
|
|||
|
|
If data_list(temp_num - 2).tick.month = 0 Then
|
|||
|
|
temp_time2.month = data_list(temp_num - 2).tick.month + 1
|
|||
|
|
Else
|
|||
|
|
temp_time2.month = data_list(temp_num - 2).tick.month
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If data_list(temp_num - 2).tick.day = 0 Then
|
|||
|
|
temp_time2.day = data_list(temp_num - 2).tick.day + 1
|
|||
|
|
Else
|
|||
|
|
temp_time2.day = data_list(temp_num - 2).tick.day
|
|||
|
|
End If
|
|||
|
|
temp_time2.hour = data_list(temp_num - 2).tick.hour
|
|||
|
|
temp_time2.minute = data_list(temp_num - 2).tick.minute
|
|||
|
|
temp_time2.second = data_list(temp_num - 2).tick.second
|
|||
|
|
temp_time2.milliscond = data_list(temp_num - 2).tick.milliscond
|
|||
|
|
|
|||
|
|
Console.WriteLine($"时间:{temp_time.year}-{temp_time.month}-{temp_time.day} {temp_time.hour}:{temp_time.minute}:{temp_time.second}.{temp_time.milliscond}")
|
|||
|
|
Console.WriteLine($"时间:{temp_time2.year}-{temp_time2.month}-{temp_time2.day} {temp_time2.hour}:{temp_time2.minute}:{temp_time2.second}.{temp_time2.milliscond}")
|
|||
|
|
Dim temp_date1 As New DateTime(temp_time.year, temp_time.month, temp_time.day, temp_time.hour, temp_time.minute, temp_time.second)
|
|||
|
|
Dim temp_date2 As New DateTime(temp_time2.year, temp_time2.month, temp_time2.day, temp_time2.hour, temp_time2.minute, temp_time2.second)
|
|||
|
|
|
|||
|
|
|
|||
|
|
'Console.WriteLine(temp_date1.ToString())
|
|||
|
|
|
|||
|
|
|
|||
|
|
temp_tick = DateDiff(DateInterval.Second, temp_date2, temp_date1) 'temp_date1 - temp_date2
|
|||
|
|
Console.WriteLine($"时间戳:{temp_tick}s")
|
|||
|
|
temp_tick = temp_tick * 1000 + temp_time.milliscond - temp_time2.milliscond
|
|||
|
|
|
|||
|
|
Console.WriteLine($"时间戳:{temp_tick}ms")
|
|||
|
|
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
|
|||
|
|
Return temp_tick
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
Public Function Get_Data_Time_Difference2(data_list As List(Of Parsing_Data_List), data As Parsing_Data_List) As Int64
|
|||
|
|
Dim temp_tick As Int64 = 0
|
|||
|
|
Dim temp_time As New LOG_DATE
|
|||
|
|
Dim temp_time2 As New LOG_DATE
|
|||
|
|
Dim temp_num As Int32
|
|||
|
|
|
|||
|
|
temp_num = data_list.Count '获取当前数据列表中有多少条数据
|
|||
|
|
Console.WriteLine($"now list num:{temp_num:00}")
|
|||
|
|
|
|||
|
|
If temp_num >= 1 Then
|
|||
|
|
|
|||
|
|
temp_time.year = data.tick.year + 2000
|
|||
|
|
|
|||
|
|
If data.tick.month = 0 Then
|
|||
|
|
temp_time.month = data.tick.month + 1
|
|||
|
|
Else
|
|||
|
|
temp_time.month = data.tick.month
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If data.tick.day = 0 Then
|
|||
|
|
temp_time.day = data.tick.day + 1
|
|||
|
|
Else
|
|||
|
|
temp_time.day = data.tick.day
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
temp_time.hour = data.tick.hour
|
|||
|
|
temp_time.minute = data.tick.minute
|
|||
|
|
temp_time.second = data.tick.second
|
|||
|
|
temp_time.milliscond = data.tick.milliscond
|
|||
|
|
|
|||
|
|
temp_time2.year = data_list(temp_num - 1).tick.year + 2000
|
|||
|
|
If data_list(temp_num - 1).tick.month = 0 Then
|
|||
|
|
temp_time2.month = data_list(temp_num - 1).tick.month + 1
|
|||
|
|
Else
|
|||
|
|
temp_time2.month = data_list(temp_num - 1).tick.month
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If data_list(temp_num - 1).tick.day = 0 Then
|
|||
|
|
temp_time2.day = data_list(temp_num - 1).tick.day + 1
|
|||
|
|
Else
|
|||
|
|
temp_time2.day = data_list(temp_num - 1).tick.day
|
|||
|
|
End If
|
|||
|
|
temp_time2.hour = data_list(temp_num - 1).tick.hour
|
|||
|
|
temp_time2.minute = data_list(temp_num - 1).tick.minute
|
|||
|
|
temp_time2.second = data_list(temp_num - 1).tick.second
|
|||
|
|
temp_time2.milliscond = data_list(temp_num - 1).tick.milliscond
|
|||
|
|
|
|||
|
|
Console.WriteLine($"时间:{temp_time.year}-{temp_time.month}-{temp_time.day} {temp_time.hour}:{temp_time.minute}:{temp_time.second}.{temp_time.milliscond}")
|
|||
|
|
Console.WriteLine($"时间:{temp_time2.year}-{temp_time2.month}-{temp_time2.day} {temp_time2.hour}:{temp_time2.minute}:{temp_time2.second}.{temp_time2.milliscond}")
|
|||
|
|
Dim temp_date1 As New DateTime(temp_time.year, temp_time.month, temp_time.day, temp_time.hour, temp_time.minute, temp_time.second)
|
|||
|
|
Dim temp_date2 As New DateTime(temp_time2.year, temp_time2.month, temp_time2.day, temp_time2.hour, temp_time2.minute, temp_time2.second)
|
|||
|
|
|
|||
|
|
|
|||
|
|
'Console.WriteLine(temp_date1.ToString())
|
|||
|
|
|
|||
|
|
|
|||
|
|
temp_tick = DateDiff(DateInterval.Second, temp_date2, temp_date1) 'temp_date1 - temp_date2
|
|||
|
|
Console.WriteLine($"时间戳:{temp_tick}s")
|
|||
|
|
temp_tick = temp_tick * 1000 + temp_time.milliscond - temp_time2.milliscond
|
|||
|
|
|
|||
|
|
Console.WriteLine($"时间戳:{temp_tick}ms")
|
|||
|
|
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Return temp_tick
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 解析回复数据协议内容
|
|||
|
|
''' </summary>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parses_The_RelayContent_Of_The_Packet(pack_data As Byte(), port As Byte) As String
|
|||
|
|
Dim data_parsing As String = ""
|
|||
|
|
|
|||
|
|
Select Case port
|
|||
|
|
Case 0 'C1F - 485_1轮询端口
|
|||
|
|
|
|||
|
|
Case 1 'C1 - 485_1轮询端口
|
|||
|
|
|
|||
|
|
Case 2 '主动端口数据
|
|||
|
|
|
|||
|
|
Case 3 '目前端口3的数据都属于BUS数据
|
|||
|
|
If Form_C5IO.Parse_RelayData_Protocol_Content(pack_data, data_parsing) = &H0 Then
|
|||
|
|
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 数据类型转化String
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_type"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_Data_Type(data_type As Byte) As String
|
|||
|
|
Dim type_string As String
|
|||
|
|
|
|||
|
|
Select Case data_type
|
|||
|
|
Case log_type.Launcher
|
|||
|
|
type_string = "Launcher信息"
|
|||
|
|
Case log_type.SYS_Record
|
|||
|
|
type_string = "RCU运行信息"
|
|||
|
|
Case log_type.Device_COMM
|
|||
|
|
type_string = "设备通讯"
|
|||
|
|
Case log_type.Device_Online
|
|||
|
|
type_string = "设备通讯状态"
|
|||
|
|
Case log_type.Global_Parameters
|
|||
|
|
type_string = "全局状态"
|
|||
|
|
Case log_type.Net_COMM
|
|||
|
|
type_string = "网络通讯"
|
|||
|
|
Case log_type.Logic_Record
|
|||
|
|
type_string = "逻辑处理"
|
|||
|
|
Case Else
|
|||
|
|
type_string = "类型错误"
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return type_string
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 数据类型是否有效,类型有效返回:0,无效返回:1
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_type"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Judge_Data_Type_Correct(data_type As Byte) As Byte
|
|||
|
|
Dim rev_type As Byte
|
|||
|
|
|
|||
|
|
Select Case data_type
|
|||
|
|
Case log_type.Launcher
|
|||
|
|
rev_type = &H0
|
|||
|
|
Case log_type.SYS_Record
|
|||
|
|
rev_type = &H0
|
|||
|
|
Case log_type.Device_COMM
|
|||
|
|
rev_type = &H0
|
|||
|
|
Case log_type.Device_Online
|
|||
|
|
rev_type = &H0
|
|||
|
|
Case log_type.Global_Parameters
|
|||
|
|
rev_type = &H0
|
|||
|
|
Case log_type.Net_COMM
|
|||
|
|
rev_type = &H0
|
|||
|
|
Case log_type.Logic_Record
|
|||
|
|
rev_type = &H0
|
|||
|
|
Case Else
|
|||
|
|
rev_type = &H1
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return rev_type
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 解析数据内容
|
|||
|
|
''' 按照数据类型来解析,用于加载表格时的数据显示 - 简单的内容解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_Data_Content(data_type As Byte, data_content As Byte()) As String
|
|||
|
|
Dim parsing As String = "无"
|
|||
|
|
|
|||
|
|
Dim dev_temp As New Device_Temp
|
|||
|
|
|
|||
|
|
Select Case data_type
|
|||
|
|
Case log_type.Launcher
|
|||
|
|
parsing = Parsing_LogData_Launcher_Content(data_content)
|
|||
|
|
Case log_type.SYS_Record
|
|||
|
|
parsing = Parsing_LogData_SYS_Record_Content(data_content)
|
|||
|
|
Case log_type.Device_COMM
|
|||
|
|
parsing = Parsing_LogData_Device_COMM_Content(data_content)
|
|||
|
|
Case log_type.Device_Online
|
|||
|
|
parsing = Parsing_LogData_Device_Online_Content(data_content)
|
|||
|
|
Case log_type.Global_Parameters
|
|||
|
|
parsing = Parsing_LogData_Global_Parameters_Content(data_content)
|
|||
|
|
Case log_type.Net_COMM
|
|||
|
|
parsing = Parsing_LogData_Net_COMM_Content(data_content)
|
|||
|
|
Case log_type.Logic_Record
|
|||
|
|
parsing = Parsing_LogData_Logic_Record_Content(data_content)
|
|||
|
|
Case Else
|
|||
|
|
parsing = " 数据类型错误"
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' Launcher类型数据解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_LogData_Launcher_Content(data_content As Byte()) As String
|
|||
|
|
Dim parsing As String
|
|||
|
|
Dim Launcher_type As Byte = data_content(0)
|
|||
|
|
|
|||
|
|
Select Case Launcher_type
|
|||
|
|
Case LLauncher.App_Check
|
|||
|
|
parsing = "校验APP:"
|
|||
|
|
If data_content(1) = &H0 Then
|
|||
|
|
parsing += "相同"
|
|||
|
|
ElseIf data_content(1) = &H1 Then
|
|||
|
|
parsing += "APP版本号不同"
|
|||
|
|
ElseIf data_content(1) = &H2 Then
|
|||
|
|
parsing += "特征区CRC不同"
|
|||
|
|
ElseIf data_content(1) = &H3 Then
|
|||
|
|
parsing += "Flash APP地址错误"
|
|||
|
|
ElseIf data_content(1) = &H4 Then
|
|||
|
|
parsing += "Flash APP数据校验错误"
|
|||
|
|
ElseIf data_content(1) = &H5 Then
|
|||
|
|
parsing += "Flash APP标志未置位"
|
|||
|
|
ElseIf data_content(1) = &H6 Then
|
|||
|
|
parsing += "Flash 特征区的CRC校验错误"
|
|||
|
|
ElseIf data_content(1) = &H7 Then
|
|||
|
|
parsing += "MCU Flash数据校验错误"
|
|||
|
|
ElseIf data_content(1) = &H8 Then
|
|||
|
|
parsing += "MCU Flash的APP标志未置位"
|
|||
|
|
ElseIf data_content(1) = &H9 Then
|
|||
|
|
parsing += "MCU Flash特征区的CRC校验错误"
|
|||
|
|
Else
|
|||
|
|
parsing += "数据错误"
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Case LLauncher.Factory_Reset
|
|||
|
|
parsing = "恢复出厂设置"
|
|||
|
|
If data_content(1) = &H1 Then
|
|||
|
|
parsing += "-成功"
|
|||
|
|
ElseIf data_content(1) = &H2 Then
|
|||
|
|
parsing += "-读取出厂APP失败"
|
|||
|
|
ElseIf data_content(1) = &H3 Then
|
|||
|
|
parsing += "-APP写入失败"
|
|||
|
|
Else
|
|||
|
|
parsing += $"未知状态:{data_content(1):00}"
|
|||
|
|
End If
|
|||
|
|
Case LLauncher.Read_App
|
|||
|
|
parsing = "同步APP"
|
|||
|
|
If data_content(1) = &H0 Then
|
|||
|
|
parsing += "成功"
|
|||
|
|
ElseIf data_content(1) = &H1 Then
|
|||
|
|
parsing += "失败"
|
|||
|
|
Else
|
|||
|
|
parsing += $"未知状态:{data_content(1):00}"
|
|||
|
|
End If
|
|||
|
|
Case LLauncher.Write_Flash
|
|||
|
|
parsing = "写Flash"
|
|||
|
|
Case LLauncher.Reset_Source
|
|||
|
|
If data_content(1) = &H0 Then
|
|||
|
|
parsing = "软件复位"
|
|||
|
|
ElseIf data_content(1) = &H1 Then
|
|||
|
|
parsing = "上电复位"
|
|||
|
|
ElseIf data_content(1) = &H2 Then
|
|||
|
|
parsing = "看门狗超时复位"
|
|||
|
|
ElseIf data_content(1) = &H3 Then
|
|||
|
|
parsing = "外部手动复位"
|
|||
|
|
ElseIf data_content(1) = &H5 Then
|
|||
|
|
parsing = "从下电模式唤醒时的复位"
|
|||
|
|
Else
|
|||
|
|
parsing = $"复位源位置:{data_content(1):00}"
|
|||
|
|
End If
|
|||
|
|
Case LLauncher.RCUKey_State
|
|||
|
|
parsing = "RCU按键状态:"
|
|||
|
|
If data_content(1) = &H0 Then
|
|||
|
|
parsing += "点按"
|
|||
|
|
ElseIf data_content(1) = &H1 Then
|
|||
|
|
parsing += "点按"
|
|||
|
|
ElseIf data_content(1) = &H2 Then
|
|||
|
|
parsing += "长按"
|
|||
|
|
ElseIf data_content(1) = &H3 Then
|
|||
|
|
parsing += "长按松开"
|
|||
|
|
ElseIf data_content(1) = &H4 Then
|
|||
|
|
parsing += "达到恢复出厂设置条件"
|
|||
|
|
Else
|
|||
|
|
parsing += $"未知状态:{data_content(1):00}"
|
|||
|
|
End If
|
|||
|
|
Case Else
|
|||
|
|
parsing = " 数据类型错误"
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 系统运行信息数据解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_LogData_SYS_Record_Content(data_content As Byte()) As String
|
|||
|
|
Dim data_parsing As String
|
|||
|
|
'data_parsing = "系统运行数据解析" & BitConverter.ToString(data_content).Replace("-", " ")
|
|||
|
|
|
|||
|
|
Dim sys_type As Byte = data_content(0)
|
|||
|
|
|
|||
|
|
Try
|
|||
|
|
Select Case sys_type
|
|||
|
|
Case LSYS.PHY_Change
|
|||
|
|
If data_content(1) = &H0 Then
|
|||
|
|
data_parsing = "网线已拔出"
|
|||
|
|
ElseIf data_content(1) = &H1 Then
|
|||
|
|
data_parsing = "网线已插入"
|
|||
|
|
Else
|
|||
|
|
data_parsing = $"PHY状态错误:{data_content(1)}"
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Case LSYS.DevInfo_Error
|
|||
|
|
data_parsing = $"SRAM设备类型:{data_content(1)} 地址:{data_content(2)} 链表信息读取错误"
|
|||
|
|
Case LSYS.API_State
|
|||
|
|
If data_content(1) = &H1 Then
|
|||
|
|
data_parsing = "串口升级 "
|
|||
|
|
ElseIf data_content(1) = &H2 Then
|
|||
|
|
data_parsing = "网络升级 "
|
|||
|
|
Else
|
|||
|
|
data_parsing = "错误升级类型 "
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If data_content(2) = &H1 Then
|
|||
|
|
data_parsing += "写入成功"
|
|||
|
|
ElseIf data_content(2) = &H2 Then
|
|||
|
|
data_parsing += "写入失败"
|
|||
|
|
ElseIf data_content(2) = &H3 Then
|
|||
|
|
data_parsing += "文件块数错误"
|
|||
|
|
ElseIf data_content(2) = &H4 Then
|
|||
|
|
data_parsing += "MD5校验错误"
|
|||
|
|
ElseIf data_content(2) = &H5 Then
|
|||
|
|
data_parsing += "CRC校验错误"
|
|||
|
|
ElseIf data_content(2) = &H6 Then
|
|||
|
|
data_parsing += "跳转Launcher"
|
|||
|
|
Else
|
|||
|
|
data_parsing += "未知状态"
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Case LSYS.NET_ARGC
|
|||
|
|
data_parsing = "网络初始化完成后参数:" & vbCrLf
|
|||
|
|
data_parsing += $"IP : {data_content(1)}.{data_content(2)}.{data_content(3)}.{data_content(4)}" & vbCrLf
|
|||
|
|
data_parsing += $"MAC : {data_content(5)}.{data_content(6)}.{data_content(7)}.{data_content(8)}.{data_content(9)}.{data_content(10)}" & vbCrLf
|
|||
|
|
data_parsing += $"服务器IP : {data_content(11)}.{data_content(12)}.{data_content(13)}.{data_content(14)}" & vbCrLf
|
|||
|
|
data_parsing += $"TFTP服务器IP : {data_content(15)}.{data_content(16)}.{data_content(17)}.{data_content(18)}" & vbCrLf
|
|||
|
|
data_parsing += $"MQTT服务器IP : {data_content(19)}.{data_content(20)}.{data_content(21)}.{data_content(22)}" & vbCrLf
|
|||
|
|
Case LSYS.MQTT_ARGC
|
|||
|
|
data_parsing = "MQTT参数 --- 还没解析"
|
|||
|
|
Case LSYS.NetComm_State
|
|||
|
|
If data_content(1) = &H0 Then
|
|||
|
|
data_parsing = "服务器离线"
|
|||
|
|
ElseIf data_content(1) = &H1 Then
|
|||
|
|
data_parsing = "本地服务器通信正常"
|
|||
|
|
ElseIf data_content(1) = &H2 Then
|
|||
|
|
data_parsing = "云端服务器通信正常"
|
|||
|
|
Else
|
|||
|
|
data_parsing = $"云端通讯状态 - 未知状态"
|
|||
|
|
End If
|
|||
|
|
Case LSYS.NET_DafaultARGC
|
|||
|
|
data_parsing = "网络默认参数:" & vbCrLf
|
|||
|
|
data_parsing += $"IP : {data_content(1)}.{data_content(2)}.{data_content(3)}.{data_content(4)}" & vbCrLf
|
|||
|
|
data_parsing += $"网关 : {data_content(5)}.{data_content(6)}.{data_content(7)}.{data_content(8)}" & vbCrLf
|
|||
|
|
data_parsing += $"子网掩码 : {data_content(9)}.{data_content(10)}.{data_content(11)}.{data_content(12)}" & vbCrLf
|
|||
|
|
data_parsing += $"DNS_IP : {data_content(13)}.{data_content(14)}.{data_content(15)}.{data_content(16)}" & vbCrLf
|
|||
|
|
|
|||
|
|
If data_content(17) = &H1 Then
|
|||
|
|
data_parsing += "该参数是PC工具设置下发的" & vbCrLf
|
|||
|
|
Else
|
|||
|
|
data_parsing += "主机默认参数" & vbCrLf
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If data_content(18) = &H2 Then
|
|||
|
|
data_parsing += "DHCP功能已关闭" & vbCrLf
|
|||
|
|
Else
|
|||
|
|
data_parsing += "DHCP功能已开启" & vbCrLf
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
If data_content(19) = &H1 Then
|
|||
|
|
data_parsing += "使用本地服务器" & vbCrLf
|
|||
|
|
Else
|
|||
|
|
data_parsing += "使用云端服务器" & vbCrLf
|
|||
|
|
End If
|
|||
|
|
Case LSYS.RCUKey_State
|
|||
|
|
data_parsing = "RCU按键状态:"
|
|||
|
|
If data_content(1) = &H1 Then
|
|||
|
|
data_parsing += "点按"
|
|||
|
|
ElseIf data_content(1) = &H2 Then
|
|||
|
|
data_parsing += "长按"
|
|||
|
|
ElseIf data_content(1) = &H3 Then
|
|||
|
|
data_parsing += "长按松开"
|
|||
|
|
ElseIf data_content(1) = &H4 Then
|
|||
|
|
data_parsing += "达到恢复出厂设置条件"
|
|||
|
|
Else
|
|||
|
|
data_parsing += $"未知状态:{data_content(1):00}"
|
|||
|
|
End If
|
|||
|
|
Case Else
|
|||
|
|
data_parsing = $"系统运行信息 类型错误{sys_type}"
|
|||
|
|
End Select
|
|||
|
|
Catch ex As Exception
|
|||
|
|
data_parsing = "数据异常----"
|
|||
|
|
End Try
|
|||
|
|
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备通讯数据解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_LogData_Device_COMM_Content(data_content As Byte()) As String
|
|||
|
|
Dim data_type As Byte = data_content(0)
|
|||
|
|
Dim data_port As Byte = data_content(1)
|
|||
|
|
Dim data_parsing As String = Nothing
|
|||
|
|
Dim data_baud As UInt32
|
|||
|
|
|
|||
|
|
If data_content.Length < 7 Then Return data_parsing '长度不对直接退出
|
|||
|
|
|
|||
|
|
Dim data_buff(data_content.Length - 7) As Byte
|
|||
|
|
|
|||
|
|
Array.Copy(data_content, 6, data_buff, 0, data_content.Length - 6)
|
|||
|
|
|
|||
|
|
data_baud = data_content(5)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(4)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(3)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(2)
|
|||
|
|
|
|||
|
|
Select Case data_type
|
|||
|
|
Case LCOMM.Adjust_Baud
|
|||
|
|
|
|||
|
|
data_baud = data_content(6)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(5)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(4)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(3)
|
|||
|
|
|
|||
|
|
data_parsing = Obtaining_The_Device_Type(data_content(1))
|
|||
|
|
data_parsing += $" 地址:{data_content(2)}"
|
|||
|
|
data_parsing += $" 切换波特率:{data_baud}" & vbCrLf
|
|||
|
|
|
|||
|
|
'2022-07-12 增加切换波特率原因 长度增加4Byte
|
|||
|
|
If data_content.Length = 11 Then
|
|||
|
|
If data_content(7) = &H1 Then
|
|||
|
|
data_parsing += $" 连续通讯失败{data_content(8)}次" & vbCrLf
|
|||
|
|
ElseIf data_content(7) = &H2 Then
|
|||
|
|
|
|||
|
|
data_parsing += $" 通讯百分比达到上限 失败次数:{data_content(8)},记录总包数:{data_content(8)}" & vbCrLf
|
|||
|
|
Else
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Case LCOMM.ASK_TO_Reply
|
|||
|
|
data_parsing = $"Port_{data_port} "
|
|||
|
|
data_parsing += $"Baud:{data_baud} "
|
|||
|
|
data_parsing += "轮询变化:" & BitConverter.ToString(data_buff).Replace("-", " ") & vbCrLf
|
|||
|
|
'Parses_The_RelayContent_Of_The_Packet(data_buff, data_port)
|
|||
|
|
Case LCOMM.Control_Reply
|
|||
|
|
data_parsing = $"Port_{data_port} "
|
|||
|
|
data_parsing += $"Baud:{data_baud} "
|
|||
|
|
data_parsing += "控制回复:" & BitConverter.ToString(data_buff).Replace("-", " ") & vbCrLf
|
|||
|
|
'data_parsing += Parses_The_RelayContent_Of_The_Packet(data_buff, data_port)
|
|||
|
|
Case LCOMM.Send_Control
|
|||
|
|
data_parsing = $"Port_{data_port} "
|
|||
|
|
data_parsing += $"Baud:{data_baud} "
|
|||
|
|
data_parsing += "控制下发:" & BitConverter.ToString(data_buff).Replace("-", " ") & vbCrLf
|
|||
|
|
|
|||
|
|
Case Else
|
|||
|
|
data_parsing = "类型错误:" & BitConverter.ToString(data_content).Replace("-", " ")
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备通讯状态数据解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_LogData_Device_Online_Content(data_content As Byte()) As String
|
|||
|
|
Dim dev_type As Byte = data_content(0)
|
|||
|
|
Dim dev_addr As Byte = data_content(1)
|
|||
|
|
Dim dev_state As Byte = data_content(2)
|
|||
|
|
Dim data_parsing As String
|
|||
|
|
|
|||
|
|
data_parsing = Obtaining_The_Device_Type(dev_type)
|
|||
|
|
|
|||
|
|
data_parsing += $" 地址:{dev_addr} "
|
|||
|
|
If dev_state = LOG_DEV_State.Offline Then
|
|||
|
|
data_parsing += "离线" & vbCrLf
|
|||
|
|
ElseIf dev_state = LOG_DEV_State.Online Then
|
|||
|
|
data_parsing += "在线" & vbCrLf
|
|||
|
|
Else
|
|||
|
|
data_parsing += $"状态错误:{dev_state}" & vbCrLf
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 所有设备状态定期保存数据解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_LogData_Global_Parameters_Content(data_content As Byte()) As String
|
|||
|
|
Dim data_parsing As String
|
|||
|
|
data_parsing = "所有设备状态定期保存数据解析" & BitConverter.ToString(data_content).Replace("-", " ")
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 网络处理记录信息解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_LogData_Net_COMM_Content(data_content As Byte()) As String
|
|||
|
|
Dim data_parsing As String
|
|||
|
|
|
|||
|
|
Dim net_type As Byte = data_content(0)
|
|||
|
|
Dim net_port As UInt16
|
|||
|
|
|
|||
|
|
Select Case net_type
|
|||
|
|
Case LNetComm.N_Recv
|
|||
|
|
Try
|
|||
|
|
data_parsing = $"网络接收数据 SocketId{data_content(1)} "
|
|||
|
|
data_parsing += $"IP:{data_content(2)}.{data_content(3)}.{data_content(4)}.{data_content(5)}"
|
|||
|
|
net_port = data_content(7)
|
|||
|
|
net_port <<= 8
|
|||
|
|
net_port = net_port Or data_content(6)
|
|||
|
|
data_parsing += $"Port:{net_port}"
|
|||
|
|
data_parsing += BitConverter.ToString(data_content, 8).Replace("-", " ")
|
|||
|
|
Catch ex As Exception
|
|||
|
|
data_parsing = "网络数据解析错误:" & BitConverter.ToString(data_content, 1).Replace("-", " ")
|
|||
|
|
End Try
|
|||
|
|
|
|||
|
|
Case LNetComm.N_Send
|
|||
|
|
Try
|
|||
|
|
data_parsing = $"网络发送数据 SocketId{data_content(1)} "
|
|||
|
|
data_parsing += $"IP:{data_content(2)}.{data_content(3)}.{data_content(4)}.{data_content(5)}"
|
|||
|
|
net_port = data_content(7)
|
|||
|
|
net_port <<= 8
|
|||
|
|
net_port = net_port Or data_content(6)
|
|||
|
|
data_parsing += $"Port:{net_port}"
|
|||
|
|
data_parsing += BitConverter.ToString(data_content, 8).Replace("-", " ")
|
|||
|
|
Catch ex As Exception
|
|||
|
|
data_parsing = "网络数据解析错误:" & BitConverter.ToString(data_content, 1).Replace("-", " ")
|
|||
|
|
End Try
|
|||
|
|
|
|||
|
|
Case Else
|
|||
|
|
data_parsing = "网络处理信息记录类型错误"
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 事件处理记录信息解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Parsing_LogData_Logic_Record_Content(data_content As Byte()) As String
|
|||
|
|
Dim data_parsing As String
|
|||
|
|
|
|||
|
|
Dim dataArray() As Byte = data_content.Skip(1).ToArray()
|
|||
|
|
Dim logic_type As Byte = data_content(0)
|
|||
|
|
|
|||
|
|
Select Case logic_type
|
|||
|
|
Case LLogic.L_DebugString
|
|||
|
|
data_parsing = "调试日志 : " & System.Text.Encoding.Default.GetString(dataArray)
|
|||
|
|
Case Else
|
|||
|
|
data_parsing = "事件处理记录信息解析 : " & BitConverter.ToString(data_content).Replace("-", " ")
|
|||
|
|
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
Private Sub Grid_Format_initial()
|
|||
|
|
'新表格控件
|
|||
|
|
With Grid1
|
|||
|
|
|
|||
|
|
.AutoRedraw = False '禁止刷
|
|||
|
|
.Rows = 6 '返回或设置表格的行数
|
|||
|
|
.Cols = 8
|
|||
|
|
.DefaultFont = New Font("Tahoma", 8) '设置字体
|
|||
|
|
.ExtendLastCol = True '设置扩展最后一列的列宽,让表格可以充满控件
|
|||
|
|
.BackColor1 = Color.FromArgb(231, 235, 247)
|
|||
|
|
.GridColor = Color.FromArgb(148, 190, 231)
|
|||
|
|
|
|||
|
|
.Cell(0, 1).Text = "类型"
|
|||
|
|
.Cell(0, 2).Text = "序号"
|
|||
|
|
.Cell(0, 3).Text = "日期"
|
|||
|
|
.Cell(0, 4).Text = "时间"
|
|||
|
|
.Cell(0, 5).Text = "间隔时间(ms)"
|
|||
|
|
.Cell(0, 6).Text = "数据长度"
|
|||
|
|
.Cell(0, 7).Text = "数据内容"
|
|||
|
|
|
|||
|
|
.Column(1).CellType = FlexCell.CellTypeEnum.TextBox
|
|||
|
|
.Column(2).CellType = FlexCell.CellTypeEnum.TextBox
|
|||
|
|
.Column(3).CellType = FlexCell.CellTypeEnum.TextBox
|
|||
|
|
.Column(4).CellType = FlexCell.CellTypeEnum.TextBox
|
|||
|
|
.Column(5).CellType = FlexCell.CellTypeEnum.TextBox
|
|||
|
|
.Column(6).CellType = FlexCell.CellTypeEnum.TextBox
|
|||
|
|
.Column(7).CellType = FlexCell.CellTypeEnum.TextBox
|
|||
|
|
|
|||
|
|
.Column(1).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
|||
|
|
.Column(2).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
|||
|
|
.Column(3).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
|||
|
|
.Column(4).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
|||
|
|
.Column(5).Alignment = FlexCell.AlignmentEnum.CenterCenter
|
|||
|
|
.Column(6).Alignment = FlexCell.AlignmentEnum.CenterCenter '居中对齐
|
|||
|
|
.Column(7).Alignment = FlexCell.AlignmentEnum.LeftCenter '左对齐
|
|||
|
|
|
|||
|
|
.SelectionMode = FlexCell.SelectionModeEnum.ByRow '整行选取
|
|||
|
|
|
|||
|
|
.DisplayRowNumber = True '开启行号
|
|||
|
|
.AutoRedraw = True
|
|||
|
|
.Refresh() '加载数据
|
|||
|
|
|
|||
|
|
End With
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
Public Sub File_Data_Parsing_To_List(file_data As List(Of Byte()))
|
|||
|
|
Dim data_num As Int32 = file_data.Count
|
|||
|
|
|
|||
|
|
Dim hour_tick As Int32
|
|||
|
|
Dim hour_temp As Int32
|
|||
|
|
Dim data_date As Int32
|
|||
|
|
|
|||
|
|
Console.WriteLine($"当前有效数据总包数:{data_num}")
|
|||
|
|
|
|||
|
|
tb_DataLen.Text = data_num
|
|||
|
|
|
|||
|
|
|
|||
|
|
For idx = 0 To data_num - 1
|
|||
|
|
|
|||
|
|
tb_DataProcessingIdx.Text = idx
|
|||
|
|
|
|||
|
|
Dim save_data As New Parsing_Data_List
|
|||
|
|
Dim parsing_string As String
|
|||
|
|
|
|||
|
|
'数据类型及长度等
|
|||
|
|
save_data.original_data = file_data(idx)
|
|||
|
|
save_data.sn = file_data(idx)(LOG_DATA_FORMAT.SN)
|
|||
|
|
save_data.type = file_data(idx)(LOG_DATA_FORMAT.Type)
|
|||
|
|
hour_temp = file_data(idx)(LOG_DATA_FORMAT.Len_8)
|
|||
|
|
save_data.len = (file_data(idx)(LOG_DATA_FORMAT.Len) Or (hour_temp << 8)) - LOG_DATA_FORMAT.Data '数据长度
|
|||
|
|
|
|||
|
|
If save_data.len > Log_Data_Len_Max Then
|
|||
|
|
'save_data.len = Log_Data_Len_Max 数据长度超过数据最大长度
|
|||
|
|
Return
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
'日期
|
|||
|
|
data_date = (file_data(idx)(LOG_DATA_FORMAT.Date_L) And &HFF) '记录时间
|
|||
|
|
hour_temp = file_data(idx)(LOG_DATA_FORMAT.Date_H)
|
|||
|
|
data_date = data_date Or (hour_temp << 8)
|
|||
|
|
|
|||
|
|
hour_tick = file_data(idx)(LOG_DATA_FORMAT.Time8B)
|
|||
|
|
hour_temp = file_data(idx)(LOG_DATA_FORMAT.Time16B)
|
|||
|
|
hour_tick = hour_tick Or (hour_temp << 8)
|
|||
|
|
hour_temp = file_data(idx)(LOG_DATA_FORMAT.Time24B)
|
|||
|
|
hour_tick = hour_tick Or (hour_temp << 16)
|
|||
|
|
hour_temp = file_data(idx)(LOG_DATA_FORMAT.Time32B)
|
|||
|
|
hour_tick = hour_tick Or (hour_temp << 24)
|
|||
|
|
|
|||
|
|
save_data.tick.year = (data_date >> 10) And &H1F
|
|||
|
|
save_data.tick.month = (data_date >> 5) And &H1F
|
|||
|
|
save_data.tick.day = (data_date) And &H1F
|
|||
|
|
|
|||
|
|
'时间
|
|||
|
|
save_data.tick.hour = hour_tick \ 3600000
|
|||
|
|
hour_temp = hour_tick Mod 3600000
|
|||
|
|
save_data.tick.minute = hour_temp \ 60000
|
|||
|
|
hour_temp = hour_temp Mod 60000
|
|||
|
|
save_data.tick.second = hour_temp \ 1000
|
|||
|
|
save_data.tick.milliscond = hour_temp Mod 1000
|
|||
|
|
|
|||
|
|
If save_data.tick.hour >= 24 Then
|
|||
|
|
save_data.tick.hour -= 24
|
|||
|
|
save_data.tick.day += 1
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
'分离文件内容中的数据
|
|||
|
|
Dim copy As UInt16 = save_data.len - 1
|
|||
|
|
Dim parsing_data(copy - 1) As Byte
|
|||
|
|
|
|||
|
|
Array.Copy(file_data(idx), LOG_DATA_FORMAT.Data, parsing_data, 0, copy)
|
|||
|
|
|
|||
|
|
save_data.data = parsing_data
|
|||
|
|
parsing_string = BitConverter.ToString(parsing_data)
|
|||
|
|
parsing_string = parsing_string.Replace("-", " ")
|
|||
|
|
Console.WriteLine($"parsing_string:{parsing_string}")
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.File_Info, parsing_string, Color.Tan)
|
|||
|
|
|
|||
|
|
parsing_string = $"Data SN:{save_data.sn:d} TYPE:{save_data.type:d} Len:{save_data.len:d} data_date:{data_date:X} hour_tick:{hour_tick:X}"
|
|||
|
|
Console.WriteLine(parsing_string)
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.File_Info, parsing_string, Color.SlateGray)
|
|||
|
|
|
|||
|
|
save_data.parsing = Parsing_Data_Content(save_data.type, parsing_data) '解析数据
|
|||
|
|
Console.WriteLine(save_data.parsing)
|
|||
|
|
save_data.interval_time = Get_Data_Time_Difference2(Log_Data, save_data)
|
|||
|
|
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.File_Info, save_data.parsing, Color.Magenta)
|
|||
|
|
|
|||
|
|
'将解析后的数据添加到列表中
|
|||
|
|
Log_Data.Add(save_data)
|
|||
|
|
|
|||
|
|
Grid_ADD_LOG_Data(Log_Data, Grid1)
|
|||
|
|
|
|||
|
|
delay(1)
|
|||
|
|
Next
|
|||
|
|
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 将数据显示到表格中
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_list"></param>
|
|||
|
|
Public Sub Grid_ADD_LOG_Data(data_list As List(Of Parsing_Data_List), show_grid As FlexCell.Grid)
|
|||
|
|
Dim temp_num As Int32
|
|||
|
|
Dim temp_string As String
|
|||
|
|
'将数据对应的序号填充到对应的行号中
|
|||
|
|
|
|||
|
|
If data_list.Count > show_grid.Rows - 1 Then
|
|||
|
|
Console.WriteLine("Grid - 添加新行")
|
|||
|
|
show_grid.AddItem(" ", True) '添加新行
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
temp_num = data_list.Count - 1 '获取当前数据列表中有多少条数据
|
|||
|
|
|
|||
|
|
temp_string = $"List Count:{temp_num} Rows:{show_grid.Rows}"
|
|||
|
|
Console.WriteLine(temp_string)
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.File_Info, temp_string, Color.Blue)
|
|||
|
|
|
|||
|
|
'show_grid.AddItem(" ", True) '添加新行
|
|||
|
|
show_grid.Cell(data_list.Count, form_grid1.type + 1).Text = Parsing_Data_Type(data_list(temp_num).type)
|
|||
|
|
show_grid.Cell(data_list.Count, form_grid1.sn + 1).Text = data_list(temp_num).sn
|
|||
|
|
show_grid.Cell(data_list.Count, form_grid1.data_len + 1).Text = data_list(temp_num).len
|
|||
|
|
temp_string = $"20{data_list(temp_num).tick.year:00}-{data_list(temp_num).tick.month:00}-{data_list(temp_num).tick.day:00}"
|
|||
|
|
show_grid.Cell(data_list.Count, form_grid1.data_date + 1).Text = temp_string
|
|||
|
|
temp_string = $"{data_list(temp_num).tick.hour:00}:{data_list(temp_num).tick.minute:00}:{data_list(temp_num).tick.second:00}.{data_list(temp_num).tick.milliscond:000}"
|
|||
|
|
show_grid.Cell(data_list.Count, form_grid1.data_time + 1).Text = temp_string
|
|||
|
|
show_grid.Cell(data_list.Count, form_grid1.data_interval_time + 1).Text = data_list(temp_num).interval_time
|
|||
|
|
show_grid.Cell(data_list.Count, form_grid1.data_content + 1).Text = data_list(temp_num).parsing
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 设备通讯数据解析 - 同时解析设备通讯数据内容,用于显示在界面"数据详细"
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Expatiation_Parsing_LogData_Device_COMM_Content(data_content As Byte()) As String
|
|||
|
|
Dim data_type As Byte = data_content(0)
|
|||
|
|
Dim data_port As Byte = data_content(1)
|
|||
|
|
Dim data_parsing As String
|
|||
|
|
Dim data_baud As UInt32
|
|||
|
|
Dim data_buff(data_content.Length - 7) As Byte
|
|||
|
|
|
|||
|
|
Array.Copy(data_content, 6, data_buff, 0, data_content.Length - 6)
|
|||
|
|
|
|||
|
|
data_baud = data_content(5)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(4)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(3)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(2)
|
|||
|
|
|
|||
|
|
Select Case data_type
|
|||
|
|
Case LCOMM.Adjust_Baud
|
|||
|
|
|
|||
|
|
data_baud = data_content(6)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(5)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(4)
|
|||
|
|
data_baud = (data_baud << 8) Or data_content(3)
|
|||
|
|
|
|||
|
|
data_parsing = Obtaining_The_Device_Type(data_content(1))
|
|||
|
|
data_parsing += $" 地址:{data_content(2)}"
|
|||
|
|
data_parsing += $" 切换波特率:{data_baud}" & vbCrLf
|
|||
|
|
Case LCOMM.ASK_TO_Reply
|
|||
|
|
data_parsing = $"Port_{data_port} "
|
|||
|
|
data_parsing += $"Baud:{data_baud} "
|
|||
|
|
data_parsing += "轮询变化:" & BitConverter.ToString(data_buff).Replace("-", " ") & vbCrLf
|
|||
|
|
data_parsing += Parses_The_RelayContent_Of_The_Packet(data_buff, data_port)
|
|||
|
|
Case LCOMM.Control_Reply
|
|||
|
|
data_parsing = $"Port_{data_port} "
|
|||
|
|
data_parsing += $"Baud:{data_baud} "
|
|||
|
|
data_parsing += "控制回复:" & BitConverter.ToString(data_buff).Replace("-", " ") & vbCrLf
|
|||
|
|
data_parsing += Parses_The_RelayContent_Of_The_Packet(data_buff, data_port)
|
|||
|
|
Case LCOMM.Send_Control
|
|||
|
|
data_parsing = $"Port_{data_port} "
|
|||
|
|
data_parsing += $"Baud:{data_baud} "
|
|||
|
|
data_parsing += "控制下发:" & BitConverter.ToString(data_buff).Replace("-", " ") & vbCrLf
|
|||
|
|
|
|||
|
|
Case Else
|
|||
|
|
data_parsing = "类型错误:" & BitConverter.ToString(data_content).Replace("-", " ")
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return data_parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 详细解析数据内容
|
|||
|
|
''' 按照数据类型来解析,用于点击表格中行时的显示详细的内容解析
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="data_type"></param>
|
|||
|
|
''' <param name="data_content"></param>
|
|||
|
|
''' <returns></returns>
|
|||
|
|
Public Function Expatiation_Parsing_Data_Content(data_type As Byte, data_content As Byte()) As String
|
|||
|
|
Dim parsing As String = "无"
|
|||
|
|
|
|||
|
|
Dim dev_temp As New Device_Temp
|
|||
|
|
|
|||
|
|
Select Case data_type
|
|||
|
|
Case log_type.Launcher
|
|||
|
|
parsing = Parsing_LogData_Launcher_Content(data_content)
|
|||
|
|
Case log_type.SYS_Record
|
|||
|
|
parsing = Parsing_LogData_SYS_Record_Content(data_content)
|
|||
|
|
Case log_type.Device_COMM
|
|||
|
|
parsing = Expatiation_Parsing_LogData_Device_COMM_Content(data_content)
|
|||
|
|
Case log_type.Device_Online
|
|||
|
|
parsing = Parsing_LogData_Device_Online_Content(data_content)
|
|||
|
|
Case log_type.Global_Parameters
|
|||
|
|
parsing = Parsing_LogData_Global_Parameters_Content(data_content)
|
|||
|
|
Case log_type.Net_COMM
|
|||
|
|
parsing = Parsing_LogData_Net_COMM_Content(data_content)
|
|||
|
|
Case log_type.Logic_Record
|
|||
|
|
parsing = Parsing_LogData_Logic_Record_Content(data_content)
|
|||
|
|
Case Else
|
|||
|
|
parsing = "数据类型错误"
|
|||
|
|
End Select
|
|||
|
|
|
|||
|
|
Return parsing
|
|||
|
|
End Function
|
|||
|
|
|
|||
|
|
''' <summary>
|
|||
|
|
''' 在表格行头添加序号 - 通过行状态变化事件
|
|||
|
|
''' </summary>
|
|||
|
|
''' <param name="sender"></param>
|
|||
|
|
''' <param name="e"></param>
|
|||
|
|
Private Sub DataGridView1_RowStateChanged(sender As Object, e As DataGridViewRowStateChangedEventArgs)
|
|||
|
|
e.Row.HeaderCell.Value = (e.Row.Index + 1).ToString() '添加序号
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
|
|||
|
|
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
|
|||
|
|
If CheckBox1.Checked Then
|
|||
|
|
SplitContainer1.Panel2Collapsed = False
|
|||
|
|
Else
|
|||
|
|
SplitContainer1.Panel2Collapsed = True
|
|||
|
|
End If
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
|
|||
|
|
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
|
|||
|
|
If CheckBox2.Checked Then
|
|||
|
|
SplitContainer2.Panel2Collapsed = False
|
|||
|
|
Else
|
|||
|
|
SplitContainer2.Panel2Collapsed = True
|
|||
|
|
End If
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|||
|
|
|
|||
|
|
Me.Text = "数据解析工具(" & Application.ProductVersion & ")"
|
|||
|
|
|
|||
|
|
'是否折叠文件解析 显示页面
|
|||
|
|
If CheckBox1.Checked Then
|
|||
|
|
SplitContainer1.Panel2Collapsed = False
|
|||
|
|
Else
|
|||
|
|
SplitContainer1.Panel2Collapsed = True
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Grid_Format_initial()
|
|||
|
|
|
|||
|
|
Form_C5IO.Get_C5IO_TextBox_Name()
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
|
|||
|
|
Form_C5IO.Save_C5IO_TextBox_Name()
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
Private Sub Grid1_RowColChange(Sender As Object, e As FlexCell.Grid.RowColChangeEventArgs) Handles Grid1.RowColChange
|
|||
|
|
Console.WriteLine($"Grid1_RowColChange Rows:{Grid1.ActiveCell.IntegerValue}") '当前选中的单元格的内容
|
|||
|
|
Console.WriteLine($"Grid1_RowColChange Rows:{Grid1.ActiveCell.Row}") '当前选中单元格的行
|
|||
|
|
|
|||
|
|
'取当前行号,到日志数据列表中取日志数据内容,重新解析一下
|
|||
|
|
|
|||
|
|
'遇到问题,重新打开文件时,这事件会进入,然后队列溢出了
|
|||
|
|
|
|||
|
|
'If Grid1.ActiveCell.Row = 0 Then
|
|||
|
|
' MsgBox("Grid1_RowColChange ERROR") '弹框显示内容
|
|||
|
|
' Return
|
|||
|
|
'End If
|
|||
|
|
|
|||
|
|
'If Log_Data.Count = 0 Then
|
|||
|
|
' MsgBox("LOG_DATA ERROR") '弹框显示内容
|
|||
|
|
' Return
|
|||
|
|
'End If
|
|||
|
|
|
|||
|
|
'Dim row_num As Int64 = Grid1.ActiveCell.Row
|
|||
|
|
'Dim row_data As Byte() = Log_Data(Grid1.ActiveCell.Row - 1).data
|
|||
|
|
'Dim row_parsing As String = "Grid1_Row Data:" & BitConverter.ToString(row_data).Replace("-", " ") & vbCrLf
|
|||
|
|
|
|||
|
|
'Console.WriteLine(row_parsing)
|
|||
|
|
|
|||
|
|
Try
|
|||
|
|
Dim row_num As Int64 = Grid1.ActiveCell.Row - 1 '取当前选中行在队列中的序号
|
|||
|
|
Dim row_parsing As String = "Grid1_Row Data:" & BitConverter.ToString(Log_Data(row_num).data).Replace("-", " ") & vbCrLf
|
|||
|
|
|
|||
|
|
BLV_INFO.Debug_Display_Clear(DEBUG_WIN.Content_Info)
|
|||
|
|
|
|||
|
|
'调取该行的信息显示在调试框中
|
|||
|
|
row_parsing = "日志原始数据:" & BitConverter.ToString(Log_Data(row_num).original_data).Replace("-", " ")
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.Content_Info, row_parsing, Color.Black)
|
|||
|
|
|
|||
|
|
row_parsing = $"<序号>:{Log_Data(row_num).sn}" & vbTab
|
|||
|
|
|
|||
|
|
row_parsing += "<类型>:" & Parsing_Data_Type(Log_Data(row_num).type) & vbTab
|
|||
|
|
|
|||
|
|
row_parsing += $"<日志长度>:{Log_Data(row_num).len}" & vbTab
|
|||
|
|
|
|||
|
|
row_parsing += "<时间>:" & $"20{Log_Data(row_num).tick.year:00}-{Log_Data(row_num).tick.month:00}-{Log_Data(row_num).tick.day:00} " & $"{Log_Data(row_num).tick.hour:00}:{Log_Data(row_num).tick.minute:00}:{Log_Data(row_num).tick.second:00}.{Log_Data(row_num).tick.milliscond:000}"
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.Content_Info, row_parsing, Color.Black)
|
|||
|
|
|
|||
|
|
|
|||
|
|
row_parsing = $"<间隔时间>:{Log_Data(row_num).interval_time}" & "ms"
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.Content_Info, row_parsing, Color.Black)
|
|||
|
|
|
|||
|
|
row_parsing = "<记录内容>:" & BitConverter.ToString(Log_Data(row_num).data).Replace("-", " ") & vbCrLf
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.Content_Info, row_parsing, Color.Black)
|
|||
|
|
|
|||
|
|
If Log_Data(row_num).type = log_type.Device_COMM Then
|
|||
|
|
|
|||
|
|
'同时将解析的数据通过控件显示出来
|
|||
|
|
'TabControl1.TabPages.Clear()
|
|||
|
|
|
|||
|
|
'Dim tab_page As TabPage = New TabPage("C5IO")
|
|||
|
|
'Dim tab_page2 As TabPage = New TabPage("C5Music")
|
|||
|
|
'Dim tab_page3 As TabPage = New TabPage("温控器")
|
|||
|
|
|
|||
|
|
'tab_page.Controls.Add(Form_C5IO.Panel1)
|
|||
|
|
'Form_C5IO.Panel1.Dock = DockStyle.Fill
|
|||
|
|
'TabControl1.TabPages.Add(tab_page)
|
|||
|
|
|
|||
|
|
'tab_page2.Controls.Add(Form_C5Music.Panel1)
|
|||
|
|
'Form_C5Music.Panel1.Dock = DockStyle.Fill
|
|||
|
|
'TabControl1.TabPages.Add(tab_page2)
|
|||
|
|
|
|||
|
|
'tab_page3.Controls.Add(Form_DevTemp.Panel1)
|
|||
|
|
'Form_DevTemp.Panel1.Dock = DockStyle.Fill
|
|||
|
|
'TabControl1.TabPages.Add(tab_page3)
|
|||
|
|
|
|||
|
|
'如果当前日志数据是通讯数据的话,需要解析串口数据并显示出来
|
|||
|
|
row_parsing = "解析串口数据 内容详细:" & Expatiation_Parsing_Data_Content(log_type.Device_COMM, Log_Data(row_num).data)
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.Content_Info, row_parsing, Color.Black)
|
|||
|
|
|
|||
|
|
|
|||
|
|
ElseIf Log_Data(row_num).type = log_type.SYS_Record Then
|
|||
|
|
row_parsing = "内容详细:" & Log_Data(row_num).parsing
|
|||
|
|
BLV_INFO.Debug_Info_Display_On_Window(DEBUG_WIN.Content_Info, row_parsing, Color.Black)
|
|||
|
|
Else
|
|||
|
|
'如果是其他数据,直接显示解析的内容
|
|||
|
|
|
|||
|
|
End If
|
|||
|
|
|
|||
|
|
Console.WriteLine(row_parsing)
|
|||
|
|
Catch ex As Exception
|
|||
|
|
Console.WriteLine("Grid1_RowColChange ERROR")
|
|||
|
|
End Try
|
|||
|
|
|
|||
|
|
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
|
|||
|
|
If RichTextBox1.TextLength >= 1000000 Then RichTextBox1.Clear()
|
|||
|
|
End Sub
|
|||
|
|
|
|||
|
|
|
|||
|
|
End Class
|
|||
|
|
|
|||
|
|
|
|||
|
|
|