Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Satellite Tracking

by tekniko (Deacon)
on May 14, 2002 at 14:21 UTC ( [id://166439]=CUFP: print w/replies, xml ) Need Help??

This program queries a Predict server on port 1210/UDP and returns values for satellite information, such as next acquisition of signal (AOS) and whether or not the satellite is in sunlight. Any suggestions for making it a bit more efficient?
#!/usr/bin/perl -w use strict; use Socket; my $port = 1210; my ($predict_server, $satellite); # Use defaults if no command line arguments given if ($#ARGV eq 1) { $predict_server = $ARGV[0]; $satellite = $ARGV[1]; } else { print "WARNING: Use syntax \"sat.pl hostname satellite\" (i.e., sat. +pl localhost FO-20)\n"; print "Substituting default arguments\n"; $predict_server = "localhost"; $satellite = "OSCAR-10"; } # Setup for UDP socket commumnication my ($d1, $d2, $d3, $d4, $rawserver) = gethostbyname($predict_server); my $serveraddr = pack("Sna4x8", 2, $port, $rawserver); my $prototype = getprotobyname('udp'); socket(SOCKET,2,SOCK_DGRAM,$prototype) || die("No Socket\n"); $| = 1; # no buffering # Setup timeout routine $SIG{ALRM} = \&time_out; alarm(10); # Force exit if no response from server # Send request to predict send(SOCKET, "GET_SAT $satellite\0" , 0 , $serveraddr) or die("UDP sen +d failed $!\n"); # Get response from predict my $server_response = ''; # required by recv function recv(SOCKET, $server_response, 100, 0) or die "UDP recv failed $!\n"; # Extract individual responses my ($name, $lon, $lat, $az, $el, $aos_seconds, $foot) = split /\n/, $s +erver_response; my $aos_time_date = gmtime($aos_seconds); # Output response print "\nPREDICT returned the following string in response to GET_SAT +$satellite:\n\n$server_response\n"; print "Values are as follows:\nName: $name\nLong: $lon\nLat: $lat\nAz: + $az\nEl: $el\nNext AOS: $aos_seconds = $aos_time_date UTC\nFootprint +: $foot\n\n"; close(SOCKET); sub time_out { die "Server not responding for satellite $satellite\n"; }

Replies are listed 'Best First'.
Re: Satellite Tracking
by particle (Vicar) on May 14, 2002 at 14:47 UTC
    cool. i have a few suggestions:

    • extend your command-line argument processing, perhaps using Getopt::Std
    • allow multiple satellites to be specified by using an array/for loop
    • allow user specification of server port, either via hostname[:port] or by a seperate command-line option
    • i prefer IO::Socket to raw Sockets, but that's your choice

    ~Particle *accelerates*

Re: Satellite Tracking
by brianarn (Chaplain) on May 14, 2002 at 17:40 UTC
    I like Particle's comments, and would just add two parts to it.
    • I'd recommend use of Getopt::Long versus Getopt::Std - that way, you could take arguments such as --host and -h for the host, etc.
    • Add some POD documentation, and use the Pod::Usage module to allow for a nice way to print the POD to your user. Pod::Usage and Getopt::Long really work well together. Anytime I write something now, I always use the two to include help options, as well as portable documentation.
    Update: As per crazyinsomniac, it was pointed out that I forgot to link in the tutorial - so here you go. =)
    The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!

    ~Brian

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://166439]
Approved by particle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found