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.

172 lines
5.4 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. $Debug = false;
  3. $Max_RANGE = 300.0; // 300 meters
  4. $CAM_IP = '192.168.0.109';
  5. $CAM_USER = 'gagua';
  6. $CAM_PASS = '4GetMyID';
  7. $CAM_PTZ_PROFILE = 'Profile_1';
  8. $CAM_TARGET_MICRO_DELAY = 3.0; //3 seconds
  9. $CAM_FOV_MIN = 5.0;
  10. $CAM_FOV_MAX = 45.0;
  11. $CAM_ZOOM_FIXED = false;
  12. $CAM_SET_ZOOM = 0;// 0 - 1.0
  13. $FH_RELAY = '';
  14. $JAMMER_RELAY = '';
  15. require_once('lib/soap_asm.php');
  16. $RegData = file_get_contents('registry.sjno');
  17. if($RegData!==false){
  18. $Registry = json_decode( $RegData, true );
  19. } else {
  20. $Registry = array();
  21. };
  22. $lts = date ( "Y/m/d H:i:s" );
  23. $rts = '';
  24. $Headers = getallheaders();
  25. if($Debug){
  26. $fd = fopen( "posts.txt", "a+" );
  27. fprintf( $fd, " ----------------- \r\n" );
  28. fprintf( $fd, "Header:\r\n" );
  29. foreach( $Headers as $key=>$value){
  30. fprintf( $fd, $key.': '.$value."\r\n" );
  31. };
  32. fprintf( $fd, "Post:\r\n" );
  33. foreach( $_POST as $key=>$value){
  34. fprintf( $fd, $key.': '.$value."\r\n" );
  35. };
  36. fprintf( $fd, "Get:\r\n" );
  37. foreach( $_GET as $key=>$value){
  38. fprintf( $fd, $key.': '.$value."\r\n" );
  39. };
  40. fprintf( $fd, "REST:\r\n" );
  41. };
  42. try {
  43. if (!($Data = file_get_contents('php://input'))) {
  44. fprintf( $fd, "Can not Read STDIO Data\r\n" );
  45. } else {
  46. $JS = json_decode( $Data, true );
  47. if( !is_array($JS) ){
  48. $xml_parser = xml_parser_create();
  49. if (!xml_parse_into_struct ( $xml_parser, $Data, $XS )){
  50. $XS = false;
  51. } else {
  52. // Handle XML commands
  53. switch($XS[0]['tag']){
  54. case 'LCU:SYSTEMSTATUS':{
  55. if($Debug)fprintf( $fd, "STATUS update!\r\n" );
  56. break;
  57. };
  58. case 'LCU:EVENTLIDAR3D':{
  59. $T['el'] = $XS[7]['value'] / 1000.0;
  60. $Z = ( 90.0 - $T['el'] );
  61. if( $Z < 0.0 ){
  62. $Z *= -1.0;
  63. $T['az'] = $XS[6]['value'] / 1000.0 + 180.0;
  64. if( $T['az'] > 360.0 ) $T['az'] -= 360.0;
  65. } else {
  66. $T['az'] = $XS[6]['value'] / 1000.0;
  67. };
  68. $T['range'] = $XS[8]['value'] / 10.0;
  69. $TTS = microtime(true);
  70. if($Debug)fprintf( $fd, "3D Target! Azimuth %.2f Elevation %.2f Range %.2f\r\n", $T['az'], $T['el'], $T['range'] );
  71. $O = $Registry['old_target'];
  72. $OTS = $Registry['last_ts'];
  73. if( ( $TTS-$OTS ) < $CAM_TARGET_MICRO_DELAY ){
  74. // Target Filters
  75. if($Debug)fprintf( $fd, "Move Filtered by Cam Delay %f $f\r\n", $TTS, $OTS );
  76. } else {
  77. $T_FOV = ( $CAM_FOV_MIN + ($CAM_FOW_MAX - $CAM_FOV_MIN) * ( 1.0 - ( $O['range'] / $Max_RANGE ) )) / 2.0;
  78. if( abs($O['az']-$T['az']) > $T_FOV || abs($O['az']-$T['az']) > $T_FOV ){
  79. if($Debug)fprintf( $fd, "Move PTZ \r\n" );
  80. $CAM=new ponvif();
  81. $CAM->setUsername( $CAM_USER );
  82. $CAM->setPassword( $CAM_PASS );
  83. $CAM->setIPAddress( $CAM_IP );
  84. try {
  85. $CAM->initialize();
  86. $C_AZ = $T['az'] * ( 2.0 / 360.0 ) - 1.0;
  87. $C_EL = $Z * ( 2.0 / 90.0 ) - 1.0;
  88. $C_Z = $T['range'] / $Max_RANGE;
  89. if($CAM_ZOOM_FIXED){
  90. $CAM->ptz_AbsoluteMove( $CAM_PTZ_PROFILE, $C_AZ, $C_EL, $CAM_SET_ZOOM );
  91. } else {
  92. $CAM->ptz_AbsoluteMove( $CAM_PTZ_PROFILE, $C_AZ, $C_EL, $C_Z );
  93. };
  94. } catch (Exception $e) {
  95. if($Debug)fprintf( $fd, 'Caught exception: ', $e->getMessage(), "\r\n" );
  96. };
  97. // Update Registry
  98. $Registry['old_target'] = $T;
  99. $Registry['last_ts'] = $TTS;
  100. } else {
  101. if($Debug)fprintf( $fd, "Move is Filtered\r\n" );
  102. };
  103. };
  104. break;
  105. };
  106. case 'LCU:EVENTLIDAR2D':{
  107. if($Debug)fprintf( $fd, "2D Target!\r\n" );
  108. break;
  109. };
  110. };
  111. };
  112. xml_parser_free( $xml_parser );
  113. } else {
  114. $XS = false;
  115. // Handle Jeson commands
  116. if( isset( $JS['mitigation'] ) ){
  117. if( isset( $JS['mitigation']['parameters'] ) ){
  118. if( isset( $JS['mitigation']['parameters']['cmd'] ) ){
  119. if( $JS['mitigation']['parameters']['cmd'] == 'ARM' ){
  120. if( $_GET['z'] == 'jammer' ){
  121. $CMD = 'usbrelay ' . $JAMMER_RELAY . '=1';
  122. $D = `$CMD`;
  123. };
  124. if( $_GET['z'] == 'hunter' ){
  125. $CMD = 'usbrelay ' . $FH_RELAY . '=1';
  126. $D = `$CMD`;
  127. };
  128. };
  129. if( $JS['mitigation']['parameters']['cmd'] == 'DISARM' ){
  130. if( $_GET['z'] == 'jammer' ){
  131. $CMD = 'usbrelay ' . $JAMMER_RELAY . '=0';
  132. $D = `$CMD`;
  133. };
  134. if( $_GET['z'] == 'hunter' ){
  135. $CMD = 'usbrelay ' . $FH_RELAY . '=0';
  136. $D = `$CMD`;
  137. };
  138. };
  139. };
  140. };
  141. };
  142. };
  143. if($Debug && 0 ){
  144. fprintf( $fd, $Data . "\r\n" );
  145. ob_start();
  146. if( is_array( $JS )){
  147. print_r( $JS );
  148. };
  149. if( $XS !== false ){
  150. print_r( $XS );
  151. };
  152. $produced = ob_get_contents();
  153. ob_end_clean();
  154. fprintf( $fd, $produced . "\r\n" );
  155. };
  156. };
  157. } catch ( Exception $e ) {
  158. if($Debug)fprintf( $fd, 'Did not successfully process HTTP request: '.$e->getMessage() );
  159. };
  160. if($Debug){
  161. fprintf( $fd, " ----------------- \r\n" );
  162. fclose( $fd );
  163. };
  164. $rd = fopen( "registry.sjno", "r+" );
  165. if(flock ( $rd, LOCK_EX )){
  166. ftruncate($rd, 0);
  167. fwrite($rd, json_encode( $Registry ));
  168. fflush($rd);
  169. flock($rd, LOCK_UN);
  170. };
  171. fclose( $rd);
  172. ?>