コード例 #1
0
ファイル: BuBiaoDataSpliter.cs プロジェクト: hhahh2011/CH.Gps
        /// <summary>
        /// 将子包加入到主包中
        /// </summary>
        /// <param name="frame">子包</param>
        /// <returns>如果所有子包传输完成返加true,否则返加false</returns>
        public bool AddFrame(ref GPRSFrame frame)
        {
            bool bMergeFinish = false;
            string strKey = frame.TMLPhoneNum + frame.MsgID.ToString();

            if (_dicFrames.ContainsKey(strKey) == false)
            {
                _dicFrames.Add(strKey, frame);
            }

            GPRSFrame mainFrame = _dicFrames[strKey];
            mainFrame.AddChildPack2Dict(frame.PackageIndex, frame.Data);
            //Logger.Trace(string.Format("[{0}]总包数:{1}, 包序号{2}", strKey, frame.PackageCount, frame.PackageIndex));

            if (mainFrame.IsTransferFinish())
            {
                mainFrame.Merge();
                bMergeFinish = true;
                frame = mainFrame;
                _dicFrames.Remove(strKey);
            }
            else
            {
                _dicFrames[strKey] = mainFrame;
            }

            return bMergeFinish;
        }
コード例 #2
0
ファイル: BuBiaoDataSpliter.cs プロジェクト: hhahh2011/CH.Gps
 /// <summary>
 /// 该方法只提供给809平台使用,屏蔽了单包数据和多包数据操作的差异
 /// </summary>
 /// <param name="gprsFrame"></param>
 /// <returns>true:gprsFrame为单包数据,或已合并完整的多包数据;false: gprsFrame为还未合并完整的多包数据,需要继续接收</returns>
 public bool GetDataFame(ref GPRSFrame gprsFrame)
 {
     if (gprsFrame.IsMutiPackage)
     {
         gprsFrame.InitData();
         return AddFrame(ref gprsFrame);
     }
     return true;
 }
