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

ca: open by adapter and device number

This commit is contained in:
Andrey Dyldin 2021-03-08 16:46:58 +02:00
parent c4c33e86ad
commit 1af4957fa6
2 changed files with 20 additions and 12 deletions

View File

@ -1,6 +1,5 @@
use {
std::{
path::Path,
os::unix::io::AsRawFd,
},
@ -33,9 +32,7 @@ use {
};
fn check_ca(path: &Path) -> Result<()> {
println!("CA: {}", path.display());
fn start_ca(adapter: u32, device: u32) -> Result<()> {
// let mut ca = CaDevice::open(path, 0)?;
let timer = TimerFd::new(
@ -100,12 +97,16 @@ fn check_ca(path: &Path) -> Result<()> {
fn main() -> Result<()> {
let mut args = std::env::args().skip(1);
if let Some(path) = args.next() {
let path = Path::new(&path);
check_ca(&path)?;
} else {
eprintln!("path to ca device is not defined");
}
Ok(())
let adapter = match args.next() {
Some(v) => v.parse::<u32>().context("adapter number")?,
None => bail!("adapter number not defined"),
};
let device = match args.next() {
Some(v) => v.parse::<u32>().context("device number")?,
None => 0,
};
start_ca(adapter, device)
}

View File

@ -44,6 +44,9 @@ const CA_DELAY: Duration = Duration::from_millis(100);
#[derive(Debug)]
pub struct CaDevice {
adapter: u32,
device: u32,
file: File,
slot: CaSlotInfo,
}
@ -93,7 +96,8 @@ impl CaDevice {
}
/// Attempts to open a CA device
pub fn open(path: &Path, slot: u32) -> Result<CaDevice> {
pub fn open(adapter: u32, device: u32, slot: u32) -> Result<CaDevice> {
let path = format!("/dev/dvb/adapter{}/ca{}", adapter, device);
let file = OpenOptions::new()
.read(true)
.write(true)
@ -102,6 +106,9 @@ impl CaDevice {
.with_context(|| format!("CA: failed to open device {}", path.display()))?;
let mut ca = CaDevice {
adapter,
device,
file,
slot: CaSlotInfo::default(),
};