Example #1
0
        /// <summary>
        /// 处理GPS中心收到的GPS终端数据
        /// </summary>
        /// <param name="deliver">传入的数据结构</param>
        /// <param name="entity">输出的数据结构</param>
        public void DealWithDeliver(YaXunDeliverData deliver,ref GPSDataEntity entity)
        {
            byte[]buffer = null;

            //业务类型
            switch (deliver.businessType)
            {
                #region 线路监控
                case BusinessType.CircuitMonitor:

                    switch (deliver.dataType)
                    {
                        //监控数据
                        case DataType.MonitorData:
                        //移动台主动上报数据
                        case DataType.SubmitData:

                            int length = deliver.data.Length;

                            string msg = Transfer.ToHexString(deliver.data);

                            //解析监控数据
                            //1. 报警类型2字节---------------------------------------------
                            buffer = new byte[2];

                            Array.Copy(deliver.data, 0, buffer, 0, 2);

                            AlarmTypeParser(buffer,ref entity);

                            //2. 监控中心个数1字节-----------------------------------------
                            int number = deliver.data[2];
                            //3. gps数据---------------------------------------------------
                            buffer = new byte[length - 3];
                            Array.Copy(deliver.data, 3, buffer, 0, buffer.Length);

                            //解析GPS数据
                            GPSDataParser(buffer, ref entity);

                            //协议上有说这两个字段为新加,但从传上来的数据来看,没有此两个字段的数据
                            ////4. 报警区域编号1字节-----------------------------------------
                            //byte alarmAreaNum = deliver.data[length - 2];
                            ////5. 报警路线编号2字节-----------------------------------------
                            //byte alarmRutineNum = deliver.data[length - 1];


                            break;

                        //监控请求
                        case DataType.MonitorReq:
                            
                            //.......................................
                            //解析求助请求数据
                            AppealReqParser(deliver.data,ref entity);

                            break;

                        //监控请求应答数据
                        case DataType.MonitorReqAck:

                            entity.IsLocatedData = false;

                            //监控请成功
                            if (deliver.data[0] == 0x01)
                            { 
                                //解析GPS数据
                                byte[] data = deliver.data;

                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //解析数据分失
                            }

                            break;

                        //撤销监控请求应答
                        case DataType.CancelMonitorAck:

                            break;

                        //修改监控参数应答
                        case DataType.ModifyMonitorParaAck:

                            break;

                        //终止监控请求
                        case DataType.AbortMonitorReq:
                            
                            
                            break;

                        //位置查询请求应答
                        case DataType.PositionQueryReqAck:


                            break;

                        //报警处理指示应答
                        case DataType.AlarmInstructionAck:

                            break;

                        //盲区补传数据
                        case DataType.ComplementarityData:

                            break;

                        case DataType.AllocateInitParaAck:

                            //监控请成功
                            if (deliver.data[0] == 0x01)
                            {
                                //解析GPS数据
                                byte[] data = deliver.data;
                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //解析数据分失
                            }

                            break;
                    }

                    break;
                #endregion

                #region 求助业务
                case BusinessType.Appeal:
                    switch (deliver.dataType)
                    {
                        case DataType.AppealReq:

                            //解析求助请求数据
                            AppealReqParser(deliver.data,ref entity);

                            break;
                    }

                    break;
                #endregion

                #region 调度电召业务
                case BusinessType.DispatchRadioCall:

                    break;
                #endregion

                #region 遥控业务请求应答
                case BusinessType.RemoteControl:

                    //摇控成功
                    if (deliver.data[0] == 0x01)
                    {

                    }
                    else if (deliver.data[0] == 0x7f)
                    {
                        //摇控失败

                    }

                    break;

                #endregion

                #region 监听业务
                case BusinessType.Monitor:

                    break;
                #endregion

                #region 里程统计
                case BusinessType.MileageStatistics:

                    break;
                #endregion

                #region 黑匣子业务
                case BusinessType.BlackBoxBusiness:

                    break;
                #endregion

                #region 报警设置
                case BusinessType.AlarmSetup:

                    //数据类型
                    switch (deliver.dataType)
                    {
                        //中上监控请求
                        case DataType.AbortMonitorReq:

                            switch (deliver.data[0])
                            { 
                                //监控时间超时
                                case 0x01:

                                    break;

                                //链路维护时间超时
                                case 0x03:

                                    break;
                            
                                //报警信号终止
                                case 0x04:

                                    break;
                                //监控上发条数到
                                case 0x05:

                                    break;
                            
                            }

                            break;

                        //报警处理指示应答
                        case DataType.AlarmInstructionAck:

                            break;

                        //盲区补传数据
                        case DataType.ComplementarityData:


                            break;

                        //信息查询请求应答
                        case DataType.InfoQueryReqAck:

                            break;

                        //监控数据
                        case DataType.MonitorData:
                        case DataType.MonitorDataEx:

                            //解析监控数据
                            //MonitorDataParser(deliver.data);

                            break;

                        //监控请求应答
                        case DataType.MonitorReqAck:
                        //撤销监控请求应答
                        case DataType.CancelMonitorAck:
                        //修改监控参数应答
                        case DataType.ModifyMonitorParaAck:

                            break;
                            if (deliver.data[0] == 0x01)
                            { 
                               //监控请求成功
                            }
                            else if (deliver.data[0] == 0x7f)
                            { 
                              //监控请求失败
                            }

                            break;

                        //移动台主动上报数据
                        case DataType.SubmitData:

                            //解析终端主动上传数据
                            //SubmitDataParser(deliver.data);

                            break;
                    }

                    break;
                #endregion

                #region 用户管理
                case BusinessType.UserManage:

                    switch (deliver.dataType)
                    { 
                        //设置短信中心号码应答
                        case DataType.SetShortMsgCenterNumAck:

                            entity.IsLocatedData = false;
                            if (deliver.data[0] == 0x01)
                            {
                                //设置成功
                            }
                            else
                            {
                                //设置失败
                            }

                            break;

                        //设置报警手机号应答
                        case DataType.SetDefaultAlarmPhoneAck:

                            if (deliver.data[0] == 0x01)
                            { 
                                //设置成功
                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //设置失败
                            }

                            break;

                        //设置监听号码应答
                        case DataType.SetMonitorPhoneAck:

                            if (deliver.data[0] == 0x01)
                            {
                                //设置成功
                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //设置失败
                            }

                            break;

                        //设置呼叫限制应答
                        case DataType.SetCallLimitAck:

                            if (deliver.data[0] == 0x01)
                            {
                                //设置成功
                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //设置失败
                            }

                            break;

                        //配置报警器应答
                        case DataType.AllocateAnnounciatorAck:

                            if (deliver.data[0] == 0x01)
                            {
                                //设置成功
                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //设置失败
                            }

                            break;

                        //设置求助号码应和
                        case DataType.SetAppealPhoneAck:

                            if (deliver.data[0] == 0x01)
                            {
                                //设置成功
                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //设置失败
                            }

                            break;

                        //设置移动台初始化参数应答
                        case DataType.AllocateInitParaAck:

                            entity.IsLocatedData = false;
                            if (deliver.data[0] == 0x01)
                            {
                                //设置成功
                            }
                            else if (deliver.data[0] == 0x7f)
                            {
                                //设置失败
                            }

                            break;
                    }

                    break;

                #endregion

                #region 呼叫限制
                case BusinessType.CallLimited:


                    break;
                #endregion

                #region 记录仪业务
                case BusinessType.RecorderBusiness:

                    break;
                #endregion

                #region 记录仪报警
                case BusinessType.RecorderAlarm:

                    break;
                #endregion

                #region  拍照业务

                //拍照业务
                case BusinessType.TakePicture:

                    switch (deliver.dataType)
                    {
                        //图片抓拍应答
                        case DataType.TakeShootAck:

                            if (deliver.data[0] == 0x01)
                            {
                                //图片抓拍成功
                            }
                            else if (deliver.data[0] == 0x02)
                            {
                                //图抓拍失败,参数错误
                            }
                            else if (deliver.data[0] == 0x03)
                            {
                                //无法与中心连接
                            }
                            else if (deliver.data[0] == 0x04)
                            {
                                //无法与中心连接
                            }

                            break;

                    }

                    break;

                #endregion

            }
        }
