Explorar o código

车位缓冲位管理,界面手动初始化。初始化操作加入流程控制中

yc_t %!s(int64=7) %!d(string=hai) anos
pai
achega
e5f1f1c9b3

+ 1 - 0
parkMonitor/DataBase/DBOperation.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using MySql.Data.MySqlClient;
+using parkMonitor.server.CoreThread;
 
 namespace parkMonitor.DataBase
 {

+ 0 - 36
parkMonitor/DataBase/Parking_Space.cs

@@ -1,36 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace parkMonitor.DataBase
-{
-    /// <summary>
-    /// 车位表数据结构
-    /// </summary>
-    public class Parking_Space:ICloneable
-    {
-        public static Object spaceLock = new Object();
-        public static Object RecordLock = new Object();
-        public int parkingSpaceID { get; set; }
-        //public float parkingSpaceWeight { get; set; }
-        public int garageID { get; set; }
-        //public int parkingSpaceStatement { get; set; }
-        public int parkingSpaceX { get; set; }
-        public int parkingSpaceY { get; set; }
-        public int parkingSpaceZ { get; set; }
-        public int parkingSpaceState { get; set; }
-        public object Clone()
-        {
-            Parking_Space ps_new = new Parking_Space();
-            ps_new.parkingSpaceID = parkingSpaceID;
-            ps_new.garageID = garageID;
-            ps_new.parkingSpaceState = parkingSpaceState;
-            ps_new.parkingSpaceX = parkingSpaceX;
-            ps_new.parkingSpaceY = parkingSpaceY;
-            ps_new.parkingSpaceZ = parkingSpaceZ;
-            return ps_new;
-        }
-    }
-}

+ 4 - 1
parkMonitor/bll/MainBll.cs

@@ -31,7 +31,10 @@ namespace parkMonitor.bll
             var coreThread = EquipmentSimpleFactory.ins.CreateEquipment(EquipmentName.Core);
             if (coreThread != null)
             {
-                coreThread.Start();
+                Task.Factory.StartNew(() =>
+                {
+                    coreThread.Start();
+                });
                 Task.Factory.StartNew(() =>
                 {
                     (coreThread as ICoreThreadDoWorking).BeginWorking();

+ 97 - 0
parkMonitor/controlPanel/ControlPanel.Designer.cs

@@ -0,0 +1,97 @@
+namespace parkMonitor.controlPanel
+{
+    partial class ControlPanel
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.btn_buffer_confirm = new System.Windows.Forms.Button();
+            this.btn_refresh = new System.Windows.Forms.Button();
+            this.lb_confirmed = new System.Windows.Forms.Label();
+            this.flp_buffer = new System.Windows.Forms.FlowLayoutPanel();
+            this.SuspendLayout();
+            // 
+            // btn_buffer_confirm
+            // 
+            this.btn_buffer_confirm.Font = new System.Drawing.Font("宋体", 10F);
+            this.btn_buffer_confirm.Location = new System.Drawing.Point(74, 339);
+            this.btn_buffer_confirm.Name = "btn_buffer_confirm";
+            this.btn_buffer_confirm.Size = new System.Drawing.Size(57, 31);
+            this.btn_buffer_confirm.TabIndex = 1;
+            this.btn_buffer_confirm.Text = "确认";
+            this.btn_buffer_confirm.UseVisualStyleBackColor = true;
+            this.btn_buffer_confirm.Click += new System.EventHandler(this.btn_buffer_confirm_Click);
+            // 
+            // btn_refresh
+            // 
+            this.btn_refresh.Font = new System.Drawing.Font("宋体", 10F);
+            this.btn_refresh.Location = new System.Drawing.Point(11, 340);
+            this.btn_refresh.Name = "btn_refresh";
+            this.btn_refresh.Size = new System.Drawing.Size(57, 30);
+            this.btn_refresh.TabIndex = 2;
+            this.btn_refresh.Text = "刷新";
+            this.btn_refresh.UseVisualStyleBackColor = true;
+            this.btn_refresh.Click += new System.EventHandler(this.btn_refresh_Click);
+            // 
+            // lb_confirmed
+            // 
+            this.lb_confirmed.AutoSize = true;
+            this.lb_confirmed.Location = new System.Drawing.Point(15, 9);
+            this.lb_confirmed.Name = "lb_confirmed";
+            this.lb_confirmed.Size = new System.Drawing.Size(65, 12);
+            this.lb_confirmed.TabIndex = 4;
+            this.lb_confirmed.Text = "缓冲位确认";
+            // 
+            // flp_buffer
+            // 
+            this.flp_buffer.Location = new System.Drawing.Point(17, 34);
+            this.flp_buffer.Name = "flp_buffer";
+            this.flp_buffer.Size = new System.Drawing.Size(114, 299);
+            this.flp_buffer.TabIndex = 5;
+            // 
+            // ControlPanel
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(878, 386);
+            this.Controls.Add(this.flp_buffer);
+            this.Controls.Add(this.lb_confirmed);
+            this.Controls.Add(this.btn_refresh);
+            this.Controls.Add(this.btn_buffer_confirm);
+            this.Name = "ControlPanel";
+            this.Text = "ControlPanel";
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+        private System.Windows.Forms.Button btn_buffer_confirm;
+        private System.Windows.Forms.Button btn_refresh;
+        private System.Windows.Forms.Label lb_confirmed;
+        private System.Windows.Forms.FlowLayoutPanel flp_buffer;
+    }
+}

+ 92 - 0
parkMonitor/controlPanel/ControlPanel.cs

@@ -0,0 +1,92 @@
+using parkMonitor.server.CoreThread;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace parkMonitor.controlPanel
+{
+    public partial class ControlPanel : Form
+    {
+        public static ControlPanel ins = null;
+
+        Dictionary<int, CheckBox> IndexCbMap = null;
+
+        public ControlPanel()
+        {
+            InitializeComponent();
+            IndexCbMap = new Dictionary<int, CheckBox>();
+            //BufferList.Controls.Add(flp_buffer);
+            DisplayBufferStatus();
+            UpdateConfirmState();
+        }
+
+        public void UpdateConfirmState()
+        {
+            if (ParkingBufferManager.ins != null)
+            {
+                if (ParkingBufferManager.ins.checkedManually)
+                {
+                    lb_confirmed.Text = "缓冲位已手动确认";
+                }
+                else
+                {
+                    lb_confirmed.Text = "缓冲位未确认";
+                }
+            }
+        }
+
+        public void DisplayBufferStatus()
+        {
+            if (IndexCbMap == null) { IndexCbMap = new Dictionary<int, CheckBox>(); }
+            if (ParkingBufferManager.ins!=null) {
+                if (IndexCbMap.Count != ParkingBufferManager.ins.bufferCount)
+                {
+                    flp_buffer.Controls.Clear();
+                    for (int i = 0; i < ParkingBufferManager.ins.bufferCount; i++)
+                    {
+                        ParkingBuffer temp = ParkingBufferManager.ins.bufferList[i];
+                        CheckBox cb = new CheckBox();
+                        cb.Text = "第 " + temp.bufferID + " 号缓冲位";
+                        cb.Checked = temp.idle;
+                        IndexCbMap.Add(i, cb);
+                        flp_buffer.Controls.Add(cb);
+                    }
+                }
+                else
+                {
+                    for (int i = 0; i < ParkingBufferManager.ins.bufferCount; i++)
+                    {
+                        IndexCbMap[i].Checked = ParkingBufferManager.ins.bufferList[i].idle;
+                    }
+                }
+            }
+        }
+
+        private void btn_refresh_Click(object sender, EventArgs e)
+        {
+            DisplayBufferStatus();
+            UpdateConfirmState();
+        }
+
+        private void btn_buffer_confirm_Click(object sender, EventArgs e)
+        {
+            if (IndexCbMap == null) { IndexCbMap = new Dictionary<int, CheckBox>(); }
+            if (ParkingBufferManager.ins != null && IndexCbMap.Count == ParkingBufferManager.ins.bufferCount)
+            {
+                for (int i = 0; i < ParkingBufferManager.ins.bufferCount; i++)
+                {
+                    ParkingBufferManager.ins.bufferList[i].idle = IndexCbMap[i].Checked;
+                }
+            }
+            ParkingBufferManager.ins.checkedManually = true;
+            UpdateConfirmState();
+        }
+
+    }
+}

+ 120 - 0
parkMonitor/controlPanel/ControlPanel.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 0 - 41
parkMonitor/entity/AddressesForCore.cs

@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace parkMonitor.entity
-{
-    class AddressesForCore
-    {
-        public int equipmentStatus_address { set; get; }
-        public int park_completed_address { set; get; }
-        public int parkingEntX { set; get; }
-        public int parkingEntY { set; get; }
-        public int parkingEntZ { set; get; }
-        public int fetch_completed_address { set; get; }
-        public int wheelbase_status_address { get; set; }
-        public int parking_startRobot_address { get; set; }
-        public int fetching_startRobot_address { get; set; }
-        public int frontWheelbase_address { get; set; }
-        public int rearWheelbase_address { get; set; }
-        public static AddressesForCore ins = new AddressesForCore();
-        public AddressesForCore()
-        {
-            parking_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["parking_startRobot_address"]);
-            fetching_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetching_startRobot_address"]);
-            equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
-            park_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["park_completed_address"]);
-            parkingEntX = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntX"]);
-            parkingEntY = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntY"]);
-            parkingEntZ = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntZ"]);
-            //轮距
-            frontWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["frontWheelbase_address"]);
-            rearWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["rearWheelbase_address"]);
-            wheelbase_status_address = Convert.ToInt32(ConfigurationManager.AppSettings["wheelbase_status_address"]);
-            //取车完成
-            fetch_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetch_completed_address"]);
-        }
-    }
-}

