"; echo $cmd.""; */ foreach ($connections as $conn) { if ( (strstr($conn, $host.":".$port)) || (strstr($conn, $host_ip.":".$port)) || (strstr($conn, "localhost:".$port)) || (strstr($conn, "127.0.0.1:".$port)) ) { // $c = split(" +", $conn); $c = explode(" +", $conn); // $addr = split(":", $c[4]); $addr = explode(":", $c[4]); $state = $c[5]; if ($state == "ESTABLISHED") return $addr[0]; }; }; return ""; } function gds_check($read_osc) { global $host; global $host_ip; global $port; global $osclgrm; global $settings; $request = "*idn?\n"; $expected_reply = "GW,GDS-840C,EE142162,V2.02\n"; $gds = @fsockopen($host_ip, $port, $errno, $errstr, 1.0); if (!$gds) { // echo "
"; print_r($connections); echo "
"; // echo "fsockopen(): err #".$errno."(".$errstr.")"; // echo ""; // implies "connection refused"... // errno: 110 - conn timeout, 111 - conn refused... return -2; }; fwrite($gds, $request); stream_set_timeout($gds, 3); $reply = ""; while (strlen($reply) < strlen($expected_reply)) { $reply .= fread($gds, 128); $info = stream_get_meta_data($gds); if ($info['timed_out']) break; } if ($info['timed_out']) { // echo "
"; // print_r($info); // echo ""; // выключен/повис/не подключен return -3; } if ($read_osc) { $cmd = "CHAN1:DISP 1\n"; fwrite($gds, $cmd); $cmd = "CHAN2:DISP 1\n"; fwrite($gds, $cmd); $cmd = ":RUN\n"; fwrite($gds, $cmd); $cmd = "TIMEBASE:SCALE?\n"; fwrite($gds, $cmd); $settings['t_per_div'] = fread($gds, 32); $cmd = "CHANNEL1:SCALE?\n"; fwrite($gds, $cmd); $settings['v1_per_div'] = fread($gds, 32); $cmd = "CHANNEL2:SCALE?\n"; fwrite($gds, $cmd); $settings['v2_per_div'] = fread($gds, 32); $cmd = "ACQUIRE1:POINT\n"; fwrite($gds, $cmd); // sleep(1); $osclgrm1 = ""; while (strlen($osclgrm1) < 1014) { $osclgrm1 .= fread($gds, 1014); //$info = stream_get_meta_data($gds); //if ($info['timed_out']) // break; } $f = fopen("/tmp/gds-o1", "w"); flock($f, LOCK_EX); fwrite($f, $osclgrm1, 1014); flock($f, LOCK_UN); fclose($f); $cmd = "ACQUIRE2:POINT\n"; fwrite($gds, $cmd); // sleep(1); $osclgrm2 = ""; while (strlen($osclgrm2) < 1014) { $osclgrm2 .= fread($gds, 1014); //$info = stream_get_meta_data($gds); //if ($info['timed_out']) // break; } $f = fopen("/tmp/gds-o2", "w"); flock($f, LOCK_EX); fwrite($f, $osclgrm2, 1014); flock($f, LOCK_UN); fclose($f); } fclose($gds); echo "
"; // echo strlen($reply).""; return 1; }; function is_private_net($ip) { /* http://www.faqs.org/rfcs/rfc1918.html: 10.0.0.0 - 10.255.255.255 (10/8 prefix) 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) */ $ip_bytes = explode(".", $ip); if ($ip_bytes[0] == '10') return true; if (($ip_bytes[0] == '192') && ($ip_bytes[1] == '168')) return true; if (($ip_bytes[0] == '172') && ( ($ip_bytes[1] & 0xF0)== '16')) return true; return false; } /* function show_osc() { global $osclgrm; if (!strlen($osclgrm)) return; echo "
"; // echo strlen($expected_reply)."
"; $r = $reply; $r{strlen($r)-1} = " "; echo "*IDN? : ".$r; if (strstr($reply, $expected_reply)) { echo "
(GOOD ANSWER)"; } else { echo "
(BAD ANSWER)"; }; echo "
"; // $osc_pic = imagecreate(500, 200); // imagepng($osc_pic); // imagedestroy($osc_pic); } */ //$visiter = '172.248.56.11'; $visiter = $_SERVER['REMOTE_ADDR']; if (!is_private_net($visiter)) { echo "
"; echo strlen($osclgrm)."
"; echo "Header{}: ".$osclgrm{0}.$osclgrm{1}.$osclgrm{2}.$osclgrm{3}.$osclgrm{4}.$osclgrm{5}."\n"; $format = "A6id/fttt/C1chan/C3nnn/s500"; /// swap bytes in each sample for ($k = 0; $k < 1000; $k += 2 ) { $a = $osclgrm{$k+14}; $osclgrm{$k+14} = $osclgrm{$k+1+14}; $osclgrm{$k+1+14} = $a; }; echo $format."\n"; $data = unpack($format, $osclgrm); // if ($data['id'] != "#41008") { return; } print_r($data); echo "
UNDER con_СtРАК_ШН, ага
"; $ckinfo_file = "/tmp/gds840c_ckinfo"; $cash_expire = 30; $t3 = "проверено "; $used_by = gds_used_by(); if (!empty($used_by)) { $gds_status = -4; $t3 .= date("Y.m.d в H час i мин s сек", time()); $last_host = $visiter; } else { $time = time(); $ckinfo = @file($ckinfo_file); $last_chked = $ckinfo[0]; $gds_status = $ckinfo[1]; $last_host = $ckinfo[2]; if (($time - $last_chked) > $cash_expire) { $last_chked = $time; $gds_status = gds_check($_POST['show_osc']); $last_host = $visiter; $f = fopen($ckinfo_file, "w"); flock($f, LOCK_EX); fwrite($f, $last_chked."\n"); fwrite($f, $gds_status."\n"); fwrite($f, $last_host."\n"); flock($f, LOCK_UN); fclose($f); $t3 .= date("Y.m.d в H час i мин s сек", $last_chked); } else { $t3 .= date("Y.m.d в H час i мин s сек", $last_chked)."Легенда: жёлтенькое - канал 1, зелёненькое - канал 2 Цена деления по оси времени: ".trim($settings['t_per_div'])." Цена деления по оси напряжений, канал 1: ".trim($settings['v1_per_div'])." Цена деления по оси напряжений, канал 2: ".trim($settings['v2_per_div']).""; } } /* if (1 == $_POST['chan']) $opt1 = ""; else $opt1 = ""; if (2 == $_POST['chan']) $opt2 = ""; else $opt2 = ""; */ echo "