Browse Source

消除大部分异常提示,预约停车支持待测

yc_t 6 years ago
parent
commit
33aff7b367

+ 0 - 5
parkMonitor/bll/MainBll.cs

@@ -11,8 +11,6 @@ using MySql.Data.MySqlClient;
 using parkMonitor.DataBase;
 using System.Threading;
 using parkMonitor.LOG;
-using System.Threading;
-using parkMonitor.server.CoreThread;
 
 namespace parkMonitor.bll
 {
@@ -37,9 +35,6 @@ namespace parkMonitor.bll
                 Task.Factory.StartNew(() =>
                 {
                     coreThread.Start();
-                });
-                Task.Factory.StartNew(() =>
-                {
                     (coreThread as ICoreThreadDoWorking).BeginWorking();
                 });
             }

+ 5 - 3
parkMonitor/entity/AbstractMessage.cs

@@ -11,7 +11,7 @@ namespace parkMonitor.entity
     }
 
     /// <summary>
-    /// 用户指令类
+    /// 用户指令类,s停,f取,p预约停
     /// </summary>
     public class MessageUTF8 : AbstractMessage, ICloneable
     {
@@ -21,12 +21,13 @@ namespace parkMonitor.entity
         public string receiver { set; get; }
         public int parkingRecordsID { set; get; }
         public int garageID { get; set; }
+        public string bookTime { get; set; }
 
         public MessageUTF8()
         {
 
         }
-        public MessageUTF8(char cmd, string context, string sender, string receiver, int garageID, int parkingRecordsID)
+        public MessageUTF8(char cmd, string context, string sender, string receiver, int garageID, int parkingRecordsID, string bookTime)
         {
             this.cmd = cmd;
             this.context = context;
@@ -34,13 +35,14 @@ namespace parkMonitor.entity
             this.receiver = receiver;
             this.garageID = garageID;
             this.parkingRecordsID = parkingRecordsID;
+            this.bookTime = bookTime;
         }
 
         public object Clone()
         {
             if (this == null)
                 return null;
-            MessageUTF8 webMsg = new MessageUTF8(this.cmd, this.context, this.sender, this.receiver, this.garageID, this.parkingRecordsID);
+            MessageUTF8 webMsg = new MessageUTF8(this.cmd, this.context, this.sender, this.receiver, this.garageID, this.parkingRecordsID, this.bookTime);
             return webMsg;
         }
     }

+ 40 - 40
parkMonitor/entity/EntityForCore.cs

@@ -66,23 +66,23 @@ namespace parkMonitor.entity
             Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "数据库初始配置");
             DBConnection.Init();
             //远端连接测试
-            using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
-            //using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
-            {
-                Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "远端数据库连接测试");
-                Operation.TryOpen(conn);
-                initState = conn.Ping();
-                Operation.DBClose(conn, null, null);
-            }
-            //本地连接测试
-            using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
-            //using (MySqlConnection conn = new MySqlConnection(DBConnection.localConf))
-            {
-                Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "本地数据库连接测试");
-                Operation.TryOpen(conn);
-                initState = initState && conn.Ping();
-                Operation.DBClose(conn, null, null);
-            }
+            //using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
+            ////using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
+            //{
+            //    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "远端数据库连接测试");
+            //    Operation.TryOpen(conn);
+            //    initState = conn.Ping();
+            //    Operation.DBClose(conn, null, null);
+            //}
+            ////本地连接测试
+            //using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
+            ////using (MySqlConnection conn = new MySqlConnection(DBConnection.localConf))
+            //{
+            //    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "本地数据库连接测试");
+            //    Operation.TryOpen(conn);
+            //    initState = initState && conn.Ping();
+            //    Operation.DBClose(conn, null, null);
+            //}
             //车位管理初始化
             Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "初始化车位");
             ParkingSpaceManager.ins = new ParkingSpaceManager();
@@ -108,29 +108,29 @@ namespace parkMonitor.entity
             Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "数据库初始配置");
             DBConnection.Init();
             //远端连接测试
