From 5bd17f261bc9e71235559d6f9ef0bdb06b41dcd9 Mon Sep 17 00:00:00 2001 From: dr-i-boleet Date: Wed, 26 Mar 2025 17:37:13 +1100 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D1=8C=D1=82?= =?UTF-8?q?=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TelemetryIO.sln | 25 + TelemetryIO/App.config | 6 + TelemetryIO/DataSlots.cs | 59 ++ TelemetryIO/MainForm.Designer.cs | 253 +++++++ TelemetryIO/MainForm.cs | 166 +++++ TelemetryIO/MainForm.resx | 120 ++++ TelemetryIO/Models/Telemetry.cs | 72 ++ TelemetryIO/MonitorVars.Designer.cs | 57 ++ TelemetryIO/MonitorVars.cs | 34 + TelemetryIO/MonitorVars.resx | 120 ++++ TelemetryIO/OpenTK.dll.config | 25 + TelemetryIO/Program.cs | 22 + TelemetryIO/Properties/AssemblyInfo.cs | 36 + TelemetryIO/Properties/Resources.Designer.cs | 71 ++ TelemetryIO/Properties/Resources.resx | 117 ++++ TelemetryIO/Properties/Settings.Designer.cs | 30 + TelemetryIO/Properties/Settings.settings | 7 + TelemetryIO/RatePID.Designer.cs | 698 +++++++++++++++++++ TelemetryIO/RatePID.cs | 64 ++ TelemetryIO/RatePID.resx | 120 ++++ TelemetryIO/SerialHandler.cs | 355 ++++++++++ TelemetryIO/TelemetryIO.csproj | 172 +++++ TelemetryIO/packages.config | 24 + 23 files changed, 2653 insertions(+) create mode 100644 TelemetryIO.sln create mode 100644 TelemetryIO/App.config create mode 100644 TelemetryIO/DataSlots.cs create mode 100644 TelemetryIO/MainForm.Designer.cs create mode 100644 TelemetryIO/MainForm.cs create mode 100644 TelemetryIO/MainForm.resx create mode 100644 TelemetryIO/Models/Telemetry.cs create mode 100644 TelemetryIO/MonitorVars.Designer.cs create mode 100644 TelemetryIO/MonitorVars.cs create mode 100644 TelemetryIO/MonitorVars.resx create mode 100644 TelemetryIO/OpenTK.dll.config create mode 100644 TelemetryIO/Program.cs create mode 100644 TelemetryIO/Properties/AssemblyInfo.cs create mode 100644 TelemetryIO/Properties/Resources.Designer.cs create mode 100644 TelemetryIO/Properties/Resources.resx create mode 100644 TelemetryIO/Properties/Settings.Designer.cs create mode 100644 TelemetryIO/Properties/Settings.settings create mode 100644 TelemetryIO/RatePID.Designer.cs create mode 100644 TelemetryIO/RatePID.cs create mode 100644 TelemetryIO/RatePID.resx create mode 100644 TelemetryIO/SerialHandler.cs create mode 100644 TelemetryIO/TelemetryIO.csproj create mode 100644 TelemetryIO/packages.config diff --git a/TelemetryIO.sln b/TelemetryIO.sln new file mode 100644 index 0000000..5f4e908 --- /dev/null +++ b/TelemetryIO.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33712.159 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TelemetryIO", "TelemetryIO\TelemetryIO.csproj", "{DDC6B03D-9702-4DF4-82AC-D310ACA9C549}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DDC6B03D-9702-4DF4-82AC-D310ACA9C549}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DDC6B03D-9702-4DF4-82AC-D310ACA9C549}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDC6B03D-9702-4DF4-82AC-D310ACA9C549}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DDC6B03D-9702-4DF4-82AC-D310ACA9C549}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B159E8CE-F43C-4A4E-83AA-269FA4C8AA60} + EndGlobalSection +EndGlobal diff --git a/TelemetryIO/App.config b/TelemetryIO/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/TelemetryIO/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TelemetryIO/DataSlots.cs b/TelemetryIO/DataSlots.cs new file mode 100644 index 0000000..5d8c162 --- /dev/null +++ b/TelemetryIO/DataSlots.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TelemetryIO +{ + internal class DataSlots + { + static private int[] raw_imu = new int[6]; + public DataSlots() { } + + static public void setSlot(int slot, byte[] data, int offset, int len) + { + switch (slot) + { + case 0: + setSlot0(data, offset, len); + break; + + case 1: + setSlot0(data, offset, len); + break; + } + } + static public void setSlot0(byte[]data, int offset, int len) + { + for(int i = 0; i < (int)(len/4); i++) + { + byte[]bs = new byte[4]; + Array.Copy(data, i * 4, bs, 0, 4); + raw_imu[(int)(offset/4)] = bytes_to_int(bs, 0); + } + } + + static public int[] getSlot0() + { + return raw_imu; + } + + static public int bytes_to_int(byte[] bytes, int startPos) + { + byte[] bs = new byte[4]; + Array.Copy(bytes, startPos, bs, 0, 4); + int ret = (int)(bs[0] | (bs[1] << 8) | (bs[2] << 16) | (bs[3] << 24)); + return ret; + } + + static public uint bytes_to_uint(byte[] bytes, int startPos) + { + byte[] bs = new byte[4]; + Array.Copy(bytes, startPos, bs, 0, 4); + uint ret = (uint)(bs[0] | (bs[1] << 8) | (bs[2] << 16) | (bs[3] << 24)); + + return ret; + } + } +} diff --git a/TelemetryIO/MainForm.Designer.cs b/TelemetryIO/MainForm.Designer.cs new file mode 100644 index 0000000..69f3881 --- /dev/null +++ b/TelemetryIO/MainForm.Designer.cs @@ -0,0 +1,253 @@ +namespace TelemetryIO +{ + partial class MainForm + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором форм Windows + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.PortSelector = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.Send_btn = new System.Windows.Forms.Button(); + this.Connect_btn = new System.Windows.Forms.Button(); + this.InfoLabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.SpeedSelector = new System.Windows.Forms.ComboBox(); + this.SendContinuous_btn = new System.Windows.Forms.Button(); + this.IMU_label = new System.Windows.Forms.Label(); + this.TestWrite_btn = new System.Windows.Forms.Button(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.ratePID_control = new TelemetryIO.RatePID(); + this.monitorVars1 = new TelemetryIO.MonitorVars(); + this.name_label = new System.Windows.Forms.Label(); + this.tabControl1.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.tabPage2.SuspendLayout(); + this.SuspendLayout(); + // + // PortSelector + // + this.PortSelector.FormattingEnabled = true; + this.PortSelector.Location = new System.Drawing.Point(63, 12); + this.PortSelector.Name = "PortSelector"; + this.PortSelector.Size = new System.Drawing.Size(121, 21); + this.PortSelector.TabIndex = 0; + this.PortSelector.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PortSelector_RefreshItems); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label1.Location = new System.Drawing.Point(16, 14); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 17); + this.label1.TabIndex = 1; + this.label1.Text = "Порт"; + // + // Send_btn + // + this.Send_btn.Location = new System.Drawing.Point(118, 57); + this.Send_btn.Name = "Send_btn"; + this.Send_btn.Size = new System.Drawing.Size(66, 21); + this.Send_btn.TabIndex = 2; + this.Send_btn.Text = "Send"; + this.Send_btn.UseVisualStyleBackColor = true; + this.Send_btn.Click += new System.EventHandler(this.Send_btn_Click); + // + // Connect_btn + // + this.Connect_btn.Location = new System.Drawing.Point(19, 57); + this.Connect_btn.Name = "Connect_btn"; + this.Connect_btn.Size = new System.Drawing.Size(79, 21); + this.Connect_btn.TabIndex = 3; + this.Connect_btn.Text = "Подключить"; + this.Connect_btn.UseVisualStyleBackColor = true; + this.Connect_btn.Click += new System.EventHandler(this.Connect_btn_Click); + // + // InfoLabel + // + this.InfoLabel.Location = new System.Drawing.Point(12, 793); + this.InfoLabel.Name = "InfoLabel"; + this.InfoLabel.Size = new System.Drawing.Size(1240, 18); + this.InfoLabel.TabIndex = 4; + this.InfoLabel.Text = "Ok"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.label2.Location = new System.Drawing.Point(208, 14); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(69, 17); + this.label2.TabIndex = 6; + this.label2.Text = "Скорость"; + // + // SpeedSelector + // + this.SpeedSelector.FormattingEnabled = true; + this.SpeedSelector.Location = new System.Drawing.Point(283, 12); + this.SpeedSelector.Name = "SpeedSelector"; + this.SpeedSelector.Size = new System.Drawing.Size(121, 21); + this.SpeedSelector.TabIndex = 5; + // + // SendContinuous_btn + // + this.SendContinuous_btn.Location = new System.Drawing.Point(190, 57); + this.SendContinuous_btn.Name = "SendContinuous_btn"; + this.SendContinuous_btn.Size = new System.Drawing.Size(109, 21); + this.SendContinuous_btn.TabIndex = 7; + this.SendContinuous_btn.Text = "Send_Continuous"; + this.SendContinuous_btn.UseVisualStyleBackColor = true; + this.SendContinuous_btn.Click += new System.EventHandler(this.SendContinuous_btn_Click); + // + // IMU_label + // + this.IMU_label.Location = new System.Drawing.Point(496, 16); + this.IMU_label.Name = "IMU_label"; + this.IMU_label.Size = new System.Drawing.Size(208, 19); + this.IMU_label.TabIndex = 8; + this.IMU_label.Text = "label3"; + // + // TestWrite_btn + // + this.TestWrite_btn.Location = new System.Drawing.Point(318, 56); + this.TestWrite_btn.Name = "TestWrite_btn"; + this.TestWrite_btn.Size = new System.Drawing.Size(75, 23); + this.TestWrite_btn.TabIndex = 9; + this.TestWrite_btn.Text = "TestWrite"; + this.TestWrite_btn.UseVisualStyleBackColor = true; + this.TestWrite_btn.Click += new System.EventHandler(this.TestWrite_btn_Click); + // + // tabControl1 + // + this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Bottom; + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Location = new System.Drawing.Point(12, 110); + this.tabControl1.Multiline = true; + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(1339, 680); + this.tabControl1.TabIndex = 10; + // + // tabPage1 + // + this.tabPage1.Controls.Add(this.ratePID_control); + this.tabPage1.Location = new System.Drawing.Point(4, 4); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(1331, 654); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "PIDs"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // tabPage2 + // + this.tabPage2.Controls.Add(this.monitorVars1); + this.tabPage2.Location = new System.Drawing.Point(4, 4); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(1331, 654); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "Monitor"; + this.tabPage2.UseVisualStyleBackColor = true; + // + // ratePID_control + // + this.ratePID_control.BackColor = System.Drawing.Color.AntiqueWhite; + this.ratePID_control.bottom_label = null; + this.ratePID_control.Location = new System.Drawing.Point(6, 6); + this.ratePID_control.Name = "ratePID_control"; + this.ratePID_control.serial = null; + this.ratePID_control.Size = new System.Drawing.Size(1240, 600); + this.ratePID_control.TabIndex = 11; + // + // monitorVars1 + // + this.monitorVars1.Location = new System.Drawing.Point(6, 6); + this.monitorVars1.Name = "monitorVars1"; + this.monitorVars1.serial = null; + this.monitorVars1.Size = new System.Drawing.Size(1200, 600); + this.monitorVars1.TabIndex = 0; + // + // name_label + // + this.name_label.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.name_label.Location = new System.Drawing.Point(1203, 10); + this.name_label.Name = "name_label"; + this.name_label.Size = new System.Drawing.Size(148, 23); + this.name_label.TabIndex = 11; + this.name_label.Text = "name"; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1363, 820); + this.Controls.Add(this.name_label); + this.Controls.Add(this.tabControl1); + this.Controls.Add(this.TestWrite_btn); + this.Controls.Add(this.IMU_label); + this.Controls.Add(this.SendContinuous_btn); + this.Controls.Add(this.label2); + this.Controls.Add(this.SpeedSelector); + this.Controls.Add(this.InfoLabel); + this.Controls.Add(this.Connect_btn); + this.Controls.Add(this.Send_btn); + this.Controls.Add(this.label1); + this.Controls.Add(this.PortSelector); + this.Name = "MainForm"; + this.Text = "Form1"; + this.tabControl1.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox PortSelector; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button Send_btn; + private System.Windows.Forms.Button Connect_btn; + private System.Windows.Forms.Label InfoLabel; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox SpeedSelector; + private System.Windows.Forms.Button SendContinuous_btn; + private System.Windows.Forms.Label IMU_label; + private System.Windows.Forms.Button TestWrite_btn; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage2; + private RatePID ratePID_control; + private MonitorVars monitorVars1; + private System.Windows.Forms.Label name_label; + } +} + diff --git a/TelemetryIO/MainForm.cs b/TelemetryIO/MainForm.cs new file mode 100644 index 0000000..552e5af --- /dev/null +++ b/TelemetryIO/MainForm.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO.Ports; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Timers; +using System.Diagnostics; +using System.Reflection.Emit; +using System.Xml.Linq; +using TelemetryIO.Models; + +namespace TelemetryIO +{ + public partial class MainForm : Form + { + private SerialHandler serial = new SerialHandler(); + private string[] speedItems = { "9600", "19200", "38400", "115200" }; + private System.Timers.Timer packageReceivingTimeout = new System.Timers.Timer(5); + private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); + private System.Timers.Timer packageTransferTimer = new System.Timers.Timer(50); + private List rx_buf = new List(); + private List send_queue = new List(); + private bool sendContinuousFlag = false; + private float test_f = 0; + + public MainForm() + { + InitializeComponent(); + PortSelector.Items.AddRange(SerialPort.GetPortNames()); + PortSelector.SelectedIndex = 0; + + SpeedSelector.Items.AddRange(speedItems); + SpeedSelector.SelectedIndex = 0; + + Send_btn.Enabled = false; + + packageTransferTimer.AutoReset = true; + timer.Interval = 100; + timer.Start(); + timer.Tick += Timer_Tick; + + ratePID_control.SubscribeOnEvent(serial); + ratePID_control.bottom_label = InfoLabel; + } + + private void Timer_Tick(object sender, EventArgs e) + { + if (name_label.InvokeRequired) { + name_label.BeginInvoke(new Action(() => IMU_label.Text = Telemetry.Instance.name)); // Асинхронный вызов + } + else + { + name_label.Text = Telemetry.Instance.name; + } + UpdateLabel(serial.view_str); + } + + private void serialSend() + { + + } + + private void Send_btn_Click(object sender, EventArgs e) + { + serial.sendTest(); + } + + private void Connect_btn_Click(object sender, EventArgs e) + { + InfoLabel.Text = ""; + Button b = sender as Button; + bool a = serial.isOpen; + if (!serial.isOpen) + { + string port; + string speed; + try + { + port = PortSelector.SelectedItem.ToString(); + speed = SpeedSelector.SelectedItem.ToString(); + } + catch (Exception ex) + { + InfoLabel.Text = "Порт не существует."; + return; + } + + if (port != null) + { + try + { + serial.PortName = port; + serial.BaudRate = int.Parse(speed); + serial.Open(); + } + catch (Exception ex) + { + InfoLabel.Text = ex.Message; + return; + } + b.Text = "Отключить"; + Send_btn.Enabled = true; + } + } + else + { + serial.Close(); + b.Text = "Подключить"; + Send_btn.Enabled = false; + } + + } + + private void PortSelector_RefreshItems(object sender, MouseEventArgs e) + { + PortSelector.Items.Clear(); + PortSelector.Items.AddRange(SerialPort.GetPortNames()); + PortSelector.SelectedIndex = 0; + } + + + private void SendContinuous_btn_Click(object sender, EventArgs e) + { + serial.sendTestCont(); + /*Button b = sender as Button; + if (sendContinuousFlag == true) + { + sendContinuousFlag = false; + packageTransferTimer.Stop(); + + b.Text = "Stop_Sending"; + } + else + { + sendContinuousFlag = true; + send_queue.Add(prepareTelegram()); + packageTransferTimer.Start(); + b.Text = "Send_Continuous"; + }*/ + } + + public void UpdateLabel(string newText) + { + + if (IMU_label.InvokeRequired) + { + IMU_label.BeginInvoke(new Action(() => IMU_label.Text = newText)); // Асинхронный вызов + } + else + { + IMU_label.Text = newText; + } + } + + private void TestWrite_btn_Click(object sender, EventArgs e) + { + float[] f = {0, 1, 2, 3, 4, 5, 6, 7, 8}; + serial.sendTestWrite(f); + } + } +} diff --git a/TelemetryIO/MainForm.resx b/TelemetryIO/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TelemetryIO/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TelemetryIO/Models/Telemetry.cs b/TelemetryIO/Models/Telemetry.cs new file mode 100644 index 0000000..87c2b67 --- /dev/null +++ b/TelemetryIO/Models/Telemetry.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TelemetryIO.Models +{ + public sealed class Telemetry + { + private static volatile Telemetry instance; + private static readonly object _lock = new object(); + + public string name = ""; + public float[] raw_imu = new float[6]; + public float[] motor_act = new float[4]; + public float[] motor_sp = new float[4]; + public float[] pid0 = new float[9]; + public float[] pid1 = new float[9]; + public float[] pid2 = new float[9]; + public float[] pid3 = new float[9]; + + private Telemetry() { } + + public static Telemetry Instance + { + get + { + if(instance == null) + { + lock(_lock) + { + if (instance == null) + { + instance = new Telemetry(); + } + } + } + return instance; + } + } + + public void setSlot(int slot, byte[] data, int offset, int len) + { + switch (slot) + { + case 0://RAW IMU + set_raw_imu(data, offset, len); + break; + + case 9999: + set_name(data); + break; + } + } + private void set_raw_imu(byte[] data, int offset, int len) + { + for (int i = 0; i < (int)(len / 4); i++) + { + byte[] bs = new byte[4]; + Array.Copy(data, i * 4, bs, 0, 4); + raw_imu[(int)(offset / 4)] = BitConverter.ToSingle(bs, 0); + } + } + + private void set_name(byte[] data) + { + name = Encoding.ASCII.GetString(data, 0, 16); + } + + } +} diff --git a/TelemetryIO/MonitorVars.Designer.cs b/TelemetryIO/MonitorVars.Designer.cs new file mode 100644 index 0000000..d94db9b --- /dev/null +++ b/TelemetryIO/MonitorVars.Designer.cs @@ -0,0 +1,57 @@ +namespace TelemetryIO +{ + partial class MonitorVars + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.MainFormPlot = new ScottPlot.WinForms.FormsPlot(); + this.SuspendLayout(); + // + // MainFormPlot + // + this.MainFormPlot.DisplayScale = 0F; + this.MainFormPlot.Location = new System.Drawing.Point(115, 3); + this.MainFormPlot.Name = "MainFormPlot"; + this.MainFormPlot.Size = new System.Drawing.Size(1046, 594); + this.MainFormPlot.TabIndex = 0; + // + // MonitorVars + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.MainFormPlot); + this.Name = "MonitorVars"; + this.Size = new System.Drawing.Size(1240, 600); + this.ResumeLayout(false); + + } + + #endregion + + private ScottPlot.WinForms.FormsPlot MainFormPlot; + } +} diff --git a/TelemetryIO/MonitorVars.cs b/TelemetryIO/MonitorVars.cs new file mode 100644 index 0000000..409f8db --- /dev/null +++ b/TelemetryIO/MonitorVars.cs @@ -0,0 +1,34 @@ +using ScottPlot; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TelemetryIO +{ + public partial class MonitorVars : UserControl + { + public SerialHandler serial { get; set; } + public float[][] monitoringBuffer = new float[32][]; + public MonitorVars() + { + InitializeComponent(); + initMonitoringBuffer(); + MainFormPlot.Multiplot.AddPlots(4); + //MainFormPlot. + } + + void initMonitoringBuffer() + { + for (int i = 0; i < monitoringBuffer.Length; i++) + { + monitoringBuffer[i] = new float[8192]; + } + } + } +} diff --git a/TelemetryIO/MonitorVars.resx b/TelemetryIO/MonitorVars.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TelemetryIO/MonitorVars.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TelemetryIO/OpenTK.dll.config b/TelemetryIO/OpenTK.dll.config new file mode 100644 index 0000000..7098d39 --- /dev/null +++ b/TelemetryIO/OpenTK.dll.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TelemetryIO/Program.cs b/TelemetryIO/Program.cs new file mode 100644 index 0000000..7e8743e --- /dev/null +++ b/TelemetryIO/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TelemetryIO +{ + internal static class Program + { + /// + /// Главная точка входа для приложения. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/TelemetryIO/Properties/AssemblyInfo.cs b/TelemetryIO/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c58ec6c --- /dev/null +++ b/TelemetryIO/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов для изменения сведений, +// связанных со сборкой. +[assembly: AssemblyTitle("TelemetryIO")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TelemetryIO")] +[assembly: AssemblyCopyright("Copyright © 2025")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// COM, следует установить атрибут ComVisible в TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("ddc6b03d-9702-4df4-82ac-d310aca9c549")] + +// Сведения о версии сборки состоят из указанных ниже четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Редакция +// +// Можно задать все значения или принять номера сборки и редакции по умолчанию +// используя "*", как показано ниже: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TelemetryIO/Properties/Resources.Designer.cs b/TelemetryIO/Properties/Resources.Designer.cs new file mode 100644 index 0000000..7ab7206 --- /dev/null +++ b/TelemetryIO/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программным средством. +// Версия среды выполнения: 4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если +// код создан повторно. +// +//------------------------------------------------------------------------------ + +namespace TelemetryIO.Properties +{ + + + /// + /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. + /// + // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder + // класс с помощью таких средств, как ResGen или Visual Studio. + // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen + // с параметром /str или заново постройте свой VS-проект. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TelemetryIO.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Переопределяет свойство CurrentUICulture текущего потока для всех + /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/TelemetryIO/Properties/Resources.resx b/TelemetryIO/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/TelemetryIO/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TelemetryIO/Properties/Settings.Designer.cs b/TelemetryIO/Properties/Settings.Designer.cs new file mode 100644 index 0000000..f38c321 --- /dev/null +++ b/TelemetryIO/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TelemetryIO.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/TelemetryIO/Properties/Settings.settings b/TelemetryIO/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/TelemetryIO/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/TelemetryIO/RatePID.Designer.cs b/TelemetryIO/RatePID.Designer.cs new file mode 100644 index 0000000..6f4c4a3 --- /dev/null +++ b/TelemetryIO/RatePID.Designer.cs @@ -0,0 +1,698 @@ +namespace TelemetryIO +{ + partial class RatePID + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + this.Save_btn = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tab_pid0 = new System.Windows.Forms.TabPage(); + this.pid0_panel = new System.Windows.Forms.Panel(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.tab_pid1 = new System.Windows.Forms.TabPage(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown4 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown5 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown6 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown7 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown8 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown9 = new System.Windows.Forms.NumericUpDown(); + this.panel2 = new System.Windows.Forms.Panel(); + this.numericUpDown10 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown11 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown12 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown13 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown14 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown15 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown16 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown17 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown18 = new System.Windows.Forms.NumericUpDown(); + this.label10 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.label12 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.label15 = new System.Windows.Forms.Label(); + this.label16 = new System.Windows.Forms.Label(); + this.label17 = new System.Windows.Forms.Label(); + this.label18 = new System.Windows.Forms.Label(); + this.tabControl1.SuspendLayout(); + this.tab_pid0.SuspendLayout(); + this.pid0_panel.SuspendLayout(); + this.tab_pid1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown6)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown7)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown8)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown9)).BeginInit(); + this.panel2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown10)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown11)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown12)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown13)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown14)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown15)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown16)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown17)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown18)).BeginInit(); + this.SuspendLayout(); + // + // Save_btn + // + this.Save_btn.Location = new System.Drawing.Point(1012, 562); + this.Save_btn.Name = "Save_btn"; + this.Save_btn.Size = new System.Drawing.Size(75, 23); + this.Save_btn.TabIndex = 18; + this.Save_btn.Text = "Сохранить"; + this.Save_btn.UseVisualStyleBackColor = true; + this.Save_btn.Click += new System.EventHandler(this.Save_btn_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(1107, 562); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 19; + this.button1.Text = "Отменить"; + this.button1.UseVisualStyleBackColor = true; + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.tab_pid0); + this.tabControl1.Controls.Add(this.tab_pid1); + this.tabControl1.Location = new System.Drawing.Point(32, 23); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(570, 193); + this.tabControl1.TabIndex = 20; + // + // tab_pid0 + // + this.tab_pid0.Controls.Add(this.pid0_panel); + this.tab_pid0.Location = new System.Drawing.Point(4, 22); + this.tab_pid0.Name = "tab_pid0"; + this.tab_pid0.Padding = new System.Windows.Forms.Padding(3); + this.tab_pid0.Size = new System.Drawing.Size(562, 167); + this.tab_pid0.TabIndex = 0; + this.tab_pid0.Text = "Набор 0"; + this.tab_pid0.UseVisualStyleBackColor = true; + // + // pid0_panel + // + this.pid0_panel.Controls.Add(this.numericUpDown7); + this.pid0_panel.Controls.Add(this.numericUpDown8); + this.pid0_panel.Controls.Add(this.numericUpDown9); + this.pid0_panel.Controls.Add(this.numericUpDown4); + this.pid0_panel.Controls.Add(this.numericUpDown5); + this.pid0_panel.Controls.Add(this.numericUpDown6); + this.pid0_panel.Controls.Add(this.numericUpDown3); + this.pid0_panel.Controls.Add(this.numericUpDown2); + this.pid0_panel.Controls.Add(this.label7); + this.pid0_panel.Controls.Add(this.label8); + this.pid0_panel.Controls.Add(this.label9); + this.pid0_panel.Controls.Add(this.label4); + this.pid0_panel.Controls.Add(this.label5); + this.pid0_panel.Controls.Add(this.label6); + this.pid0_panel.Controls.Add(this.label3); + this.pid0_panel.Controls.Add(this.label2); + this.pid0_panel.Controls.Add(this.label1); + this.pid0_panel.Controls.Add(this.numericUpDown1); + this.pid0_panel.Location = new System.Drawing.Point(23, 25); + this.pid0_panel.Name = "pid0_panel"; + this.pid0_panel.Size = new System.Drawing.Size(517, 117); + this.pid0_panel.TabIndex = 0; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(347, 77); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(39, 13); + this.label7.TabIndex = 53; + this.label7.Text = "Yaw.D"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(347, 51); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(34, 13); + this.label8.TabIndex = 51; + this.label8.Text = "Yaw.I"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(347, 25); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(38, 13); + this.label9.TabIndex = 49; + this.label9.Text = "Yaw.P"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(185, 77); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(42, 13); + this.label4.TabIndex = 47; + this.label4.Text = "Pitch.D"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(185, 51); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(37, 13); + this.label5.TabIndex = 45; + this.label5.Text = "Pitch.I"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(185, 25); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(41, 13); + this.label6.TabIndex = 43; + this.label6.Text = "Pitch.P"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(26, 77); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(36, 13); + this.label3.TabIndex = 41; + this.label3.Text = "Roll.D"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(26, 51); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(31, 13); + this.label2.TabIndex = 39; + this.label2.Text = "Roll.I"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 25); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(35, 13); + this.label1.TabIndex = 37; + this.label1.Text = "Roll.P"; + // + // tab_pid1 + // + this.tab_pid1.Controls.Add(this.panel2); + this.tab_pid1.Location = new System.Drawing.Point(4, 22); + this.tab_pid1.Name = "tab_pid1"; + this.tab_pid1.Padding = new System.Windows.Forms.Padding(3); + this.tab_pid1.Size = new System.Drawing.Size(562, 167); + this.tab_pid1.TabIndex = 1; + this.tab_pid1.Text = "Набор 1"; + this.tab_pid1.UseVisualStyleBackColor = true; + // + // numericUpDown1 + // + this.numericUpDown1.DecimalPlaces = 2; + this.numericUpDown1.Location = new System.Drawing.Point(67, 23); + this.numericUpDown1.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(100, 20); + this.numericUpDown1.TabIndex = 1; + this.numericUpDown1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown2 + // + this.numericUpDown2.DecimalPlaces = 2; + this.numericUpDown2.Location = new System.Drawing.Point(67, 51); + this.numericUpDown2.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(100, 20); + this.numericUpDown2.TabIndex = 2; + this.numericUpDown2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown3 + // + this.numericUpDown3.DecimalPlaces = 2; + this.numericUpDown3.Location = new System.Drawing.Point(67, 77); + this.numericUpDown3.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown3.Name = "numericUpDown3"; + this.numericUpDown3.Size = new System.Drawing.Size(100, 20); + this.numericUpDown3.TabIndex = 3; + this.numericUpDown3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown4 + // + this.numericUpDown4.DecimalPlaces = 2; + this.numericUpDown4.Location = new System.Drawing.Point(232, 77); + this.numericUpDown4.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown4.Name = "numericUpDown4"; + this.numericUpDown4.Size = new System.Drawing.Size(100, 20); + this.numericUpDown4.TabIndex = 6; + this.numericUpDown4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown5 + // + this.numericUpDown5.DecimalPlaces = 2; + this.numericUpDown5.Location = new System.Drawing.Point(232, 51); + this.numericUpDown5.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown5.Name = "numericUpDown5"; + this.numericUpDown5.Size = new System.Drawing.Size(100, 20); + this.numericUpDown5.TabIndex = 5; + this.numericUpDown5.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown6 + // + this.numericUpDown6.DecimalPlaces = 2; + this.numericUpDown6.Location = new System.Drawing.Point(232, 23); + this.numericUpDown6.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown6.Name = "numericUpDown6"; + this.numericUpDown6.Size = new System.Drawing.Size(100, 20); + this.numericUpDown6.TabIndex = 4; + this.numericUpDown6.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown7 + // + this.numericUpDown7.DecimalPlaces = 2; + this.numericUpDown7.Location = new System.Drawing.Point(398, 77); + this.numericUpDown7.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown7.Name = "numericUpDown7"; + this.numericUpDown7.Size = new System.Drawing.Size(100, 20); + this.numericUpDown7.TabIndex = 9; + this.numericUpDown7.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown8 + // + this.numericUpDown8.DecimalPlaces = 2; + this.numericUpDown8.Location = new System.Drawing.Point(398, 51); + this.numericUpDown8.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown8.Name = "numericUpDown8"; + this.numericUpDown8.Size = new System.Drawing.Size(100, 20); + this.numericUpDown8.TabIndex = 8; + this.numericUpDown8.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown9 + // + this.numericUpDown9.DecimalPlaces = 2; + this.numericUpDown9.Location = new System.Drawing.Point(398, 23); + this.numericUpDown9.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown9.Name = "numericUpDown9"; + this.numericUpDown9.Size = new System.Drawing.Size(100, 20); + this.numericUpDown9.TabIndex = 7; + this.numericUpDown9.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // panel2 + // + this.panel2.Controls.Add(this.numericUpDown10); + this.panel2.Controls.Add(this.numericUpDown11); + this.panel2.Controls.Add(this.numericUpDown12); + this.panel2.Controls.Add(this.numericUpDown13); + this.panel2.Controls.Add(this.numericUpDown14); + this.panel2.Controls.Add(this.numericUpDown15); + this.panel2.Controls.Add(this.numericUpDown16); + this.panel2.Controls.Add(this.numericUpDown17); + this.panel2.Controls.Add(this.numericUpDown18); + this.panel2.Controls.Add(this.label10); + this.panel2.Controls.Add(this.label11); + this.panel2.Controls.Add(this.label12); + this.panel2.Controls.Add(this.label13); + this.panel2.Controls.Add(this.label14); + this.panel2.Controls.Add(this.label15); + this.panel2.Controls.Add(this.label16); + this.panel2.Controls.Add(this.label17); + this.panel2.Controls.Add(this.label18); + this.panel2.Location = new System.Drawing.Point(23, 25); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(517, 117); + this.panel2.TabIndex = 1; + // + // numericUpDown10 + // + this.numericUpDown10.DecimalPlaces = 2; + this.numericUpDown10.Location = new System.Drawing.Point(398, 77); + this.numericUpDown10.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown10.Name = "numericUpDown10"; + this.numericUpDown10.Size = new System.Drawing.Size(100, 20); + this.numericUpDown10.TabIndex = 62; + this.numericUpDown10.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown11 + // + this.numericUpDown11.DecimalPlaces = 2; + this.numericUpDown11.Location = new System.Drawing.Point(398, 51); + this.numericUpDown11.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown11.Name = "numericUpDown11"; + this.numericUpDown11.Size = new System.Drawing.Size(100, 20); + this.numericUpDown11.TabIndex = 61; + this.numericUpDown11.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown12 + // + this.numericUpDown12.DecimalPlaces = 2; + this.numericUpDown12.Location = new System.Drawing.Point(398, 23); + this.numericUpDown12.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown12.Name = "numericUpDown12"; + this.numericUpDown12.Size = new System.Drawing.Size(100, 20); + this.numericUpDown12.TabIndex = 60; + this.numericUpDown12.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown13 + // + this.numericUpDown13.DecimalPlaces = 2; + this.numericUpDown13.Location = new System.Drawing.Point(232, 77); + this.numericUpDown13.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown13.Name = "numericUpDown13"; + this.numericUpDown13.Size = new System.Drawing.Size(100, 20); + this.numericUpDown13.TabIndex = 59; + this.numericUpDown13.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown14 + // + this.numericUpDown14.DecimalPlaces = 2; + this.numericUpDown14.Location = new System.Drawing.Point(232, 51); + this.numericUpDown14.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown14.Name = "numericUpDown14"; + this.numericUpDown14.Size = new System.Drawing.Size(100, 20); + this.numericUpDown14.TabIndex = 58; + this.numericUpDown14.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown15 + // + this.numericUpDown15.DecimalPlaces = 2; + this.numericUpDown15.Location = new System.Drawing.Point(232, 23); + this.numericUpDown15.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown15.Name = "numericUpDown15"; + this.numericUpDown15.Size = new System.Drawing.Size(100, 20); + this.numericUpDown15.TabIndex = 57; + this.numericUpDown15.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown16 + // + this.numericUpDown16.DecimalPlaces = 2; + this.numericUpDown16.Location = new System.Drawing.Point(67, 77); + this.numericUpDown16.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown16.Name = "numericUpDown16"; + this.numericUpDown16.Size = new System.Drawing.Size(100, 20); + this.numericUpDown16.TabIndex = 56; + this.numericUpDown16.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown17 + // + this.numericUpDown17.DecimalPlaces = 2; + this.numericUpDown17.Location = new System.Drawing.Point(67, 51); + this.numericUpDown17.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown17.Name = "numericUpDown17"; + this.numericUpDown17.Size = new System.Drawing.Size(100, 20); + this.numericUpDown17.TabIndex = 55; + this.numericUpDown17.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // numericUpDown18 + // + this.numericUpDown18.DecimalPlaces = 2; + this.numericUpDown18.Location = new System.Drawing.Point(67, 23); + this.numericUpDown18.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown18.Name = "numericUpDown18"; + this.numericUpDown18.Size = new System.Drawing.Size(100, 20); + this.numericUpDown18.TabIndex = 54; + this.numericUpDown18.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(347, 77); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(39, 13); + this.label10.TabIndex = 53; + this.label10.Text = "Yaw.D"; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(347, 51); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(34, 13); + this.label11.TabIndex = 51; + this.label11.Text = "Yaw.I"; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(347, 25); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(38, 13); + this.label12.TabIndex = 49; + this.label12.Text = "Yaw.P"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(185, 77); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(42, 13); + this.label13.TabIndex = 47; + this.label13.Text = "Pitch.D"; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(185, 51); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(37, 13); + this.label14.TabIndex = 45; + this.label14.Text = "Pitch.I"; + // + // label15 + // + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(185, 25); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(41, 13); + this.label15.TabIndex = 43; + this.label15.Text = "Pitch.P"; + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(26, 77); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(36, 13); + this.label16.TabIndex = 41; + this.label16.Text = "Roll.D"; + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(26, 51); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(31, 13); + this.label17.TabIndex = 39; + this.label17.Text = "Roll.I"; + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(26, 25); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(35, 13); + this.label18.TabIndex = 37; + this.label18.Text = "Roll.P"; + // + // RatePID + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.tabControl1); + this.Controls.Add(this.button1); + this.Controls.Add(this.Save_btn); + this.Name = "RatePID"; + this.Size = new System.Drawing.Size(1200, 600); + this.tabControl1.ResumeLayout(false); + this.tab_pid0.ResumeLayout(false); + this.pid0_panel.ResumeLayout(false); + this.pid0_panel.PerformLayout(); + this.tab_pid1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown6)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown7)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown8)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown9)).EndInit(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown10)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown11)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown12)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown13)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown14)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown15)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown16)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown17)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown18)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button Save_btn; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tab_pid0; + private System.Windows.Forms.TabPage tab_pid1; + private System.Windows.Forms.Panel pid0_panel; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.NumericUpDown numericUpDown7; + private System.Windows.Forms.NumericUpDown numericUpDown8; + private System.Windows.Forms.NumericUpDown numericUpDown9; + private System.Windows.Forms.NumericUpDown numericUpDown4; + private System.Windows.Forms.NumericUpDown numericUpDown5; + private System.Windows.Forms.NumericUpDown numericUpDown6; + private System.Windows.Forms.NumericUpDown numericUpDown3; + private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.NumericUpDown numericUpDown10; + private System.Windows.Forms.NumericUpDown numericUpDown11; + private System.Windows.Forms.NumericUpDown numericUpDown12; + private System.Windows.Forms.NumericUpDown numericUpDown13; + private System.Windows.Forms.NumericUpDown numericUpDown14; + private System.Windows.Forms.NumericUpDown numericUpDown15; + private System.Windows.Forms.NumericUpDown numericUpDown16; + private System.Windows.Forms.NumericUpDown numericUpDown17; + private System.Windows.Forms.NumericUpDown numericUpDown18; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.Label label13; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.Label label18; + } +} diff --git a/TelemetryIO/RatePID.cs b/TelemetryIO/RatePID.cs new file mode 100644 index 0000000..64dd9b8 --- /dev/null +++ b/TelemetryIO/RatePID.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TelemetryIO +{ + public partial class RatePID : UserControl + { + private float[] pid0 = new float[9]; + private float[] pid1 = new float[9]; + private float zh = 0; + private bool isSubscribed = false; + public SerialHandler serial { get; set; } + public Label bottom_label { get; set; } + + public RatePID() + { + InitializeComponent(); + Debug.Write("tab elements = " + tabControl1.TabPages[0].Controls[0].Controls); + } + + private void Serial_AnswerReceived(object sender, SerialEventArgs e) + { + if (bottom_label.InvokeRequired) + { + bottom_label.BeginInvoke(new Action(() => bottom_label.Text = e.Answer)); // Асинхронный вызов + } + else + { + bottom_label.Text = e.Answer; ; + } + } + + public void SubscribeOnEvent(SerialHandler s) + { + if (isSubscribed) return; + isSubscribed = true; + serial = s; + serial.AnswerReceived += Serial_AnswerReceived; + } + + private void Save_btn_Click(object sender, EventArgs e) + { + + float[] floats = new float[9]; + for(int i = 0; i < pid0_panel.Controls.Count; i++) + { + if (pid0_panel.Controls[i] is NumericUpDown) + { + NumericUpDown c = pid0_panel.Controls[i] as NumericUpDown; + floats[pid0_panel.Controls[i].TabIndex - 1] = (float)c.Value; + } + } + serial.sendTestWrite(floats); + } + } +} diff --git a/TelemetryIO/RatePID.resx b/TelemetryIO/RatePID.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TelemetryIO/RatePID.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TelemetryIO/SerialHandler.cs b/TelemetryIO/SerialHandler.cs new file mode 100644 index 0000000..40a94a6 --- /dev/null +++ b/TelemetryIO/SerialHandler.cs @@ -0,0 +1,355 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO.Ports; +using System.Linq; +using System.Net.Http; +using System.Security.Permissions; +using System.Text; +using System.Threading.Tasks; +using TelemetryIO.Models; + +namespace TelemetryIO +{ + public class SerialHandler + { + public const int TELE_CMD_RD_ONCE = 1; + private const int TELE_CMD_RD_MON_ON = 2; + private const int TELE_CMD_RD_MON_OFF = 3; + private const int TELE_CMD_RD_MON_ADD = 4; + private const int TELE_CMD_RD_MON_REMOVE = 5; + private const int TELE_CMD_RD_MON_REMOVEALL = 6; + private const int TELE_CMD_WR = 10; + private const int TELE_CMD_ABORT = 999; + private const int TELE_CMD_HELLO = 9999; + private const byte CRC8_POLYNOMIAL = 0x07; + private const int CRC32_POLY = 0x04C11DB7; + private const byte ESCAPE_BEGIN = 0xBE; + private const byte ESCAPE_END = 0xED; + private const byte ESCAPE_CHAR = 0x0E; + private SerialPort com_port; + static private List rx_buf = new List(); + static private byte[] data; + public delegate void AnswerEventHandler(object sender, SerialEventArgs e); + public event AnswerEventHandler AnswerReceived; + private int int_test = 0; + private float[] monitor = new float[32]; + public string view_str = ""; + Telemetry telemetry = Telemetry.Instance; + + + public struct Telegram + { + public int cmd; + public int slot; + public int len; + public int offset; + public byte[] param; + }; + + public string PortName + { + get { return com_port.PortName; } + set { com_port.PortName = value; } + } + + public int BaudRate + { + get { return com_port.BaudRate; } + set { com_port.BaudRate = value; } + } + + public bool isOpen + { + get { return com_port.IsOpen; } + } + + public SerialHandler() + { + com_port = new SerialPort(); + } + + public SerialHandler(string PortName, int BaudRate) + { + com_port = new SerialPort(); + com_port.PortName = PortName; + com_port.BaudRate = BaudRate; + } + + private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e) + { + SerialPort sp = (SerialPort)sender; + + + while (sp.BytesToRead > 0) + { + if (!sp.IsOpen) return; + byte b = (byte)sp.ReadByte(); + + if (b == ESCAPE_END) + { + byte[] unscape = EscapeSeqToBytes(rx_buf.ToArray()); + uint checksum = crc32(unscape, unscape.Length - 4); + uint re_checksum = DataSlots.bytes_to_uint(unscape, unscape.Length - 4); + if (re_checksum == checksum) + { + //Parse telegram + int cmd = DataSlots.bytes_to_int(unscape, 0); + int slot = DataSlots.bytes_to_int(unscape, 4); + int len = DataSlots.bytes_to_int(unscape, 8); + int offset = DataSlots.bytes_to_int(unscape, 12); + byte[] data = new byte[len]; + Array.Copy(unscape, 16, data, 0, len); + + if (cmd == TELE_CMD_RD_ONCE) + { + DataSlots.setSlot(slot, data, offset, len); + } + else if (cmd == TELE_CMD_RD_MON_ON) + { + for(int i = 0; i < data.Length/4; i++) + { + monitor[i] = BitConverter.ToSingle(data, i*4); + } + view_str = string.Join(", ", monitor.Select(x => "" + x).ToArray(), 0, data.Length/4); + } + else if (cmd == TELE_CMD_WR) + { + if (data[0] == 'O' && data[1] == 'k') + { + Debug.Write("Data is written\n"); + OnAnswerReceived("Data is written"); + } + }else if(cmd == TELE_CMD_HELLO) + { + telemetry.setSlot(9999, data, 0, 0); + view_str = Encoding.ASCII.GetString(data); + } + + } + } + else if (b == ESCAPE_BEGIN) + { + rx_buf.Clear(); + } + else + { + rx_buf.Add(b); + } + + } + + } + + public void Open() + { + com_port.Open(); + com_port.DataReceived += Serial_DataReceived; + byte[] to = prepareTelegram(TELE_CMD_HELLO, 0, new byte[0], 0); + com_port.Write(to, 0, to.Length); + } + + public void Close() + { + com_port.DataReceived -= Serial_DataReceived; + com_port.Close(); + } + + byte crc8(byte[] data, int length) + { + byte crc = 0x00; // Initial value + + for (int i = 0; i < length; i++) + { + crc ^= data[i]; // XOR with the data byte + + for (int j = 0; j < 8; j++) + { + if ((byte)(crc & 0x80) > 0) + { + crc = (byte)((byte)(crc << 1) ^ CRC8_POLYNOMIAL); + } + else + { + crc = (byte)(crc << 1); + } + } + } + + return crc; + } + + uint crc32(byte[] data, int length) + { + uint crc = 0xFFFFFFFF; // Начальное значение CRC + + for (int i = 0; i < length; i++) + { + crc ^= (uint)data[i] << 24; // XOR с текущим байтом + + for (int j = 0; j < 8; j++) + { + if ((uint)(crc & 0x80000000) != 0) + { + crc = (crc << 1) ^ CRC32_POLY; + } + else + { + crc <<= 1; + } + } + } + + return crc; + } + + public void sendTest() + { + //data - index in monitor + byte[] to = prepareTelegram(TELE_CMD_RD_MON_ADD, 0, BitConverter.GetBytes(int_test), int_test, 4); + com_port.Write(to, 0, to.Length); + int_test++; + } + + public void sendTestCont() + { + byte[] b = new byte[0]; + byte[] to = prepareTelegram(TELE_CMD_RD_MON_ON, 0, b, 0, 24); + com_port.Write(to, 0, to.Length); + } + + public void sendTestWrite(float[] f) + { + byte[] b = prepareTelegram(TELE_CMD_WR, 1000, f, 0); + com_port.Write(b, 0, b.Length); + } + + byte[] prepareTelegram(int cmd, int slot, T[] load, int offset, int len = 0) + { + byte[] byteload = DataArrayToBytes(load); + int total_len = 20 + byteload.Length;//cmd[4 bytes] + slot[4 bytes] + len[4 bytes] + offset[4 bytes] + load[len bytes] + byte[] data = new byte[total_len]; + + //Construct telegram + data[0] = (byte)(0xFF & cmd); + data[1] = (byte)(0xFF & (cmd >> 8)); + data[2] = (byte)(0xFF & (cmd >> 16)); + data[3] = (byte)(0xFF & (cmd >> 24)); + + data[4] = (byte)(0xFF & slot); + data[5] = (byte)(0xFF & (slot >> 8)); + data[6] = (byte)(0xFF & (slot >> 16)); + data[7] = (byte)(0xFF & (slot >> 24)); + + int l = 0; + if (cmd == TELE_CMD_WR) l = byteload.Length; + else l = len; + + data[8] = (byte)(0xFF & l); + data[9] = (byte)(0xFF & (l >> 8)); + data[10] = (byte)(0xFF & (l >> 16)); + data[11] = (byte)(0xFF & (l >> 24)); + + data[12] = (byte)(0xFF & offset); + data[13] = (byte)(0xFF & (offset >> 8)); + data[14] = (byte)(0xFF & (offset >> 16)); + data[15] = (byte)(0xFF & (offset >> 24)); + + if(byteload.Length > 0) + { + //Copy data + Array.Copy(byteload, 0, data, 16, byteload.Length); + } + //CRC32 + uint checksum = crc32(data, total_len - 4); + data[total_len - 4] = (byte)(0xFF & checksum); + data[total_len - 3] = (byte)(0xFF & (checksum >> 8)); + data[total_len - 2] = (byte)(0xFF & (checksum >> 16)); + data[total_len - 1] = (byte)(0xFF & (checksum >> 24)); + + byte[] escape = BytesToEscapeSeq(data); + byte[] ret = new byte[escape.Length + 2]; + Array.Copy(escape, 0, ret, 1, escape.Length); + ret[0] = ESCAPE_BEGIN; + ret[ret.Length - 1] = ESCAPE_END; + return ret; + } + + byte[] DataArrayToBytes(T[] data) + { + if (data == null) return new byte[0]; + Listret = new List (); + for(int i = 0; i < data.Length; i++) + { + if(typeof(T) == typeof(float)) + { + ret.AddRange(BitConverter.GetBytes((float)(object)data[i])); + }else if(typeof(T) == typeof(int)) + { + ret.AddRange(BitConverter.GetBytes((int)(object)data[i])); + }else if(typeof(T) == typeof(byte)) + { + ret.Add((byte)(object)data[i]); + }else if(typeof(T) == typeof(bool)) + { + bool t = (bool)(object)data[i]; + if (t) ret.Add(1); + else ret.Add(0); + } + + } + return ret.ToArray(); + } + + byte[] BytesToEscapeSeq(byte[] data) + { + List ret = new List(); + for (int i = 0; i < data.Length; i++) + { + if ((data[i] == ESCAPE_BEGIN) || (data[i] == ESCAPE_CHAR) || (data[i] == ESCAPE_END)) + { + ret.Add(ESCAPE_CHAR); + ret.Add((byte)(data[i] - 0x0E)); + } + else + { + ret.Add(data[i]); + } + } + return ret.ToArray(); + } + + byte[] EscapeSeqToBytes(byte[] EscSeq) + { + List ret = new List(); + for (int i = 0; i < EscSeq.Length; i++) + { + if ((EscSeq[i] == ESCAPE_BEGIN) || (EscSeq[i] == ESCAPE_CHAR) || (EscSeq[i] == ESCAPE_END)) + { + i++; + ret.Add((byte)(EscSeq[i] + 0x0E)); + } + else + { + ret.Add(EscSeq[i]); + } + } + return ret.ToArray(); + } + + protected virtual void OnAnswerReceived(string answer) + { + AnswerReceived?.Invoke(this, new SerialEventArgs(answer)); + } + } + + public class SerialEventArgs: EventArgs + { + public string Answer { get; set; } + + public SerialEventArgs(string answer) + { + Answer = answer; + } + } +} diff --git a/TelemetryIO/TelemetryIO.csproj b/TelemetryIO/TelemetryIO.csproj new file mode 100644 index 0000000..366fd08 --- /dev/null +++ b/TelemetryIO/TelemetryIO.csproj @@ -0,0 +1,172 @@ + + + + + Debug + AnyCPU + {DDC6B03D-9702-4DF4-82AC-D310ACA9C549} + WinExe + TelemetryIO + TelemetryIO + v4.7.2 + 512 + true + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\HarfBuzzSharp.7.3.0.3\lib\net462\HarfBuzzSharp.dll + + + ..\packages\OpenTK.3.1.0\lib\net20\OpenTK.dll + + + ..\packages\OpenTK.GLControl.3.1.0\lib\net20\OpenTK.GLControl.dll + + + ..\packages\ScottPlot.5.0.55\lib\net462\ScottPlot.dll + + + ..\packages\ScottPlot.WinForms.5.0.55\lib\net462\ScottPlot.WinForms.dll + + + ..\packages\SkiaSharp.2.88.9\lib\net462\SkiaSharp.dll + + + ..\packages\SkiaSharp.HarfBuzz.2.88.9\lib\net462\SkiaSharp.HarfBuzz.dll + + + ..\packages\SkiaSharp.Views.Desktop.Common.2.88.9\lib\net462\SkiaSharp.Views.Desktop.Common.dll + + + ..\packages\SkiaSharp.Views.WindowsForms.2.88.9\lib\net462\SkiaSharp.Views.WindowsForms.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Drawing.Common.4.7.3\lib\net461\System.Drawing.Common.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + UserControl + + + MonitorVars.cs + + + + + UserControl + + + RatePID.cs + + + + MainForm.cs + Designer + + + MonitorVars.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + RatePID.cs + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TelemetryIO/packages.config b/TelemetryIO/packages.config new file mode 100644 index 0000000..bd02266 --- /dev/null +++ b/TelemetryIO/packages.config @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file