2
* Copyright (C) 2007 Michael Lamothe
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Library General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
19
#include "dvb_tuner.h"
22
DvbTuner::DvbTuner(const Glib::ustring& tuner_device_path)
26
if ( ( fd = open ( tuner_device_path.c_str(), O_RDWR | O_NONBLOCK ) ) < 0 )
28
throw SystemException("Failed to open tuner");
31
if ( ioctl ( fd, FE_GET_INFO, &frontend_info ) < 0 )
33
throw SystemException("Failed to get tuner info");
45
void DvbTuner::tune_to (Transponder& transponder)
47
struct dvb_frontend_event ev;
49
if (frontend_info.type == FE_QPSK)
54
// Discard stale events
55
while (ioctl(fd, FE_GET_EVENT, &ev) != -1);
57
if ( ioctl ( fd, FE_SET_FRONTEND, &(transponder.frontend_parameters) ) < 0 )
59
throw SystemException("Failed to tune device");
62
Log::write("Waiting for signal lock ...");
64
Log::write("Got signal lock");
67
void DvbTuner::diseqc(const Transponder& transponder)
69
int satellite_number = transponder.satellite_number;
70
int polarisation = transponder.polarisation;
71
int hi_band = transponder.hi_band;
73
struct dvb_diseqc_master_cmd cmd = { {0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4};
74
cmd.msg[3] = 0xf0 | (((satellite_number * 4) & 0x0f) | (hi_band ? 1 : 0) | (polarisation ? 0 : 2));
76
fe_sec_voltage_t voltage = polarisation ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18;
77
fe_sec_tone_mode_t tone = hi_band ? SEC_TONE_ON : SEC_TONE_OFF;
78
fe_sec_mini_cmd_t burst = (satellite_number / 4) % 2 ? SEC_MINI_B : SEC_MINI_A;
80
if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
82
throw SystemException("Failed to set tone off");
85
if (ioctl(fd, FE_SET_VOLTAGE, voltage) == -1)
87
throw SystemException("Failed to set voltage");
91
if (ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd) == -1)
93
throw SystemException("Failed to send master command");
97
if (ioctl(fd, FE_DISEQC_SEND_BURST, burst) == -1)
99
throw SystemException("Failed to send burst");
103
if (ioctl(fd, FE_SET_TONE, tone) == -1)
105
throw SystemException("Failed to set tone");
109
void DvbTuner::wait_lock()
112
time_t start_time = time(NULL);
114
while ((start_time + 10) > time(NULL))
116
if (!ioctl(fd, FE_READ_STATUS, &status))
118
if (status & FE_HAS_LOCK)
127
if (!(status & FE_HAS_LOCK))
129
throw Exception("Failed to lock to channel");