pub struct CayenneLPP<'a> { /* private fields */ }
Expand description
This struct contains the data of the added payload objects and an index that points to the next free value in the array. All newly added values will increase the index. After adding all the values, the buffer contains the payloads of the different data types and has a length of ’‘index’’.
Implementations§
Source§impl<'a> CayenneLPP<'a>
impl<'a> CayenneLPP<'a>
Sourcepub fn new(buffer: &'a mut [u8]) -> Self
pub fn new(buffer: &'a mut [u8]) -> Self
Creates a new buffer for the Cayenne LPP. Since the library works without a memory allocator, it is necessary to provide it with an array that equals the length or is bigger then the data that shall be added to it.
It is possible to use the size constants for the data types (e.g. LPP_TEMPERATURE_SIZE), to exactly calculate the size of the needed array.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the index that is pointing into the buffer, so it is possible to reuse the buffer and add new payloads to it. Remark: the buffer is not cleared by this operation.
Sourcepub fn payload_slice(&self) -> &[u8]
pub fn payload_slice(&self) -> &[u8]
Returns the slice of the buffer that contains the payload of the added data types.
Sourcepub fn add_digital_input(&mut self, channel: u8, value: u8) -> Result<(), Error>
pub fn add_digital_input(&mut self, channel: u8, value: u8) -> Result<(), Error>
Adds the payload for a digital input to the Cayenne LPP data structure.
Sourcepub fn add_digital_output(
&mut self,
channel: u8,
value: u8,
) -> Result<(), Error>
pub fn add_digital_output( &mut self, channel: u8, value: u8, ) -> Result<(), Error>
Adds the payload for a digital output to the Cayenne LPP data structure.
Sourcepub fn add_analog_input(&mut self, channel: u8, value: f32) -> Result<(), Error>
pub fn add_analog_input(&mut self, channel: u8, value: f32) -> Result<(), Error>
Adds the payload for an analog input to the Cayenne LPP data structure.
Sourcepub fn add_analog_output(
&mut self,
channel: u8,
value: f32,
) -> Result<(), Error>
pub fn add_analog_output( &mut self, channel: u8, value: f32, ) -> Result<(), Error>
Adds the payload for an analog output to the Cayenne LPP data structure.
Sourcepub fn add_luminosity(&mut self, channel: u8, lux: u16) -> Result<(), Error>
pub fn add_luminosity(&mut self, channel: u8, lux: u16) -> Result<(), Error>
Adds the payload for luminosity to the Cayenne LPP data structure. The value should be provided in lux.
Sourcepub fn add_presence(&mut self, channel: u8, value: u8) -> Result<(), Error>
pub fn add_presence(&mut self, channel: u8, value: u8) -> Result<(), Error>
Adds the payload for a presence sensor to the Cayenne LPP data structure.
Sourcepub fn add_temperature(
&mut self,
channel: u8,
celsius: f32,
) -> Result<(), Error>
pub fn add_temperature( &mut self, channel: u8, celsius: f32, ) -> Result<(), Error>
Adds the payload for temperature to the Cayenne LPP data structure.
Sourcepub fn add_relative_humidity(
&mut self,
channel: u8,
relative_humidity: f32,
) -> Result<(), Error>
pub fn add_relative_humidity( &mut self, channel: u8, relative_humidity: f32, ) -> Result<(), Error>
Adds the payload for relative humidity to the Cayenne LPP data structure.
Sourcepub fn add_accelerometer(
&mut self,
channel: u8,
x: f32,
y: f32,
z: f32,
) -> Result<(), Error>
pub fn add_accelerometer( &mut self, channel: u8, x: f32, y: f32, z: f32, ) -> Result<(), Error>
Adds the payload of an accelerometer to the Cayenne LPP data structure.
Sourcepub fn add_barometric_pressure(
&mut self,
channel: u8,
hpa: f32,
) -> Result<(), Error>
pub fn add_barometric_pressure( &mut self, channel: u8, hpa: f32, ) -> Result<(), Error>
Adds the payload for barometric pressure to the Cayenne LPP data structure.