Example #2
0
        /// <summary> 
        /// 分析GPS数据包
        /// </summary>
        /// <param name="buffer">收到的原始数据</param>
        /// <param name="responseList">应答数据</param>
        /// <param name="fullGpsCode">解析后加前缀的GPSCode</param>
        /// <param name="sessionID">会话ID:IP地址+端口号</param>
        /// <returns></returns>
        public GPSDataEntity Parse(byte[] buffer, out List<byte[]> responseList, out string fullGpsCode, string sessionID)
        {
            //传进去赋值,必须在外面创建对象
            GPSDataEntity dataEntity = new GPSDataEntity();

            responseList = new List<byte[]>();
            
            fullGpsCode = GetGPSCode(sessionID);

            //string data = Encoding.ASCII.GetString(buffer);

            //GPRS信息帧数据
            GPRSFrame gprsFrame = new GPRSFrame();
            gprsFrame.ReadBuffer(buffer);

            if (!gprsFrame.IsValidData)
            {
                return null;
            }

            //发送数据缓冲区
            byte[] dataBuffer = null;
            //gprs数据帧
            byte[]destBuffer = null;

            //转义之后的数据帧
            byte[] sendBuffer = null;

            switch (gprsFrame.CmdType)
            {
                //移动台登录请求
                case GPRSCmdType.MobileLoginReq:

                    //读取数据
                    MobileLoginReq mobileLoginReq = new MobileLoginReq();
                    mobileLoginReq.ReadBuffer(gprsFrame.Data);

                    fullGpsCode = CodePrefix + mobileLoginReq.Telephone;

                    //将gpsCode加入列表
                    AddCodeSessionTb(fullGpsCode, sessionID);
                    
                    //将连接加入关系表
                    if (!string.IsNullOrEmpty(fullGpsCode))
                    {
                        OnAddConnectionEvent(fullGpsCode, sessionID);
                    }
                    //如果为有效数据则发送应答消息
                    if (mobileLoginReq.IsValidData)
                    {
                        //发送应答消息
                        MobileLoginAck mobileLoginAck = new MobileLoginAck();
                        mobileLoginAck.Data = 0x01;
                        dataBuffer = new byte[mobileLoginAck.GetLength()];                        
                        mobileLoginAck.WriteBuffer(dataBuffer);

                        gprsFrame.Data = dataBuffer;
                        gprsFrame.CmdType = GPRSCmdType.MobileLoginAck;
                        destBuffer = new byte[gprsFrame.GetLength()];                         
                        gprsFrame.WriteBuffer(destBuffer);

                        sendBuffer = YaXunDataSpliter.BufferToESC(destBuffer);

                        responseList.Add(sendBuffer);

                        //移动台初始化


                        //设置短信中心号码
                        responseList.Add(SetShortMsgCenterNum(mobileLoginReq.Telephone));

                        //加入链路探测关系
                        AddLinkSesskTb(fullGpsCode, DateTime.Now);

                        //再发送个链路探测
                        responseList.Add(GPRSSeekLink(0x14));

                        //设置监控请求 
                        responseList.Add(MonitorReq(mobileLoginReq.Telephone));

                        ////设置移动台初始化参数
                        //responseList.Add(SetMobileInitPara(mobileLoginReq.Telephone,10));

                        ////激活gprs连接
                        //responseList.Add(ActiveGPRSLink(mobileLoginReq.Telephone, 0x01));
                    }
                    break;

                //移动台上传数据
                case GPRSCmdType.MobileTransferData:

                    //读取数据
                    YaXunDeliverData DeliverData = new YaXunDeliverData();
                    
                    DeliverData.ReadBuffer(gprsFrame.Data);

                    //处理接收到的数据
                    DealWithDeliver(DeliverData,ref dataEntity);

                    //在每次收到数据时判断是否需要下发链路探测数据
                    if (NeedLinkSeek(fullGpsCode))
                    {
                        //10分钟发一次链接探测,但是发送的时间值为20分钟
                        responseList.Add(GPRSSeekLink(0x14));

                        //added by lixun 更新链接探测时间
                        AddLinkSesskTb(fullGpsCode, DateTime.Now);
                    }

                    break;

                //GPRS前置机探录TCP链路应答
                case GPRSCmdType.GPRSSeekLinkAck:

                    //需要应答
                    //TCPSeekLinkAck tcpSeekLinkAck = new TCPSeekLinkAck();
                    
                    //dataBuffer = new byte[tcpSeekLinkAck.GetLength()];
                    //tcpSeekLinkAck.Result = 0x01;
                    //tcpSeekLinkAck.WriteBuffer(dataBuffer);
                    //gprsFrame.Data = dataBuffer;
                    //destBuffer = new byte[gprsFrame.GetLength()];
                    //gprsFrame.WriteBuffer(destBuffer);
                    //responseList.Add(destBuffer);
                    
                    if (buffer[0] == 0x01)
                    { 
                       //成功收到链路探测数据
  
                    }


                    break;

            }
            return dataEntity;
        }