|
@@ -7,17 +7,66 @@ using parkMonitor.DB;
|
|
|
using parkMonitor.LOG;
|
|
|
using parkMonitor.entity;
|
|
|
using parkMonitor.model;
|
|
|
+using System.Configuration;
|
|
|
+using System.Threading;
|
|
|
|
|
|
namespace parkMonitor.server.CoreThread
|
|
|
{
|
|
|
- class CoreThreadTest:IEquipments,ICoreThreadDoWorking
|
|
|
+ class CoreThreadTest : IEquipments, ICoreThreadDoWorking
|
|
|
{
|
|
|
+ string startRobot_address;//启动机械手地址
|
|
|
+ string parkingSpaceID_address;
|
|
|
+ string parkingSpaceX_address;
|
|
|
+ string parkingSpaceY_address;
|
|
|
+ string parkingSpaceZ_address;
|
|
|
+ int equipmentStatus_address;//设备总控状态地址
|
|
|
+ int park_completed_address;//停车完成地址
|
|
|
+ int parkingEntX;//入口
|
|
|
+ int parkingEntY;
|
|
|
+ int parkingEntZ;
|
|
|
+ string park_command_address;//启动激光
|
|
|
+ //int vehicleTypeLength_address;
|
|
|
+ //int vehicleTypeWidth_address;
|
|
|
+ //int vehicleTypeHeight_address;
|
|
|
+ //int vehicleTypeWheelbase_address;
|
|
|
+ string parking_startRobot_address;//停车启动
|
|
|
+ int fetch_completed_address;
|
|
|
//获取PLC句柄
|
|
|
IEquipments PLC = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.PLC);
|
|
|
//获取队列句柄
|
|
|
- QueuingThread queuingThread = new QueuingThread();
|
|
|
+ IEquipments queuingThread = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Queue);
|
|
|
+ //QueuingThread queuingThread = new QueuingThread();
|
|
|
+ //数据库
|
|
|
+ DBOperation oper = new DBOperation();
|
|
|
+ //车位分配
|
|
|
+ CEntrance c = new CEntrance();
|
|
|
+ AllotParkingSpace aps = new AllotParkingSpace();
|
|
|
+
|
|
|
public static CoreThread ins = new CoreThread();
|
|
|
- string[] equipNames = new string[] { EquipmentName.PLC, EquipmentName.NumMachine,EquipmentName.Web};
|
|
|
+ string[] equipNames = new string[] { EquipmentName.PLC, EquipmentName.NumMachine, EquipmentName.Web, EquipmentName.Queue };
|
|
|
+
|
|
|
+ public CoreThreadTest()
|
|
|
+ {
|
|
|
+ startRobot_address = ConfigurationManager.AppSettings["startRobot_address"];
|
|
|
+ parkingSpaceID_address = ConfigurationManager.AppSettings["parkingSpaceID_address"];
|
|
|
+ parkingSpaceX_address = ConfigurationManager.AppSettings["parkingSpaceX_address"];
|
|
|
+ parkingSpaceY_address = ConfigurationManager.AppSettings["parkingSpaceY_address"];
|
|
|
+ parkingSpaceZ_address = ConfigurationManager.AppSettings["parkingSpaceZ_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"]);
|
|
|
+ //启动激光
|
|
|
+ park_command_address = ConfigurationManager.AppSettings["park_command_address"];
|
|
|
+ ////激光测量数据
|
|
|
+ //vehicleTypeLength_address = Convert.ToInt32(ConfigurationManager.AppSettings["vehicleTypeLength_address"]);
|
|
|
+ //vehicleTypeWidth_address = Convert.ToInt32(ConfigurationManager.AppSettings["vehicleTypeWidth_address"]);
|
|
|
+ //vehicleTypeHeight_address = Convert.ToInt32(ConfigurationManager.AppSettings["vehicleTypeHeight_address"]);
|
|
|
+ //vehicleTypeWheelbase_address = Convert.ToInt32(ConfigurationManager.AppSettings["vehicleTypeWheelbase_address"]);
|
|
|
+ //取车完成
|
|
|
+ fetch_completed_address = Convert.ToInt32(ConfigurationManager.AppSettings["fetch_completed_address"]);
|
|
|
+ }
|
|
|
|
|
|
public void Start()
|
|
|
{
|
|
@@ -31,7 +80,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
//监听总状态改变消息
|
|
|
//由监控线程发出
|
|
|
AsyncCmdServer.ins.listen(AsyncCmdType.TotalStatusChanged, (AlarmStatus type) =>
|
|
@@ -67,34 +116,131 @@ namespace parkMonitor.server.CoreThread
|
|
|
|
|
|
public void BeginWorking()
|
|
|
{
|
|
|
- PLCMessage PLCMsg;
|
|
|
- Command queueCmd;
|
|
|
- Task PLCTask = Task.Factory.StartNew(() =>
|
|
|
+ while (true)
|
|
|
{
|
|
|
- while (true)
|
|
|
+ PLCMessage PLCMsg = null;
|
|
|
+ Command queueCmd = null;
|
|
|
+ //等待PLC设备就绪状态
|
|
|
+ Task PLCTask = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
- int normalStatus = Convert.ToInt32(PLCMsg.plcList[0].Value);
|
|
|
- //设备总控状态
|
|
|
- if (normalStatus == 1)
|
|
|
+ while (true)
|
|
|
{
|
|
|
- break;
|
|
|
+ PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
+ int normalStatus = Convert.ToInt32(PLCMsg.plcList[equipmentStatus_address].Value);
|
|
|
+ //设备总控状态
|
|
|
+ if (normalStatus == 1)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
- Task queueTask = Task.Factory.StartNew(() =>
|
|
|
- {
|
|
|
- while (true)
|
|
|
+ });
|
|
|
+ //等待号牌资源
|
|
|
+ Task queueTask = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- queueCmd = (Command)queuingThread.GetMessage();
|
|
|
- if (queueCmd != null)
|
|
|
+ while (true)
|
|
|
{
|
|
|
- break;
|
|
|
+ queueCmd = (Command)queuingThread.GetMessage();
|
|
|
+ if (queueCmd != null)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ });
|
|
|
+ Task.WaitAll(PLCTask, queueTask);
|
|
|
+
|
|
|
+ if (queueCmd.commandType == 'f')
|
|
|
+ {
|
|
|
+ Vehicle vehiclelist = oper.GetVehicle(queueCmd.LicenseNum);
|
|
|
+ int parkingSpaceID = vehiclelist.parkingSpaceID;
|
|
|
+ int garageID = vehiclelist.garageID;
|
|
|
+ Fetching_Space fslist = oper.GetFetchingSpace(parkingSpaceID, garageID);
|
|
|
+ int parkingSpaceX = fslist.parkingSpaceX;
|
|
|
+ int parkingSpaceY = fslist.parkingSpaceY;
|
|
|
+ int parkingSpaceZ = fslist.parkingSpaceZ;
|
|
|
+ string startRobot = "1";
|
|
|
+ PLC.SetMessage(new PLCNode(startRobot_address, Convert.ToString(startRobot)));
|
|
|
+ PLC.SetMessage(new PLCNode(parkingSpaceID_address, Convert.ToString(parkingSpaceID)));
|
|
|
+ PLC.SetMessage(new PLCNode(parkingSpaceX_address, Convert.ToString(parkingSpaceX)));
|
|
|
+ PLC.SetMessage(new PLCNode(parkingSpaceY_address, Convert.ToString(parkingSpaceY)));
|
|
|
+ PLC.SetMessage(new PLCNode(parkingSpaceZ_address, Convert.ToString(parkingSpaceZ)));
|
|
|
+ //等待PLC取车完成信号
|
|
|
+ Task signalFromPLC = Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ Thread.Sleep(2000);
|
|
|
+ PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
+ int fetchingStatus = Convert.ToInt32(PLCMsg.plcList[fetch_completed_address].Value);
|
|
|
+ //取车完成信号
|
|
|
+ if (fetchingStatus == 1)
|
|
|
+ {
|
|
|
+ //fetchingStatus = 0;
|
|
|
+ //PLC.SetMessage(new PLCNode(Convert.ToString(park_completed_address), Convert.ToString(fetchingStatus)));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Task.WaitAll(signalFromPLC);
|
|
|
+ //数据库更新
|
|
|
}
|
|
|
- });
|
|
|
- Task.WaitAll(PLCTask, queueTask);
|
|
|
- //if(queueCmd.command='f')
|
|
|
+
|
|
|
+ if (queueCmd.commandType == 's')
|
|
|
+ {
|
|
|
+ c.parkingEntX = parkingEntX;
|
|
|
+ c.parkingEntY = parkingEntY;
|
|
|
+ c.parkingEntZ = parkingEntZ;
|
|
|
+ Parking_Space ppp = new Parking_Space();
|
|
|
+ ppp = aps.MallocParkingSpace(c);//得到车位
|
|
|
+ int parkingSpaceID = ppp.parkingSpaceID;
|
|
|
+ //int garageID = ppp.garageID;
|
|
|
+ string numberPlate = queueCmd.LicenseNum;
|
|
|
+ int userID = Convert.ToInt32(queueCmd.userID);
|
|
|
+ int garageID = queueCmd.garageID;
|
|
|
+ string realParkTime = queueCmd.TimeRecord;
|
|
|
+ int parkingRecordsID = oper.InsertToParkingRecords(userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);//插入停车记录表
|
|
|
+ string startLaser= "1";
|
|
|
+ PLC.SetMessage(new PLCNode(park_command_address, Convert.ToString(startLaser)));//启动激光
|
|
|
+ Task dataFromLaser = Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
+ if (PLCMsg!=null)
|
|
|
+ {
|
|
|
+ if (PLCMsg.laser1.data != null)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Task.WaitAll(dataFromLaser);
|
|
|
+ int centerX;
|
|
|
+ int centerY;
|
|
|
+ int angleA;
|
|
|
+ int length;
|
|
|
+ int width;
|
|
|
+ int height;
|
|
|
+ if (PLCMsg.laser1.status == 0 || PLCMsg.laser1.status == 3)
|
|
|
+ {
|
|
|
+ centerX = PLCMsg.laser1.data.centerX;
|
|
|
+ centerY = PLCMsg.laser1.data.centerY;
|
|
|
+ angleA = PLCMsg.laser1.data.angleA;
|
|
|
+ length = PLCMsg.laser1.data.length;
|
|
|
+ width = PLCMsg.laser1.data.width;
|
|
|
+ height = PLCMsg.laser1.data.height;
|
|
|
+ }
|
|
|
+ //int vehicleTypeLength = Convert.ToInt32(PLCMsg.plcList[vehicleTypeLength_address].Value);
|
|
|
+ //int vehicleTypeWidth = Convert.ToInt32(PLCMsg.plcList[vehicleTypeWidth_address].Value);
|
|
|
+ //int vehicleTypeHeight = Convert.ToInt32(PLCMsg.plcList[vehicleTypeHeight_address].Value);
|
|
|
+ //int vehicleTypeWheelbase = Convert.ToInt32(PLCMsg.plcList[vehicleTypeWheelbase_address].Value);
|
|
|
+ int vehicleTypeID = oper.getVehicleTypeID(numberPlate);
|
|
|
+ //判断测量数据是否准确
|
|
|
+ //bool isDataRight = oper.IsDataRight(vehicleTypeLength, vehicleTypeWidth, vehicleTypeHeight, vehicleTypeWheelbase, vehicleTypeID);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>挂起</summary>
|