Browse Source

first commit

master
Денис Кузнецов 3 years ago
commit
7bccc55044
  1. 16
      .gitignore
  2. 224
      AboutBox1.Designer.cs
  3. 181
      AboutBox1.cs
  4. 3463
      AboutBox1.resx
  5. 98
      AdvancedRadioButton.cs
  6. 56
      Class1.cs
  7. 51
      Class2.cs
  8. 66
      RichTextBoxExtensions.cs
  9. 97
      UnsafeBitmap.cs
  10. 182
      asmbl.cs
  11. 51
      gkalman.cs
  12. BIN
      gravity2.ico
  13. 66
      inifile.cs
  14. 20
      inv.snippet
  15. 49
      loadstruct.cs
  16. 2347
      piv.cs
  17. 207
      rtp.cs
  18. 558
      util.cs

16
.gitignore vendored

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
lib/
ImageDraw/
packages/
ipch/
*.zip
*.pdf
*.rar
*.txt
*.pdb
obj/
Debug/
*.html
*.*~
*.suo
*.sdf
.vs/

224
AboutBox1.Designer.cs generated

@ -0,0 +1,224 @@ @@ -0,0 +1,224 @@
namespace AB
{
partial class AboutBox1
{
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором форм Windows
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutBox1));
this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.logoPictureBox = new System.Windows.Forms.PictureBox();
this.labelProductName = new System.Windows.Forms.Label();
this.labelVersion = new System.Windows.Forms.Label();
this.labelCopyright = new System.Windows.Forms.Label();
this.labelCompanyName = new System.Windows.Forms.Label();
this.textBoxDescription = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.okButton = new System.Windows.Forms.Button();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.tableLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel
//
this.tableLayoutPanel.ColumnCount = 2;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 220F));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 269F));
this.tableLayoutPanel.Controls.Add(this.logoPictureBox, 0, 0);
this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 0);
this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 1);
this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2);
this.tableLayoutPanel.Controls.Add(this.labelCompanyName, 1, 3);
this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 1, 5);
this.tableLayoutPanel.Controls.Add(this.label1, 1, 4);
this.tableLayoutPanel.Controls.Add(this.okButton, 1, 6);
this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel.Location = new System.Drawing.Point(9, 9);
this.tableLayoutPanel.Name = "tableLayoutPanel";
this.tableLayoutPanel.RowCount = 7;
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tableLayoutPanel.Size = new System.Drawing.Size(489, 222);
this.tableLayoutPanel.TabIndex = 0;
//
// logoPictureBox
//
this.logoPictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.logoPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("logoPictureBox.Image")));
this.logoPictureBox.Location = new System.Drawing.Point(3, 3);
this.logoPictureBox.Name = "logoPictureBox";
this.tableLayoutPanel.SetRowSpan(this.logoPictureBox, 7);
this.logoPictureBox.Size = new System.Drawing.Size(214, 216);
this.logoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.logoPictureBox.TabIndex = 12;
this.logoPictureBox.TabStop = false;
this.logoPictureBox.MouseEnter += new System.EventHandler(this.logoPictureBox_MouseEnter);
this.logoPictureBox.MouseLeave += new System.EventHandler(this.logoPictureBox_MouseLeave);
//
// labelProductName
//
this.labelProductName.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelProductName.Location = new System.Drawing.Point(226, 0);
this.labelProductName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelProductName.MaximumSize = new System.Drawing.Size(0, 17);
this.labelProductName.Name = "labelProductName";
this.labelProductName.Size = new System.Drawing.Size(260, 17);
this.labelProductName.TabIndex = 19;
this.labelProductName.Text = "Название продукта";
this.labelProductName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelVersion
//
this.labelVersion.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelVersion.Location = new System.Drawing.Point(226, 20);
this.labelVersion.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelVersion.MaximumSize = new System.Drawing.Size(0, 17);
this.labelVersion.Name = "labelVersion";
this.labelVersion.Size = new System.Drawing.Size(260, 17);
this.labelVersion.TabIndex = 0;
this.labelVersion.Text = "Версия";
this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelCopyright
//
this.labelCopyright.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelCopyright.Location = new System.Drawing.Point(226, 40);
this.labelCopyright.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelCopyright.MaximumSize = new System.Drawing.Size(0, 17);
this.labelCopyright.Name = "labelCopyright";
this.labelCopyright.Size = new System.Drawing.Size(260, 17);
this.labelCopyright.TabIndex = 21;
this.labelCopyright.Text = "Авторские права";
this.labelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelCompanyName
//
this.labelCompanyName.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelCompanyName.Location = new System.Drawing.Point(226, 60);
this.labelCompanyName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelCompanyName.MaximumSize = new System.Drawing.Size(0, 17);
this.labelCompanyName.Name = "labelCompanyName";
this.labelCompanyName.Size = new System.Drawing.Size(260, 17);
this.labelCompanyName.TabIndex = 22;
this.labelCompanyName.Text = "Название организации";
this.labelCompanyName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// textBoxDescription
//
this.textBoxDescription.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxDescription.Location = new System.Drawing.Point(226, 103);
this.textBoxDescription.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
this.textBoxDescription.Multiline = true;
this.textBoxDescription.Name = "textBoxDescription";
this.textBoxDescription.ReadOnly = true;
this.textBoxDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxDescription.Size = new System.Drawing.Size(260, 86);
this.textBoxDescription.TabIndex = 23;
this.textBoxDescription.TabStop = false;
this.textBoxDescription.Text = "Описание";
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Location = new System.Drawing.Point(226, 80);
this.label1.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.label1.MaximumSize = new System.Drawing.Size(0, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(260, 17);
this.label1.TabIndex = 25;
this.label1.Text = "Описание";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// okButton
//
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.okButton.Location = new System.Drawing.Point(411, 196);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 24;
this.okButton.Text = "&ОК";
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "im1.gif");
this.imageList1.Images.SetKeyName(1, "im2.gif");
//
// timer1
//
this.timer1.Interval = 200;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// AboutBox1
//
this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(507, 240);
this.Controls.Add(this.tableLayoutPanel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AboutBox1";
this.Padding = new System.Windows.Forms.Padding(9);
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "AboutBox1";
this.Load += new System.EventHandler(this.AboutBox1_Load);
this.tableLayoutPanel.ResumeLayout(false);
this.tableLayoutPanel.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.PictureBox logoPictureBox;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Button okButton;
public System.Windows.Forms.Label labelProductName;
public System.Windows.Forms.Label labelVersion;
public System.Windows.Forms.Label labelCopyright;
public System.Windows.Forms.Label labelCompanyName;
public System.Windows.Forms.TextBox textBoxDescription;
public System.Windows.Forms.Label label1;
}
}

