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

cleaning; FeStats: get_ber(), get_unc()

This commit is contained in:
Andrey Dyldin 2021-01-29 20:29:19 +02:00
parent 1c43e2bf60
commit 8c8979b9c5
4 changed files with 43 additions and 42 deletions

View File

@ -53,5 +53,5 @@ Frontend status:
let fe = FeDevice::open_rd("/dev/dvb/adapter0/frontend0")?;
let mut status = FeStatus::default();
status.read(&fe)?;
println!("{}", &status.display(1));
println!("{}", &status);
```

View File

@ -125,7 +125,7 @@ impl FeDevice {
DtvProperty::new(DTV_TONE, SEC_TONE_OFF),
DtvProperty::new(DTV_CLEAR, 0),
];
self.set_properties(&cmdseq).context("frontend clear")?;
self.set_properties(&cmdseq).context("FE: clear")?;
let mut event = FeEvent::default();
@ -145,7 +145,7 @@ impl FeDevice {
ioctl_read!(#[inline] ioctl_call, b'o', 61, FeInfo);
unsafe {
ioctl_call(self.as_raw_fd(), &mut feinfo as *mut _)
}.context("frontend get info")?;
}.context("FE: get info")?;
if let Some(len) = feinfo.name.iter().position(|&b| b == 0) {
let name = unsafe { CStr::from_ptr(feinfo.name[.. len + 1].as_ptr()) };
@ -165,7 +165,7 @@ impl FeDevice {
DtvProperty::new(DTV_API_VERSION, 0),
DtvProperty::new(DTV_ENUM_DELSYS, 0),
];
self.get_properties(&mut cmdseq).context("frontend get api version (deprecated driver)")?;
self.get_properties(&mut cmdseq).context("FE: get api version (deprecated driver)")?;
// DVB API Version
@ -181,7 +181,7 @@ impl FeDevice {
// dev-file metadata
let metadata = self.file.metadata().context("frontend get device metadata")?;
let metadata = self.file.metadata().context("FE: get device metadata")?;
ensure!(
metadata.file_type().is_char_device(),
@ -197,7 +197,7 @@ impl FeDevice {
.write(w)
.custom_flags(::nix::libc::O_NONBLOCK)
.open(path)
.context("fe open")?;
.context("FE: open")?;
let mut fe = FeDevice {
file,
@ -292,7 +292,7 @@ impl FeDevice {
/// Sets properties on frontend device
pub fn set_properties(&self, cmdseq: &[DtvProperty]) -> Result<()> {
self.check_properties(cmdseq).context("fe property check")?;
self.check_properties(cmdseq).context("FE: property check")?;
#[repr(C)]
pub struct DtvProperties {
@ -309,7 +309,7 @@ impl FeDevice {
ioctl_write_ptr!(#[inline] ioctl_call, b'o', 82, DtvProperties);
unsafe {
ioctl_call(self.as_raw_fd(), &cmd as *const _)
}.context("frontend set properties")?;
}.context("FE: set properties")?;
Ok(())
}
@ -331,7 +331,7 @@ impl FeDevice {
ioctl_read!(#[inline] ioctl_call, b'o', 83, DtvProperties);
unsafe {
ioctl_call(self.as_raw_fd(), &mut cmd as *mut _)
}.context("frontend get properties")?;
}.context("FE: get properties")?;
Ok(())
}
@ -343,7 +343,7 @@ impl FeDevice {
unsafe {
ioctl_call(self.as_raw_fd(), event as *mut _)
}.context("frontend get event")?;
}.context("FE: get event")?;
Ok(())
}
@ -360,7 +360,7 @@ impl FeDevice {
unsafe {
ioctl_call(self.as_raw_fd(), value as _)
}.context("frontend set tone")?;
}.context("FE: set tone")?;
Ok(())
}
@ -389,7 +389,7 @@ impl FeDevice {
unsafe {
ioctl_call(self.as_raw_fd(), value as _)
}.context("frontend set voltage")?;
}.context("FE: set voltage")?;
Ok(())
}
@ -423,7 +423,7 @@ impl FeDevice {
ioctl_write_ptr!(ioctl_call, b'o', 63, DiseqcMasterCmd);
unsafe {
ioctl_call(self.as_raw_fd(), &cmd as *const _)
}.context("frontend diseqc master cmd")?;
}.context("FE: diseqc master cmd")?;
Ok(())
}

View File

@ -104,15 +104,15 @@ impl fmt::Display for FeStatus {
}
write!(f, " BER:")?;
if let Some(ber) = self.props[2].get_stats_counter() {
write!(f, "{}", ber & 0xFFFF)?;
if let Some(ber) = self.get_ber() {
write!(f, "{}", ber)?;
} else {
write!(f, "-")?;
}
write!(f, " UNC:")?;
if let Some(unc) = self.props[3].get_stats_counter() {
write!(f, "{}", unc & 0xFFFF)?;
if let Some(unc) = self.get_unc() {
write!(f, "{}", unc)?;
} else {
write!(f, "-")?;
}
@ -124,6 +124,8 @@ impl fmt::Display for FeStatus {
impl FeStatus {
fn get_signal_level(&self) -> Option<(f64, u64)> {
let stats = self.props.get(0)?;
let _stats = unsafe { &stats.u.st };
// TODO: config for lo/hi
// let lo: f64 = -85.0;
// let hi: f64 = -6.0;
@ -132,10 +134,32 @@ impl FeStatus {
}
fn get_signal_noise_ratio(&self) -> Option<(f64, u64)> {
let stats = self.props.get(1)?;
let _stats = unsafe { &stats.u.st };
// let relative = 5 * decibel as u32;
None
}
fn get_stats_counter(&self, u: usize) -> Option<u32> {
let stats = self.props.get(u)?;
let stats = unsafe { &stats.u.st };
if stats.len > 0 {
let s = &stats.stat[0];
if s.scale == FE_SCALE_COUNTER {
return Some((s.value & 0xFFFF) as u32);
}
}
None
}
/// Returns BER value if available
#[inline]
pub fn get_ber(&self) -> Option<u32> { self.get_stats_counter(2) }
/// Returns UNC value if available
#[inline]
pub fn get_unc(&self) -> Option<u32> { self.get_stats_counter(3) }
/// Reads frontend status
pub fn read(&mut self, fe: &FeDevice) -> Result<()> {
self.status = FE_NONE;
@ -144,7 +168,7 @@ impl FeStatus {
ioctl_read!(#[inline] ioctl_call, b'o', 69, u32);
unsafe {
ioctl_call(fe.as_raw_fd(), &mut self.status as *mut _)
}.context("frontend read status")?;
}.context("FE: read status")?;
if self.status == FE_NONE {
return Ok(());

View File

@ -454,7 +454,7 @@ impl fmt::Debug for DtvStats {
}
FE_SCALE_RELATIVE => {
s.field(FIELD_SCALE, &"FE_SCALE_RELATIVE");
s.field(FIELD_VALUE, &{(self.value as u64) * 100 / 65535});
s.field(FIELD_VALUE, &{self.value as u64});
}
FE_SCALE_COUNTER => {
s.field(FIELD_SCALE, &"FE_SCALE_COUNTER");
@ -729,29 +729,6 @@ impl DtvProperty {
result: 0,
}
}
pub fn get_stats_counter(&self) -> Option<u64> {
match self.cmd {
DTV_STAT_PRE_ERROR_BIT_COUNT |
DTV_STAT_PRE_TOTAL_BIT_COUNT |
DTV_STAT_POST_ERROR_BIT_COUNT |
DTV_STAT_POST_TOTAL_BIT_COUNT |
DTV_STAT_ERROR_BLOCK_COUNT |
DTV_STAT_TOTAL_BLOCK_COUNT => {
let stats = unsafe { &self.u.st };
if stats.len > 0 {
let s = &stats.stat[0];
if s.scale == FE_SCALE_COUNTER {
return Some(s.value as u64);
}
}
}
_ => {}
}
None
}
}