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/Videon_D.lua

-- Videon RS422D PROTOCOL
-- watchnetҪ���PelcoDЭ��

local Protocol = {};

Protocol.Attr = 
{
	Name = "Videon-D",	
		
	Type = "PTZ",
	
	Internal = 200,
				
	CamAddrRange 		= {0x01, 0x1F}, 
	MonAddrRange		= {0x00, 0xFF},	
	PresetRange 		= {0x00, 0xff},
	TourRange		= {0x01, 0xff},
	PatternRange		= {1, 4},
	TileSpeedRange 		= {0x00, 0x3F},
	PanSpeedRange 		= {0x00, 0x3F},
	AuxRange 		= {0x01, 0x08},
}

Protocol.CommandAttr =
{
	AddrPos 		= 2, 
	PresetPos 		= 6, 
	TileSpeedPos 		= 6,
	PanSpeedPos 		= 5,
	AuxPos 			= 6,
}

Protocol.Command = 
{
	Start= 
	{
		TileUp 		= "0xFF, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00",
		TileDown 	= "0xFF, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00",
		PanLeft 	= "0xFF, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00",
		PanRight 	= "0xFF, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00",
		LeftUp 		= "0xFF, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00",
		LeftDown 	= "0xFF, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00",
		RightUp		= "0xFF, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00",
		RightDown 	= "0xFF, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00",

		ZoomWide 	= "0xFF, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00",
		ZoomTele 	= "0xFF, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00",
		FocusNear	= "0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00",
		FocusFar 	= "0xFF, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00",
		IrisSmall 	= "0xFF, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00",
		IrisLarge 	= "0xFF, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00",
			
		SetPreset 	= "0xFF, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00",
		ClearPreset	= "0xFF, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00",
		GoToPreset 	= "0xFF, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00",
			
		SetLeftLimit 	= "0xFF, 0x00, 0x00, 0x07, 0x00, 0x5C, 0x00",
		SetRightLimit	= "0xFF, 0x00, 0x00, 0x07, 0x00, 0x5D, 0x00",
		AutoScanOn 	= "0xFF, 0x00, 0x00, 0x07, 0x00, 0x61, 0x00",
		-- �÷���������ֹͣ
		AutoScanOff	= "0xFF, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",
		
		StartTour 	= "0xFF, 0x00, 0x00, 0x07, 0x00, 0x62, 0x00",
                StopTour        = "0xFF, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",
			
		SetPatternStart = "0xFF, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00",
		SetPatternStop 	= "0xFF, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00",
		StartPattern 	= "0xFF, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00",
                StopPattern     = "0xFF, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",
		
		AuxOn 		= "0xFF, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00",
		AuxOff 		= "0xFF, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00",
		
		Position = "0xff, 0x00, 0xa6, 0x89, 0x00, 0x00, 0x00, 0xff, 0x00, 0xa5, 0x89, 0x00, 0x00, 0x00",	
		
		Menu 		= "0xFF, 0x00, 0x00, 0x07, 0x00, 0x5F, 0x00",

		MenuUp = "0xFF, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,",
		MenuDown = "0xFF, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,",
		MenuLeft = "0xFF, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,",
		MenuRight = "0xFF, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00,",

	},
	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",
		
		MenuUp = "0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",
		MenuDown = "0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",
		MenuLeft = "0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",
		MenuRight = "0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00",
	},
}

Protocol.Checksum = function (s)
	s[7] = math.mod((s[2] + s[3] + s[4] + s[5] + s[6]), 256);

	if table.getn(s) >= 14 then
		s[14] = math.mod((s[9] + s[10] + s[11] + s[12] + s[13]), 256);
	end;
	
	return s;
end;

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

Protocol.PatternProcess = function(opttable, num)
	opttable[6] = num - 1;
	return opttable;
end;

--[[
���������Ϊ����ң���Ϊ����zoom���λ��ʾ�Ŵ�/�С��Ϊ0��ʾ�Ŵ�Ϊ1��ʾ�С
����Э���ѱ������˸��ģ���11��ʾ1��1������Ҫ���Ĵ���ʽ
--]]
Protocol.PositionProcess = function(s, hor, ver, zoom)
	-- ����ֻ������ٶ�λ����
	local max_pos_zoom = 40;
	s[9] = s[2];
	
	if hor >= 0 then
		s[5] = 128 + math.floor(hor * 127 / 8192);
	else
		s[5] = 128 - math.floor(math.abs(hor) * 128 / 8192);
	end;
	
	if ver >= 0 then
		s[6] = 128 - math.floor(ver * 128 / 8192);
	else
		s[6] = 128 + math.floor(math.abs(ver) * 127 / 8192);
	end;
	
	if zoom > 0 then
		s[12] = 1;
	elseif zoom < 0 then
		s[12] = 2;
	else
		s[12] = 0;
	end;
		
	if math.abs(zoom) > max_pos_zoom then
			s[13] = max_pos_zoom; 
	else		
			s[13] = math.abs(zoom) + 9;
	end;

	return s;
end;

return Protocol;