181
AboutBox1.cs

@ -0,0 +1,181 @@ @@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using UTIL;
namespace AB
{
partial class AboutBox1 : Form
{
int sw = 0;
#region Комментарий
public String comment =
"v.1.1.1.56" + "\r\n" +
" - Добавлен класс MESS для системных сообщений/команд (без данных)." + "\r\n" +
"v.1.1.1.55" + "\r\n" +
" - Первая работающая (надеюсь) сборка под новый ПИВ." + "\r\n" +
"v.1.1.0.51" + "\r\n" +
" - Первая сборка под новый ПИВ." + "\r\n" +
"v.1.0.5.50" + "\r\n" +
" - Походу, крайняя версия под старый ПИВ." + "\r\n" +
" - Полезли непонятные глюки с выводом статистики на статусбар. Выкинул, заменил на простые метки. Не так красиво, но глюки ушли." + "\r\n" +
"v.1.0.5.37" + "\r\n" +
" - Переделан прием RS. Работает быстрее." + "\r\n" +
"v.1.0.5.34" + "\r\n" +
" - В вывод картинки на экран добавлена замазка (закрашивает пропущенные строки)." + "\r\n" +
" - Добавлена функция пропуска дефектных кадров (включено по умолчанию." + "\r\n" +
" - Опять переделан прием UDP. Вариант 3-й, надеюсь, последний. Работает быстрее и надежнее." + "\r\n" +
"v.1.0.4.21" + "\r\n" +
" - Опять переделан прием. Проверить не на чем." + "\r\n" +
"v.1.0.3.13" + "\r\n" +
" - Временно бросаю прием, перехожу на АС." + "\r\n" +
" - Прием UDP заработал лучше (переделка на очереди)." + "\r\n" +
"v.1.0.2.8" + "\r\n" +
" - Прием UDP заработал." + "\r\n" +
"v.1.0.1.6" + "\r\n" +
" - Релиз версии без приема UDP." + "\r\n" +
" - Прием и передача данных не зависит от номера порта." + "\r\n" +
"v.1.0.0.4" + "\r\n" +
" - Исправлены парочка мелких ошибок. Теперь данные в БОН пересылаются корректно." + "\r\n" +
"v.1.0.0.3" + "\r\n" +
" - Заработала отправка измененных данных в БОН." + "\r\n" +
" - Устранено несколько косяков. И добавлены новые... Пока не найдены." + "\r\n" +
"v.1.0.0.2" + "\r\n" +
" - Добавлена панель с информацией, полученной ПУ" + "\r\n" +
" - Добавлена панель с вкладками. На второй вкладке ручной ввод навигационной информации" + "\r\n" +
" - Сделано чтение информации из пакетов от БОН и отправка измененных данных в БОН" + "\r\n" +
"v.1.0.0.0" + "\r\n" +
" - Индикация обмена по шине RS-485" + "\r\n" +
"";
#endregion
public string ccc = "";
public AboutBox1(String comm)
{
InitializeComponent();
this.Text = String.Format("О программе {0}", ASMBL.AssemblyTitle);
this.labelProductName.Text = ASMBL.AssemblyProduct;
this.labelVersion.Text = String.Format("Версия {0}", ASMBL.AssemblyVersion);
this.labelCopyright.Text = ASMBL.AssemblyCopyright;
this.labelCompanyName.Text = ASMBL.AssemblyCompany;
this.label1.Text = ASMBL.AssemblyDescription;
// this.textBoxDescription.Text = comment;
this.textBoxDescription.Text = comm;
}
/*
#region Методы доступа к атрибутам сборки
public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion
*/
private void AboutBox1_Load(object sender, EventArgs e)
{
}
private void logoPictureBox_MouseEnter(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void logoPictureBox_MouseLeave(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (sw == 0)
{
logoPictureBox.Image = imageList1.Images[sw];
sw = 1;
}
else
{
logoPictureBox.Image = imageList1.Images[sw];
sw = 0;
}
}
}
}

3463
AboutBox1.resx

File diff suppressed because it is too large Load Diff

98
AdvancedRadioButton.cs

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Windows.Forms.VisualStyles;
using System.Drawing;
using System.ComponentModel;
namespace ARB
{
public class AdvancedRadioButton : CheckBox
{
public enum Level { Parent, Form };
[Category("AdvancedRadioButton"),
Description("Gets or sets the level that specifies which RadioButton controls are affected."),
DefaultValue(Level.Parent)]
public Level GroupNameLevel { get; set; }
[Category("AdvancedRadioButton"),
Description("Gets or sets the name that specifies which RadioButton controls are mutually exclusive.")]
public string GroupName { get; set; }
protected override void OnCheckedChanged(EventArgs e)
{
base.OnCheckedChanged(e);
if (Checked)
{
var arbControls = (dynamic)null;
switch (GroupNameLevel)
{
case Level.Parent:
if (this.Parent != null)
arbControls = GetAll(this.Parent, typeof(AdvancedRadioButton));
break;
case Level.Form:
Form form = this.FindForm();
if (form != null)
arbControls = GetAll(this.FindForm(), typeof(AdvancedRadioButton));
break;
}
if (arbControls != null)
foreach (Control control in arbControls)
if (control != this &&
(control as AdvancedRadioButton).GroupName == this.GroupName)
(control as AdvancedRadioButton).Checked = false;
}
}
protected override void OnClick(EventArgs e)
{
if (!Checked)
base.OnClick(e);
}
protected override void OnPaint(PaintEventArgs pevent)
{
CheckBoxRenderer.DrawParentBackground(pevent.Graphics, pevent.ClipRectangle, this);
RadioButtonState radioButtonState;
if (Checked)
{
radioButtonState = RadioButtonState.CheckedNormal;
if (Focused)
radioButtonState = RadioButtonState.CheckedHot;
if (!Enabled)
radioButtonState = RadioButtonState.CheckedDisabled;
}
else
{
radioButtonState = RadioButtonState.UncheckedNormal;
if (Focused)
radioButtonState = RadioButtonState.UncheckedHot;
if (!Enabled)
radioButtonState = RadioButtonState.UncheckedDisabled;
}
Size glyphSize = RadioButtonRenderer.GetGlyphSize(pevent.Graphics, radioButtonState);
Rectangle rect = pevent.ClipRectangle;
rect.Width -= glyphSize.Width;
rect.Location = new Point(rect.Left + glyphSize.Width, rect.Top);
RadioButtonRenderer.DrawRadioButton(pevent.Graphics, new System.Drawing.Point(0, rect.Height / 2 - glyphSize.Height / 2), rect, this.Text, this.Font, this.Focused, radioButtonState);
}
private IEnumerable<Control> GetAll(Control control, Type type)
{
var controls = control.Controls.Cast<Control>();
return controls.SelectMany(ctrl => GetAll(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
}
}

56
Class1.cs

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace INI
{
public class IniFile
{
[DllImport("kernel32.dll")]
private extern static int GetPrivateProfileString(String AppName, String KeyName, String Default, StringBuilder ReturnedString, UInt32 Size, String FileName);
[DllImport("kernel32.dll")]
private extern static int WritePrivateProfileString(String AppName, String KeyName, String Str, String FileName);
public IniFile(string filename)
{
IniFileName = filename;
}
public String IniFileName
{
get;
set;
}
public String _GetString(String section, String key)
{
StringBuilder s1 = new StringBuilder(128);
GetPrivateProfileString(section, key, "", s1, 128, IniFileName);
return s1.ToString();
}
public Int64 _GetInt(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Int64.Parse(s1.ToString());
}
public Double _GetDouble(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Double.Parse(s1.ToString());
}
public void _SetString(String section, String key, String val)
{
WritePrivateProfileString(section, key, val, IniFileName);
}
public void _SetInt(String section, String key, Int64 val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
public void _SetDouble(String section, String key, Double val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
}
}

51
Class2.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GKalman
{
public class GKalman
{
double _err_measure = 0.0F;
double _err_estimate = 0.0F;
double _q = 0.0F;
double _last_estimate = 0.0F;
public GKalman(float mea_e, float est_e, float q)
{
setParameters(mea_e, est_e, q);
}
// разброс измерения, скорость изменения значений (разброс измерения принимается равным разбросу оценки)
public GKalman(float mea_e, float q)
{
setParameters(mea_e, mea_e, q);
}
// разброс измерения, разброс оценки, скорость изменения значений
public void setParameters(float mea_e, float est_e, float q)
{
_err_measure = mea_e;
_err_estimate = est_e;
_q = q;
}
// разброс измерения, скорость изменения значений (разброс измерения принимается равным разбросу оценки)
public void setParameters(float mea_e, float q)
{
setParameters(mea_e, mea_e, q);
}
// возвращает фильтрованное значение
public float filtered(float value)
{
double _kalman_gain, _current_estimate;
_kalman_gain = _err_estimate / (_err_estimate + _err_measure);
_current_estimate = _last_estimate + _kalman_gain * (value - _last_estimate);
_err_estimate = (1.0 - _kalman_gain) * _err_estimate + Math.Abs(_last_estimate - _current_estimate) * _q;
_last_estimate = _current_estimate;
return (float)_current_estimate;
}
}
}

66
RichTextBoxExtensions.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Extensions
{
public static class RichTextBoxExtensions
{
public static void AppendText(this RichTextBox box, string text, Color color)
{
if (box.InvokeRequired)
{
box.Invoke((MethodInvoker)(delegate
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.ScrollToCaret();
}));
}
else
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.ScrollToCaret();
}
}
public static void AppendText(this RichTextBox box, string text, Color bgcolor, Color fgcolor)
{
if (box.InvokeRequired)
{
box.Invoke((MethodInvoker)(delegate
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = fgcolor;
box.SelectionBackColor = bgcolor;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.SelectionBackColor = box.BackColor;
box.ScrollToCaret();
}));
}
else
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = fgcolor;
box.SelectionBackColor = bgcolor;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.SelectionBackColor = box.BackColor;
box.ScrollToCaret();
}
}
}
}

97
UnsafeBitmap.cs

@ -0,0 +1,97 @@ @@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
namespace Grav01
{
public unsafe class UnsafeBitmap
{
Bitmap bitmap;
// three elements used for MakeGreyUnsafe
int width;
BitmapData bitmapData = null;
Byte* pBase = null;
public UnsafeBitmap(Bitmap bitmap)
{
this.bitmap = new Bitmap(bitmap);
}
public UnsafeBitmap(int width, int height)
{
this.bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
}
public void Dispose()
{
bitmap.Dispose();
}
public Bitmap Bitmap
{
get
{
return (bitmap);
}
}
private Point PixelSize
{
get
{
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF bounds = bitmap.GetBounds(ref unit);
return new Point((int)bounds.Width, (int)bounds.Height);
}
}
public void LockBitmap()
{
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF boundsF = bitmap.GetBounds(ref unit);
Rectangle bounds = new Rectangle((int)boundsF.X,
(int)boundsF.Y,
(int)boundsF.Width,
(int)boundsF.Height);
// Figure out the number of bytes in a row
// This is rounded up to be a multiple of 4
// bytes, since a scan line in an image must always be a multiple of 4 bytes
// in length.
width = (int)boundsF.Width * sizeof(PixelData);
if (width % 4 != 0)
{
width = 4 * (width / 4 + 1);
}
bitmapData =
bitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
pBase = (Byte*)bitmapData.Scan0.ToPointer();
}
public PixelData GetPixel(int x, int y)
{
PixelData returnValue = *PixelAt(x, y);
return returnValue;
}
public void SetPixel(int x, int y, PixelData colour)
{
PixelData* pixel = PixelAt(x, y);
*pixel = colour;
}
public void UnlockBitmap()
{
bitmap.UnlockBits(bitmapData);
bitmapData = null;
pBase = null;
}
public PixelData* PixelAt(int x, int y)
{
return (PixelData*)(pBase + y * width + x * sizeof(PixelData));
}
}
public struct PixelData
{
public byte blue;
public byte green;
public byte red;
}
}

182
asmbl.cs

@ -0,0 +1,182 @@ @@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
namespace ASM
{
public static class ASMBL
{
#region Методы доступа к атрибутам сборки
public static string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public static string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public static string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public static string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
#if DEBUG
return ((AssemblyProductAttribute)attributes[0]).Product + " Debug version";
#else
return ((AssemblyProductAttribute)attributes[0]).Product + " Release version";
#endif
}
}
public static string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public static string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
public static string AssemblyConfiguration
{
get
{
#if DEBUG
return "Debug version";
#else
return "Release version";
#endif
}
}
public static string[] AssemblyConf
{
get
{
string[] s = new string[11];
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
#if DEBUG
s[0] = "Debug version";
#else
s[0] = "Release version";
#endif
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyAlgorithmIdAttribute), false);
if (attributes.Length == 0)
s[1] = "AssemblyAlgorithmId = ";
else
s[1] = "AssemblyAlgorithmId = " + ((AssemblyAlgorithmIdAttribute)attributes[0]).AlgorithmId;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
s[2] = "AssemblyCompany = ";
else
s[2] = "AssemblyCompany = " + ((AssemblyCompanyAttribute)attributes[0]).Company;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
s[3] = "AssemblyCopyright = ";
else
s[3] = "AssemblyCopyright = " + ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
s[4] = "AssemblyDescription = ";
else
s[4] = "AssemblyDescription = " + ((AssemblyDescriptionAttribute)attributes[0]).Description;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
if (attributes.Length == 0)
s[5] = "AssemblyFileVersion = ";
else
s[5] = "AssemblyFileVersion = " + ((AssemblyFileVersionAttribute)attributes[0]).Version;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
if (attributes.Length == 0)
s[6] = "AssemblyInformationalVersion = ";
else
s[6] = "AssemblyInformationalVersion = " + ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
s[7] = "AssemblyProduct = ";
else
s[7] = "AssemblyProduct = " + ((AssemblyProductAttribute)attributes[0]).Product;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length == 0)
s[8] = "AssemblyTitle = ";
else
s[8] = "AssemblyTitle = " + ((AssemblyTitleAttribute)attributes[0]).Title;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false);
if (attributes.Length == 0)
s[9] = "AssemblyTrademark = ";
else
s[9] = "AssemblyTrademark = " + ((AssemblyTrademarkAttribute)attributes[0]).Trademark;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyVersionAttribute), false);
if (attributes.Length == 0)
s[10] = "AssemblyVersion = ";
else
s[10] = "AssemblyVersion = " + ((AssemblyVersionAttribute)attributes[0]).Version;
return s;
}
}
#endregion
}
}

