forked from patrikf/dvbdescramble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diseqc.c
92 lines (80 loc) · 2.54 KB
/
diseqc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* (C) 2008-2009 Patrik Fimml.
*
* This file is part of dvbdescramble.
*
* dvbdescramble is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "diseqc.h"
#include <sys/ioctl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
static bool
do_burst(int fd, secBurst burst)
{
if (burst == BURST_NONE)
return false;
if (ioctl(fd, FE_DISEQC_SEND_BURST, (burst == BURST_A ? SEC_MINI_A : SEC_MINI_B)) == -1)
perror("do_burst: SEND_BURST failed");
return true;
}
/*
* Send a raw DiSEqC command.
*
* cmd and burst (if specified) will be sent and voltage/tone will be switched
* in compliance with the Eutelsat DiSEqC specification.
*/
void
diseqc_raw(int fd,
struct dvb_diseqc_master_cmd *cmd,
secStatus status,
secBurst burst)
{
// Tone OFF
if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
perror("diseqc_raw: failed to switch off tone");
// Switch Voltage
if (ioctl(fd, FE_SET_VOLTAGE, status.voltage) == -1)
perror("diseqc_raw: failed to switch voltage");
usleep(15 * 1000);
// DiSEqC message
if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, cmd) == -1)
perror("diseqc_raw: sending DiSEqC command failed");
// TODO: wait for DiSEqC response here (if requested)
usleep(15 * 1000);
// Burst, if any, comes here
if (do_burst(fd, burst))
usleep(15 * 1000);
// Switch tone to specified state
if (ioctl(fd, FE_SET_TONE, status.tone) == -1)
perror("diseqc_raw: failed to switch tone");
}
void
diseqc_lnb(int fd,
char *command, /* 1..4 */
uint8_t datalen, /* 0..3 */
secStatus status, /* after DiSEqC command */
secBurst burst)
{
struct dvb_diseqc_master_cmd cmd;
memset(cmd.msg, 0, 6);
cmd.msg[0] = DISEQC_MAGIC | DISEQC_MASTER;
cmd.msg[1] = 0x10;
memcpy(cmd.msg+2, command, datalen+1);
cmd.msg_len = datalen+3;
diseqc_raw(fd, &cmd, status, burst);
}