+ 92 - 0
parkMonitor/entity/EntityForCore.cs

@@ -0,0 +1,92 @@
+using MySql.Data.MySqlClient;
+using parkMonitor.DataBase;
+using parkMonitor.LOG;
+using parkMonitor.server.CoreThread;
+using parkMonitor.server.uiLogServer;
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace parkMonitor.entity
+{
+    class EntityForCore
+    {
+        /// <summary>
+        /// 系统全局状态
+        /// </summary>
+        public bool globalStatus { get; set; }
+        public int equipmentStatus_address { set; get; }
+        public int park_completed_address { set; get; }
+        public int parkingEntX { set; get; }
+        public int parkingEntY { set; get; }
+        public int parkingEntZ { set; get; }
+        public int fetch_completed_address { set; get; }
+        public int wheelbase_status_address { get; set; }
+        public int parking_startRobot_address { get; set; }
+        public int fetching_startRobot_address { get; set; }
+        public int frontWheelbase_address { get; set; }
+        public int rearWheelbase_address { get; set; }
+        public static EntityForCore ins = new EntityForCore();
+        public EntityForCore()
+        {
+            try
+            {
+                parking_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["parking_startRobot_address"]);
+                fetching_startRobot_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetching_startRobot_address"]);
+                equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
+                park_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["park_completed_address"]);
+                parkingEntX = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntX"]);
+                parkingEntY = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntY"]);
+                parkingEntZ = Convert.ToInt32(ConfigurationManager.AppSettings["parkingEntZ"]);
+                //轮距
+                frontWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["frontWheelbase_address"]);
+                rearWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["rearWheelbase_address"]);
+                wheelbase_status_address = Convert.ToInt32(ConfigurationManager.AppSettings["wheelbase_status_address"]);
+                //取车完成
+                fetch_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetch_completed_address"]);
+            }
+            catch
+            {
+                UILogServer.ins.log("停取车基本配置异常");
+                Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "停取车基本配置异常");
+            }
+        }
+        /// <summary>
+        /// 数据库配置,车位与缓冲位初始化
+        /// </summary>
+        /// <returns></returns>
+        public bool Init()
+        {
+            bool initState = true;
+            //数据库连接参数初始化及连接测试
+            Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "数据库初始配置");
+            DBConnection.Init();
+            //远端连接测试
+            using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
+            {
+                Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "远端数据库连接测试");
+                Operation.TryOpen(conn);
+                initState = conn.Ping();
+            }
+            //本地连接测试
+            using (MySqlConnection conn = new MySqlConnection(DBConnection.localConf))
+            {
+                Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "本地数据库连接测试");
+                Operation.TryOpen(conn);
+                initState = initState && conn.Ping();
+            }
+            //车位管理初始化
+            Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "初始化车位");
+            ParkingSpaceManager.ins = new ParkingSpaceManager();
+            initState = initState && ParkingSpaceManager.ins.InitParkingSpace();
+            //缓冲位初始化
+            Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "初始化缓冲位");
+            ParkingBufferManager.ins = new ParkingBufferManager();
+            initState = initState && ParkingBufferManager.ins.InitParkingBuffers();
+            return initState;
+        }
+    }
+}

