Browse Source

修改NC文件读取次数以减少读取错误概率

liyang 6 months ago
parent
commit
3221f69693

+ 18 - 9
SimulationServer/Entity/AircraftDY.cs

@@ -17,6 +17,10 @@ public class AircraftDY : AircraftEntity
     public double resulttime;
 
     public int targetCount;
+
+    public bool isReadNC;
+
+    Text_readNC text_ReadNC;
     public override void End()
     {
         TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
@@ -34,15 +38,20 @@ public class AircraftDY : AircraftEntity
     public override void Start()
     {
         targetCount = FlightPlanEditor.targetpoint[0].TargetType.Count;
-        getNCData = new GetNCData();
-        getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
-        getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-        getNCData.GetData();
-        Text_readNC text_ReadNC = new Text_readNC();
-        text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
-        text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-        //text_ReadNC = new Text_readNC();
-        text_ReadNC.GetNCData();
+
+        if (!isReadNC)
+        {
+            getNCData = new GetNCData();
+            getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+            getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
+            getNCData.GetData();
+            text_ReadNC = new Text_readNC();
+            text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+            text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
+            //text_ReadNC = new Text_readNC();
+            text_ReadNC.GetNCData();
+            isReadNC = true;
+        }
 
         int hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
         //Console.WriteLine("hour:" + hour);

+ 12 - 4
SimulationServer/Entity/AircraftKTKS.cs

@@ -30,6 +30,10 @@ public class AircraftKTKS : AircraftEntity
 
     public RescueDemandInfo rescueDemandInfo;
 
+    public bool isReadNC;
+
+    Text_readNC text_ReadNC;
+
     public override void End()
     {
         TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
@@ -73,10 +77,14 @@ public class AircraftKTKS : AircraftEntity
         int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
         Hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
         Days = GetDaysInYear(Year, Month, Day);
-        Text_readNC text_ReadNC = new Text_readNC();
-        text_ReadNC.initlatitudes = rescueDemandInfo.TargetPointLatitude;
-        text_ReadNC.initlongitudes = rescueDemandInfo.TargetPointLongitude;
-        text_ReadNC.GetNCData();
+        if (!isReadNC)
+        {
+            text_ReadNC = new Text_readNC();
+            text_ReadNC.initlatitudes = rescueDemandInfo.TargetPointLatitude;
+            text_ReadNC.initlongitudes = rescueDemandInfo.TargetPointLongitude;
+            text_ReadNC.GetNCData();
+            isReadNC = true;
+        }
         var nCread = text_ReadNC.windNCread;
 
         double[] windVelocity = GetWindVelocityFromAPI(nCread, rescueDemandInfo.TargetPointLatitude, rescueDemandInfo.TargetPointLongitude, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour);

+ 13 - 5
SimulationServer/Entity/AircraftLandSJ.cs

@@ -39,6 +39,10 @@ public class AircraftLandSJ : AircraftEntity
 
     public double landArea;
 
+    public bool isReadNC;
+
+    Text_readNC text_ReadNC;
+
     public override void Reset()
     {
         base.Reset();
@@ -297,11 +301,15 @@ public class AircraftLandSJ : AircraftEntity
                 double seeTime = 0;
                 if (FlightPlanEditor.targetpoint[0].TargetType.Type == "遇险人员")
                 {
-                    Text_readNC text_ReadNC = new Text_readNC();
-                    text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
-                    text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-                    //text_ReadNC = new Text_readNC();
-                    text_ReadNC.GetNCData();
+                    if (!isReadNC)
+                    {
+                        text_ReadNC = new Text_readNC();
+                        text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+                        text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
+                        //text_ReadNC = new Text_readNC();
+                        text_ReadNC.GetNCData();
+                        isReadNC = true;
+                    }
                     var nCread = text_ReadNC.windNCread;
                     var wind = SeaSJ.GetWindVelocityFromAPI(nCread, currentLocation.CurrentLat, currentLocation.CurrentLon,
                 temptime, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, text_ReadNC.times1, text_ReadNC.latitudes1, text_ReadNC.longitudes1, Days, Hour);

+ 30 - 14
SimulationServer/Entity/AircraftSJ.cs

@@ -5,6 +5,7 @@ using MuShiApp;
 using Org.BouncyCastle.Asn1.Pkcs;
 using SimulationCommon;
 using SimulationSingleServer.Utils;
+using System.Threading;
 using Unity.Mathematics;
 using Point = SimulationCommon.Point;
 using Random = System.Random;
@@ -45,6 +46,10 @@ public class AircraftSJ : AircraftEntity
 
     public double seaArea;
 
+    public bool isReadNC;
+
+    Text_readNC text_ReadNC;
+
     public override void Reset()
     {
         base.Reset();
@@ -87,16 +92,27 @@ public class AircraftSJ : AircraftEntity
         double dt = 1;
         double totalTime = 24.0;
 
-        //if (!isbool2)
-        //{
-        Text_readNC text_ReadNC = new Text_readNC();
-        text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
-        text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-        //text_ReadNC = new Text_readNC();
-        text_ReadNC.GetNCData();
-        text_ReadNC.GetWaveHighData();
-        //isbool2 = true;
-        //}
+
+        if (!isReadNC)
+        {
+            //if (!isbool2)
+            //{
+            text_ReadNC = new Text_readNC();
+            text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+            text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
+            //text_ReadNC = new Text_readNC();
+            text_ReadNC.GetNCData();
+            text_ReadNC.GetWaveHighData();
+            //isbool2 = true;
+            //}
+
+            getNCData = new GetNCData();
+            getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+            getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
+            getNCData.GetData();
+
+            isReadNC = true;
+        }
         var nCread = text_ReadNC.windNCread;
 
         //漂移轨迹
@@ -255,10 +271,10 @@ public class AircraftSJ : AircraftEntity
 
         //if (!isbool)
         //{
-        getNCData = new GetNCData();
-        getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
-        getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-        getNCData.GetData();
+        //getNCData = new GetNCData();
+        //getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
+        //getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
+        //getNCData.GetData();
         //isbool = true;
         //}
 

BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.dll


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.exe


BIN
SimulationServer/bin/Debug/net7.0/SimulationServer.pdb