Mini Kabibi Habibi
--[[
����SAE����̨����Э��.
1 Ѳ����·��4�, ���0~3, ���ǿ������(ɾ��)Ԥ�õ��Ѳ����·ֻ��0��.
--]]
local Protocol = {};
-- ��ʾ�ֵ������16��10����(��Сֵ�����ֵ)
Protocol.Attr =
{
-- Э�����ʾ���,���ܳ���16�ַ���Ŀǰ�ݲ�֧������
Name = "SAE",
-- ָ�����̨Э�黹�Ǿ���Э�飬ʹ��"PTZ", "MATRIX"��ʾ
Type = "PTZ",
-- ��msΪ��λ
Internal = 200,
-- û�ж�Ӧ�ĵ�ַ��Χ���붼���0xff
-- ��̨��ַ��Χ
CamAddrRange = {0x00, 0xFF},
-- ���ӵ�ַ��Χ
MonAddrRange = {0x00, 0xFF},
-- Ԥ�õ㷶Χ
PresetRange = {0x00, 0xff},
-- �Զ�Ѳ����·��Χ
TourRange = {0, 3},
-- �켣��·��Χ
PatternRange = {0, 3},
-- ��ֱ�ٶȷ�Χ
TileSpeedRange = {0x00, 0xFF},
-- ˮƽ�ٶȷ�Χ
PanSpeedRange = {0x00, 0xFF},
-- �����Χ
AuxRange = {0x01, 0xFF},
}
Protocol.CommandAttr =
{
-- Э������Ҫ���ĵ�λ�ã���LUA�±��ʾ�����±�ӣ���ʼ,��10���Ʊ�ʾ
AddrPos = 2,
PresetPos = 4,
TileSpeedPos = 5,
PanSpeedPos = 4,
AuxPos = 4,
}
Protocol.Command =
{
-- д����Э��ʱֻ����16���ƻ��ַ���ʾ,û�еĻ���ע�͵�
Start=
{
--д��������, ���ϣ����£����ϣ�����
--��ΪP/T�����ר�ŵ��ٶȿ���ָ��, ���ÿ�������Ҫ2�ָ�����.
TileUp = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xC4, 0x03, 0x00",
TileDown = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xC8, 0x03, 0x00",
PanLeft = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xC2, 0x03, 0x00",
PanRight = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xC1, 0x03, 0x00",
LeftUp = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xC6, 0x03, 0x00",
LeftDown = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xCA, 0x03, 0x00",
RightUp = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xC5, 0x03, 0x00",
RightDown = "0x02, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xC9, 0x03, 0x00",
--��ΪZ/F/I�����û���ٶȿ���ָ��, ���ֻ����һ�ָ��.
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",
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",
DeleteTour = "0x02, 0x00, 0x07, 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, 0x01, 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",
Position = "0x02, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 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 length = table.getn(s);
if length < 6 then
s[5] = math.mod(s[1] + s[2] + s[3] + s[4], 256);
elseif length == 6 then
s[6] = math.mod(s[1] + s[2] + s[3] + s[4] + s[5], 256);
elseif length > 6 and length ~= 10 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)
s[Protocol.CommandAttr.AddrPos] = addr;
if table.getn(s) > 6 and table.getn(s) ~= 10 then
s[Protocol.CommandAttr.AddrPos + 6] = addr;
end;
return s;
end;
Protocol.SpeedProcess = function(s, ver, hor)
if ver ~= 0 and s[3] == 0x0E then
s[Protocol.CommandAttr.TileSpeedPos] = ver;
end;
if hor ~= 0 and s[3] == 0x0E then
s[Protocol.CommandAttr.PanSpeedPos] = hor;
end;
return s;
end;
Protocol.SetTourProcess = function(opttable, tour, preset)
opttable[4] = preset;
return opttable;
end;
Protocol.TourProcess = function(opttable, tour)
opttable[4] = tour;
return opttable;
end;
Protocol.PatternProcess = function(opttable, num)
opttable[4] = num;
return opttable;
end;
Protocol.PositionProcess = function(s, hor, ver, zoom)
local length = table.getn(s);
local multiple = math.abs(zoom);
--print("hor", hor/8192)
--print("ver", ver/8192)
if length == 10 then
local max_pos_zoom = 23;
local position_x = nil;
local position_y = nil;
if hor < 0 then
position_x = 256 + (hor / 8192) * 127;
else
position_x = ( hor/ 8192) * 127;
end
if ver < 0 then
position_y = ((0 - ver) / 8192) * 127;
else
position_y = 256 - (ver / 8192) * 127;
end
s[4] = math.floor(position_x / 1);
s[5] = math.floor(position_y / 1);
--print("horSS",s[4])
--print("verSS",s[5])
if multiple > max_pos_zoom then
s[6] = 11;
s[7] = 11;
elseif multiple == 0 then
s[6] = 254;
s[7] = 254;
else
s[6] = math.floor(math.sqrt((254 * 254) / multiple) / 1);
s[7] = math.floor(math.sqrt((254 * 254) / multiple) / 1);
end;
s[10] = math.mod((s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7] + s[8] + s[9]), 256);
end;
return s;
end;
return Protocol;