gotox.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (C) 2006 by Michel Verbraak <michel@verbraak.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the
  16. * Free Software Foundation, Inc.,
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <unistd.h>
  25. #include <libdvbapi/dvbfe.h>
  26. #include <libdvbsec/dvbsec_api.h>
  27. static char *usage_str =
  28. "\nusage: gotox [options] -d <angle>\n"
  29. " Goto the specified angle. Positive value for East rotation\n"
  30. " Negative value for West rotation on Northern Hemisphere.\n"
  31. " -d degrees : Angle to turn to in degrees (default 0)\n"
  32. " -a number : use given adapter (default 0)\n"
  33. " -f number : use given frontend (default 0)\n"
  34. " -t seconds : leave power on to rotor for at least specified seconds of time (default 30)\n\n";
  35. int main(int argc, char *argv[])
  36. {
  37. struct dvbfe_handle *fe;
  38. unsigned int adapter = 0, frontend = 0;
  39. double angle = 0;
  40. int opt;
  41. unsigned int sleepcount = 30;
  42. static char *weststr = "west";
  43. static char *eaststr = "east";
  44. while ((opt = getopt(argc, argv, "ha:f:t:d:")) != -1) {
  45. switch (opt){
  46. case '?':
  47. case 'h':
  48. default:
  49. fprintf(stderr, "%s", usage_str);
  50. return EXIT_SUCCESS;
  51. case 'a':
  52. adapter = strtoul(optarg, NULL, 0);
  53. break;
  54. case 'f':
  55. frontend = strtoul(optarg, NULL, 0);
  56. break;
  57. case 't':
  58. sleepcount = strtoul(optarg, NULL, 0);
  59. break;
  60. case 'd':
  61. angle = strtod(optarg, NULL);
  62. break;
  63. }
  64. }
  65. printf("Will try to rotate %s to %.2f degrees.\n", (angle < 0.0) ? weststr : eaststr, angle );
  66. fe = dvbfe_open(adapter, frontend, 0);
  67. if (fe == NULL) {
  68. fprintf(stderr, "Could not open frontend %d on adapter %d.\n", frontend, adapter);
  69. exit(1);
  70. }
  71. if (dvbfe_set_voltage(fe, DVBFE_SEC_VOLTAGE_OFF) != 0) {
  72. fprintf(stderr, "Could not turn off power.\n");
  73. dvbfe_close(fe);
  74. return 1;
  75. }
  76. else
  77. printf("Power OFF.\n");
  78. sleep(1);
  79. if (dvbfe_set_voltage(fe, DVBFE_SEC_VOLTAGE_18) != 0) {
  80. fprintf(stderr, "Could not turn on power.\n");
  81. dvbfe_close(fe);
  82. return 1;
  83. }
  84. else
  85. printf("Power on to 18V.\n");
  86. sleep(1);
  87. if (abs(angle) == 0.0) {
  88. if (dvbsec_diseqc_goto_satpos_preset(fe, DISEQC_ADDRESS_POLAR_AZIMUTH_POSITIONER, 0) != 0) {
  89. fprintf(stderr, "Could not goto 0.\n");
  90. dvbfe_close(fe);
  91. return 2;
  92. } else {
  93. printf("Going to home base 0 degrees.\n");
  94. }
  95. } else {
  96. if (dvbsec_diseqc_goto_rotator_bearing(fe, DISEQC_ADDRESS_POLAR_AZIMUTH_POSITIONER, angle) != 0) {
  97. fprintf(stderr, "Could not rotate.\n");
  98. dvbfe_close(fe);
  99. return 2;
  100. }
  101. }
  102. while (sleepcount != 0) {
  103. printf("%d: Rotating to %.2f.\r", sleepcount, angle);
  104. fflush(NULL);
  105. sleepcount--;
  106. sleep(1);
  107. }
  108. printf("\nRotated.\n");
  109. if (dvbfe_set_voltage(fe, DVBFE_SEC_VOLTAGE_OFF) != 0) {
  110. fprintf(stderr, "Could not turn off power.\n");
  111. dvbfe_close(fe);
  112. return 1;
  113. }
  114. else
  115. printf("Power OFF.\n");
  116. sleep(1);
  117. dvbfe_close(fe);
  118. return EXIT_SUCCESS;
  119. }