#[cfg(feature = "serde")]
use super::SerializeUbxPacketFields;
#[cfg(feature = "serde")]
use crate::serde::ser::SerializeMap;
#[allow(unused_imports, reason = "It is only unused in some feature sets")]
use crate::FieldIter;
use crate::{error::ParserError, UbxPacketMeta};
use ublox_derive::ubx_packet_recv;
const NUM_TARGETS: usize = 6;
#[ubx_packet_recv]
#[ubx(class = 0x0a, id = 0x08, fixed_payload_len = 28)]
struct MonTxbuf {
#[ubx(map_type = &[u16], from = pending_from_bytes, is_valid = pending_is_valid, get_as_ref)]
pending: [u8; 12],
#[ubx(map_type = &[u8], from = usage_from_bytes, is_valid = usage_is_valid, get_as_ref)]
usage: [u8; 6],
#[ubx(map_type = &[u8], from = peak_usage_from_bytes, is_valid = peak_usage_is_valid, get_as_ref)]
peak_usage: [u8; 6],
t_usage: u8,
t_peak_usage: u8,
#[ubx(map_type = MonTxbufErrors)]
errors: u8,
reserved0: u8,
}
fn pending_from_bytes(bytes: &[u8]) -> &[u16] {
let ptr = bytes.as_ptr() as *const u16;
unsafe { core::slice::from_raw_parts(ptr, NUM_TARGETS) }
}
#[allow(dead_code, reason = "Used by ubx_packet_recv macro for validation")]
fn pending_is_valid(bytes: &[u8]) -> bool {
bytes.len() == NUM_TARGETS * 2
}
fn usage_from_bytes(bytes: &[u8]) -> &[u8] {
bytes
}
#[allow(dead_code, reason = "Used by ubx_packet_recv macro for validation")]
fn usage_is_valid(bytes: &[u8]) -> bool {
bytes.len() == NUM_TARGETS
}
fn peak_usage_from_bytes(bytes: &[u8]) -> &[u8] {
bytes
}
#[allow(dead_code, reason = "Used by ubx_packet_recv macro for validation")]
fn peak_usage_is_valid(bytes: &[u8]) -> bool {
bytes.len() == NUM_TARGETS
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct MonTxbufErrors(u8);
impl MonTxbufErrors {
pub fn limit(&self) -> u8 {
self.0 & 0x3F
}
pub fn limit_reached(&self, target: usize) -> bool {
target < NUM_TARGETS && (self.0 & (1 << target)) != 0
}
pub fn mem(&self) -> bool {
self.0 & 0x40 != 0
}
pub fn alloc(&self) -> bool {
self.0 & 0x80 != 0
}
pub fn raw(&self) -> u8 {
self.0
}
}
impl From<u8> for MonTxbufErrors {
fn from(value: u8) -> Self {
Self(value)
}
}