$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); ?>