Skip to content

Commit

Permalink
Add .mavlink to .json log file converter (in MavLinkTest)
Browse files Browse the repository at this point in the history
Fix bugs in MavLinkLog read method.
Add unit test for this.
Beginnings of json support in LogViewer (not done yet).
  • Loading branch information
lovettchris committed Mar 18, 2017
1 parent 4073615 commit 4b2b612
Show file tree
Hide file tree
Showing 16 changed files with 13,422 additions and 317 deletions.
5 changes: 5 additions & 0 deletions LogViewer/LogViewer/LogViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
<HintPath>..\packages\Microsoft.Maps.MapControl.WPF.1.0.0.3\lib\net40-Client\Microsoft.Maps.MapControl.WPF.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
Expand Down Expand Up @@ -138,6 +142,7 @@
<Compile Include="Model\ChartModels.cs" />
<Compile Include="Model\CsvDataLog.cs" />
<Compile Include="Model\IDataLog.cs" />
<Compile Include="Model\JSonDataLog.cs" />
<Compile Include="Model\MavlinkLog.cs" />
<Compile Include="Model\Px4DataLog.cs" />
<Compile Include="Utilities\ColorExtensions.cs" />
Expand Down
119 changes: 66 additions & 53 deletions LogViewer/LogViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public MainWindow()
ChartStack.Visibility = Visibility.Collapsed;
initialAttitude = ModelViewer.ModelAttitude;
CameraPanel.Visibility = Visibility.Collapsed;
SystemConsole.Visibility = Visibility.Collapsed;
SystemConsole.Visibility = Visibility.Collapsed;
}

private void OnWindowLocationChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -109,7 +109,7 @@ private async void OnChannelConnected(object sender, EventArgs e)
ConnectorControl.Connected = true;

QuadButton.IsChecked = true;

var channel = ConnectionPanel.Channel;
channel.MessageReceived += OnMavlinkMessageReceived;

Expand Down Expand Up @@ -298,7 +298,7 @@ private void ShowImage(byte[] image)

private void OnChannelDisconnected(object sender, EventArgs e)
{
ConnectorControl.Connected = false;
ConnectorControl.Connected = false;
SystemConsole.Channel = null;
}

Expand All @@ -313,7 +313,7 @@ private async void OnOpenFile(object sender, RoutedEventArgs e)
OpenButton.IsEnabled = false;

Microsoft.Win32.OpenFileDialog fo = new Microsoft.Win32.OpenFileDialog();
fo.Filter = "PX4 Log Files (*.px4log)|*.px4log|CSV Files (*.csv)|*.csv|bin files (*.bin)|*.bin|mavlink files (*.mavlink)|*.mavlink";
fo.Filter = "PX4 Log Files (*.px4log)|*.px4log|CSV Files (*.csv)|*.csv|bin files (*.bin)|*.bin|mavlink files (*.mavlink)|*.mavlink|JSON files (*.json)|*.json";
fo.CheckFileExists = true;
fo.Multiselect = true;
if (fo.ShowDialog() == true)
Expand All @@ -334,17 +334,20 @@ private async void OnOpenFile(object sender, RoutedEventArgs e)
case ".mavlink":
await Task.Run(async () => { await LoadMavlinkFile(file); });
break;
case ".json":
await Task.Run(async () => { await LoadJSonFile(file); });
break;
default:
MessageBox.Show("Do not know how to read files of type : " + System.IO.Path.GetExtension(file),
"Unsupported file extension", MessageBoxButton.OK, MessageBoxImage.Exclamation);
break;
}
}
}
}
OpenButton.IsEnabled = true;
}

private async Task LoadBinaryFile(string file)
private async Task LoadJSonFile(string file)
{
try
{
Expand All @@ -355,37 +358,40 @@ private async Task LoadBinaryFile(string file)
AppendMessage("Loading " + file);
ShowStatus("Loading " + file);

Px4DataLog data = new Px4DataLog();
JSonDataLog data = new JSonDataLog();
await data.Load(file, progress);

logs.Add(data);
//logs.Add(data);
ShowSchema();

LoadFlights(data);

}
catch (Exception ex)
{
AppendMessage("### Error loading json file: " + ex.Message);
}
ShowStatus("Done Loading " + file);
UpdateButtons();
}

private async Task LoadBinaryFile(string file)
{
try
{
UiDispatcher.RunOnUIThread(() =>
{
// add flights
Flight entireLog = new Flight()
{
Name = "Log " + logs.Count,
StartTime = data.StartTime,
Duration = data.Duration
};
allFlights.Add(entireLog);

foreach (var flight in data.GetFlights())
{
flight.Name = "Flight " + allFlights.Count;
allFlights.Add(flight);
AppendMessage("Motor started at {0} and ran for {1} ", flight.StartTime, flight.Duration);
}
SystemConsole.Show();
});
AppendMessage("Loading " + file);
ShowStatus("Loading " + file);

if (myMap.Visibility == Visibility.Visible)
{
ShowMap();
}
Px4DataLog data = new Px4DataLog();
await data.Load(file, progress);

ShowTotalFlightTime();
});
logs.Add(data);
ShowSchema();
LoadFlights(data);

// remember successfully loaded log file.
Settings settings = await ((App)App.Current).LoadSettings();
Expand All @@ -400,6 +406,36 @@ private async Task LoadBinaryFile(string file)
UpdateButtons();
}

private void LoadFlights(IDataLog data)
{
UiDispatcher.RunOnUIThread(() =>
{
// add flights
Flight entireLog = new Flight()
{
Name = "Log " + logs.Count,
StartTime = data.StartTime,
Duration = data.Duration
};
allFlights.Add(entireLog);

foreach (var flight in data.GetFlights())
{
flight.Name = "Flight " + allFlights.Count;
allFlights.Add(flight);
AppendMessage("Motor started at {0} and ran for {1} ", flight.StartTime, flight.Duration);
}

if (myMap.Visibility == Visibility.Visible)
{
ShowMap();
}

ShowTotalFlightTime();
});

}

private void ShowTotalFlightTime()
{
TimeSpan total = new TimeSpan();
Expand Down Expand Up @@ -447,30 +483,7 @@ private async Task LoadMavlinkFile(string file)
ShowSchema();

Debug.WriteLine(data.StartTime.ToString());

UiDispatcher.RunOnUIThread(() =>
{
foreach (var flight in data.GetFlights())
{
flight.Name = "Flight " + allFlights.Count;
allFlights.Add(flight);
AppendMessage("Motor started at {0} and ran for {1} ", flight.StartTime, flight.Duration);
}

if (myMap.Visibility == Visibility.Visible)
{
ShowMap();
}

foreach (var text in data.GetStatusMessages())
{
SystemConsole.Write(text + "\n");
}

ShowTotalFlightTime();
});


LoadFlights(data);

// remember successfully loaded log file.
Settings settings = await ((App)App.Current).LoadSettings();
Expand Down
Loading

0 comments on commit 4b2b612

Please sign in to comment.