Skip to content

Commit

Permalink
Add message ‘Q’ support
Browse files Browse the repository at this point in the history
  • Loading branch information
cfrpg committed May 31, 2022
1 parent 792cedf commit dd6fb0a
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 28 deletions.
19 changes: 17 additions & 2 deletions src/SharpBladeFlightAnalyzer/Controls/LogPageControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,35 @@
</TabItem>
<TabItem Header="参数" Width="100" Height="30" >
<ListView x:Name="paramList" ItemsSource="{Binding}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="BorderThickness" Value="0,0,0,1" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="参数" Width="150" DisplayMemberBinding="{Binding Item1}"/>
<GridViewColumn Header="" Width="150" DisplayMemberBinding="{Binding Item2}"/>
<GridViewColumn Header="参数" Width="150" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="" Width="150" DisplayMemberBinding="{Binding Value}"/>
<GridViewColumn Header="系统默认值" Width="150" DisplayMemberBinding="{Binding DisplayedSysDefalut}"/>
<GridViewColumn Header="机型默认值" Width="150" DisplayMemberBinding="{Binding DisplayedAirframeDefault}"/>
</GridView>
</ListView.View>
</ListView>
</TabItem>
<TabItem Header="消息" Width="100" Height="30">
<ListView x:Name="msgList" ItemsSource="{Binding}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="BorderThickness" Value="0,0,0,1" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="等级" Width="150" DisplayMemberBinding="{Binding Level}"/>
<GridViewColumn Header="时间" Width="150" DisplayMemberBinding="{Binding Time,StringFormat={}{0:HH:mm:ss.fff}}"/>
<GridViewColumn Header="来源" Width="100" DisplayMemberBinding="{Binding TagString}"/>
<GridViewColumn Header="消息" Width="400" DisplayMemberBinding="{Binding Message}"/>
</GridView>
</ListView.View>
Expand Down
4 changes: 2 additions & 2 deletions src/SharpBladeFlightAnalyzer/Controls/LogPageControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private void exportAcmiBtn_Click(object sender, RoutedEventArgs e)
(logFile.FormatList["vehicle_attitude"].SubscribedID.Count == 0)
)
{
MessageBox.Show("数据不全");
MessageBox.Show("数据不全", "SharpBladeFlightAnalyzer");
return;
}
DataField[] posData = new DataField[3];
Expand Down Expand Up @@ -359,7 +359,7 @@ private void exportCsvBtn_Click(object sender, RoutedEventArgs e)
(logFile.FormatList["vehicle_attitude"].SubscribedID.Count == 0)
)
{
MessageBox.Show("数据不全");
MessageBox.Show("数据不全", "SharpBladeFlightAnalyzer");
return;
}
DataField[] posData = new DataField[3];
Expand Down
33 changes: 33 additions & 0 deletions src/SharpBladeFlightAnalyzer/LoggedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class LoggedMessage
ulong timestamp;
string message;
DateTime time;
LogTag tag;

public LogLevel Level
{
Expand Down Expand Up @@ -39,6 +40,23 @@ public DateTime Time
{
get { return time; }
}

public LogTag Tag { get => tag; set => tag = value; }

public string TagString
{
get
{
if (Tag != LogTag.notag)
return tag.ToString();
return "";
}
}

public LoggedMessage()
{
tag = LogTag.notag;
}
}

public enum LogLevel:byte
Expand All @@ -52,4 +70,19 @@ public enum LogLevel:byte
INFO = 0x36,
DEBUG = 0x37
}

