|
@@ -82,7 +82,13 @@ namespace parkMonitor.server.CoreThread
|
|
|
/// 号牌机线程句柄
|
|
|
/// </summary>
|
|
|
public IEquipments NumMachine { set; get; }
|
|
|
+ /// <summary>
|
|
|
+ /// 车库中心
|
|
|
+ /// </summary>
|
|
|
public CEntrance cEntrance { set; get; }
|
|
|
+ /// <summary>
|
|
|
+ /// 车位分配
|
|
|
+ /// </summary>
|
|
|
public AllotParkingSpace aps { set; get; }
|
|
|
|
|
|
public AbstractCmd()
|
|
@@ -116,6 +122,11 @@ namespace parkMonitor.server.CoreThread
|
|
|
//locationOper = new DBLocationOperator();
|
|
|
}
|
|
|
public abstract void executeCmd(Command queueCmd);
|
|
|
+ /// <summary>
|
|
|
+ /// 等待机械手空闲资源
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="robotID"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public bool WaitForRobotResource(int robotID)
|
|
|
{
|
|
|
PLCMessage PLCMsg = null;
|
|
@@ -571,12 +582,11 @@ namespace parkMonitor.server.CoreThread
|
|
|
{
|
|
|
//UILogServer.ins.info("停车流程:" + queueCmd.LicenseNum + "开始");
|
|
|
Log.WriteLog(LogFile.LOG, "停车流程:" + queueCmd.LicenseNum + "开始");
|
|
|
- string connectionStr = null;
|
|
|
- bool disappeared = false;
|
|
|
- bool stopChecking = false;
|
|
|
- bool robotError = false;
|
|
|
- string numberPlate = queueCmd.LicenseNum;
|
|
|
- int userID = 0;
|
|
|
+ string connectionStr = null; //数据库连接字符串
|
|
|
+ bool disappeared = false; //车辆检测结果
|
|
|
+ bool stopChecking = false; //是否停止检测
|
|
|
+ bool robotError = false; //机械手是否异常
|
|
|
+ int userID = 0; //用户ID
|
|
|
|
|
|
//第一步,激光与车位:
|
|
|
int status = 1;//停车
|
|
@@ -592,10 +602,10 @@ namespace parkMonitor.server.CoreThread
|
|
|
//车位分配数据库操作加锁,直到启动机械手
|
|
|
Parking_Space ppp = new Parking_Space();
|
|
|
Data dataReal = new Data();
|
|
|
- int garageID;
|
|
|
- string realParkTime;
|
|
|
- LaserMessage lmToBeReleased;
|
|
|
- int freeSpaceCount = 0;
|
|
|
+ int garageID; //车库ID(Web发送)
|
|
|
+ string realParkTime; //停车时间(可执行队列)
|
|
|
+ LaserMessage lmToBeReleased; //激光
|
|
|
+ int freeSpaceCount = 0; //剩余空闲车位
|
|
|
dataReal = WaitForLaserResource(queueCmd, disappeared, out lmToBeReleased);
|
|
|
//判断激光资源有效性,无效则回滚
|
|
|
if (dataReal == null)
|
|
@@ -603,6 +613,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
Rollback(queueCmd, 0, false, true, lmToBeReleased);
|
|
|
return;
|
|
|
}
|
|
|
+ //车位分配锁
|
|
|
lock (Parking_Space.spaceLock)
|
|
|
{
|
|
|
//获取车位资源
|
|
@@ -667,13 +678,13 @@ namespace parkMonitor.server.CoreThread
|
|
|
using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
|
|
|
{
|
|
|
Operation.TryOpen(conn);
|
|
|
- bool DBStoreStatus = false;
|
|
|
+ bool DBStoreStatus = false; //判断数据库事务操作是否正常
|
|
|
int temp;
|
|
|
- string updateParkingSpace = "update parkingspace set parkingSpaceState = 1 where parkingSpaceID = '" + ppp.parkingSpaceID + "'";
|
|
|
- string updateFreeSpace = "update garage set garageFreeSpace = '" + (freeSpaceCount - 1) + "' where garageID = '" + garageID + "'";
|
|
|
+ string updateParkingSpaceSql = "update parkingspace set parkingSpaceState = 1 where parkingSpaceID = '" + ppp.parkingSpaceID + "'";
|
|
|
+ string updateFreeSpaceSql = "update garage set garageFreeSpace = '" + (freeSpaceCount - 1) + "' where garageID = '" + garageID + "'";
|
|
|
List<string> strs = new List<string>();
|
|
|
- strs.Add(updateParkingSpace);
|
|
|
- strs.Add(updateFreeSpace);
|
|
|
+ strs.Add(updateParkingSpaceSql);
|
|
|
+ strs.Add(updateFreeSpaceSql);
|
|
|
while (!DBStoreStatus)
|
|
|
{
|
|
|
DBStoreStatus = Operation.MyTransaction(conn, strs, out temp);
|
|
@@ -682,13 +693,13 @@ namespace parkMonitor.server.CoreThread
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- throw;
|
|
|
+ throw; //数据库异常待处理
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionLocation";
|
|
|
+ connectionStr = DBConnection.localStr;
|
|
|
//更新本地车位表车位状态
|
|
|
oper.UpdateParkingSpaceState(connectionStr, ppp.parkingSpaceID, 1);
|
|
|
//更新车库表剩余车位数
|
|
@@ -702,12 +713,12 @@ namespace parkMonitor.server.CoreThread
|
|
|
NumReset(queueCmd);
|
|
|
if (!queueCmd.manual)
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionStr";
|
|
|
+ connectionStr = DBConnection.remoteStr;
|
|
|
oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionLocation";
|
|
|
+ connectionStr = DBConnection.localStr;
|
|
|
oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
|
|
|
}
|
|
|
return;
|
|
@@ -741,6 +752,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
cm.length = Convert.ToString(dataReal.length);
|
|
|
cm.width = Convert.ToString(dataReal.width);
|
|
|
cm.height = Convert.ToString(dataReal.height);
|
|
|
+ //分配的车位数据
|
|
|
cm.parkingSpaceID = Convert.ToString(ppp.parkingSpaceID);
|
|
|
cm.parkingSpaceX = Convert.ToString(ppp.parkingSpaceX);
|
|
|
cm.parkingSpaceY = Convert.ToString(ppp.parkingSpaceY);
|
|
@@ -771,10 +783,11 @@ namespace parkMonitor.server.CoreThread
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- //停车流程结束,将相应车牌复位
|
|
|
+ //停车流程结束,将相应车牌复位,从号牌队列中出队
|
|
|
NumReset(queueCmd);
|
|
|
Log.WriteLog(LogFile.LOG, "停车流程:" + queueCmd.LicenseNum + "停车完成,状态复位");
|
|
|
UILogServer.ins.info("停车流程:" + queueCmd.LicenseNum + "停车完成,状态复位");
|
|
|
+ //释放机械手
|
|
|
if (lmToBeReleased != null)
|
|
|
{
|
|
|
lmToBeReleased.occupied = false;
|
|
@@ -812,16 +825,16 @@ namespace parkMonitor.server.CoreThread
|
|
|
{
|
|
|
Operation.TryOpen(conn);
|
|
|
bool DBStoreStatus = false;
|
|
|
- string insertRecord = "insert into parkingrecords(userID,numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime) values('" + userID + "','" + numberPlate + "','" + ppp.parkingSpaceID + "','" + garageID + "',3,'" + realParkTime + "')";
|
|
|
+ string insertRecordSql = "insert into parkingrecords(userID,numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime) values('" + userID + "','" + queueCmd.LicenseNum + "','" + ppp.parkingSpaceID + "','" + garageID + "',3,'" + realParkTime + "')";
|
|
|
while (!DBStoreStatus)
|
|
|
{
|
|
|
- DBStoreStatus = Operation.MyTransaction(conn,insertRecord, out parkingRecordsID);
|
|
|
+ DBStoreStatus = Operation.MyTransaction(conn,insertRecordSql, out parkingRecordsID);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- throw;
|
|
|
+ throw; //数据库操作失败异常待处理
|
|
|
}
|
|
|
//事务更新车辆信息
|
|
|
try
|
|
@@ -830,24 +843,24 @@ namespace parkMonitor.server.CoreThread
|
|
|
{
|
|
|
Operation.TryOpen(conn);
|
|
|
bool DBStoreStatus = false;
|
|
|
- string updateVehicle = "update vehicle set vehiclepParkState = 1,scanEntryTime = '" + queueCmd.TimeRecord + "',parkingRecordsID = '" + parkingRecordsID + "',parkingSpaceID = '" + ppp.parkingSpaceID + "',vehicleTypeConfirm = 1,frontwheelbase = '" + frontWheelbase + "',rearwheelbase = '" + rearWheelbase + "' where numberPlate = '" + numberPlate + "'";
|
|
|
+ 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 +"'";
|
|
|
while (!DBStoreStatus)
|
|
|
{
|
|
|
int temp;
|
|
|
- DBStoreStatus = Operation.MyTransaction(conn, updateVehicle, out temp);
|
|
|
+ DBStoreStatus = Operation.MyTransaction(conn, updateVehicleSql, out temp);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- throw;
|
|
|
+ throw; //数据库操作失败异常待处理
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionLocation";
|
|
|
+ connectionStr = DBConnection.localStr;
|
|
|
//插入停车记录表
|
|
|
- int parkingRecordsID = oper.InsertToLocalParkingRecords(connectionStr, 1, userID, numberPlate, ppp.parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
|
|
|
+ int parkingRecordsID = oper.InsertToLocalParkingRecords(connectionStr, 1, userID, queueCmd.LicenseNum, ppp.parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -855,7 +868,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
else
|
|
|
{
|
|
|
LogFile logFile = LogFile.ERROR_NUMBERPLATE;
|
|
|
- Log.WriteLog(logFile, "号牌:" + numberPlate);
|
|
|
+ Log.WriteLog(logFile, "号牌:" + queueCmd.LicenseNum);
|
|
|
Log.WriteLog(logFile, "入库时间:" + realParkTime);
|
|
|
Log.WriteLog(logFile, "车位id:" + ppp.parkingSpaceID);
|
|
|
Log.WriteLog(logFile, "车位x:" + ppp.parkingSpaceX);
|
|
@@ -871,6 +884,14 @@ namespace parkMonitor.server.CoreThread
|
|
|
/// </summary>
|
|
|
public class FetchCmd : AbstractCmd
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// 等待取车完成信号
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="queueCmd"></param>
|
|
|
+ /// <param name="parkingSpaceID"></param>
|
|
|
+ /// <param name="robotError"></param>
|
|
|
+ /// <param name="status"></param>
|
|
|
+ /// <returns></returns>
|
|
|
private bool waitForFetchCompletionSignal(Command queueCmd, int parkingSpaceID, ref bool robotError, int status)
|
|
|
{
|
|
|
string connectionStr = null;
|
|
@@ -932,24 +953,24 @@ namespace parkMonitor.server.CoreThread
|
|
|
{
|
|
|
//UILogServer.ins.info("取车流程:" + queueCmd.LicenseNum + "开始");
|
|
|
Log.WriteLog(LogFile.LOG, "取车流程:" + queueCmd.LicenseNum + "开始");
|
|
|
- string connectionStr = null;
|
|
|
- PLCMessage PLCMsg = null;
|
|
|
- Vehicle vehiclelist = null;
|
|
|
+ string connectionStr = null; //数据库连接字符串
|
|
|
+ PLCMessage PLCMsg = null; //PLC信息
|
|
|
+ Vehicle vehiclelist = null; //待取车辆信息
|
|
|
ControlMessage cm = null;
|
|
|
- Parking_Space ps = null;
|
|
|
- int frontwheelbase;
|
|
|
- int rearwheelbase;
|
|
|
- int garageID;
|
|
|
- bool robotError = false;
|
|
|
+ Parking_Space ps = null; //车位信息
|
|
|
+ int frontwheelbase; //前轮距
|
|
|
+ int rearwheelbase; //后轮距
|
|
|
+ int garageID; //车库ID
|
|
|
+ bool robotError = false; //机械手是否异常
|
|
|
//获取车辆表中车辆相关信息
|
|
|
if (queueCmd.manual)
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionLocation";
|
|
|
+ connectionStr = DBConnection.localStr;
|
|
|
vehiclelist = oper.GetLocalVehicle(connectionStr, queueCmd.LicenseNum, queueCmd.garageID);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionStr";
|
|
|
+ connectionStr = DBConnection.remoteStr;
|
|
|
vehiclelist = oper.GetVehicle(connectionStr, queueCmd.LicenseNum);
|
|
|
}
|
|
|
if (vehiclelist == null)
|
|
@@ -964,12 +985,12 @@ namespace parkMonitor.server.CoreThread
|
|
|
//获取车位表中车辆具体的车位信息
|
|
|
if (queueCmd.manual)
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionLocation";
|
|
|
+ connectionStr = DBConnection.localStr;
|
|
|
ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionStr";
|
|
|
+ connectionStr = DBConnection.remoteStr;
|
|
|
ps = oper.GetFetchingSpace(connectionStr, parkingSpaceID);
|
|
|
}
|
|
|
if (ps == null)
|
|
@@ -978,7 +999,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
return;
|
|
|
}
|
|
|
cm = new ControlMessage();
|
|
|
-
|
|
|
+ //启动机械手
|
|
|
int robotID = 0;
|
|
|
robotID = parkingSpaceID / 50 + 1;
|
|
|
if (!WaitForRobotResource(robotID))
|
|
@@ -990,8 +1011,8 @@ namespace parkMonitor.server.CoreThread
|
|
|
int status = 4;
|
|
|
cm.status = status;
|
|
|
//先手动赋值
|
|
|
- cm.RobotID = 1;
|
|
|
- cm.fetchPosition = 1;//放置地址
|
|
|
+ cm.RobotID = 1; //1号机械手
|
|
|
+ cm.fetchPosition = 1; //放置地址
|
|
|
cm.parkingSpaceID = Convert.ToString(ps.parkingSpaceID);
|
|
|
cm.parkingSpaceX = Convert.ToString(ps.parkingSpaceX);
|
|
|
cm.parkingSpaceY = Convert.ToString(ps.parkingSpaceY);
|
|
@@ -1013,13 +1034,14 @@ namespace parkMonitor.server.CoreThread
|
|
|
ControlMessage cm2 = new ControlMessage();
|
|
|
cm2.status = status;
|
|
|
//先手动赋值
|
|
|
- cm2.RobotID = 1;
|
|
|
+ cm2.RobotID = 1; //机械手复位
|
|
|
PLC.SetMessage(cm2);
|
|
|
if (!waitForFetchCompletionSignal(queueCmd, ps.parkingSpaceID, ref robotError, 0))
|
|
|
{
|
|
|
Rollback(queueCmd, ps.parkingSpaceID, true, false, null);
|
|
|
return;
|
|
|
}
|
|
|
+ //释放机械手
|
|
|
Robot.robot1.occupied = false;
|
|
|
Robot.robot1.waitCount -= 1;
|
|
|
Log.WriteLog("取车流程:号牌:" + queueCmd.LicenseNum + "取车完成");
|
|
@@ -1046,13 +1068,13 @@ namespace parkMonitor.server.CoreThread
|
|
|
//oper.UpdateVehicleParkState(connectionStr, queueCmd.LicenseNum, 0);
|
|
|
//更新停车记录表
|
|
|
//oper.UpdateParkingRecords(connectionStr, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
|
|
|
-
|
|
|
+ //取车事务
|
|
|
try
|
|
|
{
|
|
|
using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
|
|
|
{
|
|
|
Operation.TryOpen(conn);
|
|
|
- bool DBStoreStatus = false;
|
|
|
+ bool DBStoreStatus = false; //判断数据库事务操作是否正常
|
|
|
int temp;
|
|
|
List<string> strs = new List<string>();
|
|
|
strs.Add("update parkingspace set parkingSpaceState = 0 where parkingSpaceID = '" + ps.parkingSpaceID + "'");
|
|
@@ -1067,12 +1089,12 @@ namespace parkMonitor.server.CoreThread
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- throw;
|
|
|
+ throw; //数据库操作失败异常待处理
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- connectionStr = "SqlConnectionLocation";
|
|
|
+ connectionStr = DBConnection.localStr;
|
|
|
//更新车库表车位数
|
|
|
int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, garageID);
|
|
|
freeSpaceCount = freeSpaceCount + 1;
|
|
@@ -1096,7 +1118,7 @@ namespace parkMonitor.server.CoreThread
|
|
|
{
|
|
|
public override void executeCmd(Command queueCmd)
|
|
|
{
|
|
|
- string connectionStr = "SqlConnectionLocation";
|
|
|
+ string connectionStr = DBConnection.remoteStr;
|
|
|
if (queueCmd.commandType == 'e')
|
|
|
{
|
|
|
int userId = Convert.ToInt32(queueCmd.userID);
|