コード例 #3
0
ファイル: GPSHBBuBiaoParser.cs プロジェクト: hhahh2011/CH.Gps
        private void AutoInfoService()
        {
            try
            {
                List<string> InfoPlaySetting = FetchData.GetInstance().GetInfoPlaySetting();
                foreach (string strInfo in InfoPlaySetting)
                {
                    string[] aryInfo = strInfo.Split('|');
                    string strGpsCode = aryInfo[0];
                    MediaInfoSetItem item1 = new MediaInfoSetItem();
                    item1.InfoType = byte.Parse(aryInfo[1]);
                    item1.Info = "自动发送信息点播" + aryInfo[1];

                    AddSerialNum(strGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.MediaInfoService, false, EncryptType.NoEncrypt
                        , (ushort)item1.dataBuffer.Length, strGpsCode
                        , GetSerialNum(strGpsCode), 0, 0, item1.dataBuffer);

                    Socket socket = TCPConnList.Instance().GetTCPConnection(strGpsCode);
                    if (socket == null)
                    {
                        Logger.Trace("[部标:下发信息点播] socket == null");
                        continue;
                    }
                    if (socket.Connected == false)
                    {
                        Logger.Trace("[部标:下发信息点播] Connected == false");
                        continue;
                    }

                    int send = socket.Send(BuBiaoSendMsg.WriteBuffer());
                    Logger.Trace("[部标:下发信息点播]" + strGpsCode + " " + aryInfo[1]);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
コード例 #4
0
ファイル: GPSHBBuBiaoParser.cs プロジェクト: hhahh2011/CH.Gps
        /// <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 = null;
            responseList = new List<byte[]>();
            string strPicFile = "";
            //GPRS信息帧数据
            GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrame = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame();
            gprsFrame.ReadBuffer(buffer);
            if (!gprsFrame.IsValidData)
            {
                fullGpsCode = "";
                return null;
            }
            fullGpsCode = gprsFrame.GPSCode;
            //将连接加入关系表
            if (!string.IsNullOrEmpty(fullGpsCode))
            {
                OnAddConnectionEvent(fullGpsCode, sessionID);
            }

            if (gprsFrame.IsMutiPackage)
            {

                byte[] bSerialNum = gprsFrame.SerialNum;
                gprsFrame.InitData();

                if (gprsFrame.MsgID == BuBiaoMsgIdType.MediaDataReport)
                {
                    //上传一帧,保存一帧
                    if (gprsFrame.PackageIndex == 1)
                    {
                        //第一帧已包括图片信息定位信息
                        MediaDataReport aMediaDataReport = new MediaDataReport();
                        aMediaDataReport.dataBuffer = gprsFrame.Data;
                        aMediaDataReport.ReadBuffer(gprsFrame.DataLength);

                        dataEntity = new GPSDataEntity();
                        GetGPSDataEntity(fullGpsCode, aMediaDataReport.PhotoLocation, ref dataEntity);

                        WritePicFile(fullGpsCode, aMediaDataReport.ChannelID.ToString(), aMediaDataReport.Data, aMediaDataReport.MediaFomat, aMediaDataReport.EventCode, FileMode.OpenOrCreate, ref dataEntity, ref strPicFile);

                        if (dicCurPicCameraId.ContainsKey(fullGpsCode))
                        {
                            dicCurPicCameraId.Remove(fullGpsCode);
                        }
                        dicCurPicCameraId.Add(fullGpsCode, strPicFile);
                    }
                    else
                    {
                        if (dicCurPicCameraId.ContainsKey(fullGpsCode))
                        {
                            strPicFile = dicCurPicCameraId[fullGpsCode];
                            WritePicFile(strPicFile, gprsFrame.Data, FileMode.Append);
                            dataEntity = null;
                        }
                    }
                }


                Logger.Trace("[部标:分包消息]" + fullGpsCode + "  " + string.Format("消息类型:{0}总包数:{1}, 包序号{2}", gprsFrame.MsgID.ToString(), gprsFrame.PackageCount, gprsFrame.PackageIndex));
                if (_LongMsgProcessor.AddFrame(ref gprsFrame) == false)
                {
                    //最后一包不发送通用应答
                    TMLOrPFCommonRsp PCMPackage = GetTMLOrPFCommonRsp(bSerialNum, BuBiaoMsgIdType.MediaDataReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameMPackage = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCMPackage.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCMPackage.dataBuffer);
                    responseList.Add(gprsFrameMPackage.WriteBuffer());

                    return dataEntity;
                }

            }


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

            switch (gprsFrame.MsgID)
            {
                case BuBiaoMsgIdType.BSJBlindZoneUpload:
                    //博实结盲区补传,跟厂家确认需要给应答,否则会导致终端重发
                    TMLOrPFCommonRsp PCBSJRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.BSJBlindZoneUpload, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameBSJ = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCBSJRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCBSJRsp.dataBuffer);

                    responseList.Add(gprsFrameBSJ.WriteBuffer());

                    break;

                //终端通用应答
                case BuBiaoMsgIdType.TMLCommonRsp:
                    TMLOrPFCommonRsp TCRsp = new TMLOrPFCommonRsp();
                    TCRsp.dataBuffer = gprsFrame.Data;
                    TCRsp.ReadBuffer();

                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCRsp,fullGpsCode);
                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "[通用应答] 消息类型:" + TCRsp.RspID.ToString() + " 消息流水号:" + TCRsp.SerialNum.ToString() + " 结果:" + TCRsp.Result.ToString());                    
                    Logger.Trace("[部标:通用应答]" + fullGpsCode + "  " + string.Format("消息类型:{0},消息流水号:{1}, 结果{2}", TCRsp.RspID.ToString(), TCRsp.SerialNum.ToString(), TCRsp.Result.ToString()));
                    break;
                //提问应答消息
                case BuBiaoMsgIdType.TMLAnwerQuestion:
                    TMLAnswerQuestion aTMLAnswerQuestion = new TMLAnswerQuestion();
                    aTMLAnswerQuestion.ReadBuffer(gprsFrame.Data);
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().UpdateBubiaoQuestion(aTMLAnswerQuestion, fullGpsCode);

                    TMLOrPFCommonRsp PCAnswerRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLAnwerQuestion, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameAnswer = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCAnswerRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCAnswerRsp.dataBuffer);
                    responseList.Add(gprsFrameAnswer.WriteBuffer());

                    Logger.Trace("[部标:提问应答]" + fullGpsCode + "  " + gprsFrame.Data[0]);
                    break;
                //事件上报
                case BuBiaoMsgIdType.TMLEventReport:
                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "[事件报告]:" + gprsFrame.Data[0]);
                    int iEventId = (int)gprsFrame.Data[0];
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveEventReport(iEventId, fullGpsCode);

                    TMLOrPFCommonRsp PCEventRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLEventReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameEvent = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCEventRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCEventRsp.dataBuffer);
                    responseList.Add(gprsFrameEvent.WriteBuffer());

                    Logger.Trace("[部标:事件报告]" + fullGpsCode + "  " + gprsFrame.Data[0]);
                    break;
                //车辆控制应答
                case BuBiaoMsgIdType.TMLVehicleControlRsp:
                    byte[] RspSerialNum = new byte[2];
                    Array.Copy(gprsFrame.Data, 0, RspSerialNum, 0, 2);
                    UInt16 iSerialNum = BitConverter.ToUInt16(BuBiaoData.LocalByteToNetByteOrder(RspSerialNum), 0);

                    byte[] locData = new byte[gprsFrame.Data.Length - 2];
                    Array.Copy(gprsFrame.Data, 2, locData, 0, locData.Length);
                    LocationReport VC_LR = new LocationReport();
                    VC_LR.ReadBuffer(locData, locData.Length);

                    dataEntity = new GPSDataEntity();
                    GetGPSDataEntity(fullGpsCode, VC_LR, ref dataEntity);
                    TMLOrPFCommonRsp TCVehicle = new TMLOrPFCommonRsp();
                    TCVehicle.RspID = BuBiaoMsgIdType.TMLVehicleControl;
                    TCVehicle.SerialNum = iSerialNum;
                    TCVehicle.Result = 0;
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCVehicle, fullGpsCode);

                    TMLOrPFCommonRsp PCControlRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLVehicleControlRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameControl = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCControlRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCControlRsp.dataBuffer);
                    responseList.Add(gprsFrameControl.WriteBuffer());

                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "[车辆控制应答]:" + iSerialNum.ToString());
                    Logger.Trace("[部标:车辆控制应答]" + fullGpsCode + "  " + iSerialNum.ToString());
                    break;
                //信息点播或取消
                case BuBiaoMsgIdType.TMLInfoPlayOrCancel:
                    TMLMediaPlayOrCancel TCPc = new TMLMediaPlayOrCancel();
                    TCPc.dataBuffer = gprsFrame.Data;
                    TCPc.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().UpdateInfoPlay(TCPc, fullGpsCode);                                        

                    TMLOrPFCommonRsp PCInfoPlayRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLInfoPlayOrCancel, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameInfoPlay = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCInfoPlayRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCInfoPlayRsp.dataBuffer);
                    responseList.Add(gprsFrameInfoPlay.WriteBuffer());

                    //Add2InfoService(TCPc, fullGpsCode);
                    Logger.Trace("[部标:信息点播或取消]" + fullGpsCode + "  " + string.Format("消息类型:{0},flag:{1}", TCPc.InfoType.ToString(), TCPc.InfoFlag.ToString()));
                    break;
                //心跳
                case BuBiaoMsgIdType.TMLKeepAlive:
                    TMLOrPFCommonRsp PCHeartRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLKeepAlive, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameHeart = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCHeartRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCHeartRsp.dataBuffer);
                    responseList.Add(gprsFrameHeart.WriteBuffer());
                    break;
                //终端注册
                case BuBiaoMsgIdType.TMLRegisterReq:
                    //解析终端注册消息
                    //if (!dicDeviceHasRegiste.ContainsKey(fullGpsCode))
                    //{
                    //    dicDeviceHasRegiste.Add(fullGpsCode, 0);
                    //}

                    //byte hasRegiste = dicDeviceHasRegiste[fullGpsCode];

                    TMLRegisterFrameReq RstReq = new TMLRegisterFrameReq();
                    RstReq.ReadBuffer(gprsFrame.Data, gprsFrame.DataLength);

                    Logger.Trace("终端注册(Device):" + RstReq.LicenceNum + " " + RstReq.DeviceId);

                    TMLRegisterFrameRsp RstRsp = new TMLRegisterFrameRsp();
                    RstRsp.SerialNumByte = gprsFrame.SerialNum;
                    //0--成功 1--车辆已注册 2--数据库无此车辆 3--终端已注册 4--数据库无此终端 
                    RstRsp.Result = 0;
                    RstRsp.Akey = gprsFrame.GPSCode;

                    //if (CheckDeviceIsVaild(fullGpsCode, RstReq.LicenceNum, RstReq.DeviceId))
                    //{
                    //    if (hasRegiste == 1)
                    //    {
                    //        //已经注册                        
                    //        RstRsp.Result = 3;
                    //    }
                    //    else
                    //    {
                    //        RstRsp.Result = 0;
                    //        RstRsp.Akey = gprsFrame.GPSCode;
                    //        dicDeviceHasRegiste[fullGpsCode] = 1;

                    //        lock (dicNeedSaveDeviceRegiste)
                    //        {
                    //            if (dicNeedSaveDeviceRegiste.ContainsKey(fullGpsCode))
                    //                dicNeedSaveDeviceRegiste.Remove(fullGpsCode);
                    //            dicNeedSaveDeviceRegiste.Add(fullGpsCode, RstReq);
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //        RstRsp.Result = 4;
                    //}

                    RstRsp.WriteBuffer();
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameSendRstRsp = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.TMLRegisterRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(RstRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, RstRsp.dataBuffer);
                    responseList.Add(gprsFrameSendRstRsp.WriteBuffer());

                    Logger.Trace("[部标:终端注册]" + fullGpsCode + " " + RstRsp.Result);
                    break;
                //终端注销
                case BuBiaoMsgIdType.TMLCancelReq:
                    TMLOrPFCommonRsp PCCancelRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLCancelReq, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameCancel = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCCancelRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCCancelRsp.dataBuffer);
                    responseList.Add(gprsFrameCancel.WriteBuffer());

                    if (dicDeviceHasRegiste.ContainsKey(fullGpsCode))
                    {
                        dicDeviceHasRegiste.Remove(fullGpsCode);
                    }
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().RemoveDeviceRegInfo(fullGpsCode);
                    Logger.Trace("[部标:终端注销]" + fullGpsCode);
                    break;
                //数据透传
                case BuBiaoMsgIdType.DataTransparentUp:
                    TransparentTranData aTransparentTranData = new TransparentTranData();
                    aTransparentTranData.dataBuffer = gprsFrame.Data;
                    aTransparentTranData.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveTransparentTranInfo(aTransparentTranData,fullGpsCode);

                    TMLOrPFCommonRsp PCTTRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.DataTransparentUp, 0);
                    AddSerialNum(fullGpsCode); ;
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameTT = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCTTRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCTTRsp.dataBuffer);
                    responseList.Add(gprsFrameTT.WriteBuffer());
                    Logger.Trace("[部标:数据透传]" + aTransparentTranData.DataType);

                    break;
                //鉴权
                case BuBiaoMsgIdType.TMLAuthenticationReq:

                    TMLAuthenticationReq aTMLAuthenticationReq = new TMLAuthenticationReq();
                    aTMLAuthenticationReq.ReadBuffer(gprsFrame.Data);
                    //取得鉴权码,去判断是否已经合法车辆
                    byte bResult = 0;

                    //改为从内存鉴权
                    //正式环境暂不认证
                    //if (dicPlatformAllVehilceInfo.ContainsKey(aTMLAuthenticationReq.Akey))
                    //    bResult = 0;
                    //else
                    //    bResult = 1;
                    TMLOrPFCommonRsp PCRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TMLAuthenticationReq, bResult);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameSend = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCRsp.dataBuffer);
                    responseList.Add(gprsFrameSend.WriteBuffer());

                    //设置参数默认值,统一通过终端参数设置

                    SetTMLPara setPara = new SetTMLPara();
                    List<TMLParaItem> paraList = new List<TMLParaItem>();
                    TMLParaItem item;
                    int BufferLen = 0;
                    //终端心跳发送间隔,单位为秒(s)
                    //item = new TMLParaItem(ParaIDType.TMLKeepAlive, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(0x0000003c)));
                    //BufferLen += item.GetItemLen();
                    //paraList.Add(item);

                    //位置汇报策略
                    item = new TMLParaItem(ParaIDType.LocationReportStrategy, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(0)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    //位置汇报方案
                    item = new TMLParaItem(ParaIDType.LocationReportProgram, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(0)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    //缺省时间汇报间隔
                    item = new TMLParaItem(ParaIDType.DefaultReportInterval, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(15)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    item = new TMLParaItem(ParaIDType.SleepReportInterval, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(60)));
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    item = new TMLParaItem(ParaIDType.DriverNoLoginReportInterval, 4, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(60))); ;
                    BufferLen += item.GetItemLen();
                    paraList.Add(item);

                    setPara.AddTMLParaItem(paraList, BufferLen);
                    AddSerialNum(fullGpsCode);
                    gprsFrameSend = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SetTMLPara, false, EncryptType.NoEncrypt, Convert.ToUInt16(setPara.dataBuffer.Length)
                        , gprsFrame.TMLPhoneNumByte, BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, setPara.dataBuffer);

                    byte[] sendbuffer = gprsFrameSend.WriteBuffer();
                    responseList.Add(sendbuffer);

                    Logger.Trace("[部标:终端签权]" + fullGpsCode + "  " + bResult);
                    break;
                //查询终端参数应答
                case BuBiaoMsgIdType.QueryTMLParaRsp:

                    CmdData cmdData = new CmdData();
                    cmdData.Data.Cmd = ControlCmdType.QueryTerminalParamRsp;
                    cmdData.DataBuffer = gprsFrame.Data;
                    cmdData.Data.DataLen = (ushort)gprsFrame.Data.Length;

                    byte[] RspBuffer = new byte[cmdData.GetLenth()];
                    cmdData.WriteBuffer(0, RspBuffer);


                    //生成公共应答
                    //QueryTMLPara tmlparam = new QueryTMLPara();
                    //tmlparam.ReadBuffer(gprsFrame.Data);
                    //TMLOrPFCommonRsp TCQuery = new TMLOrPFCommonRsp();
                    //TCQuery.RspID = BuBiaoMsgIdType.QueryTMLParaReq;
                    //TCQuery.SerialNum = tmlparam.RspSerialNumber;
                    //TCQuery.Result = 0;
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCQuery, fullGpsCode);

                    TMLOrPFCommonRsp PCQuery = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.QueryTMLParaRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameQuery = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCQuery.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCQuery.dataBuffer);
                    responseList.Add(gprsFrameQuery.WriteBuffer());

                    base.OnPostAckMsgHandlerEvent(fullGpsCode, RspBuffer);
                    //base.OnDebugDataEvent(base.TransfersType.ToString(), fullGpsCode, "查询终端参数应答" + gprsFrame.DataLength);
                    Logger.Trace("[部标:查询终端参数应答]" + gprsFrame.DataLength);

                    break;
                case BuBiaoMsgIdType.LocationReport:

                    LocationReport LR = new LocationReport();
                    LR.ReadBuffer(gprsFrame.Data, gprsFrame.DataLength);

                    dataEntity = new GPSDataEntity();
                    GetGPSDataEntity(fullGpsCode, LR, ref dataEntity);
                    DealWithAlarm(LR, gprsFrame, ref responseList);

                    //TO DO

                    break;
                //驾驶员上报
                case BuBiaoMsgIdType.DriverInfoReport:
                    DriverInfoReport aDriverInfoReport = new DriverInfoReport();
                    aDriverInfoReport.dataBuffer = gprsFrame.Data;
                    aDriverInfoReport.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveDriverReport(aDriverInfoReport, fullGpsCode);

                    TMLOrPFCommonRsp PCVehicleRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.DriverInfoReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameVehilce = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCVehicleRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCVehicleRsp.dataBuffer);
                    responseList.Add(gprsFrameVehilce.WriteBuffer());
                    Logger.Trace("[部标:驾驶员身份上报]" + fullGpsCode + "  " + aDriverInfoReport.DriverName);

                    break;
                //电子运单上报
                case BuBiaoMsgIdType.ConsignOrderReport:
                    ConsignOrderReport aConsignOrderReport = new ConsignOrderReport();
                    aConsignOrderReport.dataBuffer = gprsFrame.Data;
                    aConsignOrderReport.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveETransForm(aConsignOrderReport, fullGpsCode);

                    TMLOrPFCommonRsp PCOrderRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.ConsignOrderReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameOrder = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCOrderRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCOrderRsp.dataBuffer);
                    responseList.Add(gprsFrameOrder.WriteBuffer());

                    Logger.Trace("[部标:电子运单上报]" + fullGpsCode);
                    break;
                //多媒体事件信息上传
                case BuBiaoMsgIdType.MediaEventInfoReport:
                    MediaEventInfoReport aMediaEventInfoReport = new MediaEventInfoReport();
                    aMediaEventInfoReport.ReadBuffer(gprsFrame.Data);

                    TMLOrPFCommonRsp PCMediaReportRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.MediaEventInfoReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameMediaReport = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCMediaReportRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCMediaReportRsp.dataBuffer);
                    responseList.Add(gprsFrameMediaReport.WriteBuffer());

                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveMediaEventInfo(aMediaEventInfoReport, fullGpsCode);
                    Logger.Trace("[部标:多媒体事件信息上传]" + fullGpsCode);
                    break;
                //多媒体数据检索应答
                case BuBiaoMsgIdType.MediaDataSearchRsp:

                    CmdData cmdData1 = new CmdData();
                    cmdData1.Data.Cmd = ControlCmdType.MediaDataSearchRsp;
                    cmdData1.DataBuffer = gprsFrame.Data;
                    cmdData1.Data.DataLen = (ushort)gprsFrame.Data.Length;

                    byte[] RspBuffer1 = new byte[cmdData1.GetLenth()];
                    cmdData1.WriteBuffer(0, RspBuffer1);
                    base.OnPostAckMsgHandlerEvent(fullGpsCode, RspBuffer1);


                    TMLOrPFCommonRsp PCMediaSearchRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.MediaDataSearchRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameMediaSearch = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCMediaSearchRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCMediaSearchRsp.dataBuffer);
                    responseList.Add(gprsFrameMediaSearch.WriteBuffer());

                    MediaDataSearchRsp aMediaDataSearchRsp = new MediaDataSearchRsp();
                    aMediaDataSearchRsp.ReadBuffer(gprsFrame.Data);
                    TMLOrPFCommonRsp TCDataSearch = new TMLOrPFCommonRsp();
                    TCDataSearch.RspID = BuBiaoMsgIdType.MediaDataSearch;
                    TCDataSearch.SerialNum = aMediaDataSearchRsp.SerialNumber;
                    TCDataSearch.Result = 0;
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().SaveBubiaoCommonRsp(TCDataSearch, fullGpsCode);

                    Logger.Trace("[部标:多媒体数据检索应答] " + fullGpsCode);

                    break;
                //多媒体数据上传
                case BuBiaoMsgIdType.MediaDataReport:
                    MediaDataReport aMediaDataReport = new MediaDataReport();
                    aMediaDataReport.dataBuffer = gprsFrame.Data;
                    aMediaDataReport.ReadBuffer(gprsFrame.DataLength);

                    //将图片数据写成图片文件存入指定位置
                    if (dicCurPicCameraId.ContainsKey(fullGpsCode))
                    {
                        strPicFile = dicCurPicCameraId[fullGpsCode];
                        WritePicFile(strPicFile, aMediaDataReport.Data, FileMode.OpenOrCreate);
                    }

                    //应答0x8800
                    AddSerialNum(fullGpsCode);
                    byte[] bMediaDataRsp = GetMediaDataReportRsp(aMediaDataReport, null);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameSend3 = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.MediaDataReportRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(bMediaDataRsp.Length), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, bMediaDataRsp);
                    responseList.Add(gprsFrameSend3.WriteBuffer());

                    //平台下发拍照指令
                    if (aMediaDataReport.EventCode == 0)
                    {
                        if (CheckTaskThread.GetInstance().PicTaskPool.ContainsKey(fullGpsCode))
                        {
                            if (CheckTaskThread.GetInstance().PicTaskPool[fullGpsCode].Count > 0)
                            {
                                TakePicTask task = CheckTaskThread.GetInstance().PicTaskPool[fullGpsCode].Peek();
                                if (task != null)
                                {
                                    task.Status = TakePicTaskStatus.LastPicFinished;
                                    CheckTaskThread.GetInstance().DoShoot(fullGpsCode, false);
                                    Logger.Trace("[拍照]完成,更改任务状态 ChannelID" + aMediaDataReport.ChannelID + "--" + task.CameraList[task.CurrentCameraIndex]);
                                }
                            }
                        }
                    }

                    Logger.Trace("[部标:多媒体上传完成]" + fullGpsCode);
                    break;
                //行驶记录上传
                case BuBiaoMsgIdType.TravelRecordReport:
                    TravelRecordReport aTravelRecReport = new TravelRecordReport();
                    aTravelRecReport.DataBuffer = gprsFrame.Data;
                    aTravelRecReport.ReadBuffer();
                    //GPSGatewayServer.DataAccess.FetchData.GetInstance().UpdateTravelRecordReport(aTravelRecReport, fullGpsCode);


                    TMLOrPFCommonRsp PCTravelRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.TravelRecordReport, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameTravel = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCTravelRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCTravelRsp.dataBuffer);
                    responseList.Add(gprsFrameTravel.WriteBuffer());
                    Logger.Trace("[部标:行驶记录数据上报]" + fullGpsCode);
                    break;
                case BuBiaoMsgIdType.QueryPositionRsp:
                    QueryPositionRsp aQueryPositionRsp = new QueryPositionRsp();
                    aQueryPositionRsp.dataBuffer = gprsFrame.Data;
                    aQueryPositionRsp.ReadBuffer(gprsFrame.DataLength);
                    //FetchData.GetInstance().UpdateTMLResponse(fullGpsCode, aQueryPositionRsp.SerialNum, DateTime.Now, 0);

                    dataEntity = new GPSDataEntity();
                    GetGPSDataEntity(fullGpsCode, aQueryPositionRsp.LR, ref dataEntity);

                    TMLOrPFCommonRsp PCPositionRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, BuBiaoMsgIdType.QueryPositionRsp, 0);
                    AddSerialNum(fullGpsCode);
                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFramePosition = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                        , Convert.ToByte(PCPositionRsp.getLength()), gprsFrame.TMLPhoneNumByte
                        , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(fullGpsCode))), 0, 0, PCPositionRsp.dataBuffer);
                    responseList.Add(gprsFramePosition.WriteBuffer());


                    Logger.Trace("[部标:点名]" + fullGpsCode);
                    //DealWithAlarm(aQueryPositionRsp.LR, gprsFrame, ref responseList);
                    break;

            }
            return dataEntity;
        }
