Exemplo n.º 1
0
        protected void ParseSimpleInstructionControl(SimpleInstructionControlEntity entity, ref uint instructionLen, ref byte[] instruction)
        {

            string gpsCode = entity.GPSCode;

            byte[] LEDData;

            SimpleCmdType simpleCmdType = entity.InstructionType;
            Logger.Trace("部标LED控制:" + simpleCmdType.ToString() + "  " + entity.InstructionContent + " " + entity.GPSCode);

            switch (simpleCmdType)
            {


                //LED打开
                case SimpleCmdType.LEDOpen:

                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDTurnOn();

                    Change2TransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction, gpsCode);

                    break;

                //LED关闭
                case SimpleCmdType.LEDClose:

                    //LEDData = YouWeiLEDCommander.GenerateTurnOffCommand();
                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDTurnOff();

                    Change2TransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction, gpsCode);

                    break;

                //LED校时
                case SimpleCmdType.LEDSynchronizetime:

                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDSynchronizeTime(DateTime.Now);

                    Change2TransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction, gpsCode);

                    break;

                //LED删除信息
                case SimpleCmdType.LEDDeleteControlInfo:

                    //DeleteLEDBoxNumContent(entity, ref instructionLen, ref instruction);

                    break;

                //LED调节亮度
                case SimpleCmdType.LEDAdjustBrightness:

                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDAdjustBrightness(Convert.ToInt32(entity.InstructionContent));

                    Change2TransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction, gpsCode);

                    break;

            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取简单控制命令,并发送后,删除简单控制命令信息
        /// 旧版本对应数据库表:gps_simpleinstructioncontrol
        /// </summary>
        /// <param name="simpleControl"></param>
        /// <param name="type"></param>
        public void HandleSimpleInstructionControl(SimpleInstructionControl simpleControl)
        {
            byte[] sendBuffer;

            string gpsCode = simpleControl.GPSCode;

            SimpleInstructionControlEntity entity = new SimpleInstructionControlEntity();
            entity.InstructionContent = simpleControl.SendContent;
            entity.GPSCode = simpleControl.GPSCode;
            entity.InstructionType = simpleControl.Data.InstructionType;

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

                //解析页面下发数据
                sendBuffer = GpsDataParser.ParseControlInstruction(ControlCmdType.SimpleInstruction, entity);
                if (sendBuffer == null || sendBuffer.Length <= 0)
                {
                    return;
                }

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

                    if (send > 0)
                    {
                        //发送回复表示执行成功
                        //SendAnswerToWeb(simpleControl.SerialNumber, false, gpsCode, ControlCmdType.SimpleInstruction,true,new SimpleCmdType[]{entity.InstructionType});
                        OnSendAnswerToWebEvent(simpleControl.SerialNumber, false, gpsCode, ControlCmdType.SimpleInstruction,true,new SimpleCmdType[]{entity.InstructionType});
                        Logger.Trace("GPSYouWei--Gps:" + gpsCode + " HandleSimpleInstructionControl: "+entity.InstructionType.ToString()+" successfully", null);
                        switch (entity.InstructionType)
                        {
                            //设置IP和端口号
                            case SimpleCmdType.SetIPAndPort:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set ip and port instuction successfully", null);

                                break;

                            case SimpleCmdType.SetITimerTrack:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set time tracker instuction successfully", null);

                                break;

                            case SimpleCmdType.ResetDevice:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset deivce instuction successfully", null);

                                break;

                            case SimpleCmdType.ResetGPS:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset GPS instuction successfully", null);

                                break;

                            case SimpleCmdType.ResetGSM:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset GSM instuction successfully", null);

                                break;

                            case SimpleCmdType.ResetFittings:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset fitting instuction successfully", null);

                                break;

                            case SimpleCmdType.SetSMSPhoneNumber:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set SMS Phone Number instuction successfully", null);

                                break;

                            case SimpleCmdType.RealTimeShoot:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send real time picture instuction successfully", null);

                                break;
                            case SimpleCmdType.LEDClose:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set LEDClose instuction successfully", null);

                                break;

                            case SimpleCmdType.LEDOpen:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set LEDOpen instuction successfully", null);

                                break;
                        }
                    }
                    else
                    {
                        //发送回复表示执行失败
                        //SendAnswerToWeb(simpleControl.SerialNumber, false, gpsCode, ControlCmdType.SimpleInstruction, false, new SimpleCmdType[] { entity.InstructionType });
                        OnSendAnswerToWebEvent(simpleControl.SerialNumber, false, gpsCode, ControlCmdType.SimpleInstruction, false, new SimpleCmdType[] { entity.InstructionType });
                        Logger.Trace("GPSYouWei--Gps:" + gpsCode + " HandleSimpleInstructionControl: " + entity.InstructionType.ToString() + " failed", null);

                        switch (entity.InstructionType)
                        {
                            case SimpleCmdType.SetIPAndPort:

                                Logger.Trace("GPSYouWei--Gps:" + "gpsCode+ send set ip and port instuction failed", null);

                                break;

                            case SimpleCmdType.SetITimerTrack:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set time tracker instuction failed", null);

                                break;

                            case SimpleCmdType.ResetDevice:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset deivce instuction failed", null);

                                break;

                            case SimpleCmdType.ResetGPS:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset GPS instuction failed", null);

                                break;

                            case SimpleCmdType.ResetGSM:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset GSM instuction failed", null);

                                break;

                            case SimpleCmdType.ResetFittings:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send reset fitting instuction failed", null);

                                break;

                            case SimpleCmdType.SetSMSPhoneNumber:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set SMS Phone Number instuction failed", null);

                                break;

                            case SimpleCmdType.RealTimeShoot:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send real time picture instuction failed", null);

                                //测试拍照
                                //Logger.Trace("发送失败:id=" + entity.ID + ",InstructionType=" + entity.InstructionType.ToString(), null);

                                break;

                            case SimpleCmdType.LEDClose:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set LEDClose instuction failed", null);

                                break;

                            case SimpleCmdType.LEDOpen:

                                Logger.Trace("GPSYouWei--Gps:" + gpsCode + " send set LEDOpen instuction failed", null);

                                break;
                        }
                    }
                }
                catch (SocketException ex)
                {
                    //从列表移除此连接
                    //TCPConnList.Instance().RemoveTCPConnection(gpsCode);
                    
                    Logger.Trace("GPSYouWei--Gps:" + gpsCode + "发送简单控制命令时异常" + ex.ToString(), null);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
            }
            finally
            {
                sendBuffer = null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 删除LED信箱
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="instructionLen"></param>
        /// <param name="instruction"></param>
        private void DeleteLEDBoxNumContent(SimpleInstructionControlEntity entity, ref uint instructionLen, ref byte[] instruction)
        {
            byte[] LEDData;

            try
            {
                if (entity.InstructionContent == null)
                {
                    entity.InstructionContent = "0|0";
                }

                string[] BoxNums = entity.InstructionContent.Split('|');

                if (BoxNums.Length == 2)
                {
                    if (Convert.ToInt32(BoxNums[1]) == 0)
                    {
                        LEDData = YouWeiLEDCommander.GenerateDeleteAllCommand();
                    }
                    else
                    {
                        LEDData = YouWeiLEDCommander.GenerateDeleteCommand(Convert.ToInt32(BoxNums[0]).ToString("0000"), Convert.ToInt32(BoxNums[0]).ToString("0000"));
                    }

                    SendTransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GPSYouWei.YouWeiDataParser.DeleteLEDBoxNumContent" + ex.ToString(), null);
                instruction = null;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 设置GPS的IP和端口号
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="instructionLen"></param>
        /// <param name="instruction"></param>
        private void SetGPSIPAndPort(SimpleInstructionControlEntity entity, ref uint instructionLen, ref byte[] instruction)
        {
            string gpsCode = entity.GPSCode.Substring(GPSCODEPRDFIXLEN, entity.GPSCode.Length - GPSCODEPRDFIXLEN);

            try
            {
                if (entity.InstructionContent != null)
                {
                    string[] strIPPort = entity.InstructionContent.Split('|');

                    if (strIPPort.Length == 2)
                    {
                        YouWeiGPSInterface.EncodeSetGPRSChannel(
                            (byte)GPSYouWeiProtocolType.GPRSORCDMA,
                            YouWeiPublicDefine.PROTOCOLVER,
                            YouWeiPublicDefine.SEQUENCEID,
                            Convert.ToUInt32(gpsCode),
                            15,
                            "CMNET",
                            strIPPort[0],
                            Convert.ToUInt16(strIPPort[1]),
                            1,
                            ref instructionLen,
                            instruction);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GPSYouWei.YouWeiDataParser.SetGPSIPAndPort" + ex.ToString(), null);
                instruction = null;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 解析简单GPS控制命令,在旧版本网关中此命令从selp库gps_simpleinstructioncontrol表读取,现在改为从应用层直接下发
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="instructionLen"></param>
        /// <param name="instruction"></param>
        protected void ParseSimpleInstructionControl(SimpleInstructionControlEntity entity, ref uint instructionLen, ref byte[] instruction)
        {
            //string gpsCode = entity.GPSCode.Substring(GPSCODEPRDFIXLEN, entity.GPSCode.Length - GPSCODEPRDFIXLEN);

            string gpsCode = entity.GPSCode;

            byte[] LEDData;

            SimpleCmdType simpleCmdType = entity.InstructionType;

            switch (simpleCmdType)
            {
                //复位终端
                case SimpleCmdType.ResetDevice:

                    YouWeiGPSInterface.EncodeResetDevice(
                        (byte)GPSYouWeiProtocolType.GPRSORCDMA,
                        YouWeiPublicDefine.PROTOCOLVER,
                        YouWeiPublicDefine.SEQUENCEID,
                        ref instructionLen,
                        instruction);

                    break;

                //复位GPS
                case SimpleCmdType.ResetGPS:

                    YouWeiGPSInterface.EncodeResetGPS(
                        (byte)GPSYouWeiProtocolType.GPRSORCDMA,
                        YouWeiPublicDefine.PROTOCOLVER,
                        YouWeiPublicDefine.SEQUENCEID,
                        ref instructionLen,
                        instruction);

                    //instruction = ClearUselessDataFromInstruction((int)instructionLen, instruction);

                    break;

                //复位GSM
                case SimpleCmdType.ResetGSM:

                    YouWeiGPSInterface.EncodeResetGSM(
                        (byte)GPSYouWeiProtocolType.GPRSORCDMA,
                        YouWeiPublicDefine.PROTOCOLVER,
                        YouWeiPublicDefine.SEQUENCEID,
                        ref instructionLen,
                        instruction);

                    break;

                //复位终端外部设备
                case SimpleCmdType.ResetFittings:

                    YouWeiGPSInterface.EncodeResetFittings(
                        (byte)GPSYouWeiProtocolType.GPRSORCDMA,
                        YouWeiPublicDefine.PROTOCOLVER,
                        YouWeiPublicDefine.SEQUENCEID,
                        ref instructionLen,
                        instruction);

                    break;

                //LED打开
                case SimpleCmdType.LEDOpen:

                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDTurnOn();

                    SendTransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction);

                    break;

                //LED关闭
                case SimpleCmdType.LEDClose:

                    //LEDData = YouWeiLEDCommander.GenerateTurnOffCommand();
                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDTurnOff();

                    SendTransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction);

                    break;

                //LED校时
                case SimpleCmdType.LEDSynchronizetime:

                    //LEDData = YouWeiLEDCommander.GenerateSynchronizeTimeCommand(DateTime.Now);
                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDSynchronizeTime(DateTime.Now);

                    SendTransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction);

                    break;

                //LED删除信息
                case SimpleCmdType.LEDDeleteControlInfo:

                    DeleteLEDBoxNumContent(entity, ref instructionLen, ref instruction);

                    //instruction = ClearUselessDataFromInstruction((int)instructionLen, instruction);

                    break;

                //LED调节亮度
                case SimpleCmdType.LEDAdjustBrightness:

                    LEDData = BeiJingShiZhanLEDCommander.BJSZ_LEDAdjustBrightness(Convert.ToInt32(entity.InstructionContent));

                    SendTransparentData((uint)LEDData.Length, LEDData, ref instructionLen, ref instruction);

                    break;

                //设置GPS的IP和端口号
                case SimpleCmdType.SetIPAndPort:

                    SetGPSIPAndPort(entity, ref instructionLen, ref instruction);

                    //instruction = ClearUselessDataFromInstruction((int)instructionLen, instruction);

                    break;

                //设置GPS (15秒)定时监控
                case SimpleCmdType.SetITimerTrack:

                    YouWeiGPSInterface.EncodeStartTimerTrack(
                        (byte)GPSYouWeiProtocolType.GPRSORCDMA,
                        YouWeiPublicDefine.PROTOCOLVER,
                        YouWeiPublicDefine.SEQUENCEID,
                        (ushort)Convert.ToInt32(entity.InstructionContent),
                        0xFFFF,
                        ref instructionLen,
                        instruction);

                    //instruction = ClearUselessDataFromInstruction((int)instructionLen, instruction);

                    break;

                //劫警连拍
                case SimpleCmdType.TakePictureRobShoot:

                    StartTakePictureRobShootTime(gpsCode);

                    CheckIsNeedTakePictureRobShootTime(gpsCode, ref instructionLen, ref instruction);

                    break;
            }
        }