mirror of
https://github.com/danog/libdvb.git
synced 2024-11-26 20:04:39 +01:00
ca: open by adapter and device number
This commit is contained in:
parent
c4c33e86ad
commit
1af4957fa6
@ -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)
|
||||
}
|
||||
|
@ -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(),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user