コード例 #5
0
ファイル: GPSHBBuBiaoParser.cs プロジェクト: hhahh2011/CH.Gps
        private void Change2TransparentData(uint LEDDataLen, byte[] LEDData, ref uint sendDataLen, ref byte[] sendData, string strGPSCode)
        {
            byte[] dataBuffer = new byte[LEDDataLen + 1];
            dataBuffer[0] = 20;
            //透传消息类型
            Array.Copy(LEDData, 0, dataBuffer, 1, LEDDataLen);

            GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.DataTransparentDown, false, EncryptType.NoEncrypt
                , (ushort)dataBuffer.Length, strGPSCode
                , _SerialNumber, 0, 0, dataBuffer);
            sendData = BuBiaoSendMsg.WriteBuffer();
            sendDataLen = (uint)sendData.Length;

            SafeAddSequence();
        }
コード例 #6
0
ファイル: GPSHBBuBiaoParser.cs プロジェクト: hhahh2011/CH.Gps
        public override byte[] ParseControlInstruction(ControlCmdType cmdType, object entity)
        {
            byte[] pOutData = null;
            string strGPSCode;
            GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame SendMsg;
            switch (cmdType)
            {
                case ControlCmdType.DispatchControl:
                    DispatchControl dc = (DispatchControl)entity;

                    SendTxtToTML obj = new SendTxtToTML();
                    obj.IsEmergency = 1;
                    obj.IsTMLLCDShow = 1;
                    obj.IsTMLTTSRead = 1;
                    obj.IsAdvertisingScreenShow = 1;
                    obj.TxtMassage = dc.SendContent;
                    obj.WriteBuffer();

                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SendTxtToTML, false, EncryptType.NoEncrypt
                        , (ushort)obj.getLength(), dc.GPSCode
                        , _SerialNumber, 0, 0, obj.dataBuffer);
                    pOutData = BuBiaoSendMsg.WriteBuffer();
                    SafeAddSequence();
                    break;
                case ControlCmdType.ListenCall:
                    YWListenCallInfoEntity callInfo = (YWListenCallInfoEntity)entity;
                    PhoneCallback objCallBack = new PhoneCallback();
                    if (callInfo.ListenCallType == 1)
                        objCallBack.flageByte = 1;
                    else
                        objCallBack.flageByte = 0;
                    objCallBack.PhoneNum = callInfo.Phone;
                    objCallBack.WriteBuffer();

                    GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame BuBiaoSendMsg1 = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PhoneCallback, false, EncryptType.NoEncrypt
                       , (ushort)objCallBack.getLength(), callInfo.FullGPSCode
                       , _SerialNumber, 0, 0, objCallBack.dataBuffer);
                    pOutData = BuBiaoSendMsg1.WriteBuffer();
                    SafeAddSequence();
                    break;
                case ControlCmdType.BreakOilCircuitByForce:
                case ControlCmdType.BreakOilCircuitBySmart:
                    byte[] BreakOilByte = new byte[] { 0xf0 };
                    strGPSCode = entity.ToString();
                    SendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.TMLControl, false, EncryptType.NoEncrypt, (ushort)BreakOilByte.Length, strGPSCode, _SerialNumber, 0, 0, BreakOilByte);
                    pOutData = SendMsg.WriteBuffer();
                    Debug.WriteLine(Transfer.ConvertBytesToHexString(pOutData));
                    SafeAddSequence();

                    break;
                case ControlCmdType.SupplyOilCircuit:
                    byte[] SupplyOilByte = new byte[] { 0xf1 };
                    strGPSCode = entity.ToString();
                    SendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.TMLControl, false, EncryptType.NoEncrypt, (ushort)SupplyOilByte.Length, strGPSCode, _SerialNumber, 0, 0, SupplyOilByte);
                    pOutData = SendMsg.WriteBuffer();
                    SafeAddSequence();

                    break;
                case ControlCmdType.SimpleInstruction:

                    byte[] instruction = new byte[512];
                    uint instructionLen = 0;
                    SimpleInstructionControlEntity simpleInstructionControlEntity = entity as SimpleInstructionControlEntity;

                    ParseSimpleInstructionControl(simpleInstructionControlEntity, ref instructionLen, ref instruction);

                    pOutData = new byte[instructionLen];
                    Array.Copy(instruction, pOutData, instructionLen);
                    break;
            }
            return pOutData;
        }
