Skip to content

Commit

Permalink
SerialOutputPass: multi mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Nov 6, 2024
1 parent 4f07aea commit 3827d9a
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 46 deletions.
9 changes: 9 additions & 0 deletions Controls/SerialOutputPass.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 40 additions & 18 deletions Controls/SerialOutputPass.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Scripting.Utils;
using DeviceProgramming.Dfu;
using Microsoft.Scripting.Utils;
using MissionPlanner.Comms;
using MissionPlanner.Utilities;
using Newtonsoft.Json;
Expand Down Expand Up @@ -131,15 +132,17 @@ private void BUT_connect_Click(object sender, EventArgs e)
void DoAcceptTcpClientCallback(IAsyncResult ar)
{
// Get the listener that handles the client request.
TcpListener listener = (TcpListener)ar.AsyncState;
var state = (ValueTuple<TcpListener, MAVLinkInterface.Mirror>)ar.AsyncState;
TcpListener listener = state.Item1;
MAVLinkInterface.Mirror mirror = state.Item2;

// End the operation and display the received data on
// the console.
TcpClient client = listener.EndAcceptTcpClient(ar);

((TcpSerial)MainV2.comPort.MirrorStream).client = client;
((TcpSerial)mirror.MirrorStream).client = client;

listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), listener);
listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), state);
}

private void chk_write_CheckedChanged(object sender, EventArgs e)
Expand All @@ -165,7 +168,7 @@ private void Save()
Settings.Instance.SetList(configlist, ans);
}

private void Load()
private void Load()
{
var ans = Settings.Instance.GetList(configlist);

Expand All @@ -174,11 +177,17 @@ private void Load()
if (row == null || row == "")
continue;
var data = ((JArray)JsonConvert.DeserializeObject(row)).Select(a => ((JValue)a).Value).ToArray();
myDataGridView1.Rows.Add(data);
var index = myDataGridView1.Rows.Add(data);

if (Started.Contains(index))
{
myDataGridView1[Go.Index, index].Value = "Started";
}
}
}

string configlist = "serialpasslist";
static private List<int> Started = new List<int>();

private void myDataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
Expand All @@ -191,26 +200,31 @@ private void myDataGridView1_CellContentClick(object sender, DataGridViewCellEve
{
try
{
MAVLinkInterface.Mirror mirror = new MAVLinkInterface.Mirror();

var protocol = myDataGridView1[Type.Index, e.RowIndex].Value.ToString();
var direction = myDataGridView1[Direction.Index, e.RowIndex].Value.ToString();
var port = myDataGridView1[Port.Index, e.RowIndex].Value.ToString();
var extra = myDataGridView1[Extra.Index, e.RowIndex].Value.ToString();
var write = myDataGridView1[Write.Index, e.RowIndex].Value.ToString();
if (protocol == "TCP")
{
if (direction == "Inbound")
{
MainV2.comPort.MirrorStream = new TcpSerial();
{
mirror.MirrorStream = new TcpSerial();
mirror.MirrorStreamWrite = bool.Parse(write);
CMB_baudrate.SelectedIndex = 0;
listener = new TcpListener(System.Net.IPAddress.Any, int.Parse(port.ToString()));
listener.Start(0);
listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), listener);
listener.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), (listener, mirror));
BUT_connect.Text = Strings.Stop;
}
else if (direction == "Outbound")
{
MainV2.comPort.MirrorStream = new TcpSerial() { retrys = 999999, autoReconnect = true, Host = extra, Port = port, ConfigRef = "SerialOutputPassTCP" };
mirror.MirrorStream = new TcpSerial() { retrys = 999999, autoReconnect = true, Host = extra, Port = port, ConfigRef = "SerialOutputPassTCP" };
CMB_baudrate.SelectedIndex = 0;
MainV2.comPort.MirrorStream.Open();
mirror.MirrorStream.Open();
mirror.MirrorStreamWrite = bool.Parse(write);
}
}
else if (protocol == "UDP")
Expand All @@ -220,27 +234,35 @@ private void myDataGridView1_CellContentClick(object sender, DataGridViewCellEve
var udp = new UdpSerial()
{ ConfigRef = "SerialOutputPassUDP", Port = port.ToString() };
udp.client = new UdpClient(int.Parse(port));
MainV2.comPort.MirrorStream = udp;
mirror.MirrorStream = udp;
udp.IsOpen = true;
CMB_baudrate.SelectedIndex = 0;
MainV2.comPort.MirrorStream.Open();
mirror.MirrorStream.Open();
mirror.MirrorStreamWrite = bool.Parse(write);
}
else if (direction == "Outbound")
{
var udp = new UdpSerialConnect() { ConfigRef = "SerialOutputPassUDPCL" };
udp.hostEndPoint = new IPEndPoint(IPAddress.Parse(extra), int.Parse(port));
udp.client = new UdpClient();
udp.IsOpen = true;
MainV2.comPort.MirrorStream = udp;
mirror.MirrorStream = udp;
mirror.MirrorStreamWrite = bool.Parse(write);
CMB_baudrate.SelectedIndex = 0;
}
}
else if (protocol == "Serial")
{
MainV2.comPort.MirrorStream = new SerialPort();
MainV2.comPort.MirrorStream.PortName = port;
MainV2.comPort.MirrorStream.BaudRate = int.Parse(extra);
MainV2.comPort.MirrorStream.Open();
mirror.MirrorStream = new SerialPort();
mirror.MirrorStream.PortName = port;
mirror.MirrorStream.BaudRate = int.Parse(extra);
mirror.MirrorStream.Open();
mirror.MirrorStreamWrite = bool.Parse(write);
}

