[PR-159] Fix diseqc 1.1 support for use with uncommited switches

This commit is contained in:
Joakim Hernberg 2012-10-08 13:26:06 +02:00 committed by Adam Sutton
parent 977a35375f
commit bfa18f5440
2 changed files with 77 additions and 110 deletions

View file

@ -2,123 +2,103 @@
#include <linux/dvb/frontend.h>
#include <sys/ioctl.h>
//#include "scan.h"
#include "tvheadend.h"
#include "diseqc.h"
//#define DISEQC_TRACE
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 }
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;
int i = (input % 4) * 4 + voltage * 2 + (band ? 1 : 0);
int j = input / 4;
int err;
if ((err = ioctl(fd, FE_SET_TONE, SEC_TONE_OFF)))
return 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;
if ((err = ioctl(fd, FE_SET_VOLTAGE, v)))
return err;
/* turn off continuous tone */
if ((err = ioctl(fe_fd, FE_SET_TONE, SEC_TONE_OFF)))
return err;
msleep(15);
while (*cmd) {
if ((err = ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &(*cmd)->cmd)))
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);
msleep((*cmd)->wait);
cmd++;
}
/* send uncommited command */
if ((err = ioctl(fe_fd, FE_DISEQC_SEND_MASTER_CMD,
&diseqc_uncommited_cmds[j])))
return err;
msleep(15);
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);
if ((err = ioctl(fd, FE_DISEQC_SEND_BURST, b)))
return err;
/* 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);
msleep(15);
return ioctl(fd, FE_SET_TONE, t);
/* set continuous tone */
if ((ioctl(fe_fd, FE_SET_TONE, i % 2 ? SEC_TONE_ON : SEC_TONE_OFF)))
return err;
return 0;
}
int
diseqc_setup(int frontend_fd, int switch_pos, int voltage_18, int hiband,
int diseqc_ver)
int
diseqc_voltage_off(int fe_fd)
{
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 diseqc_voltage_off(int frontend_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);
}

View 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