gongqiuhong 1 year ago
parent
commit
ef539c2b13

+ 27 - 0
XdCxRhDW.App/Api/EphHelper.cs

@@ -168,22 +168,49 @@ namespace PosResAnalysis
     }
     public class SatEphDto
     {
+        /// <summary>
+        /// 卫星编号
+        /// </summary>
         [Display(Name = "卫星编号")]
         public int SatId { get; set; }
+        /// <summary>
+        /// 卫星时刻(北京时间)
+        /// </summary>
         [Display(Name = "卫星时刻")]
         public DateTime SatTime { get; set; }
+        /// <summary>
+        /// 星厉时刻(北京时间)
+        /// </summary>
         [Display(Name = "星厉时刻")]
         public DateTime TleTime { get; set; }
+        /// <summary>
+        /// X坐标
+        /// </summary>
         [Display(Name = "X")]
         public double X { get; set; }
+        /// <summary>
+        /// Y坐标
+        /// </summary>
         [Display(Name = "Y")]
         public double Y { get; set; }
+        /// <summary>
+        /// Z坐标
+        /// </summary>
         [Display(Name = "Z")]
         public double Z { get; set; }
+        /// <summary>
+        /// X方向速率
+        /// </summary>
         [Display(Name = "VX")]
         public double VX { get; set; }
+        /// <summary>
+        /// Y方向速率
+        /// </summary>
         [Display(Name = "VY")]
         public double VY { get; set; }
+        /// <summary>
+        /// Z方向速率
+        /// </summary>
         [Display(Name = "VZ")]
         public double VZ { get; set; }
         public override string ToString()

+ 1 - 1
XdCxRhDW.App/Api/PosApi.cs

@@ -25,7 +25,7 @@ namespace XdCxRhDW.App.Api
         private const string X2D1 = @"AddIns\DLL_SC_2X1D_DW.dll";
 
         [DllImport(XDCX, EntryPoint = "XD_CX_DW", CallingConvention = CallingConvention.Cdecl)]//一星一地
-        private extern static void X1D1_POS2023_Core(double[] mainSat, double[] satStation, double[] cdbStation, double[] cxStation, double[] refStation, double[] zone, double theta, double tarDto, double refDto, double[] res);
+        public extern static void X1D1_POS2023_Core(double[] mainSat, double[] satStation, double[] cdbStation, double[] cxStation, double[] refStation, double[] zone, double theta, double tarDto, double refDto, double[] res);
 
 
         [DllImport(X2D1, EntryPoint = "SC_2X1D_DW", CallingConvention = CallingConvention.Cdecl)]//两星一地

+ 4 - 0
XdCxRhDW.App/Properties/licenses.licx

@@ -0,0 +1,4 @@
+DevExpress.XtraLayout.LayoutControl, DevExpress.XtraLayout.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
+DevExpress.XtraGrid.GridControl, DevExpress.XtraGrid.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
+DevExpress.XtraMap.MapControl, DevExpress.XtraMap.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
+DevExpress.XtraBars.BarManager, DevExpress.XtraBars.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a

+ 4 - 0
XdCxRhDW.App/UserControl/CtrlHome.cs

@@ -536,6 +536,10 @@ namespace XdCxRhDW.App.UserControl
                 var msg = Encoding.UTF8.GetString(data);
                 var dto = Newtonsoft.Json.JsonConvert.DeserializeObject<SendDto>(msg);
                 if (dto == null) return;
+                if (!dto.MainX.HasValue || !dto.AdjaX.HasValue)//没有推送星厉
+                { 
+
+                }
                 var sigTime = DateTime.Now;
                 using (RHDWContext db = new RHDWContext())
                 {

+ 59 - 4
XdCxRhDW.App/WebAPI/Controllers/PosController.cs

@@ -17,6 +17,7 @@ using XdCxRhDW.App.WebAPI.DTO;
 using XdCxRhDW.Dto;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
 using static XdCxRhDw.CpuCgTools.FormCpuCg;
+using CgRes = XdCxRhDW.App.Model.CgRes;
 
 namespace XdCxRhDW.App.WebAPI
 {
@@ -108,14 +109,68 @@ namespace XdCxRhDW.App.WebAPI
             }
             return Success();
         }
-
         /// <summary>
-        /// 查询定位结果(暂未实现)
+        /// 推送时有星厉
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
-        /// <exception cref="Exception"></exception>
-        [HttpGet]
+        readonly Random r = new Random();
+        [HttpPost]
+        public async Task<AjaxResult<double[]>> PosX1D1Async(IEnumerable<SendDto> dtoList)
+        {
+            using (RHDWContext db = new RHDWContext())
+            {
+                foreach (var dto in dtoList)
+                {
+                    var sigTime = DateTime.Now;
+
+                    var cgRes = db.CgRes.Add(new CgRes()
+                    {
+                        SigTime = sigTime,
+                        DtoSx = dto.SxDto * 1e6,
+                        DfoSx = 200 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
+                        SnrSx = r.Next(18, 24) + Math.Round(r.NextDouble(), 1),
+                        DtoCdb = dto.XdDto * 1e6,
+                        DfoCdb = 600 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
+                        SnrCdb = r.Next(22, 32) + Math.Round(r.NextDouble(), 1),
+                        YbMain = dto.MainYbDto * 1e6,
+                        YbAdja = dto.AdjaYbDto * 1e6,
+                        MainX = dto.MainX,
+                        MainY = dto.MainY,
+                        MainZ = dto.MainZ,
+                        AdjaX = dto.AdjaX,
+                        AdjaY = dto.AdjaY,
+                        AdjaZ = dto.AdjaZ,
+                    });
+                }
+            }
+            var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
+            var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
+            var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
+            var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
+            double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
+            double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
+            double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
+            double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
+            double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
+            double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
+            double theta = cxRes.Fx;//单位°
+            double[] res = new double[6];
+            PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, res);
+            return Success(res.Select(p => Math.Round(p, 4)).ToArray());
+        }
+        [HttpPost]
+        //public async Task<AjaxResult<double[]>> PosX1D1NoXlAsync(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
+        //{
+          
+        //}
+            /// <summary>
+            /// 查询定位结果(暂未实现)
+            /// </summary>
+            /// <param name="dto"></param>
+            /// <returns></returns>
+            /// <exception cref="Exception"></exception>
+            [HttpGet]
         public async Task<AjaxResult<PosResDto>> GetPosRes(PosResQueryDto dto)
         {
             await Task.Delay(100);

+ 52 - 0
XdCxRhDW.App/WebAPI/Controllers/SendController.cs

@@ -0,0 +1,52 @@
+using DevExpress.XtraLayout;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Web.Http;
+using XdCxRhDw.Dto;
+using XdCxRhDW.Dto;
+
+namespace XdCxRhDW.App.WebAPI.Controllers
+{
+    /// <summary>
+    /// 推送接口
+    /// </summary>
+    public class SendController : BaseController
+    {
+        CancellationTokenSource cts1;
+        /// <summary>
+        /// 推送数据
+        /// </summary>
+        /// <param name="dtoList"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<AjaxResult> SendXdCxRhDW(IEnumerable<SendDto> dtoList)
+        {
+            cts1 = new CancellationTokenSource();
+            while (!cts1.IsCancellationRequested)
+            {
+                try
+                {
+                    //int idx = 1;
+                    foreach (var dto in dtoList)
+                    {
+                        if (cts1.IsCancellationRequested) break;
+                        var msg = Newtonsoft.Json.JsonConvert.SerializeObject(dto);
+                        await Task.Delay(3000, cts1.Token);
+                    }
+                    return Success();
+                }
+                catch (Exception ex)
+                {
+                    await Task.Delay(5000, cts1.Token);
+                    return Error("推送异常!");
+                }
+            }
+            return Error("");
+        }
+    }
+}

+ 6 - 0
XdCxRhDW.App/WebAPI/Controllers/XlController.cs

@@ -28,6 +28,8 @@ namespace XdCxRhDW.App.WebAPI
         /// <summary>
         /// 推算某个时间点星厉
         /// </summary>
+        /// <param name="tleStr">双行根</param>
+        /// <param name="dt">推算时刻(北京时刻)</param>
         /// <returns></returns>
         [HttpGet]
         public async Task<AjaxResult<SatEphDto>> Calc(string tleStr, DateTime dt)
@@ -39,6 +41,10 @@ namespace XdCxRhDW.App.WebAPI
         /// <summary>
         /// 推算某个时间段星厉
         /// </summary>
+        /// <param name="tleStr">双行根</param>
+        /// <param name="start">开始时刻(北京时刻)</param>
+        /// <param name="end">结束时刻(北京时刻)</param
+        /// <param name="spanSeconds">推算间隔(秒)</param>
         /// <returns></returns>
         [HttpGet]
         public async Task<AjaxResult<List<SatEphDto>>> CalcMult(string tleStr, DateTime start, DateTime end, int spanSeconds)

+ 2 - 0
XdCxRhDW.App/XdCxRhDW.App.csproj

@@ -369,6 +369,7 @@
     </Compile>
     <Compile Include="WebAPI\Controllers\BaseController.cs" />
     <Compile Include="WebAPI\Controllers\DetectCgController.cs" />
+    <Compile Include="WebAPI\Controllers\SendController.cs" />
     <Compile Include="WebAPI\Controllers\XlController.cs" />
     <Compile Include="WebAPI\Controllers\PosController.cs" />
     <Compile Include="WebAPI\DTO\Test.cs" />
@@ -407,6 +408,7 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
     <None Include="packages.config" />
+    <EmbeddedResource Include="Properties\licenses.licx" />
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>

+ 93 - 41
XdCxRhDW.Sender/Form1.cs

@@ -1,4 +1,5 @@
-using System;
+using Newtonsoft.Json;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
@@ -6,6 +7,7 @@ using System.Drawing;
 using System.IO;
 using System.Linq;
 using System.Net;
+using System.Net.Http;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
@@ -22,7 +24,6 @@ namespace XdCxRhDW.Sender
             InitializeComponent();
         }
         CancellationTokenSource cts1;
