Mini Kabibi Habibi

Current Path : C:/Program Files/Smart Professional Surveillance System/PC-NVR/Common/Lua/ptz/
Upload File :
Current File : C:/Program Files/Smart Professional Surveillance System/PC-NVR/Common/Lua/ptz/PelcoD1_Tour.lua

--PelcoDͨ��Э��û�е��Ѳ������˲�����Ѳ�����ܣ���Ӧ�ó������ʵ�֣���
local Protocol = {};

-- ��ʾ�ֵ������16��10����(��Сֵ�����ֵ)
Protocol.Attr = 
{
	-- Э�����ʾ���,���ܳ���16�ַ���Ŀǰ�ݲ�֧������
	Name = "PELCOD1-T",	
		
	-- ָ�����̨Э�黹�Ǿ���Э�飬ʹ��"PTZ", "MATRIX"��ʾ
	Type = "PTZ",
	
	-- ��msΪ��λ
	Internal = 200,
				
	-- û�ж�Ӧ�ĵ�ַ��Χ���붼���0xff
	-- ��̨��ַ��Χ
	CamAddrRange 		= {0x01, 0xFF}, 
	-- ���ӵ�ַ��Χ
	MonAddrRange		= {0x00, 0xFF},	
	-- Ԥ�õ㷶Χ
	PresetRange 		= {0x00, 0xFF},
	-- �Զ�Ѳ����·��Χ
	TourRange				= {0x01, 0xff},
	-- �켣��·��Χ
	PatternRange		= {0x01, 0xff},
	-- ��ֱ�ٶȷ�Χ
	TileSpeedRange 		= {0x01, 0x3F},
	-- ˮƽ�ٶȷ�Χ
	PanSpeedRange 		= {0x01, 0x3F},
	
	-- �����Χ
	AuxRange 			= {0x01, 0x08},
}

Protocol.CommandAttr =
{
	-- Э������Ҫ���ĵ�λ�ã���LUA�±��ʾ�����±�ӣ���ʼ,��10���Ʊ�ʾ
	AddrPos 			= 2, 
	PresetPos 		= 6, 
	TileSpeedPos 	= 6,
	PanSpeedPos 	= 5,
	AuxPos 				= 6,
}

Protocol.Command = 
{
	-- д����Э��ʱֻ����16���ƻ��ַ���ʾ,û�еĻ���ע�͵�
	Start= 
	{
		--д��������, ���ϣ����£����ϣ�����
		TileUp 		= "0xff, 0x01, 0x00, 0x08, 0x00, 0x1f, 0x00,",
		TileDown 	= "0xff, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00,",
		PanLeft 	= "0xff, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,", 
		PanRight 	= "0xff, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,",
		LeftUp 		= "0xff, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00,",
		LeftDown 	= "0xff, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00,",
		RightUp		= "0xff, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x00,",
		RightDown = "0xff, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00,",

		ZoomWide 	= "0xff, 0x01, 0x00, 0x40, 0x00, 0x00, 0xc9",
		ZoomTele 	= "0xff, 0x01, 0x00, 0x20, 0x00, 0x00, 0xa9",
		FocusNear	= "0xff, 0x01, 0x01, 0x00, 0x00, 0x00, 0x8a",
		FocusFar 	= "0xff, 0x01, 0x00, 0x80, 0x00, 0x00, 0x09",
		IrisSmall 	= "0xff, 0x01, 0x04, 0x00, 0x00, 0x00, 0x8d",
		IrisLarge 	= "0xff, 0x01, 0x02, 0x00, 0x00, 0x00, 0x8b",		
		-- �ƹ�
		LightOn		= "0xff, 0x01, 0x88, 0x00, 0x00, 0x00, 0x00",
		LightOff  	= "0xff, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00",
			
		-- Ԥ�õ��������ã�����ת��)
		SetPreset 	= "0xff, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00",
		ClearPreset	= "0xff, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00",
		GoToPreset 	= "0xff, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00",
		
		-- ˮƽ�ת��
		AutoPanOn	= "0xFF, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00",
		AutoPanOff	= "0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",			
			
		-- �Զ�ɨ�裬��Ԥ�����õı߽��м�ת��
		SetLeftLimit 	= "0xff, 0x01, 0x00, 0x11, 0x00, 0x00, 0x00",
		SetRightLimit	= "0xff, 0x01, 0x00, 0x13, 0x00, 0x00, 0x00", 
		AutoScanOn 		= "0xff, 0x01, 0x00, 0x1B, 0x00, 0x00, 0x00",
		AutoScanOff		= "0xff, 0x01, 0x00, 0x1D, 0x00, 0x00, 0x00",
		
		--[[�Զ�Ѳ��, �ֱ���76�ź�96��Ԥ�õ�.�˴�����SatrtTour�����ʹ��Ӧ�ó����е���Ѳ�����ܡ�
		StartTour 	= "0xff, 0x01, 0x00, 0x07, 0x00, 0x4C, 0x00",
		StopTour	= "0xff, 0x01, 0x00, 0x07, 0x00, 0x60, 0x00",
		--]]
		
		-- �켣Ѳ��, һ��ָģʽ(���ÿ�ʼ�����ý�������У�ֹͣ����ģʽ
		SetPatternStart = "0xff, 0x01, 0x00, 0x1f, 0x00, 0x00, 0x00",
		SetPatternStop 	= "0xff, 0x01, 0x00, 0x21, 0x00, 0x00, 0x00",
		StartPattern 		= "0xff, 0x01, 0x00, 0x23, 0x00, 0x00, 0x00",
    StopPattern     = "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",

		
		AuxOn 	= "0xff, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00",
		AuxOff 	= "0xff, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00",
		
		Position = "0x3a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,0x00, 0xff",	
			
	},
	Stop = 
	{
		TileUp 		= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		TileDown 	= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		PanLeft 	= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		PanRight 	= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		LeftUp 		= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		LeftDown 	= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		RightUp		= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		RightDown = "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		
		ZoomWide 	= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		ZoomTele 	= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		FocusNear = "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		FocusFar 	= "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		IrisSmall = "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
		IrisLarge = "0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,",
	},
}

Protocol.Checksum = function (s)
	if s[1] ~= 0x3a then
		s[7] = math.mod((s[2] + s[3] + s[4] + s[5] + s[6]), 256);
	end;
	return s;
end;

Protocol.CamAddrProcess = function(s, addr)
	local addr = math.mod(addr,256);
	if s[1] ~= 0x3a then
		s[Protocol.CommandAttr.AddrPos] = addr;
	else
		s[2] = addr;
	end;
	return s;
end;

Protocol.SpeedProcess = function(s, ver, hor)
	if s[4] ~= 0x00 then
		s[6] = ver;
		s[5] = hor;
	end;
	return s;
end;

Protocol.PositionProcess = function(s, hor, ver, zoom)
	-- ����ֻ������ٶ�λ����
	local max_pos_zoom = 16;
	if s[1] == 0x3a then
		s[4] = bits.band(hor,0xff00)/256;
		s[5] = bits.band(hor, 0xff);
		s[6] = bits.band(ver,0xff00)/256;
		s[7] = bits.band(ver,0xff);
		if zoom == 0 then
			s[8] = 0;
		else 
			if math.abs(zoom) > max_pos_zoom then
				s[8] = max_pos_zoom; 
			else 
				s[8] = math.abs(zoom);
			end;
			s[8] = zoom > 0 and s[8] or 0x80 + s[8];
		end
		s[9] = math.mod((s[2] + s[3] + s[4] + s[5] + s[6] + s[7] + s[8]), 256);
		return s;
	end;	
end;

return Protocol;