diseqc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #define USAGE \
  2. "\n" \
  3. "\nTest sending DiSEqC commands on a SAT frontend." \
  4. "\n" \
  5. "\nusage: FRONTEND=/dev/dvb/adapterX/frontendX diseqc [test_seq_no|'all']" \
  6. "\n"
  7. #include <pthread.h>
  8. #include <time.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <stdint.h>
  12. #include <stdio.h>
  13. #include <unistd.h>
  14. #include <sys/ioctl.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <fcntl.h>
  18. #include <linux/dvb/frontend.h>
  19. struct diseqc_cmd {
  20. struct dvb_diseqc_master_cmd cmd;
  21. uint32_t wait;
  22. };
  23. struct diseqc_cmd switch_cmds[] = {
  24. { { { 0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00 }, 4 }, 0 },
  25. { { { 0xe0, 0x10, 0x38, 0xf2, 0x00, 0x00 }, 4 }, 0 },
  26. { { { 0xe0, 0x10, 0x38, 0xf1, 0x00, 0x00 }, 4 }, 0 },
  27. { { { 0xe0, 0x10, 0x38, 0xf3, 0x00, 0x00 }, 4 }, 0 },
  28. { { { 0xe0, 0x10, 0x38, 0xf4, 0x00, 0x00 }, 4 }, 0 },
  29. { { { 0xe0, 0x10, 0x38, 0xf6, 0x00, 0x00 }, 4 }, 0 },
  30. { { { 0xe0, 0x10, 0x38, 0xf5, 0x00, 0x00 }, 4 }, 0 },
  31. { { { 0xe0, 0x10, 0x38, 0xf7, 0x00, 0x00 }, 4 }, 0 },
  32. { { { 0xe0, 0x10, 0x38, 0xf8, 0x00, 0x00 }, 4 }, 0 },
  33. { { { 0xe0, 0x10, 0x38, 0xfa, 0x00, 0x00 }, 4 }, 0 },
  34. { { { 0xe0, 0x10, 0x38, 0xf9, 0x00, 0x00 }, 4 }, 0 },
  35. { { { 0xe0, 0x10, 0x38, 0xfb, 0x00, 0x00 }, 4 }, 0 },
  36. { { { 0xe0, 0x10, 0x38, 0xfc, 0x00, 0x00 }, 4 }, 0 },
  37. { { { 0xe0, 0x10, 0x38, 0xfe, 0x00, 0x00 }, 4 }, 0 },
  38. { { { 0xe0, 0x10, 0x38, 0xfd, 0x00, 0x00 }, 4 }, 0 },
  39. { { { 0xe0, 0x10, 0x38, 0xff, 0x00, 0x00 }, 4 }, 0 }
  40. };
  41. /*--------------------------------------------------------------------------*/
  42. static inline
  43. void msleep(uint32_t msec)
  44. {
  45. struct timespec req = { msec / 1000, 1000000 * (msec % 1000) };
  46. while (nanosleep(&req, &req))
  47. ;
  48. }
  49. static
  50. void diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd **cmd,
  51. fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
  52. {
  53. ioctl(fd, FE_SET_TONE, SEC_TONE_OFF);
  54. ioctl(fd, FE_SET_VOLTAGE, v);
  55. msleep(15);
  56. while (*cmd) {
  57. printf("msg: %02x %02x %02x %02x %02x %02x\n",
  58. (*cmd)->cmd.msg[0], (*cmd)->cmd.msg[1],
  59. (*cmd)->cmd.msg[2], (*cmd)->cmd.msg[3],
  60. (*cmd)->cmd.msg[4], (*cmd)->cmd.msg[5]);
  61. ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &(*cmd)->cmd);
  62. msleep((*cmd)->wait);
  63. cmd++;
  64. }
  65. printf("%s: ", __FUNCTION__);
  66. printf(" %s ", v == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
  67. v == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "???");
  68. printf(" %s ", b == SEC_MINI_A ? "SEC_MINI_A" :
  69. b == SEC_MINI_B ? "SEC_MINI_B" : "???");
  70. printf(" %s\n", t == SEC_TONE_ON ? "SEC_TONE_ON" :
  71. t == SEC_TONE_OFF ? "SEC_TONE_OFF" : "???");
  72. msleep(15);
  73. ioctl(fd, FE_DISEQC_SEND_BURST, b);
  74. msleep(15);
  75. ioctl(fd, FE_SET_TONE, t);
  76. }
  77. int main(int argc, char **argv)
  78. {
  79. struct diseqc_cmd *cmd[2] = { NULL, NULL };
  80. char *fedev = "/dev/dvb/adapter0/frontend0";
  81. int fd;
  82. if (getenv("FRONTEND"))
  83. fedev = getenv("FRONTEND");
  84. printf("diseqc test: using '%s'\n", fedev);
  85. if ((fd = open(fedev, O_RDWR)) < 0) {
  86. perror("open");
  87. return -1;
  88. }
  89. if (argc != 2) {
  90. fprintf (stderr, "usage: %s [number|'all']\n" USAGE, argv[0]);
  91. return 1;
  92. } else if (strcmp(argv[1], "all")) {
  93. int i = atol(argv[1]);
  94. cmd[0] = &switch_cmds[i];
  95. diseqc_send_msg(fd,
  96. i % 2 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
  97. cmd,
  98. (i/2) % 2 ? SEC_TONE_ON : SEC_TONE_OFF,
  99. (i/4) % 2 ? SEC_MINI_B : SEC_MINI_A);
  100. } else {
  101. unsigned int j;
  102. for (j=0; j<sizeof(switch_cmds)/sizeof(struct diseqc_cmd); j++)
  103. {
  104. cmd[0] = &switch_cmds[j];
  105. diseqc_send_msg(fd,
  106. j % 2 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
  107. cmd,
  108. (j/2) % 2 ? SEC_TONE_ON : SEC_TONE_OFF,
  109. (j/4) % 2 ? SEC_MINI_B : SEC_MINI_A);
  110. msleep (1000);
  111. }
  112. }
  113. close(fd);
  114. return 0;
  115. }