public override void ExecuteCommand(MySession session, StringRequestInfo requestInfo) { AuthorizationRequest real = Analysis.analysisAuthorizationReq(requestInfo); if (RealTimeThread.dic.ContainsKey(real.TerminalId)) { CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo; if (info == null) { info.Power = int.Parse(real.Power); info.Voltage = int.Parse(real.Voltage); info.Current = int.Parse(real.Current); info.Temperature = int.Parse(real.Temperature); RealTimeThread.dic[real.TerminalId] = info; } } else { CarInfo c = new CarInfo(); c.Power = int.Parse(real.Power); c.Voltage = int.Parse(real.Voltage); c.Current = int.Parse(real.Current); c.Temperature = int.Parse(real.Temperature); RealTimeThread.dic.Add(real.TerminalId, c); } if (real != null) { byte[] head = new byte[] { 0xd3, 0xd3 }; byte[] outs = db_realtime.uploadAuthorization(real); session.Send(head, 0, head.Length); session.Send(outs, 0, outs.Length); } }
public void Authorization() { try { LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 收到终端授权请求"); Stream inputStream = Request.GetBufferedInputStream(); Stream outputStream = Response.OutputStream; AuthorizationRequest real = RealTimeAnalysis.analysisAuthorizationReq(inputStream); if (RealTimeThread.dic.ContainsKey(real.TerminalId)) { CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo; if (info == null) { info.Power = int.Parse(real.Power); info.Voltage = int.Parse(real.Voltage); info.Current = int.Parse(real.Current); info.Temperature = int.Parse(real.Temperature); RealTimeThread.dic[real.TerminalId] = info; } } else { CarInfo c = new CarInfo(); c.Power = int.Parse(real.Power); c.Voltage = int.Parse(real.Voltage); c.Current = int.Parse(real.Current); c.Temperature = int.Parse(real.Temperature); RealTimeThread.dic.Add(real.TerminalId, c); } if (real != null) { byte[] outs = orderbll.uploadAuthorization(real); Thread.Sleep(1000); if (outs != null) { outputStream.WriteByte(0xd3); outputStream.WriteByte(0xd3); outputStream.Write(outs, 0, outs.Length); LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 下发终端授权响应" + ByteUtils.byteToHexStr(outs)); //修改订单状态为已使用 outputStream.Flush(); } } outputStream.Close(); inputStream.Close(); }catch (Exception e) { LogerHelper.exception("error occured!", e); } }