Browse Source

udplib 1.1.2.264

Исправлен класс UDPTransmitSim
20230911
Денис Кузнецов 3 years ago
parent
commit
a812b8b5af
  1. 82
      rtp.cs
  2. 240
      udplib.cs

82
rtp.cs

@ -105,13 +105,13 @@ namespace nRTP
public static Int16 SD_Course; // Курс БЛА (0,01 град) public static Int16 SD_Course; // Курс БЛА (0,01 град)
public static Int16 SD_Roll; // Крен БЛА (0,01 град) public static Int16 SD_Roll; // Крен БЛА (0,01 град)
public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град) public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град)
public static Int16 SD_FrameId;
public static UInt16 rez0; // координата центра цели в растре изображения по горизонтали public static UInt16 rez0; // координата центра цели в растре изображения по горизонтали
public static UInt16 rez1; //координата центра цели в растре изображения по вертикали public static UInt16 rez1; //координата центра цели в растре изображения по вертикали
public static UInt16 rez2; //координата центра цели в растре изображения по вертикали
public static Byte rez2; // размер цели в растре эталонного изображения по горизонтали public static Byte rez3; // размер цели в растре эталонного изображения по горизонтали
public static Byte rez3; // размер цели в растре эталонного изображения по вертикали public static Byte rez4; // размер цели в растре эталонного изображения по вертикали
public static Byte SD_rejim_oes // Режим ОЭС: «0» – Обзор, «1» – АС public static Byte SD_rejim_oes // Режим ОЭС: «0» – Обзор, «1» – АС
{ {
@ -145,13 +145,7 @@ namespace nRTP
_color = (Byte)((value >> 2) & 0x01); _color = (Byte)((value >> 2) & 0x01);
} }
} }
public static Byte SD_rezerv; public static Byte rez5;
//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 public static UInt32 SeqCounter
{ {
@ -194,20 +188,15 @@ namespace nRTP
Array.Copy(BitConverter.GetBytes(SD_Course), 0, DataH0, 44, 2); // 44 - 45 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_Roll), 0, DataH0, 46, 2); // 46 - 47
Array.Copy(BitConverter.GetBytes(SD_Pitch), 0, DataH0, 48, 2); // 48 - 49 Array.Copy(BitConverter.GetBytes(SD_Pitch), 0, DataH0, 48, 2); // 48 - 49
Array.Copy(BitConverter.GetBytes(SD_FrameId), 0, DataH0, 50, 2); // 50 - 51 Array.Copy(BitConverter.GetBytes(rez0), 0, DataH0, 50, 2); // 50 - 51
Array.Copy(BitConverter.GetBytes(rez0), 0, DataH0, 52, 2); // 52 - 53 Array.Copy(BitConverter.GetBytes(rez1), 0, DataH0, 52, 2); // 52 - 53
Array.Copy(BitConverter.GetBytes(rez1), 0, DataH0, 54, 2); // 54 - 55 Array.Copy(BitConverter.GetBytes(rez2), 0, DataH0, 54, 2); // 54 - 55
Array.Copy(BitConverter.GetBytes(rez2), 0, DataH0, 56, 1); // 56 - 56 Array.Copy(BitConverter.GetBytes(rez3), 0, DataH0, 56, 1); // 56 - 56
Array.Copy(BitConverter.GetBytes(rez3), 0, DataH0, 57, 1); // 57 - 57 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(SD_Status), 0, DataH0, 58, 1); // 58 - 58
Array.Copy(BitConverter.GetBytes(SD_rezerv), 0, DataH0, 59, 1); // 59 - 59 Array.Copy(BitConverter.GetBytes(rez5), 0, DataH0, 59, 1); // 59 - 59
//Array.Copy(BitConverter.GetBytes(DE_TLV_X), 0, DataH0, 60, 4); // 60 - 63
//Array.Copy(BitConverter.GetBytes(DE_TLV_Y), 0, DataH0, 64, 4); // 64 - 67
//Array.Copy(BitConverter.GetBytes(DE_TLV_dX), 0, DataH0, 68, 4); // 68 - 71
//Array.Copy(BitConverter.GetBytes(DE_TLV_dY), 0, DataH0, 72, 4); // 72 - 75
} }
public static void MakeDataH1() public static void MakeDataH1()
{ {
@ -234,25 +223,21 @@ namespace nRTP
MH_Offset = BitConverter.ToUInt16(DataH0, 18); MH_Offset = BitConverter.ToUInt16(DataH0, 18);
SD_Width = BitConverter.ToUInt16(DataH0, 20); SD_Width = BitConverter.ToUInt16(DataH0, 20);
SD_Height = BitConverter.ToUInt16(DataH0, 22); SD_Height = BitConverter.ToUInt16(DataH0, 22);
SD_AzUpr = BitConverter.ToUInt16(DataH0, 24); SD_AzUpr = BitConverter.ToSingle(DataH0, 24);
SD_ElUpr = BitConverter.ToUInt16(DataH0, 28); SD_ElUpr = BitConverter.ToSingle(DataH0, 28);
SD_Shirota = BitConverter.ToUInt16(DataH0, 32); SD_Shirota = BitConverter.ToInt32(DataH0, 32);
SD_Dolgota = BitConverter.ToUInt16(DataH0, 36); SD_Dolgota = BitConverter.ToInt32(DataH0, 36);
SD_Vysota = BitConverter.ToUInt16(DataH0, 40); SD_Vysota = BitConverter.ToInt32(DataH0, 40);
SD_Course = BitConverter.ToInt16(DataH0, 44); SD_Course = BitConverter.ToInt16(DataH0, 44);
SD_Roll = BitConverter.ToInt16(DataH0, 46); SD_Roll = BitConverter.ToInt16(DataH0, 46);
SD_Pitch = BitConverter.ToInt16(DataH0, 48); SD_Pitch = BitConverter.ToInt16(DataH0, 48);
SD_FrameId = BitConverter.ToInt16(DataH0, 50); rez0 = BitConverter.ToUInt16(DataH0, 50);
rez0 = BitConverter.ToUInt16(DataH0, 52); rez1 = BitConverter.ToUInt16(DataH0, 52);
rez1 = BitConverter.ToUInt16(DataH0, 54); rez2 = BitConverter.ToUInt16(DataH0, 54);
rez2 = DataH0[56]; rez3 = DataH0[56];
rez3 = DataH0[57]; rez4 = DataH0[57];
SD_Status = DataH0[58]; SD_Status = DataH0[58];
SD_rezerv = DataH0[59]; rez5 = DataH0[59];
//DE_TLV_X = BitConverter.ToUInt32(DataH0, 60);
//DE_TLV_Y = BitConverter.ToUInt32(DataH0, 64);
//DE_TLV_dX = BitConverter.ToUInt32(DataH0, 68);
//DE_TLV_dY = BitConverter.ToUInt32(DataH0, 72);
} }
public static void GetDataH1() public static void GetDataH1()
{ {
@ -367,7 +352,7 @@ namespace nRTP
public static Int16 SD_Course; // Курс БЛА (0,01 град) public static Int16 SD_Course; // Курс БЛА (0,01 град)
public static Int16 SD_Roll; // Крен БЛА (0,01 град) public static Int16 SD_Roll; // Крен БЛА (0,01 град)
public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град) public static Int16 SD_Pitch; // Тангаж БЛА (0,01 град)
public static Int16 SD_FrameId; public static UInt16 rez0;
public static UInt16 SD_X; // координата центра цели в растре изображения по горизонтали public static UInt16 SD_X; // координата центра цели в растре изображения по горизонтали
public static UInt16 SD_Y; //координата центра цели в растре изображения по вертикали public static UInt16 SD_Y; //координата центра цели в растре изображения по вертикали
@ -455,7 +440,7 @@ namespace nRTP
Array.Copy(BitConverter.GetBytes(SD_Course), 0, DataH0, 44, 2); Array.Copy(BitConverter.GetBytes(SD_Course), 0, DataH0, 44, 2);
Array.Copy(BitConverter.GetBytes(SD_Roll), 0, DataH0, 46, 2); Array.Copy(BitConverter.GetBytes(SD_Roll), 0, DataH0, 46, 2);
Array.Copy(BitConverter.GetBytes(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(rez0), 0, DataH0, 50, 2);
Array.Copy(BitConverter.GetBytes(SD_X), 0, DataH0, 52, 2); Array.Copy(BitConverter.GetBytes(SD_X), 0, DataH0, 52, 2);
Array.Copy(BitConverter.GetBytes(SD_Y), 0, DataH0, 54, 2); Array.Copy(BitConverter.GetBytes(SD_Y), 0, DataH0, 54, 2);
@ -464,11 +449,6 @@ namespace nRTP
Array.Copy(BitConverter.GetBytes(SD_ly), 0, DataH0, 57, 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_Status), 0, DataH0, 58, 1);
Array.Copy(BitConverter.GetBytes(SD_rezerv), 0, DataH0, 59, 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()
{ {
@ -495,25 +475,21 @@ namespace nRTP
MH_Offset = BitConverter.ToUInt16(DataH0, 18); MH_Offset = BitConverter.ToUInt16(DataH0, 18);
SD_Width = BitConverter.ToUInt16(DataH0, 20); SD_Width = BitConverter.ToUInt16(DataH0, 20);
SD_Height = BitConverter.ToUInt16(DataH0, 22); SD_Height = BitConverter.ToUInt16(DataH0, 22);
SD_AzUpr = BitConverter.ToUInt16(DataH0, 24); SD_AzUpr = BitConverter.ToSingle(DataH0, 24);
SD_ElUpr = BitConverter.ToUInt16(DataH0, 28); SD_ElUpr = BitConverter.ToSingle(DataH0, 28);
SD_Shirota = BitConverter.ToUInt16(DataH0, 32); SD_Shirota = BitConverter.ToInt32(DataH0, 32);
SD_Dolgota = BitConverter.ToUInt16(DataH0, 36); SD_Dolgota = BitConverter.ToInt32(DataH0, 36);
SD_Vysota = BitConverter.ToUInt16(DataH0, 40); SD_Vysota = BitConverter.ToInt32(DataH0, 40);
SD_Course = BitConverter.ToInt16(DataH0, 44); SD_Course = BitConverter.ToInt16(DataH0, 44);
SD_Roll = BitConverter.ToInt16(DataH0, 46); SD_Roll = BitConverter.ToInt16(DataH0, 46);
SD_Pitch = BitConverter.ToInt16(DataH0, 48); SD_Pitch = BitConverter.ToInt16(DataH0, 48);
SD_FrameId = BitConverter.ToInt16(DataH0, 50); rez0 = BitConverter.ToUInt16(DataH0, 50);
SD_X = BitConverter.ToUInt16(DataH0, 52); SD_X = BitConverter.ToUInt16(DataH0, 52);
SD_Y = BitConverter.ToUInt16(DataH0, 54); SD_Y = BitConverter.ToUInt16(DataH0, 54);
SD_lx = DataH0[56]; SD_lx = DataH0[56];
SD_ly = DataH0[57]; SD_ly = DataH0[57];
SD_Status = DataH0[58]; SD_Status = DataH0[58];
SD_rezerv = DataH0[59]; SD_rezerv = DataH0[59];
//DE_TLV_X = BitConverter.ToUInt32(DataH0, 60);
//DE_TLV_Y = BitConverter.ToUInt32(DataH0, 64);
//DE_TLV_dX = BitConverter.ToUInt32(DataH0, 68);
//DE_TLV_dY = BitConverter.ToUInt32(DataH0, 72);
} }
public static void GetDataH1() public static void GetDataH1()
{ {

240
udplib.cs

@ -15,10 +15,24 @@ using UTIL;
namespace UDPLIB namespace UDPLIB
{ {
public class UDPreceive public class Data
{ {
Int32 localPort = 5004; public static string Ver = "1.1.2.264";
Int32 remotePort = 5006; protected static string IPAddr = "192.168.1.2";
protected static Int32 LocalPort = 5004;
protected static Int32 RemotePort = 5006;
#if DEBUG
public static string Conf = "Debug";
#else
public static string Conf = "Release";
#endif
}
public class UDPreceive : Data
{
//Int32 localPort = 5004;
//Int32 remotePort = 5006;
Thread UDPreceiveThread = null; Thread UDPreceiveThread = null;
// Thread processFrameThread = null; // Thread processFrameThread = null;
Thread sendFrameThread = null; Thread sendFrameThread = null;
@ -30,11 +44,26 @@ namespace UDPLIB
List<Byte[]> udata50 = new List<byte[]>(); List<Byte[]> udata50 = new List<byte[]>();
List<Byte[]> udata51 = new List<byte[]>(); List<Byte[]> udata51 = new List<byte[]>();
UInt32 cnt_frames = 0; UInt32 cnt_frames = 0;
Res2 rrr2 = new Res2(); // класс ресурсов на замену Res
#region Прием данных #region Прием данных
public UDPreceive(Int32 localPortUDP) public UDPreceive(Int32 localPortUDP)
{ {
localPort = localPortUDP; LocalPort = localPortUDP;
for (int i = 0; i < 2500; i++)
{
udata50.Add(new Byte[0]);
udata51.Add(new Byte[0]);
}
fpstimer = new Stopwatch();
UDPreceiveThread = new Thread(new ThreadStart(UDPReceive7));
listening = true;
UDPreceiveThread.Start();
cnt_frames = 0;
}
public UDPreceive()
{
for (int i = 0; i < 2500; i++) for (int i = 0; i < 2500; i++)
{ {
udata50.Add(new Byte[0]); udata50.Add(new Byte[0]);
@ -70,13 +99,14 @@ namespace UDPLIB
DialogResult res = DialogResult.OK; DialogResult res = DialogResult.OK;
try try
{ {
receiver = new UdpClient(localPort); // receiver = new UdpClient(localPort);
endPoint = new IPEndPoint(IPAddress.Any, localPort); receiver = new UdpClient(LocalPort);
endPoint = new IPEndPoint(IPAddress.Any, LocalPort);
remoteIp = new IPEndPoint(IPAddress.Any, 0); remoteIp = new IPEndPoint(IPAddress.Any, 0);
} }
catch (Exception ee) catch (Exception ee)
{ {
res = MessageBox.Show("Порт " + localPort.ToString() + " используется како-то программой. \r\n" + res = MessageBox.Show("Порт " + LocalPort.ToString() + " используется како-то программой. \r\n" +
"Прием видео невозможен. Перезапустите программу.", "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); "Прием видео невозможен. Перезапустите программу.", "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Diagnostics.Process.GetCurrentProcess().Kill(); System.Diagnostics.Process.GetCurrentProcess().Kill();
return; return;
@ -116,18 +146,55 @@ namespace UDPLIB
} }
if (numrow == 0 && ssrc == 12345678) // Packet 0 if (numrow == 0 && ssrc == 12345678) // Packet 0
{ {
iwidth = BitConverter.ToUInt16(data, 20); //iwidth = BitConverter.ToUInt16(data, 20);
iheight = BitConverter.ToUInt16(data, 22); //iheight = BitConverter.ToUInt16(data, 22);
blackline = new Byte[iwidth * 3 + 20]; blackline = new Byte[iwidth * 3 + 20];
Res.Iwidth = iwidth; RTP.DataH0 = data;
Res.Iheight = iheight; RTP.GetDataH0();
Res.AzUpr = BitConverter.ToSingle(data, 24);
Res.ElUpr = BitConverter.ToSingle(data, 28); //Res.Iwidth = iwidth;
Res.Course = BitConverter.ToInt16(data, 32); //Res.Iheight = iheight;
Res.Roll = BitConverter.ToInt16(data, 34); //Res.AzUpr = BitConverter.ToSingle(data, 24);
Res.Pitch = BitConverter.ToInt16(data, 36); //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;
Res.Iwidth = RTP.SD_Width;
Res.Iheight = RTP.SD_Height;
Res.AzUpr = RTP.SD_AzUpr;
Res.ElUpr = RTP.SD_ElUpr;
Res.Course = RTP.SD_Course;
Res.Roll = RTP.SD_Roll;
Res.Pitch = RTP.SD_Pitch;
Res.Shirota = RTP.SD_Shirota;
Res.Dolgota = RTP.SD_Dolgota;
Res.Vysota = RTP.SD_Vysota;
Res.rejim_oes = RTP.SD_rejim_oes;
Res.zahvat = RTP.SD_zahvat;
Res.color = RTP.SD_color;
rrr2.Iwidth = RTP.SD_Width;
rrr2.Iheight = RTP.SD_Height;
rrr2.AzUpr = RTP.SD_AzUpr;
rrr2.ElUpr = RTP.SD_ElUpr;
rrr2.Course = RTP.SD_Course;
rrr2.Roll = RTP.SD_Roll;
rrr2.Pitch = RTP.SD_Pitch;
rrr2.Shirota = RTP.SD_Shirota;
rrr2.Dolgota = RTP.SD_Dolgota;
rrr2.Vysota = RTP.SD_Vysota;
rrr2.rejim_oes = RTP.SD_rejim_oes;
rrr2.zahvat = RTP.SD_zahvat;
rrr2.color = RTP.SD_color;
} }
if (data[1] == 0xC7 && iheight != 0 && iwidth != 0) if (data[1] == 0xC7 && iheight != 0 && iwidth != 0)
@ -227,14 +294,19 @@ namespace UDPLIB
Res.Clearimg = (Bitmap)img.Clone(); Res.Clearimg = (Bitmap)img.Clone();
Res.Bmp = img; Res.Bmp = img;
rrr2.Clearimg = (Bitmap)img.Clone();
rrr2.Bmp = img;
fpstimer.Stop(); fpstimer.Stop();
// Res.Fps = gk.filtered(1000F / fpstimer.ElapsedMilliseconds); // Res.Fps = gk.filtered(1000F / fpstimer.ElapsedMilliseconds);
Res.Fps = 1000F / fpstimer.ElapsedMilliseconds; Res.Fps = 1000F / fpstimer.ElapsedMilliseconds;
Res.Frames = cnt_frames++; Res.Frames = cnt_frames++;
rrr2.Fps = 1000F / fpstimer.ElapsedMilliseconds;
rrr2.Frames = cnt_frames++;
// Res.Fps = 1000F / fpstimer.ElapsedMilliseconds; // Res.Fps = 1000F / fpstimer.ElapsedMilliseconds;
fpstimer.Reset(); fpstimer.Reset();
fpstimer.Start(); fpstimer.Start();
CallBack.Event_newimg_Handler(); CallBack.Event_newimg_Handler2(rrr2);
} }
catch (Exception) catch (Exception)
{ {
@ -247,7 +319,7 @@ namespace UDPLIB
#endregion #endregion
} }
public class UDPTransmit public class UDPTransmit : Data
{ {
UdpClient transmitter = null; UdpClient transmitter = null;
IPEndPoint endPoint = null; IPEndPoint endPoint = null;
@ -283,6 +355,20 @@ namespace UDPLIB
Thread UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame)); Thread UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame));
UDPtransmitThread.Start(); UDPtransmitThread.Start();
} }
public UDPTransmit((UInt16, UInt16, UInt16, UInt16) p)
{
transmitter = new UdpClient();
endPoint = new IPEndPoint(IPAddress.Parse(IPAddr), RemotePort);
pntX = p.Item1; // X координата
pntY = p.Item2; // Y координата
pntlx = p.Item3; // ширина эталона
pntly = p.Item4; // высота эталона
Res.Crop = Res.Clearimg.Clone(new Rectangle(pntX - pntlx / 2, pntY - pntly / 2, pntlx, pntly), PixelFormat.Format24bppRgb);
Thread UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame));
UDPtransmitThread.Start();
}
public UDPTransmit(String IPaddr, Int32 remotePortUDP, Bitmap crop) public UDPTransmit(String IPaddr, Int32 remotePortUDP, Bitmap crop)
{ {
transmitter = new UdpClient(); transmitter = new UdpClient();
@ -319,7 +405,6 @@ namespace UDPLIB
RTPet.SD_Course = RTP.SD_Course; RTPet.SD_Course = RTP.SD_Course;
RTPet.SD_Roll = RTP.SD_Roll; RTPet.SD_Roll = RTP.SD_Roll;
RTPet.SD_Pitch = RTP.SD_Pitch; RTPet.SD_Pitch = RTP.SD_Pitch;
RTPet.SD_FrameId = 0;
RTPet.SD_X = pntX; RTPet.SD_X = pntX;
RTPet.SD_Y = pntY; RTPet.SD_Y = pntY;
RTPet.SD_lx = (Byte)pntlx; RTPet.SD_lx = (Byte)pntlx;
@ -378,7 +463,7 @@ namespace UDPLIB
} }
public class UDPTransmitSim public class UDPTransmitSim : Data
{ {
UdpClient transmitter = null; UdpClient transmitter = null;
IPEndPoint endPoint = null; IPEndPoint endPoint = null;
@ -388,19 +473,40 @@ namespace UDPLIB
Int32 delayMS = 0; Int32 delayMS = 0;
public Bitmap img = null; // Resources.che1; public Bitmap img = null; // Resources.che1;
volatile Boolean flag = false; volatile Boolean flag = false;
Thread UDPtransmitThread = null;
Stopwatch fpstmr;
private UInt32 cnt_frame = 0;
float fps = 0;
public UDPTransmitSim(String IPaddr, Int32 remotePortUDP, Int32 sizeX, Int32 sizeY, Int32 delayMS) public UDPTransmitSim(String ipaddr, Int32 remotePortUDP, Int32 sizeX, Int32 sizeY, Int32 delayMS)
{ {
transmitter = new UdpClient(); transmitter = new UdpClient();
endPoint = new IPEndPoint(IPAddress.Parse(IPaddr), remotePortUDP); endPoint = new IPEndPoint(IPAddress.Parse(ipaddr), remotePortUDP);
this.sizeX = sizeX; this.sizeX = sizeX;
this.sizeY = sizeY; this.sizeY = sizeY;
this.delayMS = delayMS; this.delayMS = delayMS;
img = new Bitmap(Res.Sim, new Size(sizeX, sizeY)); img = new Bitmap(Res.Sim, new Size(sizeX, sizeY));
Thread UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame)); UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame));
UDPtransmitThread.Start();
Start();
fpstmr = new Stopwatch();
}
public UDPTransmitSim(Int32 sizeX, Int32 sizeY, Int32 delayMS)
{
transmitter = new UdpClient();
endPoint = new IPEndPoint(IPAddress.Parse(IPAddr), RemotePort);
this.sizeX = sizeX;
this.sizeY = sizeY;
this.delayMS = delayMS;
img = new Bitmap(Res.Sim, new Size(sizeX, sizeY));
UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame));
UDPtransmitThread.Start(); UDPtransmitThread.Start();
Start();
fpstmr = new Stopwatch();
} }
public UDPTransmitSim(String IPaddr, Int32 remotePortUDP, Int32 delayMS, Bitmap i) public UDPTransmitSim(String IPaddr, Int32 remotePortUDP, Int32 delayMS, Bitmap i)
{ {
@ -410,10 +516,12 @@ namespace UDPLIB
sizeY = i.Height; sizeY = i.Height;
this.delayMS = delayMS; this.delayMS = delayMS;
img = i; img = new Bitmap(i);
Thread UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame)); UDPtransmitThread = new Thread(new ThreadStart(UDPtransmitFrame));
UDPtransmitThread.Start(); UDPtransmitThread.Start();
Start();
fpstmr = new Stopwatch();
} }
public void Start() public void Start()
{ {
@ -421,13 +529,17 @@ namespace UDPLIB
} }
public void Stop() public void Stop()
{ {
flag &= false; flag = false;
} }
void UDPtransmitFrame() void UDPtransmitFrame()
{ {
transmitter.Connect(endPoint);
Res.Frames = 0;
//cnt_frame = 0;
while (flag) while (flag)
{ {
transmitter.Connect(endPoint); fpstmr.Start();
// RTPMsgHeader // RTPMsgHeader
RTP.MH_VerPXCC = 2; RTP.MH_VerPXCC = 2;
RTP.MH_MPT = 0xC6; RTP.MH_MPT = 0xC6;
@ -452,8 +564,6 @@ namespace UDPLIB
RTP.SD_rejim_oes = 2; RTP.SD_rejim_oes = 2;
RTP.SD_color = 1; RTP.SD_color = 1;
RTP.SD_FrameId = 0;
RTP.MakeDataH0(); RTP.MakeDataH0();
transmitter.Send(RTP.DataH0, RTP.DataH0.Length); transmitter.Send(RTP.DataH0, RTP.DataH0.Length);
@ -484,9 +594,9 @@ namespace UDPLIB
for (int j = 0; j < sizeX; j++) for (int j = 0; j < sizeX; j++)
{ {
Color c = img.GetPixel(j, i); Color c = img.GetPixel(j, i);
dataimg[ccc++] = c.B;
dataimg[ccc++] = c.G;
dataimg[ccc++] = c.R; dataimg[ccc++] = c.R;
dataimg[ccc++] = c.G;
dataimg[ccc++] = c.B;
} }
} }
catch (Exception ee) catch (Exception ee)
@ -499,10 +609,32 @@ namespace UDPLIB
Array.Copy(dataimg, 0, dataudp, RTP.DataH1.Length, dataimg.Length); Array.Copy(dataimg, 0, dataudp, RTP.DataH1.Length, dataimg.Length);
transmitter.Send(dataudp, dataudp.Length); transmitter.Send(dataudp, dataudp.Length);
} }
transmitter.Close(); Res.Frames++;
// transmitter.Close();
fpstmr.Stop();
fps = 1000F / fpstmr.ElapsedMilliseconds;
Res.Fps = fps;
fpstmr.Reset();
cnt_frame++;
CallBack.Event_transmitted_Handler();
Thread.Sleep(delayMS); Thread.Sleep(delayMS);
} }
Res.Frames = 0;
Res.Fps = 0;
CallBack.Event_transmitted_Handler();
transmitter.Close();
transmitter.Dispose();
}
public void Dispose()
{
if (img != null)
{
UDPtransmitThread.Abort();
img.Dispose();
}
flag = false;
} }
} }
class thrdata class thrdata
@ -542,27 +674,13 @@ namespace UDPLIB
public static Byte rejim_oes { set; get; } // Режим ОЭС: «0» – Обзор, «1» – АС public static Byte rejim_oes { set; get; } // Режим ОЭС: «0» – Обзор, «1» – АС
public static Byte zahvat { set; get; } // Захват: «0» – отсутствие захвата, «1» – налачие захвата public static Byte zahvat { set; get; } // Захват: «0» – отсутствие захвата, «1» – налачие захвата
public static Byte color { set; get; } // Цвет изображения: «1» – цветное, «0» – монохромное public static Byte color { set; get; } // Цвет изображения: «1» – цветное, «0» – монохромное
public static String Version public static String Version { get => Data.Ver; }
{ public static String Configuration { get => Data.Conf; }
get
{
return "1.1.0.255";
// return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public static String Configuration
{
get
{
#if DEBUG
return "Debug";
#else
return "Release";
#endif
}
}
public static Boolean status_rs { set; get; } public static Boolean status_rs { set; get; }
public static Boolean status_eth { set; get; } public static Boolean status_eth { set; get; }
public static float Az { set; get; }
public static float El { set; get; }
} }
public class Res2 public class Res2
{ {
@ -588,24 +706,8 @@ namespace UDPLIB
public Byte rejim_oes; // Режим ОЭС: «0» – Обзор, «1» – АС public Byte rejim_oes; // Режим ОЭС: «0» – Обзор, «1» – АС
public Byte zahvat; // Захват: «0» – отсутствие захвата, «1» – налачие захвата public Byte zahvat; // Захват: «0» – отсутствие захвата, «1» – налачие захвата
public Byte color; // Цвет изображения: «1» – цветное, «0» – монохромное public Byte color; // Цвет изображения: «1» – цветное, «0» – монохромное
public String Version public String Version { get => Data.Ver; }
{ public String Configuration { get => Data.Conf; }
get
{
return "1.1.0.255";
}
}
public String Configuration
{
get
{
#if DEBUG
return "Debug";
#else
return "Release";
#endif
}
}
public Boolean status_rs { set; get; } public Boolean status_rs { set; get; }
public Boolean status_eth { set; get; } public Boolean status_eth { set; get; }
} }

Loading…
Cancel
Save