-            if (DBmode == 0 || DBmode == 1)
-            {
-                using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
-                //using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
-                {
-                    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "远端数据库连接测试");
-                    Operation.TryOpen(conn);
-                    initState = conn.Ping();
-                    DBConnectionPool.getPool(DBConnection.remoteConf).ConnectionClose(conn);
-                }
-            }
-            //本地连接测试
-            if (DBmode == 0 || DBmode == 1)
-            {
-                using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
-                //using (MySqlConnection conn = new MySqlConnection(DBConnection.localConf))
-                {
-                    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "本地数据库连接测试");
-                    Operation.TryOpen(conn);
-                    initState = initState && conn.Ping();
-                    Operation.DBClose(conn, null, null);
-                }
-            }
+            //if (DBmode == 0 || DBmode == 1)
+            //{
+            //    using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
+            //    //using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
+            //    {
+            //        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "远端数据库连接测试");
+            //        Operation.TryOpen(conn);
+            //        initState = conn.Ping();
+            //        DBConnectionPool.getPool(DBConnection.remoteConf).ConnectionClose(conn);
+            //    }
+            //}
+            ////本地连接测试
+            //if (DBmode == 0 || DBmode == 1)
+            //{
+            //    using (MySqlConnection conn = DBConnectionPool.getPool(DBConnection.remoteConf).getConnection())
+            //    //using (MySqlConnection conn = new MySqlConnection(DBConnection.localConf))
+            //    {
+            //        Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "本地数据库连接测试");
+            //        Operation.TryOpen(conn);
+            //        initState = initState && conn.Ping();
+            //        Operation.DBClose(conn, null, null);
+            //    }
+            //}
             //车位管理初始化
             Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "初始化车位");
             ParkingSpaceManager.ins = new ParkingSpaceManager();

+ 1 - 0
parkMonitor/entity/EquipmentSimpleFactory.cs

@@ -57,6 +57,7 @@ namespace parkMonitor.entity
 			try {
 				//反射创建类
 				Type t = Type.GetType(className);
+                if (t == null) { return null; }
 				object instance = Activator.CreateInstance(t);
 				equipments = instance as IEquipments;
 

+ 22 - 0
parkMonitor/parkMonitor.csproj

@@ -14,6 +14,21 @@
     <WarningLevel>4</WarningLevel>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
     <TargetFrameworkProfile />
+    <PublishUrl>publish\</PublishUrl>
+    <Install>true</Install>
+    <InstallFrom>Disk</InstallFrom>
+    <UpdateEnabled>false</UpdateEnabled>
+    <UpdateMode>Foreground</UpdateMode>
+    <UpdateInterval>7</UpdateInterval>
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+    <UpdatePeriodically>false</UpdatePeriodically>
+    <UpdateRequired>false</UpdateRequired>
+    <MapFileExtensions>true</MapFileExtensions>
+    <ApplicationRevision>0</ApplicationRevision>
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+    <IsWebBootstrapper>false</IsWebBootstrapper>
+    <UseApplicationTrust>false</UseApplicationTrust>
+    <BootstrapperEnabled>true</BootstrapperEnabled>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -635,6 +650,13 @@
     <Content Include="sdk\log4net\log4net.dll" />
     <Resource Include="sdk\log4net\log4net.xml" />
   </ItemGroup>
+  <ItemGroup>
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
+      <Install>false</Install>
+    </BootstrapperPackage>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
     <PostBuildEvent>xcopy /s /e /d /y "$(ProjectDir)sdk\VZ_Sdk" "$(ProjectDir)$(OutDir)"</PostBuildEvent>

BIN
parkMonitor/resource/inlineRes/plcAddr.csv


+ 5 - 8
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -383,7 +383,6 @@ namespace parkMonitor.server.CoreThread
         /// <returns></returns>
         private Parking_Space WaitForParkingSpaceResource(Command queueCmd, out int count)
         {
-            string connectionStr = null;
             //中心点
             cEntrance.parkingEntX = parkingEntX;
             cEntrance.parkingEntY = parkingEntY;
@@ -396,11 +395,11 @@ namespace parkMonitor.server.CoreThread
             {
                 if (!queueCmd.manual)
                 {
-                    ppp = ParkingSpaceManager.ins.MallocParkingSpace(cEntrance, DBConnection.remoteConf, queueCmd, out count);//自动 
+                    ppp = ParkingSpaceManager.ins.MallocParkingSpace(cEntrance, queueCmd, false, out count);//自动 
                 }
                 else
                 {
-                    ppp = ParkingSpaceManager.ins.MallocParkingSpace(cEntrance, DBConnection.localConf, queueCmd, out count);//手动
+                    ppp = ParkingSpaceManager.ins.MallocParkingSpace(cEntrance, queueCmd, false, out count);//手动
                 }
                 if (ppp != null)
                 {
@@ -670,7 +669,7 @@ namespace parkMonitor.server.CoreThread
             {
                 bool displayed = false;
                 //等待获取缓冲位资源
-                
+
 
                 //获取车位资源
                 ppp = WaitForParkingSpaceResource(queueCmd, out freeSpaceCount);
@@ -897,7 +896,7 @@ namespace parkMonitor.server.CoreThread
                                 }
                             }
                         }
-                        catch(Exception e)
+                        catch (Exception e)
                         {
                             Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, e.StackTrace);//数据库操作失败异常待处理
                         }
@@ -999,7 +998,6 @@ namespace parkMonitor.server.CoreThread
             //UILogServer.ins.info("取车流程:" + queueCmd.LicenseNum + "开始");
             Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "取车流程:" + queueCmd.LicenseNum + "开始");
             string connectionStr = null;            //数据库连接字符串