public enum LogTag : ushort
{
unassigned,
mavlink_handler,
ppk_handler,
camera_handler,
ptp_handler,
serial_handler,
watchdog,
io_service,
cbuf,
ulg,
notag=9999
}
}
4 changes: 3 additions & 1 deletion src/SharpBladeFlightAnalyzer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="1" Grid.Row="1" Stroke="Gray" StrokeThickness="10" StrokeDashArray="3 1.55" RadiusX="20" RadiusY="20"/>
<Path Grid.Column="1" Grid.Row="1" Data="M100,60 100,140 M60,100 140,100" Stroke="Gray" StrokeThickness="10"/>
<Button Grid.Column="1" Grid.Row="1" Background="Transparent" BorderBrush="Transparent" Foreground="Transparent" Style="{DynamicResource ButtonStyle1}" Click="Button_Click"/>
<Button x:Name="loadButton" Grid.Column="1" Grid.Row="1" Background="Transparent" BorderBrush="Transparent" Foreground="Transparent" Style="{DynamicResource ButtonStyle1}" Click="Button_Click"/>
<ProgressBar x:Name="loadProgressBar" HorizontalAlignment="Center" Height="20" VerticalAlignment="Center" Width="300" Grid.Row="1" Grid.ColumnSpan="3" Margin="0" Visibility="Hidden"/>

</Grid>
</local:TabPage>

