|
@@ -27,9 +27,9 @@ namespace parkMonitor.server.CoreThread
|
|
|
public IEquipments queuingThread { set; get; }
|
|
|
public DBOperation oper { set; get; }
|
|
|
public IEquipments NumMachine { set; get; }
|
|
|
- public CEntrance c { set; get; }
|
|
|
+ public CEntrance cEntrance { set; get; }
|
|
|
public AllotParkingSpace aps { set; get; }
|
|
|
- public abstract void executeCmd(Command queueCmd);
|
|
|
+
|
|
|
public int parking_startRobot_address { get; set; }
|
|
|
public int fetching_startRobot_address { get; set; }
|
|
|
public DBLocationOperator locationOper { get; set; }
|
|
@@ -62,7 +62,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
//数据库
|
|
|
oper = new DBOperation();
|
|
|
//车位分配
|
|
|
- c = new CEntrance();
|
|
|
+ cEntrance = new CEntrance();
|
|
|
aps = new AllotParkingSpace();
|
|
|
robot = new Robot()
|
|
|
{
|
|
@@ -72,9 +72,10 @@ namespace parkMonitor.server.CoreThread
|
|
|
};
|
|
|
locationOper = new DBLocationOperator();
|
|
|
}
|
|
|
-
|
|
|
- public void WaitForRobotResource(PLCMessage PLCMsg, int robotID)
|
|
|
+ public abstract void executeCmd(Command queueCmd);
|
|
|
+ public void WaitForRobotResource( int robotID)
|
|
|
{
|
|
|
+ PLCMessage PLCMsg = null;
|
|
|
while (true)
|
|
|
{
|
|
|
lock (robot)
|
|
@@ -162,17 +163,139 @@ namespace parkMonitor.server.CoreThread
|
|
|
numberMachineMessage.aNode.LicenseNum = queueCmd.LicenseNum;
|
|
|
queuingThread.SetMessage(numberMachineMessage);
|
|
|
}
|
|
|
-
|
|
|
- public override void executeCmd(Command queueCmd)
|
|
|
+ /// <summary>
|
|
|
+ /// 车位资源
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="queueCmd"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private Parking_Space WaitForParkingSpaceResource(Command queueCmd)
|
|
|
+ {
|
|
|
+ //中心点
|
|
|
+ cEntrance.parkingEntX = parkingEntX;
|
|
|
+ cEntrance.parkingEntY = parkingEntY;
|
|
|
+ cEntrance.parkingEntZ = parkingEntZ;
|
|
|
+ Parking_Space ppp = new Parking_Space();
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ if (!queueCmd.manual)
|
|
|
+ {
|
|
|
+ ppp = aps.MallocParkingSpace(cEntrance, oper);//自动
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ppp = aps.MallocParkingSpace(cEntrance, locationOper);//手动
|
|
|
+ }
|
|
|
+ if (ppp != null)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (isClosing)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Thread.Sleep(200);
|
|
|
+ }
|
|
|
+ return ppp;
|
|
|
+ }
|
|
|
+ private Data WaitForLaserResource(Command queueCmd, bool disappeared)
|
|
|
{
|
|
|
//激光数据
|
|
|
- int centerX = 0;
|
|
|
- int centerY = 0;
|
|
|
- int angleA = 0;
|
|
|
- int length = 0;
|
|
|
- int width = 0;
|
|
|
- int height = 0;
|
|
|
+ Data data = new Data();
|
|
|
+ bool jumpOut = false;
|
|
|
+ PLCMessage PLCMsg = null;
|
|
|
+ jumpOut = false;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
+ if (PLCMsg != null)
|
|
|
+ {
|
|
|
+ foreach (LaserMessage lm in PLCMsg.laserMsgList)
|
|
|
+ {
|
|
|
+ if (lm.id == queueCmd.id && lm.data != null)
|
|
|
+ {
|
|
|
+ lock (lm)
|
|
|
+ {
|
|
|
+ //判断车辆检测结果,
|
|
|
+ if (disappeared)
|
|
|
+ {
|
|
|
+ lm.abort_rescan = true;
|
|
|
+ jumpOut = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //存储相应激光数据
|
|
|
+ if (lm.recorded)
|
|
|
+ {
|
|
|
+ data.angleA = lm.data.angleA;
|
|
|
+ data.centerX = lm.data.centerX;
|
|
|
+ data.centerY = lm.data.centerY;
|
|
|
+ data.length = lm.data.length;
|
|
|
+ data.width = lm.data.width;
|
|
|
+ data.height = lm.data.height;
|
|
|
+ jumpOut = true;
|
|
|
+ lm.recorded = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else if (lm.status == -1)
|
|
|
+ {
|
|
|
+ LogFile logFile = LogFile.ERROR;
|
|
|
+ UILogServer.ins.error("激光" + lm.id + "连接异常");
|
|
|
+ Log.WriteLog(logFile, "激光异常");
|
|
|
+ Thread.Sleep(5000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (jumpOut)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Thread.Sleep(1000);
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 停车完成
|
|
|
+ /// </summary>
|
|
|
+ private void WaitForStoreSignal(Command queueCmd, ref int parkingSpaceID, ref int frontWheelbase, ref int rearWheelbase, ref bool robotError)
|
|
|
+ {
|
|
|
PLCMessage PLCMsg = null;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ Thread.Sleep(1000);
|
|
|
+ PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
+ int storeStatus = Convert.ToInt32(PLCMsg.originalPlcList[park_completed_address].Value);
|
|
|
+ //停车完成信号
|
|
|
+ if (storeStatus == 1)
|
|
|
+ {
|
|
|
+ frontWheelbase = Convert.ToInt32(PLCMsg.originalPlcList[frontWheelbase_address].Value);
|
|
|
+ rearWheelbase = Convert.ToInt32(PLCMsg.originalPlcList[rearWheelbase_address].Value);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else if (1 == 2)//机械手异常,则退指令,写数据库归位
|
|
|
+ {
|
|
|
+ robotError = true;
|
|
|
+ queueCmd.returnedCount += 1;
|
|
|
+ queuingThread.SetMessage(queueCmd);
|
|
|
+ if (!queueCmd.manual)
|
|
|
+ {
|
|
|
+ oper.UpdateParkingSpaceState(parkingSpaceID, 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 停车流程
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="queueCmd"></param>
|
|
|
+ public override void executeCmd(Command queueCmd)
|
|
|
+ {
|
|
|
+ //第一步:
|
|
|
int status = 1;//停车
|
|
|
ParkingMessage pm = new ParkingMessage();
|
|
|
pm.status = status;
|
|
@@ -180,26 +303,13 @@ namespace parkMonitor.server.CoreThread
|
|
|
PLC.SetMessage(pm);
|
|
|
Console.WriteLine("停车,开激光:" + queueCmd.LicenseNum);
|
|
|
Log.WriteLog("停车,开激光:" + queueCmd.LicenseNum);
|
|
|
- UILogServer.ins.info("停车,开激光:" + queueCmd.LicenseNum);
|
|
|
- c.parkingEntX = parkingEntX;
|
|
|
- c.parkingEntY = parkingEntY;
|
|
|
- c.parkingEntZ = parkingEntZ;
|
|
|
+ UILogServer.ins.info("停车,开激光:" + queueCmd.LicenseNum);
|
|
|
+
|
|
|
Parking_Space ppp = new Parking_Space();
|
|
|
Task parkingSpace = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- while (true)
|
|
|
- {
|
|
|
- ppp = aps.MallocParkingSpace(c);//得到车位
|
|
|
- if (ppp != null)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- if (isClosing) { return; }
|
|
|
- Thread.Sleep(200);
|
|
|
- }
|
|
|
+ ppp = WaitForParkingSpaceResource(queueCmd);
|
|
|
});
|
|
|
- //parkingSpace.Wait();
|
|
|
-
|
|
|
//int garageID = ppp.garageID;
|
|
|
string numberPlate = queueCmd.LicenseNum;
|
|
|
int userID = 0;
|
|
@@ -210,8 +320,6 @@ namespace parkMonitor.server.CoreThread
|
|
|
}
|
|
|
int garageID = queueCmd.garageID;
|
|
|
string realParkTime = queueCmd.TimeRecord;
|
|
|
-
|
|
|
- bool jumpOut = false;
|
|
|
bool disappeared = false;
|
|
|
bool stopChecking = false;
|
|
|
bool robotError = false;
|
|
@@ -242,71 +350,36 @@ namespace parkMonitor.server.CoreThread
|
|
|
// t = startTime - endTime;
|
|
|
// }
|
|
|
//});
|
|
|
-
|
|
|
+ Data dataReal = new Data();
|
|
|
Task dataFromLaser = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- while (true)
|
|
|
- {
|
|
|
- jumpOut = false;
|
|
|
- PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
- if (PLCMsg != null)
|
|
|
- {
|
|
|
- foreach (LaserMessage lm in PLCMsg.laserMsgList)
|
|
|
- {
|
|
|
- if (lm.id == queueCmd.id && lm.data != null)
|
|
|
- {
|
|
|
- lock (lm)
|
|
|
- {
|
|
|
- //判断车辆检测结果,
|
|
|
- if (disappeared)
|
|
|
- {
|
|
|
- lm.abort_rescan = true;
|
|
|
- jumpOut = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- //存储相应激光数据
|
|
|
- if (lm.recorded)
|
|
|
- {
|
|
|
- centerX = lm.data.centerX;
|
|
|
- centerY = lm.data.centerY;
|
|
|
- angleA = lm.data.angleA;
|
|
|
- length = lm.data.length;
|
|
|
- width = lm.data.width;
|
|
|
- height = lm.data.height;
|
|
|
- jumpOut = true;
|
|
|
- lm.recorded = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- else if (lm.status == -1)
|
|
|
- {
|
|
|
- LogFile logFile = LogFile.ERROR;
|
|
|
- UILogServer.ins.error("激光" + lm.id + "连接异常");
|
|
|
- Log.WriteLog(logFile, "激光异常");
|
|
|
- Thread.Sleep(5000);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (jumpOut)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- Thread.Sleep(1000);
|
|
|
- }
|
|
|
+ dataReal = WaitForLaserResource(queueCmd, disappeared);
|
|
|
});
|
|
|
-
|
|
|
- //dataFromLaser.Wait();
|
|
|
- Task.WaitAll(parkingSpace,dataFromLaser);
|
|
|
+ Task.WaitAll(parkingSpace, dataFromLaser);
|
|
|
+ //车位
|
|
|
int parkingSpaceID = ppp.parkingSpaceID;
|
|
|
int parkingSpaceX = ppp.parkingSpaceX;
|
|
|
int parkingSpaceY = ppp.parkingSpaceY;
|
|
|
int parkingSpaceZ = ppp.parkingSpaceZ;
|
|
|
-
|
|
|
+ //激光数据
|
|
|
+ int centerX = dataReal.centerX;
|
|
|
+ int centerY = dataReal.centerY;
|
|
|
+ int angleA = dataReal.angleA;
|
|
|
+ int length = dataReal.length;
|
|
|
+ int width = dataReal.width;
|
|
|
+ int height = dataReal.height;
|
|
|
+ //号牌失效,数据库回滚
|
|
|
if (disappeared)
|
|
|
{
|
|
|
NumReset(queueCmd);
|
|
|
- oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
|
|
|
+ if (!queueCmd.manual)
|
|
|
+ {
|
|
|
+ oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
stopChecking = true;//开始启动机械手,停止检测号牌
|
|
@@ -316,9 +389,10 @@ namespace parkMonitor.server.CoreThread
|
|
|
Task robotFree = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
//需要先遍历robot数组,根据id找到对应机械手
|
|
|
- WaitForRobotResource(PLCMsg, robotID);
|
|
|
+ WaitForRobotResource(robotID);
|
|
|
});
|
|
|
robotFree.Wait();
|
|
|
+ //第二步:
|
|
|
status = 2;
|
|
|
pm.status = status;
|
|
|
pm.RobotID = robotID;//启动对应机械手
|
|
@@ -342,29 +416,10 @@ namespace parkMonitor.server.CoreThread
|
|
|
int rearWheelbase = 0;
|
|
|
Task storeSignal = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- while (true)
|
|
|
- {
|
|
|
- Thread.Sleep(1000);
|
|
|
- PLCMsg = (PLCMessage)PLC.GetMessage();
|
|
|
- int storeStatus = Convert.ToInt32(PLCMsg.originalPlcList[park_completed_address].Value);
|
|
|
- //停车完成信号
|
|
|
- if (storeStatus == 1)
|
|
|
- {
|
|
|
- frontWheelbase = Convert.ToInt32(PLCMsg.originalPlcList[frontWheelbase_address].Value);
|
|
|
- rearWheelbase = Convert.ToInt32(PLCMsg.originalPlcList[rearWheelbase_address].Value);
|
|
|
- break;
|
|
|
- }
|
|
|
- else if (1 == 2)//机械手异常,则退指令,写数据库归位
|
|
|
- {
|
|
|
- robotError = true;
|
|
|
- queueCmd.returnedCount += 1;
|
|
|
- queuingThread.SetMessage(queueCmd);
|
|
|
- oper.UpdateParkingSpaceState(parkingSpaceID, 0);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ WaitForStoreSignal(queueCmd, ref parkingSpaceID, ref frontWheelbase, ref rearWheelbase, ref robotError);
|
|
|
});
|
|
|
storeSignal.Wait();
|
|
|
+ //第三步:
|
|
|
status = 3;
|
|
|
pm.status = status;
|
|
|
PLC.SetMessage(pm);
|
|
@@ -403,7 +458,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
//插入停车记录表
|
|
|
int parkingRecordsID = oper.InsertToParkingRecords(userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
|
|
|
//车辆表更新车辆信息
|
|
|
- oper.UpdateVehicle(numberPlate, 1, realParkTime, parkingRecordsID, parkingSpaceID, 1,frontWheelbase,rearWheelbase);
|
|
|
+ oper.UpdateVehicle(numberPlate, 1, realParkTime, parkingRecordsID, parkingSpaceID, 1, frontWheelbase, rearWheelbase);
|
|
|
//更新车库表剩余车位数
|
|
|
int freeSpaceCount = oper.getGarageFreeSpace(garageID);
|
|
|
freeSpaceCount = freeSpaceCount - 1;
|
|
@@ -425,7 +480,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
else
|
|
|
{
|
|
|
//插入停车记录表
|
|
|
- int parkingRecordsID = locationOper.InsertToParkingRecords(1,userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
|
|
|
+ int parkingRecordsID = locationOper.InsertToParkingRecords(1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
|
|
|
//判断车辆表是否存在车辆
|
|
|
bool isNumberPlateFromVehicle = locationOper.IsNumberPlateFromVehicle(numberPlate);
|
|
|
if (isNumberPlateFromVehicle == false)
|
|
@@ -474,17 +529,17 @@ namespace parkMonitor.server.CoreThread
|
|
|
int parkingSpaceX = fslist.parkingSpaceX;
|
|
|
int parkingSpaceY = fslist.parkingSpaceY;
|
|
|
int parkingSpaceZ = fslist.parkingSpaceZ;
|
|
|
- int status = 4;//取车
|
|
|
-
|
|
|
ParkingMessage pm = new ParkingMessage();
|
|
|
+
|
|
|
int robotID = 0;
|
|
|
robotID = parkingSpaceID / 15 + 1;
|
|
|
Task robotFree = Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
- WaitForRobotResource(PLCMsg, robotID);
|
|
|
+ WaitForRobotResource(robotID);
|
|
|
});
|
|
|
robotFree.Wait();
|
|
|
-
|
|
|
+ //取车
|
|
|
+ int status = 4;
|
|
|
pm.status = status;
|
|
|
//先手动赋值
|
|
|
pm.RobotID = 1;
|
|
@@ -518,6 +573,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
});
|
|
|
//Task.WaitAll(signalFromPLC);
|
|
|
signalFromPLC.Wait();
|
|
|
+ //取车完成
|
|
|
status = 5;
|
|
|
ParkingMessage pm2 = new ParkingMessage();
|
|
|
pm2.status = status;
|
|
@@ -562,7 +618,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
//更新车辆表车辆停车状态
|
|
|
locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
|
|
|
//更新停车记录表
|
|
|
- locationOper.UpdateParkingRecords(0,6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
|
|
|
+ locationOper.UpdateParkingRecords(0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
|
|
|
}
|
|
|
}
|
|
|
}
|