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"; }

In reply to Satellite Tracking by tekniko

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.