51
gkalman.cs

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GKalman
{
public class GKalman
{
double _err_measure = 0.0F;
double _err_estimate = 0.0F;
double _q = 0.0F;
double _last_estimate = 0.0F;
public GKalman(double mea_e, double est_e, double q)
{
setParameters(mea_e, est_e, q);
}
// разброс измерения, скорость изменения значений (разброс измерения принимается равным разбросу оценки)
public GKalman(double mea_e, double q)
{
setParameters(mea_e, mea_e, q);
}
// разброс измерения, разброс оценки, скорость изменения значений
public void setParameters(double mea_e, double est_e, double q)
{
_err_measure = mea_e;
_err_estimate = est_e;
_q = q;
}
// разброс измерения, скорость изменения значений (разброс измерения принимается равным разбросу оценки)
public void setParameters(double mea_e, double q)
{
setParameters(mea_e, mea_e, q);
}
// возвращает фильтрованное значение
public double filtered(double value)
{
double _kalman_gain, _current_estimate;
_kalman_gain = _err_estimate / (_err_estimate + _err_measure);
_current_estimate = _last_estimate + _kalman_gain * (value - _last_estimate);
_err_estimate = (1.0 - _kalman_gain) * _err_estimate + Math.Abs(_last_estimate - _current_estimate) * _q;
_last_estimate = _current_estimate;
return (double)_current_estimate;
}
}
}