-            PLCMessage PLCMsg = null;          //PLC信息
             Vehicle vehiclelist = null;                 //待取车辆信息
             ControlMessage cm = null;
             Parking_Space ps = null;                 //车位信息
@@ -1144,7 +1142,6 @@ namespace parkMonitor.server.CoreThread
                             //using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
                             {
                                 Operation.TryOpen(conn);
-                                bool DBStoreStatus = false;       //判断数据库事务操作是否正常 
                                 int temp;
                                 List<string> strs = new List<string>();
                                 //string updateParkingSpaceStateSql = "update parkingspace set parkingSpaceState = 0 where parkingSpaceID = '" + ps.parkingSpaceID + "'";
@@ -1166,7 +1163,7 @@ namespace parkMonitor.server.CoreThread
                                 }
                             }
                         }
-                        catch(Exception e)
+                        catch (Exception e)
                         {
                             Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, e.StackTrace);//数据库操作失败异常待处理
                         }

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

@@ -13,7 +13,6 @@ using parkMonitor.tools;
 using parkMonitor.DataBase;
 using MySql.Data.MySqlClient;
 using parkMonitor.server.CoreThread;
-using System.Threading;
 
 namespace parkMonitor.server.CoreThread
 {
@@ -50,14 +49,16 @@ namespace parkMonitor.server.CoreThread
 
         public void Start()
         {
-
+            //创建所有实例
             for (int i = 0; i < equipNames.Length; ++i)
             {
                 IEquipments equip = EquipmentSimpleFactory.ins.CreateEquipment(equipNames[i]);
-                if (equip != null)
-                {
-                    equip.Start();
-                }
+            }
+            //启动所有实例
+            for (int i = 0; i < equipNames.Length; ++i)
+            {
+                IEquipments equip = EquipmentSimpleFactory.ins.FindEquipment(equipNames[i]);
+                equip.Start();
             }
             PLC = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
             queuingThread = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Queue);
@@ -236,7 +237,6 @@ namespace parkMonitor.server.CoreThread
                     {
 
                         Operation.TryOpen(conn);
-                        bool DBStoreStatus = false;                       //判断数据库事务操作是否正常
                         int temp;
                         List<string> strs = new List<string>();
                         string updateParkingSpaceSql = "";

+ 71 - 6
parkMonitor/server/CoreThread/QueuingThread.cs

@@ -20,6 +20,10 @@ namespace parkMonitor.server.CoreThread
     /// </summary>
     public class QueuingThread : IEquipments
     {
+        /// <summary>
+        /// 预约停车队列
+        /// </summary>
+        Queue<Command> BookParkingQueue = new Queue<Command>();
         /// <summary>
         /// 号牌队列,放入来自于号牌机的号牌。与当前指令队列中指令匹配不上的号牌将被放入该队列
         /// </summary>
@@ -40,7 +44,7 @@ namespace parkMonitor.server.CoreThread
         /// 可执行阻塞队列,放入来自于取指或合法停指的经过调度的停取车指令。
         /// </summary>
         BlockingQueue ExecutableCmdQueue = new BlockingQueue();
-        int fetchStoreRatio, licenseTime, userTime;
+        int fetchStoreRatio, licenseTime, userTime, bookTime;
         bool isClosing = false;
         IEquipments webHandle = null;
         IEquipments numMachineHandle = null;
@@ -65,6 +69,7 @@ namespace parkMonitor.server.CoreThread
                 fetchStoreRatio = Int32.Parse(ConfigurationManager.AppSettings.Get("fetch_store_ratio"));
                 licenseTime = Int32.Parse(ConfigurationManager.AppSettings.Get("licenseTime"));
                 userTime = Int32.Parse(ConfigurationManager.AppSettings.Get("userTime"));
+                bookTime = Int32.Parse(ConfigurationManager.AppSettings.Get("bookTime"));
             }
             catch (Exception) { fetchStoreRatio = 3; UILogServer.ins.error("未找到停取车比例与计时参数"); Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "未找到停取车比例与计时参数"); }
         }
