tinkerforge_async/bindings/
real_time_clock_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//! Battery-backed real-time clock.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/RealTimeClock_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 RealTimeClockBrickletFunction {
24    SetDateTime,
25    GetDateTime,
26    GetTimestamp,
27    SetOffset,
28    GetOffset,
29    SetDateTimeCallbackPeriod,
30    GetDateTimeCallbackPeriod,
31    SetAlarm,
32    GetAlarm,
33    GetIdentity,
34    CallbackDateTime,
35    CallbackAlarm,
36}
37impl From<RealTimeClockBrickletFunction> for u8 {
38    fn from(fun: RealTimeClockBrickletFunction) -> Self {
39        match fun {
40            RealTimeClockBrickletFunction::SetDateTime => 1,
41            RealTimeClockBrickletFunction::GetDateTime => 2,
42            RealTimeClockBrickletFunction::GetTimestamp => 3,
43            RealTimeClockBrickletFunction::SetOffset => 4,
44            RealTimeClockBrickletFunction::GetOffset => 5,
45            RealTimeClockBrickletFunction::SetDateTimeCallbackPeriod => 6,
46            RealTimeClockBrickletFunction::GetDateTimeCallbackPeriod => 7,
47            RealTimeClockBrickletFunction::SetAlarm => 8,
48            RealTimeClockBrickletFunction::GetAlarm => 9,
49            RealTimeClockBrickletFunction::GetIdentity => 255,
50            RealTimeClockBrickletFunction::CallbackDateTime => 10,
51            RealTimeClockBrickletFunction::CallbackAlarm => 11,
52        }
53    }
54}
55pub const REAL_TIME_CLOCK_BRICKLET_WEEKDAY_MONDAY: u8 = 1;
56pub const REAL_TIME_CLOCK_BRICKLET_WEEKDAY_TUESDAY: u8 = 2;
57pub const REAL_TIME_CLOCK_BRICKLET_WEEKDAY_WEDNESDAY: u8 = 3;
58pub const REAL_TIME_CLOCK_BRICKLET_WEEKDAY_THURSDAY: u8 = 4;
59pub const REAL_TIME_CLOCK_BRICKLET_WEEKDAY_FRIDAY: u8 = 5;
60pub const REAL_TIME_CLOCK_BRICKLET_WEEKDAY_SATURDAY: u8 = 6;
61pub const REAL_TIME_CLOCK_BRICKLET_WEEKDAY_SUNDAY: u8 = 7;
62pub const REAL_TIME_CLOCK_BRICKLET_ALARM_MATCH_DISABLED: i8 = -1;
63pub const REAL_TIME_CLOCK_BRICKLET_ALARM_INTERVAL_DISABLED: i32 = -1;
64
65#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
66pub struct DateTime {
67    pub year: u16,
68    pub month: u8,
69    pub day: u8,
70    pub hour: u8,
71    pub minute: u8,
72    pub second: u8,
73    pub centisecond: u8,
74    pub weekday: u8,
75}
76impl FromByteSlice for DateTime {
77    fn bytes_expected() -> usize {
78        9
79    }
80    fn from_le_byte_slice(bytes: &[u8]) -> DateTime {
81        DateTime {
82            year: <u16>::from_le_byte_slice(&bytes[0..2]),
83            month: <u8>::from_le_byte_slice(&bytes[2..3]),
84            day: <u8>::from_le_byte_slice(&bytes[3..4]),
85            hour: <u8>::from_le_byte_slice(&bytes[4..5]),
86            minute: <u8>::from_le_byte_slice(&bytes[5..6]),
87            second: <u8>::from_le_byte_slice(&bytes[6..7]),
88            centisecond: <u8>::from_le_byte_slice(&bytes[7..8]),
89            weekday: <u8>::from_le_byte_slice(&bytes[8..9]),
90        }
91    }
92}
93
94#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
95pub struct Alarm {
96    pub month: i8,
97    pub day: i8,
98    pub hour: i8,
99    pub minute: i8,
100    pub second: i8,
101    pub weekday: i8,
102    pub interval: i32,
103}
104impl FromByteSlice for Alarm {
105    fn bytes_expected() -> usize {
106        10
107    }
108    fn from_le_byte_slice(bytes: &[u8]) -> Alarm {
109        Alarm {
110            month: <i8>::from_le_byte_slice(&bytes[0..1]),
111            day: <i8>::from_le_byte_slice(&bytes[1..2]),
112            hour: <i8>::from_le_byte_slice(&bytes[2..3]),
113            minute: <i8>::from_le_byte_slice(&bytes[3..4]),
114            second: <i8>::from_le_byte_slice(&bytes[4..5]),
115            weekday: <i8>::from_le_byte_slice(&bytes[5..6]),
116            interval: <i32>::from_le_byte_slice(&bytes[6..10]),
117        }
118    }
119}
120
121#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
122pub struct DateTimeEvent {
123    pub year: u16,
124    pub month: u8,
125    pub day: u8,
126    pub hour: u8,
127    pub minute: u8,
128    pub second: u8,
129    pub centisecond: u8,
130    pub weekday: u8,
131    pub timestamp: i64,
132}
133impl FromByteSlice for DateTimeEvent {
134    fn bytes_expected() -> usize {
135        17
136    }
137    fn from_le_byte_slice(bytes: &[u8]) -> DateTimeEvent {
138        DateTimeEvent {
139            year: <u16>::from_le_byte_slice(&bytes[0..2]),
140            month: <u8>::from_le_byte_slice(&bytes[2..3]),
141            day: <u8>::from_le_byte_slice(&bytes[3..4]),
142            hour: <u8>::from_le_byte_slice(&bytes[4..5]),
143            minute: <u8>::from_le_byte_slice(&bytes[5..6]),
144            second: <u8>::from_le_byte_slice(&bytes[6..7]),
145            centisecond: <u8>::from_le_byte_slice(&bytes[7..8]),
146            weekday: <u8>::from_le_byte_slice(&bytes[8..9]),
147            timestamp: <i64>::from_le_byte_slice(&bytes[9..17]),
148        }
149    }
150}
151
152#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
153pub struct AlarmEvent {
154    pub year: u16,
155    pub month: u8,
156    pub day: u8,
157    pub hour: u8,
158    pub minute: u8,
159    pub second: u8,
160    pub centisecond: u8,
161    pub weekday: u8,
162    pub timestamp: i64,
163}
164impl FromByteSlice for AlarmEvent {
165    fn bytes_expected() -> usize {
166        17
167    }
168    fn from_le_byte_slice(bytes: &[u8]) -> AlarmEvent {
169        AlarmEvent {
170            year: <u16>::from_le_byte_slice(&bytes[0..2]),
171            month: <u8>::from_le_byte_slice(&bytes[2..3]),
172            day: <u8>::from_le_byte_slice(&bytes[3..4]),
173            hour: <u8>::from_le_byte_slice(&bytes[4..5]),
174            minute: <u8>::from_le_byte_slice(&bytes[5..6]),
175            second: <u8>::from_le_byte_slice(&bytes[6..7]),
176            centisecond: <u8>::from_le_byte_slice(&bytes[7..8]),
177            weekday: <u8>::from_le_byte_slice(&bytes[8..9]),
178            timestamp: <i64>::from_le_byte_slice(&bytes[9..17]),
179        }
180    }
181}
182
183#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
184pub struct Identity {
185    pub uid: String,
186    pub connected_uid: String,
187    pub position: char,
188    pub hardware_version: [u8; 3],
189    pub firmware_version: [u8; 3],
190    pub device_identifier: u16,
191}
192impl FromByteSlice for Identity {
193    fn bytes_expected() -> usize {
194        25
195    }
196    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
197        Identity {
198            uid: <String>::from_le_byte_slice(&bytes[0..8]),
199            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
200            position: <char>::from_le_byte_slice(&bytes[16..17]),
201            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
202            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
203            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
204        }
205    }
206}
207
208/// Battery-backed real-time clock
209#[derive(Clone)]
210pub struct RealTimeClockBricklet {
211    device: Device,
212}
213impl RealTimeClockBricklet {
214    pub const DEVICE_IDENTIFIER: u16 = 268;
215    pub const DEVICE_DISPLAY_NAME: &'static str = "Real-Time Clock Bricklet";
216    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
217    pub fn new(uid: Uid, connection: AsyncIpConnection) -> RealTimeClockBricklet {
218        let mut result = RealTimeClockBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
219        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::SetDateTime) as usize] = ResponseExpectedFlag::False;
220        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::GetDateTime) as usize] = ResponseExpectedFlag::AlwaysTrue;
221        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::GetTimestamp) as usize] = ResponseExpectedFlag::AlwaysTrue;
222        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::SetOffset) as usize] = ResponseExpectedFlag::False;
223        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::GetOffset) as usize] = ResponseExpectedFlag::AlwaysTrue;
224        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::SetDateTimeCallbackPeriod) as usize] =
225            ResponseExpectedFlag::True;
226        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::GetDateTimeCallbackPeriod) as usize] =
227            ResponseExpectedFlag::AlwaysTrue;
228        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::SetAlarm) as usize] = ResponseExpectedFlag::True;
229        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::GetAlarm) as usize] = ResponseExpectedFlag::AlwaysTrue;
230        result.device.response_expected[u8::from(RealTimeClockBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
231        result
232    }
233
234    /// Returns the response expected flag for the function specified by the function ID parameter.
235    /// It is true if the function is expected to send a response, false otherwise.
236    ///
237    /// For getter functions this is enabled by default and cannot be disabled, because those
238    /// functions will always send a response. For callback configuration functions it is enabled
239    /// by default too, but can be disabled by [`set_response_expected`](crate::real_time_clock_bricklet::RealTimeClockBricklet::set_response_expected).
240    /// For setter functions it is disabled by default and can be enabled.
241    ///
242    /// Enabling the response expected flag for a setter function allows to detect timeouts
243    /// and other error conditions calls of this setter as well. The device will then send a response
244    /// for this purpose. If this flag is disabled for a setter function then no response is sent
245    /// and errors are silently ignored, because they cannot be detected.
246    ///
247    /// See [`set_response_expected`](crate::real_time_clock_bricklet::RealTimeClockBricklet::set_response_expected) for the list of function ID constants available for this function.
248    pub fn get_response_expected(&mut self, fun: RealTimeClockBrickletFunction) -> Result<bool, GetResponseExpectedError> {
249        self.device.get_response_expected(u8::from(fun))
250    }
251
252    /// Changes the response expected flag of the function specified by the function ID parameter.
253    /// This flag can only be changed for setter (default value: false) and callback configuration
254    /// functions (default value: true). For getter functions it is always enabled.
255    ///
256    /// Enabling the response expected flag for a setter function allows to detect timeouts and
257    /// other error conditions calls of this setter as well. The device will then send a response
258    /// for this purpose. If this flag is disabled for a setter function then no response is sent
259    /// and errors are silently ignored, because they cannot be detected.
260    pub fn set_response_expected(
261        &mut self,
262        fun: RealTimeClockBrickletFunction,
263        response_expected: bool,
264    ) -> Result<(), SetResponseExpectedError> {
265        self.device.set_response_expected(u8::from(fun), response_expected)
266    }
267
268    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
269    pub fn set_response_expected_all(&mut self, response_expected: bool) {
270        self.device.set_response_expected_all(response_expected)
271    }
272
273    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
274    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
275    pub fn get_api_version(&self) -> [u8; 3] {
276        self.device.api_version
277    }
278
279    /// This receiver is triggered periodically with the period that is set by
280    /// [`set_date_time_callback_period`]. The parameters are the same
281    /// as for [`get_date_time`] and [`get_timestamp`] combined.
282    ///
283    /// The [`get_date_time_callback_receiver`] receiver is only triggered if the date or time changed
284    /// since the last triggering.
285    ///
286    /// [`get_date_time`]: #method.get_date_time
287    /// [`get_timestamp`]: #method.get_timestamp
288    /// [`set_date_time_callback_period`]: #method.set_date_time_callback_period
289    /// [`get_date_time_callback_receiver`]: #method.get_date_time_callback_receiver
290    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
291    pub async fn get_date_time_callback_receiver(&mut self) -> impl Stream<Item = DateTimeEvent> {
292        self.device
293            .get_callback_receiver(u8::from(RealTimeClockBrickletFunction::CallbackDateTime))
294            .await
295            .map(|p| DateTimeEvent::from_le_byte_slice(p.body()))
296    }
297
298    /// This receiver is triggered every time the current date and time matches the
299    /// configured alarm (see [`set_alarm`]). The parameters are the same
300    /// as for [`get_date_time`] and [`get_timestamp`] combined.
301    ///
302    ///
303    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
304    pub async fn get_alarm_callback_receiver(&mut self) -> impl Stream<Item = AlarmEvent> {
305        self.device
306            .get_callback_receiver(u8::from(RealTimeClockBrickletFunction::CallbackAlarm))
307            .await
308            .map(|p| AlarmEvent::from_le_byte_slice(p.body()))
309    }
310
311    /// Sets the current date (including weekday) and the current time.
312    ///
313    /// If the backup battery is installed then the real-time clock keeps date and
314    /// time even if the Bricklet is not powered by a Brick.
315    ///
316    /// The real-time clock handles leap year and inserts the 29th of February
317    /// accordingly. But leap seconds, time zones and daylight saving time are not
318    /// handled.
319    ///
320    /// Associated constants:
321    /// * REAL_TIME_CLOCK_BRICKLET_WEEKDAY_MONDAY
322    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_TUESDAY
323    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_WEDNESDAY
324    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_THURSDAY
325    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_FRIDAY
326    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_SATURDAY
327    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_SUNDAY
328    pub async fn set_date_time(
329        &mut self,
330        year: u16,
331        month: u8,
332        day: u8,
333        hour: u8,
334        minute: u8,
335        second: u8,
336        centisecond: u8,
337        weekday: u8,
338    ) -> Result<(), TinkerforgeError> {
339        let mut payload = [0; 9];
340        year.write_to_slice(&mut payload[0..2]);
341        month.write_to_slice(&mut payload[2..3]);
342        day.write_to_slice(&mut payload[3..4]);
343        hour.write_to_slice(&mut payload[4..5]);
344        minute.write_to_slice(&mut payload[5..6]);
345        second.write_to_slice(&mut payload[6..7]);
346        centisecond.write_to_slice(&mut payload[7..8]);
347        weekday.write_to_slice(&mut payload[8..9]);
348
349        #[allow(unused_variables)]
350        let result = self.device.set(u8::from(RealTimeClockBrickletFunction::SetDateTime), &payload).await?;
351        Ok(())
352    }
353
354    /// Returns the current date (including weekday) and the current time of the
355    /// real-time clock.
356    ///
357    /// Associated constants:
358    /// * REAL_TIME_CLOCK_BRICKLET_WEEKDAY_MONDAY
359    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_TUESDAY
360    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_WEDNESDAY
361    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_THURSDAY
362    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_FRIDAY
363    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_SATURDAY
364    ///	* REAL_TIME_CLOCK_BRICKLET_WEEKDAY_SUNDAY
365    pub async fn get_date_time(&mut self) -> Result<DateTime, TinkerforgeError> {
366        let payload = [0; 0];
367
368        #[allow(unused_variables)]
369        let result = self.device.get(u8::from(RealTimeClockBrickletFunction::GetDateTime), &payload).await?;
370        Ok(DateTime::from_le_byte_slice(result.body()))
371    }
372
373    /// Returns the current date and the time of the real-time clock.
374    /// The timestamp has an effective resolution of hundredths of a
375    /// second and is an offset to 2000-01-01 00:00:00.000.
376    pub async fn get_timestamp(&mut self) -> Result<i64, TinkerforgeError> {
377        let payload = [0; 0];
378
379        #[allow(unused_variables)]
380        let result = self.device.get(u8::from(RealTimeClockBrickletFunction::GetTimestamp), &payload).await?;
381        Ok(i64::from_le_byte_slice(result.body()))
382    }
383
384    /// Sets the offset the real-time clock should compensate for in 2.17 ppm steps
385    /// between -277.76 ppm (-128) and +275.59 ppm (127).
386    ///
387    /// The real-time clock time can deviate from the actual time due to the frequency
388    /// deviation of its 32.768 kHz crystal. Even without compensation (factory
389    /// default) the resulting time deviation should be at most ±20 ppm (±52.6
390    /// seconds per month).
391    ///
392    /// This deviation can be calculated by comparing the same duration measured by the
393    /// real-time clock (``rtc_duration``) an accurate reference clock
394    /// (``ref_duration``).
395    ///
396    /// For best results the configured offset should be set to 0 ppm first and then a
397    /// duration of at least 6 hours should be measured.
398    ///
399    /// The new offset (``new_offset``) can be calculated from the currently configured
400    /// offset (``current_offset``) and the measured durations as follow::
401    ///
402    ///   new_offset = current_offset - round(1000000 * (rtc_duration - ref_duration) / rtc_duration / 2.17)
403    ///
404    /// If you want to calculate the offset, then we recommend using the calibration
405    /// dialog in Brick Viewer, instead of doing it manually.
406    ///
407    /// The offset is saved in the EEPROM of the Bricklet and only needs to be
408    /// configured once.
409    pub async fn set_offset(&mut self, offset: i8) -> Result<(), TinkerforgeError> {
410        let mut payload = [0; 1];
411        offset.write_to_slice(&mut payload[0..1]);
412
413        #[allow(unused_variables)]
414        let result = self.device.set(u8::from(RealTimeClockBrickletFunction::SetOffset), &payload).await?;
415        Ok(())
416    }
417
418    /// Returns the offset as set by [`set_offset`].
419    pub async fn get_offset(&mut self) -> Result<i8, TinkerforgeError> {
420        let payload = [0; 0];
421
422        #[allow(unused_variables)]
423        let result = self.device.get(u8::from(RealTimeClockBrickletFunction::GetOffset), &payload).await?;
424        Ok(i8::from_le_byte_slice(result.body()))
425    }
426
427    /// Sets the period with which the [`get_date_time_callback_receiver`] receiver is triggered
428    /// periodically. A value of 0 turns the receiver off.
429    ///
430    /// The [`get_date_time_callback_receiver`] Receiver is only triggered if the date or time changed
431    /// since the last triggering.
432    ///
433    ///
434    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
435    pub async fn set_date_time_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
436        let mut payload = [0; 4];
437        period.write_to_slice(&mut payload[0..4]);
438
439        #[allow(unused_variables)]
440        let result = self.device.set(u8::from(RealTimeClockBrickletFunction::SetDateTimeCallbackPeriod), &payload).await?;
441        Ok(())
442    }
443
444    /// Returns the period as set by [`set_date_time_callback_period`].
445    ///
446    ///
447    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
448    pub async fn get_date_time_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
449        let payload = [0; 0];
450
451        #[allow(unused_variables)]
452        let result = self.device.get(u8::from(RealTimeClockBrickletFunction::GetDateTimeCallbackPeriod), &payload).await?;
453        Ok(u32::from_le_byte_slice(result.body()))
454    }
455
456    /// Configures a repeatable alarm. The [`get_alarm_callback_receiver`] receiver is triggered if the
457    /// current date and time matches the configured alarm.
458    ///
459    /// Setting a parameter to -1 means that it should be disabled and doesn't take part
460    /// in the match. Setting all parameters to -1 disables the alarm completely.
461    ///
462    /// For example, to make the alarm trigger every day at 7:30 AM it can be
463    /// configured as (-1, -1, 7, 30, -1, -1, -1). The hour is set to match 7 and the
464    /// minute is set to match 30. The alarm is triggered if all enabled parameters
465    /// match.
466    ///
467    /// The interval has a special role. It allows to make the alarm reconfigure itself.
468    /// This is useful if you need a repeated alarm that cannot be expressed by matching
469    /// the current date and time. For example, to make the alarm trigger every 23
470    /// seconds it can be configured as (-1, -1, -1, -1, -1, -1, 23). Internally the
471    /// Bricklet will take the current date and time, add 23 seconds to it and set the
472    /// result as its alarm. The first alarm will be triggered 23 seconds after the
473    /// call. Because the interval is not -1, the Bricklet will do the same again
474    /// internally, take the current date and time, add 23 seconds to it and set that
475    /// as its alarm. This results in a repeated alarm that triggers every 23 seconds.
476    ///
477    /// The interval can also be used in combination with the other parameters. For
478    /// example, configuring the alarm as (-1, -1, 7, 30, -1, -1, 300) results in an
479    /// alarm that triggers every day at 7:30 AM and is then repeated every 5 minutes.
480    ///
481    ///
482    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
483    ///
484    /// Associated constants:
485    /// * REAL_TIME_CLOCK_BRICKLET_ALARM_MATCH_DISABLED
486    ///	* REAL_TIME_CLOCK_BRICKLET_ALARM_INTERVAL_DISABLED
487    pub async fn set_alarm(
488        &mut self,
489        month: i8,
490        day: i8,
491        hour: i8,
492        minute: i8,
493        second: i8,
494        weekday: i8,
495        interval: i32,
496    ) -> Result<(), TinkerforgeError> {
497        let mut payload = [0; 10];
498        month.write_to_slice(&mut payload[0..1]);
499        day.write_to_slice(&mut payload[1..2]);
500        hour.write_to_slice(&mut payload[2..3]);
501        minute.write_to_slice(&mut payload[3..4]);
502        second.write_to_slice(&mut payload[4..5]);
503        weekday.write_to_slice(&mut payload[5..6]);
504        interval.write_to_slice(&mut payload[6..10]);
505
506        #[allow(unused_variables)]
507        let result = self.device.set(u8::from(RealTimeClockBrickletFunction::SetAlarm), &payload).await?;
508        Ok(())
509    }
510
511    /// Returns the alarm configuration as set by [`set_alarm`].
512    ///
513    ///
514    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
515    ///
516    /// Associated constants:
517    /// * REAL_TIME_CLOCK_BRICKLET_ALARM_MATCH_DISABLED
518    ///	* REAL_TIME_CLOCK_BRICKLET_ALARM_INTERVAL_DISABLED
519    pub async fn get_alarm(&mut self) -> Result<Alarm, TinkerforgeError> {
520        let payload = [0; 0];
521
522        #[allow(unused_variables)]
523        let result = self.device.get(u8::from(RealTimeClockBrickletFunction::GetAlarm), &payload).await?;
524        Ok(Alarm::from_le_byte_slice(result.body()))
525    }
526
527    /// Returns the UID, the UID where the Bricklet is connected to,
528    /// the position, the hardware and firmware version as well as the
529    /// device identifier.
530    ///
531    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
532    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
533    /// position 'z'.
534    ///
535    /// The device identifier numbers can be found [here](device_identifier).
536    /// |device_identifier_constant|
537    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
538        let payload = [0; 0];
539
540        #[allow(unused_variables)]
541        let result = self.device.get(u8::from(RealTimeClockBrickletFunction::GetIdentity), &payload).await?;
542        Ok(Identity::from_le_byte_slice(result.body()))
543    }
544}