Browse Source

переделан rtp.cs под новый ПИВ 1.23

в util.cs добавлен класс SetNet
20230911
Денис Кузнецов 3 years ago
parent
commit
98b3fb8ad7
  1. 8
      piv.cs
  2. 226
      rtp.cs
  3. 118
      util.cs

8
piv.cs

@ -2423,7 +2423,8 @@ namespace PIV
/// </summary> /// </summary>
public static class sTOBON0322 public static class sTOBON0322
{ {
private const UInt16 _len_pack = 49; private const UInt16 _len_pack = 53;
// private const UInt16 _len_pack = 49;
private static UInt16 _infoword = 0; private static UInt16 _infoword = 0;
private static UInt16 _i_vstr_kontr = 0; private static UInt16 _i_vstr_kontr = 0;
@ -2471,6 +2472,8 @@ namespace PIV
private static UInt16 _ko_prev_dop_gyro; private static UInt16 _ko_prev_dop_gyro;
private static UInt16 _ko_prev_dop_axel; private static UInt16 _ko_prev_dop_axel;
private static Int32 _vremya_ustar;
public static Byte Start = CONST.STARTTOBON0322; public static Byte Start = CONST.STARTTOBON0322;
/// <summary> /// <summary>
/// Слово информационное /// Слово информационное
@ -2600,6 +2603,7 @@ namespace PIV
/// <summary> /// <summary>
/// Время устаревания информации от комплекса /// Время устаревания информации от комплекса
/// </summary> /// </summary>
public static Int32 Vremya_ustar { get => _vremya_ustar; set => _vremya_ustar = value; }
public static Byte[] Data = new Byte[_len_pack]; public static Byte[] Data = new Byte[_len_pack];
/// <summary> /// <summary>
@ -2629,8 +2633,8 @@ namespace PIV
Array.Copy(BitConverter.GetBytes(UskX), 0, Data, 41, 2); Array.Copy(BitConverter.GetBytes(UskX), 0, Data, 41, 2);
Array.Copy(BitConverter.GetBytes(UskY), 0, Data, 43, 2); Array.Copy(BitConverter.GetBytes(UskY), 0, Data, 43, 2);
Array.Copy(BitConverter.GetBytes(UskZ), 0, Data, 45, 2); Array.Copy(BitConverter.GetBytes(UskZ), 0, Data, 45, 2);
Array.Copy(BitConverter.GetBytes(Kod_Oshibki), 0, Data, 47, 2); Array.Copy(BitConverter.GetBytes(Kod_Oshibki), 0, Data, 47, 2);
Array.Copy(BitConverter.GetBytes(Vremya_ustar), 0, Data, 49, 4);
} }
/// <summary> /// <summary>
/// Функция извлечения данных из массива /// Функция извлечения данных из массива

226
rtp.cs

