nvsPtzcontrol.js 7.42 KB

(function () {
    var nvs = {};

	
	/// 播放类型
    nvs.PlayerType = new function () {
        this.kLivePlayer = 0;		/// 实时预览
        this.kRecordPlayer = 1;		/// 录像回放
        this.kFilePlayer = 2;		/// 文件回放
    };
	
	/// 录像类型
    nvs.RecordType = new function () {
        this.kNone = 0;
        this.kSystemRecord = 0x01;
        this.kFrontRecord  = 0x02;
        this.kManualRecord = 0x04;
        this.kAlarmRecord  = 0x08;
    };
	
	/// 上下线状态
    nvs.StatusType = new function () {
        this.kOffline = 0;	/// 下线
        this.kOnline = 1;	/// 上线
    };

	/// PTZ命令
    nvs.PTZCommand = new function () {
        this.PTZ_CMD_START = 0;
        this.PTZ_CMD_STOP = 1;		///停止	

        this.PTZ_CMD_RIGHT = 2;		///右	
        this.PTZ_CMD_LEFT = 4;		///左
        this.PTZ_CMD_DOWN = 6;		/// 下
        this.PTZ_CMD_UP = 8;		/// 上

		this.PTZ_CMD_RIGHT_UP    = 22;	//右上
		this.PTZ_CMD_LEFT_UP     = 24;	//左上
		this.PTZ_CMD_RIGHT_DOWN  = 26;	//右下
		this.PTZ_CMD_LEFT_DOWN   = 28;	//左下
	
        this.PTZ_CMD_SMALL = 10;	///光圈变小
        this.PTZ_CMD_LARGE = 12;	///光圈变大

        this.PTZ_CMD_ZOOM_IN = 14;	///焦距变大
        this.PTZ_CMD_ZOOM_OUT = 16;	///焦距变小

        this.PTZ_CMD_FOCUS_IN = 18;		///焦点前调	
        this.PTZ_CMD_FOCUS_OUT = 20;	///焦点后调

        this.PTZ_CMD_ASSIST_FUNC_1 = 30;	///雨刷
        this.PTZ_CMD_ASSIST_FUNC_2 = 32;
        this.PTZ_CMD_ASSIST_FUNC_3 = 34;
        this.PTZ_CMD_ASSIST_FUNC_4 = 36;

        this.PTZ_RIGHT_APPLY = 40;		///权限申请
        this.PTZ_RIGHT_RELEASE = 42;	///权限释放

        this.PTZ_PRESET_ADD = 110;		///添加预置位
        this.PTZ_PRESET_MODIDY = 112;	///修改预置位
        this.PTZ_PRESET_DELETE = 114;	///删除预置位
        this.PTZ_PRESET_GOTO = 116;		///转到预置位	

        this.PTZ_CMD_SCAN = 120;		///自动扫描开 
        this.PTZ_CMD_LENGTH = 121;
    };
	
	/// 预置位标识
    nvs.PresetFlag = new function () {
        this.kNormal = 0;		///普通预置位
        this.kDay = 1;			///白天守望位
        this.kNight = 2;		///夜晚守望位  
    };
	

    window['nvs'] = nvs;
    
})();





function getParamsId(url){
    var obj = {};
   
    // pure user query object.
    obj.user_query = {};
    
    // parse the query string.
    var query_string = String(url).replace(" ", "").split("?")[1];
    if(query_string == undefined){
        return "";
    }
    
    var queries = query_string.split("&");
    $(queries).each(function(){
        var query = this.split("=");
        obj[query[0]] = query[1];
        obj.user_query[query[0]] = query[1];
    });
    
    return obj.id;
}


function sendPtzcontrol(userId,id,cmd,para,speed){
	var xhr = $.ajax({
		url: "/nvsthird/ptzcontrol",
		type: "post",
		async: true,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			userId: userId,
			chnId: id,
			action:cmd,
			data:para,
			speed:speed
		}),
		timeout: 3000,
		success: function(res) {
			console.log('res:'+res); 
			//layer.msg('云镜控制成功', {icon: 1, time: 1000,skin: 'layer-ext-moon' });  
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('云镜控制超时:' + errorThrown, {icon: 2, time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('云镜控制失败', {icon: 2, time: 2000,skin: 'layer-ext-moon' });
			}
  	},
	});
}




function handlePtzcontrol(cmd,stop,para){

	if (arguments.length == 1) {
		doPtzcontrol(cmd,""+nvs.PTZCommand.PTZ_CMD_START,""+g_speed*8,false);
	} else if (arguments.length == 2) {
		if(stop == false) {
			doPtzcontrol(cmd,""+nvs.PTZCommand.PTZ_CMD_START,""+g_speed*8,stop);
		} else {
			doPtzcontrol(cmd,""+nvs.PTZCommand.PTZ_CMD_STOP,""+g_speed*8,stop);
		}
		
	} else if (arguments.length == 3) {
		doPtzcontrol(cmd,para,""+g_speed*8,stop);
	}
}

// 云镜控制
$('.ptzsubwd_top').mousedown(function() { //向上
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_UP);
});

$('.ptzsubwd_top').mouseup(function() { //向上停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_UP,true);
});



$('.ptzsubwd_bottom').mousedown(function() { //向下
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_DOWN);
});
$('.ptzsubwd_bottom').mouseup(function() { //向下停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_DOWN,true);
});



$('.ptzsubwd_left').mousedown(function() { //左键
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT);
});
$('.ptzsubwd_left').mouseup(function() { //左键停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT,true);
});



$('.ptzsubwd_right').mousedown(function() { //右键
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT);
});
$('.ptzsubwd_right').mouseup(function() { //右键停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT,true);
});



$('.ptzsubwd_left_top').mousedown(function() { //左上
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_UP);
});
$('.ptzsubwd_left_top').mouseup(function() { //左上停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_UP,true);
});



$('.ptzsubwd_top_right').mousedown(function() { //右上
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_UP);
});
$('.ptzsubwd_top_right').mouseup(function() { //右上停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_UP,true);
});



$('.ptzsubwd_right_bottom').mousedown(function() { //右下
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_DOWN);
});
$('.ptzsubwd_right_bottom').mouseup(function() { //右下停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_RIGHT_DOWN,true);
});



$('.ptzsubwd_bottom_left').mousedown(function() { //左下
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_DOWN);
});
$('.ptzsubwd_bottom_left').mouseup(function() { //左下停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LEFT_DOWN,true);
});


$('.cloud_halo_big').mousedown(function() { //光圈放大
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LARGE);
});
$('.cloud_halo_big').mouseup(function() { //光圈放大停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_LARGE,true);
});



$('.cloud_halo_small').mousedown(function() { //光圈缩小
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_SMALL);
});
$('.cloud_halo_small').mouseup(function() { //光圈缩小停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_SMALL,true);
});



$('.cloud_big').mousedown(function() { //焦距变大
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_IN);
});
$('.cloud_big').mouseup(function() { //焦距变大停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_IN,true);
});



$('.cloud_small').mousedown(function() { //焦距变小
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_OUT);
});
$('.cloud_small').mouseup(function() { //焦距变小停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_ZOOM_OUT,true);
});



$('.cloud_focus_big').mousedown(function() { //焦点变大
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_OUT);
});
$('.cloud_focus_big').mouseup(function() { //焦点变大停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_OUT,true);
});



$('.cloud_focus_small').mousedown(function() { //焦点变小
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_IN);
});
$('.cloud_focus_small').mouseup(function() { //焦点变小停止
	handlePtzcontrol(""+nvs.PTZCommand.PTZ_CMD_FOCUS_IN,true);
});