コード例 #7
0
ファイル: GPSHBBuBiaoParser.cs プロジェクト: hhahh2011/CH.Gps
        public override void TakePicture(string gpsCode, uint cameraID, ref uint sendDataLen, ref byte[] sendData)
        {

            CameraShootImmediately obj = new CameraShootImmediately();
            obj.ChannelID = (byte)cameraID;
            //拍摄命令
            obj.ShootCMD = 1;
            //拍摄间隔/录像时间
            obj.ShootInterval = 30;
            obj.SaveFlage = 0;
            obj.Resolution = 0x01;
            obj.MediaQuality = 4;
            obj.Luminance = 255;
            obj.Contrast = 120;
            obj.Saturation = 120;
            obj.Chroma = 255;
            obj.WriteBuffer();

            GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.CameraShootImmediately, false, EncryptType.NoEncrypt
                        , (ushort)obj.getLength(), gpsCode
                        , _SerialNumber, 0, 0, obj.dataBuffer);
            sendData = BuBiaoSendMsg.WriteBuffer();
            sendDataLen = (uint)sendData.Length;
            SafeAddSequence();
        }
コード例 #8
0
ファイル: GPSHBBuBiaoParser.cs プロジェクト: hhahh2011/CH.Gps
        /// <summary>
        /// 处理报警信息
        /// </summary>
        /// <param name="LR"></param>
        private void DealWithAlarm(LocationReport LR, GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrame, ref List<byte[]> responseList)
        {

            TMLOrPFCommonRsp PCRsp = GetTMLOrPFCommonRsp(gprsFrame.SerialNum, gprsFrame.MsgID, 0);
            AddSerialNum(gprsFrame.GPSCode);
            GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame gprsFrameSend = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PFCommonRsp, false, EncryptType.NoEncrypt
                , Convert.ToByte(PCRsp.getLength()), gprsFrame.TMLPhoneNumByte
                , BuBiaoData.LocalByteToNetByteOrder(BitConverter.GetBytes(GetSerialNum(gprsFrame.GPSCode))), 0, 0, PCRsp.dataBuffer);
            responseList.Add(gprsFrameSend.WriteBuffer());

            if (LR.EmergencyAlarm == 1)
            {
                List<byte[]> PluderLedInstruction = GetLedInstructionWhenPlunder(gprsFrame.GPSCode);
                IEnumerator<byte[]> en = PluderLedInstruction.GetEnumerator();
                while (en.MoveNext())
                {
                    byte[] data = en.Current;
                    responseList.Add(data);
                }
            }
        }