-        TcpClient client1;
         private async void btn1_Click(object sender, EventArgs e)
         {
             layoutControlItem1.Enabled = false;
@@ -36,37 +37,15 @@ namespace XdCxRhDW.Sender
                     var addrArr = txtAddr1.Text.Trim().Replace(":", ":").Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                     string ip = addrArr[0];
                     int port = Convert.ToInt32(addrArr[1]);
-                    S:
-                    if (string.IsNullOrWhiteSpace(localPort1.Text))
-                        client1 = new TcpClient();
-                    else
-                        client1 = new TcpClient(new IPEndPoint(IPAddress.Any, Convert.ToInt32(localPort1.Text)));
-                    client1.NoDelay = true;
-                    client1.SendTimeout = 5000;
-                    client1.ReceiveTimeout = 5000;
-                    while (!cts1.IsCancellationRequested)
+                    //S:
+                    using (var client = new HttpClient())
                     {
                         try
                         {
-                            await client1.ConnectAsync(IPAddress.Parse(ip), port);
-                            break;
-                        }
-                        catch (Exception ex)
-                        {
-                            Log(ex);
-                            await Task.Delay(5000, cts1.Token);
-                        }
-                    }
-                    Log($"已成功连接到[{txtAddr1.Text}]");
-                    var lines = File.ReadAllLines("Simulation_Data2023.dat");
-                    while (!cts1.IsCancellationRequested)
-                    {
-                        try
-                        {
-                            int idx = 1;
+                            var lines = File.ReadAllLines("Simulation_Data2023.dat");
+                            List<SendDto> sendDtoList = new List<SendDto>();
                             foreach (var line in lines)
                             {
-                                if (cts1.IsCancellationRequested) break;
                                 if (string.IsNullOrWhiteSpace(line)) continue;
                                 var items = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                 SendDto dto = new SendDto()
@@ -83,26 +62,99 @@ namespace XdCxRhDW.Sender
                                     AdjaY = Convert.ToDouble(items[11]),
                                     AdjaZ = Convert.ToDouble(items[12]),
                                 };
-                                var msg = Newtonsoft.Json.JsonConvert.SerializeObject(dto);
-                                var data = Encoding.UTF8.GetBytes(msg);
-                                var dataWithHeader = BitConverter.GetBytes(data.Length).Concat(data).ToArray();
-                                await client1.GetStream().WriteAsync(dataWithHeader, 0, dataWithHeader.Length);
-                                Log($"已向[{txtAddr1.Text}]发送第{idx++}条仿真结果");
-                                await Task.Delay(3000, cts1.Token);
+                                sendDtoList.Add(dto);
                             }
-
-                        }
-                        catch (InvalidOperationException)
-                        {
-                            goto S;
+                            string url = string.Format("http://{0}:{1}/Api/Send/SendXdCxRhDW", ip, port);
+                            var content = new StringContent(JsonConvert.SerializeObject(sendDtoList), System.Text.Encoding.UTF8, "application/json");
+                            var response = await client.PostAsync(url, content);
+                            Log($"已向[{txtAddr1.Text}]发送{sendDtoList.Count}条仿真结果");
                         }
                         catch (Exception ex)
                         {
                             Log($"向[{txtAddr1.Text}]发送结果失败.{ex.Message}");
-                            await Task.Delay(5000, cts1.Token);
                         }
                     }
 
