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

-- SpeedDome��AD��
local Protocol = {};

Protocol.Attr = 
{
	Name = "AD1641M",	
	Type = "PTZ",
	Internal = 200,
	CamAddrRange 		= {0x00, 0xFF}, 
	MonAddrRange		= {0x00, 0xFF},	
	PresetRange 		= {0x00, 0xff},
	TourRange		= {0x01, 0x04},
	PatternRange		= {0x01, 0x04},
	TileSpeedRange 		= {0x00, 0xfF},
	PanSpeedRange 		= {0x00, 0xfF},
	AuxRange 			= {0x01, 0xff},
}

Protocol.CommandAttr =
{
	AddrPos 		= 2, 
	PresetPos 		= 4, 
	TileSpeedPos 	= 11,
	PanSpeedPos 	= 10,
	AuxPos 			= 4,
}

Protocol.Command = 
{
	Start= 
	{
		TileUp 		= "0x02, 0x00, 0x01, 0xC4, 0x03, 0x00, 0x02, 0x00, 0x0e, 0x00, 0xff, 0x00,",
		TileDown 	= "0x02, 0x00, 0x01, 0xC8, 0x03, 0x00, 0x02, 0x00, 0x0e, 0x00, 0xff, 0x00,",
		PanLeft 	= "0x02, 0x00, 0x01, 0xC2, 0x03, 0x00, 0x02, 0x00, 0x0e, 0xff, 0x00, 0x00,", 
		PanRight 	= "0x02, 0x00, 0x01, 0xC1, 0x03, 0x00, 0x02, 0x00, 0x0e, 0xff, 0x00, 0x00,",
		LeftUp 		= "0x02, 0x00, 0x01, 0xC6, 0x03, 0x00, 0x02, 0x00, 0x0e, 0xff, 0xff, 0x00,",
		LeftDown 	= "0x02, 0x00, 0x01, 0xCa, 0x03, 0x00, 0x02, 0x00, 0x0e, 0xff, 0xff, 0x00,",
		RightUp		= "0x02, 0x00, 0x01, 0xC5, 0x03, 0x00, 0x02, 0x00, 0x0e, 0xff, 0xff, 0x00,",
		RightDown = "0x02, 0x00, 0x01, 0xC9, 0x03, 0x00, 0x02, 0x00, 0x0e, 0xff, 0xff, 0x00,",

		ZoomWide 	= "0x02, 0x00, 0x01, 0xd0, 0x03, 0x00,",
		ZoomTele 	= "0x02, 0x00, 0x01, 0xe0, 0x03, 0x00,",
		FocusNear	= "0x02, 0x00, 0x01, 0x40, 0x03, 0x00,",
		FocusFar 	= "0x02, 0x00, 0x01, 0x80, 0x03, 0x00,",
		IrisSmall = "0x02, 0x00, 0x01, 0xC0, 0x02, 0x00,",
		IrisLarge = "0x02, 0x00, 0x01, 0xC0, 0x01, 0x00,",
			
		SetPreset 	= "0x02, 0x00, 0x05, 0x00, 0x00,",
		ClearPreset	= "0x02, 0x00, 0x07, 0x00, 0x00,",
		GoToPreset 	= "0x02, 0x00, 0x02, 0x00, 0x00,",			
			
		SetLeftLimit 	= "0x02, 0x00, 0x0f, 0x02, 0x02, 0x00,",
		SetRightLimit	= "0x02, 0x00, 0x0f, 0x02, 0x01, 0x00,", 
		AutoScanOn 	= "0x02, 0x00, 0x0f, 0x03, 0x00, 0x00,",
                AutoScanOff     = "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
		
		AddTour 		= "0x02, 0x00, 0x06, 0x00, 0x00,",
		StartTour 	= "0x02, 0x00, 0x03, 0x00, 0x00,",
		ClearTour	= "0x02, 0x00, 0x08, 0x00, 0x00,",
                StopTour        = "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",

		SetPatternStart = "0x02, 0x00, 0x1b, 0x00, 0xff, 0x00",
		SetPatternStop 	= "0x02, 0x00, 0x1b, 0x00, 0x00, 0x00",
		StartPattern 	= "0x02, 0x00, 0x1c, 0x00, 0x00, 0x00",
                StopPattern     = "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
		
		AuxOn 	= "0x02, 0x00, 0x0d, 0x00, 0x01, 0x00",
		AuxOff 	= "0x02, 0x00, 0x0d, 0x00, 0x00, 0x00",
			
	},
	Stop = 
	{
		TileUp 		= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		TileDown 	= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		PanLeft 	= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		PanRight 	= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		LeftUp 		= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		LeftDown 	= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		RightUp		= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		RightDown       = "0x02, 0x00, 0x01, 0x00, 0x00, 0x00, ",
		
		ZoomWide 	= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
		ZoomTele 	= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
		FocusNear = "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
		FocusFar 	= "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
		IrisSmall = "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
		IrisLarge = "0x02, 0x00, 0x01, 0x00, 0x00, 0x00,",
	},
}

Protocol.Checksum = function (s)
	local len = table.getn(s);
	local sum = 0;
	
	if len <= 6 then
		for i = 1, len do
			sum = sum + s[i];
		end;
		s[len] = math.mod(sum, 256);
	elseif len == 12 then
		s[6] = math.mod((s[1] + s[2] + s[3] + s[4] + s[5]), 256);
		s[12] = math.mod((s[7] + s[8] + s[9] + s[10] + s[11]), 256);
	end;
	return s;
end;


Protocol.CamAddrProcess = function(s, addr)
	local addr = math.mod(addr,256);
	local len = table.getn(s);
	
	s[Protocol.CommandAttr.AddrPos] = addr;
	if len == 12 then
		s[Protocol.CommandAttr.AddrPos + 6] = addr;
	end;

	return s;
end;

Protocol.SetTourProcess = function(s, tour, preset)
	s[4] = preset;
	return s;
end;

Protocol.TourProcess = function(s, tour)
	s[4] = tour -1;
	return s;
end;

Protocol.PatternProcess = function(s, pattern)
	s[4] = pattern -1;
	return s;
end;

return Protocol;