예제 #1
0
        /// <summary>
        /// 调整音量测试
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void kBut_BroadcastTest_Click(object sender, EventArgs e)
        {
            //设置一个音量
            BroadcastUDP a = new BroadcastUDP();

            a.setBroadcastDeviceVolume("172.16.17.20", 20, 20);
        }
예제 #2
0
        /// <summary>
        /// 用于设置websocket端口同时开启所有功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_StartWebSocket_Click(object sender, EventArgs e)
        {
            ///
            ///初始化界面相关数据
            ///
            InitUI();

            ///
            ///初始化第三方设备
            ///
            //注册设备线程
            InitDevices();


            ///
            ///开启websocket线程
            ///
            Thread thrWebSocket = new Thread(new ThreadStart(WebSocketInit));

            thrWebSocket.IsBackground = true;
            thrWebSocket.Start();


            ///
            ///开启摄像头初始化线程
            ////* 摄像头数量较多,初始化过程牵扯到多步操作(eg:数据库摄像头相关状态更新)。因此开启子线程执行耗时操作,避免主线程卡死 */
            ///
            SkyinforHikvision skyinforhk = new SkyinforHikvision();

            InitCamera(ref skyinforhk);
            Thread thrCamerainit = new Thread(new ThreadStart(skyinforhk.UpdateDB));

            thrCamerainit.IsBackground = true;
            thrCamerainit.Start();
            //轮询完所有摄像头,开启摄像头转码线程,
            //读取dt表中flag字段跟rtsp留,然后开线程转码
            //SkyinforVideoTransform videoTransform = SkyinforVideoTransform.getInstance();
            //Thread thrCamerainit = new Thread(new ThreadStart(videoTransform.SkyinforVideoServer));
            //thrCamerainit.IsBackground = true;
            //thrCamerainit.Start();

            ///
            ///轮询第三方设备
            ///
            //轮询机房环控
            SkyinforMachineRoom environment = new SkyinforMachineRoom();
            Thread thrEnvironment           = new Thread(new ThreadStart(environment.MachineRoom_Get));

            thrEnvironment.IsBackground = true;
            thrEnvironment.Start();


            //轮询广播 : 一直监听broadcast硬件的广播,没隔30秒左右会返回一遍状态
            BroadcastUDP serverReceive = new BroadcastUDP();
            Thread       thrUDP        = new Thread(new ThreadStart(serverReceive.BroadServerReceive));

            thrUDP.IsBackground = true;
            thrUDP.Start();


            //轮询停车场
            SkyinforParking skinforParing = new SkyinforParking();
            Thread          Parking       = new Thread(new ThreadStart(skinforParing.ParkingWebRequest_Get));

            Parking.IsBackground = true;
            Parking.Start();

            //轮询闸机
            SkyinforGate skyinforGate = new SkyinforGate();
            Thread       Gate         = new Thread(new ThreadStart(skyinforGate.Gate_Get));

            Gate.IsBackground = true;
            Gate.Start();

            //轮询Wifi列表
            SkyinforWifi skyinforWifi = new SkyinforWifi();
            Thread       Wifi         = new Thread(new ThreadStart(skyinforWifi.WifiList_Get)); // 获取所有AP的基本信息的列表

            Wifi.IsBackground = true;
            Wifi.Start();


            //App上报故障事件监听线程
            Thread AppEventListener = new Thread(new ThreadStart(PollForAppEvent));

            AppEventListener.IsBackground = true;
            AppEventListener.Start();

            ///
            ///界面刷新及状态监控
            ///
            //软件占用资源信息线程
            Thread ProgramInfo = new Thread(new ThreadStart(GetProgramInfo));

            ProgramInfo.IsBackground = true;
            ProgramInfo.Start();

            //设备状态统计信息线程
            Thread DeviceInfo = new Thread(new ThreadStart(UpdateForm));

            DeviceInfo.IsBackground = true;
            DeviceInfo.Start();


            kBut_StartService.Text      = "服务运行中...";
            kBut_StartService.BackColor = ColorTranslator.FromHtml("#4679FF");

            kBut_StartService.FlatAppearance.BorderSize = 0;
            kBut_StartService.Enabled = false;
        }
        /// <summary>
        /// 命令解析函数
        /// </summary>
        /// <param name="strJson"></param>
        /// <returns></returns>
        public string ReceiceJson(string strJson)
        {
            try
            {
                JsonObject joWebCmd      = (JsonObject)JsonValue.Parse(strJson);
                string     strResult     = "null";
                string     strResult2    = "null";
                string     strStatusCode = "0";
                string     strCmd        = "";
                #region 摄像头云台控制命令
                if (joWebCmd["requestType"] == "Camera")
                {
                    string strCameraNVRip   = joWebCmd["requestDetail"]["nvrip"];
                    string strCameraChannel = joWebCmd["requestDetail"]["channel"];
                    string strCameraCmd     = joWebCmd["requestDetail"]["command"];
                    //执行命令
                    HikvisionPTZControl hkPtzCtl = new HikvisionPTZControl();
                    //根据选中的摄像头通道号跟IP地址进行预览
                    //zzt补充,这里加个界面日志,告诉别人收到了什么命令,时间跟
                    DataRow[] dr;
                    switch (strCameraCmd)
                    {
                    case "left":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "right":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "up":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZup(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "down":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdown(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "upleft":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZupleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "upright":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "downleft":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdownleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "downright":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdownright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "zoom_out":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZzoomout(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "zoom_in":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZzoomin(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;
                    }

                    //更新下界面
                    StaticUtils.ShowCMDMsg("接收时间:" + DateTime.Now.ToString() + "  摄像头云台控制命令!\n" + "控制nvrip为:" + strCameraNVRip + "   通道号为:" + strCameraChannel + "   命令为:" + strCameraCmd + "\n");

                    //得到状态,下一步封装成json传回去
                    JsonObject returnJS        = SendJson("Camera", strStatusCode, m_lCameraIP, m_lChannel, strCmd, strResult, strResult2);
                    string     strReturnResult = returnJS.ToString();
                    strReturnResult = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(strReturnResult));
                    return(strReturnResult);
                }
                #endregion


                #region 广播控制命令
                if (joWebCmd["requestType"] == "Broadcast")
                {
                    string strBroadcastDeviceId    = joWebCmd["requestDetail"]["deviceid"];
                    string strBroadcastChannel     = joWebCmd["requestDetail"]["channel"];
                    string strBroadcastDeviceIp    = joWebCmd["requestDetail"]["deviceip"];
                    string strBroadcastVolumeValue = joWebCmd["requestDetail"]["volumeValue"];
                    string strBroadcastCmd         = joWebCmd["requestDetail"]["command"];

                    //执行命令
                    BroadcastUDP broadcastUDP = new BroadcastUDP();
                    //根据选中的摄像头通道号跟IP地址进行预览
                    //zzt补充,这里加个界面日志,告诉别人收到了什么命令,时间跟
                    switch (strBroadcastCmd)
                    {
                    case "volume":
                        //此命令为修改设备音量,需要设备id,设备ip地址,音量值。
                        Byte volumeArray = (Byte)Convert.ToInt32(strBroadcastVolumeValue);     // 将获取到的string转化为 byte
                        broadcastUDP.setBroadcastDeviceVolume(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), volumeArray);
                        break;

                    case "stop":
                        //此命令为 强制关闭设备,需要设备id,设备ip地址,音量值。
                        Byte nMode = (Byte)Convert.ToInt32("1");     // 输入默认值 ;强制关闭类型: 1 表示强制关闭
                        broadcastUDP.closeBroadcastDevice(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), nMode);
                        break;

                    case "channel":
                        //此命令为 切换设备频道,需要设备id,设备ip地址,频道。
                        Byte nChannel = (Byte)Convert.ToInt32(strBroadcastChannel);
                        broadcastUDP.changeBroadcastDeviceChannel(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), nChannel);
                        break;
                    }

                    //更新下界面
                    StaticUtils.ShowCMDMsg("接收时间:" + DateTime.Now.ToString() + "  广播云台控制命令!\n" + "控制广播设备编号为:" + strBroadcastDeviceId + "   命令为:" + strBroadcastCmd + "   广播设备IP为:" + strBroadcastDeviceIp + "\n");
                }
                #endregion

                return(strResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                StaticUtils.ShowEventMsg("MgJsonCtrl.class-ReceiceJson : 数据格式错误,请输入标准Json格式或产生异常\n");
                return("数据格式错误,请输入标准Json格式或产生异常");
            }
        }