瀏覽代碼

模拟web端停取指令

yc_t 7 年之前
父節點
當前提交
0544eaabd5

+ 1 - 0
parkMonitor/parkMonitor.csproj

@@ -151,6 +151,7 @@
       <DependentUpon>NumMachine.cs</DependentUpon>
     </Compile>
     <Compile Include="server\NumMachine\NumMachineSimul.cs" />
+    <Compile Include="server\NumMachine\ParkingSimul.cs" />
     <Compile Include="server\NumMachine\VzClientSDK.cs" />
     <Compile Include="server\PLCLinker\PLCLinker.cs" />
     <Compile Include="server\monitorServer\DevParamModel.cs" />

+ 4 - 0
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -12,6 +12,7 @@ using parkMonitor.server.uiLogServer;
 using parkMonitor.tools;
 using parkMonitor.DataBase;
 using MySql.Data.MySqlClient;
+using parkMonitor.server.NumMachine;
 
 namespace parkMonitor.server.CoreThread
 {
@@ -678,6 +679,7 @@ namespace parkMonitor.server.CoreThread
                 while (pb == null && !MyTimer.restart)
                 {
                     pb = ParkingBufferManager.ins.MallocParkingBuffer(queueCmd.id);
+                    Log.WriteLog(LogType.NOT_DATABASE, LogFile.INFO, queueCmd.LicenseNum + "分配缓冲位:"+pb.bufferID);
                     if (pb == null && !displayed)
                     {
                         UILogServer.ins.error(queueCmd.LicenseNum + "缓冲位已满");
@@ -885,6 +887,7 @@ namespace parkMonitor.server.CoreThread
             Robot.robot1.waitCount -= 1;
             //自动化测试用
             //ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
+            ParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
             //根据号牌查找车型
             //int vehicleTypeID = oper.getVehicleTypeID(numberPlate);
             //判断测量数据是否准确
@@ -1137,6 +1140,7 @@ namespace parkMonitor.server.CoreThread
 
             //自动化测试用
             //ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
+            ParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
 
             int freeSpaceCount = ParkingSpaceManager.ins.GetFreeSpaceCount();
             //数据库更新

+ 14 - 14
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -143,7 +143,7 @@ namespace parkMonitor.server.CoreThread
                                 //远端或本地异常,遇到相应指令则退回
                                 if ((!queueCmd.manual && Operation.malfunctionRemote) || (queueCmd.manual && Operation.malfunctionLocal))
                                 {
-                                    queueCmd.returnedCount = +1;
+                                    queueCmd.returnedCount = 1;
                                     queuingThread.SetMessage((Command)queueCmd.Clone());
                                     Thread.Sleep(5000);
                                 }
@@ -247,18 +247,18 @@ namespace parkMonitor.server.CoreThread
         /// <summary>
         /// 获取可执行号牌
         /// </summary>
-        private AbstractMessage GetExecuteNumberPlate()
-        {
-            AbstractMessage msg = null;
-            while (!isClosing)
-            {
-                msg = queuingThread.GetMessage();
-                if (msg != null)
-                {
-                    break;
-                }
-            }
-            return msg;
-        }
+        //private AbstractMessage GetExecuteNumberPlate()
+        //{
+        //    AbstractMessage msg = null;
+        //    while (!isClosing)
+        //    {
+        //        msg = queuingThread.GetMessage();
+        //        if (msg != null)
+        //        {
+        //            break;
+        //        }
+        //    }
+        //    return msg;
+        //}
     }
 }

+ 2 - 0
parkMonitor/server/NumMachine/NumMachineSimul.cs

@@ -1,4 +1,5 @@
 using parkMonitor.entity;
+using parkMonitor.server.NumMachine;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -180,6 +181,7 @@ namespace parkMonitor.server
             Task.Factory.StartNew(() =>
             {
                 //ManualParkingSimul.ins = new ManualParkingSimul();
+                ParkingSimul.ins = new ParkingSimul();
             });
            
         }

+ 162 - 0
parkMonitor/server/NumMachine/ParkingSimul.cs

