[pskmail] Re: A tiny progress report regarding gps

  • From: Rein Couperus <rein@xxxxxxxxxxxx>
  • To: pskmail@xxxxxxxxxxxxx
  • Date: Sat, 10 Feb 2007 22:59:42 +0100

This piece of code does the same as the previous one, nut at 0% CPU. It 
subscribes to gpsd and writes the intresting values (lat lon, time) into a file 
called .gps, where it can be fetched from anywhere with a simple $gpsvalues = 
`cat .gps`;
I think gpsd runs in user space so we can spawn it from pskmail...:

#!/usr/bin/perl -w

=head1 NAME

example-subscribe - Net::GPSD subscribe method example

=cut

use strict;
use lib qw{./lib ../lib};
use Net::GPSD;

my ($host,$port)=split(q{:}, shift()||'');
$host||=q{localhost};
$port||=q{2947};

my $gps=Net::GPSD->new(host=>$host, port=>$port)
    || die("Error: Cannot connect to the gpsd server");

$gps->subscribe(handler=>\&point_handler);

print "Note: Nothing after the subscribe will be executed.\n";

sub point_handler {
  my $last_return=shift()||1; #the return from the last call or undef if first
  my $point=shift(); #current point $point->fix is true!
  my $config=shift();
          if ($point->fix) {
                open (OUTGPS, ">.gps");
                print OUTGPS $last_return, " ", $point->lat, " ", $point->lon, 
" ", $point->time. "\n";
                close (OUTGPS);
          } else { 
                open (OUTGPS, ">.gps");
                print "No fix\n";
                close (OUTGPS);
          }
  return $last_return + 1; #Return a true scalar type e.g. $a, {}, []
                           #try the interesting return of $point
}



> -----Ursprüngliche Nachricht-----
> Von: pskmail@xxxxxxxxxxxxx
> Gesendet: 10.02.07 21:25:42
> An: pskmail@xxxxxxxxxxxxx
> Betreff: [pskmail] Re: A tiny progress report regarding gps


> 
> Hi Rein and all,
> 
> I started this "thread" by looking at gpsd as I figured that would be
> the best way to interface with a gps. I then set my eyes on GPS::NMEA
> and saw how easy that was to use...
> The benefit of working without gpsd would be to make installs easier and
> minimize external dependencies. if GPS::NMEA now uses a lot of cpu then
> that is certainly not in its favour. We could do it all the hard way
> also and open a port and parse nmea direct. Such as here:
> http://vancouver-webpages.com/peter/nmea.perl
> 
> But, then we would really be building a new gpsd and I find thats a
> waste of effort. So, should we go with gpsd then ?
> 
> On a sidenote I have a hard time adjusting to the use of loops in perl.
> If I would do that in any other language then everything would freeze.
> In Pascal I would call Application.ProcessMessages once in a while to
> leave some time for the OS to do its things.
> 
> 73 de Per, sm0rwo
> 
> 
> lör 2007-02-10 klockan 20:53 +0100 skrev Rein Couperus:
> > Hi Per,
> > 
> > I have been testing around a bit an d found a problem with GPS::NMEA.
> > 
> > below is a little test progam. It reads the gps constantly and puts the 
> > time and position into ~/mail/.utc
> > 
> > The problem is that reading the socket this way takes up to 30% of my CPU. 
> > (As a reference, fldigi takes 3% of may CPU).
> > 
> > I have also checked gpsd, and that does it with 0% CPU. I will now start 
> > some testing with NET::GPSD.
> > 
> > Here is the little test program. Even if you only want the position it 
> > takes a lot of CPU time:
> > 
> > #!/usr/bin/perl
> > use GPS::NMEA;
> > use Data::Dumper;
> > 
> > my $gps = GPS::NMEA->new(Port => '/dev/ttyUSB0',
> > Baud => 4800);
> > 
> > print "Starting gps\n";
> > 
> > while(1) {
> >     my($ns,$lat,$ew,$lon) = $gps->get_position;
> > 
> >     $data= Data::Dumper->new([$gps->{NMEADATA}],[])->Dump;
> >     @items = split ",", $data;
> >     for $utc (@items) {
> >             if ($utc =~ /(\d\d:\d\d:\d\d)/) { 
> >                     if ($ns eq "S") {
> >                             $ns = "-";
> >                     } else {
> >                             $ns = " ";
> >                     }
> >                     if ($ew eq "W") {
> >                             $ew = "-";
> >                     } else {
> >                             $ew = " ";
> >                     }
> >                     $outstring = sprintf("%s %s%s %s%s\n", 
> > $1,$ns,$lat,$ew,$lon);
> >                     `echo "$outstring" > ~/mail/.utc`;
> >                     print $outstring;
> >                     last;
> >             } else {
> >                     unlink "$ENV{HOME}/mail/.utc";
> >             }
> >     }
> >     select undef, undef, undef, 0.5;
> > } # end while
> > 
> > exit;
> > 
> > 
> > > -----Ursprüngliche Nachricht-----
> > > Von: pskmail@xxxxxxxxxxxxx
> > > Gesendet: 10.02.07 15:39:04
> > > An: pskmail@xxxxxxxxxxxxx
> > > Betreff: [pskmail] Re: A tiny progress report regarding gps
> > 
> > 
> > > 
> > > I agree, that is an absolute must.
> > > 
> > > Per
> > > 
> > > (Sunny, -10C in the sun now)
> > > 
> > > lör 2007-02-10 klockan 13:54 +0100 skrev Rein Couperus:
> > > > forgot, it would be nice if we could also get gps time so we can update 
> > > > the clock without internet...
> > > > 
> > > > Rein
> > > > 
> > > > (Sunny, 20 degrees in the shade...)
> > > > 
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: pskmail@xxxxxxxxxxxxx
> > > > > Gesendet: 10.02.07 11:58:00
> > > > > An: pskmail@xxxxxxxxxxxxx
> > > > > Betreff: [pskmail] Re: A tiny progress report regarding gps
> > > > 
> > > > 
> > > > > 
> > > > > lör 2007-02-10 klockan 10:55 +0100 skrev Rein Couperus:
> > > > > > Hi Per,
> > > > > > 
> > > > > > I think what we need is something we can poll from pskmail, so we 
> > > > > > can get the position when we want.
> > > > > > One way to do that is to fork a new process which does exactly what 
> > > > > > you did, and put the result in a file which we can read any time 
> > > > > > from any of the other preocesses...
> > > > > > 
> > > > > > Rein EA/PA0R/P
> > > > > > 
> > > > > Ok, that should be easy (will fix).
> > > > > I haven't looked at the client at all so I'll talk to you agn when I
> > > > > need to have some gui control of this. I suppose we can agree that we
> > > > > wont need gpsd if we do it this way ?
> > > > > 
> > > > > Another subject:
> > > > > Dave has improved fldigi dominoex, oh7jjt and I are testing dominoex16
> > > > > on 80 (and 40) meters now. Looks good so far, snr is really bad on 80
> > > > > now but I got some parts anyway (more on that as snr improves).
> > > > > This means I am using fldigi 1.32e and its much slower on psk than it
> > > > > used to be, timing could be a bit off now.
> > > > > 
> > > > > 73 de Per, sm0rwo
> > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > 
> > > -- 
> > > Pär Crusefalk
> > > Turnévägen 5
> > > 14243 Skogås
> > > Tel: +4687717482
> > > Mob: +46768800670
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > 
> 
> 
> 

-- 
http://pa0r.blogspirit.com

Other related posts: