]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
linuxdvb rotor: add ROTOR_TEST code
authorJaroslav Kysela <perex@perex.cz>
Tue, 16 Dec 2014 07:55:10 +0000 (08:55 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 16 Dec 2014 07:55:10 +0000 (08:55 +0100)
src/input/mpegts/linuxdvb/linuxdvb_rotor.c

index 92794b1f244771d64f358c2afdaf2213fc28456a..68583ba2c0b3db45a113175b8df8e0354dd053f3 100644 (file)
@@ -17,6 +17,7 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifndef ROTOR_TEST
 #include "tvheadend.h"
 #include "linuxdvb_private.h"
 #include "settings.h"
 #include <math.h>
 #include <linux/dvb/frontend.h>
 
+#else /* ROTOR_TEST */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <math.h>
+
+typedef struct {
+  double   ls_site_lat;
+  double   ls_site_lon;
+  double   ls_site_altitude;
+  int      ls_site_lat_south;
+  int      ls_site_lon_west;
+} linuxdvb_satconf_t;
+
+typedef struct {
+  linuxdvb_satconf_t *lse_parent;
+} linuxdvb_satconf_ele_t;
+
+double gazimuth, gelevation;
+
+#endif
+
 /* **************************************************************************
  * Class definition
  * *************************************************************************/
 
 typedef struct linuxdvb_rotor
 {
+#ifndef ROTOR_TEST
   linuxdvb_diseqc_t;
+#endif
 
   double    lr_sat_lon;
   uint32_t  lr_position;
 
 } linuxdvb_rotor_t;
 
+#ifndef ROTOR_TEST
+
 static const char *
 linuxdvb_rotor_class_get_title ( idnode_t *o )
 {
@@ -100,6 +129,8 @@ const idclass_t linuxdvb_rotor_usals_class =
   }
 };
 
+#endif /* ROTOR_TEST */
+
 /*
  *
  */
@@ -201,10 +232,20 @@ sat_angle( linuxdvb_rotor_t *lr, linuxdvb_satconf_ele_t *ls )
 
   double azimuth, elevation;
 
+#ifndef ROTOR_TEST
+  tvhtrace("diseqc", "site: lat %.4f, lon %.4f, alt %.4f; sat lon %.4f",
+                     site_lat, site_lon, site_alt, sat_lon);
+#endif
+
   sat_azimuth_and_elevation(site_lat, site_lon, site_alt, sat_lon,
                             &azimuth, &elevation);
 
+#ifndef ROTOR_TEST
   tvhtrace("diseqc", "rotor angle azimuth %.4f elevation %.4f", azimuth, elevation);
+#else
+  gazimuth = azimuth;
+  gelevation = elevation;
+#endif
 
   double rad_azimuth   = to_radians(azimuth);
   double rad_elevation = to_radians(elevation);
@@ -241,6 +282,8 @@ sat_angle( linuxdvb_rotor_t *lr, linuxdvb_satconf_ele_t *ls )
   return ret;
 }
 
+#ifndef ROTOR_TEST
+
 /* **************************************************************************
  * Class methods
  * *************************************************************************/
@@ -445,6 +488,46 @@ linuxdvb_rotor_destroy ( linuxdvb_diseqc_t *lr )
   free(lr);
 }
 
+#else /* ROTOR_TEST */
+
+int main(int argc, char *argv[])
+{
+  if (argc < 5) {
+    fprintf(stderr, "Usage: <site_latitude> <site_lontitude> <site_altitude> <sat_longtitude>\n");
+    return 1;
+  }
+  linuxdvb_rotor_t lr;
+  linuxdvb_satconf_t ls;
+  linuxdvb_satconf_ele_t lse;
+  int angle;
+
+  memset(&lr, 0, sizeof(lr));
+  memset(&ls, 0, sizeof(ls));
+  memset(&lse, 0, sizeof(lse));
+
+  lse.lse_parent = &ls;
+
+  ls.ls_site_lat = atof(argv[1]);
+  ls.ls_site_lon = atof(argv[2]);
+  ls.ls_site_altitude = atof(argv[3]);
+  lr.lr_sat_lon  = atof(argv[4]);
+
+  angle = sat_angle(&lr, &lse);
+
+  printf("Input values:\n");
+  printf("  %20s: %.4f\n", "Site Latidude", ls.ls_site_lat);
+  printf("  %20s: %.4f\n", "Site Longtitude", ls.ls_site_lon);
+  printf("  %20s: %.4f\n", "Site Altitude", ls.ls_site_altitude);
+  printf("  %20s: %.4f\n", "Satellite Longtitude", lr.lr_sat_lon);
+  printf("\nResult:\n");
+  printf("  %20s: %.4f\n", "Azimuth", gazimuth);
+  printf("  %20s: %.4f\n", "Elevation", gelevation);
+  printf("  %20s: %.1f %sclockwise\n", "Angle", (double)abs(angle) / 10.0, angle < 0 ? "counter-" : "");
+  return 0;
+}
+
+#endif
+
 /******************************************************************************
  * Editor Configuration
  *