pgps.cgi 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use CGI qw{};
  5. use CGI::Carp qw(fatalsToBrowser);
  6. use Net::GPSD3 0.14;
  7. =head1 NAME
  8. pgps.cgi - Builds a Satellite List and displays GPS data from a POLL request to a GPSD server
  9. =head1 COPYRIGHT
  10. Copyright 2011 - Michael R. Davis
  11. This file is Copyright 2011 by the GPSD project
  12. SPDX-License-Identifier: BSD-2-clause
  13. This program is free software licensed under The BSD License.
  14. =cut
  15. my $cgi=CGI->new;
  16. my $host=$cgi->param("host") || undef;
  17. my $port=$cgi->param("port") || undef;
  18. my $gpsd=Net::GPSD3->new(host=>$host, port=>$port);
  19. my $poll=$gpsd->poll;
  20. my @param=();
  21. push @param, "host=".$host if defined $host;
  22. push @param, "port=".$port if defined $port;
  23. my $img=join("?", "skyview.cgi", scalar(@param) ? join(";", @param) : ());
  24. my $content=join "",
  25. $cgi->start_html(-title=>"Perl GPSD CGI"),
  26. $cgi->table({border=>0, width=>"100%", style=>"BORDER-COLLAPSE: collapse"},
  27. $cgi->Tr(
  28. $cgi->td({width=>"30%", valign=>"top"},"Satellite List",
  29. $cgi->table({border=>2, width=>"100%", style=>"BORDER-COLLAPSE: collapse"},
  30. $cgi->Tr(
  31. $cgi->td([qw{PRN Elev Azim SNR Used}]),
  32. ),
  33. map {
  34. $cgi->Tr([
  35. $cgi->td([$_->prn, $_->el, $_->az, $_->ss, $_->used ? "Y" : "N"])])
  36. } sort {$b->used <=> $a->used or $b->ss <=> $a->ss} $poll->sky->Satellites
  37. ),
  38. ),
  39. $cgi->td({valign=>"top"}, "Skyview",
  40. $cgi->table({border=>2, style=>"BORDER-COLLAPSE: collapse"},
  41. $cgi->Tr(
  42. $cgi->td(
  43. $cgi->img({-src=>$img}),
  44. ),
  45. ),
  46. ),
  47. ),
  48. ),
  49. $cgi->Tr(
  50. $cgi->td({-colspan=>2, valign=>"top"}, "GPS data",
  51. $cgi->table({border=>2, width=>"100%", style=>"BORDER-COLLAPSE: collapse"},
  52. $cgi->Tr(
  53. $cgi->td({align=>"right", width=>"25%"}, "Time:"),
  54. $cgi->td({width=>"25%"}, $poll->tpv->timestamp),
  55. $cgi->td({align=>"right", width=>"25%"}, "Status:"),
  56. $cgi->td({width=>"25%"}, $poll->tpv->mode),
  57. ),
  58. $cgi->Tr(
  59. $cgi->td({align=>"right"}, "Latitude:"),
  60. $cgi->td($poll->tpv->lat),
  61. $cgi->td({align=>"right"}, "EPX:"),
  62. $cgi->td($poll->tpv->epx),
  63. ),
  64. $cgi->Tr(
  65. $cgi->td({align=>"right"}, "Longitude:"),
  66. $cgi->td($poll->tpv->lon),
  67. $cgi->td({align=>"right"}, "EPY:"),
  68. $cgi->td($poll->tpv->epy),
  69. ),
  70. $cgi->Tr(
  71. $cgi->td({align=>"right"}, "Altitude:"),
  72. $cgi->td($poll->tpv->alt),
  73. $cgi->td({align=>"right"}, "EPV:"),
  74. $cgi->td($poll->tpv->epv),
  75. ),
  76. $cgi->Tr(
  77. $cgi->td({align=>"right"}, "Speed:"),
  78. $cgi->td($poll->tpv->speed),
  79. $cgi->td({align=>"right"}, "EPS:"),
  80. $cgi->td($poll->tpv->eps),
  81. ),
  82. $cgi->Tr(
  83. $cgi->td({align=>"right"}, "Climb:"),
  84. $cgi->td($poll->tpv->climb),
  85. $cgi->td({align=>"right"}, "EPC:"),
  86. $cgi->td($poll->tpv->epc),
  87. ),
  88. $cgi->Tr(
  89. $cgi->td({align=>"right"}, "Track:"),
  90. $cgi->td($poll->tpv->track),
  91. $cgi->td({align=>"right"}, "EPD:"),
  92. $cgi->td($poll->tpv->epd),
  93. ),
  94. ),
  95. ),
  96. ),
  97. ),
  98. $cgi->p({align=>"center"}, "Copyright &copy; 2011 - Michael R. Davis, License: BSD"),
  99. $cgi->end_html, "\n";
  100. print join "",
  101. $cgi->header(
  102. -content_length => length($content),
  103. -expires => '+5m',
  104. -Refresh => '30', #seconds
  105. ),
  106. $content;