public Recv机头地址动态分配(FrameData data) { try { RecvData = data; if (data.commandData.Length >= 8) { List <byte> mid = new List <byte>(data.commandData); UInt64 ui64 = BitConverter.ToUInt64(mid.ToArray(), 0); MCUID = Convert.ToString((long)ui64, 16).ToUpper().Substring(0, 14); //if (!SecrityHeadInfo.CheckHead(MCUID)) return; Ask.Ask机头地址动态分配 ask = new Command.Ask.Ask机头地址动态分配(data.Code, MCUID); 机头地址 = PubLib.Hex2String(ask.机头地址); byte[] readyToSend = PubLib.GetBytesByObject(ask); SendData = PubLib.GetFrameDataBytes(data, readyToSend, CommandType.机头地址动态分配应答); SendDataTime = DateTime.Now; LogHelper.WriteLogSpacail(string.Format("{0} 申请地址 {1}", MCUID, 机头地址)); } } catch { throw; } }
//public void RunCallBack(IAsyncResult ar) //{ // AsyncResult result = (AsyncResult)ar; // DelegRun d = (DelegRun)result.AsyncDelegate; // d.EndInvoke(ar); //} public Recv机头网络状态报告(FrameData data) { //RecvData = data; //DelegRun a = Run; //a.BeginInvoke(data, new AsyncCallback(RunCallBack), null); Run(data); SendData = PubLib.GetFrameDataBytes(data, null, CommandType.机头网络状态报告应答); SendDate = DateTime.Now; }
public Recv游戏机参数申请(FrameData data) { try { 机头地址 = PubLib.Hex2String(data.commandData[0]); CloudRS232Server.Info.HeadInfo.机头绑定信息 bind = new Info.HeadInfo.机头绑定信息(); bind.控制器令牌 = data.Code; bind.短地址 = 机头地址; Info.HeadInfo.机头信息 head = Info.HeadInfo.GetHeadInfoByShort(bind); if (head != null) { switch (head.类型) { case Info.HeadInfo.设备类型.存币机: case Info.HeadInfo.设备类型.提_售币机: IsDevice = true; Ask.Ask设备参数申请 askData1 = new Ask.Ask设备参数申请(bind); 应答数据 = askData1; break; default: IsDevice = false; Ask.Ask终端参数申请 askData2 = new Command.Ask.Ask终端参数申请(bind); 应答数据 = askData2; break; } byte[] dataBuf = PubLib.GetBytesByObject(应答数据); SendData = PubLib.GetFrameDataBytes(data, dataBuf, CommandType.游戏机参数申请应答); RecvData = data; } } catch { throw; } }
public Recv卡头进出币数据(FrameData f, DateTime RecvDateTime) { try { RecvData = f; if (f.commandData.Length >= 15) { 机头地址 = PubLib.Hex2String(f.commandData[0]); for (int i = 0; i < 8; i++) { if (f.commandData[i + 1] < 0x30 || f.commandData[i + 1] > 0x39) { f.commandData[i + 1] = 32; } } IC卡号码 = Encoding.ASCII.GetString(f.commandData, 1, 8); IC卡号码 = IC卡号码.Trim(); 动态密码 = f.commandData[9]; 控制类型 = (CoinType)f.commandData[10]; 币数 = (int)BitConverter.ToUInt16(f.commandData, 11); 测试数据 = BitConverter.ToUInt16(f.commandData, 13); 流水号 = BitConverter.ToUInt16(f.commandData, 15); 高速投币标志 = (测试数据 / 256 == 1); 投币目标地址 = PubLib.Hex2String((byte)(测试数据 % 256)); Info.HeadInfo.机头绑定信息 bind = new Info.HeadInfo.机头绑定信息(); bind.控制器令牌 = f.Code; bind.短地址 = 机头地址; Info.HeadInfo.机头信息 head = Info.HeadInfo.GetHeadInfoByShort(bind); if (head != null) { if (IC卡号码 == "") IC卡号码 = head.常规.当前卡片号; if (IC卡号码 == "") IC卡号码 = "0"; if (控制类型 == CoinType.实物投币) IC卡号码 = "0"; //实物投币过滤卡号,有可能是卡头没有清缓存导致 head.临时错误计数 = 测试数据; head.状态.出币机或存币机正在数币 = false; object obj = null; int res = UDPServerHelper.CheckRepeat(f.Code, 机头地址, IC卡号码, CommandType.IC卡模式投币数据, ref obj, 流水号); if (res == 0) { //if (高速投币标志) // Ask.Ask远程投币上分数据 ask = new Ask.Ask远程投币上分数据(投币目标地址, 币数, "刷卡", 流水号); string msg = ""; 应答数据 = new Ask.Ask卡头进出币数据应答(head, IC卡号码, 币数, 控制类型, 动态密码, (UInt16)流水号, f, 高速投币标志, 投币目标地址, ref msg); if (f.commandType == CommandType.IC卡模式投币数据) { UDPServerHelper.InsertRepeat(f.routeAddress, 机头地址, IC卡号码, CommandType.IC卡模式投币数据, CommandType.IC卡模式投币数据应答, 应答数据, 流水号, RecvDateTime); if (应答数据.脉冲数 == 0) { LogHelper.WriteLog("IC卡进出币数据有误\r\n" + msg, f.commandData); } } else UDPServerHelper.InsertRepeat(f.routeAddress, 机头地址, IC卡号码, CommandType.IC卡模式退币数据, CommandType.IC卡模式退币数据应答, 应答数据, 流水号, RecvDateTime); } else if (res == 1) { 应答数据 = (Ask.Ask卡头进出币数据应答)obj; PubLib.当前IC卡进出币指令重复数++; } else { //重复性检查错误 return; } byte[] dataBuf = PubLib.GetBytesByObject(应答数据); if (f.commandType == CommandType.IC卡模式投币数据) SendData = PubLib.GetFrameDataBytes(f, dataBuf, CommandType.IC卡模式投币数据应答); else { SendData = PubLib.GetFrameDataBytes(f, dataBuf, CommandType.IC卡模式退币数据应答); LogHelper.WriteTBLog(PubLib.BytesToString(f.recvData)); } } } } catch { //LogHelper.WriteLog("IC卡进出币数据有误", f.commandData); throw; } }
public Recv机头卡片报警指令(FrameData f, DateTime RecvDateTime) { RecvData = f; 机头地址 = PubLib.Hex2String(f.commandData[0]); if (f.commandLength < 12) { return; } IC卡号码 = Encoding.ASCII.GetString(f.commandData, 1, 8); IC卡号码 = IC卡号码.Replace("\0", ""); int cardid = 0; if (!int.TryParse(IC卡号码, out cardid)) { IC卡号码 = "0"; } 卡片类型 = f.commandData[9]; 报警类别 = f.commandData[10]; 处理结果 = f.commandData[11]; AlertType = ""; switch (报警类别) { case 0: AlertType = "用户异常退币报警"; break; case 1: AlertType = "非法专卡专用解锁"; break; case 2: AlertType = "专卡专用解锁"; break; case 3: AlertType = "非法送分券解锁"; break; case 4: AlertType = "常规解锁"; break; case 5: AlertType = "退币锁定"; break; default: AlertType = "未知错误报警"; break; } 流水号 = BitConverter.ToUInt16(f.commandData, 12); Info.HeadInfo.机头绑定信息 bind = new Info.HeadInfo.机头绑定信息(); bind.控制器令牌 = f.Code; bind.短地址 = 机头地址; Info.HeadInfo.机头信息 机头 = Info.HeadInfo.GetHeadInfoByShort(bind); string 管理卡号 = "0"; if (机头 != null) { 管理卡号 = 机头.常规.管理卡号; } if (!int.TryParse(管理卡号, out cardid)) { 管理卡号 = "0"; } object obj = null; //DataAccess ac = new DataAccess(); int res = UDPServerHelper.CheckRepeat(f.Code, 机头地址, IC卡号码, CommandType.机头卡片报警指令, ref obj, 流水号); if (res == 0) { switch (报警类别) { case 0: case 1: int d = 0; if (!int.TryParse(管理卡号, out d)) { 管理卡号 = "0"; } if (!int.TryParse(IC卡号码, out d)) { IC卡号码 = "0"; } string sql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),null,0,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); //ac.Execute(sql); XCCloudRS232BLL.ExecuteSql(sql); break; case 2: { //if (卡片类型 == 1) //管理卡 { if (机头.状态.超级解锁卡标识) { AlertType = "超级卡解锁专卡专用解锁"; } string dbsql = ""; if (!机头.状态.超级解锁卡标识 && 处理结果 == 1) //普通卡,处理结果成功的直接写2 { dbsql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),GETDATE(),2,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); } else { dbsql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),null,0,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); } //ac.Execute(dbsql); XCCloudRS232BLL.ExecuteSql(dbsql); } string IC = 机头.常规.当前卡片号; //if (Info.CoinInfo.被动退分解锁队列.ContainsKey(IC)) //{ // if (处理结果 == 0) // { // Info.CoinInfo.被动退分解锁队列[IC].是否允许退分标识 = false; // Info.CoinInfo.被动退分解锁队列[IC].错误信息 = string.Format("机头编号:{0} 有分;", 机头.常规.机头长地址); // } // else // { // 机头.常规.当前卡片号 = ""; // } // Info.CoinInfo.被动退分解锁队列[IC].当前序号++; // if (Info.CoinInfo.被动退分解锁队列[IC].当前序号 >= Info.CoinInfo.被动退分解锁队列[IC].机头列表.Count) // { // //发送完毕 // //ServiceDll.ClientCall.远程强制退分应答(Info.CoinInfo.被动退分解锁队列[IC].错误信息, IC, (Info.CoinInfo.被动退分解锁队列[IC].错误信息 == "")); // //StringBuilder sb1 = new StringBuilder(); // //sb1.Append("=============================================\r\n"); // //sb1.AppendFormat("{0:yyyy-MM-dd HH:mm:ss.fff} 远程强制退分应答\r\n", DateTime.Now); // //sb1.AppendFormat("IC卡号:{0}\r\n", IC); // //sb1.AppendFormat("结果:{0}\r\n", Info.CoinInfo.被动退分解锁队列[IC].错误信息); // //UIClass.接收内容 = sb1.ToString(); // } //} } break; case 3: { 机头.状态.是否正在使用限时送分优惠 = (处理结果 == 1); 机头.常规.是否为首次投币 = (处理结果 == 1); if (处理结果 == 0) { string qsql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),null,0,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); //ac.Execute(qsql); XCCloudRS232BLL.ExecuteSql(qsql); } else { if (机头.状态.超级解锁卡标识) //超级管理卡 { string dbsql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),null,0,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); //ac.Execute(dbsql); XCCloudRS232BLL.ExecuteSql(dbsql); } else { AlertType = "解锁限时送分"; string dbsql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),GETDATE(),2,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); //ac.Execute(dbsql); XCCloudRS232BLL.ExecuteSql(dbsql); } } } break; case 4: //常规解锁,解除报警,修改数据库 { if (机头.状态.超级解锁卡标识) //超级管理卡 { AlertType = "超级卡解锁常规锁定"; string dbsql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),null,0,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); //ac.Execute(dbsql); XCCloudRS232BLL.ExecuteSql(dbsql); } string usql = string.Format("update flw_game_alarm set EndTime=GETDATE(),ICCardID='{2}',`state`=1 where `state`=0 and LockGame=1 and MerchID='{0}' and DeviceID='{1}'", 机头.商户号, 机头.常规.机头编号, 管理卡号); //ac.Execute(usql); XCCloudRS232BLL.ExecuteSql(usql); } break; case 5: { if (机头.状态.超级解锁卡标识) //超级管理卡 { AlertType = "超级卡解锁退币锁定"; string dbsql = string.Format("INSERT INTO flw_game_alarm VALUES ('{0}','{1}','{2}','{3}',GETDATE(),null,0,0,0,'会员卡号:{4}')", 管理卡号, 机头.商户号, 机头.常规.机头编号, AlertType, IC卡号码); //ac.Execute(dbsql); XCCloudRS232BLL.ExecuteSql(dbsql); } } break; default: break; } if (处理结果 == 1) { 机头.常规.当前卡片号 = ""; } 应答数据 = new Ask.Ask机头卡片报警指令(机头地址, 流水号); UDPServerHelper.InsertRepeat(f.routeAddress, 机头地址, IC卡号码, CommandType.机头卡片报警指令, CommandType.机头卡片报警指令应答, 应答数据, 流水号, RecvDateTime); } else if (res == 1) { 应答数据 = (Ask.Ask机头卡片报警指令)obj; } else { //重复性检查出错 return; } byte[] dataBuf = PubLib.GetBytesByObject(应答数据); SendData = PubLib.GetFrameDataBytes(f, dataBuf, CommandType.机头卡片报警指令应答); SendDataTime = DateTime.Now; }