+ 11 - 3
parkMonitor/parkMonitor.csproj

@@ -87,10 +87,15 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="bll\MainBll.cs" />
+    <Compile Include="controlPanel\ControlPanel.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="controlPanel\ControlPanel.Designer.cs">
+      <DependentUpon>ControlPanel.cs</DependentUpon>
+    </Compile>
     <Compile Include="DataBase\DBConnection.cs" />
     <Compile Include="DataBase\DBOperation.cs" />
     <Compile Include="DataBase\IDBOperation.cs" />
-    <Compile Include="DataBase\Parking_Space.cs" />
     <Compile Include="DataBase\Vehicle.cs" />
     <Compile Include="DBLocation\DBLocation.cs" />
     <Compile Include="DBLocation\IDBLocation.cs" />
@@ -101,7 +106,7 @@
     <Compile Include="DB\Parking_Space.cs" />
     <Compile Include="DB\Vehicle.cs" />
     <Compile Include="entity\AbstractMessage.cs" />
-    <Compile Include="entity\AddressesForCore.cs" />
+    <Compile Include="entity\EntityForCore.cs" />
     <Compile Include="entity\Equipments.cs" />
     <Compile Include="entity\EquipmentSimpleFactory.cs" />
     <Compile Include="entity\ICoreThreadDoWorking.cs" />
@@ -128,7 +133,7 @@
     <Compile Include="sdk\superscene\TimeTest.cs" />
     <Compile Include="server\AsyncCmdServer.cs" />
     <Compile Include="server\CoreThread\AbstractCmd.cs" />
-    <Compile Include="server\CoreThread\AllotParkingSpace.cs" />
+    <Compile Include="server\CoreThread\SpaceManager.cs" />
     <Compile Include="server\CoreThread\AllotTest.cs" />
     <Compile Include="server\CoreThread\CoreThread.cs" />
     <Compile Include="server\CoreThread\CoreThreadTest.cs" />
@@ -466,6 +471,9 @@
       <DependentUpon>Settings.settings</DependentUpon>
       <DesignTimeSharedInput>True</DesignTimeSharedInput>
     </Compile>
+    <EmbeddedResource Include="controlPanel\ControlPanel.resx">
+      <DependentUpon>ControlPanel.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="manualParking\ManualParking.resx">
       <DependentUpon>ManualParking.cs</DependentUpon>
     </EmbeddedResource>

+ 49 - 57
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -89,19 +89,19 @@ namespace parkMonitor.server.CoreThread
 
         public AbstractCmd()
         {
-            parking_startRobot_address = AddressesForCore.ins.parking_startRobot_address;
-            fetching_startRobot_address = AddressesForCore.ins.fetching_startRobot_address;
-            equipmentStatus_address = AddressesForCore.ins.equipmentStatus_address;
-            park_completed_address = AddressesForCore.ins.park_completed_address;
-            parkingEntX = AddressesForCore.ins.parkingEntX;
-            parkingEntY = AddressesForCore.ins.parkingEntY;
-            parkingEntZ = AddressesForCore.ins.parkingEntZ;
+            parking_startRobot_address = EntityForCore.ins.parking_startRobot_address;
+            fetching_startRobot_address = EntityForCore.ins.fetching_startRobot_address;
+            equipmentStatus_address = EntityForCore.ins.equipmentStatus_address;
+            park_completed_address = EntityForCore.ins.park_completed_address;
+            parkingEntX = EntityForCore.ins.parkingEntX;
+            parkingEntY = EntityForCore.ins.parkingEntY;
+            parkingEntZ = EntityForCore.ins.parkingEntZ;
             //轮距
-            frontWheelbase_address = AddressesForCore.ins.frontWheelbase_address;
-            rearWheelbase_address = AddressesForCore.ins.rearWheelbase_address;
-            wheelbase_status_address = AddressesForCore.ins.wheelbase_status_address;
+            frontWheelbase_address = EntityForCore.ins.frontWheelbase_address;
+            rearWheelbase_address = EntityForCore.ins.rearWheelbase_address;
+            wheelbase_status_address = EntityForCore.ins.wheelbase_status_address;
             //取车完成
-            fetch_completed_address = AddressesForCore.ins.fetch_completed_address;
+            fetch_completed_address = EntityForCore.ins.fetch_completed_address;
             //获取PLC句柄
             PLC = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
             //获取队列句柄
@@ -162,7 +162,7 @@ namespace parkMonitor.server.CoreThread
                     {
                         Robot.robot1.occupied = true;
                         //UILogServer.ins.log("获得机械手资源");
-                        Log.WriteLog(LogType.NOTDATABASE,LogFile.LOG, "获得机械手资源");
+                        Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "获得机械手资源");
                         break;
                     }
                     mt.EndTiming();
