/// <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 List<GPSDataEntity> Parse(byte[] buffer, out List<byte[]> responseList, out string fullGpsCode,string sessionID) { YouWeiGPSData result = null; responseList = null; List<GPSDataEntity> dataList = new List<GPSDataEntity>(); //DLL协议实体 YouWeiGPSReceiveDataCondition receiveDataCondition = new YouWeiGPSReceiveDataCondition(); YouWeiGPSData gpsData = new YouWeiGPSData(); YouWeiGPSData[] YouWeiDataEx = null; YouWeiGPSData pictureData = new YouWeiGPSData(); try { //LED报警显示也从Decode下发 bool returnValue = Decode( (byte)GPSYouWeiProtocolType.GPRSORCDMA, buffer, ref receiveDataCondition, ref gpsData, ref YouWeiDataEx, ref pictureData, out responseList); if (returnValue == false) { fullGpsCode = string.Empty; return null; } //FullGpsCode未赋值,重新赋值 if (string.IsNullOrEmpty(gpsData.FullGpsCode)) { fullGpsCode = CodePrefix + gpsData.BaseData.GPSCode; gpsData.FullGpsCode = fullGpsCode; } else { fullGpsCode = gpsData.FullGpsCode; } //将连接加入连接集合,如果是连接后的第一点数据,则同时会更新路由关系表 //注意UpdateFirstDataRela的先后关系 if (!String.IsNullOrEmpty(gpsData.FullGpsCode)) { OnAddConnectionEvent(gpsData.FullGpsCode, sessionID); } //更新上一次数据 if (TCPConnList.Instance().IsFirstDataOfConn(sessionID)) { if (string.IsNullOrEmpty(gpsData.FullGpsCode)) { Logger.Error("gpsData.FullGpsCode为空:" + gpsData.BaseData.GPSCode, null); } //更新上一点数据 //CacheUtility.UpdateLastGPSData(gpsData.FullGpsCode); //更改记录状态,标明以后的数据已不是第一点数据 TCPConnList.Instance().UpdateFirstDataRela(sessionID, 0); } //含有拍照数据 if (pictureData.BaseData.GPSCode.Length > 4) { result = pictureData; dataList.Add(pictureData.BaseData); } result = gpsData; //设备注册 if (receiveDataCondition.commandID == YouWeiPublicDefine.ICOMMAND_DEVICEREGISTERED) { lock (dicSendTrackEx) { if (dicSendTrackEx.ContainsKey(gpsData.FullGpsCode) == false) { //修改下发指令长度方法 2010-3-11 gxl uint instructionLen = 0; byte[] instruction = new byte[512]; byte[] pOutData = null; //ACC=1时的上报时间间隔 int TimeAccOn; //ACC=0时的上报时间间隔 int TimeAccOff; //GPSTraceIntervalGetTraceInterval(string gpsCode); if (dicGPSTraceInterval.ContainsKey(gpsData.FullGpsCode)) { GPSTraceInterval _GPSTraceInterval = dicGPSTraceInterval[gpsData.FullGpsCode]; TimeAccOn = _GPSTraceInterval.TimeAccOn; TimeAccOff = _GPSTraceInterval.TimeAccOff; } else { TimeAccOn = 15; TimeAccOff = 60; } //启动定时报警 YouWeiGPSInterface.EncodeStartTimerTrackEx( (byte)GPSYouWeiProtocolType.GPRSORCDMA, YouWeiPublicDefine.PROTOCOLVER, YouWeiPublicDefine.SEQUENCEID, (ushort)TimeAccOn, (ushort)nTimeACCOffContinue, (ushort)TimeAccOff, ref instructionLen, instruction); pOutData = new byte[instructionLen]; Array.Copy(instruction, pOutData, instructionLen); responseList.Add(pOutData); if (!dicSendTrackEx.ContainsKey(gpsData.FullGpsCode)) { dicSendTrackEx.Add(gpsData.FullGpsCode, ""); } instruction = null; //非私家车,关闭解除报警 //if (this.mIsPrivateCar.ToLower() == "false") //{ // byte[] byt = new byte[4] { 255, 255, 255, 255 }; // instructionLen = 0; // instruction = new byte[512]; // pOutData = null; // YouWeiGPSInterface.EncodeConfDeviceAlarmFun( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // byt, // ref instructionLen, // instruction); // pOutData = new byte[instructionLen]; // Array.Copy(instruction, pOutData, instructionLen); // instruction = null; // aResponseList.Add(pOutData); //} } } } //当前状态 if (gpsData.BaseData.GPSCode.Length > 4) { //主动上传数据、设备定位信息 //获得当前位置(点名)\ //获得当前状态 GPSDataEntity aLastData = null; bool AddedDataFlag = false; switch (receiveDataCondition.commandID) { //added by lixun on 2011/11/22 for solve ticket #2269 case YouWeiPublicDefine.ICOMMAND_DEVICEPOSITION2: case YouWeiPublicDefine.ICOMMAND_DEVICEPOSITION: case YouWeiPublicDefine.ICOMMAND_DEVICECURRENTPOSRES: case YouWeiPublicDefine.ICOMMAND_DEVICECURRSTATUSRES: dataList.Add(result.BaseData); break; case YouWeiPublicDefine.ICOMMAND_DEVICEALARMEVENT: if (gpsData.BaseData.PlunderState == 0 || gpsData.BaseData.PlunderState > 10) { dataList.Add(result.BaseData); } break; } } if (YouWeiDataEx != null && YouWeiDataEx.Length > 1) { for (int i = 1; i < YouWeiDataEx.Length; i++) { if (YouWeiDataEx[i] == null) continue; YouWeiDataEx[i].FullGpsCode = base.CodePrefix + YouWeiDataEx[i].BaseData.GPSCode; result = YouWeiDataEx[i]; if (YouWeiDataEx[i] == null) { continue; } if (YouWeiDataEx[i].BaseData.GPSCode.Length > 4) { switch (receiveDataCondition.commandID) { case YouWeiPublicDefine.ICOMMAND_DEVICEPOSITION2: case YouWeiPublicDefine.ICOMMAND_DEVICEPOSITION: case YouWeiPublicDefine.ICOMMAND_DEVICECURRENTPOSRES: case YouWeiPublicDefine.ICOMMAND_DEVICECURRSTATUSRES: dataList.Add(result.BaseData); break; } } if (receiveDataCondition.commandID == YouWeiPublicDefine.ICOMMAND_DEVICEALARMEVENT) { if (YouWeiDataEx[i].BaseData.PlunderState == 0 || gpsData.BaseData.PlunderState > 10) { dataList.Add(result.BaseData); } } } } //判断持续未定位状态时发送重启GPS指令 if (IsSendRestartMsg(gpsData, DicIsGPSLocated, RestartTimeByUnGPSLocated)) { //bShouldResponse = true; uint instructionLen = 0; byte[] instruction = new byte[512]; byte[] pOutData = null; if (responseList != null) { YouWeiGPSInterface.EncodeResetDevice( (byte)GPSYouWeiProtocolType.GPRSORCDMA, YouWeiPublicDefine.PROTOCOLVER, YouWeiPublicDefine.SEQUENCEID, ref instructionLen, instruction); //instruction = ClearUselessDataFromInstruction((int)instructionLen, instruction); //aResponseList.Add(instruction); pOutData = new byte[instructionLen]; Array.Copy(instruction, pOutData, instructionLen); responseList.Add(pOutData); instruction = null; } else { responseList = new List<byte[]>(); //复位终端 YouWeiGPSInterface.EncodeResetDevice( (byte)GPSYouWeiProtocolType.GPRSORCDMA, YouWeiPublicDefine.PROTOCOLVER, YouWeiPublicDefine.SEQUENCEID, ref instructionLen, instruction); //instruction = ClearUselessDataFromInstruction((int)instructionLen, instruction); //aResponseList.Add(instruction); pOutData = new byte[instructionLen]; Array.Copy(instruction, pOutData, instructionLen); responseList.Add(pOutData); instruction = null; } Logger.Trace("UnGPSLocaatedRestart,GPSCode:" + gpsData.BaseData.GPSCode, null); } return dataList; } catch (Exception ex) { Logger.Error(ex, null); fullGpsCode = string.Empty; return null; } }
/// <summary> /// 解析GPS回传的命令 /// </summary> /// <param name="protocolType">协议类型</param> /// <param name="pInData">GPS回传的命令</param> /// <param name="receiveDataCondition"></param> /// <param name="gpsData">解析后的GPS数据</param> /// <param name="gpsDataEx"></param> /// <param name="pictureData"></param> /// <param name="responseList"></param> /// <returns></returns> private bool Decode( byte protocolType, byte[] pInData, ref YouWeiGPSReceiveDataCondition receiveDataCondition, ref YouWeiGPSData gpsData, ref YouWeiGPSData[] gpsDataEx, ref YouWeiGPSData pictureData, out List<byte[]> responseList) { bool Result = false; responseList = new List<byte[]>(); //解析上传数据 int nResult = ParseGPSCode(protocolType, pInData, ref receiveDataCondition); if (nResult < 0) { Logger.Error("GPSYouWei.YouWeiDataParser.Decode,ParseGPSCode方法返回值为负数,解析数据失败。" + CommonMethod.Transfer.ToHexString(pInData), null); return false; } // 128,下发到GPS的数据长度 uint sendDataLen = 0; //下发到GPS的数据 byte[] sendData = null; //解析后的输出数据 byte[] pOutData = null; try { //应答数据 if (receiveDataCondition.isNeedAnswer) { responseList.Add(receiveDataCondition.pAnswerData); } switch (receiveDataCondition.commandID) { //终端注册 case YouWeiPublicDefine.ICOMMAND_DEVICEREGISTERED: //解析出gpsData数据 IDeviceRegistered Reg = (IDeviceRegistered)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceRegistered)); YouWeiParseGPSDataToEntity.ParseGPSData_Registered_ToEntity(Reg, ref gpsData, base.CodePrefix); break; case YouWeiPublicDefine.ICOMMAND_DEVICEPOSITION2: case YouWeiPublicDefine.ICOMMAND_DEVICEPOSITION: //主动上传数据、设备定位信息 case YouWeiPublicDefine.ICOMMAND_DEVICECURRENTPOSRES: //获得当前位置(点名) case YouWeiPublicDefine.ICOMMAND_DEVICECURRSTATUSRES: //获得当前状态 if (receiveDataCondition.commandID == YouWeiPublicDefine.ICOMMAND_DEVICEPOSITION2) { IDevicePostionStatus PosRes42 = (IDevicePostionStatus)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDevicePostionStatus)); YouWeiParseGPSDataToEntity.ParseGPSData_PostionAndStatus_ToEntity2(PosRes42, ref gpsData, ref gpsDataEx, base.CodePrefix); } else { IDevicePositionAndStatus PosRes = (IDevicePositionAndStatus)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDevicePositionAndStatus)); YouWeiParseGPSDataToEntity.ParseGPSData_PostionAndStatus_ToEntity(PosRes, ref gpsData, ref gpsDataEx, base.CodePrefix); } base.OnDebugDataEvent(this.TransfersType.ToString(), gpsData.FullGpsCode, "----------" + receiveDataCondition.commandID.ToString() + "(" + gpsData.BaseData.OilBearing.ToString() + ")------"); #region 测试命令 //#region 命令发送成功,并且终端有回应,但是这两条指令下发后,终端回应的数据一致 int i = 0; ////停止看守报警 //if (i == 19) //{ // YouWeiGPSInterface.EncodeWatchAlarm( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // 0, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} ////进入看守报警 //if (i == 18) //{ // YouWeiGPSInterface.EncodeWatchAlarm( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // 1, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} //#endregion ////唤醒睡眠 //if (i == 17) //{ // YouWeiGPSInterface.EncodeConfDeviceSleep( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // 0, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} ////进入睡眠 //if (i == 16) //{ // YouWeiGPSInterface.EncodeConfDeviceSleep( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // 1, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} ////查询/设置油耗检测参数 //if (i == 8) //{ // YouWeiGPSInterface.EncodeQueryDeviceOilCheck((byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} ////配置油耗检测参数 //if (i == 9) //{ // ushort[] ratio = new ushort[5] { 0, 25, 50, 75, 100 }; // ushort[] sample = new ushort[5] { 0, 16, 32, 64, 80 }; // YouWeiGPSInterface.EncodeConfDeviceOilCheck( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // 5, // ratio, // sample, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} //配置短信接收号码 //if (i == 4) //{ // sendDataLen = 0; // sendData = new byte[512]; // StringBuilder phone = new StringBuilder("13554930639"); // YouWeiGPSInterface.EncodeSetCenterSMSRecvNumber( // (byte)GPSYouWeiProtocolType.GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // Convert.ToUInt32(gpsData.GPSCode), // (byte)GPSYouWei_Flag.Flag1, // 1, // phone, // ref sendDataLen, // sendData); //} ////设置油量异常(漏油、偷油) 报警检测参数 //if (i == 31) //{ // YouWeiGPSInterface.EncodeConfDeviceOilExceptionCheck( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // 1, // 100, // 1, // 100, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} ////查询油量异常(漏油、偷油)报警检测参数 //if (i == 30) //{ // YouWeiGPSInterface.EncodeQueryDeviceOilExceptionCheck( // (byte)GPSYouWei_ProtocolType.GPSYouWei_ProtocolType_GPRSORCDMA, // YouWeiPublicDefine.PROTOCOLVER, // YouWeiPublicDefine.SEQUENCEID, // ref sendDataLen, // sendData); // blnShouldResponse = true; //} //if (i != 0) //{ // responseList.Add(sendData); //} #endregion break; //车辆报警事件 case YouWeiPublicDefine.ICOMMAND_DEVICEALARMEVENT: IDeviceAlarmEvent AlarmEvent = (IDeviceAlarmEvent)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceAlarmEvent)); YouWeiParseGPSDataToEntity.ParseGPSData_AlarmEvent_ToEntity(AlarmEvent, ref gpsData, base.CodePrefix); Logger.Trace("车辆主动报警。GPSCODE:" + gpsData.FullGpsCode + " 报警类型:" + gpsData.BaseData.PlunderState + " 经纬度--lat:" + gpsData.BaseData.Latitude + " log:" + gpsData.BaseData.Longitude); //不是私家车,立即解除。gxl 2010-3-5 if (!mIsPrivateCar) { //解除报警 3-11注释撤销报警 有为告知 报警不应解除 gxl //YouWeiGPSInterface.EncodeRelieveAlarm(protocolType, YouWeiPublicDefine.PROTOCOLVER, YouWeiPublicDefine.SEQUENCEID, 0, 0, ref sendDataLen, sendData); //aResponseList.Add(sendData); //若是劫警,下发LED信息 if (gpsData.BaseData.PlunderState == 0) { //解除报警 3-11 非私家车,且是劫警,才解除 gxl sendDataLen = 0; sendData = new byte[512]; YouWeiGPSInterface.EncodeRelieveAlarm(protocolType, YouWeiPublicDefine.PROTOCOLVER, YouWeiPublicDefine.SEQUENCEID, 0, 0, ref sendDataLen, sendData); pOutData = new byte[sendDataLen]; Array.Copy(sendData, pOutData, sendDataLen); sendData = null; Logger.Trace("非私家车,自动解除劫警。GPSCODE:" + gpsData.FullGpsCode + " 报警类型:" + gpsData.BaseData.PlunderState); responseList.Add(pOutData); Logger.Trace("GPSYouWei--Gps:" + gpsData.FullGpsCode + " is robbed", null); List<byte[]> PluderLedInstruction = GetLedInstructionWhenPlunder(gpsData.FullGpsCode); IEnumerator<byte[]> en = PluderLedInstruction.GetEnumerator(); while (en.MoveNext()) { byte[] data = en.Current; responseList.Add(data); } //当劫警发生时,终端自动会拍照并上报 } } break; //终端开始上传图片 case YouWeiPublicDefine.ICOMMAND_PICDATAUPLOADSTART: IDeviceUploadPictureStart UploadPictureStart = (IDeviceUploadPictureStart)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceUploadPictureStart)); YouWeiParseGPSDataToEntity.ParseGPSData_UploadPictureStart_ToEntity(UploadPictureStart, ref gpsData, base.CodePrefix); //加入拍照实体 KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.SetGPSCode, null); //每次开始开始上传照片时,先将报警状态清1 KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.PlunderState, 1); if (UploadPictureStart.dwEventNo == 1) //劫警照片 { //标记为劫警拍照 KeepPictureInfo(gpsData.FullGpsCode,TakePictureAction.PlunderState, 0); //正在上传劫警照片 Logger.Trace("GPSYouWei--Gps:" + gpsData.FullGpsCode + " 开始上传劫警照片", null); } else if (UploadPictureStart.dwEventNo == 4) //上车照片 { gpsData.BaseData.IsOnCar = true; KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.CustomerIn, TakePictureType.TakePictureForGetOn); //正在上传上车拍照照片 Logger.Trace("GPSYouWei--Gps:" + gpsData.FullGpsCode + " 开始上传上车照片", null); } else if (UploadPictureStart.dwEventNo == 9)//开门拍照车台自动触发的照片 { KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.RealTimeTakePicture, TakePictureType.TakePictureForOpenDoor); //开门拍照车台自动触发的照片 Logger.Trace("GPSYouWei--Gps:" + gpsData.FullGpsCode + " 开始上传开门照片", null); } else { if (PicTaskPool.ContainsKey(gpsData.FullGpsCode) && PicTaskPool[gpsData.FullGpsCode].Count > 0) { //取出队首的任务 TakePicTask task = PicTaskPool[gpsData.FullGpsCode].Peek(); if (task.TaskType == SimpleCmdType.TimingShoot) { KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.RealTimeTakePicture, TakePictureType.TakePictureForFixedTime); } else if (task.TaskType == SimpleCmdType.TakePictureForDoorShot) { KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.RealTimeTakePicture, TakePictureType.TakePictureForOpenDoor); } else if (task.TaskType == SimpleCmdType.RealTimeShoot || task.TaskType == SimpleCmdType.NormalSeriateShoot) { KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.RealTimeTakePicture, TakePictureType.TakePictureForRealTime); } } Logger.Trace("GPSYouWei--Gps:" + gpsData.FullGpsCode + " 开始上传照片", null); } KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.ReplyCameraID, UploadPictureStart.dwChannelID); KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.PictureCompress, UploadPictureStart.dwPictureCompress); YouWeiParseGPSDataToEntity.ParseGPSData_UploadPictureStart_ToEntity(UploadPictureStart, ref gpsData,CodePrefix); KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.PictureYouWeiGPSData, gpsData); break; case YouWeiPublicDefine.ICOMMAND_PICDATAUPLOAD://图片数据帧 IDeviceUploadPictureData UploadPictureData = (IDeviceUploadPictureData)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceUploadPictureData)); gpsData.FullGpsCode = CodePrefix + UploadPictureData.NotifyHead.dwDeviceNumber.ToString(); gpsData.BaseData.GPSCode = UploadPictureData.NotifyHead.dwDeviceNumber.ToString(); KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.SetPictureData, UploadPictureData.pPicData); Logger.Trace("图片数据接收,GPSCode:" + gpsData.FullGpsCode); //最后一桢数据 if (UploadPictureData.bIsLastFrame) { Logger.Trace("最后一帧图片数据接收,GPSCode:" + gpsData.FullGpsCode); KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.LastFrameNo, UploadPictureData.dwPicFrameNo); KeepPictureInfo(gpsData.FullGpsCode, TakePictureAction.LastFramePictureSeq, UploadPictureData.dwPictureSeq); sendDataLen = 0; sendData = new byte[512]; //下发图片数据确认命令到GPS终端 YouWeiGPSInterface.EncodeUploadPicDataConfirm( (byte)GPSYouWeiProtocolType.GPRSORCDMA, YouWeiPublicDefine.PROTOCOLVER, YouWeiPublicDefine.SEQUENCEID, 0, (byte)dicTakePictureInfo[gpsData.FullGpsCode].LastFramePictureSeq, (ushort)dicTakePictureInfo[gpsData.FullGpsCode].LastFrameNo, ref sendDataLen, sendData); pOutData = new byte[sendDataLen]; Array.Copy(sendData, pOutData, sendDataLen); responseList.Add(pOutData); sendData = null; TakePictureType picType = dicTakePictureInfo[gpsData.FullGpsCode].PictureType; int PlunderState = dicTakePictureInfo[gpsData.FullGpsCode].PlunderState; //将图片数据写成图片文件存入指定位置 WritePicFile(gpsData.BaseData.GPSCode,gpsData.FullGpsCode, ref pictureData); //不是劫警照片,不是开门拍照硬件自动触发的照片,才触发任务对列中的后续照片 if ((PlunderState != 0 && picType != TakePictureType.TakePicutureForNull && picType != TakePictureType.TakePictureForOpenDoor && picType != TakePictureType.TakePictureForGetOn) || (PicTaskPool.ContainsKey(gpsData.FullGpsCode) && PicTaskPool[gpsData.FullGpsCode].Count > 0 && PicTaskPool[gpsData.FullGpsCode].Peek().TaskType == SimpleCmdType.TakePictureForDoorShot)) { //取出队首的任务 TakePicTask task = PicTaskPool[gpsData.FullGpsCode].Peek(); //将任务的状态改为“上一张图片已完成” task.Status = TakePicTaskStatus.LastPicFinished; //执行该任务 DoShoot(gpsData.FullGpsCode, false); } else { Logger.Trace(string.Format("没有触发下一张照片的原因,PlunderState:{0},picType:{1},gpscode:{2}", PlunderState, picType.ToString(), gpsData.FullGpsCode), null); if (PicTaskPool.ContainsKey(gpsData.FullGpsCode)) { if (PicTaskPool[gpsData.FullGpsCode].Count > 0) { Logger.Trace(string.Format("[{0}]队首任务的TaskType:{1}",gpsData.FullGpsCode, PicTaskPool[gpsData.FullGpsCode].Peek().TaskType.ToString()), null); } else { Logger.Trace(string.Format("[{0}]的任务队列任务数为0", gpsData.FullGpsCode), null); } } else { Logger.Trace(string.Format("[{0}]没有任务队列", gpsData.FullGpsCode), null); } } //zhoub@2010-03-30 //对于连拍的情况,触发下一张图片的拍摄,目前只针对有一个摄相头的情况 //分为正常连拍和劫警连拍两种情况 //------------------------------------------------------------------------------------------------------------------ sendDataLen = 0; sendData = new byte[512]; bool bNeedTakePicture = false; //是否需要劫警连拍 bNeedTakePicture = CheckIsNeedTakePictureRobShootTime(gpsData.FullGpsCode, ref sendDataLen, ref sendData); if (bNeedTakePicture == true) { pOutData = new byte[sendDataLen]; Array.Copy(sendData, pOutData, sendDataLen); responseList.Add(pOutData); sendData = null; } } break; //控制电路应答 case YouWeiPublicDefine.ICOMMAND_DEVICECONTROLCIRCUITRES: IDeviceControlCircuitRes ControlCircuitRes = (IDeviceControlCircuitRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceControlCircuitRes)); OnPostAnswer(ControlCircuitRes.NotifyHead, ControlCmdType.DeviceCircuitresAndOil); break; //设置查询短信中心应答 case YouWeiPublicDefine.ICOMMAND_DEVICESMSCENTERES: IGetSetSMSCenterRes SMSCenterRes = (IGetSetSMSCenterRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IGetSetSMSCenterRes)); break; //设置查询GPRS中心应答 case YouWeiPublicDefine.ICOMMAND_DEVICEGPRSCENTERES: IGetSetGPRSCenterRes GPRSCenterRes = (IGetSetGPRSCenterRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IGetSetGPRSCenterRes)); break; //终端心跳消息 case YouWeiPublicDefine.ICOMMAND_DEVICECHECKLINKER: IDeviceCheckLinker HeartBeat = (IDeviceCheckLinker)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceCheckLinker)); break; //终端故障 case YouWeiPublicDefine.ICOMMAND_DEVICETROUBLEEVENT: IDeviceTroubleEvent TroubleEvent = (IDeviceTroubleEvent)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceTroubleEvent)); break; //终端上报事件 case YouWeiPublicDefine.ICOMMAND_DEVICEADDONSEVENT: IDeviceAddOnsEvent AddOnsEvent = (IDeviceAddOnsEvent)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceAddOnsEvent)); break; //查询配置电话号码应答 case YouWeiPublicDefine.ICOMMAND_DEVICEPHONENUMBER: IDevicePhoneNumberRes PhoneNumberRes = (IDevicePhoneNumberRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDevicePhoneNumberRes)); break; //查询设置监控应答 case YouWeiPublicDefine.ICOMMAND_DEVICEMONITORSTATUSRES: IDeviceMonitorStatusRes MonitorStatusRes = (IDeviceMonitorStatusRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceMonitorStatusRes)); break; //设置看守报警应答 case YouWeiPublicDefine.ICOMMAND_DEVICEWATCHALARMRES: IDeviceWatchAlarmRes WatchAlarmRes = (IDeviceWatchAlarmRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceWatchAlarmRes)); break; //设置监听应答 case YouWeiPublicDefine.ICOMMAND_DEVICELISTENRES: IDeviceSetListenRes SetListenRes = (IDeviceSetListenRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceSetListenRes)); OnPostAnswer(SetListenRes.NotifyHead, ControlCmdType.ListenCall, new SimpleCmdType[] { SimpleCmdType .SetITimerTrack}); break; //复位操作应答 case YouWeiPublicDefine.ICOMMAND_DEVICERESETRES: IDeviceResetRes ResetRes = (IDeviceResetRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceResetRes)); OnPostAnswer(ResetRes.NotifyHead, ControlCmdType.SimpleInstruction, new SimpleCmdType[] { SimpleCmdType.ResetGPS}); break; //获取终端版本应答 case YouWeiPublicDefine.ICOMMAND_DEVICEVERSIONRES: IDeviceVersionRes VersionRes = (IDeviceVersionRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceVersionRes)); break; //中心向终端发送文本消息应答(调度) case YouWeiPublicDefine.ICOMMAND_DELIVERTEXTTODEVICE: IDeivceResDeliverTextMsg ResDeliverTextMsg = (IDeivceResDeliverTextMsg)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeivceResDeliverTextMsg)); OnPostAnswer(ResDeliverTextMsg.NotifyHead,ControlCmdType.DispatchControl); break; //终端向中心发送文本消息 case YouWeiPublicDefine.ICOMMAND_DEVICESENDTEXTMSG: IDeviceSendTextMsg SendTextMsg = (IDeviceSendTextMsg)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceSendTextMsg)); YouWeiParseGPSDataToEntity.parseGPSData_DeviceSendTextMsg_ToEntity(SendTextMsg, ref gpsData, base.CodePrefix); TransferGPSMsgAndSaveMsgToDB(SendTextMsg.NotifyHead.dwDeviceNumber.ToString(), SendTextMsg.wTextCodingMode, SendTextMsg.wTextLen, SendTextMsg.TextContent); break; //获取终端功能应答 case YouWeiPublicDefine.ICOMMAND_DEVICEFUNGETRES: IDeviceFunctionConfigRes FunctionConfigRes = (IDeviceFunctionConfigRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceFunctionConfigRes)); break; //查询/设置油量异常(漏油、偷油) 报警检测参数 case YouWeiPublicDefine.ICOMMAND_DEVICEOILEXCEPTIONPARAMRES: IDeviceOilConsumeAlarmParamRes OilConsumeAlarmParamRes = (IDeviceOilConsumeAlarmParamRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceOilConsumeAlarmParamRes)); YouWeiParseGPSDataToEntity.ParseGPSData_OilConsumeAlarmParamRes_ToEntity(OilConsumeAlarmParamRes, ref gpsData, base.CodePrefix); break; //查询/设置油耗检测参数 case YouWeiPublicDefine.ICOMMAND_DEVICEOILSAMPLINGPARAMRES: IDeviceOilSamplingParamRes OilSamplingParamRes = (IDeviceOilSamplingParamRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceOilSamplingParamRes)); break; //营运数据上传 case YouWeiPublicDefine.ICOMMAND_DEVICEUPLOADBUSINESSDATA: IDeviceUploadBusinessData UploadBusinessData = (IDeviceUploadBusinessData)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceUploadBusinessData)); break; //设置参数应答 case YouWeiPublicDefine.ICOMMAND_CONFDEVICEPARAMRES: IConfDeviceParamRes ConfDeviceParamRes = (IConfDeviceParamRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IConfDeviceParamRes)); break; //设置电子围栏应答 case YouWeiPublicDefine.ICOMMAND_DEVICELINEAREASETRES: IDeviceLineAreaRes LineAreaRes = (IDeviceLineAreaRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceLineAreaRes)); break; //设置轨迹参数应答 case YouWeiPublicDefine.ICOMMAND_CONFPOSSTOREPARAMRES: IConfDevicePosStoreParamRes PosStoreParamRes = (IConfDevicePosStoreParamRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IConfDevicePosStoreParamRes)); break; case YouWeiPublicDefine.ICOMMAND_GETHISPOSTIONRES://获取轨迹应答 case YouWeiPublicDefine.ICOMMAND_GETHISPICTIONRES://获取历史图片清单应答 IGetDeviceHisPosRes HisPosRes = (IGetDeviceHisPosRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IGetDeviceHisPosRes)); break; //设置图片参数应答 case YouWeiPublicDefine.ICOMMAND_CONFPICSTOREPARAMRES: IConfDevicePicStoreParamRes PicStoreParamRes = (IConfDevicePicStoreParamRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IConfDevicePicStoreParamRes)); break; //历史图片清单上传 case YouWeiPublicDefine.ICOMMAND_DEVICEUPLOADHISPICLIST: IDeviceUploadHisPicList UploadHisPicList = (IDeviceUploadHisPicList)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceUploadHisPicList)); break; //拍照应答 case YouWeiPublicDefine.ICOMMAND_TAKEPICTURERES: IDeviceTakePictureRes TakePictureRes = (IDeviceTakePictureRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceTakePictureRes)); YouWeiParseGPSDataToEntity.parseGPSData_TakePictureRes_ToEntity(TakePictureRes, ref gpsData, base.CodePrefix); OnPostAnswer(TakePictureRes.NotifyHead, ControlCmdType.SendTakePicture); break; //终端核实图片 case YouWeiPublicDefine.ICOMMAND_PICDATACONFIRM: IDevicePictureDataConfirm PictureDataConfirm = (IDevicePictureDataConfirm)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDevicePictureDataConfirm)); break; //终端应答中心下发透明数据 case YouWeiPublicDefine.ICOMMAND_DEVLIVERTRANSDATARES: IDeliverTransparentDataRes TransparentDataRes = (IDeliverTransparentDataRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeliverTransparentDataRes)); OnPostAnswer(TransparentDataRes.NotifyHead, ControlCmdType.SendAdvertisement); break; //终端上传透明数据 case YouWeiPublicDefine.ICOMMAND_SUBMITTRANSDATA: IDeviceSubmitTransparentDataReq SubmitTransparentDataReq = (IDeviceSubmitTransparentDataReq)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceSubmitTransparentDataReq)); break; //解除报警 case YouWeiPublicDefine.ICOMMAND_DEVICERELIEVEALARMRES: IDeviceRelieveAlarmRes RelieveAlarmRes = (IDeviceRelieveAlarmRes)Transfer.BytesToStuct(receiveDataCondition.pOutData, typeof(IDeviceRelieveAlarmRes)); OnPostAnswer(RelieveAlarmRes.NotifyHead,ControlCmdType.DischargeAlarm); break; } Result = true; } catch (Exception e) { Result = false; Logger.Error("GPSYouWei.YouWeiDataParser.Decode:" + e.ToString()); } return Result; }
/// <summary> /// 解析GPS上传数据 /// </summary> /// <param name="protocolType">协议类型</param> /// <param name="pInData">GPS数据</param> /// <param name="receiveDataCondition"></param> public int ParseGPSCode(byte protocolType, byte[] pInData, ref YouWeiGPSReceiveDataCondition receiveDataCondition) { uint commandID = 0;//消息命令字 byte sequenceID = 0;//消息流水号 uint pOutDataLen = 0;//终端发送的数据长度 byte[] pOutData = new byte[2048];//终端发送的数据内容 bool isNeedAnswer = false;//是否需要中心应答 uint pAnswerDataLen = 0; //发送给终端应答的数据长度 byte[] pAnswerData = new byte[256]; //发送给终端应答的数据内容 uint inDataLen = (uint)pInData.Length;//要解析数据的长度 int oResult = YouWeiGPSInterface.GPSDecode(protocolType, inDataLen, pInData, ref commandID, ref sequenceID, ref pOutDataLen, pOutData, ref isNeedAnswer, ref pAnswerDataLen, pAnswerData); receiveDataCondition.commandID = commandID;//消息命令字 receiveDataCondition.sequenceID = sequenceID;//消息流水号 receiveDataCondition.pOutDataLen = pOutDataLen;//终端发送的数据长度 receiveDataCondition.pOutData = new byte[4096]; //receiveDataCondition.pOutData = new byte[pOutDataLen]; Array.Copy(pOutData, receiveDataCondition.pOutData, pOutDataLen);//终端发送的数据内容 pOutData = null; receiveDataCondition.isNeedAnswer = isNeedAnswer;//是否需要中心应答 receiveDataCondition.pAnswerDataLen = pAnswerDataLen;//发送给终端应答的数据长度 receiveDataCondition.pAnswerData = new byte[pAnswerDataLen]; Array.Copy(pAnswerData, receiveDataCondition.pAnswerData, pAnswerDataLen);//发送给终端应答的数据内容 pAnswerData = null; return oResult; }