first commit

This commit is contained in:
Grzegorz Surmann 2023-01-16 19:27:05 +01:00
commit fb301ecd7e
7 changed files with 411 additions and 0 deletions

109
rigctld.php Normal file
View File

@ -0,0 +1,109 @@
<?
$mycall='XXXXXX'; # my call sign
$apikey='XXXXXXXXXXXXXXXX'; # my qrzcq api key
$rigctl='/usr/bin/rigctl'; # where rigctl lives
$rmodel='363'; # rig model for hamlib
$device='/dev/ttyUSB0'; # serial device connected to rig
$dspeed='19200'; # serial speed set in rig
$ssb_wid='3000';
$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('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;
}

89
rigctld2.php Normal file
View File

@ -0,0 +1,89 @@
<?php
$mycall='XXXXXX'; # my call sign
$apikey='XXXXXXXXXXXXXXXX'; # my qrzcq api key
$rigctl='/usr/bin/rigctl'; # where rigctl lives
$rmodel='363'; # rig model for hamlib
$device='/dev/ttyUSB0'; # serial device connected to rig
$dspeed='19200'; # serial speed set in rig
$ssb_wid='2400'; # Icom IC-7600 -> 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;
}

108
rigctld3.php Normal file
View File

@ -0,0 +1,108 @@
<?php
$mycall='XXXXXX'; # my call sign
$apikey='XXXXXXXXXXXXXXXX'; # my qrzcq api key
$rigctl='/usr/bin/rigctl'; # where rigctl lives
$rmodel='363'; # rig model for hamlib
$device='/dev/ttyUSB1'; # serial device connected to rig
$dspeed='19200'; # serial speed set in rig
$ssb_wid='2400'; # Icom IC-7600 -> 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;
}

50
rigscan.php Normal file
View File

@ -0,0 +1,50 @@
<?php
$beg=3600000;
$end=3800000;
$step=1000;
$rigctl='/usr/bin/rigctl'; # where rigctl lives
$rmodel='363'; # rig model for hamlib
$device='/dev/ttyUSB0'; # serial device connected to rig
$dspeed='19200'; # serial speed set in rig
###############################################################
print "==> 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;
}

31
rigswr.php Normal file
View File

@ -0,0 +1,31 @@
<?
$beg=3500000;
$end=3800000;
$step=20000;
$rigctl='/usr/bin/rigctl'; # where rigctl lives
$rmodel='363'; # rig model for hamlib
$device='/dev/ttyUSB0'; # serial device connected to rig
$dspeed='19200'; # serial speed set in rig
###############################################################
print "==> 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);
}

12
tune.php Normal file
View File

@ -0,0 +1,12 @@
<?php
$rigctl='/usr/bin/rigctl'; # where rigctl lives
$rmodel='363'; # rig model for hamlib
$device='/dev/ttyUSB0'; # serial device connected to rig
$dspeed='19200'; # serial speed set in rig
###############################################################
print "==> 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";

12
tune2.php Normal file
View File

@ -0,0 +1,12 @@
<?php
$rigctl='/usr/bin/rigctl'; # where rigctl lives
$rmodel='363'; # rig model for hamlib
$device='/dev/ttyUSB0'; # serial device connected to rig
$dspeed='19200'; # serial speed set in rig
###############################################################
print "==> 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";