@@ -177,7 +177,7 @@ namespace parkMonitor.server.CoreThread
                         {
                             mt.rolledBack = true;
                             UILogServer.ins.error("启动机械手资源超时,已启动回滚");
-                            Log.WriteLog(LogType.NOTDATABASE,LogFile.ERROR, "启动机械手资源超时,已启动回滚");
+                            Log.WriteLog(LogType.NOTDATABASE, LogFile.ERROR, "启动机械手资源超时,已启动回滚");
                             return false;
                         }
                         Thread.Sleep(100);
@@ -354,7 +354,7 @@ namespace parkMonitor.server.CoreThread
                 }
                 if (ppp != null)
                 {
-                    Log.WriteLog(LogType.NOTDATABASE,LogFile.LOG, "停车流程:" + queueCmd.LicenseNum + "已分配车位");
+                    Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "停车流程:" + queueCmd.LicenseNum + "已分配车位");
                     break;
                 }
                 Thread.Sleep(200);
@@ -370,7 +370,7 @@ namespace parkMonitor.server.CoreThread
                     {
                         mt.rolledBack = true;
                         UILogServer.ins.error(queueCmd.LicenseNum + "超时未获得车位,指令退回");
-                        Log.WriteLog(LogType.NOTDATABASE,LogFile.ERROR, queueCmd.LicenseNum + "超时未获得车位,指令退回");
+                        Log.WriteLog(LogType.NOTDATABASE, LogFile.ERROR, queueCmd.LicenseNum + "超时未获得车位,指令退回");
                         return null;
                     }
                     Thread.Sleep(100);
@@ -436,7 +436,7 @@ namespace parkMonitor.server.CoreThread
                                     if (disconnectionCount == 1)
                                     {
                                         UILogServer.ins.error("激光" + lm.id + "连接异常");
-                                        Log.WriteLog(LogType.NOTDATABASE,LogFile.ERROR, "激光" + lm.id + "连接异常");
+                                        Log.WriteLog(LogType.NOTDATABASE, LogFile.ERROR, "激光" + lm.id + "连接异常");
                                     }
                                     Thread.Sleep(10000);
                                 }
@@ -598,7 +598,6 @@ namespace parkMonitor.server.CoreThread
             cm.LicenseNum = queueCmd.LicenseNum;
             PLC.SetMessage(cm);
             Log.WriteLog(LogType.NOTDATABASE, "停车流程:车牌号为" + queueCmd.LicenseNum + "的车辆准备开启激光");
-            //UILogServer.ins.info("停车流程:车牌号为" + queueCmd.LicenseNum + "的车辆准备开启激光");
 
             //车位分配数据库操作加锁,直到启动机械手
             Parking_Space ppp = new Parking_Space();
@@ -682,7 +681,7 @@ namespace parkMonitor.server.CoreThread
                             bool DBStoreStatus = false;                       //判断数据库事务操作是否正常
                             int temp;
                             string updateParkingSpaceSql = "update parkingspace set parkingSpaceState = 1 where parkingSpaceID = '" + ppp.parkingSpaceID + "'";
-                            string updateFreeSpaceSql = "update garage set garageFreeSpace = '" + (freeSpaceCount - 1) + "' where garageID = '" + garageID + "'";
+                            string updateFreeSpaceSql = "update garage set garageFreeSpace = '" + freeSpaceCount+ "' where garageID = '" + garageID + "'";
                             List<string> strs = new List<string>();
                             strs.Add(updateParkingSpaceSql);
                             strs.Add(updateFreeSpaceSql);
@@ -748,6 +747,12 @@ namespace parkMonitor.server.CoreThread
             status = 2;
             cm.status = status;
             cm.RobotID = robotID;//启动对应机械手
+            ParkingBuffer pb = ParkingBufferManager.ins.MallocPakringBuffer(queueCmd.id);
+            if (pb == null)
+            {
+                Rollback(queueCmd, ppp.parkingSpaceID, true, true, lmToBeReleased);
+                return;
+            }
             //激光数据
             cm.centerX = Convert.ToString(dataReal.centerX);
             cm.centerY = Convert.ToString(dataReal.centerY);
@@ -757,7 +762,9 @@ namespace parkMonitor.server.CoreThread
             cm.height = Convert.ToString(dataReal.height);
             //分配的车位数据
             cm.parkingSpaceID = Convert.ToString(ppp.parkingSpaceID);
-            cm.parkingSpaceX = Convert.ToString(ppp.parkingSpaceX);
+            //!!!之前把停车位X坐标当做缓冲位ID,现修改为被管理的缓冲位ID,之后PLC地址需调整!!!
+            //cm.parkingSpaceX = Convert.ToString(ppp.parkingSpaceX);
+            cm.parkingSpaceX = Convert.ToString(pb.bufferID);
             cm.parkingSpaceY = Convert.ToString(ppp.parkingSpaceY);
             cm.parkingSpaceZ = Convert.ToString(ppp.parkingSpaceZ);
             PLC.SetMessage(cm);
@@ -788,7 +795,7 @@ namespace parkMonitor.server.CoreThread
 
             //停车流程结束,将相应车牌复位,从号牌队列中出队
             NumReset(queueCmd);
