Skip to content

Commit

Permalink
Implement MavFraming selection and Params saving
Browse files Browse the repository at this point in the history
  • Loading branch information
justas- committed Dec 14, 2020
1 parent 999beb8 commit 272e582
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 16 deletions.
7 changes: 7 additions & 0 deletions SiKGUIWPF/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ You should have received a copy of the GNU Lesser General Public License
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows.Controls;

namespace SiKGUIWPF
{
class Helpers
{
public static ReadOnlyCollection<int> SerialRates = new ReadOnlyCollection<int>(new int[] { 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400 });
public static ReadOnlyCollection<ComboBoxItem> MavVersions = new ReadOnlyCollection<ComboBoxItem>(new ComboBoxItem[]
{
new ComboBoxItem(){Content = "MavLink 1"},
new ComboBoxItem(){Content = "MavLink 2"},
new ComboBoxItem(){Content = "MavLink 2 Low Latency"}
});
}
}
8 changes: 6 additions & 2 deletions SiKGUIWPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ along with this program.If not, see<http://www.gnu.org/licenses/> .
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SiKGUIWPF"
mc:Ignorable="d"
Title="SiK Radio Configurator" Height="300" Width="650">
Title="SiK Radio Configurator" Height="300" Width="700">
<Window.Resources>
<local:MavVerToIdConverter x:Key="MavVerToId"/>
</Window.Resources>
<Grid>
<TabControl>
<TabItem Header="Disconnected">
Expand Down Expand Up @@ -73,7 +76,7 @@ along with this program.If not, see<http://www.gnu.org/licenses/> .
</WrapPanel>
<WrapPanel Grid.Column="3" Grid.Row="0" Background="AliceBlue">
<Label Content="Mavlink:" />
<ComboBox MinWidth="70" Name="MavlinkFrame" VerticalAlignment="Center" SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=SiKConfig.MavlinkMode}">
<ComboBox MinWidth="70" Name="MavlinkFrame" VerticalAlignment="Center" SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=SiKConfig.MavlinkMode, Converter={StaticResource MavVerToId}}">
</ComboBox>
</WrapPanel>
<WrapPanel Grid.Column="0" Grid.Row="1" Background="AliceBlue">
Expand Down Expand Up @@ -151,3 +154,4 @@ along with this program.If not, see<http://www.gnu.org/licenses/> .
</TabControl>
</Grid>
</Window>

7 changes: 3 additions & 4 deletions SiKGUIWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public MainWindow()
foreach (var item in SiKLink.Constants.SiKSerialRates)
SiKSerialSpeed.Items.Add(item);

foreach (var item in SiKLink.Constants.MavlinkFrame)
foreach (var item in Helpers.MavVersions)
MavlinkFrame.Items.Add(item);

foreach (var item in SiKLink.Constants.AirPower)
Expand All @@ -119,7 +119,6 @@ public MainWindow()
foreach (var item in Enumerable.Range(33, 99))
MaxWnd.Items.Add(item);


SiKConfig = _sikInterface.SiKConfig;
}
/// <summary>
Expand Down Expand Up @@ -176,7 +175,7 @@ private void Button_ConnectClick(object sender, RoutedEventArgs e)
}
}

// Are we in the comman mode already?
// Are we in the command mode already?
var in_command = _sikInterface.CheckCommandMode();
if (!in_command)
{
Expand Down Expand Up @@ -221,7 +220,7 @@ private void Button_ReadValuesClick(object sender, RoutedEventArgs e)

private void Button_WriteValuesClick(object sender, RoutedEventArgs e)
{

_sikInterface.SaveParameters();
}
private void Button_SaveEepromClick(object sender, RoutedEventArgs e)
{
Expand Down
40 changes: 40 additions & 0 deletions SiKGUIWPF/MavVerToIdConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
SiK Link - GUI and control library for SiK radios.
Copyright(C) 2020 J. Poderys
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program.If not, see<http://www.gnu.org/licenses/>.
*/
using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;

namespace SiKGUIWPF
{
[ValueConversion(typeof(int), typeof(ComboBoxItem))]
class MavVerToIdConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int numeric_id = (int)value;
return Helpers.MavVersions[numeric_id];
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
ComboBoxItem item = (ComboBoxItem)value;
return Helpers.MavVersions.IndexOf(item);
}
}
}
4 changes: 2 additions & 2 deletions SiKLink/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace SiKLink
{
public class Constants
{
public static ReadOnlyCollection<int> AirRates = new ReadOnlyCollection<int>(new int[]{ 2, 4, 8, 16, 19, 24, 32, 48, 64, 96, 128, 192, 250 });
public static ReadOnlyCollection<int> AirRates = new ReadOnlyCollection<int>(new int[] { 2, 4, 8, 16, 19, 24, 32, 48, 64, 96, 128, 192, 250 });
public static ReadOnlyCollection<int> MavlinkFrame = new ReadOnlyCollection<int>(new int[] { 0, 1, 2 });
public static ReadOnlyCollection<int> SiKSerialRates = new ReadOnlyCollection<int>(new int[] { 1, 2, 4, 9, 19, 38, 57, 115, 230 });
public static ReadOnlyCollection<int> AirPower = new ReadOnlyCollection<int>(new int[] { 1, 2, 5, 8, 11, 14, 17, 20 });
Expand All @@ -46,5 +46,5 @@ public enum SikParameters
RTSCTS,
MAX_WINDOW
}
}
}
}
3 changes: 1 addition & 2 deletions SiKLink/SiKConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ public class SiKConfig : INotifyPropertyChanged
private string _boardFrequency;
private string _bootloaderVersion;

