Ejemplo n.º 1
0
        /// <summary>
        /// 处理请求用户信息
        /// </summary>
        /// <param name="response"></param>
        /// <param name="frameBean"></param>
        private void HandleRequestUserInfo(ref byte[] response, TcpFrameBean frameBean)
        {
            byte[] body   = frameBean.DataBody;
            string idcard = ProtocolUtil.GetEndUserIdString(body, 0);

            byte[] data = MakerTCPFrame.GetInstance().Make800AFrame(idcard);

            response = MakerTCPFrame.GetInstance().PackData(MsgId.X800A, frameBean.TerminalId, data);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 处理心跳
 /// </summary>
 /// <param name="response"></param>
 /// <param name="frameBean"></param>
 public void HandleHeartBeat(ref byte[] response, TcpFrameBean frameBean)
 {
     try
     {
         onlineDeviceService.SavaOrUpdateOnlineInfo(frameBean);
     }catch (Exception ex)
     {
         logger.Error("心跳更新或存储在线时间时发生异常:" + ex.ToString());
     }
     byte[] data = MakerTCPFrame.GetInstance().Make8001Frame(frameBean.SerialNo, frameBean.MsgId, CommResponse.Success);
     response = MakerTCPFrame.GetInstance().PackData(MsgId.X8001, frameBean.TerminalId, data);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理请求处方信息
        /// </summary>
        /// <param name="response"></param>
        /// <param name="frameBean"></param>
        public void HandleStartPrictice(ref byte[] response, TcpFrameBean frameBean)
        {
            var maker = MakerTCPFrame.GetInstance();;

            byte[] data   = frameBean.DataBody;
            string userId = ProtocolUtil.GetEndUserIdString(data, 0);

            DeviceType deviceType = (DeviceType)data[32];

            byte[] d = maker.Make8008Frame(userId, deviceType);
            response = MakerTCPFrame.GetInstance().PackData(MsgId.X8008, frameBean.TerminalId, d);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 处理训练结果上报
        /// </summary>
        /// <param name="response"></param>
        /// <param name="frameBean"></param>
        private void HandlePricticeResult(ref byte[] response, TcpFrameBean frameBean)
        {
            ParserPricticeResult paser = new ParserPricticeResult();

            byte[] body   = frameBean.DataBody;
            string idCard = ProtocolUtil.GetEndUserIdString(body, 0);

            byte[] d = new byte[body.Length - 32];
            Array.Copy(body, 32, d, 0, d.Length);
            //设备类型
            DeviceType deviceType = (DeviceType)d[0];

            logger.Info("收到训练结果上报,设备是:" + deviceType.ToString());

            paser.PaserXall(d, idCard, deviceType);
            //数据上报响应通用应答
            byte[] data = MakerTCPFrame.GetInstance().Make8001Frame(frameBean.SerialNo, frameBean.MsgId, CommResponse.Success);
            response = MakerTCPFrame.GetInstance().PackData(MsgId.X8001, frameBean.TerminalId, data);
        }
Ejemplo n.º 5
0
        public byte[] Parser(byte[] source)
        {
            byte[] response = new byte[0];

            byte[] buffer   = ProtocolUtil.UnTransfer(source);
            MsgId  msgId    = ProtocolUtil.BytesToMsgId(buffer, 0);
            Int16  data_len = BitConverter.ToInt16(buffer, 2);

            data_len = IPAddress.NetworkToHostOrder(data_len);
            string terminalId = ProtocolUtil.BcdToString(buffer, 4, 6);
            Int16  serialNo   = BitConverter.ToInt16(buffer, 10);

            serialNo = IPAddress.NetworkToHostOrder(serialNo);
            byte xor = buffer[12 + data_len];

            //数据体
            byte[] data = new byte[data_len];

            Array.Copy(buffer, 12, data, 0, data_len);

            byte calcXor = ProtocolUtil.XorByByte(buffer, 0, 12 + data_len);

            TcpFrameBean frameBean = new TcpFrameBean();

            frameBean.DataBody   = data;
            frameBean.SerialNo   = serialNo;
            frameBean.TerminalId = terminalId;
            frameBean.MsgId      = msgId;
            frameBean.DeviceType = (DeviceType)buffer[4];
            if (xor != calcXor)
            {
                logger.Error("校验码不符合预期:" + ProtocolUtil.BytesToString(source));

                frameBean.AppendErrorMsg("校验码不符合预期");
                byte[] d = MakerTCPFrame.GetInstance().Make8001Frame(serialNo, MsgId.X0001, CommResponse.MistakeMsg);
                response = MakerTCPFrame.GetInstance().PackData(MsgId.X8001, frameBean.TerminalId, d);
                return(response);
            }

            switch (msgId)
            {
            case MsgId.X0001:    //设备通用应答
                break;

            case MsgId.X0002:    //心跳OK
                logger.Info("收到心跳:" + ProtocolUtil.BytesToString(source));
                WriteLogFile("收到心跳:" + ProtocolUtil.BytesToString(source));
                HandleHeartBeat(ref response, frameBean);
                break;

            case MsgId.X0008:    //开始训练
                logger.Info("收到开始训练请求:" + ProtocolUtil.BytesToString(source));
                WriteLogFile("收到开始训练请求:" + ProtocolUtil.BytesToString(source));
                HandleStartPrictice(ref response, frameBean);
                break;

            case MsgId.X0009:    //训练结果上报
                logger.Info("收到训练结果上报:" + ProtocolUtil.BytesToString(source));
                WriteLogFile("收到训练结果上报:" + ProtocolUtil.BytesToString(source));
                byte[] dd = MakerTCPFrame.GetInstance().Make8001Frame(serialNo, MsgId.X0001, CommResponse.Success);
                response = MakerTCPFrame.GetInstance().PackData(MsgId.X8001, frameBean.TerminalId, dd);
                HandlePricticeResult(ref response, frameBean);
                break;

            case MsgId.X000A:    //请求使用者信息
                logger.Info("收到请求使用者信息:" + ProtocolUtil.BytesToString(source));
                WriteLogFile("收到请求使用者信息:" + ProtocolUtil.BytesToString(source));

                HandleRequestUserInfo(ref response, frameBean);
                break;

            case MsgId.X0007:    //请求照片数据OK
                logger.Info("收到请求照片数据OK:" + ProtocolUtil.BytesToString(source));
                WriteLogFile("收到请求照片数据OK:" + ProtocolUtil.BytesToString(source));
                HandleRequestImageData(ref response, frameBean);
                break;

            default:
                logger.Error("收到未知消息:" + ProtocolUtil.BytesToString(source));
                WriteLogFile("收到未知消息:" + ProtocolUtil.BytesToString(source));
                frameBean.AppendErrorMsg("未知的消息ID");
                byte[] d = MakerTCPFrame.GetInstance().Make8001Frame(serialNo, MsgId.X0001, CommResponse.UnSupport);
                response = MakerTCPFrame.GetInstance().PackData(MsgId.X8001, frameBean.TerminalId, d);
                break;
            }
            logger.Info("响应的报文:" + ProtocolUtil.BytesToString(response));
            WriteLogFile("响应的报文:" + ProtocolUtil.BytesToString(response));
            return(response);
        }