-            Log.WriteLog(LogType.NOTDATABASE,LogFile.LOG, "停车流程:" + queueCmd.LicenseNum + "停车完成,状态复位");
+            Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "停车流程:" + queueCmd.LicenseNum + "停车完成,状态复位");
             UILogServer.ins.info("停车流程:" + queueCmd.LicenseNum + "停车完成,状态复位");
             //释放机械手与激光
             if (lmToBeReleased != null)
@@ -798,7 +805,7 @@ namespace parkMonitor.server.CoreThread
             Robot.robot1.occupied = false;
             Robot.robot1.waitCount -= 1;
             //自动化测试用
-            ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
+            //ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
             //根据号牌查找车型
             //int vehicleTypeID = oper.getVehicleTypeID(numberPlate);
             //判断测量数据是否准确
@@ -820,7 +827,7 @@ namespace parkMonitor.server.CoreThread
                         //插入消息队列表
                         //oper.InsertToMessageQueue(connectionStr, userID, "停车成功", 1);
 
-                        //事务,写入停车记录
+                        //事务,写入停车记录, 更新车辆信息
                         int parkingRecordsID = 0;
                         try
                         {
@@ -833,18 +840,6 @@ namespace parkMonitor.server.CoreThread
                                     //数据库操作失败写日志
                                     Log.WriteLog(LogType.DATABASE, insertRecordSql);
                                 }
-                            }
-                        }
-                        catch
-                        {
-                            throw;//数据库操作失败异常待处理
-                        }
-                        //事务更新车辆信息
-                        try
-                        {
-                            using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
-                            {
-                                Operation.TryOpen(conn);
                                 string updateVehicleSql = "update vehicle set vehiclepParkState = 1,scanEntryTime = '" + queueCmd.TimeRecord + "',parkingRecordsID = '" + parkingRecordsID + "',parkingSpaceID = '" + ppp.parkingSpaceID + "',vehicleTypeConfirm = 1,frontwheelbase = '" + frontWheelbase + "',rearwheelbase = '" + rearWheelbase + "' where numberPlate = '" + queueCmd.LicenseNum + "'";
                                 int temp;
                                 if (!Operation.MyTransaction(conn, updateVehicleSql, out temp))
@@ -986,21 +981,22 @@ namespace parkMonitor.server.CoreThread
             frontwheelbase = vehiclelist.frontwheelbase;
             rearwheelbase = vehiclelist.rearwheelbase;
             //获取车位表中车辆具体的车位信息
-            if (queueCmd.manual)
-            {
-                connectionStr = DBConnection.localStr;
-                ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
-            }
-            else
-            {
-                connectionStr = DBConnection.remoteStr;
-                ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
-            }
-            if (ps == null)
+            //if (queueCmd.manual)
+            //{
+            //    connectionStr = DBConnection.localStr;
+            //    ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
+            //}
+            //else
+            //{
+            //    connectionStr = DBConnection.remoteStr;
+            //    ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
+            //}
+            if(ParkingSpaceManager.ins.parkingSpaceStatusMap.TryGetValue(parkingSpaceID, out ps) || ps == null)
             {
                 Rollback(queueCmd, parkingSpaceID, false, false, null);
                 return;
             }
+
             cm = new ControlMessage();
             //启动机械手
             int robotID = 0;
@@ -1047,17 +1043,17 @@ namespace parkMonitor.server.CoreThread
             //释放机械手
             Robot.robot1.occupied = false;
             Robot.robot1.waitCount -= 1;
-            //释放车位
-            if (ParkingSpaceManager.ins == null || !ParkingSpaceManager.ins.releaseParkingSpace(ps.parkingSpaceID))
+            //释放缓冲位与车位,缓冲位ID暂用车位X代替
+            if (ParkingSpaceManager.ins == null || !ParkingSpaceManager.ins.ReleaseParkingSpace(ps.parkingSpaceID) || ParkingBufferManager.ins == null || !ParkingBufferManager.ins.ReleaseParkingBuffer(ps.parkingSpaceX))
             {
-                Log.WriteLog(LogType.NOTDATABASE, LogFile.ERROR, "车位异常,请检查"); UILogServer.ins.error("车位异常,请检查");
+                Log.WriteLog(LogType.NOTDATABASE, LogFile.ERROR, "车位或缓冲位异常,请检查"); UILogServer.ins.error("车位或缓冲位异常,请检查");
             }
 
-            Log.WriteLog(LogType.NOTDATABASE,"取车流程:号牌:" + queueCmd.LicenseNum + "取车完成");
+            Log.WriteLog(LogType.NOTDATABASE, "取车流程:号牌:" + queueCmd.LicenseNum + "取车完成");
             UILogServer.ins.info("取车流程:号牌:" + queueCmd.LicenseNum + "取车完成");
 
             //自动化测试用
-            ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
+            //ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2, 1)));
 
             //数据库更新
             lock (Parking_Space.RecordLock)
@@ -1090,10 +1086,6 @@ namespace parkMonitor.server.CoreThread
                                 string updateFreeSpaceSql = "update garage set garageFreeSpace = '" + freeSpaceCount + "' where garageID = '" + garageID + "'";
                                 string updateVehicleStateSql = "update vehicle set vehiclepParkState = 0 where numberPlate = '" + queueCmd.LicenseNum + "'";
                                 string updateParkingRecordsSql = "update parkingrecords set parkingRecordsState = 6,realGetTime = '" + queueCmd.TimeRecord + "'where parkingRecordsID = '" + queueCmd.parkingRecordsID + "'";
-                                //strs.Add("update parkingspace set parkingSpaceState = 0 where parkingSpaceID = '" + ps.parkingSpaceID + "'");
-                                //strs.Add("update garage set garageFreeSpace = '" + freeSpaceCount + "' where garageID = '" + garageID + "'");
-                                //strs.Add("update vehicle set vehiclepParkState = 0 where numberPlate = '" + queueCmd.LicenseNum + "'");
-                                //strs.Add("update parkingrecords set parkingRecordsState = 6,realGetTime = '" + queueCmd.TimeRecord + "'where parkingRecordsID = '" + queueCmd.parkingRecordsID + "'");
                                 strs.Add(updateParkingSpaceStateSql);
                                 strs.Add(updateFreeSpaceSql);
                                 strs.Add(updateVehicleStateSql);
@@ -1103,9 +1095,9 @@ namespace parkMonitor.server.CoreThread
                                     Log.WriteLog(LogType.NOTDATABASE, "数据库操作出错,记录sql语句等待流程回滚");
                                     //写日志记录sql,以待之后处理
                                     Log.WriteLog(LogType.DATABASE, updateParkingSpaceStateSql);
-                                    Log.WriteLog(LogType.DATABASE,updateFreeSpaceSql);
-                                    Log.WriteLog(LogType.DATABASE,updateVehicleStateSql);
-                                    Log.WriteLog(LogType.DATABASE,updateParkingRecordsSql);
+                                    Log.WriteLog(LogType.DATABASE, updateFreeSpaceSql);
+                                    Log.WriteLog(LogType.DATABASE, updateVehicleStateSql);
+                                    Log.WriteLog(LogType.DATABASE, updateParkingRecordsSql);
                                 }
                             }
                         }

