Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

173 lines
5.4 KiB

<?php
$Debug = false;
$Max_RANGE = 300.0; // 300 meters
$CAM_IP = '192.168.0.109';
$CAM_USER = 'gagua';
$CAM_PASS = '4GetMyID';
$CAM_PTZ_PROFILE = 'Profile_1';
$CAM_TARGET_MICRO_DELAY = 3.0; //3 seconds
$CAM_FOV_MIN = 5.0;
$CAM_FOV_MAX = 45.0;
$CAM_ZOOM_FIXED = false;
$CAM_SET_ZOOM = 0;// 0 - 1.0
$FH_RELAY = '';
$JAMMER_RELAY = '';
require_once('lib/soap_asm.php');
$RegData = file_get_contents('registry.sjno');
if($RegData!==false){
$Registry = json_decode( $RegData, true );
} else {
$Registry = array();
};
$lts = date ( "Y/m/d H:i:s" );
$rts = '';
$Headers = getallheaders();
if($Debug){
$fd = fopen( "posts.txt", "a+" );
fprintf( $fd, " ----------------- \r\n" );
fprintf( $fd, "Header:\r\n" );
foreach( $Headers as $key=>$value){
fprintf( $fd, $key.': '.$value."\r\n" );
};
fprintf( $fd, "Post:\r\n" );
foreach( $_POST as $key=>$value){
fprintf( $fd, $key.': '.$value."\r\n" );
};
fprintf( $fd, "Get:\r\n" );
foreach( $_GET as $key=>$value){
fprintf( $fd, $key.': '.$value."\r\n" );
};
fprintf( $fd, "REST:\r\n" );
};
try {
if (!($Data = file_get_contents('php://input'))) {
fprintf( $fd, "Can not Read STDIO Data\r\n" );
} else {
$JS = json_decode( $Data, true );
if( !is_array($JS) ){
$xml_parser = xml_parser_create();
if (!xml_parse_into_struct ( $xml_parser, $Data, $XS )){
$XS = false;
} else {
// Handle XML commands
switch($XS[0]['tag']){
case 'LCU:SYSTEMSTATUS':{
if($Debug)fprintf( $fd, "STATUS update!\r\n" );
break;
};
case 'LCU:EVENTLIDAR3D':{
$T['el'] = $XS[7]['value'] / 1000.0;
$Z = ( 90.0 - $T['el'] );
if( $Z < 0.0 ){
$Z *= -1.0;
$T['az'] = $XS[6]['value'] / 1000.0 + 180.0;
if( $T['az'] > 360.0 ) $T['az'] -= 360.0;
} else {
$T['az'] = $XS[6]['value'] / 1000.0;
};
$T['range'] = $XS[8]['value'] / 10.0;
$TTS = microtime(true);
if($Debug)fprintf( $fd, "3D Target! Azimuth %.2f Elevation %.2f Range %.2f\r\n", $T['az'], $T['el'], $T['range'] );
$O = $Registry['old_target'];
$OTS = $Registry['last_ts'];
if( ( $TTS-$OTS ) < $CAM_TARGET_MICRO_DELAY ){
// Target Filters
if($Debug)fprintf( $fd, "Move Filtered by Cam Delay %f $f\r\n", $TTS, $OTS );
} else {
$T_FOV = ( $CAM_FOV_MIN + ($CAM_FOW_MAX - $CAM_FOV_MIN) * ( 1.0 - ( $O['range'] / $Max_RANGE ) )) / 2.0;
if( abs($O['az']-$T['az']) > $T_FOV || abs($O['az']-$T['az']) > $T_FOV ){
if($Debug)fprintf( $fd, "Move PTZ \r\n" );
$CAM=new ponvif();
$CAM->setUsername( $CAM_USER );
$CAM->setPassword( $CAM_PASS );
$CAM->setIPAddress( $CAM_IP );
try {
$CAM->initialize();
$C_AZ = $T['az'] * ( 2.0 / 360.0 ) - 1.0;
$C_EL = $Z * ( 2.0 / 90.0 ) - 1.0;
$C_Z = $T['range'] / $Max_RANGE;
if($CAM_ZOOM_FIXED){
$CAM->ptz_AbsoluteMove( $CAM_PTZ_PROFILE, $C_AZ, $C_EL, $CAM_SET_ZOOM );
} else {
$CAM->ptz_AbsoluteMove( $CAM_PTZ_PROFILE, $C_AZ, $C_EL, $C_Z );
};
} catch (Exception $e) {
if($Debug)fprintf( $fd, 'Caught exception: ', $e->getMessage(), "\r\n" );
};
// Update Registry
$Registry['old_target'] = $T;
$Registry['last_ts'] = $TTS;
} else {
if($Debug)fprintf( $fd, "Move is Filtered\r\n" );
};
};
break;
};
case 'LCU:EVENTLIDAR2D':{
if($Debug)fprintf( $fd, "2D Target!\r\n" );
break;
};
};
};
xml_parser_free( $xml_parser );
} else {
$XS = false;
// Handle Jeson commands
if( isset( $JS['mitigation'] ) ){
if( isset( $JS['mitigation']['parameters'] ) ){
if( isset( $JS['mitigation']['parameters']['cmd'] ) ){
if( $JS['mitigation']['parameters']['cmd'] == 'ARM' ){
if( $_GET['z'] == 'jammer' ){
$CMD = 'usbrelay ' . $JAMMER_RELAY . '=1';
$D = `$CMD`;
};
if( $_GET['z'] == 'hunter' ){
$CMD = 'usbrelay ' . $FH_RELAY . '=1';
$D = `$CMD`;
};
};
if( $JS['mitigation']['parameters']['cmd'] == 'DISARM' ){
if( $_GET['z'] == 'jammer' ){
$CMD = 'usbrelay ' . $JAMMER_RELAY . '=0';
$D = `$CMD`;
};
if( $_GET['z'] == 'hunter' ){
$CMD = 'usbrelay ' . $FH_RELAY . '=0';
$D = `$CMD`;
};
};
};
};
};
};
if($Debug && 0 ){
fprintf( $fd, $Data . "\r\n" );
ob_start();
if( is_array( $JS )){
print_r( $JS );
};
if( $XS !== false ){
print_r( $XS );
};
$produced = ob_get_contents();
ob_end_clean();
fprintf( $fd, $produced . "\r\n" );
};
};
} catch ( Exception $e ) {
if($Debug)fprintf( $fd, 'Did not successfully process HTTP request: '.$e->getMessage() );
};
if($Debug){
fprintf( $fd, " ----------------- \r\n" );
fclose( $fd );
};
$rd = fopen( "registry.sjno", "r+" );
if(flock ( $rd, LOCK_EX )){
ftruncate($rd, 0);
fwrite($rd, json_encode( $Registry ));
fflush($rd);
flock($rd, LOCK_UN);
};
fclose( $rd);
?>