@ -22,6 +22,11 @@ namespace nRTP
private static UInt32 _Seqcounter = 0; private static UInt32 _Seqcounter = 0;
private static UInt16 _SeqCounter_Hi; private static UInt16 _SeqCounter_Hi;
private static UInt16 _SeqCounter_Low; 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 public static Byte MH_VerPXCC
{ {
get => _VerPXCC; get => _VerPXCC;
@ -100,6 +105,46 @@ namespace nRTP
public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град) public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град)
public static Int16 SD_FrameId; public static Int16 SD_FrameId;
public static UInt16 SD_X; // координата центра цели в растре изображения по горизонтали
public static UInt16 SD_Y; //координата центра цели в растре изображения по вертикали
public static Byte SD_lx; // размер цели в растре эталонного изображения по горизонтали
public static Byte SD_ly; // размер цели в растре эталонного изображения по вертикали
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 |= (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 SD_rezerv;
//RTPVideoSupplementalDataExtra //RTPVideoSupplementalDataExtra
public static UInt32 DE_TLV_X; // Линия визирования цели в растроввых координатах public static UInt32 DE_TLV_X; // Линия визирования цели в растроввых координатах
public static UInt32 DE_TLV_Y; // public static UInt32 DE_TLV_Y; //
@ -119,101 +164,104 @@ namespace nRTP
} }
} }
public static Byte[] DataH0 = new Byte[68]; public static Byte[] DataH0 = new Byte[76];
public static Byte[] DataH1 = new Byte[20]; public static Byte[] DataH1 = new Byte[20];
public static void MakeDataH0() public static void MakeDataH0()
{ {
Array.Copy(BitConverter.GetBytes(RTP.MH_VerPXCC), 0, DataH0, 0, 1); Array.Copy(BitConverter.GetBytes(MH_VerPXCC), 0, DataH0, 0, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_MPT), 0, DataH0, 1, 1); Array.Copy(BitConverter.GetBytes(MH_MPT), 0, DataH0, 1, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Low), 0, DataH0, 2, 2); Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Low), 0, DataH0, 2, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Timestamp), 0, DataH0, 4, 4); Array.Copy(BitConverter.GetBytes(MH_Timestamp), 0, DataH0, 4, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SSRC), 0, DataH0, 8, 4); Array.Copy(BitConverter.GetBytes(MH_SSRC), 0, DataH0, 8, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Hi), 0, DataH0, 12, 2); Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Hi), 0, DataH0, 12, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_DataLen), 0, DataH0, 14, 2); Array.Copy(BitConverter.GetBytes(MH_DataLen), 0, DataH0, 14, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_RowNumber), 0, DataH0, 16, 2); Array.Copy(BitConverter.GetBytes(MH_RowNumber), 0, DataH0, 16, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Offset), 0, DataH0, 18, 2); Array.Copy(BitConverter.GetBytes(MH_Offset), 0, DataH0, 18, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Width), 0, DataH0, 20, 2); Array.Copy(BitConverter.GetBytes(SD_Width), 0, DataH0, 20, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Height), 0, DataH0, 22, 2); Array.Copy(BitConverter.GetBytes(SD_Height), 0, DataH0, 22, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_AzUpr), 0, DataH0, 24, 4); Array.Copy(BitConverter.GetBytes(SD_AzUpr), 0, DataH0, 24, 4);
Array.Copy(BitConverter.GetBytes(RTP.SD_ElUpr), 0, DataH0, 28, 4); Array.Copy(BitConverter.GetBytes(SD_ElUpr), 0, DataH0, 28, 4);
Array.Copy(BitConverter.GetBytes(RTP.SD_Shirota), 0, DataH0, 32, 4); Array.Copy(BitConverter.GetBytes(SD_Shirota), 0, DataH0, 32, 4);
Array.Copy(BitConverter.GetBytes(RTP.SD_Dolgota), 0, DataH0, 36, 4); Array.Copy(BitConverter.GetBytes(SD_Dolgota), 0, DataH0, 36, 4);
Array.Copy(BitConverter.GetBytes(RTP.SD_Vysota), 0, DataH0, 40, 4); Array.Copy(BitConverter.GetBytes(SD_Vysota), 0, DataH0, 40, 4);
Array.Copy(BitConverter.GetBytes(RTP.SD_Course), 0, DataH0, 44, 2); Array.Copy(BitConverter.GetBytes(SD_Course), 0, DataH0, 44, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Roll), 0, DataH0, 46, 2); Array.Copy(BitConverter.GetBytes(SD_Roll), 0, DataH0, 46, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_Pitch), 0, DataH0, 48, 2); Array.Copy(BitConverter.GetBytes(SD_Pitch), 0, DataH0, 48, 2);
Array.Copy(BitConverter.GetBytes(SD_FrameId), 0, DataH0, 50, 2);
Array.Copy(BitConverter.GetBytes(RTP.SD_FrameId), 0, DataH0, 50, 2);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_X), 0, DataH0, 52, 4); Array.Copy(BitConverter.GetBytes(SD_X), 0, DataH0, 52, 2);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_Y), 0, DataH0, 56, 4); Array.Copy(BitConverter.GetBytes(SD_Y), 0, DataH0, 54, 2);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_dX), 0, DataH0, 60, 4);
Array.Copy(BitConverter.GetBytes(RTP.DE_TLV_dY), 0, DataH0, 64, 4); Array.Copy(BitConverter.GetBytes(SD_lx), 0, DataH0, 56, 1);
Array.Copy(BitConverter.GetBytes(SD_ly), 0, DataH0, 57, 1);
Array.Copy(BitConverter.GetBytes(SD_Status), 0, DataH0, 58, 1);
Array.Copy(BitConverter.GetBytes(SD_rezerv), 0, DataH0, 59, 1);
Array.Copy(BitConverter.GetBytes(DE_TLV_X), 0, DataH0, 60, 4);
Array.Copy(BitConverter.GetBytes(DE_TLV_Y), 0, DataH0, 64, 4);
Array.Copy(BitConverter.GetBytes(DE_TLV_dX), 0, DataH0, 68, 4);
Array.Copy(BitConverter.GetBytes(DE_TLV_dY), 0, DataH0, 72, 4);
} }
public static void MakeDataH1() public static void MakeDataH1()
{ {
Array.Copy(BitConverter.GetBytes(RTP.MH_VerPXCC), 0, DataH1, 0, 1); Array.Copy(BitConverter.GetBytes(MH_VerPXCC), 0, DataH1, 0, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_MPT), 0, DataH1, 1, 1); Array.Copy(BitConverter.GetBytes(MH_MPT), 0, DataH1, 1, 1);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Low), 0, DataH1, 2, 2); Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Low), 0, DataH1, 2, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Timestamp), 0, DataH1, 4, 4); Array.Copy(BitConverter.GetBytes(MH_Timestamp), 0, DataH1, 4, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SSRC), 0, DataH1, 8, 4); Array.Copy(BitConverter.GetBytes(MH_SSRC), 0, DataH1, 8, 4);
Array.Copy(BitConverter.GetBytes(RTP.MH_SeqCounter_Hi), 0, DataH1, 12, 2); Array.Copy(BitConverter.GetBytes(MH_SeqCounter_Hi), 0, DataH1, 12, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_DataLen), 0, DataH1, 14, 2); Array.Copy(BitConverter.GetBytes(MH_DataLen), 0, DataH1, 14, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_RowNumber), 0, DataH1, 16, 2); Array.Copy(BitConverter.GetBytes(MH_RowNumber), 0, DataH1, 16, 2);
Array.Copy(BitConverter.GetBytes(RTP.MH_Offset), 0, DataH1, 18, 2); Array.Copy(BitConverter.GetBytes(MH_Offset), 0, DataH1, 18, 2);
} }
public static void GetDataH0()
/* {
struct RTPMsgHeader MH_VerPXCC = DataH0[0];
{ MH_MPT = DataH0[1];
uint8_t Ver : 2; // версия протокола (текущая версия 2) MH_SeqCounter_Low = BitConverter.ToUInt16(DataH0, 2);
uint8_t P : 1; // = 0 (не используется заполнение в конце пакета) MH_Timestamp = BitConverter.ToUInt32(DataH0, 4);
uint8_t X : 1; // = 0 (не используются дополнительные заголовки) MH_SSRC = BitConverter.ToUInt32(DataH0, 8);
uint8_t CC : 4; // = 0 (CSRC - идентификаторы не используются); MH_SeqCounter_Hi = BitConverter.ToUInt16(DataH0, 12);
MH_DataLen = BitConverter.ToUInt16(DataH0, 14);
uint8_t M : 1; // маркерный бит. Установка этого бита в 1 свидетельствует о том, что данный UDP – пакет содержит последнюю строку кадра, для всех остальных пакетов задается 0 MH_RowNumber = BitConverter.ToUInt16(DataH0, 16);
uint8_t PT : 7; // поле идентифицирует формат трафика RTP и определяет его интерпретацию. Задается 99 MH_Offset = BitConverter.ToUInt16(DataH0, 18);
SD_Width = BitConverter.ToUInt16(DataH0, 20);
uint16_t SeqCounter_Low; // Номер последовательности (младшие 16 бит) SD_Height = BitConverter.ToUInt16(DataH0, 22);
uint32_t Timestamp; // Метка времени (90 кГц отсчеты), одинакова для всех пакетов кадра SD_AzUpr = BitConverter.ToUInt16(DataH0, 24);
uint32_t SSRC; // 12345678 (идентификатор источника информации) SD_ElUpr = BitConverter.ToUInt16(DataH0, 28);
uint16_t SeqCounter_Hi; // Номер последовательности (старшие 16 бит) SD_Shirota = BitConverter.ToUInt16(DataH0, 32);
uint16_t DataLen; // Количество байт данных строки, включенной в пакет SD_Dolgota = BitConverter.ToUInt16(DataH0, 36);
uint16_t RowNumber; // Номер строки SD_Vysota = BitConverter.ToUInt16(DataH0, 40);
uint16_t Offset; // Смещение первого пиксела в строке (= 0) SD_Course = BitConverter.ToInt16(DataH0, 44);
SD_Roll = BitConverter.ToInt16(DataH0, 46);
uint32_t get_seqcounter() { return ((SeqCounter_Hi << 16) | SeqCounter_Low); } SD_Pitch = BitConverter.ToInt16(DataH0, 48);
}; SD_FrameId = BitConverter.ToInt16(DataH0, 50);
//------------------------------------------------------------------------------------------------------------ SD_X = BitConverter.ToUInt16(DataH0, 52);
struct RTPVideoSupplementalData SD_Y = BitConverter.ToUInt16(DataH0, 54);
{ SD_lx = DataH0[56];
uint16_t Width; // Ширина (пиксели) SD_ly = DataH0[57];
uint16_t Height; // Высота (пиксели) SD_Status = DataH0[58];
SD_rezerv = DataH0[59];
float AzUpr; // (град) DE_TLV_X = BitConverter.ToUInt32(DataH0, 60);
float ElUpr; // (град) DE_TLV_Y = BitConverter.ToUInt32(DataH0, 64);
int16_t Course; // Курс БЛА (0,01 град) DE_TLV_dX = BitConverter.ToUInt32(DataH0, 68);
int16_t Roll; // Крен БЛА (0,01 град) DE_TLV_dY = BitConverter.ToUInt32(DataH0, 72);
int16_t Pitch; // Тангаж БЛА (0,01 град) }
int16_t FrameId; public static void GetDataH1()
{
RTPVideoSupplementalData() MH_VerPXCC = DataH0[0];
{ MH_MPT = DataH0[1];
::memset(this, 0, sizeof(RTPVideoSupplementalData)); 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);
struct RTPVideoSupplementalDataExtra MH_RowNumber = BitConverter.ToUInt16(DataH0, 16);
{ MH_Offset = BitConverter.ToUInt16(DataH0, 18);
uint32_t TLV_X; // Линия визирования цели в растроввых координатах }
uint32_t TLV_Y; //
uint32_t TLV_dX; // поправки для линии визирования цели в растроввых координатах
uint32_t TLV_dY; //
};
*/
} }
} }