BIN
gravity2.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

66
inifile.cs

@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace INI
{
public class IniFile
{
[DllImport("kernel32.dll")]
private extern static int GetPrivateProfileString(String AppName, String KeyName, String Default, StringBuilder ReturnedString, UInt32 Size, String FileName);
[DllImport("kernel32.dll")]
private extern static int WritePrivateProfileString(String AppName, String KeyName, String Str, String FileName);
public IniFile(string filename)
{
IniFileName = filename;
}
public String IniFileName
{
get;
set;
}
public String _GetString(String section, String key)
{
StringBuilder s1 = new StringBuilder(128);
GetPrivateProfileString(section, key, "", s1, 128, IniFileName);
return s1.ToString();
}
public Int64 _GetInt(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Int64.Parse(s1.ToString());
}
public Boolean _GetBool(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Boolean.Parse(s1.ToString());
}
public Double _GetDouble(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Double.Parse(s1.ToString());
}
public void _SetString(String section, String key, String val)
{
WritePrivateProfileString(section, key, val, IniFileName);
}
public void _SetInt(String section, String key, Int64 val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
public void _SetDouble(String section, String key, Double val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
public void _SetBool(String section, String key, Boolean val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
}
}

20
inv.snippet

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Invoke</Title>
<Shortcut>inv</Shortcut>
<Description>Code snippet Invoke</Description>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[Invoke((MethodInvoker)(delegate
{
textBox17.Text += "\r\n\r\n" + ttt;
}));
this.pictureBox3.BeginInvoke((MethodInvoker)(() => this.pictureBox3.Image = crop));
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

49
loadstruct.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace LoadStruct
{
public static class S2B
{
#region Загрузка/выгрузка данных в структуру
public static T BuffToStruct<T>(byte[] arr)
{
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned);
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
T ret = (T)Marshal.PtrToStructure(ptr, typeof(T));
gch.Free();
return default(T);
}
public static T BuffToClass<T>(byte[] arr)
{
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned);
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
T ret = (T)Marshal.PtrToStructure(ptr, typeof(T));
gch.Free();
return default(T);
}
public static byte[] StructToBuff<T>(T value) where T : struct
{
byte[] arr = new byte[Marshal.SizeOf(value)]; // создать массив
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned); // зафиксировать в памяти
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0); // и взять его адрес
Marshal.StructureToPtr(value, ptr, true); // копировать в массив
gch.Free(); // снять фиксацию
return arr;
}
public static byte[] ClassToBuff<T>(T value) where T : class
{
byte[] arr = new byte[Marshal.SizeOf(value)]; // создать массив
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned); // зафиксировать в памяти
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0); // и взять его адрес
Marshal.StructureToPtr(value, ptr, true); // копировать в массив
gch.Free(); // снять фиксацию
return arr;
}
#endregion
}
}

