|
@@ -16,9 +16,16 @@ namespace Terminal
|
|
|
public class Terminal
|
|
|
{
|
|
|
public static List<TerminalStru> terminalInfo = new List<PLCS7.TerminalStru>();
|
|
|
+ /// <summary>
|
|
|
+ /// 记录地面停车位id与获取号牌映射
|
|
|
+ /// </summary>
|
|
|
private static Dictionary<int, string> idLicMap = new Dictionary<int, string>();
|
|
|
+ /// <summary>
|
|
|
+ /// 取车地面位id与是否已计费标记映射
|
|
|
+ /// </summary>
|
|
|
public static Dictionary<int, bool> termUsedMap = new Dictionary<int, bool>();
|
|
|
private static Dictionary<int, FetchInfo> fetchMap = new Dictionary<int, FetchInfo>();
|
|
|
+ private static List<object> lockList = new List<object>();
|
|
|
public static bool isClosing = false;
|
|
|
|
|
|
public void FeeCal()
|
|
@@ -396,105 +403,108 @@ namespace Terminal
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ #region 早期获取号牌方法,已弃用
|
|
|
/// <summary>
|
|
|
/// 停车流程,收到号牌机启动后操作过程
|
|
|
/// </summary>
|
|
|
- private static void ParkNumSubProcess()
|
|
|
- {
|
|
|
- //int numMachineLaunch = Monitor.Monitor.mainBlockInfo.numMachineLaunch;
|
|
|
- //if (numMachineLaunch != 0)
|
|
|
- //{
|
|
|
- for (int i = 0; i < terminalInfo.Count; i++)
|
|
|
- {
|
|
|
- //启动指令与终端id匹配
|
|
|
- //if (numMachineLaunch == terminalInfo[i].terminalID)
|
|
|
- if (terminalInfo[i].numMachineLaunch == 1 && !idLicMap.ContainsKey(terminalInfo[i].terminalID) && terminalInfo[i].licVerification == 0)
|
|
|
- {
|
|
|
- int numReceivedStatus = 0;//1获得,2终止
|
|
|
- TerminalStru term = terminalInfo[i];
|
|
|
- if (term.terminalStatus == (short)1)
|
|
|
- {
|
|
|
- string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
|
|
|
- Monitor.Monitor.SetNotification("启动" + terminalInfo[i].terminalID + "号号牌机,号牌:" + license);
|
|
|
- //未获得号牌,告知PLC终止,告诉终端提示用户重新操作
|
|
|
- if (license == "")
|
|
|
- {
|
|
|
- MainBlockStru mb = new MainBlockStru
|
|
|
- {
|
|
|
- licenseReceived = (short)2
|
|
|
- };
|
|
|
- Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
|
|
|
- TerminalStru ts = new TerminalStru
|
|
|
- {
|
|
|
- terminalID = (short)terminalInfo[i].terminalID,
|
|
|
- paymentStatus = -1,
|
|
|
- parkingFee = -1,
|
|
|
- userType = -1,
|
|
|
- licVerification = (short)2
|
|
|
- };
|
|
|
- Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
|
|
|
- Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //记录或更新当前号牌
|
|
|
- lock (idLicMap)
|
|
|
- {
|
|
|
- if (idLicMap.ContainsKey(terminalInfo[i].terminalID))
|
|
|
- {
|
|
|
- idLicMap[terminalInfo[i].terminalID] = license;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- idLicMap.Add(terminalInfo[i].terminalID, license);
|
|
|
- }
|
|
|
- }
|
|
|
- Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "已记录");
|
|
|
+ //private static void ParkNumSubProcess()
|
|
|
+ //{
|
|
|
+ // //int numMachineLaunch = Monitor.Monitor.mainBlockInfo.numMachineLaunch;
|
|
|
+ // //if (numMachineLaunch != 0)
|
|
|
+ // //{
|
|
|
+ // for (int i = 0; i < terminalInfo.Count; i++)
|
|
|
+ // {
|
|
|
+ // //启动指令与终端id匹配
|
|
|
+ // //if (numMachineLaunch == terminalInfo[i].terminalID)
|
|
|
+ // if (terminalInfo[i].numMachineLaunch == 1 && !idLicMap.ContainsKey(terminalInfo[i].terminalID) && terminalInfo[i].licVerification == 0)
|
|
|
+ // {
|
|
|
+ // int numReceivedStatus = 0;//1获得,2终止
|
|
|
+ // TerminalStru term = terminalInfo[i];
|
|
|
+ // if (term.terminalStatus == (short)1)
|
|
|
+ // {
|
|
|
+ // string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
|
|
|
+ // Monitor.Monitor.SetNotification("启动" + terminalInfo[i].terminalID + "号号牌机,号牌:" + license);
|
|
|
+ // //未获得号牌,告知PLC终止,告诉终端提示用户重新操作
|
|
|
+ // if (license == "")
|
|
|
+ // {
|
|
|
+ // MainBlockStru mb = new MainBlockStru
|
|
|
+ // {
|
|
|
+ // licenseReceived = (short)2
|
|
|
+ // };
|
|
|
+ // Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
|
|
|
+ // TerminalStru ts = new TerminalStru
|
|
|
+ // {
|
|
|
+ // terminalID = (short)terminalInfo[i].terminalID,
|
|
|
+ // paymentStatus = -1,
|
|
|
+ // parkingFee = -1,
|
|
|
+ // userType = -1,
|
|
|
+ // licVerification = (short)2
|
|
|
+ // };
|
|
|
+ // Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
|
|
|
+ // Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // //记录或更新当前号牌
|
|
|
+ // lock (idLicMap)
|
|
|
+ // {
|
|
|
+ // if (idLicMap.ContainsKey(terminalInfo[i].terminalID))
|
|
|
+ // {
|
|
|
+ // idLicMap[terminalInfo[i].terminalID] = license;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // idLicMap.Add(terminalInfo[i].terminalID, license);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "已记录");
|
|
|
+
|
|
|
+ // TerminalStru ts = new TerminalStru
|
|
|
+ // {
|
|
|
+ // terminalID = (short)terminalInfo[i].terminalID,
|
|
|
+ // paymentStatus = -1,
|
|
|
+ // parkingFee = -1,
|
|
|
+ // userType = -1
|
|
|
+ // };
|
|
|
+ // //注册用户
|
|
|
+ // if (term.btnStatus == (short)2)
|
|
|
+ // {
|
|
|
+ // int userID = term.licenseCodeA;
|
|
|
+ // string userLicense = GetLicenseFromTerm(term);
|
|
|
+ // //与云端数据比对
|
|
|
+ // ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
|
|
|
+ // if (numReceivedStatus == 2)
|
|
|
+ // {
|
|
|
+ // idLicMap.Remove(terminalInfo[i].terminalID);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //非注册用户
|
|
|
+ // else if (term.btnStatus == (short)1)
|
|
|
+ // {
|
|
|
+ // numReceivedStatus = 1;
|
|
|
+ // ts.licVerification = 1;
|
|
|
+ // Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
|
|
|
+ // }
|
|
|
+ // //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
|
|
|
+ // MainBlockStru mb = new MainBlockStru
|
|
|
+ // {
|
|
|
+ // licenseReceived = (short)numReceivedStatus
|
|
|
+ // };
|
|
|
+ // Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
|
|
|
+ // //号牌获取结果被清零才跳出
|
|
|
+ // Monitor.Monitor.SetNotification("已写入号牌获取结果,等待号牌机启动指令清零");
|
|
|
+ // }
|
|
|
+ // while (term.numMachineLaunch != 0)
|
|
|
+ // {
|
|
|
+ // Thread.Sleep(1000);
|
|
|
+ // }
|
|
|
+ // Monitor.Monitor.SetNotification("号牌机启动指令已被清零");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ #endregion
|
|
|
|
|
|
- TerminalStru ts = new TerminalStru
|
|
|
- {
|
|
|
- terminalID = (short)terminalInfo[i].terminalID,
|
|
|
- paymentStatus = -1,
|
|
|
- parkingFee = -1,
|
|
|
- userType = -1
|
|
|
- };
|
|
|
- //注册用户
|
|
|
- if (term.btnStatus == (short)2)
|
|
|
- {
|
|
|
- int userID = term.licenseCodeA;
|
|
|
- string userLicense = GetLicenseFromTerm(term);
|
|
|
- //与云端数据比对
|
|
|
- ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
|
|
|
- if (numReceivedStatus == 2)
|
|
|
- {
|
|
|
- idLicMap.Remove(terminalInfo[i].terminalID);
|
|
|
- }
|
|
|
- }
|
|
|
- //非注册用户
|
|
|
- else if (term.btnStatus == (short)1)
|
|
|
- {
|
|
|
- numReceivedStatus = 1;
|
|
|
- ts.licVerification = 1;
|
|
|
- Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
|
|
|
- }
|
|
|
- //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
|
|
|
- MainBlockStru mb = new MainBlockStru
|
|
|
- {
|
|
|
- licenseReceived = (short)numReceivedStatus
|
|
|
- };
|
|
|
- Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
|
|
|
- //号牌获取结果被清零才跳出
|
|
|
- Monitor.Monitor.SetNotification("已写入号牌获取结果,等待号牌机启动指令清零");
|
|
|
- }
|
|
|
- while (Monitor.Monitor.mainBlockInfo.numMachineLaunch != 0)
|
|
|
- {
|
|
|
- Thread.Sleep(1000);
|
|
|
- }
|
|
|
- Monitor.Monitor.SetNotification("号牌机启动指令已被清零");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
/// <summary>
|
|
|
/// 停车流程,收到PLC停车完成信号后操作过程
|
|
|
/// </summary>
|
|
@@ -594,7 +604,99 @@ namespace Terminal
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 预约车辆检测
|
|
|
+ /// </summary>
|
|
|
+ private static void ReservedCarCheck()
|
|
|
+ {
|
|
|
+ if (lockList.Count != terminalInfo.Count)
|
|
|
+ {
|
|
|
+ lockList.Clear();
|
|
|
+ for (int i = 0; i < terminalInfo.Count; i++)
|
|
|
+ {
|
|
|
+ lockList.Add(new object());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //找到停车终端,且有地感无按钮数据
|
|
|
+ for (int i = 0; i < terminalInfo.Count; i++)
|
|
|
+ {
|
|
|
+ if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0)
|
|
|
+ {
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ lock (lockList[i])
|
|
|
+ {
|
|
|
+ string license = "";
|
|
|
+ int countdown = 2;
|
|
|
+ short registered = 4;
|
|
|
+ while (license == "" && countdown-- > 0)
|
|
|
+ {
|
|
|
+ license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
|
|
|
+ }
|
|
|
+ if (license != "")
|
|
|
+ {
|
|
|
+ //map中加入或更新号牌,供完成时写入数据库用
|
|
|
+ if (idLicMap.ContainsKey(terminalInfo[i].terminalID))
|
|
|
+ {
|
|
|
+ idLicMap[terminalInfo[i].terminalID] = license;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ idLicMap.Add(terminalInfo[i].terminalID, license);
|
|
|
+ }
|
|
|
+ if (Monitor.Monitor.webServer.ReservedCarCheck(license))
|
|
|
+ {
|
|
|
+ registered = 3;
|
|
|
+ }
|
|
|
+ #region 通过数据库查询是否预约车,方法待定
|
|
|
+ //int vehicleState = -1;
|
|
|
+ //string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
|
|
|
+ //MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
|
|
|
+ //if (reader != null)
|
|
|
+ //{
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // if (reader.Read())
|
|
|
+ // {
|
|
|
+ // vehicleState = reader.GetInt32("vehiclepParkState");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // reader.Close();
|
|
|
+ // reader.Dispose();
|
|
|
+ // }
|
|
|
+ // catch { }
|
|
|
+ //}
|
|
|
+ //已预约车辆入场
|
|
|
+ //if (vehicleState == 4)
|
|
|
+ //{
|
|
|
+ // registered = 3;
|
|
|
+ //}
|
|
|
+ #endregion
|
|
|
+ TerminalStru ts = new TerminalStru
|
|
|
+ {
|
|
|
+ terminalID = terminalInfo[i].terminalID,
|
|
|
+ paymentStatus = (short)-1,
|
|
|
+ btnStatus = registered,
|
|
|
+ cmd = (short)-1,
|
|
|
+ licenseCodeA = -1,
|
|
|
+ licenseCodeB = -1,
|
|
|
+ licenseCodeC = -1,
|
|
|
+ licenseCodeD = -1,
|
|
|
+ receiptNum = -1
|
|
|
+ };
|
|
|
+ Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
|
|
|
+ }
|
|
|
+ Thread.Sleep(500);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 停车相关操作
|
|
|
/// 0.观测到地感信号,且按钮状态不为3,则启动号牌机获取号牌,并判断是否预约车
|
|
@@ -606,21 +708,21 @@ namespace Terminal
|
|
|
///
|
|
|
private static void ParkProcess()
|
|
|
{
|
|
|
- Task.Factory.StartNew(() =>
|
|
|
- {
|
|
|
- while (!isClosing)
|
|
|
- {
|
|
|
- ParkNumSubProcess();
|
|
|
- Thread.Sleep(Monitor.Monitor.plcRefreshInterval*5);
|
|
|
- }
|
|
|
- });
|
|
|
+ //Task.Factory.StartNew(() =>
|
|
|
+ //{
|
|
|
+ // while (!isClosing)
|
|
|
+ // {
|
|
|
+ // ParkNumSubProcess();
|
|
|
+ // Thread.Sleep(Monitor.Monitor.plcRefreshInterval*5);
|
|
|
+ // }
|
|
|
+ //});
|
|
|
|
|
|
Task.Factory.StartNew(() =>
|
|
|
{
|
|
|
while (!isClosing)
|
|
|
{
|
|
|
ParkCompleteSubProcess();
|
|
|
- Thread.Sleep(Monitor.Monitor.plcRefreshInterval*5);
|
|
|
+ Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -629,7 +731,7 @@ namespace Terminal
|
|
|
while (!isClosing)
|
|
|
{
|
|
|
ReservedCarCheck();
|
|
|
- Thread.Sleep(Monitor.Monitor.plcRefreshInterval*5);
|
|
|
+ Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -1072,59 +1174,12 @@ namespace Terminal
|
|
|
|
|
|
}
|
|
|
|
|
|
- private static void ReservedCarCheck()
|
|
|
+ public static void Start()
|
|
|
{
|
|
|
- //找到停车终端,且有地感
|
|
|
- for (int i = 0; i < terminalInfo.Count; i++)
|
|
|
+ for (int i = 0; i < Monitor.Monitor.plcTerminalCount; i++)
|
|
|
{
|
|
|
- if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0)
|
|
|
- {
|
|
|
- string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
|
|
|
- int vehicleState = -1;
|
|
|
- string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
|
|
|
- MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
|
|
|
- if (reader != null)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- if (reader.Read())
|
|
|
- {
|
|
|
- vehicleState = reader.GetInt32("vehiclepParkState");
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
|
|
|
- try
|
|
|
- {
|
|
|
- reader.Close();
|
|
|
- reader.Dispose();
|
|
|
- }
|
|
|
- catch { }
|
|
|
- }
|
|
|
- short registered = 4;
|
|
|
- //已预约车辆入场
|
|
|
- if (vehicleState == 4)
|
|
|
- {
|
|
|
- registered = 3;
|
|
|
- }
|
|
|
- TerminalStru ts = new TerminalStru
|
|
|
- {
|
|
|
- terminalID = terminalInfo[i].terminalID,
|
|
|
- paymentStatus = (short)-1,
|
|
|
- btnStatus = registered,
|
|
|
- cmd = (short)-1,
|
|
|
- licenseCodeA = -1,
|
|
|
- licenseCodeB = -1,
|
|
|
- licenseCodeC = -1,
|
|
|
- licenseCodeD = -1,
|
|
|
- receiptNum = -1
|
|
|
- };
|
|
|
- Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
|
|
|
- }
|
|
|
+ lockList.Add(new object());
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- public static void Start()
|
|
|
- {
|
|
|
ParkProcess();
|
|
|
FetchProcess();
|
|
|
}
|