+                    //if (string.IsNullOrWhiteSpace(localPort1.Text))
+                    //    client1 = new TcpClient();
+                    //else
+                    //    client1 = new TcpClient(new IPEndPoint(IPAddress.Any, Convert.ToInt32(localPort1.Text)));
+                    //client1.NoDelay = true;
+                    //client1.SendTimeout = 5000;
+                    //client1.ReceiveTimeout = 5000;
+                    //while (!cts1.IsCancellationRequested)
+                    //{
+                    //    try
+                    //    {
+                    //        await client1.ConnectAsync(IPAddress.Parse(ip), port);
+                    //        break;
+                    //    }
+                    //    catch (Exception ex)
+                    //    {
+                    //        Log(ex);
+                    //        await Task.Delay(5000, cts1.Token);
+                    //    }
+                    //}
+                    //Log($"已成功连接到[{txtAddr1.Text}]");
+                    //var lines = File.ReadAllLines("Simulation_Data2023.dat");
+                    //while (!cts1.IsCancellationRequested)
+                    //{
+                    //    try
+                    //    {
+                    //        int idx = 1;
+                    //        foreach (var line in lines)
+                    //        {
+                    //            if (cts1.IsCancellationRequested) break;
+                    //            if (string.IsNullOrWhiteSpace(line)) continue;
+                    //            var items = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+                    //            //SendDto dto = new SendDto()
+                    //            //{
+                    //            //    SxDto = Convert.ToDouble(items[0]),
+                    //            //    XdDto = Convert.ToDouble(items[1]),
+                    //            //    MainYbDto = Convert.ToDouble(items[2]),
+                    //            //    AdjaYbDto = Convert.ToDouble(items[3]),
+                    //            //    CxRes = Convert.ToDouble(items[4]),
+                    //            //    MainX = Convert.ToDouble(items[7]),
+                    //            //    MainY = Convert.ToDouble(items[8]),
+                    //            //    MainZ = Convert.ToDouble(items[9]),
+                    //            //    AdjaX = Convert.ToDouble(items[10]),
+                    //            //    AdjaY = Convert.ToDouble(items[11]),
+                    //            //    AdjaZ = Convert.ToDouble(items[12]),
+                    //            //};
+                    //            SendDto dto = new SendDto()
+                    //            {
+                    //                SxDto = Convert.ToDouble(items[0]),
+                    //                XdDto = Convert.ToDouble(items[1]),
+                    //                MainYbDto = Convert.ToDouble(items[2]),
+                    //                AdjaYbDto = Convert.ToDouble(items[3]),
+                    //                CxRes = Convert.ToDouble(items[4]),
+                    //                MainX = null,
+                    //                MainY = null,
+                    //                MainZ = null,
+                    //                AdjaX = null,
+                    //                AdjaY = null,
+                    //                AdjaZ = null,
+                    //            };
+                    //            var msg = Newtonsoft.Json.JsonConvert.SerializeObject(dto);
+                    //            var data = Encoding.UTF8.GetBytes(msg);
+                    //            var dataWithHeader = BitConverter.GetBytes(data.Length).Concat(data).ToArray();
+                    //            await client1.GetStream().WriteAsync(dataWithHeader, 0, dataWithHeader.Length);
+                    //            Log($"已向[{txtAddr1.Text}]发送第{idx++}条仿真结果");
+                    //            await Task.Delay(3000, cts1.Token);
+                    //        }
+
+                    //    }
+                    //    catch (InvalidOperationException)
+                    //    {
+                    //        goto S;
+                    //    }
+                    //    catch (Exception ex)
+                    //    {
+                    //        Log($"向[{txtAddr1.Text}]发送结果失败.{ex.Message}");
+                    //        await Task.Delay(5000, cts1.Token);
+                    //    }
+                    //}
+
                 }
                 catch (Exception ex)
                 {
@@ -118,7 +170,7 @@ namespace XdCxRhDW.Sender
             else
             {
                 cts1?.Cancel();
-                client1?.Dispose();
+               // client1?.Dispose();
             }
         }
 

