-
Notifications
You must be signed in to change notification settings - Fork 1
/
19001651_lbs.php
207 lines (156 loc) · 4.56 KB
/
19001651_lbs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
###[DEF]###
[name = Wegfahrautomatik 0.1 ]
[e#1 important = OnOff ]
[e#2 important = Trigger_Open ]
[e#3 important = Wait_Open [s] ]
[e#4 important = Trigger_Close ]
[e#10 = Loglevel #init=8 ]
[a#1 = state ]
[a#2 = OpenDoors ]
[a#3 = CloseDoors ]
[v#100 = 0.01 ]
[v#101 = 19001651 ]
[v#102 = Wegfahrautomatik ]
[v#103 = 0 ]
###[/DEF]###
###[HELP]###
Dieser LBS öffnet und schließt Tore
Inputs:
E1 - abc: bla
Outputs:
A1 - abc: bla
Versions:
V0.01 2019-04-12 SirSydom
Open Issues:
Timeout
Author:
SirSydom - [email protected]
Copyright (c) 2019 SirSydom
Github:
https://github.com/SirSydom/edomi_LBS_sirsydom
Links:
Contributions:
###[/HELP]###
###[LBS]###
<?
function LB_LBSID($id)
{
if($E=getLogicEingangDataAll($id))
{
setLogicElementVar($id, 103, $E[10]['value']); //set loglevel to #VAR 103
if($E[1]['value'] == 1 && $E[1]['refresh'] == 1) // ON received
{
if(getLogicElementVar($id,1)!=1) // not running => Start
{
setLogicElementVar($id,1,1); //setzt V1=1, um einen mehrfachen Start des EXEC-Scripts zu verhindern
callLogicFunctionExec(LBSID,$id); //EXEC-Script starten (garantiert nur einmalig)
}
}
}
}
?>
###[/LBS]###
###[EXEC]###
<?
require(dirname(__FILE__)."/../../../../main/include/php/incl_lbsexec.php");
set_time_limit(0); //Wichtig! Script soll endlos laufen
sql_connect();
logging($id, "EXEC started", null, 5);
$E = logic_getInputs($id);
$mystate = "initial";
logic_setOutput($id,1,$mystate);
$timer = 0;
$run = 1;
while (getSysInfo(1)>=1 && $run)
{
logging($id, "main while cycle start", null, 8);
$E = logic_getInputs($id);
if($mystate = "initial")
{
if($E[2]['value'] == 1)
{
$mystate = "countdown_to_open";
logic_setOutput($id,1,$mystate);
$timer = time();
}
else
{
usleep(500000);
}
}
else if($mystate = "countdown_to_open")
{
if($timer > time() + $E[3]['value'])
{
$mystate = "wait_to_close";
logic_setOutput($id,1,$mystate);
logic_setOutput($id,2,1); // open the doors with "1" on the output
}
else
{
usleep(500000);
}
}
else if($mystate = "wait_to_close")
{
if($E[4]['value'] == 1)
{
$mystate = "wait_for_closing";
logic_setOutput($id,1,$mystate);
logic_setOutput($id,3,1); // close the doors with "1" on the output
}
else
{
usleep(500000);
}
}
else if($mystate = "wait_for_closing")
{
//do stuff here to supervice door closing
$run = 0; // exit EXEC
}
logging($id, "main while cycle end", null, 8);
}
logging($id, "Cycle exit", null, 8);
sql_disconnect();
logging($id, "EXEC exit", null, 5);
setLogicElementVar($id,1,0); //setzt V1=0, um einen Start des EXEC-Scripts zu erlauben
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
global $id;
logging($id, "File: $errfile | Error: $errno | Line: $errline | $errstr ");
}
function error_off()
{
$error_handler = set_error_handler("myErrorHandler");
error_reporting(0);
}
function error_on()
{
restore_error_handler();
error_reporting(E_ALL);
}
function logging($id,$msg, $var=NULL, $priority=8)
{
$E=getLogicEingangDataAll($id);
$logLevel = getLogicElementVar($id,103);
if (is_int($priority) && $priority<=$logLevel && $priority>0)
{
$logLevelNames = array('none','emerg','alert','crit','err','warning','notice','info','debug');
$version = getLogicElementVar($id,100);
$lbsNo = getLogicElementVar($id,101);
$logName = getLogicElementVar($id,102) . ' --- LBS'.$lbsNo;
strpos($_SERVER['SCRIPT_NAME'],$lbsNo) ? $scriptname='EXE'.$lbsNo : $scriptname = 'LBS'.$lbsNo;
writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname." [v$version]:\t".$msg);
if (is_object($var)) $var = get_object_vars($var); // transfer object into array
if (is_array($var)) // print out array
{
writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname." [v$version]:\t================ ARRAY/OBJECT START ================");
foreach ($var as $index => $line)
writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname." [v$version]:\t".$index." => ".$line);
writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname." [v$version]:\t================ ARRAY/OBJECT END ================");
}
}
}
?>
###[/EXEC]###