+ 49 - 52
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -18,10 +18,7 @@ namespace parkMonitor.server.CoreThread
     {
 
         int equipmentStatus_address;//设备总控状态地址
-        /// <summary>
-        /// 系统全局状态
-        /// </summary>
-        public static bool globalStatus;
+        bool initialized = false;
         /// <summary>
         /// 获取PLC句柄
         /// </summary>
@@ -42,7 +39,7 @@ namespace parkMonitor.server.CoreThread
         {
             try
             {
-                globalStatus = true;
+                EntityForCore.ins.globalStatus = true;
                 equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
             }
             catch (Exception) { }
@@ -62,14 +59,11 @@ namespace parkMonitor.server.CoreThread
             PLC = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
             queuingThread = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Queue);
             NumMachine = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.NumMachine);
-            //数据库连接参数初始化
-            DBConnection.Init();
-            //车位管理初始化
-            ParkingSpaceManager.ins = new ParkingSpaceManager();
-            globalStatus = globalStatus && ParkingSpaceManager.ins.InitParkingSpace();
-            //缓冲位初始化
-            ParkingBufferManager.ins = new ParkingBufferManager();
-            globalStatus = globalStatus && ParkingBufferManager.ins.InitParkingBuffers();
+            if (!(EntityForCore.ins.globalStatus = EntityForCore.ins.Init()))
+            {
+                UILogServer.ins.error("系统初始化异常,请检查配置");
+            }
+            initialized = true;
             //BeginWorking();
             //监听总状态改变消息
             //由监控线程发出
@@ -111,52 +105,55 @@ namespace parkMonitor.server.CoreThread
             Command queueCmd = null;
             while (!isClosing)
             {
-                if (queueCmd != null)
+                if (initialized && EntityForCore.ins.globalStatus)
                 {
-                    if (queueCmd.id / 6 == Robot.robot1.id && Robot.robot1.waitCount >= 2)
+                    if (queueCmd != null)
                     {
-                        Thread.Sleep(10000);
-                        continue;
+                        if (queueCmd.id / 6 == Robot.robot1.id && Robot.robot1.waitCount >= 2)
+                        {
+                            Thread.Sleep(10000);
+                            continue;
+                        }
+                        if (queueCmd.id / 6 == Robot.robot2.id && Robot.robot2.waitCount >= 2)
+                        {
+                            Thread.Sleep(10000);
+                            continue;
+                        }
                     }
-                    if (queueCmd.id / 6 == Robot.robot2.id && Robot.robot2.waitCount >= 2)
+                    //等待系统总状态
+                    Task getSysStatus = Task.Factory.StartNew(() =>
                     {
-                        Thread.Sleep(10000);
-                        continue;
-                    }
-                }
-                //等待系统总状态
-                Task getSysStatus = Task.Factory.StartNew(() =>
-                {
-                    GetTotalStatus();
-                });
-                //等待号牌资源
-                Task getCmd = Task.Factory.StartNew(() =>
-                {
-                    while (true)
+                        GetTotalStatus();
+                    });
+                    //等待号牌资源
+                    Task getCmd = Task.Factory.StartNew(() =>
                     {
-                        queueCmd = (Command)queuingThread.GetMessage();
-                        if (queueCmd != null)
+                        while (true)
                         {
-                            break;
+                            queueCmd = (Command)queuingThread.GetMessage();
+                            if (queueCmd != null)
+                            {
+                                break;
+                            }
                         }
-                    }
-                });
-                Task.WaitAll(getSysStatus, getCmd);
-                //Command queueCmd = (Command)func.EndInvoke(result);
-                Task.Factory.StartNew(() =>
-                {
-                    if (queueCmd.id == Robot.robot1.id)
+                    });
+                    Task.WaitAll(getSysStatus, getCmd);
+                    //Command queueCmd = (Command)func.EndInvoke(result);
+                    Task.Factory.StartNew(() =>
                     {
-                        Robot.robot1.waitCount += 1;
-                    }
-                    else if (queueCmd.id == Robot.robot2.id)
-                    {
-                        Robot.robot2.waitCount += 1;
-                    }
-                    SimpleCMDFactory simpleCMDFactory = new SimpleCMDFactory();
-                    AbstractCmd abstractCmd = simpleCMDFactory.createCmd(queueCmd);
-                    abstractCmd.executeCmd(queueCmd);
-                });
+                        if (queueCmd.id == Robot.robot1.id)
+                        {
+                            Robot.robot1.waitCount += 1;
+                        }
+                        else if (queueCmd.id == Robot.robot2.id)
+                        {
+                            Robot.robot2.waitCount += 1;
+                        }
+                        SimpleCMDFactory simpleCMDFactory = new SimpleCMDFactory();
+                        AbstractCmd abstractCmd = simpleCMDFactory.createCmd(queueCmd);
+                        abstractCmd.executeCmd(queueCmd);
+                    });
+                }
                 Thread.Sleep(100);
             }
 
