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

cleaning: remove thiserror

This commit is contained in:
Andrey Dyldin 2021-02-01 10:35:10 +02:00
parent 0aef88bedb
commit e4360f3e04
5 changed files with 14 additions and 43 deletions

View File

@ -14,4 +14,3 @@ edition = "2018"
[dependencies] [dependencies]
nix = "0.19" nix = "0.19"
anyhow = "1.0" anyhow = "1.0"
thiserror = "1.0"

View File

@ -26,7 +26,7 @@ fn check_ca(path: &Path) -> Result<()> {
fn main() -> Result<()> { fn main() -> Result<()> {
let mut args = std::env::args().skip(1); let mut args = std::env::args().skip(1);
if let Some(path) = args.next() { if let Some(path) = args.next() {
let path = Path::new(path); let path = Path::new(&path);
check_ca(&path)?; check_ca(&path)?;
} else { } else {
eprintln!("path to ca device is not defined"); eprintln!("path to ca device is not defined");

View File

@ -42,8 +42,7 @@ use {
#[derive(Debug)] #[derive(Debug)]
pub struct CaDevice { pub struct CaDevice {
file: File, file: File,
slot_id: u8,
slot_id: u8
} }
@ -99,8 +98,7 @@ impl CaDevice {
}.context("CA: failed to get slot info")?; }.context("CA: failed to get slot info")?;
if slot_info.flags == CA_CI_MODULE_NOT_FOUND { if slot_info.flags == CA_CI_MODULE_NOT_FOUND {
println!("CA: module not found"); return Err(anyhow!("CA: module not found"));
return Ok(());
} }
if slot_info.typ != CA_CI_LINK { if slot_info.typ != CA_CI_LINK {

View File

@ -28,7 +28,6 @@ use {
Context, Context,
Result, Result,
}, },
thiserror::Error,
nix::{ nix::{
ioctl_read, ioctl_read,
@ -46,30 +45,6 @@ pub use {
}; };
/// The error type for frontend operations
#[derive(Debug, Error)]
pub enum FeError {
#[error("frontend is not char device")]
InvalidDeviceFormat,
#[error("frequency out of range")]
InvalidFrequency,
#[error("symbolrate out of range")]
InvalidSymbolrate,
#[error("unknown subsystem")]
InvalidSubsystem,
#[error("no auto inversion")]
NoAutoInversion,
#[error("no auto transmission mode")]
NoAutoTransmitMode,
#[error("no auto guard interval")]
NoAutoGuardInterval,
#[error("no auto hierarchy")]
NoAutoHierarchy,
#[error("multistream not supported")]
NoMultistream,
}
/// A reference to the frontend device and device information /// A reference to the frontend device and device information
#[derive(Debug)] #[derive(Debug)]
pub struct FeDevice { pub struct FeDevice {
@ -185,7 +160,7 @@ impl FeDevice {
ensure!( ensure!(
metadata.file_type().is_char_device(), metadata.file_type().is_char_device(),
FeError::InvalidDeviceFormat "FE: path is not to char device"
); );
Ok(()) Ok(())
@ -231,14 +206,14 @@ impl FeDevice {
let v = unsafe { p.u.data }; let v = unsafe { p.u.data };
ensure!( ensure!(
self.frequency_range.contains(&v), self.frequency_range.contains(&v),
FeError::InvalidFrequency "FE: frequency out of range"
); );
} }
DTV_SYMBOL_RATE => { DTV_SYMBOL_RATE => {
let v = unsafe { p.u.data }; let v = unsafe { p.u.data };
ensure!( ensure!(
self.symbolrate_range.contains(&v), self.symbolrate_range.contains(&v),
FeError::InvalidSymbolrate "FE: symbolrate out of range"
); );
} }
DTV_INVERSION => { DTV_INVERSION => {
@ -246,7 +221,7 @@ impl FeDevice {
if v == INVERSION_AUTO { if v == INVERSION_AUTO {
ensure!( ensure!(
self.caps & FE_CAN_INVERSION_AUTO != 0, self.caps & FE_CAN_INVERSION_AUTO != 0,
FeError::NoAutoInversion "FE: auto inversion is not available"
); );
} }
} }
@ -255,7 +230,7 @@ impl FeDevice {
if v == TRANSMISSION_MODE_AUTO { if v == TRANSMISSION_MODE_AUTO {
ensure!( ensure!(
self.caps & FE_CAN_TRANSMISSION_MODE_AUTO != 0, self.caps & FE_CAN_TRANSMISSION_MODE_AUTO != 0,
FeError::NoAutoTransmitMode "FE: no auto transmission mode"
); );
} }
} }
@ -264,7 +239,7 @@ impl FeDevice {
if v == GUARD_INTERVAL_AUTO { if v == GUARD_INTERVAL_AUTO {
ensure!( ensure!(
self.caps & FE_CAN_GUARD_INTERVAL_AUTO != 0, self.caps & FE_CAN_GUARD_INTERVAL_AUTO != 0,
FeError::NoAutoGuardInterval "FE: no auto guard interval"
); );
} }
} }
@ -273,14 +248,14 @@ impl FeDevice {
if v == HIERARCHY_AUTO { if v == HIERARCHY_AUTO {
ensure!( ensure!(
self.caps & FE_CAN_HIERARCHY_AUTO != 0, self.caps & FE_CAN_HIERARCHY_AUTO != 0,
FeError::NoAutoHierarchy "FE: no auto hierarchy"
); );
} }
} }
DTV_STREAM_ID => { DTV_STREAM_ID => {
ensure!( ensure!(
self.caps & FE_CAN_MULTISTREAM != 0, self.caps & FE_CAN_MULTISTREAM != 0,
FeError::NoMultistream "FE: no multistream"
); );
} }
_ => {} _ => {}

View File

@ -81,7 +81,7 @@ impl fmt::Display for FeStatus {
return Ok(()); return Ok(());
} }
write!(f, " S:")?; write!(f, " Signal:")?;
if let Some(s) = self.get_signal_level() { if let Some(s) = self.get_signal_level() {
// TODO: config for lo/hi // TODO: config for lo/hi
let lo: f64 = -85.0; let lo: f64 = -85.0;
@ -96,10 +96,9 @@ impl fmt::Display for FeStatus {
return Ok(()); return Ok(());
} }
write!(f, " Q:")?; write!(f, " Quality:")?;
if let Some(q) = self.get_signal_noise_ratio() { if let Some(q) = self.get_signal_noise_ratio() {
let relative = q * 2.; write!(f, "{:.02}dB", q)?;
write!(f, "{:.02}dB ({:.0}%)", q, relative)?;
} else { } else {
write!(f, "-")?; write!(f, "-")?;
} }