tinkerforge_async/bindings/
outdoor_weather_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! 433MHz receiver for outdoor weather station.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/OutdoorWeather_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, converting_receiver::BrickletRecvTimeoutError, device::*, error::TinkerforgeError,
17    ip_connection::async_io::AsyncIpConnection, low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum OutdoorWeatherBrickletFunction {
24    GetStationIdentifiersLowLevel,
25    GetSensorIdentifiersLowLevel,
26    GetStationData,
27    GetSensorData,
28    SetStationCallbackConfiguration,
29    GetStationCallbackConfiguration,
30    SetSensorCallbackConfiguration,
31    GetSensorCallbackConfiguration,
32    GetSpitfpErrorCount,
33    SetBootloaderMode,
34    GetBootloaderMode,
35    SetWriteFirmwarePointer,
36    WriteFirmware,
37    SetStatusLedConfig,
38    GetStatusLedConfig,
39    GetChipTemperature,
40    Reset,
41    WriteUid,
42    ReadUid,
43    GetIdentity,
44    CallbackStationData,
45    CallbackSensorData,
46}
47impl From<OutdoorWeatherBrickletFunction> for u8 {
48    fn from(fun: OutdoorWeatherBrickletFunction) -> Self {
49        match fun {
50            OutdoorWeatherBrickletFunction::GetStationIdentifiersLowLevel => 1,
51            OutdoorWeatherBrickletFunction::GetSensorIdentifiersLowLevel => 2,
52            OutdoorWeatherBrickletFunction::GetStationData => 3,
53            OutdoorWeatherBrickletFunction::GetSensorData => 4,
54            OutdoorWeatherBrickletFunction::SetStationCallbackConfiguration => 5,
55            OutdoorWeatherBrickletFunction::GetStationCallbackConfiguration => 6,
56            OutdoorWeatherBrickletFunction::SetSensorCallbackConfiguration => 7,
57            OutdoorWeatherBrickletFunction::GetSensorCallbackConfiguration => 8,
58            OutdoorWeatherBrickletFunction::GetSpitfpErrorCount => 234,
59            OutdoorWeatherBrickletFunction::SetBootloaderMode => 235,
60            OutdoorWeatherBrickletFunction::GetBootloaderMode => 236,
61            OutdoorWeatherBrickletFunction::SetWriteFirmwarePointer => 237,
62            OutdoorWeatherBrickletFunction::WriteFirmware => 238,
63            OutdoorWeatherBrickletFunction::SetStatusLedConfig => 239,
64            OutdoorWeatherBrickletFunction::GetStatusLedConfig => 240,
65            OutdoorWeatherBrickletFunction::GetChipTemperature => 242,
66            OutdoorWeatherBrickletFunction::Reset => 243,
67            OutdoorWeatherBrickletFunction::WriteUid => 248,
68            OutdoorWeatherBrickletFunction::ReadUid => 249,
69            OutdoorWeatherBrickletFunction::GetIdentity => 255,
70            OutdoorWeatherBrickletFunction::CallbackStationData => 9,
71            OutdoorWeatherBrickletFunction::CallbackSensorData => 10,
72        }
73    }
74}
75pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_N: u8 = 0;
76pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NNE: u8 = 1;
77pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NE: u8 = 2;
78pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_ENE: u8 = 3;
79pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_E: u8 = 4;
80pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_ESE: u8 = 5;
81pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SE: u8 = 6;
82pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SSE: u8 = 7;
83pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_S: u8 = 8;
84pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SSW: u8 = 9;
85pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SW: u8 = 10;
86pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_WSW: u8 = 11;
87pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_W: u8 = 12;
88pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_WNW: u8 = 13;
89pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NW: u8 = 14;
90pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NNW: u8 = 15;
91pub const OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_ERROR: u8 = 255;
92pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
93pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
94pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
95pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
96pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
97pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
98pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
99pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
100pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
101pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
102pub const OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
103pub const OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
104pub const OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
105pub const OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
106pub const OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
107
108#[derive(Clone, Copy)]
109pub struct StationIdentifiersLowLevel {
110    pub identifiers_length: u16,
111    pub identifiers_chunk_offset: u16,
112    pub identifiers_chunk_data: [u8; 60],
113}
114impl FromByteSlice for StationIdentifiersLowLevel {
115    fn bytes_expected() -> usize {
116        64
117    }
118    fn from_le_byte_slice(bytes: &[u8]) -> StationIdentifiersLowLevel {
119        StationIdentifiersLowLevel {
120            identifiers_length: <u16>::from_le_byte_slice(&bytes[0..2]),
121            identifiers_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
122            identifiers_chunk_data: <[u8; 60]>::from_le_byte_slice(&bytes[4..64]),
123        }
124    }
125}
126impl LowLevelRead<u8, StationIdentifiersResult> for StationIdentifiersLowLevel {
127    fn ll_message_length(&self) -> usize {
128        self.identifiers_length as usize
129    }
130
131    fn ll_message_chunk_offset(&self) -> usize {
132        self.identifiers_chunk_offset as usize
133    }
134
135    fn ll_message_chunk_data(&self) -> &[u8] {
136        &self.identifiers_chunk_data
137    }
138
139    fn get_result(&self) -> StationIdentifiersResult {
140        StationIdentifiersResult {}
141    }
142}
143
144#[derive(Clone, Copy)]
145pub struct SensorIdentifiersLowLevel {
146    pub identifiers_length: u16,
147    pub identifiers_chunk_offset: u16,
148    pub identifiers_chunk_data: [u8; 60],
149}
150impl FromByteSlice for SensorIdentifiersLowLevel {
151    fn bytes_expected() -> usize {
152        64
153    }
154    fn from_le_byte_slice(bytes: &[u8]) -> SensorIdentifiersLowLevel {
155        SensorIdentifiersLowLevel {
156            identifiers_length: <u16>::from_le_byte_slice(&bytes[0..2]),
157            identifiers_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
158            identifiers_chunk_data: <[u8; 60]>::from_le_byte_slice(&bytes[4..64]),
159        }
160    }
161}
162impl LowLevelRead<u8, SensorIdentifiersResult> for SensorIdentifiersLowLevel {
163    fn ll_message_length(&self) -> usize {
164        self.identifiers_length as usize
165    }
166
167    fn ll_message_chunk_offset(&self) -> usize {
168        self.identifiers_chunk_offset as usize
169    }
170
171    fn ll_message_chunk_data(&self) -> &[u8] {
172        &self.identifiers_chunk_data
173    }
174
175    fn get_result(&self) -> SensorIdentifiersResult {
176        SensorIdentifiersResult {}
177    }
178}
179
180#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
181pub struct StationData {
182    pub temperature: i16,
183    pub humidity: u8,
184    pub wind_speed: u32,
185    pub gust_speed: u32,
186    pub rain: u32,
187    pub wind_direction: u8,
188    pub battery_low: bool,
189    pub last_change: u16,
190}
191impl FromByteSlice for StationData {
192    fn bytes_expected() -> usize {
193        19
194    }
195    fn from_le_byte_slice(bytes: &[u8]) -> StationData {
196        StationData {
197            temperature: <i16>::from_le_byte_slice(&bytes[0..2]),
198            humidity: <u8>::from_le_byte_slice(&bytes[2..3]),
199            wind_speed: <u32>::from_le_byte_slice(&bytes[3..7]),
200            gust_speed: <u32>::from_le_byte_slice(&bytes[7..11]),
201            rain: <u32>::from_le_byte_slice(&bytes[11..15]),
202            wind_direction: <u8>::from_le_byte_slice(&bytes[15..16]),
203            battery_low: <bool>::from_le_byte_slice(&bytes[16..17]),
204            last_change: <u16>::from_le_byte_slice(&bytes[17..19]),
205        }
206    }
207}
208
209#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
210pub struct SensorData {
211    pub temperature: i16,
212    pub humidity: u8,
213    pub last_change: u16,
214}
215impl FromByteSlice for SensorData {
216    fn bytes_expected() -> usize {
217        5
218    }
219    fn from_le_byte_slice(bytes: &[u8]) -> SensorData {
220        SensorData {
221            temperature: <i16>::from_le_byte_slice(&bytes[0..2]),
222            humidity: <u8>::from_le_byte_slice(&bytes[2..3]),
223            last_change: <u16>::from_le_byte_slice(&bytes[3..5]),
224        }
225    }
226}
227
228#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
229pub struct StationDataEvent {
230    pub identifier: u8,
231    pub temperature: i16,
232    pub humidity: u8,
233    pub wind_speed: u32,
234    pub gust_speed: u32,
235    pub rain: u32,
236    pub wind_direction: u8,
237    pub battery_low: bool,
238}
239impl FromByteSlice for StationDataEvent {
240    fn bytes_expected() -> usize {
241        18
242    }
243    fn from_le_byte_slice(bytes: &[u8]) -> StationDataEvent {
244        StationDataEvent {
245            identifier: <u8>::from_le_byte_slice(&bytes[0..1]),
246            temperature: <i16>::from_le_byte_slice(&bytes[1..3]),
247            humidity: <u8>::from_le_byte_slice(&bytes[3..4]),
248            wind_speed: <u32>::from_le_byte_slice(&bytes[4..8]),
249            gust_speed: <u32>::from_le_byte_slice(&bytes[8..12]),
250            rain: <u32>::from_le_byte_slice(&bytes[12..16]),
251            wind_direction: <u8>::from_le_byte_slice(&bytes[16..17]),
252            battery_low: <bool>::from_le_byte_slice(&bytes[17..18]),
253        }
254    }
255}
256
257#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
258pub struct SensorDataEvent {
259    pub identifier: u8,
260    pub temperature: i16,
261    pub humidity: u8,
262}
263impl FromByteSlice for SensorDataEvent {
264    fn bytes_expected() -> usize {
265        4
266    }
267    fn from_le_byte_slice(bytes: &[u8]) -> SensorDataEvent {
268        SensorDataEvent {
269            identifier: <u8>::from_le_byte_slice(&bytes[0..1]),
270            temperature: <i16>::from_le_byte_slice(&bytes[1..3]),
271            humidity: <u8>::from_le_byte_slice(&bytes[3..4]),
272        }
273    }
274}
275
276#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
277pub struct SpitfpErrorCount {
278    pub error_count_ack_checksum: u32,
279    pub error_count_message_checksum: u32,
280    pub error_count_frame: u32,
281    pub error_count_overflow: u32,
282}
283impl FromByteSlice for SpitfpErrorCount {
284    fn bytes_expected() -> usize {
285        16
286    }
287    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
288        SpitfpErrorCount {
289            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
290            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
291            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
292            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
293        }
294    }
295}
296
297#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
298pub struct Identity {
299    pub uid: String,
300    pub connected_uid: String,
301    pub position: char,
302    pub hardware_version: [u8; 3],
303    pub firmware_version: [u8; 3],
304    pub device_identifier: u16,
305}
306impl FromByteSlice for Identity {
307    fn bytes_expected() -> usize {
308        25
309    }
310    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
311        Identity {
312            uid: <String>::from_le_byte_slice(&bytes[0..8]),
313            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
314            position: <char>::from_le_byte_slice(&bytes[16..17]),
315            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
316            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
317            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
318        }
319    }
320}
321
322#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
323pub struct StationIdentifiersResult {}
324
325#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
326pub struct SensorIdentifiersResult {}
327
328/// 433MHz receiver for outdoor weather station
329#[derive(Clone)]
330pub struct OutdoorWeatherBricklet {
331    device: Device,
332}
333impl OutdoorWeatherBricklet {
334    pub const DEVICE_IDENTIFIER: u16 = 288;
335    pub const DEVICE_DISPLAY_NAME: &'static str = "Outdoor Weather Bricklet";
336    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
337    pub fn new(uid: Uid, connection: AsyncIpConnection) -> OutdoorWeatherBricklet {
338        let mut result = OutdoorWeatherBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
339        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetStationIdentifiersLowLevel) as usize] =
340            ResponseExpectedFlag::AlwaysTrue;
341        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetSensorIdentifiersLowLevel) as usize] =
342            ResponseExpectedFlag::AlwaysTrue;
343        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetStationData) as usize] =
344            ResponseExpectedFlag::AlwaysTrue;
345        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetSensorData) as usize] =
346            ResponseExpectedFlag::AlwaysTrue;
347        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::SetStationCallbackConfiguration) as usize] =
348            ResponseExpectedFlag::True;
349        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetStationCallbackConfiguration) as usize] =
350            ResponseExpectedFlag::AlwaysTrue;
351        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::SetSensorCallbackConfiguration) as usize] =
352            ResponseExpectedFlag::True;
353        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetSensorCallbackConfiguration) as usize] =
354            ResponseExpectedFlag::AlwaysTrue;
355        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetSpitfpErrorCount) as usize] =
356            ResponseExpectedFlag::AlwaysTrue;
357        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::SetBootloaderMode) as usize] =
358            ResponseExpectedFlag::AlwaysTrue;
359        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetBootloaderMode) as usize] =
360            ResponseExpectedFlag::AlwaysTrue;
361        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::SetWriteFirmwarePointer) as usize] =
362            ResponseExpectedFlag::False;
363        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::WriteFirmware) as usize] =
364            ResponseExpectedFlag::AlwaysTrue;
365        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::SetStatusLedConfig) as usize] =
366            ResponseExpectedFlag::False;
367        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetStatusLedConfig) as usize] =
368            ResponseExpectedFlag::AlwaysTrue;
369        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetChipTemperature) as usize] =
370            ResponseExpectedFlag::AlwaysTrue;
371        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
372        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
373        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
374        result.device.response_expected[u8::from(OutdoorWeatherBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
375        result
376    }
377
378    /// Returns the response expected flag for the function specified by the function ID parameter.
379    /// It is true if the function is expected to send a response, false otherwise.
380    ///
381    /// For getter functions this is enabled by default and cannot be disabled, because those
382    /// functions will always send a response. For callback configuration functions it is enabled
383    /// by default too, but can be disabled by [`set_response_expected`](crate::outdoor_weather_bricklet::OutdoorWeatherBricklet::set_response_expected).
384    /// For setter functions it is disabled by default and can be enabled.
385    ///
386    /// Enabling the response expected flag for a setter function allows to detect timeouts
387    /// and other error conditions calls of this setter as well. The device will then send a response
388    /// for this purpose. If this flag is disabled for a setter function then no response is sent
389    /// and errors are silently ignored, because they cannot be detected.
390    ///
391    /// See [`set_response_expected`](crate::outdoor_weather_bricklet::OutdoorWeatherBricklet::set_response_expected) for the list of function ID constants available for this function.
392    pub fn get_response_expected(&mut self, fun: OutdoorWeatherBrickletFunction) -> Result<bool, GetResponseExpectedError> {
393        self.device.get_response_expected(u8::from(fun))
394    }
395
396    /// Changes the response expected flag of the function specified by the function ID parameter.
397    /// This flag can only be changed for setter (default value: false) and callback configuration
398    /// functions (default value: true). For getter functions it is always enabled.
399    ///
400    /// Enabling the response expected flag for a setter function allows to detect timeouts and
401    /// other error conditions calls of this setter as well. The device will then send a response
402    /// for this purpose. If this flag is disabled for a setter function then no response is sent
403    /// and errors are silently ignored, because they cannot be detected.
404    pub fn set_response_expected(
405        &mut self,
406        fun: OutdoorWeatherBrickletFunction,
407        response_expected: bool,
408    ) -> Result<(), SetResponseExpectedError> {
409        self.device.set_response_expected(u8::from(fun), response_expected)
410    }
411
412    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
413    pub fn set_response_expected_all(&mut self, response_expected: bool) {
414        self.device.set_response_expected_all(response_expected)
415    }
416
417    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
418    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
419    pub fn get_api_version(&self) -> [u8; 3] {
420        self.device.api_version
421    }
422
423    /// Reports the station data every time a new data packet is received.
424    /// See [`get_station_data`] for information about the data.
425    ///
426    /// For each station the receiver will be triggered about every 45 seconds.
427    ///
428    /// Turn the receiver on/off with [`set_station_callback_configuration`]
429    /// (by default it is turned off).
430    ///
431    /// [`get_station_data`]: #method.get_station_data
432    /// [`set_station_callback_configuration`]: #method.set_station_callback_configuration
433    pub async fn get_station_data_callback_receiver(&mut self) -> impl Stream<Item = StationDataEvent> {
434        self.device
435            .get_callback_receiver(u8::from(OutdoorWeatherBrickletFunction::CallbackStationData))
436            .await
437            .map(|p| StationDataEvent::from_le_byte_slice(p.body()))
438    }
439
440    /// Reports the sensor data every time a new data packet is received.
441    /// See [`get_sensor_data`] for information about the data.
442    ///
443    /// For each sensor the receiver will be called about every 45 seconds.
444    ///
445    /// Turn the receiver on/off with [`set_sensor_callback_configuration`]
446    /// (by default it is turned off).
447    pub async fn get_sensor_data_callback_receiver(&mut self) -> impl Stream<Item = SensorDataEvent> {
448        self.device
449            .get_callback_receiver(u8::from(OutdoorWeatherBrickletFunction::CallbackSensorData))
450            .await
451            .map(|p| SensorDataEvent::from_le_byte_slice(p.body()))
452    }
453
454    /// Returns the identifiers (number between 0 and 255) of all `stations
455    /// <https://www.tinkerforge.com/en/shop/accessories/sensors/outdoor-weather-station-ws-6147.html>`__
456    /// that have been seen since the startup of the Bricklet.
457    ///
458    /// Each station gives itself a random identifier on first startup.
459    ///
460    /// Since firmware version 2.0.2 a station is removed from the list if no data was received for
461    /// 12 hours.
462    pub async fn get_station_identifiers_low_level(&mut self) -> Result<StationIdentifiersLowLevel, TinkerforgeError> {
463        let payload = [0; 0];
464
465        #[allow(unused_variables)]
466        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetStationIdentifiersLowLevel), &payload).await?;
467        Ok(StationIdentifiersLowLevel::from_le_byte_slice(result.body()))
468    }
469
470    /// Returns the identifiers (number between 0 and 255) of all `sensors
471    /// <https://www.tinkerforge.com/en/shop/accessories/sensors/temperature-humidity-sensor-th-6148.html>`__
472    /// that have been seen since the startup of the Bricklet.
473    ///
474    /// Each sensor gives itself a random identifier on first startup.
475    ///
476    /// Since firmware version 2.0.2 a sensor is removed from the list if no data was received for
477    /// 12 hours.
478    pub async fn get_sensor_identifiers_low_level(&mut self) -> Result<SensorIdentifiersLowLevel, TinkerforgeError> {
479        let payload = [0; 0];
480
481        #[allow(unused_variables)]
482        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetSensorIdentifiersLowLevel), &payload).await?;
483        Ok(SensorIdentifiersLowLevel::from_le_byte_slice(result.body()))
484    }
485
486    /// Returns the last received data for a station with the given identifier.
487    /// Call [`get_station_identifiers`] for a list of all available identifiers.
488    ///
489    /// The return values are:
490    ///
491    /// * Temperature,
492    /// * Humidity,
493    /// * Wind Speed,
494    /// * Gust Speed,
495    /// * Rain Fall (accumulated since station power-up),
496    /// * Wind Direction,
497    /// * Battery Low (true if battery is low) and
498    /// * Last Change (seconds since the reception of this data).
499    ///
500    /// Associated constants:
501    /// * OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_N
502    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NNE
503    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NE
504    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_ENE
505    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_E
506    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_ESE
507    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SE
508    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SSE
509    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_S
510    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SSW
511    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_SW
512    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_WSW
513    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_W
514    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_WNW
515    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NW
516    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_NNW
517    ///	* OUTDOOR_WEATHER_BRICKLET_WIND_DIRECTION_ERROR
518    pub async fn get_station_data(&mut self, identifier: u8) -> Result<StationData, TinkerforgeError> {
519        let mut payload = [0; 1];
520        identifier.write_to_slice(&mut payload[0..1]);
521
522        #[allow(unused_variables)]
523        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetStationData), &payload).await?;
524        Ok(StationData::from_le_byte_slice(result.body()))
525    }
526
527    /// Returns the last measured data for a sensor with the given identifier.
528    /// Call [`get_sensor_identifiers`] for a list of all available identifiers.
529    ///
530    /// The return values are:
531    ///
532    /// * Temperature,
533    /// * Humidity and
534    /// * Last Change (seconds since the last reception of data).
535    pub async fn get_sensor_data(&mut self, identifier: u8) -> Result<SensorData, TinkerforgeError> {
536        let mut payload = [0; 1];
537        identifier.write_to_slice(&mut payload[0..1]);
538
539        #[allow(unused_variables)]
540        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetSensorData), &payload).await?;
541        Ok(SensorData::from_le_byte_slice(result.body()))
542    }
543
544    /// Turns receiver for station data on or off.
545    pub async fn set_station_callback_configuration(&mut self, enable_callback: bool) -> Result<(), TinkerforgeError> {
546        let mut payload = [0; 1];
547        enable_callback.write_to_slice(&mut payload[0..1]);
548
549        #[allow(unused_variables)]
550        let result = self.device.set(u8::from(OutdoorWeatherBrickletFunction::SetStationCallbackConfiguration), &payload).await?;
551        Ok(())
552    }
553
554    /// Returns the configuration as set by [`set_station_callback_configuration`].
555    pub async fn get_station_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
556        let payload = [0; 0];
557
558        #[allow(unused_variables)]
559        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetStationCallbackConfiguration), &payload).await?;
560        Ok(bool::from_le_byte_slice(result.body()))
561    }
562
563    /// Turns receiver for sensor data on or off.
564    pub async fn set_sensor_callback_configuration(&mut self, enable_callback: bool) -> Result<(), TinkerforgeError> {
565        let mut payload = [0; 1];
566        enable_callback.write_to_slice(&mut payload[0..1]);
567
568        #[allow(unused_variables)]
569        let result = self.device.set(u8::from(OutdoorWeatherBrickletFunction::SetSensorCallbackConfiguration), &payload).await?;
570        Ok(())
571    }
572
573    /// Returns the configuration as set by [`set_sensor_callback_configuration`].
574    pub async fn get_sensor_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
575        let payload = [0; 0];
576
577        #[allow(unused_variables)]
578        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetSensorCallbackConfiguration), &payload).await?;
579        Ok(bool::from_le_byte_slice(result.body()))
580    }
581
582    /// Returns the error count for the communication between Brick and Bricklet.
583    ///
584    /// The errors are divided into
585    ///
586    /// * ACK checksum errors,
587    /// * message checksum errors,
588    /// * framing errors and
589    /// * overflow errors.
590    ///
591    /// The errors counts are for errors that occur on the Bricklet side. All
592    /// Bricks have a similar function that returns the errors on the Brick side.
593    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
594        let payload = [0; 0];
595
596        #[allow(unused_variables)]
597        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetSpitfpErrorCount), &payload).await?;
598        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
599    }
600
601    /// Sets the bootloader mode and returns the status after the requested
602    /// mode change was instigated.
603    ///
604    /// You can change from bootloader mode to firmware mode and vice versa. A change
605    /// from bootloader mode to firmware mode will only take place if the entry function,
606    /// device identifier and CRC are present and correct.
607    ///
608    /// This function is used by Brick Viewer during flashing. It should not be
609    /// necessary to call it in a normal user program.
610    ///
611    /// Associated constants:
612    /// * OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
613    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE
614    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
615    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
616    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
617    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_OK
618    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
619    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
620    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
621    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
622    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
623    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
624        let mut payload = [0; 1];
625        mode.write_to_slice(&mut payload[0..1]);
626
627        #[allow(unused_variables)]
628        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::SetBootloaderMode), &payload).await?;
629        Ok(u8::from_le_byte_slice(result.body()))
630    }
631
632    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
633    ///
634    /// Associated constants:
635    /// * OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
636    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE
637    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
638    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
639    ///	* OUTDOOR_WEATHER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
640    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
641        let payload = [0; 0];
642
643        #[allow(unused_variables)]
644        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetBootloaderMode), &payload).await?;
645        Ok(u8::from_le_byte_slice(result.body()))
646    }
647
648    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
649    /// to be increased by chunks of size 64. The data is written to flash
650    /// every 4 chunks (which equals to one page of size 256).
651    ///
652    /// This function is used by Brick Viewer during flashing. It should not be
653    /// necessary to call it in a normal user program.
654    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
655        let mut payload = [0; 4];
656        pointer.write_to_slice(&mut payload[0..4]);
657
658        #[allow(unused_variables)]
659        let result = self.device.set(u8::from(OutdoorWeatherBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
660        Ok(())
661    }
662
663    /// Writes 64 Bytes of firmware at the position as written by
664    /// [`set_write_firmware_pointer`] before. The firmware is written
665    /// to flash every 4 chunks.
666    ///
667    /// You can only write firmware in bootloader mode.
668    ///
669    /// This function is used by Brick Viewer during flashing. It should not be
670    /// necessary to call it in a normal user program.
671    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
672        let mut payload = [0; 64];
673        data.write_to_slice(&mut payload[0..64]);
674
675        #[allow(unused_variables)]
676        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::WriteFirmware), &payload).await?;
677        Ok(u8::from_le_byte_slice(result.body()))
678    }
679
680    /// Sets the status LED configuration. By default the LED shows
681    /// communication traffic between Brick and Bricklet, it flickers once
682    /// for every 10 received data packets.
683    ///
684    /// You can also turn the LED permanently on/off or show a heartbeat.
685    ///
686    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
687    ///
688    /// Associated constants:
689    /// * OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_OFF
690    ///	* OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_ON
691    ///	* OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
692    ///	* OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
693    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
694        let mut payload = [0; 1];
695        config.write_to_slice(&mut payload[0..1]);
696
697        #[allow(unused_variables)]
698        let result = self.device.set(u8::from(OutdoorWeatherBrickletFunction::SetStatusLedConfig), &payload).await?;
699        Ok(())
700    }
701
702    /// Returns the configuration as set by [`set_status_led_config`]
703    ///
704    /// Associated constants:
705    /// * OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_OFF
706    ///	* OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_ON
707    ///	* OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
708    ///	* OUTDOOR_WEATHER_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
709    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
710        let payload = [0; 0];
711
712        #[allow(unused_variables)]
713        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetStatusLedConfig), &payload).await?;
714        Ok(u8::from_le_byte_slice(result.body()))
715    }
716
717    /// Returns the temperature as measured inside the microcontroller. The
718    /// value returned is not the ambient temperature!
719    ///
720    /// The temperature is only proportional to the real temperature and it has bad
721    /// accuracy. Practically it is only useful as an indicator for
722    /// temperature changes.
723    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
724        let payload = [0; 0];
725
726        #[allow(unused_variables)]
727        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetChipTemperature), &payload).await?;
728        Ok(i16::from_le_byte_slice(result.body()))
729    }
730
731    /// Calling this function will reset the Bricklet. All configurations
732    /// will be lost.
733    ///
734    /// After a reset you have to create new device objects,
735    /// calling functions on the existing ones will result in
736    /// undefined behavior!
737    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
738        let payload = [0; 0];
739
740        #[allow(unused_variables)]
741        let result = self.device.set(u8::from(OutdoorWeatherBrickletFunction::Reset), &payload).await?;
742        Ok(())
743    }
744
745    /// Writes a new UID into flash. If you want to set a new UID
746    /// you have to decode the Base58 encoded UID string into an
747    /// integer first.
748    ///
749    /// We recommend that you use Brick Viewer to change the UID.
750    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
751        let mut payload = [0; 4];
752        uid.write_to_slice(&mut payload[0..4]);
753
754        #[allow(unused_variables)]
755        let result = self.device.set(u8::from(OutdoorWeatherBrickletFunction::WriteUid), &payload).await?;
756        Ok(())
757    }
758
759    /// Returns the current UID as an integer. Encode as
760    /// Base58 to get the usual string version.
761    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
762        let payload = [0; 0];
763
764        #[allow(unused_variables)]
765        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::ReadUid), &payload).await?;
766        Ok(u32::from_le_byte_slice(result.body()))
767    }
768
769    /// Returns the UID, the UID where the Bricklet is connected to,
770    /// the position, the hardware and firmware version as well as the
771    /// device identifier.
772    ///
773    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
774    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
775    /// position 'z'.
776    ///
777    /// The device identifier numbers can be found [here](device_identifier).
778    /// |device_identifier_constant|
779    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
780        let payload = [0; 0];
781
782        #[allow(unused_variables)]
783        let result = self.device.get(u8::from(OutdoorWeatherBrickletFunction::GetIdentity), &payload).await?;
784        Ok(Identity::from_le_byte_slice(result.body()))
785    }
786}