@@ -211,7 +208,7 @@ namespace parkMonitor.server.CoreThread
                     normalStatus = Convert.ToInt32(PLCMsg.originalPlcList[equipmentStatus_address].Value);
                 }
                 //设备总控状态
-                if (normalStatus == 1)
+                if (normalStatus == 1 && EntityForCore.ins.globalStatus && ParkingBufferManager.ins.checkedManually)
                 {
                     UILogServer.ins.log("设备总状态正常");
                     Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "设备总状态正常");

+ 111 - 14
parkMonitor/server/CoreThread/AllotParkingSpace.cs

@@ -9,6 +9,7 @@ using parkMonitor.entity;
 using System.Configuration;
 using parkMonitor.LOG;
 using parkMonitor.server.uiLogServer;
+using parkMonitor.controlPanel;
 
 namespace parkMonitor.server.CoreThread
 {
@@ -119,7 +120,7 @@ namespace parkMonitor.server.CoreThread
                             rps = enumer2.Current.Value;
                         }
                     }
-                    count = lps.Count;
+                    count = lps.Count - 1;
                     //分配后将该车位置为占用
                     parkingSpaceStatusMap[rps.parkingSpaceID].parkingSpaceState = 1;
                     return rps;
@@ -132,9 +133,9 @@ namespace parkMonitor.server.CoreThread
         /// </summary>
         /// <param name="parkingSpaceID"></param>
         /// <returns></returns>