//
// ATS parameters https://github.com/ArduPilot/SiK/blob/master/Firmware/radio/parameters.h
// Defaults:
//{"FORMAT", PARAM_FORMAT_CURRENT},
//{"SERIAL_SPEED", 57}, // match APM default of 57600
//{"AIR_SPEED", 64}, // relies on MAVLink flow control
//{"AIR_SPEED", 64}, // relies on MAVLink flow control
//{"NETID", 25},
//{"TXPOWER", 20},
//{"ECC", 0},
Expand Down
61 changes: 55 additions & 6 deletions SiKLink/SiKInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public bool PortConnected
/// <summary>
/// SiK radio in Command mode.
/// </summary>
public bool CommandMode { get; private set; } = false;
public bool CommandMode { get; private set; } = false;
/// <summary>
/// Configuration parameters of the local SiK board.
/// </summary>
Expand Down Expand Up @@ -98,7 +98,7 @@ public bool Connect(string port, int baudrate)
{
return false;
}

return true;
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public bool RebootRadio()
{
return false;
}

}
/// <summary>
/// Save current parameters to the EEPROM
Expand All @@ -250,7 +250,7 @@ public bool SaveToEEPROM()
{
return true;
}
else
else
{
return false;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ public bool ReadEEPROMData()
return false;
}

foreach(var line in params_list)
foreach (var line in params_list)
{
// Skip echo
if (line.StartsWith("AT"))
Expand All @@ -299,7 +299,7 @@ public bool ReadEEPROMData()
var tokens = line.Split(':');
var param_id = tokens[0];
var param_val = tokens[1].Split("=")[1];

switch (param_id)
{
case "S0":
Expand Down Expand Up @@ -358,6 +358,55 @@ public bool ReadEEPROMData()
return true;
}
/// <summary>
/// Transfer all parameter values to the radio.
/// </summary>
/// <remarks>This function does not save parameters to the EEPROM!</remarks>
/// <returns>true on success</returns>
public bool SaveParameters()
{
try
{
if (!WriteParameter(Constants.SikParameters.FORMAT, SiKConfig.ParameterFormat))
return false;
if (!WriteParameter(Constants.SikParameters.SERIAL_SPEED, SiKConfig.SerialSpeed))
return false;
if (!WriteParameter(Constants.SikParameters.AIR_SPEED, SiKConfig.AirSpeed))
return false;
if (!WriteParameter(Constants.SikParameters.NETID, SiKConfig.NetworkID))
return false;
if (!WriteParameter(Constants.SikParameters.TXPOWER, SiKConfig.TxPower))
return false;
if (!WriteParameter(Constants.SikParameters.ECC, SiKConfig.ECC))
return false;
if (!WriteParameter(Constants.SikParameters.MAVLINK, SiKConfig.MavlinkMode))
return false;
if (!WriteParameter(Constants.SikParameters.OPPRESEND, SiKConfig.OpportunisticResend))
return false;
if (!WriteParameter(Constants.SikParameters.MIN_FREQ, SiKConfig.MinFrequency))
return false;
if (!WriteParameter(Constants.SikParameters.MAX_FREQ, SiKConfig.MaxFrequency))
return false;
if (!WriteParameter(Constants.SikParameters.NUM_CHANNELS, SiKConfig.NumChannels))
return false;
if (!WriteParameter(Constants.SikParameters.DUTY_CYCLE, SiKConfig.DutyCycle))
return false;
if (!WriteParameter(Constants.SikParameters.LBT_RSSI, SiKConfig.LbtRssiThreshold))
return false;
if (!WriteParameter(Constants.SikParameters.MANCHESTER, SiKConfig.ManchesterEncoding))
return false;
if (!WriteParameter(Constants.SikParameters.RTSCTS, SiKConfig.UseRtsCts))
return false;
if (!WriteParameter(Constants.SikParameters.MAX_WINDOW, SiKConfig.MaxWindowSize))
return false;

return true;
}
catch
{
return false;
}
}
/// <summary>
/// Set SiK radio parameter value
/// </summary>
/// <param name="paramNum">Parameter number</param>
Expand Down

0 comments on commit 272e582

Please # to comment.