Пример #1
0
        /// <summary>
        /// 选择应用层下发的任务
        /// </summary>
        /// <param name="receivedBuffer">接收缓冲区数据</param>
        /// <param name="remotePoint">客户端端点</param>
        public void SwitchEvent(EndPoint remotePoint, byte[] receivedBuffer)
        {
            try
            {
                //GPSCode
                string gpsCode = string.Empty;

                //读取命令
                CmdData cmdData = new CmdData();

                //读入数据
                cmdData.ReadBuffer(0, receivedBuffer);
                Logger.Trace("收到应用层下发指令,指令类型:" + cmdData.Data.Cmd.ToString());

                byte[] sendBuffer = null;

                switch (cmdData.Data.Cmd)
                {
                    //调度命令
                    case ControlCmdType.DispatchControl:

                        DispatchControl DispatchControl = new DispatchControl();

                        //读入数据
                        DispatchControl.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + DispatchControl.GPSCode);

                        //将连接加入连接哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(DispatchControl.GPSCode, remotePoint);

                        //下发调度命令
                        HandleDispatchControlInfo(DispatchControl);

                        break;

                    //监听喊话
                    case ControlCmdType.ListenCall:

                        ListenCallControl CallControl = new ListenCallControl();

                        //读入数据
                        CallControl.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + CallControl.GPSCode);

                        //将连接加入连接哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(CallControl.GPSCode, remotePoint);

                        //下发调度命令
                        HandleListenCallInfo(CallControl);

                        break;

                    //简单控制命令
                    //case ControlCmdType.SimpleInstruction:
                    //下发广告或LED其它命令
                    case ControlCmdType.LEDControl:

                        SimpleInstructionControl SimpleControl = new SimpleInstructionControl();
                        SimpleControl.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + SimpleControl.GPSCode);

                        //将连接加入连接哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(SimpleControl.GPSCode, remotePoint);

                        HandleSimpleInstructionControl(SimpleControl);

                        break;

                    //下发拍照的动作
                    case ControlCmdType.SendTakePicture:

                        TakePictureControl takePicture = new TakePictureControl();
                        takePicture.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + takePicture.GPSCode);

                        //将连接加入哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(takePicture.GPSCode, remotePoint);

                        HandleShootInstructionControl(takePicture);

                        break;

                    //下发拍照的动作(多摄像头)
                    case ControlCmdType.SendTakePictureMultiCamera:

                        TakePictureControlMultiCamera takePictureMultiCamera = new TakePictureControlMultiCamera();
                        takePictureMultiCamera.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + takePictureMultiCamera.GPSCode);

                        //将连接加入哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(takePictureMultiCamera.GPSCode, remotePoint);

                        HandleShootInstructionControl(takePictureMultiCamera);

                        break;

                    case ControlCmdType.SupplyOilCircuit:
                    //强制断油断电
                    case ControlCmdType.BreakOilCircuitByForce:
                    //智能断油断电
                    case ControlCmdType.BreakOilCircuitBySmart:

                        ControlOilCircuit ControlOil = new ControlOilCircuit();

                        ControlOil.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + ControlOil.GPSCode);

                        //将连接加入连接哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(ControlOil.GPSCode, remotePoint);

                        //油路通断控制
                        HandleBreakOilCircuit(ControlOil);

                        break;

                    //北京视展LED控制
                    case ControlCmdType.BJSZLedControl:
                    case ControlCmdType.SendAdvertisement:

                        LEDControl ledControl = new LEDControl();
                        ledControl.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + ledControl.GPSCode);
                        //将连接加入连接哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(ledControl.GPSCode, remotePoint);
                        HandleBJSZLEDContentInfo(ledControl);
                        break;

                    //解除报警
                    case ControlCmdType.DischargeAlarm:

                        DischangeAlarmControl dischangeAlarm = new DischangeAlarmControl();
                        dischangeAlarm.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + dischangeAlarm.GPSCode);
                        //将连接加入连接哈希表
                        GpsDataParser.OnPostAppLayerAddressEvent(dischangeAlarm.GPSCode, remotePoint);
                        DischargeAlarm(dischangeAlarm);

                        break;

                    //超速报警
                    case ControlCmdType.OverSpeedAlarm:

                        OverSpeedAlarmControl overSpeedAlarm = new OverSpeedAlarmControl();
                        overSpeedAlarm.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + overSpeedAlarm.GPSCode);
                        GpsDataParser.OnPostAppLayerAddressEvent(overSpeedAlarm.GPSCode, remotePoint);
                        HandleOverSpeed(overSpeedAlarm);

                        break;

                    //获取网关活动信息
                    case ControlCmdType.GetGatewayActiveInfo:

                        GatewayActiveInfo activeInfo = new GatewayActiveInfo();
                        activeInfo.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + activeInfo.GPSCode);
                        GpsDataParser.OnPostAppLayerAddressEvent(activeInfo.GPSCode, remotePoint);
                        SendGatewayActiveInfo(activeInfo, remotePoint);
                        break;
                    //更新GPS总里程值
                    case ControlCmdType.updatemileage:

                        UpdateMileage UpMileage = new UpdateMileage();
                        UpMileage.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + UpMileage.GPSCode);
                        GpsDataParser.OnPostAppLayerAddressEvent(UpMileage.GPSCode, remotePoint);
                        SendUpdateMileage(UpMileage);
                        break;
                    //设置GPS上传周期
                    case ControlCmdType.SendGPSPosUploadInterval:

                        GPSPosUploadInterval posUploadInterval = new GPSPosUploadInterval();
                        posUploadInterval.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + posUploadInterval.GPSCode);
                        GpsDataParser.OnPostAppLayerAddressEvent(posUploadInterval.GPSCode, remotePoint);
                        HandleGPSPosUploadInterval(posUploadInterval);
                        break;

                    //设置移动台初始经参数
                    case ControlCmdType.SetMobileInitPara:

                        SetMobileInitPara setMobileInitPara = new SetMobileInitPara();
                        setMobileInitPara.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + setMobileInitPara.GPSCode);
                        SetMobileInitPara(setMobileInitPara);

                        break;

                    //雅迅设备,配置报警器
                    case ControlCmdType.AllocateAnnounciator:

                        SetAnnounciator setAnnounciator = new SetAnnounciator();
                        setAnnounciator.ReadBuffer(0, cmdData.DataBuffer);

                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + setAnnounciator.GPSCode);

                        gpsCode = setAnnounciator.GPSCode;

                        sendBuffer = GpsDataParser.ParseControlInstruction(ControlCmdType.AllocateAnnounciator, setAnnounciator);

                        break;
                    case ControlCmdType.SetCircleRegion:
                    case ControlCmdType.SetRectangleRegion:
                    case ControlCmdType.SetPloygon:
                    case ControlCmdType.SetFixedLine:
                    case ControlCmdType.RemoveCircleRegion:
                    case ControlCmdType.RemoveRectangleRegion:
                    case ControlCmdType.RemovePloygon:
                    case ControlCmdType.RemoveFixedLine:
                    case ControlCmdType.TMLControl:
                    case ControlCmdType.SendTxtToTML:
                    case ControlCmdType.PhoneCallback:
                    case ControlCmdType.CameraShootImmediately:
                    case ControlCmdType.PositionQueryReq:
                    case ControlCmdType.SetStopCarAlarm:
                    case ControlCmdType.SetOverFatigueAlarm:
                    case ControlCmdType.SetOverSpeedAlarm:
                    case ControlCmdType.GetRravelRecord:

                        BuBiaoCommonControl BBControl = new BuBiaoCommonControl();
                        BBControl.ReadBuffer(0, cmdData.DataBuffer);

                        GpsDataParser.OnPostAppLayerAddressEvent(BBControl.GPSCode, remotePoint);
                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + BBControl.GPSCode);

                        HandleBuBiaoMessage(BBControl, cmdData.Data.Cmd);
                        break;
                    //部标解除报警
                    case ControlCmdType.ReleaseAlarm:
                        BuBiaoCommonControl ReleaseControl = new BuBiaoCommonControl();
                        ReleaseControl.ReadBuffer(0, cmdData.DataBuffer);

                        GpsDataParser.ReleaseAlarm(ReleaseControl);
                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + ReleaseControl.GPSCode);
                        break;
                    case ControlCmdType.OpenGPS:
                        KKSSimpleControl openGPSControl = new KKSSimpleControl();
                        openGPSControl.ReadBuffer(0, cmdData.DataBuffer);
                        GpsDataParser.OnPostAppLayerAddressEvent(openGPSControl.GPSCode, remotePoint);
                        HandleKKSSimpleControlInfo(ControlCmdType.OpenGPS, openGPSControl);
                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + openGPSControl.GPSCode);
                        break;
                    case ControlCmdType.SetFriendNumber:
                        KKSSimpleControl setfriendnumberControl = new KKSSimpleControl();
                        setfriendnumberControl.ReadBuffer(0, cmdData.DataBuffer);
                        GpsDataParser.OnPostAppLayerAddressEvent(setfriendnumberControl.GPSCode, remotePoint);
                        HandleKKSSimpleControlInfo(ControlCmdType.SetFriendNumber,setfriendnumberControl);
                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + setfriendnumberControl.GPSCode);
                        break;
                    case ControlCmdType.GetFriendNumber:
                        KKSSimpleControl getfriendnumberControl = new KKSSimpleControl();
                        getfriendnumberControl.ReadBuffer(0, cmdData.DataBuffer);
                        GpsDataParser.OnPostAppLayerAddressEvent(getfriendnumberControl.GPSCode, remotePoint);
                        HandleKKSSimpleControlInfo(ControlCmdType.GetFriendNumber,getfriendnumberControl);
                        Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + getfriendnumberControl.GPSCode);
                        break;

                    default:


                        break;
                }
                //GpsDataParser.OnPostSendHandlerEvent(gpsCode, string.Empty, sendBuffer);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }
        }
