tinkerforge_async/bindings/
isolator_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//! Galvanically isolates any Bricklet from any Brick.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/Isolator_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17    low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum IsolatorBrickletFunction {
24    GetStatistics,
25    SetSpitfpBaudrateConfig,
26    GetSpitfpBaudrateConfig,
27    SetSpitfpBaudrate,
28    GetSpitfpBaudrate,
29    GetIsolatorSpitfpErrorCount,
30    SetStatisticsCallbackConfiguration,
31    GetStatisticsCallbackConfiguration,
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    CallbackStatistics,
45}
46impl From<IsolatorBrickletFunction> for u8 {
47    fn from(fun: IsolatorBrickletFunction) -> Self {
48        match fun {
49            IsolatorBrickletFunction::GetStatistics => 1,
50            IsolatorBrickletFunction::SetSpitfpBaudrateConfig => 2,
51            IsolatorBrickletFunction::GetSpitfpBaudrateConfig => 3,
52            IsolatorBrickletFunction::SetSpitfpBaudrate => 4,
53            IsolatorBrickletFunction::GetSpitfpBaudrate => 5,
54            IsolatorBrickletFunction::GetIsolatorSpitfpErrorCount => 6,
55            IsolatorBrickletFunction::SetStatisticsCallbackConfiguration => 7,
56            IsolatorBrickletFunction::GetStatisticsCallbackConfiguration => 8,
57            IsolatorBrickletFunction::GetSpitfpErrorCount => 234,
58            IsolatorBrickletFunction::SetBootloaderMode => 235,
59            IsolatorBrickletFunction::GetBootloaderMode => 236,
60            IsolatorBrickletFunction::SetWriteFirmwarePointer => 237,
61            IsolatorBrickletFunction::WriteFirmware => 238,
62            IsolatorBrickletFunction::SetStatusLedConfig => 239,
63            IsolatorBrickletFunction::GetStatusLedConfig => 240,
64            IsolatorBrickletFunction::GetChipTemperature => 242,
65            IsolatorBrickletFunction::Reset => 243,
66            IsolatorBrickletFunction::WriteUid => 248,
67            IsolatorBrickletFunction::ReadUid => 249,
68            IsolatorBrickletFunction::GetIdentity => 255,
69            IsolatorBrickletFunction::CallbackStatistics => 9,
70        }
71    }
72}
73pub const ISOLATOR_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
74pub const ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
75pub const ISOLATOR_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
76pub const ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
77pub const ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
78pub const ISOLATOR_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
79pub const ISOLATOR_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
80pub const ISOLATOR_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
81pub const ISOLATOR_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
82pub const ISOLATOR_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
83pub const ISOLATOR_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
84pub const ISOLATOR_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
85pub const ISOLATOR_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
86pub const ISOLATOR_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
87pub const ISOLATOR_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
88
89#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
90pub struct Statistics {
91    pub messages_from_brick: u32,
92    pub messages_from_bricklet: u32,
93    pub connected_bricklet_device_identifier: u16,
94    pub connected_bricklet_uid: String,
95}
96impl FromByteSlice for Statistics {
97    fn bytes_expected() -> usize {
98        18
99    }
100    fn from_le_byte_slice(bytes: &[u8]) -> Statistics {
101        Statistics {
102            messages_from_brick: <u32>::from_le_byte_slice(&bytes[0..4]),
103            messages_from_bricklet: <u32>::from_le_byte_slice(&bytes[4..8]),
104            connected_bricklet_device_identifier: <u16>::from_le_byte_slice(&bytes[8..10]),
105            connected_bricklet_uid: <String>::from_le_byte_slice(&bytes[10..18]),
106        }
107    }
108}
109
110#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
111pub struct SpitfpBaudrateConfig {
112    pub enable_dynamic_baudrate: bool,
113    pub minimum_dynamic_baudrate: u32,
114}
115impl FromByteSlice for SpitfpBaudrateConfig {
116    fn bytes_expected() -> usize {
117        5
118    }
119    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpBaudrateConfig {
120        SpitfpBaudrateConfig {
121            enable_dynamic_baudrate: <bool>::from_le_byte_slice(&bytes[0..1]),
122            minimum_dynamic_baudrate: <u32>::from_le_byte_slice(&bytes[1..5]),
123        }
124    }
125}
126
127#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
128pub struct IsolatorSpitfpErrorCount {
129    pub error_count_ack_checksum: u32,
130    pub error_count_message_checksum: u32,
131    pub error_count_frame: u32,
132    pub error_count_overflow: u32,
133}
134impl FromByteSlice for IsolatorSpitfpErrorCount {
135    fn bytes_expected() -> usize {
136        16
137    }
138    fn from_le_byte_slice(bytes: &[u8]) -> IsolatorSpitfpErrorCount {
139        IsolatorSpitfpErrorCount {
140            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
141            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
142            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
143            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
144        }
145    }
146}
147
148#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
149pub struct StatisticsCallbackConfiguration {
150    pub period: u32,
151    pub value_has_to_change: bool,
152}
153impl FromByteSlice for StatisticsCallbackConfiguration {
154    fn bytes_expected() -> usize {
155        5
156    }
157    fn from_le_byte_slice(bytes: &[u8]) -> StatisticsCallbackConfiguration {
158        StatisticsCallbackConfiguration {
159            period: <u32>::from_le_byte_slice(&bytes[0..4]),
160            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
161        }
162    }
163}
164
165#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
166pub struct StatisticsEvent {
167    pub messages_from_brick: u32,
168    pub messages_from_bricklet: u32,
169    pub connected_bricklet_device_identifier: u16,
170    pub connected_bricklet_uid: String,
171}
172impl FromByteSlice for StatisticsEvent {
173    fn bytes_expected() -> usize {
174        18
175    }
176    fn from_le_byte_slice(bytes: &[u8]) -> StatisticsEvent {
177        StatisticsEvent {
178            messages_from_brick: <u32>::from_le_byte_slice(&bytes[0..4]),
179            messages_from_bricklet: <u32>::from_le_byte_slice(&bytes[4..8]),
180            connected_bricklet_device_identifier: <u16>::from_le_byte_slice(&bytes[8..10]),
181            connected_bricklet_uid: <String>::from_le_byte_slice(&bytes[10..18]),
182        }
183    }
184}
185
186#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
187pub struct SpitfpErrorCount {
188    pub error_count_ack_checksum: u32,
189    pub error_count_message_checksum: u32,
190    pub error_count_frame: u32,
191    pub error_count_overflow: u32,
192}
193impl FromByteSlice for SpitfpErrorCount {
194    fn bytes_expected() -> usize {
195        16
196    }
197    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
198        SpitfpErrorCount {
199            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
200            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
201            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
202            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
203        }
204    }
205}
206
207#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
208pub struct Identity {
209    pub uid: String,
210    pub connected_uid: String,
211    pub position: char,
212    pub hardware_version: [u8; 3],
213    pub firmware_version: [u8; 3],
214    pub device_identifier: u16,
215}
216impl FromByteSlice for Identity {
217    fn bytes_expected() -> usize {
218        25
219    }
220    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
221        Identity {
222            uid: <String>::from_le_byte_slice(&bytes[0..8]),
223            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
224            position: <char>::from_le_byte_slice(&bytes[16..17]),
225            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
226            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
227            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
228        }
229    }
230}
231
232/// Galvanically isolates any Bricklet from any Brick
233#[derive(Clone)]
234pub struct IsolatorBricklet {
235    device: Device,
236}
237impl IsolatorBricklet {
238    pub const DEVICE_IDENTIFIER: u16 = 2122;
239    pub const DEVICE_DISPLAY_NAME: &'static str = "Isolator Bricklet";
240    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
241    pub fn new(uid: Uid, connection: AsyncIpConnection) -> IsolatorBricklet {
242        let mut result = IsolatorBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
243        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetStatistics) as usize] = ResponseExpectedFlag::AlwaysTrue;
244        result.device.response_expected[u8::from(IsolatorBrickletFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
245        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetSpitfpBaudrateConfig) as usize] =
246            ResponseExpectedFlag::AlwaysTrue;
247        result.device.response_expected[u8::from(IsolatorBrickletFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
248        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
249        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetIsolatorSpitfpErrorCount) as usize] =
250            ResponseExpectedFlag::AlwaysTrue;
251        result.device.response_expected[u8::from(IsolatorBrickletFunction::SetStatisticsCallbackConfiguration) as usize] =
252            ResponseExpectedFlag::True;
253        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetStatisticsCallbackConfiguration) as usize] =
254            ResponseExpectedFlag::AlwaysTrue;
255        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetSpitfpErrorCount) as usize] =
256            ResponseExpectedFlag::AlwaysTrue;
257        result.device.response_expected[u8::from(IsolatorBrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
258        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
259        result.device.response_expected[u8::from(IsolatorBrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
260        result.device.response_expected[u8::from(IsolatorBrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
261        result.device.response_expected[u8::from(IsolatorBrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
262        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
263        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
264        result.device.response_expected[u8::from(IsolatorBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
265        result.device.response_expected[u8::from(IsolatorBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
266        result.device.response_expected[u8::from(IsolatorBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
267        result.device.response_expected[u8::from(IsolatorBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
268        result
269    }
270
271    /// Returns the response expected flag for the function specified by the function ID parameter.
272    /// It is true if the function is expected to send a response, false otherwise.
273    ///
274    /// For getter functions this is enabled by default and cannot be disabled, because those
275    /// functions will always send a response. For callback configuration functions it is enabled
276    /// by default too, but can be disabled by [`set_response_expected`](crate::isolator_bricklet::IsolatorBricklet::set_response_expected).
277    /// For setter functions it is disabled by default and can be enabled.
278    ///
279    /// Enabling the response expected flag for a setter function allows to detect timeouts
280    /// and other error conditions calls of this setter as well. The device will then send a response
281    /// for this purpose. If this flag is disabled for a setter function then no response is sent
282    /// and errors are silently ignored, because they cannot be detected.
283    ///
284    /// See [`set_response_expected`](crate::isolator_bricklet::IsolatorBricklet::set_response_expected) for the list of function ID constants available for this function.
285    pub fn get_response_expected(&mut self, fun: IsolatorBrickletFunction) -> Result<bool, GetResponseExpectedError> {
286        self.device.get_response_expected(u8::from(fun))
287    }
288
289    /// Changes the response expected flag of the function specified by the function ID parameter.
290    /// This flag can only be changed for setter (default value: false) and callback configuration
291    /// functions (default value: true). For getter functions it is always enabled.
292    ///
293    /// Enabling the response expected flag for a setter function allows to detect timeouts and
294    /// other error conditions calls of this setter as well. The device will then send a response
295    /// for this purpose. If this flag is disabled for a setter function then no response is sent
296    /// and errors are silently ignored, because they cannot be detected.
297    pub fn set_response_expected(
298        &mut self,
299        fun: IsolatorBrickletFunction,
300        response_expected: bool,
301    ) -> Result<(), SetResponseExpectedError> {
302        self.device.set_response_expected(u8::from(fun), response_expected)
303    }
304
305    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
306    pub fn set_response_expected_all(&mut self, response_expected: bool) {
307        self.device.set_response_expected_all(response_expected)
308    }
309
310    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
311    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
312    pub fn get_api_version(&self) -> [u8; 3] {
313        self.device.api_version
314    }
315
316    /// This receiver is triggered periodically according to the configuration set by
317    /// [`set_statistics_callback_configuration`].
318    ///
319    /// The parameters are the same as [`get_statistics`].
320    ///
321    /// [`get_statistics`]: #method.get_statistics
322    /// [`set_statistics_callback_configuration`]: #method.set_statistics_callback_configuration
323    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
324    pub async fn get_statistics_callback_receiver(&mut self) -> impl Stream<Item = StatisticsEvent> {
325        self.device
326            .get_callback_receiver(u8::from(IsolatorBrickletFunction::CallbackStatistics))
327            .await
328            .map(|p| StatisticsEvent::from_le_byte_slice(p.body()))
329    }
330
331    /// Returns statistics for the Isolator Bricklet.
332    pub async fn get_statistics(&mut self) -> Result<Statistics, TinkerforgeError> {
333        let payload = [0; 0];
334
335        #[allow(unused_variables)]
336        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetStatistics), &payload).await?;
337        Ok(Statistics::from_le_byte_slice(result.body()))
338    }
339
340    /// The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is
341    /// enabled, the Isolator Bricklet will try to adapt the baudrate for the communication
342    /// between Bricks and Bricklets according to the amount of data that is transferred.
343    ///
344    /// The baudrate for communication config between
345    /// Brick and Isolator Bricklet can be set through the API of the Brick.
346    ///
347    /// The baudrate will be increased exponentially if lots of data is sent/received and
348    /// decreased linearly if little data is sent/received.
349    ///
350    /// This lowers the baudrate in applications where little data is transferred (e.g.
351    /// a weather station) and increases the robustness. If there is lots of data to transfer
352    /// (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.
353    ///
354    /// In cases where some data has to transferred as fast as possible every few seconds
355    /// (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn
356    /// the dynamic baudrate off to get the highest possible performance.
357    ///
358    /// The maximum value of the baudrate can be set per port with the function
359    /// [`set_spitfp_baudrate`]. If the dynamic baudrate is disabled, the baudrate
360    /// as set by [`set_spitfp_baudrate`] will be used statically.
361    pub async fn set_spitfp_baudrate_config(
362        &mut self,
363        enable_dynamic_baudrate: bool,
364        minimum_dynamic_baudrate: u32,
365    ) -> Result<(), TinkerforgeError> {
366        let mut payload = [0; 5];
367        enable_dynamic_baudrate.write_to_slice(&mut payload[0..1]);
368        minimum_dynamic_baudrate.write_to_slice(&mut payload[1..5]);
369
370        #[allow(unused_variables)]
371        let result = self.device.set(u8::from(IsolatorBrickletFunction::SetSpitfpBaudrateConfig), &payload).await?;
372        Ok(())
373    }
374
375    /// Returns the baudrate config, see [`set_spitfp_baudrate_config`].
376    pub async fn get_spitfp_baudrate_config(&mut self) -> Result<SpitfpBaudrateConfig, TinkerforgeError> {
377        let payload = [0; 0];
378
379        #[allow(unused_variables)]
380        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetSpitfpBaudrateConfig), &payload).await?;
381        Ok(SpitfpBaudrateConfig::from_le_byte_slice(result.body()))
382    }
383
384    /// Sets the baudrate for a the communication between Isolator Bricklet
385    /// and the connected Bricklet. The baudrate for communication between
386    /// Brick and Isolator Bricklet can be set through the API of the Brick.
387    ///
388    /// If you want to increase the throughput of Bricklets you can increase
389    /// the baudrate. If you get a high error count because of high
390    /// interference (see [`get_spitfp_error_count`]) you can decrease the
391    /// baudrate.
392    ///
393    /// If the dynamic baudrate feature is enabled, the baudrate set by this
394    /// function corresponds to the maximum baudrate (see [`set_spitfp_baudrate_config`]).
395    ///
396    /// Regulatory testing is done with the default baudrate. If CE compatibility
397    /// or similar is necessary in your applications we recommend to not change
398    /// the baudrate.
399    pub async fn set_spitfp_baudrate(&mut self, baudrate: u32) -> Result<(), TinkerforgeError> {
400        let mut payload = [0; 4];
401        baudrate.write_to_slice(&mut payload[0..4]);
402
403        #[allow(unused_variables)]
404        let result = self.device.set(u8::from(IsolatorBrickletFunction::SetSpitfpBaudrate), &payload).await?;
405        Ok(())
406    }
407
408    /// Returns the baudrate, see [`set_spitfp_baudrate`].
409    pub async fn get_spitfp_baudrate(&mut self) -> Result<u32, TinkerforgeError> {
410        let payload = [0; 0];
411
412        #[allow(unused_variables)]
413        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetSpitfpBaudrate), &payload).await?;
414        Ok(u32::from_le_byte_slice(result.body()))
415    }
416
417    /// Returns the error count for the communication between Isolator Bricklet and
418    /// the connected Bricklet. Call [`get_spitfp_error_count`] to get the
419    /// error count between Isolator Bricklet and Brick.
420    ///
421    /// The errors are divided into
422    ///
423    /// * ACK checksum errors,
424    /// * message checksum errors,
425    /// * framing errors and
426    /// * overflow errors.
427    pub async fn get_isolator_spitfp_error_count(&mut self) -> Result<IsolatorSpitfpErrorCount, TinkerforgeError> {
428        let payload = [0; 0];
429
430        #[allow(unused_variables)]
431        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetIsolatorSpitfpErrorCount), &payload).await?;
432        Ok(IsolatorSpitfpErrorCount::from_le_byte_slice(result.body()))
433    }
434
435    /// The period is the period with which the [`get_statistics_callback_receiver`]
436    /// receiver is triggered periodically. A value of 0 turns the receiver off.
437    ///
438    /// If the `value has to change`-parameter is set to true, the receiver is only
439    /// triggered after the value has changed. If the value didn't change within the
440    /// period, the receiver is triggered immediately on change.
441    ///
442    /// If it is set to false, the receiver is continuously triggered with the period,
443    /// independent of the value.
444    ///
445    ///
446    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
447    pub async fn set_statistics_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
448        let mut payload = [0; 5];
449        period.write_to_slice(&mut payload[0..4]);
450        value_has_to_change.write_to_slice(&mut payload[4..5]);
451
452        #[allow(unused_variables)]
453        let result = self.device.set(u8::from(IsolatorBrickletFunction::SetStatisticsCallbackConfiguration), &payload).await?;
454        Ok(())
455    }
456
457    /// Returns the receiver configuration as set by
458    /// [`set_statistics_callback_configuration`].
459    ///
460    ///
461    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
462    pub async fn get_statistics_callback_configuration(&mut self) -> Result<StatisticsCallbackConfiguration, TinkerforgeError> {
463        let payload = [0; 0];
464
465        #[allow(unused_variables)]
466        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetStatisticsCallbackConfiguration), &payload).await?;
467        Ok(StatisticsCallbackConfiguration::from_le_byte_slice(result.body()))
468    }
469
470    /// Returns the error count for the communication between Brick and Bricklet.
471    ///
472    /// The errors are divided into
473    ///
474    /// * ACK checksum errors,
475    /// * message checksum errors,
476    /// * framing errors and
477    /// * overflow errors.
478    ///
479    /// The errors counts are for errors that occur on the Bricklet side. All
480    /// Bricks have a similar function that returns the errors on the Brick side.
481    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
482        let payload = [0; 0];
483
484        #[allow(unused_variables)]
485        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetSpitfpErrorCount), &payload).await?;
486        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
487    }
488
489    /// Sets the bootloader mode and returns the status after the requested
490    /// mode change was instigated.
491    ///
492    /// You can change from bootloader mode to firmware mode and vice versa. A change
493    /// from bootloader mode to firmware mode will only take place if the entry function,
494    /// device identifier and CRC are present and correct.
495    ///
496    /// This function is used by Brick Viewer during flashing. It should not be
497    /// necessary to call it in a normal user program.
498    ///
499    /// Associated constants:
500    /// * ISOLATOR_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
501    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE
502    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
503    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
504    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
505    ///	* ISOLATOR_BRICKLET_BOOTLOADER_STATUS_OK
506    ///	* ISOLATOR_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
507    ///	* ISOLATOR_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
508    ///	* ISOLATOR_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
509    ///	* ISOLATOR_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
510    ///	* ISOLATOR_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
511    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
512        let mut payload = [0; 1];
513        mode.write_to_slice(&mut payload[0..1]);
514
515        #[allow(unused_variables)]
516        let result = self.device.get(u8::from(IsolatorBrickletFunction::SetBootloaderMode), &payload).await?;
517        Ok(u8::from_le_byte_slice(result.body()))
518    }
519
520    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
521    ///
522    /// Associated constants:
523    /// * ISOLATOR_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
524    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE
525    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
526    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
527    ///	* ISOLATOR_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
528    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
529        let payload = [0; 0];
530
531        #[allow(unused_variables)]
532        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetBootloaderMode), &payload).await?;
533        Ok(u8::from_le_byte_slice(result.body()))
534    }
535
536    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
537    /// to be increased by chunks of size 64. The data is written to flash
538    /// every 4 chunks (which equals to one page of size 256).
539    ///
540    /// This function is used by Brick Viewer during flashing. It should not be
541    /// necessary to call it in a normal user program.
542    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
543        let mut payload = [0; 4];
544        pointer.write_to_slice(&mut payload[0..4]);
545
546        #[allow(unused_variables)]
547        let result = self.device.set(u8::from(IsolatorBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
548        Ok(())
549    }
550
551    /// Writes 64 Bytes of firmware at the position as written by
552    /// [`set_write_firmware_pointer`] before. The firmware is written
553    /// to flash every 4 chunks.
554    ///
555    /// You can only write firmware in bootloader mode.
556    ///
557    /// This function is used by Brick Viewer during flashing. It should not be
558    /// necessary to call it in a normal user program.
559    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
560        let mut payload = [0; 64];
561        data.write_to_slice(&mut payload[0..64]);
562
563        #[allow(unused_variables)]
564        let result = self.device.get(u8::from(IsolatorBrickletFunction::WriteFirmware), &payload).await?;
565        Ok(u8::from_le_byte_slice(result.body()))
566    }
567
568    /// Sets the status LED configuration. By default the LED shows
569    /// communication traffic between Brick and Bricklet, it flickers once
570    /// for every 10 received data packets.
571    ///
572    /// You can also turn the LED permanently on/off or show a heartbeat.
573    ///
574    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
575    ///
576    /// Associated constants:
577    /// * ISOLATOR_BRICKLET_STATUS_LED_CONFIG_OFF
578    ///	* ISOLATOR_BRICKLET_STATUS_LED_CONFIG_ON
579    ///	* ISOLATOR_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
580    ///	* ISOLATOR_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
581    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
582        let mut payload = [0; 1];
583        config.write_to_slice(&mut payload[0..1]);
584
585        #[allow(unused_variables)]
586        let result = self.device.set(u8::from(IsolatorBrickletFunction::SetStatusLedConfig), &payload).await?;
587        Ok(())
588    }
589
590    /// Returns the configuration as set by [`set_status_led_config`]
591    ///
592    /// Associated constants:
593    /// * ISOLATOR_BRICKLET_STATUS_LED_CONFIG_OFF
594    ///	* ISOLATOR_BRICKLET_STATUS_LED_CONFIG_ON
595    ///	* ISOLATOR_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
596    ///	* ISOLATOR_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
597    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
598        let payload = [0; 0];
599
600        #[allow(unused_variables)]
601        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetStatusLedConfig), &payload).await?;
602        Ok(u8::from_le_byte_slice(result.body()))
603    }
604
605    /// Returns the temperature as measured inside the microcontroller. The
606    /// value returned is not the ambient temperature!
607    ///
608    /// The temperature is only proportional to the real temperature and it has bad
609    /// accuracy. Practically it is only useful as an indicator for
610    /// temperature changes.
611    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
612        let payload = [0; 0];
613
614        #[allow(unused_variables)]
615        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetChipTemperature), &payload).await?;
616        Ok(i16::from_le_byte_slice(result.body()))
617    }
618
619    /// Calling this function will reset the Bricklet. All configurations
620    /// will be lost.
621    ///
622    /// After a reset you have to create new device objects,
623    /// calling functions on the existing ones will result in
624    /// undefined behavior!
625    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
626        let payload = [0; 0];
627
628        #[allow(unused_variables)]
629        let result = self.device.set(u8::from(IsolatorBrickletFunction::Reset), &payload).await?;
630        Ok(())
631    }
632
633    /// Writes a new UID into flash. If you want to set a new UID
634    /// you have to decode the Base58 encoded UID string into an
635    /// integer first.
636    ///
637    /// We recommend that you use Brick Viewer to change the UID.
638    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
639        let mut payload = [0; 4];
640        uid.write_to_slice(&mut payload[0..4]);
641
642        #[allow(unused_variables)]
643        let result = self.device.set(u8::from(IsolatorBrickletFunction::WriteUid), &payload).await?;
644        Ok(())
645    }
646
647    /// Returns the current UID as an integer. Encode as
648    /// Base58 to get the usual string version.
649    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
650        let payload = [0; 0];
651
652        #[allow(unused_variables)]
653        let result = self.device.get(u8::from(IsolatorBrickletFunction::ReadUid), &payload).await?;
654        Ok(u32::from_le_byte_slice(result.body()))
655    }
656
657    /// Returns the UID, the UID where the Bricklet is connected to,
658    /// the position, the hardware and firmware version as well as the
659    /// device identifier.
660    ///
661    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
662    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
663    /// position 'z'.
664    ///
665    /// The device identifier numbers can be found [here](device_identifier).
666    /// |device_identifier_constant|
667    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
668        let payload = [0; 0];
669
670        #[allow(unused_variables)]
671        let result = self.device.get(u8::from(IsolatorBrickletFunction::GetIdentity), &payload).await?;
672        Ok(Identity::from_le_byte_slice(result.body()))
673    }
674}