[Date Prev][Date Next][Thread Prev][Thread Next] - [Date Index][Thread Index][Author Index]

Linux Doppler Control



Hi,

I've been running this script for the last week or so (warts and  
all). It seems to be working reasonably well.  I'm using hamlib to  
talk to my FT-847 and predict in server mode to return the Doppler  
info.  Its based on the script Andrew Rich (nice pics of the  
A380 :) ) emailed previously.

It may be useful to someone else. If not, please excuse the spam.

Regards
de John
EI7IG

[snip]
#!/usr/bin/perl -w
# Based on script by Andrew Rich, VK4TEC.
# Thanks to MSOF for perl help.
# John Ronan, EI7IG October 2005

# MSOF: using standard libraries needed (perl modules)
# MSOF: One might consider adding:
# use strict;
# MSOF: to enable the strict parsing, but this may require some editing

use Socket;
use Net::Telnet;
use Math::Round;

# MSOF: Default values for global variables
# MSOF: "my" scope means only active in the main body not subroutines
# MSOF: I have changed to "local" to allow subroutines to see them
local $frequency;
local $port;
local $predict_server;
local $satellite;

# Set to 1 to enable debug information
local $debug = 1;

# MSOF: Parsing cmd line arguments
# If the no of args is 2 (i.e. <cmd> $ARGV[1] $ARGV[2])
if ($#ARGV eq 1) {
   $predict_server = $ARGV[0];
   $port		  = $ARGV[1];
} else {
   # Print Usage and assume default values
   print "WARNING: Use syntax \"predict_radiocontrol.pl hostname  
portnum\" (i.e., predict_radioconttrol localhost port)\n";
   print "Substituting default arguments\n";
   $predict_server = "localhost";
   $port = 1210;
}
# End parsing cmd line arguments

# MSOF: Associative array of name=>value pairs
# MSOF: associate arrays have no order, so my hack here
#       is to prepend a letter denoting order that I then strip off
#	- awkward as must use original version as key to get value
my %sats = (
   "aISS"             =>       43527500,
   "bPCSAT"            =>      14582600,
#  "cXI-V" 	      =>      43746500,
#  "dOSCAR-50"         =>      43680000,
#  "eAMSAT ECHO"       =>      43530000,
#  "fOSCAR-11"         =>      14582600,
#  "gOSCAR-27"	      =>      43679500
);
do{	
   foreach $sat (sort keys %sats) {
	# MSOF: hack to strip off prepended letter to force PCSAT 1st
	my $satstrip = substr($sat,1);
	if ($debug)
	{
	  print "Calling: $satstrip \t $sats{$sat} \n";
         }
	my_main($predict_server,$port,$satstrip,$sats{$sat});	# Call with  
key and value
   }
   #wait 30 sec and check again	
sleep 30;
}while (1);
# MSOF: Finish
exit;

#================================================================

# MSOF: Wrapped as new sub routine
sub my_main {
   # MSOF: Perl arguments passed in array @_ in elements $_[0]...$_[N]
#  do {
   # MSOF: Set values to arguments
   # MSOF: (no checking as we did this ourselves and it should be right)
   $predict_server = $_[0];
   $port		  = $_[1];
   $satellite 	  = $_[2];
   $frequency 	  = $_[3];

   # if freq is VHF use 30 second loop time
   $sleep	  = 1;

   if ($debug)
   {
     print "Sleep is $sleep\n";
   }
   # Doing unix-style DNS calls here

   my ($d1, $d2, $d3, $d4, $rawserver) = gethostbyname($predict_server);
   my $serveraddr = pack("Sna4x8", 2, $port, $rawserver);
   my $prototype = getprotobyname('udp');
   do {
   socket(SOCKET,2,SOCK_DGRAM,$prototype)
	|| die("No Socket\n");
   $| = 1;  # no buffering
   $SIG{ALRM} = \&time_out;
   alarm(10);  # Force exit if no response from server
   send(SOCKET, "GET_DOPPLER $satellite\0" , 0 , $serveraddr)
	or die ("UDP send failed $!\n");
   my $server_response = '';  # required by recv function
   recv(SOCKET, $server_response, 100, 0) or die "UDP recv failed $!\n";
   alarm(0);
   # My is that at this point we loop changing doppler for
   # PCSAT2 as it is in range.
# $shift = (($server_response * 4.375) / 100 );
   $shift = (($server_response * ($frequency/10000000)) / 10 );
   $newfreq = (int($frequency + $shift));
   $rounded = nearest(1,$newfreq) ;
   if ( $debug )
   {
     # MSOF: Replaced backtick with qx// notation
     $date = qx/date +%d\/%m\/%y" "%H:%M:%S/;
     chop $date;
     print "DATE: $date \n";
     print "SATT: $satellite \n";
     print "BASE: $frequency \n";
     print "HOST: $predict_server \n";
     print "PORT: $port \n";
     print "TUNE: $rounded"."00"."\n";
     print "DOPP: $shift \n\n";
   }

   $sendtorig = $rounded."0";
   sleep $sleep;
   # If the satellite above the horizon is at VHF, we don't need to  
loop as quickly.
   # reduces the load on my machine
   if (  int($frequency/100000) eq "145" )
   {
     $sleep = 30;
   }
   # If the satellite is not in range, don't change the vfo
   # This allow two things
   # a) I can use the radio when the satellite is not in range
   # b) I can continue to listen after "LOS".
   if ($shift ne "0")
   {
     # Calls hamlib to change the frequency of the radio
     system("/usr/local/bin/rigctl -m 101 -r /dev/ttyS5 -s 4800 F  
$sendtorig");

     # Andrews original code
     #need to loop here reading the socket until it equals - again.
     #open (comport, "> /dev/ttyS0");
     #print comport "FQ 00".$rounded."000,0\n";
     #close(comport);
   }
   close(SOCKET);
   # If the satellite is over the horizon, stay with it until AOS
   } while ( $shift ne "0" );

} # MSOF: End my_main()

sub time_out {
	die "Server not responding for satellite $satellite\n";
}

--
John Ronan <jronan@tssg.org>, +353-51-302938
Telecommunications Software &  Systems Group,  http://www.tssg.org
----
Sent via amsat-bb@amsat.org. Opinions expressed are those of the author.
Not an AMSAT member? Join now to support the amateur satellite program!
To unsubscribe, send "unsubscribe amsat-bb" to Majordomo@amsat.org



AMSAT Top AMSAT Home