コード例 #9
0
        public void HandleBuBiaoMessage(BuBiaoCommonControl bbControl, ControlCmdType cmdType)
        {

            byte[] sendBuffer = null;
            byte[] BodyBuffer = GpsDataParser.ParseControlInstruction(cmdType, bbControl);
            GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame BuBiaoSendMsg;

            switch (cmdType)
            {
                case ControlCmdType.SetCircleRegion:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SetCircleRegion, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.RemoveCircleRegion:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.RemoveCircleRegion, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.TMLControl:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.TMLControl, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.SendTxtToTML:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SendTxtToTML, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.PhoneCallback:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.PhoneCallback, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.CameraShootImmediately:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.CameraShootImmediately, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.SetRectangleRegion:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SetRectangleRegion, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.SetPloygon:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SetPloygonRegion, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.SetFixedLine:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SetFixedLine, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.RemoveRectangleRegion:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.RemoveRectangleRegion, false, EncryptType.NoEncrypt
                       , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                       , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.RemovePloygon:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.RemovePloygonRegion, false, EncryptType.NoEncrypt
                       , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                       , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.RemoveFixedLine:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.RemoveFixedLine, false, EncryptType.NoEncrypt
                       , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                       , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.SetOverSpeedAlarm:
                case ControlCmdType.SetOverFatigueAlarm:
                case ControlCmdType.SetStopCarAlarm:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.SetTMLPara, false, EncryptType.NoEncrypt
                       , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                       , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.PositionQueryReq:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.QueryPosition, false, EncryptType.NoEncrypt
                       , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                       , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
                case ControlCmdType.GetRravelRecord:
                    BuBiaoSendMsg = new GPSGatewayServer.DataModel.BuBiaoData.GPRSFrame(BuBiaoMsgIdType.GetRravelRecord, false, EncryptType.NoEncrypt
                        , (ushort)bbControl.Data.CommandLen, bbControl.GPSCode
                        , bbControl.Data.SerialNumber, 0, 0, bbControl.Command);
                    sendBuffer = BuBiaoSendMsg.WriteBuffer();
                    break;
            }


            //解析页面下发数据
            if (sendBuffer == null || sendBuffer.Length <= 0)
            {
                Logger.Trace("指令为空, GPSCODE:" + bbControl.GPSCode);
                return;
            }

            try
            {
                //取得已建立的套接字
                Socket socket = TCPConnList.Instance().GetTCPConnection(bbControl.GPSCode);
                if (socket == null)
                {
                    return;
                }
                if (socket.Connected == false)
                {
                    //从集合移除
                    //TCPConnList.Instance().RemoveTCPConnection(bbControl.GPSCode);
                    return;
                }


                try
                {
                    int send = socket.Send(sendBuffer);

                    StringBuilder sbBinaryData = new StringBuilder();
                    for (int i = 0; i < sendBuffer.Length; i++)
                    {
                        sbBinaryData.Append(sendBuffer[i].ToString("X2"));
                        if (i < sendBuffer.Length - 1)
                            sbBinaryData.Append(",");
                    }
                    string ss = sbBinaryData.ToString();

                    GpsDataParser.OnDebugDataEvent(GpsDataParser.TransfersType.ToString(), bbControl.GPSCode, "[应用层下发指令]" + ss);

                    if (send > 0)
                    {
                        //发送回复表示执行成功                        
                        OnSendAnswerToWebEvent(bbControl.Data.SerialNumber.ToString(), false, bbControl.GPSCode, cmdType, true);
                        Logger.Trace("发送部标里程指令成功.GPSCODE:" + bbControl.GPSCode);
                    }
                    else
                    {
                        //发送回复表示执行失败                        
                        OnSendAnswerToWebEvent(bbControl.Data.SerialNumber.ToString(), false, bbControl.GPSCode, cmdType, false);
                        Logger.Trace("发送部标指令失败GPSCODE:" + bbControl.GPSCode);
                    }
                }
                catch (SocketException ex)
                {
                    //从列表移除此连接
                    //TCPConnList.Instance().RemoveTCPConnection(bbControl.GPSCode);
                    Logger.Trace(bbControl.GPSCode + "发送部标里程指令时异常" + ex.ToString(), null);
                }

            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }
            finally
            {
                sendBuffer = null;
            }
        }
