1#[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 RealTimeClockV2BrickletFunction {
24 SetDateTime,
25 GetDateTime,
26 GetTimestamp,
27 SetOffset,
28 GetOffset,
29 SetDateTimeCallbackConfiguration,
30 GetDateTimeCallbackConfiguration,
31 SetAlarm,
32 GetAlarm,
33 GetSpitfpErrorCount,
34 SetBootloaderMode,
35 GetBootloaderMode,
36 SetWriteFirmwarePointer,
37 WriteFirmware,
38 SetStatusLedConfig,
39 GetStatusLedConfig,
40 GetChipTemperature,
41 Reset,
42 WriteUid,
43 ReadUid,
44 GetIdentity,
45 CallbackDateTime,
46 CallbackAlarm,
47}
48impl From<RealTimeClockV2BrickletFunction> for u8 {
49 fn from(fun: RealTimeClockV2BrickletFunction) -> Self {
50 match fun {
51 RealTimeClockV2BrickletFunction::SetDateTime => 1,
52 RealTimeClockV2BrickletFunction::GetDateTime => 2,
53 RealTimeClockV2BrickletFunction::GetTimestamp => 3,
54 RealTimeClockV2BrickletFunction::SetOffset => 4,
55 RealTimeClockV2BrickletFunction::GetOffset => 5,
56 RealTimeClockV2BrickletFunction::SetDateTimeCallbackConfiguration => 6,
57 RealTimeClockV2BrickletFunction::GetDateTimeCallbackConfiguration => 7,
58 RealTimeClockV2BrickletFunction::SetAlarm => 8,
59 RealTimeClockV2BrickletFunction::GetAlarm => 9,
60 RealTimeClockV2BrickletFunction::GetSpitfpErrorCount => 234,
61 RealTimeClockV2BrickletFunction::SetBootloaderMode => 235,
62 RealTimeClockV2BrickletFunction::GetBootloaderMode => 236,
63 RealTimeClockV2BrickletFunction::SetWriteFirmwarePointer => 237,
64 RealTimeClockV2BrickletFunction::WriteFirmware => 238,
65 RealTimeClockV2BrickletFunction::SetStatusLedConfig => 239,
66 RealTimeClockV2BrickletFunction::GetStatusLedConfig => 240,
67 RealTimeClockV2BrickletFunction::GetChipTemperature => 242,
68 RealTimeClockV2BrickletFunction::Reset => 243,
69 RealTimeClockV2BrickletFunction::WriteUid => 248,
70 RealTimeClockV2BrickletFunction::ReadUid => 249,
71 RealTimeClockV2BrickletFunction::GetIdentity => 255,
72 RealTimeClockV2BrickletFunction::CallbackDateTime => 10,
73 RealTimeClockV2BrickletFunction::CallbackAlarm => 11,
74 }
75 }
76}
77pub const REAL_TIME_CLOCK_V2_BRICKLET_WEEKDAY_MONDAY: u8 = 1;
78pub const REAL_TIME_CLOCK_V2_BRICKLET_WEEKDAY_TUESDAY: u8 = 2;
79pub const REAL_TIME_CLOCK_V2_BRICKLET_WEEKDAY_WEDNESDAY: u8 = 3;
80pub const REAL_TIME_CLOCK_V2_BRICKLET_WEEKDAY_THURSDAY: u8 = 4;
81pub const REAL_TIME_CLOCK_V2_BRICKLET_WEEKDAY_FRIDAY: u8 = 5;
82pub const REAL_TIME_CLOCK_V2_BRICKLET_WEEKDAY_SATURDAY: u8 = 6;
83pub const REAL_TIME_CLOCK_V2_BRICKLET_WEEKDAY_SUNDAY: u8 = 7;
84pub const REAL_TIME_CLOCK_V2_BRICKLET_ALARM_MATCH_DISABLED: i8 = -1;
85pub const REAL_TIME_CLOCK_V2_BRICKLET_ALARM_INTERVAL_DISABLED: i32 = -1;
86pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
87pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
88pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
89pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
90pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
91pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
92pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
93pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
94pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
95pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
96pub const REAL_TIME_CLOCK_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
97pub const REAL_TIME_CLOCK_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
98pub const REAL_TIME_CLOCK_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
99pub const REAL_TIME_CLOCK_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
100pub const REAL_TIME_CLOCK_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
101
102#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
103pub struct DateTime {
104 pub year: u16,
105 pub month: u8,
106 pub day: u8,
107 pub hour: u8,
108 pub minute: u8,
109 pub second: u8,
110 pub centisecond: u8,
111 pub weekday: u8,
112 pub timestamp: i64,
113}
114impl FromByteSlice for DateTime {
115 fn bytes_expected() -> usize {
116 17
117 }
118 fn from_le_byte_slice(bytes: &[u8]) -> DateTime {
119 DateTime {
120 year: <u16>::from_le_byte_slice(&bytes[0..2]),
121 month: <u8>::from_le_byte_slice(&bytes[2..3]),
122 day: <u8>::from_le_byte_slice(&bytes[3..4]),
123 hour: <u8>::from_le_byte_slice(&bytes[4..5]),
124 minute: <u8>::from_le_byte_slice(&bytes[5..6]),
125 second: <u8>::from_le_byte_slice(&bytes[6..7]),
126 centisecond: <u8>::from_le_byte_slice(&bytes[7..8]),
127 weekday: <u8>::from_le_byte_slice(&bytes[8..9]),
128 timestamp: <i64>::from_le_byte_slice(&bytes[9..17]),
129 }
130 }
131}
132
133#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
134pub struct Alarm {
135 pub month: i8,
136 pub day: i8,
137 pub hour: i8,
138 pub minute: i8,
139 pub second: i8,
140 pub weekday: i8,
141 pub interval: i32,
142}
143impl FromByteSlice for Alarm {
144 fn bytes_expected() -> usize {
145 10
146 }
147 fn from_le_byte_slice(bytes: &[u8]) -> Alarm {
148 Alarm {
149 month: <i8>::from_le_byte_slice(&bytes[0..1]),
150 day: <i8>::from_le_byte_slice(&bytes[1..2]),
151 hour: <i8>::from_le_byte_slice(&bytes[2..3]),
152 minute: <i8>::from_le_byte_slice(&bytes[3..4]),
153 second: <i8>::from_le_byte_slice(&bytes[4..5]),
154 weekday: <i8>::from_le_byte_slice(&bytes[5..6]),
155 interval: <i32>::from_le_byte_slice(&bytes[6..10]),
156 }
157 }
158}
159
160#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
161pub struct DateTimeEvent {
162 pub year: u16,
163 pub month: u8,
164 pub day: u8,
165 pub hour: u8,
166 pub minute: u8,
167 pub second: u8,
168 pub centisecond: u8,
169 pub weekday: u8,
170 pub timestamp: i64,
171}
172impl FromByteSlice for DateTimeEvent {
173 fn bytes_expected() -> usize {
174 17
175 }
176 fn from_le_byte_slice(bytes: &[u8]) -> DateTimeEvent {
177 DateTimeEvent {
178 year: <u16>::from_le_byte_slice(&bytes[0..2]),
179 month: <u8>::from_le_byte_slice(&bytes[2..3]),
180 day: <u8>::from_le_byte_slice(&bytes[3..4]),
181 hour: <u8>::from_le_byte_slice(&bytes[4..5]),
182 minute: <u8>::from_le_byte_slice(&bytes[5..6]),
183 second: <u8>::from_le_byte_slice(&bytes[6..7]),
184 centisecond: <u8>::from_le_byte_slice(&bytes[7..8]),
185 weekday: <u8>::from_le_byte_slice(&bytes[8..9]),
186 timestamp: <i64>::from_le_byte_slice(&bytes[9..17]),
187 }
188 }
189}
190
191#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
192pub struct AlarmEvent {
193 pub year: u16,
194 pub month: u8,
195 pub day: u8,
196 pub hour: u8,
197 pub minute: u8,
198 pub second: u8,
199 pub centisecond: u8,
200 pub weekday: u8,
201 pub timestamp: i64,
202}
203impl FromByteSlice for AlarmEvent {
204 fn bytes_expected() -> usize {
205 17
206 }
207 fn from_le_byte_slice(bytes: &[u8]) -> AlarmEvent {
208 AlarmEvent {
209 year: <u16>::from_le_byte_slice(&bytes[0..2]),
210 month: <u8>::from_le_byte_slice(&bytes[2..3]),
211 day: <u8>::from_le_byte_slice(&bytes[3..4]),
212 hour: <u8>::from_le_byte_slice(&bytes[4..5]),
213 minute: <u8>::from_le_byte_slice(&bytes[5..6]),
214 second: <u8>::from_le_byte_slice(&bytes[6..7]),
215 centisecond: <u8>::from_le_byte_slice(&bytes[7..8]),
216 weekday: <u8>::from_le_byte_slice(&bytes[8..9]),
217 timestamp: <i64>::from_le_byte_slice(&bytes[9..17]),
218 }
219 }
220}
221
222#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
223pub struct SpitfpErrorCount {
224 pub error_count_ack_checksum: u32,
225 pub error_count_message_checksum: u32,
226 pub error_count_frame: u32,
227 pub error_count_overflow: u32,
228}
229impl FromByteSlice for SpitfpErrorCount {
230 fn bytes_expected() -> usize {
231 16
232 }
233 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
234 SpitfpErrorCount {
235 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
236 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
237 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
238 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
239 }
240 }
241}
242
243#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
244pub struct Identity {
245 pub uid: String,
246 pub connected_uid: String,
247 pub position: char,
248 pub hardware_version: [u8; 3],
249 pub firmware_version: [u8; 3],
250 pub device_identifier: u16,
251}
252impl FromByteSlice for Identity {
253 fn bytes_expected() -> usize {
254 25
255 }
256 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
257 Identity {
258 uid: <String>::from_le_byte_slice(&bytes[0..8]),
259 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
260 position: <char>::from_le_byte_slice(&bytes[16..17]),
261 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
262 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
263 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
264 }
265 }
266}
267
268#[derive(Clone)]
270pub struct RealTimeClockV2Bricklet {
271 device: Device,
272}
273impl RealTimeClockV2Bricklet {
274 pub const DEVICE_IDENTIFIER: u16 = 2106;
275 pub const DEVICE_DISPLAY_NAME: &'static str = "Real-Time Clock Bricklet 2.0";
276 pub fn new(uid: Uid, connection: AsyncIpConnection) -> RealTimeClockV2Bricklet {
278 let mut result = RealTimeClockV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
279 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::SetDateTime) as usize] = ResponseExpectedFlag::False;
280 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetDateTime) as usize] = ResponseExpectedFlag::AlwaysTrue;
281 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetTimestamp) as usize] =
282 ResponseExpectedFlag::AlwaysTrue;
283 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::SetOffset) as usize] = ResponseExpectedFlag::False;
284 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetOffset) as usize] = ResponseExpectedFlag::AlwaysTrue;
285 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::SetDateTimeCallbackConfiguration) as usize] =
286 ResponseExpectedFlag::True;
287 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetDateTimeCallbackConfiguration) as usize] =
288 ResponseExpectedFlag::AlwaysTrue;
289 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::SetAlarm) as usize] = ResponseExpectedFlag::True;
290 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetAlarm) as usize] = ResponseExpectedFlag::AlwaysTrue;
291 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetSpitfpErrorCount) as usize] =
292 ResponseExpectedFlag::AlwaysTrue;
293 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::SetBootloaderMode) as usize] =
294 ResponseExpectedFlag::AlwaysTrue;
295 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetBootloaderMode) as usize] =
296 ResponseExpectedFlag::AlwaysTrue;
297 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
298 ResponseExpectedFlag::False;
299 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::WriteFirmware) as usize] =
300 ResponseExpectedFlag::AlwaysTrue;
301 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::SetStatusLedConfig) as usize] =
302 ResponseExpectedFlag::False;
303 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetStatusLedConfig) as usize] =
304 ResponseExpectedFlag::AlwaysTrue;
305 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetChipTemperature) as usize] =
306 ResponseExpectedFlag::AlwaysTrue;
307 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
308 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
309 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
310 result.device.response_expected[u8::from(RealTimeClockV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
311 result
312 }
313
314 pub fn get_response_expected(&mut self, fun: RealTimeClockV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
329 self.device.get_response_expected(u8::from(fun))
330 }
331
332 pub fn set_response_expected(
341 &mut self,
342 fun: RealTimeClockV2BrickletFunction,
343 response_expected: bool,
344 ) -> Result<(), SetResponseExpectedError> {
345 self.device.set_response_expected(u8::from(fun), response_expected)
346 }
347
348 pub fn set_response_expected_all(&mut self, response_expected: bool) {
350 self.device.set_response_expected_all(response_expected)
351 }
352
353 pub fn get_api_version(&self) -> [u8; 3] {
356 self.device.api_version
357 }
358
359 pub async fn get_date_time_callback_receiver(&mut self) -> impl Stream<Item = DateTimeEvent> {
366 self.device
367 .get_callback_receiver(u8::from(RealTimeClockV2BrickletFunction::CallbackDateTime))
368 .await
369 .map(|p| DateTimeEvent::from_le_byte_slice(p.body()))
370 }
371
372 pub async fn get_alarm_callback_receiver(&mut self) -> impl Stream<Item = AlarmEvent> {
376 self.device
377 .get_callback_receiver(u8::from(RealTimeClockV2BrickletFunction::CallbackAlarm))
378 .await
379 .map(|p| AlarmEvent::from_le_byte_slice(p.body()))
380 }
381
382 pub async fn set_date_time(
400 &mut self,
401 year: u16,
402 month: u8,
403 day: u8,
404 hour: u8,
405 minute: u8,
406 second: u8,
407 centisecond: u8,
408 weekday: u8,
409 ) -> Result<(), TinkerforgeError> {
410 let mut payload = [0; 9];
411 year.write_to_slice(&mut payload[0..2]);
412 month.write_to_slice(&mut payload[2..3]);
413 day.write_to_slice(&mut payload[3..4]);
414 hour.write_to_slice(&mut payload[4..5]);
415 minute.write_to_slice(&mut payload[5..6]);
416 second.write_to_slice(&mut payload[6..7]);
417 centisecond.write_to_slice(&mut payload[7..8]);
418 weekday.write_to_slice(&mut payload[8..9]);
419
420 #[allow(unused_variables)]
421 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::SetDateTime), &payload).await?;
422 Ok(())
423 }
424
425 pub async fn get_date_time(&mut self) -> Result<DateTime, TinkerforgeError> {
440 let payload = [0; 0];
441
442 #[allow(unused_variables)]
443 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetDateTime), &payload).await?;
444 Ok(DateTime::from_le_byte_slice(result.body()))
445 }
446
447 pub async fn get_timestamp(&mut self) -> Result<i64, TinkerforgeError> {
451 let payload = [0; 0];
452
453 #[allow(unused_variables)]
454 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetTimestamp), &payload).await?;
455 Ok(i64::from_le_byte_slice(result.body()))
456 }
457
458 pub async fn set_offset(&mut self, offset: i8) -> Result<(), TinkerforgeError> {
484 let mut payload = [0; 1];
485 offset.write_to_slice(&mut payload[0..1]);
486
487 #[allow(unused_variables)]
488 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::SetOffset), &payload).await?;
489 Ok(())
490 }
491
492 pub async fn get_offset(&mut self) -> Result<i8, TinkerforgeError> {
494 let payload = [0; 0];
495
496 #[allow(unused_variables)]
497 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetOffset), &payload).await?;
498 Ok(i8::from_le_byte_slice(result.body()))
499 }
500
501 pub async fn set_date_time_callback_configuration(&mut self, period: u32) -> Result<(), TinkerforgeError> {
504 let mut payload = [0; 4];
505 period.write_to_slice(&mut payload[0..4]);
506
507 #[allow(unused_variables)]
508 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::SetDateTimeCallbackConfiguration), &payload).await?;
509 Ok(())
510 }
511
512 pub async fn get_date_time_callback_configuration(&mut self) -> Result<u32, TinkerforgeError> {
514 let payload = [0; 0];
515
516 #[allow(unused_variables)]
517 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetDateTimeCallbackConfiguration), &payload).await?;
518 Ok(u32::from_le_byte_slice(result.body()))
519 }
520
521 pub async fn set_alarm(
550 &mut self,
551 month: i8,
552 day: i8,
553 hour: i8,
554 minute: i8,
555 second: i8,
556 weekday: i8,
557 interval: i32,
558 ) -> Result<(), TinkerforgeError> {
559 let mut payload = [0; 10];
560 month.write_to_slice(&mut payload[0..1]);
561 day.write_to_slice(&mut payload[1..2]);
562 hour.write_to_slice(&mut payload[2..3]);
563 minute.write_to_slice(&mut payload[3..4]);
564 second.write_to_slice(&mut payload[4..5]);
565 weekday.write_to_slice(&mut payload[5..6]);
566 interval.write_to_slice(&mut payload[6..10]);
567
568 #[allow(unused_variables)]
569 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::SetAlarm), &payload).await?;
570 Ok(())
571 }
572
573 pub async fn get_alarm(&mut self) -> Result<Alarm, TinkerforgeError> {
579 let payload = [0; 0];
580
581 #[allow(unused_variables)]
582 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetAlarm), &payload).await?;
583 Ok(Alarm::from_le_byte_slice(result.body()))
584 }
585
586 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
598 let payload = [0; 0];
599
600 #[allow(unused_variables)]
601 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
602 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
603 }
604
605 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
628 let mut payload = [0; 1];
629 mode.write_to_slice(&mut payload[0..1]);
630
631 #[allow(unused_variables)]
632 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::SetBootloaderMode), &payload).await?;
633 Ok(u8::from_le_byte_slice(result.body()))
634 }
635
636 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
645 let payload = [0; 0];
646
647 #[allow(unused_variables)]
648 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetBootloaderMode), &payload).await?;
649 Ok(u8::from_le_byte_slice(result.body()))
650 }
651
652 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
659 let mut payload = [0; 4];
660 pointer.write_to_slice(&mut payload[0..4]);
661
662 #[allow(unused_variables)]
663 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
664 Ok(())
665 }
666
667 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
676 let mut payload = [0; 64];
677 data.write_to_slice(&mut payload[0..64]);
678
679 #[allow(unused_variables)]
680 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::WriteFirmware), &payload).await?;
681 Ok(u8::from_le_byte_slice(result.body()))
682 }
683
684 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
698 let mut payload = [0; 1];
699 config.write_to_slice(&mut payload[0..1]);
700
701 #[allow(unused_variables)]
702 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::SetStatusLedConfig), &payload).await?;
703 Ok(())
704 }
705
706 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
714 let payload = [0; 0];
715
716 #[allow(unused_variables)]
717 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetStatusLedConfig), &payload).await?;
718 Ok(u8::from_le_byte_slice(result.body()))
719 }
720
721 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
728 let payload = [0; 0];
729
730 #[allow(unused_variables)]
731 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetChipTemperature), &payload).await?;
732 Ok(i16::from_le_byte_slice(result.body()))
733 }
734
735 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
742 let payload = [0; 0];
743
744 #[allow(unused_variables)]
745 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::Reset), &payload).await?;
746 Ok(())
747 }
748
749 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
755 let mut payload = [0; 4];
756 uid.write_to_slice(&mut payload[0..4]);
757
758 #[allow(unused_variables)]
759 let result = self.device.set(u8::from(RealTimeClockV2BrickletFunction::WriteUid), &payload).await?;
760 Ok(())
761 }
762
763 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
766 let payload = [0; 0];
767
768 #[allow(unused_variables)]
769 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::ReadUid), &payload).await?;
770 Ok(u32::from_le_byte_slice(result.body()))
771 }
772
773 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
784 let payload = [0; 0];
785
786 #[allow(unused_variables)]
787 let result = self.device.get(u8::from(RealTimeClockV2BrickletFunction::GetIdentity), &payload).await?;
788 Ok(Identity::from_le_byte_slice(result.body()))
789 }
790}