175 lines
5.5 KiB
PHP
175 lines
5.5 KiB
PHP
<?php
|
|
require "functions.php";
|
|
|
|
function pgobject(array $data, $device, $ch, $row,$logfile){
|
|
|
|
$name = bacname($data);
|
|
$csv = "";
|
|
$csv = '
|
|
{
|
|
"$base": "Object",
|
|
"object-identifier": {
|
|
"$base": "ObjectIdentifier",
|
|
"value": "pg,'.$data[14].'"
|
|
},
|
|
"object-name": {
|
|
"$base": "String",
|
|
"value": "'.$name.'"
|
|
},
|
|
"description": {
|
|
"$base": "String",
|
|
"value": "'.$data[12].'"
|
|
}
|
|
}
|
|
';
|
|
fireCurl($csv, $ch, $row,$logfile,$data);
|
|
}
|
|
|
|
|
|
|
|
function program(array $data, $device, $ch, $row, $logfile){
|
|
if (($pghandle = fopen('./programs/pg'.$data[20].'.csv',"r")) !== FALSE) {
|
|
$pgrow = 1;
|
|
echo "<script>console.log('CSV opened');</script>";
|
|
|
|
pgobject($data, $device, $ch, $row,$logfile);
|
|
|
|
$prefix = $data[23];
|
|
$suffix = $data[24];
|
|
|
|
$bacnameFirst = bacnameF($data);
|
|
///$bacnameLast = bacnameL($data); //actully not ness
|
|
$bacname = bacname($data);
|
|
|
|
$genpgfilename = './programs/generated/genpg'.$prefix.$bacname.$suffix.'.txt';
|
|
$genfilesize = filesize($genpgfilename);
|
|
echo "<script>console.log('Old filesize was $genfilesize');</script>";
|
|
|
|
if (file_exists($genpgfilename)==TRUE){
|
|
unlink($genpgfilename);
|
|
echo "<script>console.log('File deleted');</script>";
|
|
}
|
|
|
|
$genpghandle = fopen($genpgfilename, "a+");
|
|
|
|
|
|
if ($genpghandle !== FALSE){
|
|
echo "<script>console.log('generated Program opened/created');</script>";
|
|
}else{
|
|
echo "<script>console.log('failed to open/create generated Program');</script>";
|
|
}
|
|
|
|
|
|
$rawpgfilename = './programs/pg'.$data[20].'.txt';
|
|
//$rawpghandle = fopen($rawpgfilename, "r"); //not needed with get_contens
|
|
$rawpgcont = file_get_contents($rawpgfilename,false);
|
|
|
|
|
|
while (($pgdata = fgetcsv($pghandle, 0, ",","\"","\\")) !== FALSE) {
|
|
|
|
$handlecounter=fopen('counter',"a+");
|
|
|
|
|
|
/// usleep(250000);
|
|
|
|
|
|
$num = count($pgdata);
|
|
|
|
if ($pgrow < $num){
|
|
$pgrow++;
|
|
}
|
|
|
|
echo '<script>console.log("Loop for program started. Row: '.$pgrow.'");</script>';
|
|
if ($pgrow>2){
|
|
|
|
$pgdata[13] = strtolower($pgdata[13]);
|
|
|
|
$varInt=$pgdata[21];
|
|
$out=strtolower($pgdata[22]);
|
|
|
|
$pgname = $bacnameFirst.bacnameL($pgdata);
|
|
$pgdata[0] = $data[0];
|
|
$pgdata[1] = $data[1];
|
|
$pgdata[2] = $data[2];
|
|
$pgdata[3] = $data[3];
|
|
$pgdata[4] = $data[4];
|
|
$pgdata[5] = $data[5];
|
|
|
|
|
|
|
|
$pgdata[14] = $pgdata[14] + $data[14];
|
|
|
|
$genline ='';
|
|
|
|
if (($out == 'out') | ($out == 'o') | ($out == 'q')){
|
|
$dot = '';
|
|
if (!empty($pgdata[20])){
|
|
$dot = '.';
|
|
}
|
|
$genline = ($pgname.$dot.$pgdata[20].' = '.$varInt."\r\n");
|
|
echo "<script>console.log('Programline for Outputmapping generated');</script>";
|
|
|
|
}
|
|
|
|
if (($out == 'in') | ($out == 'i')){
|
|
$dot = '';
|
|
if (!empty($pgdata[20])){
|
|
$dot = '.';
|
|
}
|
|
$genline = ($varInt.' = '.$pgname.$dot.$pgdata[20]."\r\n");
|
|
echo "<script>console.log('Programline for Inputmapping generated');</script>";
|
|
}
|
|
|
|
if (($out == 'udef') | ($out == '0') | ($out == 'undef') | ($out == 'no') | ($out == 'none') | ($out == 'null')| ($out == 'n')){
|
|
|
|
$genline = ($varInt.' = '.$varInt."\r\n");
|
|
echo "<script>console.log('Programline for internal generated');</script>";
|
|
}
|
|
|
|
|
|
fwrite($genpghandle, $genline);
|
|
|
|
analogvalue($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
multistatevalue($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
binaryvalue($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
analoginput($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
analogoutput($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
binaryinput($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
binaryoutput($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
schedule($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
controller($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
totalizer($pgdata,$device,$ch,$pgrow,$logfile);
|
|
|
|
if ($pgdata[13] == 'tl'){
|
|
trendlog($pgdata,$device,$ch,$pgrow,$logfile);
|
|
};
|
|
}
|
|
$ctName = bacname($pgdata);
|
|
fwrite($handlecounter,'SUBLOOP! | Mainrow:'.sprintf("%'.04d", $row).' | '.'Subrow:'.sprintf("%'.04d", $pgrow).' | '.$ctName.' | '.$pgdata[13].' '.$pgdata[14]."\r\n");
|
|
fclose($handlecounter);
|
|
}
|
|
$genline ='';
|
|
$genline = ($rawpgcont."\r\n");
|
|
fwrite($genpghandle, $genline);
|
|
|
|
fclose($genpghandle);
|
|
$genfilesize = filesize($genpgfilename);
|
|
echo "<script>console.log('New filesize is $genfilesize');</script>";
|
|
fclose($pghandle);
|
|
|
|
$handlecounter=fopen('counter',"a+");
|
|
fwrite($handlecounter,'Subloop FINISHED'."\r\n");
|
|
fclose($handlecounter);
|
|
}
|
|
}
|
|
|
|
?>
|