Пример #2
0
        public string GetGpsCodeFromBuffer(byte[] receivedBuffer)
        {
            string gpsCode = string.Empty;

            try
            {
                CmdData cmdData = new CmdData();
                cmdData.ReadBuffer(0, receivedBuffer);
                switch (cmdData.Data.Cmd)
                {
                    //调度命令
                    case ControlCmdType.DispatchControl:
                        DispatchControl DispatchControl = new DispatchControl();
                        DispatchControl.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = DispatchControl.GPSCode;

                        break;

                    //监听喊话
                    case ControlCmdType.ListenCall:
                        ListenCallControl CallControl = new ListenCallControl();
                        CallControl.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = CallControl.GPSCode;
                        break;

                    case ControlCmdType.LEDControl:
                        SimpleInstructionControl SimpleControl = new SimpleInstructionControl();
                        SimpleControl.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = SimpleControl.GPSCode;

                        break;

                    //下发拍照的动作
                    case ControlCmdType.SendTakePicture:
                        TakePictureControl takePicture = new TakePictureControl();
                        takePicture.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = takePicture.GPSCode;

                        break;

                    //下发拍照的动作(多摄像头)
                    case ControlCmdType.SendTakePictureMultiCamera:
                        TakePictureControlMultiCamera takePictureMultiCamera = new TakePictureControlMultiCamera();
                        takePictureMultiCamera.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = takePictureMultiCamera.GPSCode;
                        break;

                    case ControlCmdType.SupplyOilCircuit:
                    //强制断油断电
                    case ControlCmdType.BreakOilCircuitByForce:
                    //智能断油断电
                    case ControlCmdType.BreakOilCircuitBySmart:
                        ControlOilCircuit ControlOil = new ControlOilCircuit();
                        ControlOil.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = ControlOil.GPSCode;
                        break;

                    //北京视展LED控制
                    case ControlCmdType.BJSZLedControl:
                    case ControlCmdType.SendAdvertisement:
                        LEDControl ledControl = new LEDControl();
                        ledControl.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = ledControl.GPSCode;

                        break;
                    //解除报警
                    case ControlCmdType.DischargeAlarm:
                        DischangeAlarmControl dischangeAlarm = new DischangeAlarmControl();
                        dischangeAlarm.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = dischangeAlarm.GPSCode;

                        break;

                    //超速报警
                    case ControlCmdType.OverSpeedAlarm:
                        OverSpeedAlarmControl overSpeedAlarm = new OverSpeedAlarmControl();
                        overSpeedAlarm.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = overSpeedAlarm.GPSCode;
                        break;

                    //获取网关活动信息
                    case ControlCmdType.GetGatewayActiveInfo:
                        GatewayActiveInfo activeInfo = new GatewayActiveInfo();
                        activeInfo.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = activeInfo.GPSCode;
                        break;
                    //更新GPS总里程值
                    case ControlCmdType.updatemileage:
                        UpdateMileage UpMileage = new UpdateMileage();
                        UpMileage.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = UpMileage.GPSCode;
                        break;
                    //设置GPS上传周期
                    case ControlCmdType.SendGPSPosUploadInterval:
                        GPSPosUploadInterval posUploadInterval = new GPSPosUploadInterval();
                        posUploadInterval.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = posUploadInterval.GPSCode;
                        break;

                    //设置移动台初始经参数
                    case ControlCmdType.SetMobileInitPara:
                        SetMobileInitPara setMobileInitPara = new SetMobileInitPara();
                        setMobileInitPara.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = setMobileInitPara.GPSCode;
                        break;

                    //雅迅设备,配置报警器
                    case ControlCmdType.AllocateAnnounciator:
                        SetAnnounciator setAnnounciator = new SetAnnounciator();
                        setAnnounciator.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = setAnnounciator.GPSCode;
                        break;
                    case ControlCmdType.SetCircleRegion:
                    case ControlCmdType.SetRectangleRegion:
                    case ControlCmdType.SetPloygon:
                    case ControlCmdType.SetFixedLine:
                    case ControlCmdType.RemoveCircleRegion:
                    case ControlCmdType.RemoveRectangleRegion:
                    case ControlCmdType.RemovePloygon:
                    case ControlCmdType.RemoveFixedLine:
                    case ControlCmdType.TMLControl:
                    case ControlCmdType.SendTxtToTML:
                    case ControlCmdType.PhoneCallback:
                    case ControlCmdType.CameraShootImmediately:
                    case ControlCmdType.PositionQueryReq:
                    case ControlCmdType.SetStopCarAlarm:
                    case ControlCmdType.SetOverFatigueAlarm:
                    case ControlCmdType.SetOverSpeedAlarm:
                    case ControlCmdType.GetRravelRecord:
                    //case ControlCmdType.MediaInfoSetting:
                    //case ControlCmdType.MediaInfoService:
                    //case ControlCmdType.EventSetting:
                    //case ControlCmdType.PublishQuestion:
                    //case ControlCmdType.TempLocationTrace:
                    //case ControlCmdType.VehicleControl:

                        BuBiaoCommonControl BBControl = new BuBiaoCommonControl();
                        BBControl.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = BBControl.GPSCode;
                        break;
                    //部标解除报警
                    case ControlCmdType.ReleaseAlarm:
                        BuBiaoCommonControl ReleaseControl = new BuBiaoCommonControl();
                        ReleaseControl.ReadBuffer(0, cmdData.DataBuffer);
                        gpsCode = ReleaseControl.GPSCode;
                        break;

                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }

            return gpsCode;
        }