diff --git a/piv.cs b/piv.cs index 33ece37..c78b2b0 100644 --- a/piv.cs +++ b/piv.cs @@ -1,9 +1,13 @@ -using System; +#define VLADIMIR + +using System; +using UTIL; /// /// Ноавя версия ПИВ 1.23 /// + namespace PIV { public static class CONST @@ -2182,6 +2186,12 @@ namespace PIV /// public static class AZUM { + public static int WF { get => (int)Wfull; set => Wfull = (double)value; } + public static int HF { get => (int)Hfull; set => Hfull = (double)value; } + private static Double Wfull; // = (Double)WF; + private static Double Hfull; // = (Double)HF; + //const Double Wfull = 4072.0; + //const Double Hfull = 3064.0; /* private static void pix2ang() { @@ -2272,31 +2282,41 @@ namespace PIV //% w - количество столбцов изображения //% h - количество строк изображения //sAZUM retu; + if (WF == 0 || HF == 0) + { + throw new Exception("Не заданы значения размера матрицы!"); + } + Double w_full = Wfull; + Double h_full = Hfull; - Double w_full = 4072.0; - Double h_full = 3064.0; - +//#if DEBUG +// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}"); +//#endif +#if VLADIMIR + Double focus_meters = 27.5e-3; + Double pixel_size_meters = 3.2e-6; //22.5'' +#else Double focus_meters = 12e-3; Double pixel_size_meters = 1.55e-6; - +#endif Double rad2deg = (180.0 / (Double)Math.PI); - Double f = focus_meters / pixel_size_meters; + //Double xc_full = 0.5f * w_full; + //Double yc_full = 0.5f * h_full; + Double xc_full = 0.5f * w_full; - Double yc_full = 0.5f * h_full; + Double yc_full = (6.0 / 42.0) * h_full; Double x_full = (X + 0.5) * w_full / W; Double y_full = (Y + 0.5) * h_full / H; - Double x_ohf = x_full - xc_full; Double y_ohf = y_full - yc_full; Double z_ohf = f; - Double rho = (Double)Math.Sqrt(x_ohf * x_ohf + z_ohf * z_ohf); A = (Double)Math.Atan2(x_ohf, z_ohf) * rad2deg; U = (Double)(-Math.Atan2(y_ohf, rho) * rad2deg); } - public static void pix2ang(ref float A, ref float U, float W, float H, float X, float Y) + public static void p2a(ref Double A, ref Double U, Double W, Double H, Double X, Double Y) { //% (x, y) - координаты центра пикселя изображения //% начало O = (0, 0) системы координат изображения находится @@ -2307,18 +2327,75 @@ namespace PIV //% w - количество столбцов изображения //% h - количество строк изображения //sAZUM retu; + if (WF == 0 || HF == 0) + { + throw new Exception("Не заданы значения размера матрицы!"); + } + Double w_full = Wfull; + Double h_full = Hfull; - float w_full = (float)4072.0; - float h_full = (float)3064.0; +//#if DEBUG +// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}"); +//#endif +#if VLADIMIR + Double focus_meters = 27.5e-3; + Double pixel_size_meters = 3.2e-6; //22.5'' +#else + Double focus_meters = 12e-3; + Double pixel_size_meters = 1.55e-6; +#endif + Double rad2deg = (180.0 / (Double)Math.PI); + Double f = focus_meters / pixel_size_meters; + //Double xc_full = 0.5f * w_full; + //Double yc_full = 0.5f * h_full; - float focus_meters = 12e-3F; - float pixel_size_meters = 1.55e-6F; + Double xc_full = 0.5f * w_full; + Double yc_full = (6.0 / 42.0) * h_full; - float rad2deg = (180.0F / (float)Math.PI); + Double x_full = (X + 0.5) * w_full / W; + Double y_full = (Y + 0.5) * h_full / H; + Double x_ohf = x_full - xc_full; + Double y_ohf = y_full - yc_full; + Double z_ohf = f; + Double rho = (Double)Math.Sqrt(x_ohf * x_ohf + z_ohf * z_ohf); + A = (Double)Math.Atan2(x_ohf, z_ohf) * rad2deg; + U = (Double)(-Math.Atan2(y_ohf, rho) * rad2deg); + } + public static void pix2ang(ref float A, ref float U, float W, float H, float X, float Y) + { + //% (x, y) - координаты центра пикселя изображения + //% начало O = (0, 0) системы координат изображения находится + //% в центре левого верхнего пикселя + //% ось OX направлена вправо по возрастанию номеров столбцов + //% ось OY направлена вниз по возрастанию номеров строк + //% + //% w - количество столбцов изображения + //% h - количество строк изображения + //sAZUM retu; + if (WF == 0 || HF == 0) + { + throw new Exception("Не заданы значения размера матрицы!"); + } + float w_full = (float)Wfull; + float h_full = (float)Hfull; +//#if DEBUG +// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}"); +//#endif +#if VLADIMIR + float focus_meters = 27.5e-3F; + float pixel_size_meters = 3.2e-6F; //22.5'' +#else + float focus_meters = 12e-3; + float pixel_size_meters = 1.55e-6; +#endif + float rad2deg = (180.0F / (float)Math.PI); float f = focus_meters / pixel_size_meters; + //float xc_full = 0.5f * w_full; + //float yc_full = 0.5f * h_full; + float xc_full = 0.5f * w_full; - float yc_full = 0.5f * h_full; + float yc_full = (6.0F / 42.0F) * h_full; float x_full = (float)(X + 0.5) * w_full / W; float y_full = (float)(Y + 0.5) * h_full / H; @@ -2345,17 +2422,29 @@ namespace PIV //% w - количество столбцов изображения, double //% h - количество строк изображения, double - Double w_full = (Double)(4072); - Double h_full = (Double)(3064); - - Double focus_meters = (Double)(12e-3); - Double pixel_size_meters = (Double)(1.55e-6); - + if (WF == 0 || HF == 0) + { + throw new Exception("Не заданы значения размера матрицы!"); + } + Double w_full = (Double)Wfull; + Double h_full = (Double)Hfull; +//#if DEBUG +// Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}"); +//#endif +#if VLADIMIR + Double focus_meters = 27.5e-3; + Double pixel_size_meters = 3.2e-6; //22.5'' +#else + Double focus_meters = 12e-3; + Double pixel_size_meters = 1.55e-6; +#endif Double deg2rad = (Double)(Math.PI / 180.0); //% pi = 3.14... - //float rad2deg = (180.0f /3.1415926f); Double f = focus_meters / pixel_size_meters; - Double xc_full = 0.5 * w_full; - Double yc_full = 0.5 * h_full; + + //Double xc_full = 0.5 * w_full; + //Double yc_full = 0.5 * h_full; + Double xc_full = 0.5f * w_full; + Double yc_full = (6.0 / 42.0) * h_full; //_au.A = _au.A * deg2rad; //_au.U = _au.U * deg2rad; @@ -2387,17 +2476,32 @@ namespace PIV //% w - количество столбцов изображения, double //% h - количество строк изображения, double - float w_full = 4072F; - float h_full = 3064F; + if (WF == 0 || HF == 0) + { + throw new Exception("Не заданы значения размера матрицы!"); + } + float w_full = (float)Wfull; + float h_full = (float)Hfull; +#if DEBUG + Console.WriteLine($"{Util.printdatetime(false)}{w_full} {h_full}"); +#endif - float focus_meters = 12e-3F; - float pixel_size_meters = 1.55e-6F; +#if VLADIMIR + float focus_meters = 27.5e-3F; + float pixel_size_meters = 3.2e-6F; //22.5'' +#else + float focus_meters = 12e-3; + float pixel_size_meters = 1.55e-6; +#endif float deg2rad = (float)(Math.PI / 180.0); //% pi = 3.14... //float rad2deg = (180.0f /3.1415926f); float f = focus_meters / pixel_size_meters; - float xc_full = 0.5F * w_full; - float yc_full = 0.5F * h_full; + + //float xc_full = 0.5F * w_full; + //float yc_full = 0.5F * h_full; + float xc_full = 0.5f * w_full; + float yc_full = (6.0F / 42.0F) * h_full; //_au.A = _au.A * deg2rad; //_au.U = _au.U * deg2rad; diff --git a/reg.cs b/reg.cs new file mode 100644 index 0000000..aad1e4a --- /dev/null +++ b/reg.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +//using System.IO.Ports; +//using System.Runtime.InteropServices; +using Microsoft.Win32; + +namespace UTIL +{ + public class Reg + { + private RegistryKey rk; + public Reg(RegistryKey k, string path) + { + rk = k.OpenSubKey(path, true); + if (rk == null) + { + rk = k.CreateSubKey(path, true); + } + + } + public string ReadKey(string keyname) + { + if (rk.GetValue(keyname) != null) + return rk.GetValue(keyname).ToString(); + else + return null; + } + public void WriteKey(string keyname, string val) + { + rk.SetValue(keyname, val); + } + } +} diff --git a/tcp — копия.cs b/tcp — копия.cs new file mode 100644 index 0000000..a85f025 --- /dev/null +++ b/tcp — копия.cs @@ -0,0 +1,370 @@ +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; +//using System.Threading.Tasks; +//using System.Windows.Forms; +//using System.Xml.Linq; +//using UDPLIB; +using UTIL; +//using PIV; +//using static UDPLIB.CallBack; +//using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button; +//using System.Reflection.Emit; +//using System.Drawing.Drawing2D; +//using System.Drawing.Imaging; +using System.Runtime.InteropServices; +//using System.Net.Sockets; +//using System.IO; +//using System.Net.Http; +//using Microsoft.Win32; + +namespace nTCP +{ + public static class TCP + { + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public static unsafe struct tcpControlHeader_s + { + public UInt16 signature; + public UInt16 cmd; + public UInt32 length; + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public unsafe struct tcpControlStatus_s + { + public tcpControlHeader_s hdr; + public UInt16 cmd; + public Byte status; + public Byte ext; + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public unsafe struct tcpControlVPFE_SensorCfg_s + { + public tcpControlHeader_s hdr; + public VPFE_sensorCfg_s cfg; + } + [StructLayout(LayoutKind.Explicit, Size = 20)] + public unsafe struct tcpControlVPFE_CCM_s + { + [FieldOffset(0)] + public tcpControlHeader_s hdr; + [FieldOffset(8)] + public UInt16[] k; + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public unsafe struct VPFE_roi_s + { + public UInt16 x; + public UInt16 y; + public UInt16 width; + public UInt16 height; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public unsafe struct VPFE_sensorCfg_s + { + public UInt32 expTimeUs; + public UInt32 framePeriodUs; + public VPFE_roi_s roi; + } + + public const UInt16 OES_CNTRL_CMD_SET_VPFE_SENSOR_CFG = 0x0004; + public const UInt16 OES_CNTRL_CMD_SET_VPFE_CCM = 0x0005; + public const UInt16 OES_CNTRL_CMD_SET_VPFE_AE = 0x0006; // Set Auto Exposure + public const UInt16 OES_CNTRL_CMD_SET_VPFE_AWB = 0x0007; // Set Auto White Balance + public const UInt16 OES_CNTRL_CMD_SET_VPFE_GC = 0x0008; // Set Gamma correction + public const UInt16 OES_CNTRL_CMD_SET_VPFE_ABL = 0x0009; + public const UInt16 OES_CNTRL_CMD_SET_VIDEO_FORMAT = 0x0010; + + public const UInt16 OES_CNTRL_CMD_GET_VPFE_SENSOR_CFG = 0x0084; + public const UInt16 OES_CNTRL_CMD_GET_VPFE_CCM = 0x0085; + public const UInt16 OES_CNTRL_CMD_GET_VPFE_AE = 0x0086; // Get Auto Exposure + public const UInt16 OES_CNTRL_CMD_GET_VPFE_AWB = 0x0087; // Get Auto White Balance + public const UInt16 OES_CNTRL_CMD_GET_VPFE_GC = 0x0088; // Get Gamma correction + public const UInt16 OES_CNTRL_CMD_GET_VPFE_ABL = 0x0089; + + private static Int32 _tcpControlHeader = Marshal.SizeOf(typeof(tcpControlHeader_s)); + private static Int32 _tcpControlStatus = Marshal.SizeOf(typeof(tcpControlStatus_s)); + private static Int32 _tcpControlVPFE_SensorCfg = Marshal.SizeOf(typeof(tcpControlVPFE_SensorCfg_s)); + private static Int32 _tcpControlVPFE_CCM = Marshal.SizeOf(typeof(tcpControlVPFE_CCM_s)); + + private static Int32 _VPFE_roi = Marshal.SizeOf(typeof(VPFE_roi_s)); + private static Int32 _VPFE_sensorCfg = Marshal.SizeOf(typeof(VPFE_sensorCfg_s)); + private static Int32 _VPFE_CCM = 12; + + public static (Int32, Int32, Int32) ggg() + { + tcpControlVPFE_SensorCfg_s. + return (_tcpControlVPFE_SensorCfg, _tcpControlVPFE_CCM, _tcpControlStatus); + } + + //RTPMsgHeader + private const UInt32 _len_pack = 60; + private const UInt32 _len_head = 20; + private static UInt32 _len_data = _len_pack - _len_head; + + 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; + private static Byte _rejim_oes; + private static Byte _zahvat; + private static Byte _color; + private static Byte _status; + + 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 = (UInt16)_len_data; // Количество байт данных строки, включенной в пакет + 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 Int32 SD_Shirota; // Широта БЛА (1е-7 град) + public static Int32 SD_Dolgota; // Долгота БЛА (1е-7 град) + public static Int32 SD_Vysota; // Высота БЛА (0,01 м) + + public static Int16 SD_Course; // Курс БЛА (0,01 град) + public static Int16 SD_Roll; // Крен БЛА (0,01 град) + public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град) + + public static UInt16 rez0; // координата центра цели в растре изображения по горизонтали + public static UInt16 rez1; //координата центра цели в растре изображения по вертикали + public static UInt16 rez2; //координата центра цели в растре изображения по вертикали + + public static Byte rez3; // размер цели в растре эталонного изображения по горизонтали + public static Byte rez4; // размер цели в растре эталонного изображения по вертикали + + public static Byte SD_rejim_oes // Режим ОЭС: «0» – Обзор, «1» – АС + { + get => _rejim_oes; + set => _rejim_oes = value; + } + public static Byte SD_zahvat // Захват: «0» – отсутствие захвата, «1» – налачие захвата + { + get => _zahvat; + set => _zahvat = value; + } + public static Byte SD_color // Цвет изображения: «1» – цветное, «0» – монохромное + { + get => _color; + set => _color = value; + } + public static Byte SD_Status + { + get + { + _status = 0; + _status |= (Byte)(_rejim_oes << 0); + _status |= (Byte)(_zahvat << 1); + _status |= (Byte)(_color << 2); + return _status; + } + set + { + _status = value; + _rejim_oes = (Byte)((value >> 0) & 0x01); + _zahvat = (Byte)((value >> 1) & 0x01); + _color = (Byte)((value >> 2) & 0x01); + } + } + public static Byte rez5; + + 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[_len_pack]; + //public static Byte[] DataH0 = new Byte[76]; + public static Byte[] DataH1 = new Byte[_len_head]; + + public static void MakeDataH0() + { + Array.Copy(BitConverter.GetBytes(MH_VerPXCC), 0, DataH0, 0, 1); // 0 - 0 + Array.Copy(BitConverter.GetBytes(MH_MPT), 0, DataH0, 1, 1); // 1 - 1 + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Low), 0, DataH0, 2, 2); // 2 - 3 + Array.Copy(BitConverter.GetBytes(MH_Timestamp), 0, DataH0, 4, 4); // 4 - 7 + Array.Copy(BitConverter.GetBytes(MH_SSRC), 0, DataH0, 8, 4); // 8 - 11 + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Hi), 0, DataH0, 12, 2); // 12 - 13 + Array.Copy(BitConverter.GetBytes(MH_DataLen), 0, DataH0, 14, 2); // 14 - 15 + Array.Copy(BitConverter.GetBytes(MH_RowNumber), 0, DataH0, 16, 2); // 16 - 17 + Array.Copy(BitConverter.GetBytes(MH_Offset), 0, DataH0, 18, 2); // 18 - 19 + + Array.Copy(BitConverter.GetBytes(SD_Width), 0, DataH0, 20, 2); // 20 - 21 + Array.Copy(BitConverter.GetBytes(SD_Height), 0, DataH0, 22, 2); // 22 - 23 + Array.Copy(BitConverter.GetBytes(SD_AzUpr), 0, DataH0, 24, 4); // 24 - 27 + Array.Copy(BitConverter.GetBytes(SD_ElUpr), 0, DataH0, 28, 4); // 28 - 31 + + Array.Copy(BitConverter.GetBytes(SD_Shirota), 0, DataH0, 32, 4); // 32 - 35 + Array.Copy(BitConverter.GetBytes(SD_Dolgota), 0, DataH0, 36, 4); // 36 - 39 + Array.Copy(BitConverter.GetBytes(SD_Vysota), 0, DataH0, 40, 4); // 40 - 43 + + Array.Copy(BitConverter.GetBytes(SD_Course), 0, DataH0, 44, 2); // 44 - 45 + Array.Copy(BitConverter.GetBytes(SD_Roll), 0, DataH0, 46, 2); // 46 - 47 + Array.Copy(BitConverter.GetBytes(SD_Pitch), 0, DataH0, 48, 2); // 48 - 49 + Array.Copy(BitConverter.GetBytes(rez0), 0, DataH0, 50, 2); // 50 - 51 + + Array.Copy(BitConverter.GetBytes(rez1), 0, DataH0, 52, 2); // 52 - 53 + Array.Copy(BitConverter.GetBytes(rez2), 0, DataH0, 54, 2); // 54 - 55 + + Array.Copy(BitConverter.GetBytes(rez3), 0, DataH0, 56, 1); // 56 - 56 + Array.Copy(BitConverter.GetBytes(rez4), 0, DataH0, 57, 1); // 57 - 57 + Array.Copy(BitConverter.GetBytes(SD_Status), 0, DataH0, 58, 1); // 58 - 58 + Array.Copy(BitConverter.GetBytes(rez5), 0, DataH0, 59, 1); // 59 - 59 + } + public static void MakeDataH1() + { + Array.Copy(BitConverter.GetBytes(MH_VerPXCC), 0, DataH1, 0, 1); + Array.Copy(BitConverter.GetBytes(MH_MPT), 0, DataH1, 1, 1); + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Low), 0, DataH1, 2, 2); + Array.Copy(BitConverter.GetBytes(MH_Timestamp), 0, DataH1, 4, 4); + Array.Copy(BitConverter.GetBytes(MH_SSRC), 0, DataH1, 8, 4); + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Hi), 0, DataH1, 12, 2); + Array.Copy(BitConverter.GetBytes(MH_DataLen), 0, DataH1, 14, 2); + Array.Copy(BitConverter.GetBytes(MH_RowNumber), 0, DataH1, 16, 2); + Array.Copy(BitConverter.GetBytes(MH_Offset), 0, DataH1, 18, 2); + } + public static void GetDataH0() + { + MH_VerPXCC = DataH0[0]; + MH_MPT = DataH0[1]; + MH_SeqCounter_Low = BitConverter.ToUInt16(DataH0, 2); + MH_Timestamp = BitConverter.ToUInt32(DataH0, 4); + MH_SSRC = BitConverter.ToUInt32(DataH0, 8); + MH_SeqCounter_Hi = BitConverter.ToUInt16(DataH0, 12); + MH_DataLen = BitConverter.ToUInt16(DataH0, 14); + MH_RowNumber = BitConverter.ToUInt16(DataH0, 16); + MH_Offset = BitConverter.ToUInt16(DataH0, 18); + SD_Width = BitConverter.ToUInt16(DataH0, 20); + SD_Height = BitConverter.ToUInt16(DataH0, 22); + SD_AzUpr = BitConverter.ToSingle(DataH0, 24); + SD_ElUpr = BitConverter.ToSingle(DataH0, 28); + SD_Shirota = BitConverter.ToInt32(DataH0, 32); + SD_Dolgota = BitConverter.ToInt32(DataH0, 36); + SD_Vysota = BitConverter.ToInt32(DataH0, 40); + SD_Course = BitConverter.ToInt16(DataH0, 44); + SD_Roll = BitConverter.ToInt16(DataH0, 46); + SD_Pitch = BitConverter.ToInt16(DataH0, 48); + rez0 = BitConverter.ToUInt16(DataH0, 50); + rez1 = BitConverter.ToUInt16(DataH0, 52); + rez2 = BitConverter.ToUInt16(DataH0, 54); + rez3 = DataH0[56]; + rez4 = DataH0[57]; + SD_Status = DataH0[58]; + rez5 = DataH0[59]; + } + public static void GetDataH1() + { + MH_VerPXCC = DataH0[0]; + MH_MPT = DataH0[1]; + MH_SeqCounter_Low = BitConverter.ToUInt16(DataH0, 2); + MH_Timestamp = BitConverter.ToUInt32(DataH0, 4); + MH_SSRC = BitConverter.ToUInt32(DataH0, 8); + MH_SeqCounter_Hi = BitConverter.ToUInt16(DataH0, 12); + MH_DataLen = BitConverter.ToUInt16(DataH0, 14); + MH_RowNumber = BitConverter.ToUInt16(DataH0, 16); + MH_Offset = BitConverter.ToUInt16(DataH0, 18); + } + + private static T BuffToStruct(byte[] arr) + { + GCHandle handle = GCHandle.Alloc(arr, GCHandleType.Pinned); + T stuff = (T)Marshal.PtrToStructure( + handle.AddrOfPinnedObject(), typeof(T)); + handle.Free(); + return stuff; + } + private static byte[] StructToBuff(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; + } + } +} diff --git a/tcp.cs b/tcp.cs new file mode 100644 index 0000000..2faf836 --- /dev/null +++ b/tcp.cs @@ -0,0 +1,402 @@ +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; +//using System.Threading.Tasks; +//using System.Windows.Forms; +//using System.Xml.Linq; +//using UDPLIB; +using UTIL; +//using PIV; +//using UDPLIB.CallBack; +//using System.Windows.Forms.VisualStyles.VisualStyleElement.Button; +//using System.Reflection.Emit; +//using System.Drawing.Drawing2D; +//using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using System.Drawing; +//using System.Net.Sockets; +//using System.IO; +//using System.Net.Http; +//using Microsoft.Win32; + +namespace nTCP +{ + public class TCP + { + public const UInt16 TCP_CONTROL_SIGNATURE = 0x4D58; + + public const UInt16 OES_CNTRL_CMD_SET_VPFE_SENSOR_CFG = 0x0004; + public const UInt16 OES_CNTRL_CMD_SET_VPFE_CCM = 0x0005; + public const UInt16 OES_CNTRL_CMD_SET_VPFE_AE = 0x0006; // Set Auto Exposure + public const UInt16 OES_CNTRL_CMD_SET_VPFE_AWB = 0x0007; // Set Auto White Balance + public const UInt16 OES_CNTRL_CMD_SET_VPFE_GC = 0x0008; // Set Gamma correction + public const UInt16 OES_CNTRL_CMD_SET_VPFE_ABL = 0x0009; + public const UInt16 OES_CNTRL_CMD_SET_VIDEO_FORMAT = 0x0010; + + public const UInt16 OES_CNTRL_CMD_GET_VPFE_SENSOR_CFG = 0x0084; + public const UInt16 OES_CNTRL_CMD_GET_VPFE_CCM = 0x0085; + public const UInt16 OES_CNTRL_CMD_GET_VPFE_AE = 0x0086; // Get Auto Exposure + public const UInt16 OES_CNTRL_CMD_GET_VPFE_AWB = 0x0087; // Get Auto White Balance + public const UInt16 OES_CNTRL_CMD_GET_VPFE_GC = 0x0088; // Get Gamma correction + public const UInt16 OES_CNTRL_CMD_GET_VPFE_ABL = 0x0089; + + private Int32 _tcpControlHeader = 8; + private Int32 _tcpControlStatus = 12; + private Int32 _tcpControlVPFE_SensorCfg = 24; + private Int32 _tcpControlVPFE_CCM = 20; + + private Int32 _VPFE_roi = 8; + private Int32 _VPFE_sensorCfg = 16; + private Int32 _VPFE_CCM = 12; + //private tcpControlVPFE_SensorCfg_s pack_SensorCfg = new tcpControlVPFE_SensorCfg_s(); + //private tcpControlVPFE_CCM_s pack_VPFE_CCM = new tcpControlVPFE_CCM_s(); + //private tcpControlStatus_s pack_Status_s = new tcpControlStatus_s(); + + public TCP() + { + //pack_SensorCfg.hdr.signature = TCP_CONTROL_SIGNATURE; + } + public Byte[] class2buf(SensorCfg_t c) + { + Byte[] buf = new Byte[_tcpControlVPFE_SensorCfg]; + + c.length = 16; + Array.Copy(BitConverter.GetBytes(c.signature), 0, buf, 0, 2); // 0 - 0 + Array.Copy(BitConverter.GetBytes(c.cmd), 0, buf, 2, 2); // 2 - 2 + Array.Copy(BitConverter.GetBytes(c.length), 0, buf, 4, 4); // 4 - 4 + Array.Copy(BitConverter.GetBytes(c.expTimeUs), 0, buf, 8, 4); // 8 - 7 + Array.Copy(BitConverter.GetBytes(c.framePeriodUs), 0, buf, 12, 4); // 12 - 11 + Array.Copy(BitConverter.GetBytes(c.x), 0, buf, 16, 2); // 16 - 13 + Array.Copy(BitConverter.GetBytes(c.y), 0, buf, 18, 2); // 18 - 17 + Array.Copy(BitConverter.GetBytes(c.width), 0, buf, 20, 2); // 20 - 19 + Array.Copy(BitConverter.GetBytes(c.height), 0, buf, 22, 2); // 22 - 21 + + return buf; + } + public Byte[] class2buf(Status_t c) + { + Byte[] buf = new Byte[_tcpControlStatus]; + + c.length = 4; + Array.Copy(BitConverter.GetBytes(c.signature), 0, buf, 0, 2); // 0 - 0 + Array.Copy(BitConverter.GetBytes(c.cmd), 0, buf, 2, 2); // 2 - 2 + Array.Copy(BitConverter.GetBytes(c.length), 0, buf, 4, 4); // 4 - 4 + Array.Copy(BitConverter.GetBytes(c.cmd2), 0, buf, 8, 2); // 8 - 7 + Array.Copy(BitConverter.GetBytes(c.status), 0, buf, 10, 1); // 8 - 7 + Array.Copy(BitConverter.GetBytes(c.ext), 0, buf, 11, 1); // 8 - 7 + + return buf; + } + public Status_t buf2Status(Byte[] buf) + { + Status_t ret = new Status_t(); + + ret.signature = BitConverter.ToUInt16(buf, 0); + ret.cmd = BitConverter.ToUInt16(buf, 2); + ret.length = BitConverter.ToUInt32(buf, 4); + ret.cmd2 = BitConverter.ToUInt16(buf, 8); + ret.status = buf[10]; + ret.ext = buf[11]; + + return ret; + } + public SensorCfg_t buf2SensorCfg(Byte[] buf) + { + SensorCfg_t ret = new SensorCfg_t(); + + ret.signature = BitConverter.ToUInt16(buf, 0); + ret.cmd = BitConverter.ToUInt16(buf, 2); + ret.length = BitConverter.ToUInt32(buf, 4); + ret.expTimeUs = BitConverter.ToUInt32(buf, 8); + ret.framePeriodUs = BitConverter.ToUInt32(buf, 12); + ret.x = BitConverter.ToUInt16(buf, 16); + ret.y = BitConverter.ToUInt16(buf, 18); + ret.width = BitConverter.ToUInt16(buf, 20); + ret.height = BitConverter.ToUInt16(buf, 22); + + return ret; + } + public (Int32, Int32, Int32) ggg() + { + return (_tcpControlVPFE_SensorCfg, _tcpControlVPFE_CCM, _tcpControlStatus); + + } + + /* + //RTPMsgHeader + private const UInt32 _len_pack = 60; + private const UInt32 _len_head = 20; + private UInt32 _len_data = _len_pack - _len_head; + + private Byte _VerPXCC = 2; + private Byte _Ver = 2; // версия протокола (текущая версия 2) + private Byte _P = 0; // = 0 (не используется заполнение в конце пакета) + private Byte _X = 0; // = 0 (не используются дополнительные заголовки) + private Byte _CC = 0; // = 0 (CSRC - идентификаторы не используются); + private Byte _MPT; + private Byte _M; // маркерный бит. + private Byte _PT = 99; // поле идентифицирует формат трафика RTP и определяет его интерпретацию. Задается 99 + private UInt32 _Seqcounter = 0; + private UInt16 _SeqCounter_Hi; + private UInt16 _SeqCounter_Low; + private Byte _rejim_oes; + private Byte _zahvat; + private Byte _color; + private Byte _status; + + public 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 Byte MH_MPT + { + get + { + return (Byte)((_PT << 1) | _M); + } + set + { + _MPT = value; + _M = (Byte)(value & 0x01); + _PT = (Byte)((value >> 1) & 0x7F); + } + } + public Byte MH_M // маркерный бит. + { + get => _M; + set + { + _M = value; + } + } + public Byte MH_PT // поле идентифицирует формат трафика RTP и определяет его интерпретацию. Задается 99 + { + get => _PT; + set + { + _PT = value; + } + } + public UInt16 MH_SeqCounter_Low // Номер последовательности (младшие 16 бит) + { + get => _SeqCounter_Low; + set + { + _SeqCounter_Low = value; + } + } + public UInt32 MH_Timestamp; // Метка времени (90 кГц отсчеты), одинакова для всех пакетов кадра + public UInt32 MH_SSRC; // 12345678 (идентификатор источника информации) + public UInt16 MH_SeqCounter_Hi // Номер последовательности (старшие 16 бит) + { + get => _SeqCounter_Hi; + set + { + _SeqCounter_Hi = value; + } + } + // public UInt16 MH_DataLen = (UInt16)_len_data; // Количество байт данных строки, включенной в пакет + public UInt16 MH_RowNumber; // Номер строки + public UInt16 MH_Offset; // Смещение первого пиксела в строке (= 0) + + //RTPVideoSupplementalData + public UInt16 SD_Width; // Ширина (пиксели) + public UInt16 SD_Height; // Высота (пиксели) + public float SD_AzUpr; // (град) + public float SD_ElUpr; // (град) + + public Int32 SD_Shirota; // Широта БЛА (1е-7 град) + public Int32 SD_Dolgota; // Долгота БЛА (1е-7 град) + public Int32 SD_Vysota; // Высота БЛА (0,01 м) + + public Int16 SD_Course; // Курс БЛА (0,01 град) + public Int16 SD_Roll; // Крен БЛА (0,01 град) + public Int16 SD_Pitch; // Тангаж БЛА (0,01 град) + + public UInt16 rez0; // координата центра цели в растре изображения по горизонтали + public UInt16 rez1; //координата центра цели в растре изображения по вертикали + public UInt16 rez2; //координата центра цели в растре изображения по вертикали + + public Byte rez3; // размер цели в растре эталонного изображения по горизонтали + public Byte rez4; // размер цели в растре эталонного изображения по вертикали + + public Byte SD_rejim_oes // Режим ОЭС: «0» – Обзор, «1» – АС + { + get => _rejim_oes; + set => _rejim_oes = value; + } + public Byte SD_zahvat // Захват: «0» – отсутствие захвата, «1» – налачие захвата + { + get => _zahvat; + set => _zahvat = value; + } + public Byte SD_color // Цвет изображения: «1» – цветное, «0» – монохромное + { + get => _color; + set => _color = value; + } + public Byte SD_Status + { + get + { + _status = 0; + _status |= (Byte)(_rejim_oes << 0); + _status |= (Byte)(_zahvat << 1); + _status |= (Byte)(_color << 2); + return _status; + } + set + { + _status = value; + _rejim_oes = (Byte)((value >> 0) & 0x01); + _zahvat = (Byte)((value >> 1) & 0x01); + _color = (Byte)((value >> 2) & 0x01); + } + } + public Byte rez5; + + public UInt32 SeqCounter + { + get + { + return (UInt32)((_SeqCounter_Hi << 16) | _SeqCounter_Low); + } + set + { + _SeqCounter_Low = (UInt16)value; + _SeqCounter_Hi = (UInt16)((value >> 16) & 0xFFFF); + } + } + + public Byte[] DataH0 = new Byte[_len_pack]; + //public Byte[] DataH0 = new Byte[76]; + public Byte[] DataH1 = new Byte[_len_head]; + + public void MakeDataH0() + { + Array.Copy(BitConverter.GetBytes(MH_VerPXCC), 0, DataH0, 0, 1); // 0 - 0 + Array.Copy(BitConverter.GetBytes(MH_MPT), 0, DataH0, 1, 1); // 1 - 1 + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Low), 0, DataH0, 2, 2); // 2 - 3 + Array.Copy(BitConverter.GetBytes(MH_Timestamp), 0, DataH0, 4, 4); // 4 - 7 + Array.Copy(BitConverter.GetBytes(MH_SSRC), 0, DataH0, 8, 4); // 8 - 11 + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Hi), 0, DataH0, 12, 2); // 12 - 13 + // Array.Copy(BitConverter.GetBytes(MH_DataLen), 0, DataH0, 14, 2); // 14 - 15 + Array.Copy(BitConverter.GetBytes(MH_RowNumber), 0, DataH0, 16, 2); // 16 - 17 + Array.Copy(BitConverter.GetBytes(MH_Offset), 0, DataH0, 18, 2); // 18 - 19 + + Array.Copy(BitConverter.GetBytes(SD_Width), 0, DataH0, 20, 2); // 20 - 21 + Array.Copy(BitConverter.GetBytes(SD_Height), 0, DataH0, 22, 2); // 22 - 23 + Array.Copy(BitConverter.GetBytes(SD_AzUpr), 0, DataH0, 24, 4); // 24 - 27 + Array.Copy(BitConverter.GetBytes(SD_ElUpr), 0, DataH0, 28, 4); // 28 - 31 + + Array.Copy(BitConverter.GetBytes(SD_Shirota), 0, DataH0, 32, 4); // 32 - 35 + Array.Copy(BitConverter.GetBytes(SD_Dolgota), 0, DataH0, 36, 4); // 36 - 39 + Array.Copy(BitConverter.GetBytes(SD_Vysota), 0, DataH0, 40, 4); // 40 - 43 + + Array.Copy(BitConverter.GetBytes(SD_Course), 0, DataH0, 44, 2); // 44 - 45 + Array.Copy(BitConverter.GetBytes(SD_Roll), 0, DataH0, 46, 2); // 46 - 47 + Array.Copy(BitConverter.GetBytes(SD_Pitch), 0, DataH0, 48, 2); // 48 - 49 + Array.Copy(BitConverter.GetBytes(rez0), 0, DataH0, 50, 2); // 50 - 51 + + Array.Copy(BitConverter.GetBytes(rez1), 0, DataH0, 52, 2); // 52 - 53 + Array.Copy(BitConverter.GetBytes(rez2), 0, DataH0, 54, 2); // 54 - 55 + + Array.Copy(BitConverter.GetBytes(rez3), 0, DataH0, 56, 1); // 56 - 56 + Array.Copy(BitConverter.GetBytes(rez4), 0, DataH0, 57, 1); // 57 - 57 + Array.Copy(BitConverter.GetBytes(SD_Status), 0, DataH0, 58, 1); // 58 - 58 + Array.Copy(BitConverter.GetBytes(rez5), 0, DataH0, 59, 1); // 59 - 59 + } + public void MakeDataH1() + { + Array.Copy(BitConverter.GetBytes(MH_VerPXCC), 0, DataH1, 0, 1); + Array.Copy(BitConverter.GetBytes(MH_MPT), 0, DataH1, 1, 1); + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Low), 0, DataH1, 2, 2); + Array.Copy(BitConverter.GetBytes(MH_Timestamp), 0, DataH1, 4, 4); + Array.Copy(BitConverter.GetBytes(MH_SSRC), 0, DataH1, 8, 4); + Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Hi), 0, DataH1, 12, 2); + // Array.Copy(BitConverter.GetBytes(MH_DataLen), 0, DataH1, 14, 2); + Array.Copy(BitConverter.GetBytes(MH_RowNumber), 0, DataH1, 16, 2); + Array.Copy(BitConverter.GetBytes(MH_Offset), 0, DataH1, 18, 2); + } + public void GetDataH0() + { + MH_VerPXCC = DataH0[0]; + MH_MPT = DataH0[1]; + MH_SeqCounter_Low = BitConverter.ToUInt16(DataH0, 2); + MH_Timestamp = BitConverter.ToUInt32(DataH0, 4); + MH_SSRC = BitConverter.ToUInt32(DataH0, 8); + MH_SeqCounter_Hi = BitConverter.ToUInt16(DataH0, 12); + // MH_DataLen = BitConverter.ToUInt16(DataH0, 14); + MH_RowNumber = BitConverter.ToUInt16(DataH0, 16); + MH_Offset = BitConverter.ToUInt16(DataH0, 18); + SD_Width = BitConverter.ToUInt16(DataH0, 20); + SD_Height = BitConverter.ToUInt16(DataH0, 22); + SD_AzUpr = BitConverter.ToSingle(DataH0, 24); + SD_ElUpr = BitConverter.ToSingle(DataH0, 28); + SD_Shirota = BitConverter.ToInt32(DataH0, 32); + SD_Dolgota = BitConverter.ToInt32(DataH0, 36); + SD_Vysota = BitConverter.ToInt32(DataH0, 40); + SD_Course = BitConverter.ToInt16(DataH0, 44); + SD_Roll = BitConverter.ToInt16(DataH0, 46); + SD_Pitch = BitConverter.ToInt16(DataH0, 48); + rez0 = BitConverter.ToUInt16(DataH0, 50); + rez1 = BitConverter.ToUInt16(DataH0, 52); + rez2 = BitConverter.ToUInt16(DataH0, 54); + rez3 = DataH0[56]; + rez4 = DataH0[57]; + SD_Status = DataH0[58]; + rez5 = DataH0[59]; + } + public void GetDataH1() + { + MH_VerPXCC = DataH0[0]; + MH_MPT = DataH0[1]; + MH_SeqCounter_Low = BitConverter.ToUInt16(DataH0, 2); + MH_Timestamp = BitConverter.ToUInt32(DataH0, 4); + MH_SSRC = BitConverter.ToUInt32(DataH0, 8); + MH_SeqCounter_Hi = BitConverter.ToUInt16(DataH0, 12); + // MH_DataLen = BitConverter.ToUInt16(DataH0, 14); + MH_RowNumber = BitConverter.ToUInt16(DataH0, 16); + MH_Offset = BitConverter.ToUInt16(DataH0, 18); + } + */ + public delegate void Event_newmsg(); + public Event_newmsg Event_newmsg_Handler; + + } + public class Status_t + { + public UInt16 signature = TCP.TCP_CONTROL_SIGNATURE; + public UInt16 cmd = 0; + public UInt32 length = 0; + public UInt16 cmd2 = 0; + public Byte status = 0; + public Byte ext = 0; + } + public class SensorCfg_t + { + public UInt16 signature = TCP.TCP_CONTROL_SIGNATURE; + public UInt16 cmd = 0; + public UInt32 length = 0; + public UInt32 expTimeUs = 0; + public UInt32 framePeriodUs = 0; + public UInt16 x = 0; + public UInt16 y = 0; + public UInt16 width = 0; + public UInt16 height = 0; + } +} diff --git a/udplib.cs b/udplib.cs index d22a306..814bffd 100644 --- a/udplib.cs +++ b/udplib.cs @@ -17,7 +17,7 @@ namespace UDPLIB { public class Data { - public static string Ver = "1.1.2.264"; + public static string Ver = "1.1.2.269"; protected static string IPAddr = "192.168.1.2"; protected static Int32 LocalPort = 5004; protected static Int32 RemotePort = 5006; @@ -31,12 +31,8 @@ namespace UDPLIB public class UDPreceive : Data { - //Int32 localPort = 5004; - //Int32 remotePort = 5006; Thread UDPreceiveThread = null; - // Thread processFrameThread = null; Thread sendFrameThread = null; - // Thread processDataFrameThread = null; Stopwatch fpstimer; private volatile bool listening = false; UInt16 iwidth = 0; @@ -79,6 +75,7 @@ namespace UDPLIB public void Stop() { listening = false; + UDPreceiveThread.Abort(); cnt_frames = 0; } public Boolean IsAlive @@ -146,22 +143,12 @@ namespace UDPLIB } if (numrow == 0 && ssrc == 12345678) // Packet 0 { - //iwidth = BitConverter.ToUInt16(data, 20); - //iheight = BitConverter.ToUInt16(data, 22); blackline = new Byte[iwidth * 3 + 20]; RTP.DataH0 = data; RTP.GetDataH0(); - //Res.Iwidth = iwidth; - //Res.Iheight = iheight; - //Res.AzUpr = BitConverter.ToSingle(data, 24); - //Res.ElUpr = BitConverter.ToSingle(data, 28); - //Res.Course = BitConverter.ToInt16(data, 32); - //Res.Roll = BitConverter.ToInt16(data, 34); - //Res.Pitch = BitConverter.ToInt16(data, 36); - iwidth = RTP.SD_Width; iheight = RTP.SD_Height; @@ -222,16 +209,25 @@ namespace UDPLIB } catch (Exception ee) { +#if DEBUG using (StreamWriter sw = new StreamWriter(System.IO.File.OpenWrite("udplib.log"))) { sw.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff ")} Error dll recv\r\n{ee.Message}"); } +#endif } } receiver.Close(); + Res.Fps = 0; + rrr2.Fps = 0; + Res.Lost = 0; + rrr2.Lost = 0; + CallBack.Event_newimg_Handler2(rrr2); } void processFrame7(object obj) { + Int32 lost = 0; + UInt32 lostfix = 0; try { thrdata arr = obj as thrdata; @@ -249,8 +245,27 @@ namespace UDPLIB udata.AddRange(udata51); break; } + //udata50.Clear(); + //udata51.Clear(); iwi = BitConverter.ToUInt16(udata[0], 20); ihe = BitConverter.ToUInt16(udata[0], 22); + // проверка потерянных строк + lost = 0; + lostfix = 0; + UInt32 ts = BitConverter.ToUInt32(udata[0], 4); + for (int i = 0; i < ihe; i++) + { + //Console.WriteLine($"{i}\t{udata[i].Length}"); + if (BitConverter.ToUInt32(udata[i], 4) != ts) + lost++; + if (udata[i].Length == 0) + lostfix++; + } + Res.Lost = (float)lost / (float)ihe; + rrr2.Lost = (float)lost / (float)ihe; + Res.LostFix = lostfix; + rrr2.LostFix = lostfix; + //Console.WriteLine($"-Lost: {(float)lost / (float)ihe * 100:F4}% {lost} {ihe} {udata.Count}"); Bitmap img = new Bitmap(iwi, ihe, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Rectangle rect = new Rectangle(0, 0, iwi, ihe); @@ -310,10 +325,12 @@ namespace UDPLIB } catch (Exception) { +#if DEBUG using (StreamWriter sw = new StreamWriter(System.IO.File.OpenWrite("udplib.log"))) { sw.WriteLine(DateTime.Now.ToString("HH:mm:ss:fff ") + "Error lib process"); } +#endif } } #endregion @@ -328,19 +345,6 @@ namespace UDPLIB UInt16 pntlx = 0; UInt16 pntly = 0; - //public UDPTransmit(String IPaddr, Int32 remotePortUDP, Point p) - //{ - // transmitter = new UdpClient(); - // endPoint = new IPEndPoint(IPAddress.Parse(IPaddr), remotePortUDP); - // pnt = p; - // pnt.X = Util.minmax((ushort)64, (ushort)576, (ushort)pnt.X); - // pnt.Y = Util.minmax((ushort)64, (ushort)416, (ushort)pnt.Y); - - // Bitmap crop = Res.Clearimg.Clone(new Rectangle(pnt.X - 64, pnt.Y - 64, 128, 128), PixelFormat.Format24bppRgb); - // Res.Crop = crop; - // Thread UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame)); - // UDPtransmitThread.Start(); - //} public UDPTransmit(String IPaddr, Int32 remotePortUDP, (UInt16, UInt16, UInt16, UInt16) p) { transmitter = new UdpClient(); @@ -670,6 +674,8 @@ namespace UDPLIB public static UInt16 Iheight { set; get; } public static UInt32 Frames { set; get; } public static float Fps { set; get; } + public static float Lost { set; get; } + public static UInt32 LostFix { set; get; } public static float AzUpr { set; get; } public static float ElUpr { set; get; } public static Int16 Course { set; get; } @@ -718,6 +724,8 @@ namespace UDPLIB public UInt16 Iwidth; public UInt16 Iheight; public UInt32 Frames; + public float Lost; + public UInt32 LostFix; public float Fps; public float AzUpr; public float ElUpr; diff --git a/util.cs b/util.cs index a99f52b..aa81055 100644 --- a/util.cs +++ b/util.cs @@ -251,13 +251,21 @@ namespace UTIL public static class S2B { #region Загрузка/выгрузка данных в структуру + //public static T BuffToStruct(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 BuffToStruct(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); + GCHandle handle = GCHandle.Alloc(arr, GCHandleType.Pinned); + T stuff = (T)Marshal.PtrToStructure( + handle.AddrOfPinnedObject(), typeof(T)); + handle.Free(); + return stuff; } public static T BuffToClass(byte[] arr) { @@ -576,15 +584,20 @@ namespace UTIL public static String printtime(Boolean ms) { if (ms == true) - return DateTime.Now.ToString("HH:mm:ss:fff"); + return DateTime.Now.ToString("HH:mm:ss:fff "); else - return DateTime.Now.ToString("HH:mm:ss"); + return DateTime.Now.ToString("HH:mm:ss "); + } + public static String printdatetime(Boolean ms) + { + if (ms == true) + return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff "); + else + return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss "); } private const int EM_SETTABSTOPS = 0x00CB; - [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam); - public static void SetTabWidth(TextBox textbox, int tabWidth) { Graphics graphics = textbox.CreateGraphics();