1
0
mirror of https://github.com/danog/libdvb.git synced 2024-11-26 20:04:39 +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]
name = "libdvb"
version = "0.2.3"
version = "0.3.0"
description = "Interface for DVB-API v5 devices in Linux"
authors = ["Cesbo Developers Team <info@cesbo.com>"]
license = "MIT"

View File

@ -36,21 +36,21 @@ let cmdseq = vec![
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)?;
```
Frontend information:
```rust
let fe = FeDevice::open_rd("/dev/dvb/adapter0/frontend0")?;
let fe = FeDevice::open_ro(0, 0)?;
println!("{}", &fe);
```
Frontend status:
```rust
let fe = FeDevice::open_rd("/dev/dvb/adapter0/frontend0")?;
let fe = FeDevice::open_ro(0, 0)?;
let mut status = FeStatus::default();
status.read(&fe)?;
println!("{}", &status);

View File

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

View File

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

View File

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

View File

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