コード例 #10
0
ファイル: BuBiaoDataSpliter.cs プロジェクト: hhahh2011/CH.Gps
        /// <summary>
        /// 将原始数据转为结构体数组,该方法用来提供给809平台使用
        /// (已无使用,改直接发送解决粘包后的数据)
        /// </summary>
        /// <param name="raw"></param>
        /// <returns></returns>
        public static List<GPRSFrame> GetFrameListFromSourceArr(byte[] raw)
        {
            List<GPRSFrame> FrameList = new List<GPRSFrame>();
            //还原数据
            byte[] buffer = BuBiaoData.FromESC(raw);


            byte[] Msgbuffer = null;
            if (_PreviousPkg == null)
            {
                Msgbuffer = buffer;
            }
            else
            {
                Msgbuffer = BuBiaoData.SuperPorcPasterPkg(_PreviousPkg, buffer);
            }

            if (Msgbuffer[0] != 0x7e)
            {
                StringBuilder sbDirtyPkg = new StringBuilder();
                for (int i = 0; i < Msgbuffer.Length; i++)
                {
                    sbDirtyPkg.Append(Msgbuffer[i].ToString("X2"));
                    if (i < Msgbuffer.Length - 1)
                        sbDirtyPkg.Append(",");
                }
                if (_PreviousPkg == null)
                    Logger.Trace("[部标:出现脏包]" + sbDirtyPkg.ToString());
                else
                    Logger.Trace("[部标:合包后出现脏包]" + _PreviousPkg.Length + " :" + sbDirtyPkg.ToString());

                _PreviousPkg = null;
                return FrameList;
            }
            List<byte[]> bufferList = BuBiaoDataSpliter.SplitDataEx(Msgbuffer, ref _PreviousPkg);
            if (_PreviousPkg != null)
            {
                Logger.Trace("[部标:出现粘包]" + Msgbuffer.Length + " " + _PreviousPkg.Length);
            }

            for (int index = 0; index < bufferList.Count; index++)
            {
                //GPRS信息帧数据
                GPRSFrame gprsFrame = new GPRSFrame();
                gprsFrame.ReadBuffer(buffer);
                //只发送有效数据
                if (gprsFrame.IsValidData)
                {
                    FrameList.Add(gprsFrame);
                }
            }

            return FrameList;
        }