From fb301ecd7ecf1b62a8659ce935faa3f5f2495d29 Mon Sep 17 00:00:00 2001 From: Grzegorz Surmann Date: Mon, 16 Jan 2023 19:27:05 +0100 Subject: [PATCH] first commit --- rigctld.php | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++ rigctld2.php | 89 +++++++++++++++++++++++++++++++++++++++++ rigctld3.php | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ rigscan.php | 50 +++++++++++++++++++++++ rigswr.php | 31 +++++++++++++++ tune.php | 12 ++++++ tune2.php | 12 ++++++ 7 files changed, 411 insertions(+) create mode 100644 rigctld.php create mode 100644 rigctld2.php create mode 100644 rigctld3.php create mode 100644 rigscan.php create mode 100644 rigswr.php create mode 100644 tune.php create mode 100644 tune2.php diff --git a/rigctld.php b/rigctld.php new file mode 100644 index 0000000..e8ab069 --- /dev/null +++ b/rigctld.php @@ -0,0 +1,109 @@ + RIG CONNECT... "; +$rigcmd=$rigctl.' -m '.$rmodel.' -r '.$device.' -s '.$dspeed; +$socket=popen($rigcmd,'r'); +print "OK (".$device.")\n"; +print "CMD[".$rigcmd."]\n"; +$last_read=time(); +while ( TRUE ) { + # GET + $get=file_get_contents('http://qrzcq.com/api/rig/get/'.$mycall.'|'.$apikey); + $put=json_decode($get); + if ( $put->status == 'OK' ) { + if ( isset($put->rig) ) { + if ( $put->rig->set->freq > 0 && $put->rig->set->freq <= 54000000 && strlen($put->rig->set->mode) > 0 ) { + $freq=$put->rig->set->freq; + $mode=$put->rig->set->mode; + ################################################################ + ## DO WHATEVER YOU NEED TO SET YOUR RIG TO THIS FREQ AND MODE ## + ################################################################ + // here for Yaesu FT-950 + // it needs to switch band before setting frequency and mode + $afreq=array(); $get_freq=$rigcmd.' f'; exec($get_freq,$afreq,$fret); $old_freq=trim($afreq[0]); + if ( get_band_of_freq($old_freq) != get_band_of_freq($freq) ) { + print "==> STACK SWITCH for $freq\n"; + $sw_count=0; + while ( get_band_of_freq($freq) != get_band_of_freq($old_freq) ) { + if ( $freq > $old_freq ) { + $aband=array(); exec($rigcmd.' G BAND_UP',$aband,$bret); + print "[upup]"; + } elseif ( $freq < $old_freq ) { + $aband=array(); exec($rigcmd.' G BAND_DOWN',$aband,$bret); + print "[down]"; + } + $sw_count++; + if ( $sw_count > 30 ) { + die("\n\nERROR: fix band switch!\nSYSTEM HALTED.\n"); + } + $afreq=array(); $get_freq=$rigcmd.' f'; exec($get_freq,$afreq,$fret); $old_freq=trim($afreq[0]); + } + print "\n"; + } + if ( $mode == 'CW' ) { $wid=$cw_wid; } else { $wid=$ssb_wid; }; + $amode=array(); exec($rigcmd.' M '.$mode.' '.$wid,$amode,$mret); + $afreq=array(); exec($rigcmd.' F '.$freq,$afreq,$fret); + print "==> RIG SET TO ".number_format($freq,0,'','.')." ".$mode." ".$wid."\n"; + ################################################################ + ################################################################ + } + } + usleep(1000); + } else { + print "ERROR: QRZCQ GET FAILED\n"; + print "SLEEP(10)\n"; + sleep(10); + } + # PUT + if ( time() != $last_read ) { + ############################################################# + ## DO WHATEVER YOU NEED TO READ THE FREQ AND MODE FROM RIG ## + ############################################################# + // here for Yaesu FT-950 + $afreq=array(); $get_freq=$rigcmd.' f'; exec($get_freq,$afreq,$fret); $freq=trim($afreq[0]); + $amode=array(); $get_mode=$rigcmd.' m'; exec($get_mode,$amode,$mret); $mode=trim($amode[0]); + $asmet=array(); $get_smet=$rigcmd.' l STRENGTH'; exec($get_smet,$asmet,$sret); $smet=trim($asmet[0]); + if ( count($amode) > 1 ) { $wid=trim($amode[1]); }; + ############################################################# + ############################################################# + if ( $freq*1 > 0 && $mode == strtoupper($mode) ) { + #print "RIG READ ".$freq." ".$mode." ".$wid."\n"; + $smet=$smet+54; # dB S9 -> dB S0 + $put=file_get_contents('http://qrzcq.com/api/rig/put/'.$mycall.'|'.$apikey.'/'.$mode.'|'.$freq.'|'.$smet); + $get=json_decode($put); + if ( $get->status != 'OK' ) { print "\nERROR: QRZCQ PUT FAILED\n"; }; + } + $last_read=time(); + if ( preg_match("/0$/",time()) && $freq*1 > 0 && $mode == strtoupper($mode) ) { print "ALIVE[_".number_format($freq,0,'','.')."_/".$mode."/".$wid."/".$smet."]\n"; }; + usleep(1000); + } + # SLEEP + usleep(200*1000); + # STAMP + if ( mt_rand(1,1000) == 1000 ) { + print "STAMP[".gmdate("Y-m-d H:i:s")."]\n"; + } +} +function get_band_of_freq($freq) { + if ( 1800000 <= $freq && $freq <= 2000000 ) { return 1; }; + if ( 3500000 <= $freq && $freq <= 4000000 ) { return 2; }; + if ( 5258500 <= $freq && $freq <= 5450000 ) { return 3; }; + if ( 7000000 <= $freq && $freq <= 7300000 ) { return 4; }; + if ( 10100000 <= $freq && $freq <= 10150000 ) { return 5; }; + if ( 14000000 <= $freq && $freq <= 14350000 ) { return 6; }; + if ( 18068000 <= $freq && $freq <= 18168000 ) { return 7; }; + if ( 21000000 <= $freq && $freq <= 21450000 ) { return 8; }; + if ( 24890000 <= $freq && $freq <= 24990000 ) { return 9; }; + if ( 28000000 <= $freq && $freq <= 29700000 ) { return 10; }; + if ( 50000000 <= $freq && $freq <= 54000000 ) { return 11; }; + #print "## OUTER BAND ## ".$freq." ##\n"; + return 0; +} diff --git a/rigctld2.php b/rigctld2.php new file mode 100644 index 0000000..0b8602c --- /dev/null +++ b/rigctld2.php @@ -0,0 +1,89 @@ + Fil-2 +$cw_wid='500'; +############################################################### +print "==> RIG CONNECT... "; +$rigcmd=$rigctl.' -m '.$rmodel.' -r '.$device.' -s '.$dspeed; +$socket=popen($rigcmd,'r'); +print "OK (".$device.")\n"; +print "CMD[".$rigcmd."]\n"; +$last_read=time(); +while ( TRUE ) { + # GET + $get=file_get_contents('https://qrzcq.com/api/rig/get/'.$mycall.'|'.$apikey); + $put=json_decode($get); + if ( $put->status == 'OK' ) { + if ( isset($put->rig) ) { + if ( $put->rig->set->freq > 0 && $put->rig->set->freq <= 54000000 && strlen($put->rig->set->mode) > 0 ) { + $freq=$put->rig->set->freq; + $mode=$put->rig->set->mode; + ################################################################ + ## DO WHATEVER YOU NEED TO SET YOUR RIG TO THIS FREQ AND MODE ## + ################################################################ + // here for Icom IC-7600 + // it needs to switch band before setting frequency and mode + if ( $mode == 'CW' ) { $wid=$cw_wid; } else { $wid=$ssb_wid; }; + $amode=array(); exec($rigcmd.' M '.$mode.' '.$wid,$amode,$mret); + $afreq=array(); exec($rigcmd.' F '.$freq,$afreq,$fret); + print "==> RIG SET TO ".number_format($freq,0,'','.')." ".$mode." ".$wid."\n"; + ################################################################ + ################################################################ + } + } + usleep(1000); + } else { + print "ERROR: QRZCQ GET FAILED\n"; + print "SLEEP(10)\n"; + sleep(10); + } + # PUT + if ( time() != $last_read ) { + ############################################################# + ## DO WHATEVER YOU NEED TO READ THE FREQ AND MODE FROM RIG ## + ############################################################# + // here for Icom IC-7600 + $afreq=array(); $get_freq=$rigcmd.' f'; exec($get_freq,$afreq,$fret); $freq=trim($afreq[0]); + $amode=array(); $get_mode=$rigcmd.' m'; exec($get_mode,$amode,$mret); $mode=trim($amode[0]); + $asmet=array(); $get_smet=$rigcmd.' l STRENGTH'; exec($get_smet,$asmet,$sret); $smet=trim($asmet[0]); + if ( count($amode) > 1 ) { $wid=trim($amode[1]); }; + ############################################################# + ############################################################# + if ( $freq*1 > 0 && $mode == strtoupper($mode) ) { + #print "RIG READ ".$freq." ".$mode." ".$wid."\n"; + $smet=$smet+54; # dB S9 -> dB S0 + $put=file_get_contents('https://qrzcq.com/api/rig/put/'.$mycall.'|'.$apikey.'/'.$mode.'|'.$freq.'|'.$smet); + $get=json_decode($put); + if ( $get->status != 'OK' ) { print "\nERROR: QRZCQ PUT FAILED\n"; }; + } + $last_read=time(); + if ( preg_match("/0$/",time()) && $freq*1 > 0 && $mode == strtoupper($mode) ) { print "ALIVE[_".number_format($freq,0,'','.')."_/".$mode."/".$wid."/".$smet."]\n"; }; + usleep(1000); + } + # SLEEP + usleep(200*1000); + # STAMP + if ( mt_rand(1,1000) == 1000 ) { + print "STAMP[".gmdate("Y-m-d H:i:s")."]\n"; + } +} +function get_band_of_freq($freq) { + if ( 1800000 <= $freq && $freq <= 2000000 ) { return 1; }; + if ( 3500000 <= $freq && $freq <= 4000000 ) { return 2; }; + if ( 5258500 <= $freq && $freq <= 5450000 ) { return 3; }; + if ( 7000000 <= $freq && $freq <= 7300000 ) { return 4; }; + if ( 10100000 <= $freq && $freq <= 10150000 ) { return 5; }; + if ( 14000000 <= $freq && $freq <= 14350000 ) { return 6; }; + if ( 18068000 <= $freq && $freq <= 18168000 ) { return 7; }; + if ( 21000000 <= $freq && $freq <= 21450000 ) { return 8; }; + if ( 24890000 <= $freq && $freq <= 24990000 ) { return 9; }; + if ( 28000000 <= $freq && $freq <= 29700000 ) { return 10; }; + if ( 50000000 <= $freq && $freq <= 54000000 ) { return 11; }; + #print "## OUTER BAND ## ".$freq." ##\n"; + return 0; +} diff --git a/rigctld3.php b/rigctld3.php new file mode 100644 index 0000000..659d118 --- /dev/null +++ b/rigctld3.php @@ -0,0 +1,108 @@ + Fil-2 +$cw_wid='500'; +############################################################### +print "==> RIG CONNECT... "; +$rigcmd=$rigctl.' -m '.$rmodel.' -r '.$device.' -s '.$dspeed; +$socket=popen($rigcmd,'r'); +print "OK (".$device.")\n"; +print "CMD[".$rigcmd."]\n"; +$last_read=time(); +while ( TRUE ) { + # GET + // get beg + $data = new stdClass(); + $data->auth = new stdClass(); + $data->auth->call=$mycall; + $data->auth->key=$apikey; + $get=qrzcq_api_rig('get',$data); + // get end + if ( $get->status == 'OK' ) { + if ( isset($get->rig) ) { + if ( $get->rig->set->freq > 0 && $get->rig->set->freq <= 54000000 && strlen($get->rig->set->mode) > 0 ) { + $freq=$get->rig->set->freq; + $mode=$get->rig->set->mode; + ################################################################ + ## DO WHATEVER YOU NEED TO SET YOUR RIG TO THIS FREQ AND MODE ## + ################################################################ + // here for Icom IC-7600 + if ( $mode == 'CW' ) { $wid=$cw_wid; } else { $wid=$ssb_wid; }; + $amode=array(); exec($rigcmd.' M '.$mode.' '.$wid,$amode,$mret); + $afreq=array(); exec($rigcmd.' F '.$freq,$afreq,$fret); + print "==> RIG SET TO ".number_format($freq,0,'','.')." ".$mode." ".$wid."\n"; + ################################################################ + ################################################################ + } + } + usleep(1000); + } else { + print "ERROR: QRZCQ GET FAILED\n"; + print "SLEEP(10)\n"; + sleep(10); + } + unset($data); + # PUT + if ( time() != $last_read ) { + ############################################################# + ## DO WHATEVER YOU NEED TO READ THE FREQ AND MODE FROM RIG ## + ############################################################# + // here for Icom IC-7600 + $afreq=array(); $get_freq=$rigcmd.' f'; exec($get_freq,$afreq,$fret); $freq=trim($afreq[0]); + $amode=array(); $get_mode=$rigcmd.' m'; exec($get_mode,$amode,$mret); $mode=trim($amode[0]); + $asmet=array(); $get_smet=$rigcmd.' l STRENGTH'; exec($get_smet,$asmet,$sret); $smet=trim($asmet[0]); + if ( count($amode) > 1 ) { $wid=trim($amode[1]); }; + ############################################################# + ############################################################# + if ( $freq*1 > 0 && $mode == strtoupper($mode) ) { + #print "RIG READ ".$freq." ".$mode." ".$wid."\n"; + $smet=$smet+54; # dB S9 -> dB S0 + // put beg + $data = new stdClass(); + $data->auth = new stdClass(); + $data->auth->call=$mycall; + $data->auth->key=$apikey; + $data->request = new stdClass(); + $data->request->mode=$mode; + $data->request->freq=$freq; + $data->request->smeter=$smet; + $put=qrzcq_api_rig('put',$data); + // put end + if ( $put->status != 'OK' ) { print "\nERROR: QRZCQ PUT FAILED\n"; }; + } + $last_read=time(); + if ( preg_match("/0$/",time()) && $freq*1 > 0 && $mode == strtoupper($mode) ) { print "ALIVE[_".number_format($freq,0,'','.')."_/".$mode."/".$wid."/".$smet."]\n"; }; + usleep(1000); + } + # SLEEP + usleep(200*1000); + # STAMP + if ( mt_rand(1,1000) == 1000 ) { + print "STAMP[".gmdate("Y-m-d H:i:s")."]\n"; + } +} +function qrzcq_api_rig($type,$data) { + if ( ( $type == 'get' || $type == 'put' ) && is_object($data) ) { + #print_r($data); + $data_string = json_encode($data); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_URL, 'https://ssl.qrzcq.com/api/rig/'.$type); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + #curl_setopt($ch, CURLOPT_VERBOSE, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_POST, 1); + $result=curl_exec($ch); + if ( $result !== FALSE ) { + $ret=json_decode($result); + #print_r($ret); + return $ret; + } + } + return FALSE; +} diff --git a/rigscan.php b/rigscan.php new file mode 100644 index 0000000..40778e8 --- /dev/null +++ b/rigscan.php @@ -0,0 +1,50 @@ + RIG CONNECT... "; +$rigcmd=$rigctl.' -m '.$rmodel.' -r '.$device.' -s '.$dspeed; +$socket=popen($rigcmd,'r'); +print "OK (".$device.")\n"; +print "CMD[".$rigcmd."]\n"; +for ($freq = $beg; $freq <= $end; $freq+=$step) { + $afreq=array(); exec($rigcmd.' F '.$freq,$afreq,$fret); + usleep(10000); + $asmet=array(); $get_smet=$rigcmd.' l STRENGTH'; exec($get_smet,$asmet,$sret); $smet=trim($asmet[0]); + if ( $smet > 60 || preg_match("/error/",$smet) ) { + usleep(10000); + $asmet=array(); $get_smet=$rigcmd.' l STRENGTH'; exec($get_smet,$asmet,$sret); $smet=trim($asmet[0]); + } + if ( $smet > 60 || preg_match("/error/",$smet) ) { + usleep(10000); + $asmet=array(); $get_smet=$rigcmd.' l STRENGTH'; exec($get_smet,$asmet,$sret); $smet=trim($asmet[0]); + } + print "[".$freq."] [".smeter($smet)."] ".str_repeat("|",($smet+60))."\n"; +} +print "-END-\n"; +pclose($socket); +function smeter($dbs9) { + if ( $dbs9 > 60 ) { + $dbs9 = 60; + } + if ( $dbs9 < -54 ) { + $dbs9 = -54; + } + $overs9 = $dbs9 - 54; + if ( $overs9 < 0 ) { + $overs9 = 0; + } + if ( $dbs9 > 0 ) { + $dbs9 = 0; + } + $smeter = 'S'.round(($dbs9+54)/6); + if ( $overs9 > 0 ) { + $smeter .= '+'.$overs9.'dB'; + } + return $smeter; +} diff --git a/rigswr.php b/rigswr.php new file mode 100644 index 0000000..904db58 --- /dev/null +++ b/rigswr.php @@ -0,0 +1,31 @@ + RIG CONNECT... "; +$rigcmd=$rigctl.' -m '.$rmodel.' -r '.$device.' -s '.$dspeed; +$socket=popen($rigcmd,'r'); +print "OK (".$device.")\n"; +print "CMD[".$rigcmd."]\n"; +for ($freq = $beg; $freq <= $end; $freq+=$step) { + $afreq=array(); exec($rigcmd.' F '.$freq,$afreq,$fret); + exec($rigcmd.' T 1'); + usleep(200000); + $aswr=array(); $get_swr=$rigcmd.' l SWR'; exec($get_swr,$aswr,$sret); $swr=trim($aswr[0]); + if ( $swr == 0 || $swr > 1 || preg_match("/error/",$swr) ) { + usleep(200000); + $aswr=array(); $get_swr=$rigcmd.' l SWR'; exec($get_swr,$aswr,$sret); $swr=trim($aswr[0]); + } + if ( $swr == 0 || $swr > 1 || preg_match("/error/",$swr) ) { + usleep(200000); + $aswr=array(); $get_swr=$rigcmd.' l SWR'; exec($get_swr,$aswr,$sret); $swr=trim($aswr[0]); + } + print "[".$freq."] [".$swr."] ".str_repeat("|",ceil($swr*100))."\n"; + exec($rigcmd.' T 0'); + usleep(200000); +} diff --git a/tune.php b/tune.php new file mode 100644 index 0000000..c506c89 --- /dev/null +++ b/tune.php @@ -0,0 +1,12 @@ + RIG CONNECT... "; +$rigcmd=$rigctl.' -m '.$rmodel.' -r '.$device.' -s '.$dspeed; +print "OK (".$device.")\n"; +print "CMD[".$rigcmd."]\n"; +$ctune=array(); $cmd_tune=$rigcmd.' G TUNE'; exec($cmd_tune,$ctune,$cret); +print "TUNE[]\n"; diff --git a/tune2.php b/tune2.php new file mode 100644 index 0000000..c506c89 --- /dev/null +++ b/tune2.php @@ -0,0 +1,12 @@ + RIG CONNECT... "; +$rigcmd=$rigctl.' -m '.$rmodel.' -r '.$device.' -s '.$dspeed; +print "OK (".$device.")\n"; +print "CMD[".$rigcmd."]\n"; +$ctune=array(); $cmd_tune=$rigcmd.' G TUNE'; exec($cmd_tune,$ctune,$cret); +print "TUNE[]\n";