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 DcBrickFunction {
24 SetVelocity,
25 GetVelocity,
26 GetCurrentVelocity,
27 SetAcceleration,
28 GetAcceleration,
29 SetPwmFrequency,
30 GetPwmFrequency,
31 FullBrake,
32 GetStackInputVoltage,
33 GetExternalInputVoltage,
34 GetCurrentConsumption,
35 Enable,
36 Disable,
37 IsEnabled,
38 SetMinimumVoltage,
39 GetMinimumVoltage,
40 SetDriveMode,
41 GetDriveMode,
42 SetCurrentVelocityPeriod,
43 GetCurrentVelocityPeriod,
44 SetSpitfpBaudrateConfig,
45 GetSpitfpBaudrateConfig,
46 GetSendTimeoutCount,
47 SetSpitfpBaudrate,
48 GetSpitfpBaudrate,
49 GetSpitfpErrorCount,
50 EnableStatusLed,
51 DisableStatusLed,
52 IsStatusLedEnabled,
53 GetProtocol1BrickletName,
54 GetChipTemperature,
55 Reset,
56 WriteBrickletPlugin,
57 ReadBrickletPlugin,
58 GetIdentity,
59 CallbackUnderVoltage,
60 CallbackEmergencyShutdown,
61 CallbackVelocityReached,
62 CallbackCurrentVelocity,
63}
64impl From<DcBrickFunction> for u8 {
65 fn from(fun: DcBrickFunction) -> Self {
66 match fun {
67 DcBrickFunction::SetVelocity => 1,
68 DcBrickFunction::GetVelocity => 2,
69 DcBrickFunction::GetCurrentVelocity => 3,
70 DcBrickFunction::SetAcceleration => 4,
71 DcBrickFunction::GetAcceleration => 5,
72 DcBrickFunction::SetPwmFrequency => 6,
73 DcBrickFunction::GetPwmFrequency => 7,
74 DcBrickFunction::FullBrake => 8,
75 DcBrickFunction::GetStackInputVoltage => 9,
76 DcBrickFunction::GetExternalInputVoltage => 10,
77 DcBrickFunction::GetCurrentConsumption => 11,
78 DcBrickFunction::Enable => 12,
79 DcBrickFunction::Disable => 13,
80 DcBrickFunction::IsEnabled => 14,
81 DcBrickFunction::SetMinimumVoltage => 15,
82 DcBrickFunction::GetMinimumVoltage => 16,
83 DcBrickFunction::SetDriveMode => 17,
84 DcBrickFunction::GetDriveMode => 18,
85 DcBrickFunction::SetCurrentVelocityPeriod => 19,
86 DcBrickFunction::GetCurrentVelocityPeriod => 20,
87 DcBrickFunction::SetSpitfpBaudrateConfig => 231,
88 DcBrickFunction::GetSpitfpBaudrateConfig => 232,
89 DcBrickFunction::GetSendTimeoutCount => 233,
90 DcBrickFunction::SetSpitfpBaudrate => 234,
91 DcBrickFunction::GetSpitfpBaudrate => 235,
92 DcBrickFunction::GetSpitfpErrorCount => 237,
93 DcBrickFunction::EnableStatusLed => 238,
94 DcBrickFunction::DisableStatusLed => 239,
95 DcBrickFunction::IsStatusLedEnabled => 240,
96 DcBrickFunction::GetProtocol1BrickletName => 241,
97 DcBrickFunction::GetChipTemperature => 242,
98 DcBrickFunction::Reset => 243,
99 DcBrickFunction::WriteBrickletPlugin => 246,
100 DcBrickFunction::ReadBrickletPlugin => 247,
101 DcBrickFunction::GetIdentity => 255,
102 DcBrickFunction::CallbackUnderVoltage => 21,
103 DcBrickFunction::CallbackEmergencyShutdown => 22,
104 DcBrickFunction::CallbackVelocityReached => 23,
105 DcBrickFunction::CallbackCurrentVelocity => 24,
106 }
107 }
108}
109pub const DC_BRICK_DRIVE_MODE_DRIVE_BRAKE: u8 = 0;
110pub const DC_BRICK_DRIVE_MODE_DRIVE_COAST: u8 = 1;
111pub const DC_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
112pub const DC_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
113pub const DC_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
114pub const DC_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
115pub const DC_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
116pub const DC_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
117pub const DC_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
118pub const DC_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;
119
120#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
121pub struct SpitfpBaudrateConfig {
122 pub enable_dynamic_baudrate: bool,
123 pub minimum_dynamic_baudrate: u32,
124}
125impl FromByteSlice for SpitfpBaudrateConfig {
126 fn bytes_expected() -> usize {
127 5
128 }
129 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpBaudrateConfig {
130 SpitfpBaudrateConfig {
131 enable_dynamic_baudrate: <bool>::from_le_byte_slice(&bytes[0..1]),
132 minimum_dynamic_baudrate: <u32>::from_le_byte_slice(&bytes[1..5]),
133 }
134 }
135}
136
137#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
138pub struct SpitfpErrorCount {
139 pub error_count_ack_checksum: u32,
140 pub error_count_message_checksum: u32,
141 pub error_count_frame: u32,
142 pub error_count_overflow: u32,
143}
144impl FromByteSlice for SpitfpErrorCount {
145 fn bytes_expected() -> usize {
146 16
147 }
148 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
149 SpitfpErrorCount {
150 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
151 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
152 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
153 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
154 }
155 }
156}
157
158#[derive(Clone)]
159pub struct Protocol1BrickletName {
160 pub protocol_version: u8,
161 pub firmware_version: [u8; 3],
162 pub name: String,
163}
164impl FromByteSlice for Protocol1BrickletName {
165 fn bytes_expected() -> usize {
166 44
167 }
168 fn from_le_byte_slice(bytes: &[u8]) -> Protocol1BrickletName {
169 Protocol1BrickletName {
170 protocol_version: <u8>::from_le_byte_slice(&bytes[0..1]),
171 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[1..4]),
172 name: <String>::from_le_byte_slice(&bytes[4..44]),
173 }
174 }
175}
176
177#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
178pub struct Identity {
179 pub uid: String,
180 pub connected_uid: String,
181 pub position: char,
182 pub hardware_version: [u8; 3],
183 pub firmware_version: [u8; 3],
184 pub device_identifier: u16,
185}
186impl FromByteSlice for Identity {
187 fn bytes_expected() -> usize {
188 25
189 }
190 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
191 Identity {
192 uid: <String>::from_le_byte_slice(&bytes[0..8]),
193 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
194 position: <char>::from_le_byte_slice(&bytes[16..17]),
195 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
196 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
197 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
198 }
199 }
200}
201
202#[derive(Clone)]
204pub struct DcBrick {
205 device: Device,
206}
207impl DcBrick {
208 pub const DEVICE_IDENTIFIER: u16 = 11;
209 pub const DEVICE_DISPLAY_NAME: &'static str = "DC Brick";
210 pub fn new(uid: Uid, connection: AsyncIpConnection) -> DcBrick {
212 let mut result = DcBrick { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
213 result.device.response_expected[u8::from(DcBrickFunction::SetVelocity) as usize] = ResponseExpectedFlag::False;
214 result.device.response_expected[u8::from(DcBrickFunction::GetVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
215 result.device.response_expected[u8::from(DcBrickFunction::GetCurrentVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
216 result.device.response_expected[u8::from(DcBrickFunction::SetAcceleration) as usize] = ResponseExpectedFlag::False;
217 result.device.response_expected[u8::from(DcBrickFunction::GetAcceleration) as usize] = ResponseExpectedFlag::AlwaysTrue;
218 result.device.response_expected[u8::from(DcBrickFunction::SetPwmFrequency) as usize] = ResponseExpectedFlag::False;
219 result.device.response_expected[u8::from(DcBrickFunction::GetPwmFrequency) as usize] = ResponseExpectedFlag::AlwaysTrue;
220 result.device.response_expected[u8::from(DcBrickFunction::FullBrake) as usize] = ResponseExpectedFlag::False;
221 result.device.response_expected[u8::from(DcBrickFunction::GetStackInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
222 result.device.response_expected[u8::from(DcBrickFunction::GetExternalInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
223 result.device.response_expected[u8::from(DcBrickFunction::GetCurrentConsumption) as usize] = ResponseExpectedFlag::AlwaysTrue;
224 result.device.response_expected[u8::from(DcBrickFunction::Enable) as usize] = ResponseExpectedFlag::False;
225 result.device.response_expected[u8::from(DcBrickFunction::Disable) as usize] = ResponseExpectedFlag::False;
226 result.device.response_expected[u8::from(DcBrickFunction::IsEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
227 result.device.response_expected[u8::from(DcBrickFunction::SetMinimumVoltage) as usize] = ResponseExpectedFlag::True;
228 result.device.response_expected[u8::from(DcBrickFunction::GetMinimumVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
229 result.device.response_expected[u8::from(DcBrickFunction::SetDriveMode) as usize] = ResponseExpectedFlag::False;
230 result.device.response_expected[u8::from(DcBrickFunction::GetDriveMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
231 result.device.response_expected[u8::from(DcBrickFunction::SetCurrentVelocityPeriod) as usize] = ResponseExpectedFlag::True;
232 result.device.response_expected[u8::from(DcBrickFunction::GetCurrentVelocityPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
233 result.device.response_expected[u8::from(DcBrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
234 result.device.response_expected[u8::from(DcBrickFunction::GetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
235 result.device.response_expected[u8::from(DcBrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
236 result.device.response_expected[u8::from(DcBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
237 result.device.response_expected[u8::from(DcBrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
238 result.device.response_expected[u8::from(DcBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
239 result.device.response_expected[u8::from(DcBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
240 result.device.response_expected[u8::from(DcBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
241 result.device.response_expected[u8::from(DcBrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
242 result.device.response_expected[u8::from(DcBrickFunction::GetProtocol1BrickletName) as usize] = ResponseExpectedFlag::AlwaysTrue;
243 result.device.response_expected[u8::from(DcBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
244 result.device.response_expected[u8::from(DcBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
245 result.device.response_expected[u8::from(DcBrickFunction::WriteBrickletPlugin) as usize] = ResponseExpectedFlag::False;
246 result.device.response_expected[u8::from(DcBrickFunction::ReadBrickletPlugin) as usize] = ResponseExpectedFlag::AlwaysTrue;
247 result.device.response_expected[u8::from(DcBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
248 result
249 }
250
251 pub fn get_response_expected(&mut self, fun: DcBrickFunction) -> Result<bool, GetResponseExpectedError> {
266 self.device.get_response_expected(u8::from(fun))
267 }
268
269 pub fn set_response_expected(&mut self, fun: DcBrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
278 self.device.set_response_expected(u8::from(fun), response_expected)
279 }
280
281 pub fn set_response_expected_all(&mut self, response_expected: bool) {
283 self.device.set_response_expected_all(response_expected)
284 }
285
286 pub fn get_api_version(&self) -> [u8; 3] {
289 self.device.api_version
290 }
291
292 pub async fn get_under_voltage_callback_receiver(&mut self) -> impl Stream<Item = u16> {
297 self.device.get_callback_receiver(u8::from(DcBrickFunction::CallbackUnderVoltage)).await.map(|p| u16::from_le_byte_slice(p.body()))
298 }
299
300 pub async fn get_emergency_shutdown_callback_receiver(&mut self) -> impl Stream<Item = ()> {
315 self.device.get_callback_receiver(u8::from(DcBrickFunction::CallbackEmergencyShutdown)).await.map(|_p| ())
316 }
317
318 pub async fn get_velocity_reached_callback_receiver(&mut self) -> impl Stream<Item = i16> {
329 self.device
330 .get_callback_receiver(u8::from(DcBrickFunction::CallbackVelocityReached))
331 .await
332 .map(|p| i16::from_le_byte_slice(p.body()))
333 }
334
335 pub async fn get_current_velocity_callback_receiver(&mut self) -> impl Stream<Item = i16> {
342 self.device
343 .get_callback_receiver(u8::from(DcBrickFunction::CallbackCurrentVelocity))
344 .await
345 .map(|p| i16::from_le_byte_slice(p.body()))
346 }
347
348 pub async fn set_velocity(&mut self, velocity: i16) -> Result<(), TinkerforgeError> {
358 let mut payload = [0; 2];
359 velocity.write_to_slice(&mut payload[0..2]);
360
361 #[allow(unused_variables)]
362 let result = self.device.set(u8::from(DcBrickFunction::SetVelocity), &payload).await?;
363 Ok(())
364 }
365
366 pub async fn get_velocity(&mut self) -> Result<i16, TinkerforgeError> {
368 let payload = [0; 0];
369
370 #[allow(unused_variables)]
371 let result = self.device.get(u8::from(DcBrickFunction::GetVelocity), &payload).await?;
372 Ok(i16::from_le_byte_slice(result.body()))
373 }
374
375 pub async fn get_current_velocity(&mut self) -> Result<i16, TinkerforgeError> {
379 let payload = [0; 0];
380
381 #[allow(unused_variables)]
382 let result = self.device.get(u8::from(DcBrickFunction::GetCurrentVelocity), &payload).await?;
383 Ok(i16::from_le_byte_slice(result.body()))
384 }
385
386 pub async fn set_acceleration(&mut self, acceleration: u16) -> Result<(), TinkerforgeError> {
397 let mut payload = [0; 2];
398 acceleration.write_to_slice(&mut payload[0..2]);
399
400 #[allow(unused_variables)]
401 let result = self.device.set(u8::from(DcBrickFunction::SetAcceleration), &payload).await?;
402 Ok(())
403 }
404
405 pub async fn get_acceleration(&mut self) -> Result<u16, TinkerforgeError> {
407 let payload = [0; 0];
408
409 #[allow(unused_variables)]
410 let result = self.device.get(u8::from(DcBrickFunction::GetAcceleration), &payload).await?;
411 Ok(u16::from_le_byte_slice(result.body()))
412 }
413
414 pub async fn set_pwm_frequency(&mut self, frequency: u16) -> Result<(), TinkerforgeError> {
423 let mut payload = [0; 2];
424 frequency.write_to_slice(&mut payload[0..2]);
425
426 #[allow(unused_variables)]
427 let result = self.device.set(u8::from(DcBrickFunction::SetPwmFrequency), &payload).await?;
428 Ok(())
429 }
430
431 pub async fn get_pwm_frequency(&mut self) -> Result<u16, TinkerforgeError> {
433 let payload = [0; 0];
434
435 #[allow(unused_variables)]
436 let result = self.device.get(u8::from(DcBrickFunction::GetPwmFrequency), &payload).await?;
437 Ok(u16::from_le_byte_slice(result.body()))
438 }
439
440 pub async fn full_brake(&mut self) -> Result<(), TinkerforgeError> {
449 let payload = [0; 0];
450
451 #[allow(unused_variables)]
452 let result = self.device.set(u8::from(DcBrickFunction::FullBrake), &payload).await?;
453 Ok(())
454 }
455
456 pub async fn get_stack_input_voltage(&mut self) -> Result<u16, TinkerforgeError> {
460 let payload = [0; 0];
461
462 #[allow(unused_variables)]
463 let result = self.device.get(u8::from(DcBrickFunction::GetStackInputVoltage), &payload).await?;
464 Ok(u16::from_le_byte_slice(result.body()))
465 }
466
467 pub async fn get_external_input_voltage(&mut self) -> Result<u16, TinkerforgeError> {
480 let payload = [0; 0];
481
482 #[allow(unused_variables)]
483 let result = self.device.get(u8::from(DcBrickFunction::GetExternalInputVoltage), &payload).await?;
484 Ok(u16::from_le_byte_slice(result.body()))
485 }
486
487 pub async fn get_current_consumption(&mut self) -> Result<u16, TinkerforgeError> {
489 let payload = [0; 0];
490
491 #[allow(unused_variables)]
492 let result = self.device.get(u8::from(DcBrickFunction::GetCurrentConsumption), &payload).await?;
493 Ok(u16::from_le_byte_slice(result.body()))
494 }
495
496 pub async fn enable(&mut self) -> Result<(), TinkerforgeError> {
499 let payload = [0; 0];
500
501 #[allow(unused_variables)]
502 let result = self.device.set(u8::from(DcBrickFunction::Enable), &payload).await?;
503 Ok(())
504 }
505
506 pub async fn disable(&mut self) -> Result<(), TinkerforgeError> {
517 let payload = [0; 0];
518
519 #[allow(unused_variables)]
520 let result = self.device.set(u8::from(DcBrickFunction::Disable), &payload).await?;
521 Ok(())
522 }
523
524 pub async fn is_enabled(&mut self) -> Result<bool, TinkerforgeError> {
526 let payload = [0; 0];
527
528 #[allow(unused_variables)]
529 let result = self.device.get(u8::from(DcBrickFunction::IsEnabled), &payload).await?;
530 Ok(bool::from_le_byte_slice(result.body()))
531 }
532
533 pub async fn set_minimum_voltage(&mut self, voltage: u16) -> Result<(), TinkerforgeError> {
539 let mut payload = [0; 2];
540 voltage.write_to_slice(&mut payload[0..2]);
541
542 #[allow(unused_variables)]
543 let result = self.device.set(u8::from(DcBrickFunction::SetMinimumVoltage), &payload).await?;
544 Ok(())
545 }
546
547 pub async fn get_minimum_voltage(&mut self) -> Result<u16, TinkerforgeError> {
549 let payload = [0; 0];
550
551 #[allow(unused_variables)]
552 let result = self.device.get(u8::from(DcBrickFunction::GetMinimumVoltage), &payload).await?;
553 Ok(u16::from_le_byte_slice(result.body()))
554 }
555
556 pub async fn set_drive_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
576 let mut payload = [0; 1];
577 mode.write_to_slice(&mut payload[0..1]);
578
579 #[allow(unused_variables)]
580 let result = self.device.set(u8::from(DcBrickFunction::SetDriveMode), &payload).await?;
581 Ok(())
582 }
583
584 pub async fn get_drive_mode(&mut self) -> Result<u8, TinkerforgeError> {
590 let payload = [0; 0];
591
592 #[allow(unused_variables)]
593 let result = self.device.get(u8::from(DcBrickFunction::GetDriveMode), &payload).await?;
594 Ok(u8::from_le_byte_slice(result.body()))
595 }
596
597 pub async fn set_current_velocity_period(&mut self, period: u16) -> Result<(), TinkerforgeError> {
600 let mut payload = [0; 2];
601 period.write_to_slice(&mut payload[0..2]);
602
603 #[allow(unused_variables)]
604 let result = self.device.set(u8::from(DcBrickFunction::SetCurrentVelocityPeriod), &payload).await?;
605 Ok(())
606 }
607
608 pub async fn get_current_velocity_period(&mut self) -> Result<u16, TinkerforgeError> {
610 let payload = [0; 0];
611
612 #[allow(unused_variables)]
613 let result = self.device.get(u8::from(DcBrickFunction::GetCurrentVelocityPeriod), &payload).await?;
614 Ok(u16::from_le_byte_slice(result.body()))
615 }
616
617 pub async fn set_spitfp_baudrate_config(
639 &mut self,
640 enable_dynamic_baudrate: bool,
641 minimum_dynamic_baudrate: u32,
642 ) -> Result<(), TinkerforgeError> {
643 let mut payload = [0; 5];
644 enable_dynamic_baudrate.write_to_slice(&mut payload[0..1]);
645 minimum_dynamic_baudrate.write_to_slice(&mut payload[1..5]);
646
647 #[allow(unused_variables)]
648 let result = self.device.set(u8::from(DcBrickFunction::SetSpitfpBaudrateConfig), &payload).await?;
649 Ok(())
650 }
651
652 pub async fn get_spitfp_baudrate_config(&mut self) -> Result<SpitfpBaudrateConfig, TinkerforgeError> {
657 let payload = [0; 0];
658
659 #[allow(unused_variables)]
660 let result = self.device.get(u8::from(DcBrickFunction::GetSpitfpBaudrateConfig), &payload).await?;
661 Ok(SpitfpBaudrateConfig::from_le_byte_slice(result.body()))
662 }
663
664 pub async fn get_send_timeout_count(&mut self, communication_method: u8) -> Result<u32, TinkerforgeError> {
684 let mut payload = [0; 1];
685 communication_method.write_to_slice(&mut payload[0..1]);
686
687 #[allow(unused_variables)]
688 let result = self.device.get(u8::from(DcBrickFunction::GetSendTimeoutCount), &payload).await?;
689 Ok(u32::from_le_byte_slice(result.body()))
690 }
691
692 pub async fn set_spitfp_baudrate(&mut self, bricklet_port: char, baudrate: u32) -> Result<(), TinkerforgeError> {
709 let mut payload = [0; 5];
710 bricklet_port.write_to_slice(&mut payload[0..1]);
711 baudrate.write_to_slice(&mut payload[1..5]);
712
713 #[allow(unused_variables)]
714 let result = self.device.set(u8::from(DcBrickFunction::SetSpitfpBaudrate), &payload).await?;
715 Ok(())
716 }
717
718 pub async fn get_spitfp_baudrate(&mut self, bricklet_port: char) -> Result<u32, TinkerforgeError> {
723 let mut payload = [0; 1];
724 bricklet_port.write_to_slice(&mut payload[0..1]);
725
726 #[allow(unused_variables)]
727 let result = self.device.get(u8::from(DcBrickFunction::GetSpitfpBaudrate), &payload).await?;
728 Ok(u32::from_le_byte_slice(result.body()))
729 }
730
731 pub async fn get_spitfp_error_count(&mut self, bricklet_port: char) -> Result<SpitfpErrorCount, TinkerforgeError> {
746 let mut payload = [0; 1];
747 bricklet_port.write_to_slice(&mut payload[0..1]);
748
749 #[allow(unused_variables)]
750 let result = self.device.get(u8::from(DcBrickFunction::GetSpitfpErrorCount), &payload).await?;
751 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
752 }
753
754 pub async fn enable_status_led(&mut self) -> Result<(), TinkerforgeError> {
764 let payload = [0; 0];
765
766 #[allow(unused_variables)]
767 let result = self.device.set(u8::from(DcBrickFunction::EnableStatusLed), &payload).await?;
768 Ok(())
769 }
770
771 pub async fn disable_status_led(&mut self) -> Result<(), TinkerforgeError> {
781 let payload = [0; 0];
782
783 #[allow(unused_variables)]
784 let result = self.device.set(u8::from(DcBrickFunction::DisableStatusLed), &payload).await?;
785 Ok(())
786 }
787
788 pub async fn is_status_led_enabled(&mut self) -> Result<bool, TinkerforgeError> {
793 let payload = [0; 0];
794
795 #[allow(unused_variables)]
796 let result = self.device.get(u8::from(DcBrickFunction::IsStatusLedEnabled), &payload).await?;
797 Ok(bool::from_le_byte_slice(result.body()))
798 }
799
800 pub async fn get_protocol1_bricklet_name(&mut self, port: char) -> Result<Protocol1BrickletName, TinkerforgeError> {
806 let mut payload = [0; 1];
807 port.write_to_slice(&mut payload[0..1]);
808
809 #[allow(unused_variables)]
810 let result = self.device.get(u8::from(DcBrickFunction::GetProtocol1BrickletName), &payload).await?;
811 Ok(Protocol1BrickletName::from_le_byte_slice(result.body()))
812 }
813
814 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
821 let payload = [0; 0];
822
823 #[allow(unused_variables)]
824 let result = self.device.get(u8::from(DcBrickFunction::GetChipTemperature), &payload).await?;
825 Ok(i16::from_le_byte_slice(result.body()))
826 }
827
828 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
835 let payload = [0; 0];
836
837 #[allow(unused_variables)]
838 let result = self.device.set(u8::from(DcBrickFunction::Reset), &payload).await?;
839 Ok(())
840 }
841
842 pub async fn write_bricklet_plugin(&mut self, port: char, offset: u8, chunk: &[u8; 32]) -> Result<(), TinkerforgeError> {
848 let mut payload = [0; 34];
849 port.write_to_slice(&mut payload[0..1]);
850 offset.write_to_slice(&mut payload[1..2]);
851 chunk.write_to_slice(&mut payload[2..34]);
852
853 #[allow(unused_variables)]
854 let result = self.device.set(u8::from(DcBrickFunction::WriteBrickletPlugin), &payload).await?;
855 Ok(())
856 }
857
858 pub async fn read_bricklet_plugin(&mut self, port: char, offset: u8) -> Result<Box<[u8; 32]>, TinkerforgeError> {
864 let mut payload = [0; 2];
865 port.write_to_slice(&mut payload[0..1]);
866 offset.write_to_slice(&mut payload[1..2]);
867
868 #[allow(unused_variables)]
869 let result = self.device.get(u8::from(DcBrickFunction::ReadBrickletPlugin), &payload).await?;
870 Ok(Box::<[u8; 32]>::from_le_byte_slice(result.body()))
871 }
872
873 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
882 let payload = [0; 0];
883
884 #[allow(unused_variables)]
885 let result = self.device.get(u8::from(DcBrickFunction::GetIdentity), &payload).await?;
886 Ok(Identity::from_le_byte_slice(result.body()))
887 }
888}