Files
REEPEAD/functions.php
T
2026-06-22 21:27:34 +02:00

859 lines
22 KiB
PHP

<?php
function fireCurl($csv, $ch, $rowfc,$logfile, array $data){
$time = date("H:i");
curl_setopt($ch, CURLOPT_POSTFIELDS, $csv);
$output = curl_exec($ch);
if ($output !== FALSE){
echo "<script>console.log('Curl successfully executed');</script>";
}else{
echo "<script>console.log('Curl failed to execute');</script>";
}
$content = json_decode($output, true);
$objname = bacname($data);
// print_r($content);
$content["id"] = $rowfc-1;
if ($content["error"]!=-1){
$logvalue = ($time ." --> ". $content["id"] ." | ". $content["error"] ." | ". $content["errorText"] .' | '. $objname .' | '.$data[13].$data[14] ." | ".$csv. "\r\n");
fwrite($logfile, $logvalue);
}
$output = '';
}
function trendlog(array $dat, $device, $ch, $rowfc,$logfile){
echo "<script>console.log('TL called');</script>";
$name = bacname($dat);
$buffersize = 1000;
$type = 'polling';
switch($dat[13]){
case 'ai':
$trendId = $dat[14]*100+1;
break;
case 'ao':
$trendId = $dat[14]*100+2;
break;
case 'bi':
$trendId = $dat[14]*100+3;
$buffersize = 300;
$type = 'cov';
break;
case 'bo':
$trendId = $dat[14]*100+4;
$buffersize = 300;
$type = 'cov';
break;
case 'av':
$trendId = $dat[14]*100+5;
break;
case 'bv':
$trendId = $dat[14]*100+6;
$buffersize = 300;
$type = 'cov';
break;
case 'mi':
$trendId = $dat[14]*100+7;
break;
case 'mo':
$trendId = $dat[14]*100+8;
break;
case 'mv':
$trendId = $dat[14]*100+9;
break;
default:
$trendId = $dat[14]*100;
}
echo '<script>console.log("Init for TL for '.$dat[13].' with id '.$trendId.'");</script>';
$csv = "";
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "tl,'.($trendId).'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'_TL"
},
"description": {
"$base": "String",
"value": "'.$dat[12].' - Trendlog"
},
"Log_DeviceObjectProperty": {
"$base": "String",
"value": "'.$device.'.'.$dat[13].$dat[14].'"
},
"Buffer_Size": {
"$base": "Integer",
"value": "'.$buffersize.'"
},
"Logging_Type": {
"$base": "String",
"value": "'.$type.'"
},
"Notification_Threshold": {
"$base": "Integer",
"value": "'.($buffersize*0.6).'"
},
"Event_Detection_Enable": {
"$base": "Boolean",
"value": "True"
},
"Notification_Class_Ref": {
"$base": "String",
"value": "EVC'.$dat[19].'"
},
"Event_Message_Texts_Config":{
"$base":"Array",
"1":
{"$base":"String","value":"Alarm: '.$dat[12].' - Trendlog"},
"2":
{"$base":"String","value":"Fehler: '.$dat[12].' - Trendlog"},
"3":
{"$base":"String","value":"Normal: '.$dat[12].' - Trendlog"}
}
}
';
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
}
function analogvalue(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'av'){
$name = bacname($dat);
if (empty($dat[18]) | ($dat[18] == 0)){
$dat[18] = 95;
}
if ((empty($dat[15])) | ($dat[15] == 0)){
$cov = ',
"cov-increment": {
"$base": "Real",
"value": "0.3"
}';
}else{
$cov = ',
"cov-increment": {
"$base": "Real",
"value": "'.$dat[15].'"
}';
}
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "analog-value,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"units": {
"$base": "Enumerated",
"value": "'.$dat[18].'"
},
"cov-increment": {
"$base": "Real",
"value": "'.$dat[15].'"
}'.$cov.'
}
';
echo "<script>console.log('AV called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
}
}
function analoginput(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'ai'){
$name = bacname($dat);
if ((empty($dat[15])) | ($dat[15] == 0)){
$cov = ',
"cov-increment": {
"$base": "Real",
"value": "0.3"
}';
}else{
$cov = ',
"cov-increment": {
"$base": "Real",
"value": "'.$dat[15].'"
}';
}
if (!empty($dat[16])){
$aic = ',
"Type_Reference": {
"$base": "String",
"value": "'.$dat[16].'"
}';
}else{
$aic = ',
"Type_Reference": {
"$base": "String",
"value": "AIC103"
}';
}
$highLimEnableStr ="";
$lowLimEnableStr ="";
$limEnDiv ="";
if ($dat[27]!==0){
$highLimEnableStr = "highLimitEnable";
}
if ($dat[28]!==0){
$lowLimEnableStr = "lowLimitEnable";
}
if(($dat[27]!==0) && ($dat[28]!==0)){
$limEnDiv = ";";
}
if($dat[19]>0){
$alarm=',
"Event_Detection_Enable": {
"$base": "Boolean",
"value": "True"
},
"Notification_Class_Ref": {
"$base": "String",
"value": "EVC'.$dat[19].'"
},
"Event_Message_Texts_Config":{
"$base":"Array",
"1":
{"$base":"String","value":"Alarm: '.$dat[12].'"},
"2":
{"$base":"String","value":"Fehler: '.$dat[12].'"},
"3":
{"$base":"String","value":"Normal: '.$dat[12].'"}
},
"Time_Delay": {
"$base": "Integer",
"value": "'.$dat[26].'"
},
"Time_Delay_Normal": {
"$base": "Integer",
"value": "3"
},
"High_Limit": {
"$base": "Real",
"value": "'.$dat[27].'"
},
"Low_Limit": {
"$base": "Real",
"value": "'.$dat[28].'"
},
"Limit_Enable": {
"$base": "BitString",
"value": "'.$highLimEnableStr.$limEnDiv.$lowLimEnableStr.'"
}';
}else{
$alarm='';
};
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "analog-input,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"Input_Configuration": {
"$base": "Enumerated",
"value": "'.$dat[17].'"
}'.$cov.$aic.$alarm.'
}
';
echo "<script>console.log('AI called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
trendlog($dat, $device, $ch, $rowfc,$logfile);
}
}
function analogoutput(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'ao'){
$name = bacname($dat);
if (!empty($dat[16])){
$aoc = ',
"Type_Reference": {
"$base": "String",
"value": "'.$dat[16].'"
}';
}else{
$aoc = ',
"Type_Reference": {
"$base": "String",
"value": "AOC180"
}';
}
if ((empty($dat[15])) | ($dat[15] == 0)){
$cov = ',
"cov-increment": {
"$base": "Real",
"value": "0.3"
}';
}else{
$cov = ',
"cov-increment": {
"$base": "Real",
"value": "'.$dat[15].'"
}';
}
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "analog-output,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"cov-increment": {
"$base": "Real",
"value": "'.$dat[15].'"
},
"Output_Configuration": {
"$base": "Enumerated",
"value": "'.$dat[17].'"
}'.$cov.$aoc.'
}
';
echo "<script>console.log('AO called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
trendlog($dat, $device, $ch, $rowfc,$logfile);
}
}
function binaryvalue(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'bv'){
$name = bacname($dat);
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "binary-value,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"Type_Reference": {
"$base": "String",
"value": "BDC'.$dat[16].'"
}
}
';
echo "<script>console.log('BV called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
}
}
function binaryinput(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'bi'){
$name = bacname($dat);
if (!empty($dat[16])){
$bdc = ',
"Type_Reference": {
"$base": "String",
"value": "'.$dat[16].'"
}';
}else{
if($dat[19]>0){
$bdc = ',
"Type_Reference": {
"$base": "String",
"value": "BDC253"
}';
}else{
$bdc = ',
"Type_Reference": {
"$base": "String",
"value": "BDC202"
}';
}
}
if($dat[19]>0){
$alarm=',
"Event_Detection_Enable": {
"$base": "Boolean",
"value": "True"
},
"Notification_Class_Ref": {
"$base": "String",
"value": "EVC'.$dat[19].'"
},
"Event_Message_Texts_Config":{
"$base":"Array",
"1":
{"$base":"String","value":"Alarm: '.$dat[12].'"},
"2":
{"$base":"String","value":"Fehler: '.$dat[12].'"},
"3":
{"$base":"String","value":"Normal: '.$dat[12].'"}
},
"Time_Delay": {
"$base": "Integer",
"value": "'.$dat[26].'"
},
"Time_Delay_Normal": {
"$base": "Integer",
"value": "3"
},
"Polarity": {
"$base": "Enumerated",
"value": "reverse"
},
"Alarm_Value": {
"$base": "Enumerated",
"value": "active"
}';
}else{
$alarm='';
};
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "binary-input,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"Input_Configuration": {
"$base": "String",
"value": "0-5-volt"
}'.$bdc.$alarm.'
}
';
echo "<script>console.log('BI called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
if($dat[19]==0){
trendlog($dat, $device, $ch, $rowfc,$logfile);
}
}
}
function binaryoutput(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'bo'){
$name = bacname($dat);
if (!empty($dat[16])){
$bdc = ',
"Type_Reference": {
"$base": "String",
"value": "'.$dat[16].'"
}';
}else{
$bdc = ',
"Type_Reference": {
"$base": "String",
"value": "BDC202"
}';
}
if($dat[19]>0){
$alarm=',
"Event_Detection_Enable": {
"$base": "Boolean",
"value": "True"
},
"Notification_Class_Ref": {
"$base": "String",
"value": "EVC'.$dat[19].'"
},
"Feedback_Reference": {
"$base": "String",
"value": "'.$dat[25].'.Present_Value"
},
"Feedback_Source": {
"$base": "String",
"value": "reference"
},
"Event_Message_Texts_Config":{
"$base":"Array",
"1":
{"$base":"String","value":"Alarm: '.$dat[12].'"},
"2":
{"$base":"String","value":"Fehler: '.$dat[12].'"},
"3":
{"$base":"String","value":"Normal: '.$dat[12].'"}
},
"Time_Delay": {
"$base": "Integer",
"value": "'.$dat[26].'"
},
"Time_Delay_Normal": {
"$base": "Integer",
"value": "3"
}
';
}else{
$alarm='';
};
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "binary-output,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"Type_Reference": {
"$base": "String",
"value": "BDC202"
},
"Output_Configuration": {
"$base": "String",
"value": "0-10-volt"
}'.$bdc.$alarm.'
}
';
echo "<script>console.log('BO called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
trendlog($dat, $device, $ch, $rowfc,$logfile);
}
}
function multistatevalue(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'mv'){
$name = bacname($dat);
$csv = '';
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "multi-state-value,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"Type_Reference": {
"$base": "String",
"value": "'.$dat[16].'"
}
}
';
echo "<script>console.log('MV called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
}
}
function schedule(array $dat, $device, $ch, $rowfc,$logfile){
if ($dat[13] == 'sch'){
$name = bacname($dat);
$csv = '';
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "schedule,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"Weekly_Schedule":{
"$base":"Array",
"1":
{"$base":"Sequence","day-schedule":
{"$base":"List",
"1":
{"$base":"Sequence","time":
{"$base":"Time","value":"06:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","enumerated":
{"$base":"Enumerated","value":"1"}}}},
"2":
{"$base":"Sequence","time":
{"$base":"Time","value":"17:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","null":{"$base":"Null"}}}}}},
"2":{"$base":"Sequence","day-schedule":
{"$base":"List",
"1":
{"$base":"Sequence","time":
{"$base":"Time","value":"06:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","enumerated":
{"$base":"Enumerated","value":"1"}}}},
"2":
{"$base":"Sequence","time":
{"$base":"Time","value":"17:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","null":{"$base":"Null"}}}}}},
"3":{"$base":"Sequence","day-schedule":
{"$base":"List",
"1":
{"$base":"Sequence","time":
{"$base":"Time","value":"06:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","enumerated":
{"$base":"Enumerated","value":"1"}}}},
"2":
{"$base":"Sequence","time":
{"$base":"Time","value":"17:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","null":{"$base":"Null"}}}}}},
"4":{"$base":"Sequence","day-schedule":
{"$base":"List",
"1":
{"$base":"Sequence","time":
{"$base":"Time","value":"06:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","enumerated":
{"$base":"Enumerated","value":"1"}}}},
"2":
{"$base":"Sequence","time":
{"$base":"Time","value":"17:30:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","null":{"$base":"Null"}}}}}},
"5":{"$base":"Sequence","day-schedule":
{"$base":"List",
"1":
{"$base":"Sequence","time":
{"$base":"Time","value":"06:00:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","enumerated":
{"$base":"Enumerated","value":"1"}}}},
"2":
{"$base":"Sequence","time":
{"$base":"Time","value":"14:00:00.00"},
"value":{"$base":"Choice","value":
{"$base":"Choice","null":{"$base":"Null"}}}}}},
"6":{"$base":"Sequence","day-schedule":
{"$base":"List"}},
"7":{"$base":"Sequence","day-schedule":
{"$base":"List"}}
}
}
';
echo "<script>console.log('Schedule called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
}
}
function controller(array $dat, $device, $ch, $rowfc,$logfile){
if (($dat[13] == 'co')|($dat[13] == 'loop')){
$name = bacname($dat);
$csv = '';
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "loop,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"algorithm": {
"$base": "Enumerated",
"value": "pi"
},
"action": {
"$base": "Enumerated",
"value": "reverse"
},
"proportional-constant": {
"$base": "Real",
"value": "0.1"
},
"proportional-constant-units": {
"$base": "Enumerated",
"value": "%"
},
"integral-constant": {
"$base": "Real",
"value": "5"
}
}
';
echo "<script>console.log('CO called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
}
}
function totalizer(array $dat, $device, $ch, $rowfc,$logfile){
if (($dat[13] == 'btz')|($dat[13] == 'tz')){
$name = bacname($dat);
$csv = '';
$csv = '
{
"$base": "Object",
"object-identifier": {
"$base": "ObjectIdentifier",
"value": "btz,'.$dat[14].'"
},
"object-name": {
"$base": "String",
"value": "'.$name.'"
},
"description": {
"$base": "String",
"value": "'.$dat[12].'"
},
"Input_Reference ": {
"$base": "String",
"value": "'.$device.'.'.$dat[25].'.Pressent_Value"
}
}
';
echo "<script>console.log('BTZ called');</script>";
fireCurl($csv, $ch, $rowfc,$logfile,$dat);
}
}
function bacnameF(array $data){
$del = $data[8];
if (empty($data[8]) | ($data[8] == 0)){
$del = "_";
}
$bacnameFirst = $data[0].$data[1].$del.$data[2].$del.$data[3].$del.$data[4].$del.$data[5].$del;
return($bacnameFirst);
}
function bacnameL(array $data){
$del = $data[8];
if (empty($data[8]) | ($data[8] == 0)){
$del = "_";
}
$bacnameLast = $data[6].$del.$data[7];
return($bacnameLast);
}
function bacname(array $data){
$del = $data[8];
if (empty($data[8]) | ($data[8] == 0)){
$del = "_";
}
$bacnameFirst = $data[0].$data[1].$del.$data[2].$del.$data[3].$del.$data[4].$del.$data[5].$del;
$bacnameLast = $data[6].$del.$data[7];
$bacname = $bacnameFirst.$bacnameLast;
return($bacname);
}
?>