]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
[PR-159] Fix diseqc 1.1 support for use with uncommited switches
authorJoakim Hernberg <jhernberg@alchemy.lu>
Mon, 8 Oct 2012 11:26:06 +0000 (13:26 +0200)
committerAdam Sutton <dev@adamsutton.me.uk>
Tue, 9 Oct 2012 11:01:27 +0000 (12:01 +0100)
src/dvb/diseqc.c
src/dvb/diseqc.h

index 404c423cb4d73d18e7f052d0a80692d60ea4f5d1..f44685880d7ceaab40823ba8712e0a38a4d61106 100644 (file)
 #include <linux/dvb/frontend.h>
 #include <sys/ioctl.h>
 
-//#include "scan.h"
+#include "tvheadend.h"
 #include "diseqc.h"
 
-
-struct diseqc_cmd switch_commited_cmds[] = {
-       { { { 0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf2, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf1, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf3, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf4, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf6, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf5, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf7, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf8, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xfa, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xf9, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xfb, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xfc, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xfe, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xfd, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x38, 0xff, 0x00, 0x00 }, 4 }, 0 }
+//#define DISEQC_TRACE
+
+struct dvb_diseqc_master_cmd diseqc_commited_cmds[] = {
+  { { 0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf1, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf2, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf3, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf4, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf5, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf6, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf7, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf8, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xf9, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xfa, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xfb, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xfc, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xfd, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xfe, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x38, 0xff, 0x00, 0x00 }, 4 }
 };
 
-struct diseqc_cmd switch_uncommited_cmds[] = {
-       { { { 0xe0, 0x10, 0x39, 0xf0, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf1, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf2, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf3, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf4, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf5, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf6, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf7, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf8, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xf9, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xfa, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xfb, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xfc, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xfd, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xfe, 0x00, 0x00 }, 4 }, 0 },
-       { { { 0xe0, 0x10, 0x39, 0xff, 0x00, 0x00 }, 4 }, 0 }
+struct dvb_diseqc_master_cmd diseqc_uncommited_cmds[] = {
+  { { 0xe0, 0x10, 0x39, 0xf0, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x39, 0xf1, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x39, 0xf2, 0x00, 0x00 }, 4 },
+  { { 0xe0, 0x10, 0x39, 0xf3, 0x00, 0x00 }, 4 }
 };
 
-
 /*--------------------------------------------------------------------------*/
 
-static inline
-void msleep(uint32_t msec)
+static inline void
+msleep(uint32_t msec)
 {
-       struct timespec req = { msec / 1000, 1000000 * (msec % 1000) };
+  struct timespec req = { msec / 1000, 1000000 * (msec % 1000) };
 
-       while (nanosleep(&req, &req))
-               ;
+  while (nanosleep(&req, &req))
+    ;
 }
 
-int diseqc_send_msg (int fd, fe_sec_voltage_t v, struct diseqc_cmd **cmd,
-                    fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
+int
+diseqc_setup(int fe_fd, int input, int voltage, int band, int diseqc_ver)
 {
-       int err;
-
-       if ((err = ioctl(fd, FE_SET_TONE, SEC_TONE_OFF)))
-               return err;
-
-       if ((err = ioctl(fd, FE_SET_VOLTAGE, v)))
-               return err;
-
-       msleep(15);
-       while (*cmd) {
-               if ((err = ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &(*cmd)->cmd)))
-                       return err;
-
-               msleep((*cmd)->wait);
-               cmd++;
-       }
-
-       msleep(15);
-
-       if ((err = ioctl(fd, FE_DISEQC_SEND_BURST, b)))
-               return err;
-
-       msleep(15);
-
-       return ioctl(fd, FE_SET_TONE, t);
-}
-
-
-int 
-diseqc_setup(int frontend_fd, int switch_pos, int voltage_18, int hiband,
-            int diseqc_ver)
-{
-       struct diseqc_cmd *cmd[2] = { NULL, NULL };
-       int i = 4 * switch_pos + 2 * hiband + (voltage_18 ? 1 : 0);
-       
-       if (diseqc_ver == 1) {
-               if(switch_pos < 0 || switch_pos >= (int) (sizeof(switch_uncommited_cmds)/sizeof(struct diseqc_cmd)))
-                       return -1;
-               cmd[0] = &switch_uncommited_cmds[switch_pos];
-       } else {
-               if(i < 0 || i >= (int) (sizeof(switch_commited_cmds)/sizeof(struct diseqc_cmd)))
-                       return -1;
-               cmd[0] = &switch_commited_cmds[i];
-       }
-
-       return diseqc_send_msg (frontend_fd,
-                               i % 2 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
-                               cmd,
-                               (i/2) % 2 ? SEC_TONE_ON : SEC_TONE_OFF,
-                               (i/4) % 2 ? SEC_MINI_B : SEC_MINI_A);
+  int i = (input % 4) * 4 + voltage * 2 + (band ? 1 : 0);
+  int j = input / 4;
+  int err;
+
+#ifdef DISEQC_TRACE
+  tvhlog(LOG_INFO, "diseqc",
+        "fe_fd %i, input %i, voltage %i, band %i, diseqc_ver %i, i %i, j %i",
+        fe_fd, input, voltage, band, diseqc_ver, i, j);
+#endif
+  /* check for invalid input number or diseqc command indexes */
+  if(input < 0 || input >=16 || i < 0 || i >= 16 || j < 0 || j >= 4)
+    return -1;
+
+  /* turn off continuous tone */
+  if ((err = ioctl(fe_fd, FE_SET_TONE, SEC_TONE_OFF)))
+    return err;
+
+  /* set lnb voltage */
+  if ((err = ioctl(fe_fd, FE_SET_VOLTAGE,
+                    (i/2) % 2 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13)))
+    return err;
+  msleep(15);
+
+  /* send uncommited command */
+  if ((err = ioctl(fe_fd, FE_DISEQC_SEND_MASTER_CMD,
+                    &diseqc_uncommited_cmds[j])))
+    return err;
+  msleep(15);
+
+  /* send commited command */
+  if ((err = ioctl(fe_fd, FE_DISEQC_SEND_MASTER_CMD,
+                    &diseqc_commited_cmds[i])))
+    return err;
+#ifdef DISEQC_TRACE
+  tvhlog(LOG_INFO, "diseqc", "E0 10 39 F%X - E0 10 38 F%X sent", j, i);
+#endif
+  msleep(15);
+
+  /* send toneburst command */
+  if ((err = ioctl(fe_fd, FE_DISEQC_SEND_BURST,
+                    (i/4) % 2 ? SEC_MINI_B : SEC_MINI_A)))
+    return err;
+  msleep(15);
+
+  /* set continuous tone */
+  if ((ioctl(fe_fd, FE_SET_TONE, i % 2 ? SEC_TONE_ON : SEC_TONE_OFF)))
+    return err;
+  return 0;
 }
 
-
-int diseqc_voltage_off(int frontend_fd)
+int
+diseqc_voltage_off(int fe_fd)
 {
-        fe_sec_voltage_t v = SEC_VOLTAGE_OFF;
-        int err;
-
-       if ((err = ioctl(frontend_fd, FE_SET_VOLTAGE, v)))
-               return err;
-
-        return 0;
+  return ioctl(fe_fd, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF);
 }
index 5daeb88dbe3d419d12feb788704c888d32a0ef39..fdabb6df50460f5ac237d610798c771026b0c5da 100644 (file)
@@ -4,23 +4,10 @@
 #include <stdint.h>
 #include <linux/dvb/frontend.h>
 
-
-struct diseqc_cmd {
-       struct dvb_diseqc_master_cmd cmd;
-       uint32_t wait;
-};
-
-
-extern int diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd **cmd,
-                          fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b);
-
-
 /**
  *   set up the switch to position/voltage/tone
  */
-int diseqc_setup(int frontend_fd, int switch_pos, int voltage_18, int hiband,
-                int diseqc_ver);
-
-int diseqc_voltage_off(int frontend_fd);
+int diseqc_setup(int fe_fd, int input, int voltage, int band, int diseqc_ver);
+int diseqc_voltage_off(int fe_fd);
 
 #endif