Skip to main content

PortValueSingleFormat

Struct PortValueSingleFormat 

Source
pub struct PortValueSingleFormat {
    pub port_id: u8,
    pub data: Vec<i8>,
}
Expand description

The PortValueSingleFormat is a list of port id & value pairs, except that the values may be different lengths (u8, u16, u32, f32) depending on the port configuration. For now we just save the payload and then later on will provide a method to split it out into port-value pairs based on a separate port type mapping.

Notes on Value Format

  1. The valuetypes are signed, i.e. the variants are i8, i16, i32, f32. This: https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#port-value-single says that the values are unsigned, but this is seemingly incorrect. Many sensors can report negative values, as can be seen by requesting Port Mode Information::Raw range.
  2. The values are not a single value but an array, the length of which is given by the “number_of_datasets”-member of Value Format. (“Single” in PortValueSingle refers to single sensor mode, but single sensors can)
    and do provide provide array data, ex. color RGB or accelerometer XYZ-data.)
  3. There are some inconsistencies looking at port mode information: HubLeds in RBG reports taking 8 bit values in the range 0-255, though this doesn’t concern the parser of incoming values. As regards sensors; TechnicHubTiltSensor mode CFG, as well as MoveHubInternalTilt modes IM_CF and CALIB: These all report that they will provide 8 bit values in range 0-255. But these are the only ones I’ve been able to find. On the whole it seems better to correctly support the multitude of sensors and modes.

Fields§

§port_id: u8§data: Vec<i8>

Implementations§

Source§

impl PortValueSingleFormat

Source

pub fn parse<'a>(msg: impl Iterator<Item = &'a u8>) -> Result<Self>

Source

pub fn process(&self, _type_mapping: ()) -> HashMap<u8, TypedValue>

Trait Implementations§

Source§

impl Clone for PortValueSingleFormat

Source§

fn clone(&self) -> PortValueSingleFormat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PortValueSingleFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PortValueSingleFormat

Source§

impl PartialEq for PortValueSingleFormat

Source§

fn eq(&self, other: &PortValueSingleFormat) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PortValueSingleFormat

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.