@@ -84,7 +89,7 @@ namespace parkMonitor.server.CoreThread
                     {
                         webMsg = (MessageUTF8)(((MessageUTF8)webHandle.GetMessage()).Clone());
                     }
-                    catch (Exception) { UILogServer.ins.error("用户指令异常"); Log.WriteLog(LogType.NOT_DATABASE, "用户指令异常"); }
+                    catch (Exception) { UILogServer.ins.error("用户指令异常"); Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "用户指令异常"); }
                 }
                 //get useful data from webMsg and assign it to output data structure
                 if (webMsg != null)
@@ -95,7 +100,19 @@ namespace parkMonitor.server.CoreThread
                     cmd.userID = webMsg.sender;
                     cmd.garageID = webMsg.garageID;
                     cmd.parkingRecordsID = webMsg.parkingRecordsID;
-                    cmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                    if (cmd.commandType == 'p' && webMsg.bookTime != null)
+                    {
+                        DateTime dt = new DateTime();
+                        if (webMsg.bookTime == "" || DateTime.TryParse(webMsg.bookTime, out dt))
+                        {
+                            cmd.TimeRecord = webMsg.bookTime;
+                        }
+                        else { Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "web发送预约时间异常,指令丢弃"); return; }
+                    }
+                    else
+                    {
+                        cmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                    }
                     webMsg = null;
                 }
                 //input user command
@@ -117,6 +134,28 @@ namespace parkMonitor.server.CoreThread
                         UILogServer.ins.info("收到web停车指令:" + cmd.LicenseNum);
                         Log.WriteLog(LogType.NOT_DATABASE, LogFile.INFO, "收到web停车指令:" + cmd.LicenseNum);
                     }
+                    else if (cmd.commandType.Equals('p'))
+                    {
+                        if (cmd.TimeRecord == "")
+                        {
+                            //取消预约
+                            UILogServer.ins.info("收到web预约停车取消指令:" + cmd.LicenseNum);
+                            Log.WriteLog(LogType.NOT_DATABASE, LogFile.INFO, "收到web预约停车取消指令:" + cmd.LicenseNum);
+                            ParkingSpaceManager.ins.CancleBooking(cmd.LicenseNum);
+                        }
+                        else
+                        {
+                            //正常预约
+                            UILogServer.ins.info("收到web预约停车指令:" + cmd.LicenseNum);
+                            Log.WriteLog(LogType.NOT_DATABASE, LogFile.INFO, "收到web预约停车指令:" + cmd.LicenseNum);
+                            int count = 0;
+                            if (!BookParkingQueue.Contains(cmd))
+                            {
+                                ParkingSpaceManager.ins.MallocParkingSpace(new CEntrance(EntityForCore.ins.parkingEntX, EntityForCore.ins.parkingEntY, EntityForCore.ins.parkingEntZ), cmd, true, out count);
+                                BookParkingQueue.Enqueue(cmd);
+                            }
+                        }
+                    }
                     else
                     {
                         Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "从web收到无法识别的用户指令");
@@ -180,6 +219,10 @@ namespace parkMonitor.server.CoreThread
                 {
                     NumTimeOut();
                 }
+                lock (BookParkingQueue)
+                {
+                    BookParkingTimeOut();
+                }
                 Thread.Sleep(500);
             }
         }
@@ -194,6 +237,27 @@ namespace parkMonitor.server.CoreThread
             return (node != null && node.ip != null && node.ip != "" && node.ip != "used") ? true : false;
         }
 
+        private void BookParkingTimeOut()
+        {
+            for (int i = 0; i < BookParkingQueue.Count; i++)
+            {
+                Command cmd = BookParkingQueue.Dequeue();
+                if (cmd != null)
+                {
+                    TimeSpan ts = DateTime.Now - DateTime.Parse(cmd.TimeRecord);
+                    if (ts.Minutes >= bookTime)
+                    {
+                        //超时则释放车位,丢出指令
+                        ParkingSpaceManager.ins.CancleBooking(cmd.LicenseNum);
+                    }
+                    else
+                    {
+                        BookParkingQueue.Enqueue(cmd);
+                    }
+                }
+            }
+        }
+
         /// <summary>
         /// 停车指令超时处理
         /// </summary>
