Skip to content

Commit

Permalink
Version 0.4
Browse files Browse the repository at this point in the history
Added libad9361
improved sampling quality
implemented filter control
implemented decimation
implemented a new settings dialog
implemented higher sample rates
fixed a lot of bugs...
  • Loading branch information
Manawyrm committed Aug 20, 2017
1 parent 2794350 commit 952c31a
Show file tree
Hide file tree
Showing 8 changed files with 647 additions and 426 deletions.
19 changes: 19 additions & 0 deletions PlutoSDR/IIOHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,26 @@ public static long GetAttribute(Device phy, string Channel, string Attribute)
}
return -1;
}
public static string GetAttributeString(Device phy, string Channel, string Attribute)
{
foreach (Channel chn in phy.channels)
{
if (chn.attrs.Count == 0)
continue;

if (chn.id.Equals(Channel))
{
foreach (Attr attr in chn.attrs)
{
if (attr.name.CompareTo(Attribute) == 0)
{
return attr.read();
}
}
}
}
return null;
}
public static Channel FindChannel(Device phy, string Channel)
{
foreach (Channel chn in phy.channels)
Expand Down
33 changes: 33 additions & 0 deletions PlutoSDR/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SDRSharp.PlutoSDR
{
class NativeMethods
{
[DllImport("libad9361.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int ad9361_set_bb_rate(IntPtr dev, [In()] uint rate);

/// <summary>
/// Uses reflection to get the field value from an object.
/// </summary>
///
/// <param name="type">The instance type.</param>
/// <param name="instance">The instance object.</param>
/// <param name="fieldName">The field's name which is to be fetched.</param>
///
/// <returns>The field value from the object.</returns>
public static object GetInstanceField(Type type, object instance, string fieldName)
{
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
| BindingFlags.Static;
FieldInfo field = type.GetField(fieldName, bindFlags);
return field.GetValue(instance);
}
}
}
460 changes: 319 additions & 141 deletions PlutoSDR/PlutoSDRControllerDialog.Designer.cs

Large diffs are not rendered by default.

212 changes: 61 additions & 151 deletions PlutoSDR/PlutoSDRControllerDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SDRSharp.Common;
using SDRSharp.Radio;
using iio;
using System.Diagnostics;

namespace SDRSharp.PlutoSDR
{
Expand All @@ -15,26 +16,17 @@ public partial class PlutoSDRControllerDialog : Form
public PlutoSDRControllerDialog(PlutoSDRIO owner)
{
InitializeComponent();

_owner = owner;
InitSampleRates();
InitBandwidths();
var devices = DeviceDisplay.GetActiveDevices();
deviceComboBox.Items.Clear();
if (devices != null)
deviceComboBox.Items.AddRange(devices);

//samplerateComboBox.SelectedIndex = Utils.GetIntSetting("PlutoSDRSampleRate", 1);
samplerateComboBox.SelectedIndex = 0;
// FIXME!!!
InitSampleRates();

agcEnabledCheckBox.Checked = (Utils.GetStringSetting("PlutoSDRGainControlMode", "manual") != "manual");
deviceUriTextbox.Text = Utils.GetStringSetting("PlutoSDRURI", "ip:192.168.2.1");

samplerateComboBox.SelectedIndex = Utils.GetIntSetting("PlutoSDRSampleRate2", 1);
//samplingModeComboBox.SelectedIndex = Utils.GetIntSetting("PlutoSDRSamplingMode", (int) PlutoSDR_sampling.PlutoSDR_SAMPLING_INTERNAL);
rxVga1GainTrackBar.Value = Utils.GetIntSetting("PlutoSDRManualGain", 20);
bandwidthComboBox.SelectedIndex = Utils.GetIntSetting("PlutoSDRBandwidth", 0);

//labelVersion.Text = "libPlutoSDR " + NativeMethods.PlutoSDR_version().describe;

rxVga1gainLabel.Text = rxVga1GainTrackBar.Value + " dB";

_initialized = true;
Expand All @@ -50,40 +42,17 @@ private bool Initialized

private void InitSampleRates()
{
/*for (int i = 40; i > 0; i--)
for (int i = 5; i > 0; i--)
{
samplerateComboBox.Items.Add(String.Format("{0} MSPS", i));
for (int i = 900; i > 0; i -= 300)
samplerateComboBox.Items.Add(String.Format("0.{0} MSPS", i));
samplerateComboBox.Items.Add("0.200 MSPS");
samplerateComboBox.Items.Add("0.160 MSPS");*/
samplerateComboBox.Items.Add("2.1 MSPS");
samplerateComboBox.Items.Add("2.5 MSPS");
samplerateComboBox.Items.Add("2 MSPS");
samplerateComboBox.Items.Add("1 MSPS");
}
}
samplerateComboBox.Items.Add("0.7 MSPS");
samplerateComboBox.Items.Add("0.521 MSPS");

private void InitBandwidths()
{
bandwidthComboBox.Items.Clear();
bandwidthComboBox.DisplayMember = "Text";
bandwidthComboBox.ValueMember = "Value";
bandwidthComboBox.Items.Add(new ComboboxItem("auto", 0));
bandwidthComboBox.Items.Add(new ComboboxItem("28 MHz", 28000000));
bandwidthComboBox.Items.Add(new ComboboxItem("20 MHz", 20000000));
bandwidthComboBox.Items.Add(new ComboboxItem("14 MHz", 14000000));
bandwidthComboBox.Items.Add(new ComboboxItem("12 MHz", 12000000));
bandwidthComboBox.Items.Add(new ComboboxItem("10 MHz", 10000000));
bandwidthComboBox.Items.Add(new ComboboxItem("8.75 MHz", 8750000));
bandwidthComboBox.Items.Add(new ComboboxItem("7 MHz", 7000000));
bandwidthComboBox.Items.Add(new ComboboxItem("6 MHz", 6000000));
bandwidthComboBox.Items.Add(new ComboboxItem("5.5 MHz", 5500000));
bandwidthComboBox.Items.Add(new ComboboxItem("5 MHz", 5000000));
bandwidthComboBox.Items.Add(new ComboboxItem("3.84 MHz", 3840000));
bandwidthComboBox.Items.Add(new ComboboxItem("3 MHz", 3000000));
bandwidthComboBox.Items.Add(new ComboboxItem("2.75 MHz", 2750000));
bandwidthComboBox.Items.Add(new ComboboxItem("2.5 MHz", 2500000));
bandwidthComboBox.Items.Add(new ComboboxItem("1.75 MHz", 1750000));
bandwidthComboBox.Items.Add(new ComboboxItem("1.5 MHz", 1500000));
for (int i = 6; i < 20; i++)
{
samplerateComboBox.Items.Add(String.Format("{0} MSPS (not supported!)", i));
}
}

private void closeButton_Click(object sender, EventArgs e)
Expand All @@ -102,53 +71,8 @@ private void PlutoSDRControllerDialog_VisibleChanged(object sender, EventArgs e)
refreshTimer.Enabled = Visible;
if (Visible)
{
deviceComboBox.Enabled = Initialized && !_owner.Device.IsStreaming;

if (Initialized && !_owner.Device.IsStreaming)
{
var devices = DeviceDisplay.GetActiveDevices();
deviceComboBox.Items.Clear();
if (devices != null)
{
deviceComboBox.Items.AddRange(devices);

for (var i = 0; i < devices.Length; i++)
{
if (devices[i].Index == ((DeviceDisplay)(deviceComboBox.Items[i])).Index)
{
_initialized = false;
deviceComboBox.SelectedIndex = i;
_initialized = true;
break;
}
}
}
}
}
}

private void refreshTimer_Tick(object sender, EventArgs e)
{
deviceComboBox.Enabled = Initialized && !_owner.Device.IsStreaming;
}

private void deviceComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (!Initialized)
{
return;
}
var deviceDisplay = (DeviceDisplay) deviceComboBox.SelectedItem;
if (deviceDisplay != null)
{
try
{
_owner.SelectDevice(deviceDisplay.Serial);
}
catch (Exception ex)
{
deviceComboBox.SelectedIndex = -1;
MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Expand All @@ -162,49 +86,21 @@ private void samplerateComboBox_SelectedIndexChanged(object sender, EventArgs e)
var samplerateString = samplerateComboBox.Items[samplerateComboBox.SelectedIndex].ToString().Split(' ')[0];
var sampleRate = double.Parse(samplerateString, CultureInfo.InvariantCulture);
_owner.Device.SampleRate = (uint) (sampleRate * 1000000.0);
Utils.SaveSetting("PlutoSDRSampleRate", samplerateComboBox.SelectedIndex);

Utils.SaveSetting("PlutoSDRSampleRate2", samplerateComboBox.SelectedIndex);
}

public void ConfigureGUI()
{
if (!Initialized)
return;

PlutoSDRTypeLabel.Text = _owner.Device.Name;

for (var i = 0; i < deviceComboBox.Items.Count; i++)
{
var deviceDisplay = (DeviceDisplay) deviceComboBox.Items[i];
/*if (deviceDisplay.Serial == _owner.Device.Serial)
{
deviceComboBox.SelectedIndex = i;
break;
}*/
}
}

public void ConfigureDevice()
{
samplerateComboBox_SelectedIndexChanged(null, null);
bandwidthComboBox_SelectedIndexChanged(null, null);
}


private void bandwidthComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (!Initialized)
return;
Utils.SaveSetting("PlutoSDRBandwidth", bandwidthComboBox.SelectedIndex);
try
{
_owner.Device.Bandwidth = (bandwidthComboBox.SelectedItem as ComboboxItem).Value;
}
catch
{
_owner.Device.Bandwidth = 0;
}
}

private class ComboboxItem
{
public string Text { get; set; }
Expand All @@ -227,11 +123,7 @@ public ISharpControl Control
get;
set;
}

private void PlutoSDRControllerDialog_Load(object sender, EventArgs e)
{

}


private void rxVga1GainTrackBar_Scroll(object sender, EventArgs e)
{
Expand All @@ -243,43 +135,61 @@ private void rxVga1GainTrackBar_Scroll(object sender, EventArgs e)
rxVga1gainLabel.Text = rxVga1GainTrackBar.Value + " dB";
Utils.SaveSetting("PlutoSDRManualGain", rxVga1GainTrackBar.Value);
}
}

public class DeviceDisplay
{
public int Index { get; private set; }
public string Name { get; set; }
public string Serial { get; private set; }
public int Bus { get; set; }
public int Address { get; set; }
public string Backend { get; set; }
private void refreshTimer_Tick(object sender, EventArgs e)
{
if (!Initialized)
{
return;
}
if (!_owner.Device.IsStreaming)
{
return;
}

rssiLabel.Text = _owner.Device.RSSI.ToString();
}

public unsafe static DeviceDisplay[] GetActiveDevices()
private void versionLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
DeviceDisplay[] result = new DeviceDisplay[1];
Process.Start("https://github.com/Manawyrm/sdrsharp-plutosdr");
}

private void connectButton_Click(object sender, EventArgs e)
{
/* Try to connect to the SDR - we set the timeout to a low value and then
* open a context to the specified URI */
try
{
Context iioCtx = new iio.Context("ip:192.168.2.1");

if (iioCtx.devices.Count > 0)
{
string name = String.Format("PlutoSDR (ip) @ 192.168.2.1");
result[0] = new DeviceDisplay { Index = 0, Name = name };
}
_owner.Device.createContext();
}
catch (Exception e)
catch (Exception ex)
{
MessageBox.Show(e.ToString(), "Error while loading PlutoSDR frontend", MessageBoxButtons.OK);
//throw new ApplicationException(e.ToString());
MessageBox.Show(ex.ToString(), "Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

return result;
}

public override string ToString()
private void agcEnabledCheckBox_CheckedChanged(object sender, EventArgs e)
{
return Name;
if (agcEnabledCheckBox.Checked)
{
rxVga1GainTrackBar.Enabled = false;
rxVga1gainLabel.Enabled = false;
label6.Enabled = false;

_owner.Device.GainControlMode = "slow_attack";
Utils.SaveSetting("PlutoSDRGainControlMode", _owner.Device.GainControlMode);
}
else
{
rxVga1GainTrackBar.Enabled = true;
rxVga1gainLabel.Enabled = true;
label6.Enabled = true;

_owner.Device.GainControlMode = "manual";
Utils.SaveSetting("PlutoSDRGainControlMode", _owner.Device.GainControlMode);
}
}

}
}
6 changes: 3 additions & 3 deletions PlutoSDR/PlutoSDRControllerDialog.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="receiverTabPage.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="refreshTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="fpgaOpenFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>137, 17</value>
</metadata>
</root>
Loading

0 comments on commit 952c31a

Please sign in to comment.