+ 3 - 0
XdCxRhDW.Sender/Properties/licenses.licx

@@ -1,2 +1,5 @@
 DevExpress.XtraCharts.Heatmap.HeatmapControl, DevExpress.XtraCharts.v23.2.UI, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
+DevExpress.XtraLayout.LayoutControl, DevExpress.XtraLayout.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
+DevExpress.XtraEditors.TextEdit, DevExpress.XtraEditors.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
+DevExpress.XtraBars.BarManager, DevExpress.XtraBars.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
 DevExpress.XtraMap.MapControl, DevExpress.XtraMap.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a

+ 6 - 6
XdCxRhDw.Dto/SendDto.cs

@@ -36,11 +36,11 @@ namespace XdCxRhDW.Dto
         /// </summary>
         public double CxRes { get; set; }
 
-        public double MainX { get; set; }
-        public double MainY { get; set; }
-        public double MainZ { get; set; }
-        public double AdjaX { get; set; }
-        public double AdjaY { get; set; }
-        public double AdjaZ { get; set; }
+        public double? MainX { get; set; }
+        public double? MainY { get; set; }
+        public double? MainZ { get; set; }
+        public double? AdjaX { get; set; }
+        public double? AdjaY { get; set; }
+        public double? AdjaZ { get; set; }
     }
 }