@@ -349,10 +413,11 @@ namespace parkMonitor.server.CoreThread
                 while (FetchCmdQueue.Count != 0 && fetch-- > 0)
                 {
                     cmd = FetchCmdQueue.Dequeue();
-                    if ((cmd.manual && Operation.malfunctionLocal) ||(!cmd.manual && Operation.malfunctionRemote))
+                    if ((cmd.manual && Operation.malfunctionLocal) || (!cmd.manual && Operation.malfunctionRemote))
                     {
                         FetchCmdQueue.Enqueue(cmd);
-                    }else
+                    }
+                    else
                     {
                         UILogServer.ins.info("任务:取出号牌为 " + cmd.LicenseNum + " 的车辆,开始排队");
                         Log.WriteLog(LogType.NOT_DATABASE, "取车命令:" + cmd.LicenseNum + "已进入可执行队列");
@@ -463,7 +528,7 @@ namespace parkMonitor.server.CoreThread
                         else
                         {
                             Log.WriteLog(LogType.NOT_DATABASE, LogFile.INFO, "本地数据库异常,暂停接收手动指令" + command.LicenseNum);
-                            UILogServer.ins.error("本地数据库异常,暂停接收关于" + command.LicenseNum+"的手动指令");
+                            UILogServer.ins.error("本地数据库异常,暂停接收关于" + command.LicenseNum + "的手动指令");
                         }
                     }
                 }

+ 66 - 7
parkMonitor/server/CoreThread/SpaceManager.cs

@@ -6,7 +6,6 @@ using System.Threading.Tasks;
 using parkMonitor.DataBase;
 using System.Configuration;
 using parkMonitor.entity;
-using System.Configuration;
 using parkMonitor.LOG;
 using parkMonitor.server.uiLogServer;
 using parkMonitor.controlPanel;
@@ -69,11 +68,11 @@ namespace parkMonitor.server.CoreThread
         /// 最短路径分配,根据车位位置及状态分配目标车位,返回Parking Space的ID
         /// </summary>
         /// <param name="pt_Ent"></param>
-        /// <param name="connectionStr"></param>
+        /// <param name="booking">进行预约,提前分配车位</param>
         /// <param name="queueCmd"></param>
         /// <param name="count"></param>
         /// <returns></returns>
-        public Parking_Space MallocParkingSpace(CEntrance pt_Ent, string connectionStr, Command queueCmd, out int count)
+        public Parking_Space MallocParkingSpace(CEntrance pt_Ent, Command queueCmd, bool booking, out int count)
         {
             count = 0;
             if (ins != null)
@@ -86,8 +85,7 @@ namespace parkMonitor.server.CoreThread
                         Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "车辆表缓存或车位权重初始化异常");
                         return null;
                     }
-
-                    //获取空闲车位
+                    //获取空闲车位和判断是否已预约车位
                     if (lps != null)
                     {
                         lps.Clear();
@@ -97,12 +95,23 @@ namespace parkMonitor.server.CoreThread
                         lps = new Dictionary<int, Parking_Space>();
                     }
                     Dictionary<int, Parking_Space>.Enumerator enumer = parkingSpaceStatusMap.GetEnumerator();
+                    Parking_Space temp = null;
                     while (enumer.MoveNext())
                     {
                         if (enumer.Current.Value.parkingSpaceState == 0)
                         {
                             lps.Add(enumer.Current.Key, enumer.Current.Value);
                         }
+                        else if (enumer.Current.Value.parkingSpaceState == 2 && enumer.Current.Value.licence == queueCmd.LicenseNum)
+                        {
+                            temp = (Parking_Space)(enumer.Current.Value.Clone());
+                        }
+                    }
+                    if (temp != null && !booking)
+                    {
+                        //分配已预约的车位后将该车位置为占用
+                        parkingSpaceStatusMap[temp.parkingSpaceID].parkingSpaceState = 1;
+                        return temp;
                     }
                     //无空闲车位则退出
                     if (lps.Count == 0)
@@ -126,8 +135,16 @@ namespace parkMonitor.server.CoreThread
                         }
                     }
                     count = lps.Count - 1;