@@ -0,0 +1,162 @@
+using parkMonitor.DataBase;
+using parkMonitor.entity;
+using parkMonitor.LOG;
+using parkMonitor.model;
+using parkMonitor.server.uiLogServer;
+using parkMonitor.Tools;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace parkMonitor.server.NumMachine
+{
+    class ParkingSimul
+    {
+        public static ParkingSimul ins;
+        private const string hostname = "119.96.206.151";
+        private const int port = 9000;
+        private const string userId = "18202736439";
+        private const string garageId = "1";
+        private const string header = "鄂A";
+        private const int licInterval = 5000;//90秒
+        private Random rnd;
+        private Dictionary<int, CarStatusStru> numStatusMap = new Dictionary<int, CarStatusStru>();
+        MessageUTF8 msgToWeb = new MessageUTF8();
+        IEquipments queue = null;
+        //DBOperation oper = new DBOperation();
+        private NetworkStream ns { get; set; }
+
+        public ParkingSimul()
+        {
+            Task.Factory.StartNew(() =>
+            {
+                for (int i = 0; i < 10; i++)
+                {
+                    numStatusMap.Add(i, new CarStatusStru(header + (i * 11111).ToString("D5"), 0));
+                }
+                while (queue == null)
+                {
+                    queue = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Queue);
+                }
+            }).Wait();
+            Task.Factory.StartNew(() =>
+            {
+                Run();
+            });
+        }
+
+        public void Store(string lic)
+        {
+            msgToWeb = new MessageUTF8();
+            msgToWeb.cmd = 's';
+            msgToWeb.garageID = 1;
+            msgToWeb.context = lic;
+            msgToWeb.sender = "1";
+            msgToWeb.receiver = hostname;
+            TcpClient client = new TcpClient();
+            while (true)
+            {
+                try
+                {
+                    client = new TcpClient();
+                    client.Connect(hostname, port);
+                    ns = client.GetStream();
+                    byte[] byteMessage = JsonByByteToObjectTools.ObjToJsonByte(msgToWeb);
+                    ns.Write(byteMessage, 0, byteMessage.Length);
+                    ns.Flush();
+                    ns.Close();
+                    client.Close();
+                    break;
+                }
+                catch { }
+                Thread.Sleep(5000);
+            }
+        }
+
+        public void Fetch(string lic)
+        {
+            msgToWeb = new MessageUTF8();
+            msgToWeb.cmd = 'f';
+            msgToWeb.garageID = 1;
+            msgToWeb.context = lic;
+            msgToWeb.sender = "1";
+            msgToWeb.receiver = hostname;
+            TcpClient client = new TcpClient();
+            while (true)
+            {
+                try
+                {
+                    client.Connect(hostname, port);
+                    ns = client.GetStream();
+                    byte[] byteMessage = JsonByByteToObjectTools.ObjToJsonByte(msgToWeb);
+                    ns.Write(byteMessage, 0, byteMessage.Length);
+                    ns.Flush();
+                    break;
+                }
+                catch { }
+                Thread.Sleep(5000);
+            }
+        }
+
+        public void Run()
+        {
+            while (true)
+            {
+                rnd = new Random(DateTime.Now.Millisecond);
+                if (numStatusMap.Count > 0)
+                {
+                    int index = -1, status = -1, count = numStatusMap.Count;
+                    do
+                    {
+                        index = rnd.Next(0, numStatusMap.Count);
+                        status = numStatusMap[index].status;
+                    } while (count-- > 0 && status != 0 && status != 1);
+                    if (status == 0)
+                    {
+                        Store(numStatusMap[index].licNum);
+                        numStatusMap[index].status = 2;
+                    }
+                    else if (status == 1)
+                    {
+                        Fetch(numStatusMap[index].licNum);
+                        numStatusMap[index].status = 3;
+                    }
+
+                }
+                Thread.Sleep(licInterval);
+            }
+        }
+
+        public void Update(int index)
+        {
+            int status = numStatusMap[index].status;
+            if (status == 2)
+            {
+                numStatusMap[index].status = 1;
+            }
+            else if (status == 3)
+            {
+                numStatusMap[index].status = 0;
+            }
+        }
+    }
+    class CarStatusStru
+    {
+        public string licNum { get; set; }
+        public int status { get; set; }
+        public CarStatusStru()
+        {
+            licNum = "";
+            status = 0;
+        }
+        public CarStatusStru(string str, int stat)
+        {
+            licNum = str;
+            status = stat;
+        }
+    }
+}