-        public bool releaseParkingSpace(int parkingSpaceID)
+        public bool ReleaseParkingSpace(int parkingSpaceID)
         {
-            if (checkIfSpaceExist(parkingSpaceID))
+            if (CheckIfSpaceExist(parkingSpaceID))
             {
                 parkingSpaceStatusMap[parkingSpaceID].parkingSpaceState = 0;
                 return true;
@@ -149,7 +150,7 @@ namespace parkMonitor.server.CoreThread
         /// </summary>
         /// <param name="parkingSpaceID"></param>
         /// <returns></returns>
-        public bool checkIfSpaceExist(int parkingSpaceID)
+        public bool CheckIfSpaceExist(int parkingSpaceID)
         {
             if (parkingSpaceStatusMap != null && parkingSpaceStatusMap.ContainsKey(parkingSpaceID))
             {
@@ -169,14 +170,42 @@ namespace parkMonitor.server.CoreThread
         public int parkingEntZ { get; set; }
     }
 
+    /// <summary>
+    /// 车位单元
+    /// </summary>
+    public class Parking_Space : ICloneable
+    {
+        public static Object spaceLock = new Object();
+        public static Object RecordLock = new Object();
+        public int parkingSpaceID { get; set; }
+        //public float parkingSpaceWeight { get; set; }
+        public int garageID { get; set; }
+        //public int parkingSpaceStatement { get; set; }
+        public int parkingSpaceX { get; set; }
+        public int parkingSpaceY { get; set; }
+        public int parkingSpaceZ { get; set; }
+        public int parkingSpaceState { get; set; }
+        public object Clone()
+        {
+            Parking_Space ps_new = new Parking_Space();
+            ps_new.parkingSpaceID = parkingSpaceID;
+            ps_new.garageID = garageID;
+            ps_new.parkingSpaceState = parkingSpaceState;
+            ps_new.parkingSpaceX = parkingSpaceX;
+            ps_new.parkingSpaceY = parkingSpaceY;
+            ps_new.parkingSpaceZ = parkingSpaceZ;
+            return ps_new;
+        }
+    }
+
     /// <summary>
     /// 缓冲位管理
     /// </summary>
     public class ParkingBufferManager
     {
-        public static ParkingBufferManager ins;
-        public static int bufferCount;
-        public static bool checkedManually;
+        public static ParkingBufferManager ins { get; set; }
+        public int bufferCount { get; set; }
+        public bool checkedManually { get; set; }
         public List<ParkingBuffer> bufferList = new List<ParkingBuffer>();
         public bool InitParkingBuffers()
         {
@@ -184,20 +213,83 @@ namespace parkMonitor.server.CoreThread
             try
             {
                 bufferCount = Int32.Parse(ConfigurationManager.AppSettings["bufferCount"]);
-                for(int i = 1; i <= bufferCount; i++)
+                for (int i = 1; i <= bufferCount; i++)
                 {
                     //初始完全占用
                     bufferList.Add(new ParkingBuffer(i));
                 }
+                UILogServer.ins.warn("请手动确认缓冲位状态");
+                Log.WriteLog(LogType.NOTDATABASE, LogFile.LOG, "初始化缓冲位成功");
                 return true;
             }
             catch { return false; }
         }
+        public ParkingBuffer MallocPakringBuffer(int numMachineID)
+        {
+            if (!checkedManually)
+                return null;
+            int min_dis_sq = 2500; //初始默认缓冲位距号牌ID 50 个单位
+            ParkingBuffer allocatedPB = null;
+            for (int i = 0; i < bufferCount; i++)
+            {
+                if (bufferList[i].idle)
+                {
+                    int diff_dis = bufferList[i].bufferID - numMachineID;
+                    if (min_dis_sq > diff_dis * diff_dis)
+                    {
+                        min_dis_sq = diff_dis * diff_dis;
+                        allocatedPB = (ParkingBuffer)bufferList[i].Clone();
+                    }
+                }
+            }
+            if (allocatedPB != null)
+            {
+                bufferList[allocatedPB.bufferID].idle = false;
+                return allocatedPB;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        /// <summary>
+        /// 暂时取车完成释放缓冲位
+        /// </summary>
+        /// <param name="parkingSpaceID"></param>
+        /// <returns></returns>
+        public bool ReleaseParkingBuffer(int bufferID)
+        {
+            if (CheckIfBufferExist(bufferID))
+            {
+                bufferList[bufferID - 1].idle = true;
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+        /// <summary>
+        /// 判断缓冲位是否存在
+        /// </summary>
+        /// <param name="parkingSpaceID"></param>
+        /// <returns></returns>
+        public bool CheckIfBufferExist(int bufferID)
+        {
+            if (bufferList != null && bufferList.Count >= bufferID)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
     }
     /// <summary>
     /// 缓冲位单元
     /// </summary>
-    public class ParkingBuffer
+    public class ParkingBuffer : ICloneable
     {
         /// <summary>
         /// 缓冲位ID
@@ -206,24 +298,29 @@ namespace parkMonitor.server.CoreThread
         /// <summary>
         /// 占用标记
         /// </summary>
-        public bool occupied;
+        public bool idle;
         /// <summary>
         /// 单参数构造函数
         /// </summary>
         /// <param name="bufferID"></param>
-        public ParkingBuffer(int bufferID) : this(bufferID, true)
+        public ParkingBuffer(int bufferID) : this(bufferID, false)
         {
         }
         /// <summary>
         /// 双参数构造函数
         /// </summary>
         /// <param name="bufferID"></param>
-        /// <param name="occupied"></param>
-        public ParkingBuffer(int bufferID, bool occupied)
+        /// <param name="Idle"></param>
+        public ParkingBuffer(int bufferID, bool Idle)
         {
             this.bufferID = bufferID;
-            this.occupied = occupied;
+            this.idle = Idle;
         }
 
+        public object Clone()
+        {
+            ParkingBuffer pbc = new ParkingBuffer(this.bufferID, this.idle);
+            return pbc;
+        }
     }
 }

+ 1 - 1
parkMonitor/server/NumMachine/NumMachineSimul.cs

@@ -179,7 +179,7 @@ namespace parkMonitor.server
             });
             Task.Factory.StartNew(() =>
             {
-                ManualParkingSimul.ins = new ManualParkingSimul();
+                //ManualParkingSimul.ins = new ManualParkingSimul();
             });
            
         }

+ 2 - 1
parkMonitor/view/menuBox/MenuBox.xaml

@@ -41,7 +41,8 @@
 						<!--<util:DevMenuListBox Margin="0,0,0,0" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="{lng:LngBind sensor}" ItemsSource="{Binding DevMenuItems.Sensor}" Source="/parkMonitor;component/resource/image/map/Sensor.png" x:Name="lstSensor" SelectionChanged="lstSensor_SelectionChanged"/>-->
 						<util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="号牌机" Source="/parkMonitor;component/resource/image/map/numMachine.png" x:Name="muRunNumMachine" MouseLeftButtonUp="muRunNumMachine_MouseLeftButtonUp"/>
                         <util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="回滚已关闭" Source="/parkMonitor;component/resource/image/map/circulate2.png" x:Name="muRunRestartProcess" MouseLeftButtonUp="muRunRestartProcess_MouseLeftButtonUp"/>
-                        <util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="启用远端DB" Source="/parkMonitor;component/resource/image/map/monitor.png" x:Name="muHandleCommandFromWeb" MouseLeftButtonUp="muHandleCommandFromWeb_MouseLeftButtonUp" IsEnabled="False"/>
+                        <util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="启用远端DB" Source="/parkMonitor;component/resource/image/map/monitor.png" x:Name="muHandleCommandFromWeb" MouseLeftButtonUp="muHandleCommandFromWeb_MouseLeftButtonUp"/>
+                        <util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="控制面板" Source="/parkMonitor;component/resource/image/map/monitor.png" x:Name="muControlPanel" MouseLeftButtonUp="muControlPanel_MouseLeftButtonUp"/>
                         <!--<util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="激光雷达" Source="/parkMonitor;component/resource/image/map/laser.png" x:Name="muRunLaser" MouseLeftButtonUp="muRunLaser_MouseLeftButtonUp"/>-->
 						<!--<util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="转运系统" Source="/parkMonitor;component/resource/image/map/tray.png" x:Name="muRunTray" MouseLeftButtonUp="muRunTray_MouseLeftButtonUp"/>-->
 						<!--<util:ImageMenuItem Margin="0,0,5,0" MouseOverColor="#808080" MiniSource="/parkMonitor;component/resource/image/menu/start.png" Content="机械手" Source="/parkMonitor;component/resource/image/map/robot.png" x:Name="muRunRobot" MouseLeftButtonUp="muRunRobot_MouseLeftButtonUp"/>-->

+ 7 - 1
parkMonitor/view/menuBox/MenuBox.xaml.cs

@@ -1,4 +1,5 @@
-using parkMonitor.DataBase;
+using parkMonitor.controlPanel;
+using parkMonitor.DataBase;
 using parkMonitor.entity;
 using parkMonitor.LOG;
 using parkMonitor.manualParking;
@@ -143,6 +144,11 @@ namespace parkMonitor.view.util
                 Log.WriteLog(LogType.NOTDATABASE, LogFile.INFO, "已重新启用远端DB");
             }
         }
+        private void muControlPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            ControlPanel.ins = new ControlPanel();
+            ControlPanel.ins.ShowDialog();
+        }
 
         ///// <summary>菜单-启动机械手</summary>
         //private void muRunRobot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { }