1
0
mirror of https://github.com/danog/libdvb.git synced 2024-11-30 04:19:00 +01:00

cleaning; update readme; version up

This commit is contained in:
Andrey Dyldin 2021-03-16 10:43:37 +02:00
parent 54fee799a7
commit 67c12ea17b
6 changed files with 27 additions and 10 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "libdvb" name = "libdvb"
version = "0.2.3" version = "0.3.0"
description = "Interface for DVB-API v5 devices in Linux" description = "Interface for DVB-API v5 devices in Linux"
authors = ["Cesbo Developers Team <info@cesbo.com>"] authors = ["Cesbo Developers Team <info@cesbo.com>"]
license = "MIT" license = "MIT"

View File

@ -36,21 +36,21 @@ let cmdseq = vec![
DtvProperty::new(DTV_TUNE, 0), DtvProperty::new(DTV_TUNE, 0),
]; ];
let fe = FeDevice::open_rw("/dev/dvb/adapter0/frontend0")?; let fe = FeDevice::open_rw(0, 0)?;
fe.set_properties(&cmdseq)?; fe.set_properties(&cmdseq)?;
``` ```
Frontend information: Frontend information:
```rust ```rust
let fe = FeDevice::open_rd("/dev/dvb/adapter0/frontend0")?; let fe = FeDevice::open_ro(0, 0)?;
println!("{}", &fe); println!("{}", &fe);
``` ```
Frontend status: Frontend status:
```rust ```rust
let fe = FeDevice::open_rd("/dev/dvb/adapter0/frontend0")?; let fe = FeDevice::open_ro(0, 0)?;
let mut status = FeStatus::default(); let mut status = FeStatus::default();
status.read(&fe)?; status.read(&fe)?;
println!("{}", &status); println!("{}", &status);

View File

@ -3,7 +3,11 @@ use {
os::unix::io::AsRawFd, os::unix::io::AsRawFd,
}, },
anyhow::Result, anyhow::{
bail,
Context,
Result,
},
nix::{ nix::{
poll::{ poll::{

View File

@ -25,7 +25,7 @@ fn main() -> Result<()> {
None => 0, None => 0,
}; };
let fe = FeDevice::open(adapter, device, true)?; let fe = FeDevice::open_ro(adapter, device)?;
println!("{}", &fe); println!("{}", &fe);
let mut status = FeStatus::default(); let mut status = FeStatus::default();

View File

@ -30,7 +30,7 @@ fn main() -> Result<()> {
None => 0, None => 0,
}; };
let fe = FeDevice::open(adapter, device, true)?; let fe = FeDevice::open_ro(adapter, device)?;
let mut status = FeStatus::default(); let mut status = FeStatus::default();
let delay = Duration::from_secs(1); let delay = Duration::from_secs(1);

View File

@ -168,12 +168,11 @@ impl FeDevice {
Ok(()) Ok(())
} }
/// Attempts to open a frontend device in read-only mode fn open(adapter: u32, device: u32, is_write: bool) -> Result<FeDevice> {
pub fn open(adapter: u32, device: u32, readonly: bool) -> Result<FeDevice> {
let path = format!("/dev/dvb/adapter{}/frontend{}", adapter, device); let path = format!("/dev/dvb/adapter{}/frontend{}", adapter, device);
let file = OpenOptions::new() let file = OpenOptions::new()
.read(true) .read(true)
.write(!readonly) .write(is_write)
.custom_flags(::nix::libc::O_NONBLOCK) .custom_flags(::nix::libc::O_NONBLOCK)
.open(&path) .open(&path)
.with_context(|| format!("FE: failed to open device {}", &path))?; .with_context(|| format!("FE: failed to open device {}", &path))?;
@ -198,6 +197,20 @@ impl FeDevice {
Ok(fe) Ok(fe)
} }
/// Attempts to open frontend device in read-only mode
#[inline]
pub fn open_ro(adapter: u32, device: u32) -> Result<FeDevice>
{
Self::open(adapter, device, false)
}
/// Attempts to open frontend device in read-write mode
#[inline]
pub fn open_rw(adapter: u32, device: u32) -> Result<FeDevice>
{
Self::open(adapter, device, true)
}
fn check_properties(&self, cmdseq: &[DtvProperty]) -> Result<()> { fn check_properties(&self, cmdseq: &[DtvProperty]) -> Result<()> {
for p in cmdseq { for p in cmdseq {
match p.cmd { match p.cmd {