MainV2.comPort.Mirrors.Add(mirror);
myDataGridView1[Go.Index, e.RowIndex].Value = "Started";
Started.Add(e.RowIndex);
}
catch (Exception ex) {
CustomMessageBox.Show("Error: " + ex.Message);
Expand Down
36 changes: 30 additions & 6 deletions Controls/SerialOutputPass.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
<data name="CMB_serialport.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="CMB_serialport.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="&gt;&gt;CMB_serialport.Name" xml:space="preserve">
<value>CMB_serialport</value>
</data>
Expand Down Expand Up @@ -156,6 +159,9 @@
<data name="BUT_connect.Text" xml:space="preserve">
<value>Connect</value>
</data>
<data name="BUT_connect.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="&gt;&gt;BUT_connect.Name" xml:space="preserve">
<value>BUT_connect</value>
</data>
Expand Down Expand Up @@ -201,6 +207,9 @@
<data name="CMB_baudrate.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
</data>
<data name="CMB_baudrate.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="&gt;&gt;CMB_baudrate.Name" xml:space="preserve">
<value>CMB_baudrate</value>
</data>
Expand Down Expand Up @@ -231,6 +240,9 @@
<data name="chk_write.Text" xml:space="preserve">
<value>Write access</value>
</data>
<data name="chk_write.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="&gt;&gt;chk_write.Name" xml:space="preserve">
<value>chk_write</value>
</data>
Expand Down Expand Up @@ -282,6 +294,15 @@
<data name="Extra.Width" type="System.Int32, mscorlib">
<value>80</value>
</data>
<metadata name="Write.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<data name="Write.HeaderText" xml:space="preserve">
<value>Write</value>
</data>
<data name="Write.Width" type="System.Int32, mscorlib">
<value>40</value>
</data>
<metadata name="Go.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand All @@ -295,7 +316,7 @@
<value>12, 69</value>
</data>
<data name="myDataGridView1.Size" type="System.Drawing.Size, System.Drawing">
<value>363, 150</value>
<value>428, 150</value>
</data>
<data name="myDataGridView1.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
Expand All @@ -304,7 +325,7 @@
<value>myDataGridView1</value>
</data>
<data name="&gt;&gt;myDataGridView1.Type" xml:space="preserve">
<value>MissionPlanner.Controls.MyDataGridView, MissionPlanner, Version=1.3.8177.19206, Culture=neutral, PublicKeyToken=null</value>
<value>MissionPlanner.Controls.MyDataGridView, MissionPlanner, Version=1.3.9076.24256, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;myDataGridView1.Parent" xml:space="preserve">
<value>$this</value>
Expand All @@ -316,7 +337,7 @@
<value>True</value>
</metadata>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>387, 228</value>
<value>452, 228</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down Expand Up @@ -394,9 +415,6 @@
AAf4AAAP/AAAH/4AAD//gAD//+AD//////8=
</value>
</data>
<data name="$this.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>SerialOutput - Mavlink</value>
</data>
Expand Down Expand Up @@ -424,6 +442,12 @@
<data name="&gt;&gt;Extra.Type" xml:space="preserve">
<value>System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;Write.Name" xml:space="preserve">
<value>Write</value>
</data>
<data name="&gt;&gt;Write.Type" xml:space="preserve">
<value>System.Windows.Forms.DataGridViewCheckBoxColumn, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;Go.Name" xml:space="preserve">
<value>Go</value>
</data>
Expand Down
Loading

0 comments on commit 3827d9a

Please sign in to comment.