2347
piv.cs

File diff suppressed because it is too large Load Diff

207
rtp.cs

@ -0,0 +1,207 @@ @@ -0,0 +1,207 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace nRTP
{
public static class RTP
{
//RTPMsgHeader
private static Byte _VerPXCC = 2;
private static Byte _Ver = 2; // версия протокола (текущая версия 2)
private static Byte _P = 0; // = 0 (не используется заполнение в конце пакета)
private static Byte _X = 0; // = 0 (не используются дополнительные заголовки)
private static Byte _CC = 0; // = 0 (CSRC - идентификаторы не используются);
private static Byte _MPT;
private static Byte _M; // маркерный бит.
private static Byte _PT = 99; // поле идентифицирует формат трафика RTP и определяет его интерпретацию. Задается 99
private static UInt32 _Seqcounter = 0;
private static UInt16 _SeqCounter_Hi;
private static UInt16 _SeqCounter_Low;
public static Byte MH_VerPXCC
{
get => _VerPXCC;
set
{
_VerPXCC = value;
_Ver = (Byte)(value & 0x03);
_P = (Byte)((value >> 2) & 0x01);
_X = (Byte)((value >> 3) & 0x01);
_CC = (Byte)((value >> 4) & 0x0F);
}
}
public static Byte MH_MPT
{
get
{
return (Byte)((_PT << 1) | _M);
}
set
{
_MPT = value;
_M = (Byte)(value & 0x01);
_PT = (Byte)((value >> 1) & 0x7F);
}
}
public static Byte MH_M // маркерный бит.
{
get => _M;
set
{
_M = value;
}
}
public static Byte MH_PT // поле идентифицирует формат трафика RTP и определяет его интерпретацию. Задается 99
{
get => _PT;
set
{
_PT = value;
}
}
public static UInt16 MH_SeqCounter_Low // Номер последовательности (младшие 16 бит)
{
get => _SeqCounter_Low;
set
{
_SeqCounter_Low = value;
}
}
public static UInt32 MH_Timestamp; // Метка времени (90 кГц отсчеты), одинакова для всех пакетов кадра
public static UInt32 MH_SSRC; // 12345678 (идентификатор источника информации)
public static UInt16 MH_SeqCounter_Hi // Номер последовательности (старшие 16 бит)
{
get => _SeqCounter_Hi;
set
{
_SeqCounter_Hi = value;
}
}
public static UInt16 MH_DataLen; // Количество байт данных строки, включенной в пакет
public static UInt16 MH_RowNumber; // Номер строки
public static UInt16 MH_Offset; // Смещение первого пиксела в строке (= 0)
//RTPVideoSupplementalData
public static UInt16 SD_Width; // Ширина (пиксели)
public static UInt16 SD_Height; // Высота (пиксели)
public static float SD_AzUpr; // (град)
public static float SD_ElUpr; // (град)
public static Int16 SD_Course; // Курс БЛА (0,01 град)
public static Int16 SD_Roll; // Крен БЛА (0,01 град)
public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град)
public static Int16 SD_FrameId;
//RTPVideoSupplementalDataExtra
public static UInt32 DE_TLV_X; // Линия визирования цели в растроввых координатах
public static UInt32 DE_TLV_Y; //
public static UInt32 DE_TLV_dX; // поправки для линии визирования цели в растроввых координатах
public static UInt32 DE_TLV_dY; //
public static UInt32 SeqCounter
{
get
{
return (UInt32)((_SeqCounter_Hi << 16) | _SeqCounter_Low);
}
set
{
_SeqCounter_Low = (UInt16)value;
_SeqCounter_Hi = (UInt16)((value >> 16) & 0xFFFF);
}
}
public static Byte[] DataH0 = new Byte[56];
public static Byte[] DataH1 = new Byte[20];
public static void MakeDataH0()
{
Array.Copy(BitConverter.GetBytes(RTP.MH_VerPXCC), 0, DataH0, 0, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_MPT), 0, DataH0, 1, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Low), 0, DataH0, 2, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Timestamp), 0, DataH0, 4, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SSRC), 0, DataH0, 8, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Hi), 0, DataH0, 12, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_DataLen), 0, DataH0, 14, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_RowNumber), 0, DataH0, 16, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Offset), 0, DataH0, 18, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Width), 0, DataH0, 20, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Height), 0, DataH0, 22, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_AzUpr), 0, DataH0, 24, 4);
Array.Copy(BitConverter.GetBytes(RTP.SD_ElUpr), 0, DataH0, 28, 4);
Array.Copy(BitConverter.GetBytes(RTP.SD_Course), 0, DataH0, 32, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Roll), 0, DataH0, 34, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Pitch), 0, DataH0, 36, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_FrameId), 0, DataH0, 38, 2);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_X), 0, DataH0, 40, 4);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_Y), 0, DataH0, 44, 4);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_dX), 0, DataH0, 48, 4);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_dY), 0, DataH0, 52, 4);
}
public static void MakeDataH1()
{
Array.Copy(BitConverter.GetBytes(RTP.MH_VerPXCC), 0, DataH1, 0, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_MPT), 0, DataH1, 1, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Low), 0, DataH1, 2, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Timestamp), 0, DataH1, 4, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SSRC), 0, DataH1, 8, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Hi), 0, DataH1, 12, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_DataLen), 0, DataH1, 14, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_RowNumber), 0, DataH1, 16, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Offset), 0, DataH1, 18, 2);
}
/*
struct RTPMsgHeader
{
uint8_t Ver : 2; // версия протокола (текущая версия 2)
uint8_t P : 1; // = 0 (не используется заполнение в конце пакета)
uint8_t X : 1; // = 0 (не используются дополнительные заголовки)
uint8_t CC : 4; // = 0 (CSRC - идентификаторы не используются);
uint8_t M : 1; // маркерный бит. Установка этого бита в 1 свидетельствует о том, что данный UDP – пакет содержит последнюю строку кадра, для всех остальных пакетов задается 0
uint8_t PT : 7; // поле идентифицирует формат трафика RTP и определяет его интерпретацию. Задается 99
uint16_t SeqCounter_Low; // Номер последовательности (младшие 16 бит)
uint32_t Timestamp; // Метка времени (90 кГц отсчеты), одинакова для всех пакетов кадра
uint32_t SSRC; // 12345678 (идентификатор источника информации)
uint16_t SeqCounter_Hi; // Номер последовательности (старшие 16 бит)
uint16_t DataLen; // Количество байт данных строки, включенной в пакет
uint16_t RowNumber; // Номер строки
uint16_t Offset; // Смещение первого пиксела в строке (= 0)
uint32_t get_seqcounter() { return ((SeqCounter_Hi << 16) | SeqCounter_Low); }
};
//------------------------------------------------------------------------------------------------------------
struct RTPVideoSupplementalData
{
uint16_t Width; // Ширина (пиксели)
uint16_t Height; // Высота (пиксели)
float AzUpr; // (град)
float ElUpr; // (град)
int16_t Course; // Курс БЛА (0,01 град)
int16_t Roll; // Крен БЛА (0,01 град)
int16_t Pitch; // Тангаж БЛА (0,01 град)
int16_t FrameId;
RTPVideoSupplementalData()
{
::memset(this, 0, sizeof(RTPVideoSupplementalData));
}
};
//------------------------------------------------------------------------------------------------------------
// Дополнительные данные нулевой строки выходящие за рамки ПИВ
struct RTPVideoSupplementalDataExtra
{
uint32_t TLV_X; // Линия визирования цели в растроввых координатах
uint32_t TLV_Y; //
uint32_t TLV_dX; // поправки для линии визирования цели в растроввых координатах
uint32_t TLV_dY; //
};
*/
}
}

