mirror of
https://github.com/danog/libdvb.git
synced 2024-12-02 09:17:54 +01:00
tune: cleaning
This commit is contained in:
parent
5e0cc9ebed
commit
d628a4643a
157
src/tune.rs
157
src/tune.rs
@ -42,7 +42,6 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy)]
|
|
||||||
pub struct dvb_frontend_info {
|
pub struct dvb_frontend_info {
|
||||||
pub name: [libc::c_char; 128],
|
pub name: [libc::c_char; 128],
|
||||||
pub fe_type: i32, /* DEPRECATED. Use DTV_ENUM_DELSYS instead */
|
pub fe_type: i32, /* DEPRECATED. Use DTV_ENUM_DELSYS instead */
|
||||||
@ -75,6 +74,40 @@ impl fmt::Debug for dvb_frontend_info {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe fn get_dvb_frontend_info(fd: RawFd) -> io::Result<dvb_frontend_info> {
|
||||||
|
let mut feinfo: dvb_frontend_info = mem::zeroed();
|
||||||
|
let x = libc::ioctl(fd, FE_GET_INFO, &mut feinfo as *mut dvb_frontend_info as *mut libc::c_void);
|
||||||
|
if x == -1 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(feinfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adapter
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Adapter {
|
||||||
|
/// Adapter number /dev/dvb/adapterX
|
||||||
|
pub adapter: usize,
|
||||||
|
/// Device number /dev/dvb/adapterX/frontendX
|
||||||
|
pub device: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Adapter {
|
||||||
|
pub fn open(&self) -> io::Result<RawFd> {
|
||||||
|
let path = format!("/dev/dvb/adapter{}/frontend{}", self.adapter, self.device);
|
||||||
|
let fd = unsafe {
|
||||||
|
libc::open(path.as_ptr() as *const i8, libc::O_NONBLOCK | libc::O_RDWR)
|
||||||
|
};
|
||||||
|
|
||||||
|
if fd == -1 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(fd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Modulation
|
/// Modulation
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -96,10 +129,6 @@ pub enum Modulation {
|
|||||||
DQPSK,
|
DQPSK,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Modulation {
|
|
||||||
fn default() -> Modulation { Modulation::AUTO }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// FEC - Forward Error Correction
|
/// FEC - Forward Error Correction
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -118,10 +147,6 @@ pub enum Fec {
|
|||||||
FEC_9_10,
|
FEC_9_10,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Fec {
|
|
||||||
fn default() -> Fec { Fec::AUTO }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// DVB-S/S2 Transponder polarization
|
/// DVB-S/S2 Transponder polarization
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Polarization {
|
pub enum Polarization {
|
||||||
@ -133,19 +158,15 @@ pub enum Polarization {
|
|||||||
OFF,
|
OFF,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Polarization {
|
|
||||||
fn default() -> Polarization { Polarization::OFF }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// DVB-S/S2 Unicable options
|
/// DVB-S/S2 Unicable options
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Unicable10 {
|
pub struct Unicable10 {
|
||||||
/// Slot range from 1 to 8
|
/// Slot range from 1 to 8
|
||||||
slot: usize,
|
pub slot: usize,
|
||||||
/// Frequency range from 950 to 2150 MHz
|
/// Frequency range from 950 to 2150 MHz
|
||||||
frequency: usize,
|
pub frequency: usize,
|
||||||
/// Position range from 1 to 2
|
/// Position range from 1 to 2
|
||||||
position: usize,
|
pub position: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DVB-S/S2 LNB mode
|
/// DVB-S/S2 LNB mode
|
||||||
@ -168,10 +189,6 @@ pub enum LnbMode {
|
|||||||
OFF,
|
OFF,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for LnbMode {
|
|
||||||
fn default() -> LnbMode { LnbMode::AUTO }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// DVB-S2 Roll-off
|
/// DVB-S2 Roll-off
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -182,107 +199,83 @@ pub enum Rof {
|
|||||||
ROF_35,
|
ROF_35,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Rof {
|
|
||||||
fn default() -> Rof { Rof::ROF_35 }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// DVB-S/S2 Transponder
|
/// DVB-S/S2 Transponder
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Transponder {
|
pub struct Transponder {
|
||||||
/// Frequency
|
/// Frequency
|
||||||
frequency: usize,
|
pub frequency: usize,
|
||||||
/// Polarization
|
/// Polarization
|
||||||
polarization: Polarization,
|
pub polarization: Polarization,
|
||||||
/// Symbol-rate
|
/// Symbol-rate
|
||||||
symbol_rate: usize,
|
pub symbolrate: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DVB-S/S2 LNB
|
/// DVB-S/S2 LNB
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Lnb {
|
pub struct Lnb {
|
||||||
/// Mode
|
/// Mode
|
||||||
lnb: LnbMode,
|
pub mode: LnbMode,
|
||||||
/// Low band frequency
|
/// Low band frequency
|
||||||
lof1: usize,
|
pub lof1: usize,
|
||||||
/// High band frequency
|
/// High band frequency
|
||||||
lof2: usize,
|
pub lof2: usize,
|
||||||
/// Threshold frequency - threshold between low and high band
|
/// Threshold frequency - threshold between low and high band
|
||||||
slof: usize,
|
pub slof: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DVB-S Options
|
/// DVB-S Options
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DvbS {
|
pub struct DvbS {
|
||||||
transponder: Transponder,
|
pub adapter: Adapter,
|
||||||
lnb: Lnb,
|
pub transponder: Transponder,
|
||||||
modulation: Modulation,
|
pub lnb: Lnb,
|
||||||
fec: Fec,
|
pub modulation: Modulation,
|
||||||
|
pub fec: Fec,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DVB-S2 Options
|
/// DVB-S2 Options
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DvbS2 {
|
pub struct DvbS2 {
|
||||||
transponder: Transponder,
|
pub adapter: Adapter,
|
||||||
lnb: Lnb,
|
pub transponder: Transponder,
|
||||||
modulation: Modulation,
|
pub lnb: Lnb,
|
||||||
fec: Fec,
|
pub modulation: Modulation,
|
||||||
rof: Rof,
|
pub fec: Fec,
|
||||||
|
pub rof: Rof,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DVB Delivery system
|
/// DVB Delivery system
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DvbSystem {
|
pub enum DvbOptions {
|
||||||
NONE,
|
|
||||||
DVB_S(DvbS),
|
|
||||||
DVB_S2(DvbS2),
|
DVB_S2(DvbS2),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DVB Options
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct DvbOptions {
|
|
||||||
/// Adapter number /dev/dvb/adapterX
|
|
||||||
adapter: usize,
|
|
||||||
/// Device number /dev/dvb/adapterX/frontendX
|
|
||||||
device: usize,
|
|
||||||
/// Delivery system
|
|
||||||
system: DvbSystem,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DvbTune {
|
pub struct DvbTune {
|
||||||
fd: RawFd,
|
fd: RawFd,
|
||||||
|
feinfo: dvb_frontend_info,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DvbTune {
|
impl DvbTune {
|
||||||
pub fn new(adapter: usize, device: usize) -> io::Result<DvbTune> {
|
pub fn new(options: &DvbOptions) -> io::Result<DvbTune> {
|
||||||
let path = format!("/dev/dvb/adapter{}/frontend{}", adapter, device);
|
println!("{:#?}", options);
|
||||||
|
|
||||||
let fd = unsafe {
|
match options {
|
||||||
let fd = libc::open(path.as_ptr() as *const i8, libc::O_NONBLOCK | libc::O_RDWR);
|
DvbOptions::DVB_S2(v) => {
|
||||||
if fd == -1 {
|
let fd = v.adapter.open()?;
|
||||||
Err(io::Error::last_os_error())
|
|
||||||
} else {
|
|
||||||
Ok(fd)
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
|
|
||||||
let feinfo = unsafe {
|
let feinfo = unsafe {
|
||||||
let mut feinfo: dvb_frontend_info = mem::zeroed();
|
get_dvb_frontend_info(fd)?
|
||||||
let x = libc::ioctl(fd, FE_GET_INFO, &mut feinfo as *mut dvb_frontend_info as *mut libc::c_void);
|
};
|
||||||
if x == -1 {
|
println!("{:#?}", feinfo);
|
||||||
libc::close(fd);
|
|
||||||
Err(io::Error::last_os_error())
|
|
||||||
} else {
|
|
||||||
Ok(feinfo)
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
|
|
||||||
println!("{:#?}", feinfo);
|
// TODO: continue here...
|
||||||
|
// DvbS::tune(v)?;
|
||||||
|
|
||||||
Ok(DvbTune {
|
Ok(DvbTune{ fd, feinfo, })
|
||||||
fd,
|
},
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user