-                    //分配后将该车位置为占用
-                    parkingSpaceStatusMap[rps.parkingSpaceID].parkingSpaceState = 1;
+                    //分配后将该车位置为占用或已预约
+                    if (!booking)
+                    {
+                        parkingSpaceStatusMap[rps.parkingSpaceID].parkingSpaceState = 1;
+                    }
+                    else
+                    {
+                        parkingSpaceStatusMap[rps.parkingSpaceID].parkingSpaceState = 2;
+                        parkingSpaceStatusMap[rps.parkingSpaceID].licence = queueCmd.LicenseNum;
+                    }
                     return rps;
                 }
             }
@@ -145,6 +162,11 @@ namespace parkMonitor.server.CoreThread
                 if (parkingSpaceStatusMap[parkingSpaceID].parkingSpaceState != status)
                 {
                     parkingSpaceStatusMap[parkingSpaceID].parkingSpaceState = status;
+                    //清空该车位号牌
+                    if (status == 0)
+                    {
+                        parkingSpaceStatusMap[parkingSpaceID].licence = "";
+                    }
                     return true;
                 }
                 else { return false; }
@@ -187,6 +209,30 @@ namespace parkMonitor.server.CoreThread
             }
             return count;
         }
+        /// <summary>
+        /// 释放已预约占用的车位
+        /// </summary>
+        /// <param name="license"></param>
+        /// <returns></returns>
+        public bool CancleBooking(string license)
+        {
+            Dictionary<int, Parking_Space>.Enumerator enumer = parkingSpaceStatusMap.GetEnumerator();
+            Parking_Space temp = null;
+            while (enumer.MoveNext())
+            {
+                if (enumer.Current.Value.parkingSpaceState == 2 && enumer.Current.Value.licence == license)
+                {
+                    temp = (Parking_Space)(enumer.Current.Value.Clone());
+                }
+            }
+            if (temp != null)
+            {
+                parkingSpaceStatusMap[temp.parkingSpaceID].parkingSpaceState = 0;
+                parkingSpaceStatusMap[temp.parkingSpaceID].licence = "";
+                return true;
+            }
+            else { return false; }
+        }
     }
 
     public class CEntrance
@@ -194,6 +240,16 @@ namespace parkMonitor.server.CoreThread
         public int parkingEntX { get; set; }
         public int parkingEntY { get; set; }
         public int parkingEntZ { get; set; }
+        public CEntrance(int entX, int entY, int entZ)
+        {
+            parkingEntX = entX;
+            parkingEntY = entY;
+            parkingEntZ = entZ;
+        }
+        public CEntrance() : this(0,0,0)
+        {
+
+        }
     }
 
     /// <summary>
@@ -210,7 +266,9 @@ namespace parkMonitor.server.CoreThread
         public int parkingSpaceX { get; set; }
         public int parkingSpaceY { get; set; }
         public int parkingSpaceZ { get; set; }
+        //  0.空闲    1.占用    2.预约
         public int parkingSpaceState { get; set; }
+        public string licence { get; set; }
         public object Clone()
         {
             Parking_Space ps_new = new Parking_Space();
@@ -220,6 +278,7 @@ namespace parkMonitor.server.CoreThread
             ps_new.parkingSpaceX = parkingSpaceX;
             ps_new.parkingSpaceY = parkingSpaceY;
             ps_new.parkingSpaceZ = parkingSpaceZ;
+            ps_new.licence = licence;
             return ps_new;
         }
     }

+ 41 - 38
parkMonitor/server/NumMachine/NumMachine.cs

@@ -57,7 +57,6 @@ namespace parkMonitor.server
 
         private static NumberMachineMessage nmMsg = new NumberMachineMessage();
         private static VzClientSDK.VZLPRC_FIND_DEVICE_CALLBACK_EX find_DeviceCB = null;
-        private static VzClientSDK.VZLPRC_PLATE_INFO_CALLBACK m_PlateResultCB = null;
         private const int MSG_PLATE_INFO = 0x901;
         private const int MSG_DEVICE_INFO = 0x902;
         /// <summary>
@@ -82,10 +81,12 @@ namespace parkMonitor.server
             hwndMain = this.Handle;
             //m_sAppPath = System.IO.Directory.GetCurrentDirectory();
         }
+
         /// <summary>
         /// 定义时钟委托
         /// </summary>
         public delegate void SetDateTime();
+
         /// <summary>
         /// 实时采集
         /// </summary>
