123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using nettyCommunication;
- using parkMonitor.LOG;
- using PLCS7;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Terminal
- {
- public class TerminalSimul
- {
- public static bool stopSimul = false;
- /// <summary>
- /// 停车终端模拟操作
- /// </summary>
- /// <returns>0成功 1寻找车辆停放位置失败 2生成凭证号失败 3凭证转换异常 4停车码解析异常 5地感异常 6终端状态异常 7指令占用异常 8其他异常</returns>
- public static int ParkTermOper(int id, string carInfo)
- {
- int countdown = 10;
- int index = -1;
- for (int i = 0; i < Terminal.terminalInfo.Count; i++)
- {
- if (Terminal.terminalInfo[i].terminalID == id)
- {
- index = i;
- break;
- }
- }
- if (index == -1)
- return 1;
- while (!stopSimul && countdown-- > 0)
- {
- //判断终端块是否有地感、为停车终端、空闲中,之后发送停车指令
- if (Terminal.terminalInfo[index].groundStatus == 1
- && Terminal.terminalInfo[index].terminalStatus == 1
- && Terminal.terminalInfo[index].cmd == 0)
- {
- string receiptNum = Credence.GetOneCredence();
- if (receiptNum == "")
- {
- Log.WriteLog(LogType.process, LogFile.ERROR, "未能获取凭证号");
- return 2;
- }
- TerminalStru ts = new TerminalStru();
- ts.terminalID = (short)id;
- ts.paymentStatus = (short)-1;
- ts.btnStatus = Terminal.terminalInfo[index].btnStatus == 3 ? (short)3 : (short)2;
- ts.cmd = 1;
- if (!int.TryParse(receiptNum, out ts.receiptNum))
- {
- Log.WriteLog(LogType.process, LogFile.ERROR, "凭证转换错误");
- return 3;
- }
- if (!licenseCodeEncoding(carInfo, ref ts))
- return 4;
- if(Monitor.Monitor.ins.GetFreeSpaceCount(1) == 0)
- {
- return 9;
- }
- Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
- return 0;
- }
- Thread.Sleep(300);
- }
- if (Terminal.terminalInfo[1].groundStatus != 1)
- {
- return 5;
- }
- else if (Terminal.terminalInfo[1].terminalStatus != 1)
- {
- return 6;
- }
- else if (Terminal.terminalInfo[1].cmd != 0)
- {
- return 7;
- }
- return 8;
- }
- /// <summary>
- /// 用户与车辆信息编码写入PLC
- /// </summary>
- /// <param name="ts"></param>
- private static bool licenseCodeEncoding(string msg, ref TerminalStru ts)
- {
- int a = 0, b = 0, c = 0, d = 0;
- //字符串分割
- try
- {
- string[] array = msg.Split('.');
- string str1 = array[0];
- string str2 = array[1];
- string s1 = str2.Substring(0, 4);
- string s2 = str2.Substring(4, 4);
- string s3 = str2.Substring(8, str2.Length - 8);
- a = BitConverter.ToInt32(Encoding.ASCII.GetBytes(s1), 0);
- b = BitConverter.ToInt32(Encoding.ASCII.GetBytes(s2), 0);
- if (s3 != null && s3 != "" && s3 != string.Empty)
- {
- c = BitConverter.ToInt32(Encoding.ASCII.GetBytes(s3), 0);
- }
- else
- {
- c = 0;
- }
- d = Convert.ToInt32(str1);
- ts.licenseCodeA = d;
- ts.licenseCodeB = a;
- ts.licenseCodeC = b;
- ts.licenseCodeD = c;
- return true;
- }
- catch (Exception ex)
- {
- Log.WriteLog(LogType.process, LogFile.ERROR, "错误码7:停车码异常,解析失败。" + ex.StackTrace);
- return false;
- }
- }
- /// <summary>
- /// 取车终端模拟操作
- /// </summary>
- /// <param name="receiptNum"></param>
- /// <returns>0成功 1地感异常 2终端状态异常 3指令占用异常 4凭证解析异常 5其他异常</returns>
- public static int FetchTermOper(string receiptNum)
- {
- ////定位2号终端
- //int index = 0;
- //for (int i = 0; i < Terminal.terminalInfo.Count; i++)
- //{
- // if (Terminal.terminalInfo[i].terminalID == 2)
- // {
- // index = i;
- // break;
- // }
- //}
- int countdown = 10;
- while (!stopSimul && countdown-- > 0)
- {
- //判断终端块是否有地感、为取车终端、空闲中,之后发送取车指令
- if (Terminal.terminalInfo[1].groundStatus == 0
- && Terminal.terminalInfo[1].terminalStatus == 2
- && Terminal.terminalInfo[1].cmd == 0)
- {
- TerminalStru ts = new TerminalStru();
- ts.terminalID = 2;
- try
- {
- ts.receiptNum = int.Parse(receiptNum);
- }
- catch { return 4; }
- ts.paymentStatus = 2;//强制支付完成
- ts.btnStatus = (short)-1;
- ts.cmd = 2;
- ts.licenseCodeA = -1;
- ts.licenseCodeB = -1;
- ts.licenseCodeC = -1;
- ts.licenseCodeD = -1;
- Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
- return 0;
- }
- Thread.Sleep(300);
- }
- if (Terminal.terminalInfo[1].groundStatus != 0)
- {
- return 1;
- }else if(Terminal.terminalInfo[1].terminalStatus != 2)
- {
- return 2;
- }else if(Terminal.terminalInfo[1].cmd != 0)
- {
- return 3;
- }
- return 5;
- }
- }
- }
|