558
util.cs

@ -0,0 +1,558 @@ @@ -0,0 +1,558 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.ComponentModel;
using System.Drawing.Imaging;
namespace UTIL
{
public static class ASMBL
{
#region Методы доступа к атрибутам сборки
public static string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public static string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public static string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public static string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
#if DEBUG
return ((AssemblyProductAttribute)attributes[0]).Product + " Debug version";
#else
return ((AssemblyProductAttribute)attributes[0]).Product + " Release version";
#endif
}
}
public static string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public static string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
public static string AssemblyConfiguration
{
get
{
#if DEBUG
return "Debug version";
#else
return "Release version";
#endif
}
}
public static string[] AssemblyConf
{
get
{
string[] s = new string[11];
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
#if DEBUG
s[0] = "Debug version";
#else
s[0] = "Release version";
#endif
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyAlgorithmIdAttribute), false);
if (attributes.Length == 0)
s[1] = "AssemblyAlgorithmId = ";
else
s[1] = "AssemblyAlgorithmId = " + ((AssemblyAlgorithmIdAttribute)attributes[0]).AlgorithmId;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
s[2] = "AssemblyCompany = ";
else
s[2] = "AssemblyCompany = " + ((AssemblyCompanyAttribute)attributes[0]).Company;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
s[3] = "AssemblyCopyright = ";
else
s[3] = "AssemblyCopyright = " + ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
s[4] = "AssemblyDescription = ";
else
s[4] = "AssemblyDescription = " + ((AssemblyDescriptionAttribute)attributes[0]).Description;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
if (attributes.Length == 0)
s[5] = "AssemblyFileVersion = ";
else
s[5] = "AssemblyFileVersion = " + ((AssemblyFileVersionAttribute)attributes[0]).Version;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
if (attributes.Length == 0)
s[6] = "AssemblyInformationalVersion = ";
else
s[6] = "AssemblyInformationalVersion = " + ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
s[7] = "AssemblyProduct = ";
else
s[7] = "AssemblyProduct = " + ((AssemblyProductAttribute)attributes[0]).Product;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length == 0)
s[8] = "AssemblyTitle = ";
else
s[8] = "AssemblyTitle = " + ((AssemblyTitleAttribute)attributes[0]).Title;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false);
if (attributes.Length == 0)
s[9] = "AssemblyTrademark = ";
else
s[9] = "AssemblyTrademark = " + ((AssemblyTrademarkAttribute)attributes[0]).Trademark;
attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyVersionAttribute), false);
if (attributes.Length == 0)
s[10] = "AssemblyVersion = ";
else
s[10] = "AssemblyVersion = " + ((AssemblyVersionAttribute)attributes[0]).Version;
return s;
}
}
#endregion
}
public class IniFile
{
[DllImport("kernel32.dll")]
private extern static int GetPrivateProfileString(String AppName, String KeyName, String Default, StringBuilder ReturnedString, UInt32 Size, String FileName);
[DllImport("kernel32.dll")]
private extern static int WritePrivateProfileString(String AppName, String KeyName, String Str, String FileName);
public IniFile(string filename)
{
IniFileName = filename;
}
public String IniFileName
{
get;
set;
}
public String _GetString(String section, String key)
{
StringBuilder s1 = new StringBuilder(128);
GetPrivateProfileString(section, key, "", s1, 128, IniFileName);
return s1.ToString();
}
public Int64 _GetInt(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Int64.Parse(s1.ToString());
}
public Boolean _GetBool(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Boolean.Parse(s1.ToString());
}
public Double _GetDouble(String section, String key)
{
StringBuilder s1 = new StringBuilder(100);
GetPrivateProfileString(section, key, "", s1, 100, IniFileName);
return Double.Parse(s1.ToString());
}
public void _SetString(String section, String key, String val)
{
WritePrivateProfileString(section, key, val, IniFileName);
}
public void _SetInt(String section, String key, Int64 val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
public void _SetDouble(String section, String key, Double val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
public void _SetBool(String section, String key, Boolean val)
{
WritePrivateProfileString(section, key, val.ToString(), IniFileName);
}
}
public static class S2B
{
#region Загрузка/выгрузка данных в структуру
public static T BuffToStruct<T>(byte[] arr)
{
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned);
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
T ret = (T)Marshal.PtrToStructure(ptr, typeof(T));
gch.Free();
return default(T);
}
public static T BuffToClass<T>(byte[] arr)
{
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned);
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
T ret = (T)Marshal.PtrToStructure(ptr, typeof(T));
gch.Free();
return default(T);
}
public static byte[] StructToBuff<T>(T value) where T : struct
{
byte[] arr = new byte[Marshal.SizeOf(value)]; // создать массив
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned); // зафиксировать в памяти
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0); // и взять его адрес
Marshal.StructureToPtr(value, ptr, true); // копировать в массив
gch.Free(); // снять фиксацию
return arr;
}
public static byte[] ClassToBuff<T>(T value) where T : class
{
byte[] arr = new byte[Marshal.SizeOf(value)]; // создать массив
GCHandle gch = GCHandle.Alloc(arr, GCHandleType.Pinned); // зафиксировать в памяти
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0); // и взять его адрес
Marshal.StructureToPtr(value, ptr, true); // копировать в массив
gch.Free(); // снять фиксацию
return arr;
}
#endregion
}
public static class RichTextBoxExtensions
{
public static void AppendText(this RichTextBox box, string text, Color color)
{
if (box.InvokeRequired)
{
box.Invoke((MethodInvoker)(delegate
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.ScrollToCaret();
}));
}
else
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.ScrollToCaret();
}
}
public static void AppendText(this RichTextBox box, string text, Color bgcolor, Color fgcolor)
{
if (box.InvokeRequired)
{
box.Invoke((MethodInvoker)(delegate
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = fgcolor;
box.SelectionBackColor = bgcolor;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.SelectionBackColor = box.BackColor;
box.ScrollToCaret();
}));
}
else
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = fgcolor;
box.SelectionBackColor = bgcolor;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.SelectionBackColor = box.BackColor;
box.ScrollToCaret();
}
}
}
public class AdvancedRadioButton : CheckBox
{
public enum Level { Parent, Form };
[Category("AdvancedRadioButton"),
Description("Gets or sets the level that specifies which RadioButton controls are affected."),
DefaultValue(Level.Parent)]
public Level GroupNameLevel { get; set; }
[Category("AdvancedRadioButton"),
Description("Gets or sets the name that specifies which RadioButton controls are mutually exclusive.")]
public string GroupName { get; set; }
protected override void OnCheckedChanged(EventArgs e)
{
base.OnCheckedChanged(e);
if (Checked)
{
var arbControls = (dynamic)null;
switch (GroupNameLevel)
{
case Level.Parent:
if (this.Parent != null)
arbControls = GetAll(this.Parent, typeof(AdvancedRadioButton));
break;
case Level.Form:
Form form = this.FindForm();
if (form != null)
arbControls = GetAll(this.FindForm(), typeof(AdvancedRadioButton));
break;
}
if (arbControls != null)
foreach (Control control in arbControls)
if (control != this &&
(control as AdvancedRadioButton).GroupName == this.GroupName)
(control as AdvancedRadioButton).Checked = false;
}
}
protected override void OnClick(EventArgs e)
{
if (!Checked)
base.OnClick(e);
}
protected override void OnPaint(PaintEventArgs pevent)
{
CheckBoxRenderer.DrawParentBackground(pevent.Graphics, pevent.ClipRectangle, this);
RadioButtonState radioButtonState;
if (Checked)
{
radioButtonState = RadioButtonState.CheckedNormal;
if (Focused)
radioButtonState = RadioButtonState.CheckedHot;
if (!Enabled)
radioButtonState = RadioButtonState.CheckedDisabled;
}
else
{
radioButtonState = RadioButtonState.UncheckedNormal;
if (Focused)
radioButtonState = RadioButtonState.UncheckedHot;
if (!Enabled)
radioButtonState = RadioButtonState.UncheckedDisabled;
}
Size glyphSize = RadioButtonRenderer.GetGlyphSize(pevent.Graphics, radioButtonState);
Rectangle rect = pevent.ClipRectangle;
rect.Width -= glyphSize.Width;
rect.Location = new Point(rect.Left + glyphSize.Width, rect.Top);
RadioButtonRenderer.DrawRadioButton(pevent.Graphics, new System.Drawing.Point(0, rect.Height / 2 - glyphSize.Height / 2), rect, this.Text, this.Font, this.Focused, radioButtonState);
}
private IEnumerable<Control> GetAll(Control control, Type type)
{
var controls = control.Controls.Cast<Control>();
return controls.SelectMany(ctrl => GetAll(ctrl, type))
.Concat(controls)
.Where(c => c.GetType() == type);
}
}
public class GKalman
{
double _err_measure = 0.0F;
double _err_estimate = 0.0F;
double _q = 0.0F;
double _last_estimate = 0.0F;
public GKalman(double mea_e, double est_e, double q)
{
setParameters(mea_e, est_e, q);
}
// разброс измерения, скорость изменения значений (разброс измерения принимается равным разбросу оценки)
public GKalman(double mea_e, double q)
{
setParameters(mea_e, mea_e, q);
}
// разброс измерения, разброс оценки, скорость изменения значений
public void setParameters(double mea_e, double est_e, double q)
{
_err_measure = mea_e;
_err_estimate = est_e;
_q = q;
}
// разброс измерения, скорость изменения значений (разброс измерения принимается равным разбросу оценки)
public void setParameters(double mea_e, double q)
{
setParameters(mea_e, mea_e, q);
}
// возвращает фильтрованное значение
public double filtered(double value)
{
double _kalman_gain, _current_estimate;
_kalman_gain = _err_estimate / (_err_estimate + _err_measure);
_current_estimate = _last_estimate + _kalman_gain * (value - _last_estimate);
_err_estimate = (1.0 - _kalman_gain) * _err_estimate + Math.Abs(_last_estimate - _current_estimate) * _q;
_last_estimate = _current_estimate;
return (double)_current_estimate;
}
}
public unsafe class UnsafeBitmap
{
Bitmap bitmap;
// three elements used for MakeGreyUnsafe
int width;
BitmapData bitmapData = null;
Byte* pBase = null;
public UnsafeBitmap(Bitmap bitmap)
{
this.bitmap = new Bitmap(bitmap);
}
public UnsafeBitmap(int width, int height)
{
this.bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
}
public void Dispose()
{
bitmap.Dispose();
}
public Bitmap Bitmap
{
get
{
return (bitmap);
}
}
private Point PixelSize
{
get
{
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF bounds = bitmap.GetBounds(ref unit);
return new Point((int)bounds.Width, (int)bounds.Height);
}
}
public void LockBitmap()
{
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF boundsF = bitmap.GetBounds(ref unit);
Rectangle bounds = new Rectangle((int)boundsF.X,
(int)boundsF.Y,
(int)boundsF.Width,
(int)boundsF.Height);
// Figure out the number of bytes in a row
// This is rounded up to be a multiple of 4
// bytes, since a scan line in an image must always be a multiple of 4 bytes
// in length.
width = (int)boundsF.Width * sizeof(PixelData);
if (width % 4 != 0)
{
width = 4 * (width / 4 + 1);
}
bitmapData =
bitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
pBase = (Byte*)bitmapData.Scan0.ToPointer();
}
public PixelData GetPixel(int x, int y)
{
PixelData returnValue = *PixelAt(x, y);
return returnValue;
}
public void SetPixel(int x, int y, PixelData colour)
{
PixelData* pixel = PixelAt(x, y);
*pixel = colour;
}
public void UnlockBitmap()
{
bitmap.UnlockBits(bitmapData);
bitmapData = null;
pBase = null;
}
public PixelData* PixelAt(int x, int y)
{
return (PixelData*)(pBase + y * width + x * sizeof(PixelData));
}
}
public struct PixelData
{
public byte blue;
public byte green;
public byte red;
}
}
Loading…
Cancel
Save