This script determines the current state of the zones on the Agent of Control side with the configured Apollo integration module. Also, when the GET_OBJECT_STATE event is received, this script generates the OBJECT_STATE_INFO event. The zones are configured and assigned to the corresponding loops when configuring the Apollo integration module.

The configuration guide for the Apollo integration module is available only in the documentation for ACFA PSIM. This script can be modified for any other integration module that supports user entry into the controller.


For details, see Configuring the special mode of Monitoring PSIM operation with ACFA PSIM.


function GetStateByCounts(armedCount, disarmedCount)
{
	/* If there are both armed and disarmed zones, then we consider that arming is partially completed */
	if(armedCount > 0 && disarmedCount > 0)
	{
		return "PART_ARMED";
	}
	/* If there are only armed zones, then we consider that the controller is armed */
	else if(armedCount > 0)
	{
		return "ARMED";
	}
	/* We consider that the controller is disarmed */
	return "DISARMED"
}
function ZoneIsUsed(params, id)
{
	var count = params.GetParam("TABLE.zone.count");
	var number = GetObjectParam("APOLLO_ZONE", id, "number");
	var i;
	for(i=0; i < count; ++i)
	{
		if(params.GetParam("TABLE.zone." + i) == number)
		{
			return "true";
		}
	}
	return "false";
}
function GetControllerState(id, zones)
{
	/* Get the controller configuration*/
	var params = CreateMsg();
	params.StringToMsg(GetObjectParams("APOLLO_DEVICE", id));
	/* Get the number of zones used by the controller */
	var count = params.GetParam("TABLE.zone.count");	
	/* If the controller uses the zones */
	if(count > 0)
	{
		/* The number of armed and disarmed zones */
		var armedCount = 0;
		var disarmedCount = 0;
		var zoneCount = zones.GetParam("id.count");
		var j;
		for(j = 0; j < zoneCount; ++j)
		{
			/* Determine if the zone belongs to the current controller
			   and determine whether this zone is used by the current controller */
			var zone = zones.GetParam("id."+j);
			if(GetObjectParentId("APOLLO_ZONE", zone, "APOLLO_DEVICE") == id && ZoneIsUsed(params, zone) == "true")
			{
				/* Check the state of the zone */
				var state = GetObjectState("APOLLO_ZONE", zone);
				switch(state)
				{
				case "ARMED":
				case "ALARM_ARMED":
				case "TROUBLE_ARMED":
					armedCount++;
					break;
				case "DISARMED":
				case "TROUBLE_DISARMED":
					disarmedCount++;
					break;
				}
			}
		}
	}

	/* Check the state of the object */
	return GetStateByCounts(armedCount, disarmedCount, msg);
}
function GetSkdStateMsg(type, id, action)
{
	var devices = CreateMsg();
	devices.StringToMsg(GetObjectIds("APOLLO_DEVICE"));
	var count = devices.GetParam("id.count");
	var zones = CreateMsg();
	zones.StringToMsg(GetObjectIds("APOLLO_ZONE"));
	/* The number of armed and disarmed zones */
	var armedCount = 0;
	var disarmedCount = 0;
	var i;
	for(i = 0; i < count; ++i)
	{
		var device = devices.GetParam("id."+i);
		var state = GetControllerState(device, zones);
		switch(state)
		{
			case "PART_ARMED":
				disarmedCount++;
			case "ARMED":
				armedCount++;
				break;
			case "DISARMED":
				disarmedCount++;
				break;
		}
	}
	var msg = CreateMsg();
	msg.SourceType = type;
	msg.SourceId = id;
	msg.Action = action;

	msg.SetParam("state", GetStateByCounts(armedCount, disarmedCount));
	msg.SetParam("card", "");
	return msg;
}
if(Event.SourceType == "VIDEOSRV_C" && Event.Action == "GET_OBJECT_STATE")
{
	NotifyEvent(GetSkdStateMsg(Event.SourceType, Event.SourceId, "OBJECT_STATE_INFO"));
}
else if(Event.SourceType == "APOLLO_DEVICE" && 
(Event.Action == "A06_CLOSE" || 
Event.Action == "A16_CLOSE" || 
Event.Action == "A06_OPEN" || 
Event.Action == "A16_OPEN" || 
Event.Action == "A06_POLICE" || 
Event.Action == "A16_POLICE" || 
Event.Action == "A06_ELECTRIC" || 
Event.Action == "A16_ELECTRIC" || 
Event.Action == "A06_ENTRY" ||
Event.Action == "A16_ENTRY"))
{
	var card = Event.GetParam("key_code");
	var msg = GetSkdStateMsg("VIDEOSRV_C", "1", "OBJECT_STATE_INFO");
	msg.SetParam("card", card);
	NotifyEvent(msg);
}