You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
370 lines
17 KiB
370 lines
17 KiB
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<T>(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>(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; |
|
} |
|
} |
|
}
|
|
|