@@ -575,6 +576,7 @@ namespace parkMonitor.server
         /// </summary>
         public void Start()
         {
+
             Task.Factory.StartNew(() =>
             {
                 isClosing = false;
@@ -757,42 +759,43 @@ namespace parkMonitor.server
         }
     }
 
-    //public class NumMachineManager : IEquipments
-    //{
-    //    public static NumMachineLinker ins;
-    //    public AbstractMessage GetMessage()
-    //    {
-    //        return ins.GetMessage();
-    //    }
-
-    //    public void SetMessage(AbstractMessage message)
-    //    {
-    //        ins.SetMessage(message);
-    //    }
-
-    //    public void Start()
-    //    {
-    //        Task.Factory.StartNew(() =>
-    //        {
-    //            ins = new NumMachineLinker();
-    //            Task.Factory.StartNew(() => {
-    //                ins.Start();
-    //                //ins.Bounds = new Rectangle(0, 0, 0, 0);
-    //                //ins.ShowDialog();
-    //            });
-    //            //ins.WindowState = FormWindowState.Minimized;
-    //            ins.Hide();
-    //        });
-    //    }
-
-    //    public void Stop()
-    //    {
-    //        Task.Factory.StartNew(() =>
-    //        {
-    //            ins.Close();
-    //            ins.Stop();
-    //        });
-    //    }
-    //}
+    public class NumMachineManager : IEquipments
+    {
+        public static NumMachineLinker ins;
+        public AbstractMessage GetMessage()
+        {
+            return ins.GetMessage();
+        }
+
+        public void SetMessage(AbstractMessage message)
+        {
+            ins.SetMessage(message);
+        }
+
+        public void Start()
+        {
+            Task.Factory.StartNew(() =>
+            {
+                ins = new NumMachineLinker();
+                Task.Factory.StartNew(() =>
+                {
+                    ins.Start();
+                    //ins.Bounds = new Rectangle(0, 0, 0, 0);
+                    //ins.ShowDialog();
+                });
+                //ins.WindowState = FormWindowState.Minimized;
+                ins.Hide();
+            });
+        }
+
+        public void Stop()
+        {
+            Task.Factory.StartNew(() =>
+            {
+                ins.Close();
+                ins.Stop();
+            });
+        }
+    }
 
 }

+ 52 - 47
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -36,7 +36,7 @@ namespace parkMonitor.server
         /// 将写入PLC的字符串
         /// </summary>
         private string json2 = "";//写入的数据
-        private PLCMessage plcMsg = new PLCMessage();
+        private PLCMessage plcMsg;
         System.Timers.Timer timer;
         //parameteres for plc read function
         private int startAddr = 0;
@@ -129,6 +129,7 @@ namespace parkMonitor.server
 
                 laser_start_address = Int32.Parse(ConfigurationManager.AppSettings.Get("laser_start_address"));
 
+                plcMsg = new PLCMessage();
                 rpu1 = new RobotProcessUnit(1, parking_startRobot_address, parkingLaserCenterX_address, parkingSpaceID_address, park_completed_address, park_completed_acknowledge_address, fetching_startRobot_address, fetch_to_address, fetch_completed_address, fetch_completed_acknowledge_address, frontWheelbase_address, rearWheelbase_address);
 
                 //激光管理
@@ -136,11 +137,15 @@ namespace parkMonitor.server
                 {
                     try
                     {
-                        string laser = ConfigurationManager.AppSettings.Get("laser" + i + "_status_address");
-                        int laser_status_address = Int32.Parse(laser);
-                        LaserProcessUnit lpu = new LaserProcessUnit(i, laser_start_address, laser_status_address, LASER_RESCAN_COUNT, LASER_HEARTBEAT_PERIOD);
-                        laserMgmtList.Add(lpu);
-                        plcMsg.laserMsgList.Add(lpu.laserMsg);
+                        if (ConfigurationManager.AppSettings.AllKeys.Contains("laser" + i + "_status_address"))
+                        {
+                            string laser = ConfigurationManager.AppSettings.Get("laser" + i + "_status_address");
+                            int laser_status_address = Int32.Parse(laser);
+                            LaserProcessUnit lpu = new LaserProcessUnit(i, laser_start_address, laser_status_address, LASER_RESCAN_COUNT, LASER_HEARTBEAT_PERIOD);
+                            laserMgmtList.Add(lpu);
+                            plcMsg.laserMsgList.Add(lpu.laserMsg);
+                        }
+                        else { break; }
                     }
                     catch (Exception) { }
                 }
