lnb.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include "lnb.h"
  5. static char *univ_desc[] = {
  6. "Europe",
  7. "10800 to 11800 MHz and 11600 to 12700 Mhz",
  8. "Dual LO, loband 9750, hiband 10600 MHz",
  9. (char *)NULL };
  10. static char *dbs_desc[] = {
  11. "Expressvu, North America",
  12. "12200 to 12700 MHz",
  13. "Single LO, 11250 MHz",
  14. (char *)NULL };
  15. static char *standard_desc[] = {
  16. "10945 to 11450 Mhz",
  17. "Single LO, 10000 Mhz",
  18. (char *)NULL };
  19. static char *enhan_desc[] = {
  20. "Astra",
  21. "10700 to 11700 MHz",
  22. "Single LO, 9750 MHz",
  23. (char *)NULL };
  24. static char *cband_desc[] = {
  25. "Big Dish",
  26. "3700 to 4200 MHz",
  27. "Single LO, 5150 Mhz",
  28. (char *)NULL };
  29. static struct lnb_types_st lnbs[] = {
  30. {"UNIVERSAL", univ_desc, 9750, 10600, 11700 },
  31. {"DBS", dbs_desc, 11250, 0, 0 },
  32. {"STANDARD", standard_desc, 10000, 0, 0 },
  33. {"ENHANCED", enhan_desc, 9750, 0, 0 },
  34. {"C-BAND", cband_desc, 5150, 0, 0 }
  35. };
  36. /* Enumerate through standard types of LNB's until NULL returned.
  37. * Increment curno each time
  38. */
  39. struct lnb_types_st *
  40. lnb_enum(int curno)
  41. {
  42. if (curno >= (int) (sizeof(lnbs) / sizeof(lnbs[0])))
  43. return (struct lnb_types_st *)NULL;
  44. return &lnbs[curno];
  45. }
  46. /* Decode an lnb type, for example given on a command line
  47. * If alpha and standard type, e.g. "Universal" then match that
  48. * otherwise low[,high[,switch]]
  49. */
  50. int
  51. lnb_decode(char *str, struct lnb_types_st *lnbp)
  52. {
  53. int i;
  54. char *cp, *np;
  55. memset(lnbp, 0, sizeof(*lnbp));
  56. cp = str;
  57. while(*cp && isspace(*cp))
  58. cp++;
  59. if (isalpha(*cp)) {
  60. for (i = 0; i < (int)(sizeof(lnbs) / sizeof(lnbs[0])); i++) {
  61. if (!strcasecmp(lnbs[i].name, cp)) {
  62. *lnbp = lnbs[i];
  63. return 1;
  64. }
  65. }
  66. return -1;
  67. }
  68. if (*cp == '\0' || !isdigit(*cp))
  69. return -1;
  70. lnbp->low_val = strtoul(cp, &np, 0);
  71. if (lnbp->low_val == 0)
  72. return -1;
  73. cp = np;
  74. while(*cp && (isspace(*cp) || *cp == ','))
  75. cp++;
  76. if (*cp == '\0')
  77. return 1;
  78. if (!isdigit(*cp))
  79. return -1;
  80. lnbp->high_val = strtoul(cp, &np, 0);
  81. cp = np;
  82. while(*cp && (isspace(*cp) || *cp == ','))
  83. cp++;
  84. if (*cp == '\0')
  85. return 1;
  86. if (!isdigit(*cp))
  87. return -1;
  88. lnbp->switch_val = strtoul(cp, NULL, 0);
  89. return 1;
  90. }