Expand Down
51 changes: 51 additions & 0 deletions src/SharpBladeFlightAnalyzer/Parameter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharpBladeFlightAnalyzer
{
public class Parameter
{
string name;
float value;
float systemDefaultValue;
float airframeDefaultValue;
string displayedSysDefalut;
string displayedAirframeDefault;

public string Name { get => name; set => name = value; }
public float Value { get => value; set => this.value = value; }
public float SystemDefaultValue
{
get => systemDefaultValue;
set
{
systemDefaultValue = value;
displayedSysDefalut = value.ToString();
}
}
public float AirframeDefaultValue
{
get => airframeDefaultValue;
set
{
airframeDefaultValue = value;
displayedAirframeDefault = value.ToString();
}
}
public string DisplayedSysDefalut { get => displayedSysDefalut; set => displayedSysDefalut = value; }
public string DisplayedAirframeDefault { get => displayedAirframeDefault; set => displayedAirframeDefault = value; }

public Parameter()
{
name = "";
value = 0;
systemDefaultValue = 0;
airframeDefaultValue = 0;
displayedSysDefalut = "";
displayedAirframeDefault = "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<Compile Include="LoggedMessage.cs" />
<Compile Include="MessageFormat.cs" />
<Compile Include="MessageViewModel.cs" />
<Compile Include="Parameter.cs" />
<Compile Include="Polar.cs" />
<Compile Include="Message.cs" />
<Compile Include="ULogFile.cs" />
Expand Down
106 changes: 83 additions & 23 deletions src/SharpBladeFlightAnalyzer/ULogFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;

namespace SharpBladeFlightAnalyzer
{
Expand All @@ -29,7 +30,7 @@ public class ULogFile :IDisposable
//key,value
List<Tuple<string, string>> infomations;
//key,value
List<Tuple<string, float>> parameters;
List<Parameter> parameters;

List<LoggedMessage> messages;

Expand Down Expand Up @@ -76,7 +77,7 @@ public static Dictionary<string, int> TypeSize
}
}

public List<Tuple<string, float>> Parameters
public List<Parameter> Parameters
{
get { return parameters; }
set { parameters = value; }
Expand All @@ -103,7 +104,7 @@ public ULogFile()
FormatList = new Dictionary<string, MessageFormat>();
MessageDict = new Dictionary<int, Message>();
infomations=new List<Tuple<string, string>>();
parameters=new List<Tuple<string, float>>();
parameters=new List<Parameter>();
Messages = new List<LoggedMessage>();
}

Expand Down Expand Up @@ -211,38 +212,71 @@ private bool readMessage()
byte msgtype = reader.ReadByte();
if (reader.BaseStream.Length - reader.BaseStream.Position < size)
return false;
bool res = false;
string errmsg="读取类型为"+msgtype.ToString()+"的消息时发生未知错误";
switch (msgtype)
{
case 66://B
return readFlagBitset(size);
res = readFlagBitset(size);
break;
case 70://F
return readFormatDefinition(size);
res = readFormatDefinition(size);
break;
case 73://I
return readInformation(size);
res = readInformation(size);
break;
case 77://M
return readInformationMulti(size);
res = readInformationMulti(size);
break;
case 80://P
return readParameter(size);
res = readParameter(size, false);
break;
case 81://Q
res = readParameter(size, true);
break;
case 65://A
if(!defEndFlag)
expendDefinition();
return readSubscribe(size);
expendDefinition();
res = readSubscribe(size);
break;
case 82://R
return readUnsubscribe(size);
res = readUnsubscribe(size);
break;
case 68://D
return readLoggedData(size);
res = readLoggedData(size);
break;
case 76://L
if (!defEndFlag)
expendDefinition();
return readLoggedString(size);
res = readLoggedString(size,false);
break;
case 67://C Tagged Logged string message
res = readLoggedString(size, true);
break;
case 83://S
return readSynchronization(size);
res = readSynchronization(size);
break;
case 79://O
return readDropoutMark(size);
res = readDropoutMark(size);
break;
default:
Debug.WriteLine("Unknow message type:{0}.", msgtype);
Debug.WriteLine("Unknow message type:{0},at {1}, size {2}.", msgtype, reader.BaseStream.Position,size);
byte[] tmp= reader.ReadBytes(size);
res = false;
errmsg = "未知日志消息类型:" + msgtype.ToString();
break;
}

if (!res)
{
errmsg = "读取文件时发生错误:" + System.Environment.NewLine + errmsg + System.Environment.NewLine + "是否继续?";
if (MessageBox.Show(errmsg, "SharpBladeFlightAnalyzer", MessageBoxButtons.YesNo) == DialogResult.Yes)
return true;
else
return false;
}

return res;
}
private void expendDefinition()
{
Expand Down Expand Up @@ -385,26 +419,50 @@ private bool readInformationMulti(ushort msglen)
return true;
}

private bool readParameter(ushort msglen)
private bool readParameter(ushort msglen,bool def)
{
Parameter p = new Parameter();
byte defaultType=0;
if(def)
{
defaultType = reader.ReadByte();
}
int keylen = reader.ReadByte();
string key = readASCIIString(keylen);
string keytype = key.Substring(0, key.IndexOf(' '));
string keyname = key.Substring(keytype.Length + 1);
float val=0;
p.Name = key.Substring(keytype.Length + 1);
float v;
switch(keytype)
{
case "int32_t":
val = reader.ReadInt32();
v = reader.ReadInt32();
break;
case "float":
val = reader.ReadSingle();
v = reader.ReadSingle();
break;
default:
Debug.WriteLine("[P]:Unknow parameter type {0}.", keytype);
return false;
}
parameters.Add(new Tuple<string, float>(keyname, val));
if (!def)
{
p.Value = v;
parameters.Add(p);
return true;
}
else
{
for(int i=0;i<parameters.Count;i++)
{
if(parameters[i].Name==p.Name)
{
if ((defaultType & 0x01) != 0)
parameters[i].SystemDefaultValue = v;
if ((defaultType & 0x02) != 0)
parameters[i].AirframeDefaultValue = v;
}
}
}
return true;
}

Expand Down Expand Up @@ -521,10 +579,12 @@ private bool readLoggedData(ushort msglen)
return true;
}

private bool readLoggedString(ushort msglen)
private bool readLoggedString(ushort msglen,bool taged)
{
LoggedMessage msg = new LoggedMessage();
msg.Level = (LogLevel)reader.ReadByte();
if (taged)
msg.Tag = (LogTag)reader.ReadUInt16();
msg.Timestamp = reader.ReadUInt64();
msg.Message = readASCIIString(msglen - 9);
Messages.Add(msg);
Expand Down

0 comments on commit dd6fb0a

Please sign in to comment.