@@ -446,32 +451,35 @@ namespace parkMonitor.server
         /// </summary>
         private void LaserMonitor()
         {
-            try
+            while (!isClosing)
             {
-                if (plcMsg.originalPlcList != null)
+                try
                 {
-                    foreach (LaserProcessUnit lds in laserMgmtList)
+                    if (plcMsg.originalPlcList != null && plcMsg.originalPlcList.Count != 0)
                     {
-                        foreach (PLCNode p in plcMsg.originalPlcList)
+                        foreach (LaserProcessUnit lds in laserMgmtList)
                         {
-                            int addr = Int32.Parse(p.Address);
-                            int value = Int32.Parse(p.Value);
-                            lds.LaserStatusChecking(addr, value);
+                            foreach (PLCNode p in plcMsg.originalPlcList)
+                            {
+                                int addr = Int32.Parse(p.Address);
+                                int value = Int32.Parse(p.Value);
+                                lds.LaserStatusChecking(addr, value);
+                            }
+                            lds.LaserRecord(plcMsg.originalPlcList);
                         }
-                        lds.LaserRecord(plcMsg.originalPlcList);
                     }
+                    else
+                    {
+                        AsyncCmdServer.ins.send(AsyncCmdType.PLCReadException);
+                        return;
+                    }
+                    Thread.Sleep(200);
                 }
-                else
+                catch (Exception)
                 {
                     AsyncCmdServer.ins.send(AsyncCmdType.PLCReadException);
                     return;
                 }
-                Thread.Sleep(200);
-            }
-            catch (Exception)
-            {
-                AsyncCmdServer.ins.send(AsyncCmdType.PLCReadException);
-                return;
             }
         }
         /// <summary>
@@ -479,33 +487,36 @@ namespace parkMonitor.server
         /// </summary>
         private void UpdateLaserStatus()
         {
-            try
+            while (!isClosing)
             {
-                lock (plcMsg)
+                try
                 {
-                    if (plcMsg.originalPlcList != null)
+                    lock (plcMsg)
                     {
-                        foreach (LaserProcessUnit lds in laserMgmtList)
+                        if (plcMsg.originalPlcList != null && plcMsg.originalPlcList.Count != 0)
                         {
-                            foreach (PLCNode p in plcMsg.originalPlcList)
+                            foreach (LaserProcessUnit lds in laserMgmtList)
                             {
-                                int addr = Int32.Parse(p.Address);
-                                int value = Int32.Parse(p.Value);
-                                lds.UpdateLaserStatus(addr, value);
+                                foreach (PLCNode p in plcMsg.originalPlcList)
+                                {
+                                    int addr = Int32.Parse(p.Address);
+                                    int value = Int32.Parse(p.Value);
+                                    lds.UpdateLaserStatus(addr, value);
+                                }
                             }
                         }
-                    }
-                    else
-                    {
-                        AsyncCmdServer.ins.send(AsyncCmdType.PLCReadException);
-                        return;
+                        else
+                        {
+                            AsyncCmdServer.ins.send(AsyncCmdType.PLCReadException);
+                            return;
+                        }
                     }
                 }
-            }
-            catch (Exception)
-            {
-                AsyncCmdServer.ins.send(AsyncCmdType.PLCReadException);
-                return;
+                catch (Exception)
+                {
+                    AsyncCmdServer.ins.send(AsyncCmdType.PLCReadException);
+                    return;
+                }
             }
         }
         /// <summary>
@@ -726,17 +737,11 @@ namespace parkMonitor.server
 
             Task.Factory.StartNew(() =>
             {
-                while (!isClosing)
-                {
-                    LaserMonitor();
-                }
+                LaserMonitor();
             });
             Task.Factory.StartNew(() =>
             {
-                while (!isClosing)
-                {
-                    UpdateLaserStatus();
-                }
+                UpdateLaserStatus();
             });
 
             ////模拟plc与激光自动操作

+ 3 - 1
模拟输入数据.txt

@@ -4,4 +4,6 @@
 
 {"cmd":"s","context":"¾©PBS362","sender":"14","receiver":"","garageID":1}
 
-{"cmd":"s","context":"¾©PH3X00","sender":"14","receiver":"","garageID":1}
+{"cmd":"s","context":"¾©PH3X00","sender":"14","receiver":"","garageID":1}
+
+{"cmd":"s","garageID":1,"parkingRecordsID":0,"context":"¶õA00000","sender":"1","receiver":"119.96.127.100"}

+ 1 - 0
预约笔记.txt

@@ -0,0 +1 @@
+预约停车,提前分配车位到截止时间。在此之前匹配上则将该车位给予该车辆。