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.
 
 

402 lines
20 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 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;
}
}