118
util.cs

@ -11,6 +11,9 @@ using System.ComponentModel;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Globalization; using System.Globalization;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Net;
namespace UTIL namespace UTIL
{ {
@ -644,4 +647,119 @@ namespace UTIL
} }
} }
} }
public class SetNet
{
public void setIP(string caption, string ipaddress, Boolean dhcp)
{
// SetIP(EthStatic, "/c netsh interface ip set address \"" + EthName + "\" static " + Properties.Settings.Default.EthIPac + " " + Properties.Settings.Default.Subnet + " " + Properties.Settings.Default.EthDnsac + " & netsh interface ip set dns \"" + EthName + "\" static " + Properties.Settings.Default.EthDnsac);
String arg = "";
if (!dhcp)
{
arg = $"/c netsh interface ipv4 set address \"{caption}\" static \"{ipaddress}\" \"255.0.0.0\"";
// arg = $"/c netsh interface ipv4 set address \"{caption}\" static \"{ipaddress}\" \"255.0.0.0\" \"192.168.1.2\" & netsh interface ipv4 set dns \"{caption}\" static \"192.168.1.2\"";
// arg = $"/c netsh interface ip set address \"{caption}\" static \"{ipaddress}\" \"255.0.0.0\" \"192.168.1.2\" & netsh interface ip set dns \"{caption}\" static \"192.168.1.2\"";
}
else
{
arg = $"/c netsh interface ipv4 set address \"{caption}\" dhcp & netsh interface ipv4 set dns \"{caption}\" dhcp";
// arg = $"/c netsh interface ip set address \"{caption}\" dhcp & netsh interface ip set dns \"{caption}\" dhcp";
}
try
{
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe");
psi.UseShellExecute = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.Verb = "runas";
psi.Arguments = arg;
Process ps = Process.Start(psi);
ps.WaitForExit();
if (ps.HasExited)
{
MessageBox.Show("Адрес изменен", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public List<String[]> getadapters()
{
List<String[]> adapters = new List<string[]>();
String ip = "";
String dns = "";
String nic = "";
String gw = "";
String dhcp = "";
String ipen = "";
String sub = "";
string[] NwDesc = { "TAP", "VMware", "Windows", "Virtual", "WAN", "Microsoft", "NDIS", "Bluetooth" }; // Adapter types (Description) to be ommited
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet && !NwDesc.Any(ni.Description.Contains)) // check for adapter type and its description
{
nic = ni.Name;
Console.WriteLine($"Name: {nic} # Desc: {ni.Description} # Mac: {ni.GetPhysicalAddress().ToString()} # Status: {ni.OperationalStatus}");
if (ni.GetIPProperties().UnicastAddresses.Count == 0)
ip = "";
else
{
foreach (UnicastIPAddressInformation ips in ni.GetIPProperties().UnicastAddresses)
{
if (ips.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
ip = ips.Address.ToString();
}
}
}
if (ni.GetIPProperties().DnsAddresses.Count == 0)
dns = "";
else
{
foreach (IPAddress dnsAdress in ni.GetIPProperties().DnsAddresses)
{
if (dnsAdress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
dns = dnsAdress.ToString();
}
}
}
if (ni.GetIPProperties().GatewayAddresses.Count == 0)
gw = "";
else
{
foreach (GatewayIPAddressInformation gwAdress in ni.GetIPProperties().GatewayAddresses)
{
gw = gwAdress.Address.ToString();
}
}
if (ni.GetIPProperties().DhcpServerAddresses.Count == 0)
dhcp = "";
else
{
foreach (IPAddress dhcpAdress in ni.GetIPProperties().DhcpServerAddresses)
{
dhcp = dhcpAdress.ToString();
}
}
sub = "255.255.255.0";
if (ni.OperationalStatus.ToString() == "Down")
ipen = "False";
else
ipen = "True";
// Caption IPAddress IPSubnet DHCPEnabled IPEnabled
Console.WriteLine($"{nic}-{ip}-{sub}-{dhcp}-{ipen}");
adapters.Add(new String[] { ni.Description, ip, sub, (dhcp == "" ? "False" : "True"), ipen, nic });
}
}
return adapters;
}
}
} }

Loading…
Cancel
Save