tinkerforge_async/bindings/esp32_ethernet_brick.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//! ESP32 microcontroller based Brick with Ethernet and 6 Bricklet ports.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricks/ESP32Ethernet_Brick_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 Esp32EthernetBrickFunction {
24 GetIdentity,
25}
26impl From<Esp32EthernetBrickFunction> for u8 {
27 fn from(fun: Esp32EthernetBrickFunction) -> Self {
28 match fun {
29 Esp32EthernetBrickFunction::GetIdentity => 255,
30 }
31 }
32}
33
34#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
35pub struct Identity {
36 pub uid: String,
37 pub connected_uid: String,
38 pub position: char,
39 pub hardware_version: [u8; 3],
40 pub firmware_version: [u8; 3],
41 pub device_identifier: u16,
42}
43impl FromByteSlice for Identity {
44 fn bytes_expected() -> usize {
45 25
46 }
47 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
48 Identity {
49 uid: <String>::from_le_byte_slice(&bytes[0..8]),
50 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
51 position: <char>::from_le_byte_slice(&bytes[16..17]),
52 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
53 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
54 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
55 }
56 }
57}
58
59/// ESP32 microcontroller based Brick with Ethernet and 6 Bricklet ports
60#[derive(Clone)]
61pub struct Esp32EthernetBrick {
62 device: Device,
63}
64impl Esp32EthernetBrick {
65 pub const DEVICE_IDENTIFIER: u16 = 115;
66 pub const DEVICE_DISPLAY_NAME: &'static str = "ESP32 Ethernet Brick";
67 /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
68 pub fn new(uid: Uid, connection: AsyncIpConnection) -> Esp32EthernetBrick {
69 let mut result = Esp32EthernetBrick { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
70 result.device.response_expected[u8::from(Esp32EthernetBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
71 result
72 }
73
74 /// Returns the response expected flag for the function specified by the function ID parameter.
75 /// It is true if the function is expected to send a response, false otherwise.
76 ///
77 /// For getter functions this is enabled by default and cannot be disabled, because those
78 /// functions will always send a response. For callback configuration functions it is enabled
79 /// by default too, but can be disabled by [`set_response_expected`](crate::esp32_ethernet_brick::Esp32EthernetBrick::set_response_expected).
80 /// For setter functions it is disabled by default and can be enabled.
81 ///
82 /// Enabling the response expected flag for a setter function allows to detect timeouts
83 /// and other error conditions calls of this setter as well. The device will then send a response
84 /// for this purpose. If this flag is disabled for a setter function then no response is sent
85 /// and errors are silently ignored, because they cannot be detected.
86 ///
87 /// See [`set_response_expected`](crate::esp32_ethernet_brick::Esp32EthernetBrick::set_response_expected) for the list of function ID constants available for this function.
88 pub fn get_response_expected(&mut self, fun: Esp32EthernetBrickFunction) -> Result<bool, GetResponseExpectedError> {
89 self.device.get_response_expected(u8::from(fun))
90 }
91
92 /// Changes the response expected flag of the function specified by the function ID parameter.
93 /// This flag can only be changed for setter (default value: false) and callback configuration
94 /// functions (default value: true). For getter functions it is always enabled.
95 ///
96 /// Enabling the response expected flag for a setter function allows to detect timeouts and
97 /// other error conditions calls of this setter as well. The device will then send a response
98 /// for this purpose. If this flag is disabled for a setter function then no response is sent
99 /// and errors are silently ignored, because they cannot be detected.
100 pub fn set_response_expected(
101 &mut self,
102 fun: Esp32EthernetBrickFunction,
103 response_expected: bool,
104 ) -> Result<(), SetResponseExpectedError> {
105 self.device.set_response_expected(u8::from(fun), response_expected)
106 }
107
108 /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
109 pub fn set_response_expected_all(&mut self, response_expected: bool) {
110 self.device.set_response_expected_all(response_expected)
111 }
112
113 /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
114 /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
115 pub fn get_api_version(&self) -> [u8; 3] {
116 self.device.api_version
117 }
118
119 /// Returns the UID, the UID where the Brick is connected to,
120 /// the position, the hardware and firmware version as well as the
121 /// device identifier.
122 ///
123 /// The position is the position in the stack from '0' (bottom) to '8' (top).
124 ///
125 /// The device identifier numbers can be found [here](device_identifier).
126 /// |device_identifier_constant|
127 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
128 let payload = [0; 0];
129
130 #[allow(unused_variables)]
131 let result = self.device.get(u8::from(Esp32EthernetBrickFunction::GetIdentity), &payload).await?;
132 Ok(Identity::from_le_byte_slice(result.body()))
133 }
134}