Logic schemes

Article contents:


Logic schemes are used to program automatic actions in the system depending on the events occurring.

Logic control is possible only with the permission of "logic" or "all" in the profile of the user performing the request.

Description of logic schemes

When you send a request for a change or creation of a logical scheme, a scheme description is sent. The format of this description is as follows:

(SENSORID OLDSTATE-NEWSTATE OPERATOR ...){SENSORID1:TIMEOUT,[REPEAT] NEWSTATE2 OPERATOR2 ...}
Where:
  • Condition (parentheses):
    • SENSORID - unique identifier of the sensor, the condition for changing the state of which is described;
    • OLDSTATE-NEWSTATE - the status codes of the element, condition is met by switching to this state (the values ​​of both parameters must be the same);
    • OPERATOR - the code of the operator using which the result of the compound condition is calculated;
  • Action (braces):
    • SENSORID1 - unique identifier of the sensor, the state of which must be changed when the conditions of the logic circuit are fulfilled;
    • TIMEOUT - timeout for the action;
    • REPEAT - repetition of execution of the condition (optional parameter) or video duration for cameras (in seconds);
    • NEWSTATE2 - the status code to which the element is to be translated;
    • OPERATOR2 - the character '+', is used to create a compound action.

State codes:

  • 'normal': 1;
  • 'low alarm': 2;
  • 'high warning' and 'warning': 3;
  • 'high alarm' and 'alarm': 4;
  • 'on': 5;
  • 'off': 6;
  • 'not connected': 7;
  • 'pulse': 8;
  • 'low warning': 9;
  • 'idle': 10.

Operator Codes:

  • 'and': the '+' character;
  • 'or': the '|' character.

Logic scheme management


For management of logic schemes, the following types of requests are used (passed in the querytype field):


addlogic - add / change logic. Extra options are:

  • k - user session ID;
  • id - identifier of the logical scheme (this is not the identifier of the element), in case the identifier absent, a new logical scheme is created, otherwise the existing one is modified;
  • logic - the description of logic (the format of the description is described above);
  • name - the name of the logical scheme.

If the new logic scheme is successfully created, the response contains the identifier of the created element (field id) and the identifier of the logical scheme (field num), and looks like:

<error type="no error" id="503001" num="3" />

When creating a new logical scheme (id is not specified), all the listed parameters are mandatory. When changing, only modifiable parameters can be specified. Empty parameters are not allowed.


getelement - reading of the element is associated with the logic scheme. Required parameters:

  • k - user session ID;
  • id - Element ID.

The answer contains information about the element:

<element id="503001" module="2001" num="1" clas="devirt" type="logic" name="logik1" state="normal" desc="(100 4-4){301001:0 5}" timeout="0" disabled="0" />

It contains the following fields:

  • num - identifier of the logical scheme used to access getlogic;
  • desc - a description of the logic scheme, compiled according to the rules above;
  • timeout - total time of locking the logic in seconds, 0 - if the circuit is not locked;
  • disabled - the remaining, at the moment, time of blocking the logic in seconds.


getlogic - get information about the logical scheme. Extra options are:

  • k - user session ID;
  • id - identifier of the requested logic scheme (this is not the identifier of the element), in the absence of which, user receives a list of all logical schemes available for reading to this user.


Example of a response to a query of a logic scheme with the identifier '3':


<syslogic>
    <logic id="3" name="Logic scheme My" disabled="0">
        <if element="201010" old="alarm" new="alarm" operator="and"></if>
        <if element="301011" old="not connected" new="not connected" operator="end"></if>
        <then element="401004" new="pulse" timeout="0"></then>
        <then element="501003" new="on" timeout="30"></then>
    </logic>
</syslogic>

dellogic - delete information about the logical scheme. Extra options are:

  • k - user session ID;
  • id - identifier of the logical scheme.


disablelogic - disable the execution of the logical scheme. Extra options are:

  • k - user session ID;
  • id - identifier of the logical scheme;
  • timeout - time for which the logic scheme is rohibited tooperate.


onlogics - enable the execution of all logical schemes. Extra options are:

  • k - user session ID.


offlogics - disable execution of all logical schemes. Extra options are:

  • k - user session ID;
  • timeout - timeout in seconds.

Element "System" in logic schemes

The "System" element corresponds to the state of the entire system. It can be used in logic schemes. The identifier of this element is fixed and equal to "100". When using this element in conditions for logic schemes, state codes can be as follows:

  • 'normal': 1;
  • 'warning': 3;
  • 'alarm': 4;
  • 'on': 5.

Code 'on' means turning on the system (system start).

When using the "System" element to perform the forced reboot task, the status code is:

  • 'off': 6.