Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoT: adds send interval and saves all settings #3104

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 54 additions & 36 deletions Controls/SerialOutputCoT.Designer.cs

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

75 changes: 38 additions & 37 deletions Controls/SerialOutputCoT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MissionPlanner.Comms;
using MissionPlanner.Utilities;
using MissionPlanner.Utilities.CoT;
using Newtonsoft.Json.Linq;
using System;
using System.Globalization;
using System.IO;
Expand All @@ -18,49 +19,24 @@ public partial class SerialOutputCoT : Form
{
static TcpListener listener;
static ICommsSerial CoTStream = new SerialPort();
static double updaterate = 1;
static int updaterate_ms = 10*1000;
System.Threading.Thread t12;
static bool threadrun = false;
static internal PointLatLngAlt HomeLoc = new PointLatLngAlt(0, 0, 0, "Home");
static object[,] tabledata;
private bool indent;

public SerialOutputCoT()
{
InitializeComponent();

CMB_serialport.Items.AddRange(SerialPort.GetPortNames());
CMB_serialport.Items.Add("TAK Multicast");
CMB_serialport.Items.Add("TCP Host - 14551");
CMB_serialport.Items.Add("TCP Client");
CMB_serialport.Items.Add("UDP Host - 14551");
CMB_serialport.Items.Add("UDP Client");


CMB_serialport.Items.Add("ATAK MC");
CMB_serialport.SelectedIndex = CMB_serialport.Items.Count - 1; // select ATAK MC as default

CMB_updaterate.Text = updaterate + "Hz";

if (threadrun)
{
BUT_connect.Text = Strings.Stop;
}

CMB_serialport.Items.AddRange(SerialPort.GetPortNames());
MissionPlanner.Utilities.Tracking.AddPage(this.GetType().ToString(), this.Text);
}

private void CMB_updaterate_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
updaterate = float.Parse(CMB_updaterate.Text.Replace("hz", ""));
}
catch
{
CustomMessageBox.Show(Strings.InvalidUpdateRate, Strings.ERROR);
}
}

private void BUT_connect_Click(object sender, EventArgs e)
{

Expand Down Expand Up @@ -106,8 +82,8 @@ private void BUT_connect_Click(object sender, EventArgs e)
CoTStream = new UdpSerialConnect();
CMB_baudrate.SelectedIndex = 0;
break;
case "ATAK MC":
CoTStream = new UdpSerialConnect() { ConfigRef = "ATAK" };
case "TAK Multicast":
CoTStream = new UdpSerialConnect() { ConfigRef = "TAK_Multicast" };
((UdpSerialConnect)CoTStream).Open("239.2.3.1", "6969");
CMB_baudrate.SelectedIndex = 0;
break;
Expand Down Expand Up @@ -206,16 +182,12 @@ void mainloop()
TB_output.Text = view;
});

var nextsend = DateTime.Now.AddMilliseconds(1000 / updaterate);
var sleepfor = Math.Min((int)Math.Abs((nextsend - DateTime.Now).TotalMilliseconds), 4000);
Thread.Sleep(sleepfor);
Thread.Sleep(updaterate_ms);
counter++;


}
catch
{
Thread.Sleep(10);
Thread.Sleep(1000);
}
}
}
Expand Down Expand Up @@ -399,13 +371,37 @@ private void SerialOutputCoT_Load(object sender, EventArgs e)
// this can crash if you're connecting as you're loading the screen so the row count may change as you're populating it.
myDataGridView1.Deserialize(Settings.Instance["CoTUID"]);
} catch { }


updateRate_numericUpDown.Value = Settings.Instance.GetDecimal("CoT_updateRate", 10);
CMB_serialport.SelectedIndex = Settings.Instance.GetInt32("CoT_CMB_serialport", 0);
CMB_baudrate.SelectedIndex = Settings.Instance.GetInt32("CoT_CMB_baudrate", 0);
CB_advancedMode.Checked = Settings.Instance.GetBoolean("CoT_CB_advancedMode", true);
chk_indent.Checked = Settings.Instance.GetBoolean("CoT_chk_indent", true);

CB_advancedMode_CheckedChanged(null, null);
chk_indent_CheckedChanged(null, null);
updateRate_numericUpDown_ValueChanged(null, null);
CMB_serialport_SelectedIndexChanged(null, null);

if (threadrun)
{
// stop
BUT_connect_Click(null, null);

// restart
BUT_connect_Click(null, null);
}

}

private void SerialOutputCoT_FormClosing(object sender, FormClosingEventArgs e)
{

Settings.Instance["CoT_updateRate"] = updateRate_numericUpDown.Value.ToString();
Settings.Instance["CoT_CMB_serialport"] = CMB_serialport.SelectedIndex.ToString();
Settings.Instance["CoT_CMB_baudrate"] = CMB_baudrate.SelectedIndex.ToString();
Settings.Instance["CoT_CB_advancedMode"] = CB_advancedMode.Checked.ToString();
Settings.Instance["CoT_chk_indent"] = chk_indent.Checked.ToString();
}

private void myDataGridView1_RowValidated(object sender, DataGridViewCellEventArgs e)
Expand Down Expand Up @@ -452,6 +448,11 @@ private void myDataGridView1_CellLeave(object sender, DataGridViewCellEventArgs
{
myDataGridView1.EndEdit();
}

private void updateRate_numericUpDown_ValueChanged(object sender, EventArgs e)
{
updaterate_ms = (int)(updateRate_numericUpDown.Value * 1000);
}
}

public sealed class Utf8StringWriter : StringWriter
Expand Down
18 changes: 18 additions & 0 deletions Controls/SerialOutputCoT.resx
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,22 @@
<metadata name="VMF.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="sysid.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="UID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="takv.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ContactCallsign.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ContactEndPointIP.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="VMF.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>
11 changes: 11 additions & 0 deletions ExtLibs/Utilities/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ public double GetDouble(string key, double defaultd = 0)
return result;
}

public decimal GetDecimal(string key, decimal defaultd = 0)
{
decimal result = defaultd;
string value = null;
if (config.TryGetValue(key, out value))
{
decimal.TryParse(value, out result);
}
return result;
}

public byte GetByte(string key, byte defaultb = 0)
{
byte result = defaultb;
Expand Down