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 RemoteSwitchV2BrickletFunction {
24 GetSwitchingState,
25 SetRepeats,
26 GetRepeats,
27 SwitchSocketA,
28 SwitchSocketB,
29 DimSocketB,
30 SwitchSocketC,
31 SetRemoteConfiguration,
32 GetRemoteConfiguration,
33 GetRemoteStatusA,
34 GetRemoteStatusB,
35 GetRemoteStatusC,
36 GetSpitfpErrorCount,
37 SetBootloaderMode,
38 GetBootloaderMode,
39 SetWriteFirmwarePointer,
40 WriteFirmware,
41 SetStatusLedConfig,
42 GetStatusLedConfig,
43 GetChipTemperature,
44 Reset,
45 WriteUid,
46 ReadUid,
47 GetIdentity,
48 CallbackSwitchingDone,
49 CallbackRemoteStatusA,
50 CallbackRemoteStatusB,
51 CallbackRemoteStatusC,
52}
53impl From<RemoteSwitchV2BrickletFunction> for u8 {
54 fn from(fun: RemoteSwitchV2BrickletFunction) -> Self {
55 match fun {
56 RemoteSwitchV2BrickletFunction::GetSwitchingState => 1,
57 RemoteSwitchV2BrickletFunction::SetRepeats => 3,
58 RemoteSwitchV2BrickletFunction::GetRepeats => 4,
59 RemoteSwitchV2BrickletFunction::SwitchSocketA => 5,
60 RemoteSwitchV2BrickletFunction::SwitchSocketB => 6,
61 RemoteSwitchV2BrickletFunction::DimSocketB => 7,
62 RemoteSwitchV2BrickletFunction::SwitchSocketC => 8,
63 RemoteSwitchV2BrickletFunction::SetRemoteConfiguration => 9,
64 RemoteSwitchV2BrickletFunction::GetRemoteConfiguration => 10,
65 RemoteSwitchV2BrickletFunction::GetRemoteStatusA => 11,
66 RemoteSwitchV2BrickletFunction::GetRemoteStatusB => 12,
67 RemoteSwitchV2BrickletFunction::GetRemoteStatusC => 13,
68 RemoteSwitchV2BrickletFunction::GetSpitfpErrorCount => 234,
69 RemoteSwitchV2BrickletFunction::SetBootloaderMode => 235,
70 RemoteSwitchV2BrickletFunction::GetBootloaderMode => 236,
71 RemoteSwitchV2BrickletFunction::SetWriteFirmwarePointer => 237,
72 RemoteSwitchV2BrickletFunction::WriteFirmware => 238,
73 RemoteSwitchV2BrickletFunction::SetStatusLedConfig => 239,
74 RemoteSwitchV2BrickletFunction::GetStatusLedConfig => 240,
75 RemoteSwitchV2BrickletFunction::GetChipTemperature => 242,
76 RemoteSwitchV2BrickletFunction::Reset => 243,
77 RemoteSwitchV2BrickletFunction::WriteUid => 248,
78 RemoteSwitchV2BrickletFunction::ReadUid => 249,
79 RemoteSwitchV2BrickletFunction::GetIdentity => 255,
80 RemoteSwitchV2BrickletFunction::CallbackSwitchingDone => 2,
81 RemoteSwitchV2BrickletFunction::CallbackRemoteStatusA => 14,
82 RemoteSwitchV2BrickletFunction::CallbackRemoteStatusB => 15,
83 RemoteSwitchV2BrickletFunction::CallbackRemoteStatusC => 16,
84 }
85 }
86}
87pub const REMOTE_SWITCH_V2_BRICKLET_SWITCHING_STATE_READY: u8 = 0;
88pub const REMOTE_SWITCH_V2_BRICKLET_SWITCHING_STATE_BUSY: u8 = 1;
89pub const REMOTE_SWITCH_V2_BRICKLET_SWITCH_TO_OFF: u8 = 0;
90pub const REMOTE_SWITCH_V2_BRICKLET_SWITCH_TO_ON: u8 = 1;
91pub const REMOTE_SWITCH_V2_BRICKLET_REMOTE_TYPE_A: u8 = 0;
92pub const REMOTE_SWITCH_V2_BRICKLET_REMOTE_TYPE_B: u8 = 1;
93pub const REMOTE_SWITCH_V2_BRICKLET_REMOTE_TYPE_C: u8 = 2;
94pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
95pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
96pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
97pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
98pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
99pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
100pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
101pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
102pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
103pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
104pub const REMOTE_SWITCH_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
105pub const REMOTE_SWITCH_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
106pub const REMOTE_SWITCH_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
107pub const REMOTE_SWITCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
108pub const REMOTE_SWITCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
109
110#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
111pub struct RemoteConfiguration {
112 pub remote_type: u8,
113 pub minimum_repeats: u16,
114 pub callback_enabled: bool,
115}
116impl FromByteSlice for RemoteConfiguration {
117 fn bytes_expected() -> usize {
118 4
119 }
120 fn from_le_byte_slice(bytes: &[u8]) -> RemoteConfiguration {
121 RemoteConfiguration {
122 remote_type: <u8>::from_le_byte_slice(&bytes[0..1]),
123 minimum_repeats: <u16>::from_le_byte_slice(&bytes[1..3]),
124 callback_enabled: <bool>::from_le_byte_slice(&bytes[3..4]),
125 }
126 }
127}
128
129#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
130pub struct RemoteStatusA {
131 pub house_code: u8,
132 pub receiver_code: u8,
133 pub switch_to: u8,
134 pub repeats: u16,
135}
136impl FromByteSlice for RemoteStatusA {
137 fn bytes_expected() -> usize {
138 5
139 }
140 fn from_le_byte_slice(bytes: &[u8]) -> RemoteStatusA {
141 RemoteStatusA {
142 house_code: <u8>::from_le_byte_slice(&bytes[0..1]),
143 receiver_code: <u8>::from_le_byte_slice(&bytes[1..2]),
144 switch_to: <u8>::from_le_byte_slice(&bytes[2..3]),
145 repeats: <u16>::from_le_byte_slice(&bytes[3..5]),
146 }
147 }
148}
149
150#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
151pub struct RemoteStatusB {
152 pub address: u32,
153 pub unit: u8,
154 pub switch_to: u8,
155 pub dim_value: u8,
156 pub repeats: u16,
157}
158impl FromByteSlice for RemoteStatusB {
159 fn bytes_expected() -> usize {
160 9
161 }
162 fn from_le_byte_slice(bytes: &[u8]) -> RemoteStatusB {
163 RemoteStatusB {
164 address: <u32>::from_le_byte_slice(&bytes[0..4]),
165 unit: <u8>::from_le_byte_slice(&bytes[4..5]),
166 switch_to: <u8>::from_le_byte_slice(&bytes[5..6]),
167 dim_value: <u8>::from_le_byte_slice(&bytes[6..7]),
168 repeats: <u16>::from_le_byte_slice(&bytes[7..9]),
169 }
170 }
171}
172
173#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
174pub struct RemoteStatusC {
175 pub system_code: char,
176 pub device_code: u8,
177 pub switch_to: u8,
178 pub repeats: u16,
179}
180impl FromByteSlice for RemoteStatusC {
181 fn bytes_expected() -> usize {
182 5
183 }
184 fn from_le_byte_slice(bytes: &[u8]) -> RemoteStatusC {
185 RemoteStatusC {
186 system_code: <char>::from_le_byte_slice(&bytes[0..1]),
187 device_code: <u8>::from_le_byte_slice(&bytes[1..2]),
188 switch_to: <u8>::from_le_byte_slice(&bytes[2..3]),
189 repeats: <u16>::from_le_byte_slice(&bytes[3..5]),
190 }
191 }
192}
193
194#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
195pub struct RemoteStatusAEvent {
196 pub house_code: u8,
197 pub receiver_code: u8,
198 pub switch_to: u8,
199 pub repeats: u16,
200}
201impl FromByteSlice for RemoteStatusAEvent {
202 fn bytes_expected() -> usize {
203 5
204 }
205 fn from_le_byte_slice(bytes: &[u8]) -> RemoteStatusAEvent {
206 RemoteStatusAEvent {
207 house_code: <u8>::from_le_byte_slice(&bytes[0..1]),
208 receiver_code: <u8>::from_le_byte_slice(&bytes[1..2]),
209 switch_to: <u8>::from_le_byte_slice(&bytes[2..3]),
210 repeats: <u16>::from_le_byte_slice(&bytes[3..5]),
211 }
212 }
213}
214
215#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
216pub struct RemoteStatusBEvent {
217 pub address: u32,
218 pub unit: u8,
219 pub switch_to: u8,
220 pub dim_value: u8,
221 pub repeats: u16,
222}
223impl FromByteSlice for RemoteStatusBEvent {
224 fn bytes_expected() -> usize {
225 9
226 }
227 fn from_le_byte_slice(bytes: &[u8]) -> RemoteStatusBEvent {
228 RemoteStatusBEvent {
229 address: <u32>::from_le_byte_slice(&bytes[0..4]),
230 unit: <u8>::from_le_byte_slice(&bytes[4..5]),
231 switch_to: <u8>::from_le_byte_slice(&bytes[5..6]),
232 dim_value: <u8>::from_le_byte_slice(&bytes[6..7]),
233 repeats: <u16>::from_le_byte_slice(&bytes[7..9]),
234 }
235 }
236}
237
238#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
239pub struct RemoteStatusCEvent {
240 pub system_code: char,
241 pub device_code: u8,
242 pub switch_to: u8,
243 pub repeats: u16,
244}
245impl FromByteSlice for RemoteStatusCEvent {
246 fn bytes_expected() -> usize {
247 5
248 }
249 fn from_le_byte_slice(bytes: &[u8]) -> RemoteStatusCEvent {
250 RemoteStatusCEvent {
251 system_code: <char>::from_le_byte_slice(&bytes[0..1]),
252 device_code: <u8>::from_le_byte_slice(&bytes[1..2]),
253 switch_to: <u8>::from_le_byte_slice(&bytes[2..3]),
254 repeats: <u16>::from_le_byte_slice(&bytes[3..5]),
255 }
256 }
257}
258
259#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
260pub struct SpitfpErrorCount {
261 pub error_count_ack_checksum: u32,
262 pub error_count_message_checksum: u32,
263 pub error_count_frame: u32,
264 pub error_count_overflow: u32,
265}
266impl FromByteSlice for SpitfpErrorCount {
267 fn bytes_expected() -> usize {
268 16
269 }
270 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
271 SpitfpErrorCount {
272 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
273 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
274 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
275 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
276 }
277 }
278}
279
280#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
281pub struct Identity {
282 pub uid: String,
283 pub connected_uid: String,
284 pub position: char,
285 pub hardware_version: [u8; 3],
286 pub firmware_version: [u8; 3],
287 pub device_identifier: u16,
288}
289impl FromByteSlice for Identity {
290 fn bytes_expected() -> usize {
291 25
292 }
293 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
294 Identity {
295 uid: <String>::from_le_byte_slice(&bytes[0..8]),
296 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
297 position: <char>::from_le_byte_slice(&bytes[16..17]),
298 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
299 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
300 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
301 }
302 }
303}
304
305#[derive(Clone)]
307pub struct RemoteSwitchV2Bricklet {
308 device: Device,
309}
310impl RemoteSwitchV2Bricklet {
311 pub const DEVICE_IDENTIFIER: u16 = 289;
312 pub const DEVICE_DISPLAY_NAME: &'static str = "Remote Switch Bricklet 2.0";
313 pub fn new(uid: Uid, connection: AsyncIpConnection) -> RemoteSwitchV2Bricklet {
315 let mut result = RemoteSwitchV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
316 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetSwitchingState) as usize] =
317 ResponseExpectedFlag::AlwaysTrue;
318 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SetRepeats) as usize] = ResponseExpectedFlag::False;
319 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetRepeats) as usize] = ResponseExpectedFlag::AlwaysTrue;
320 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SwitchSocketA) as usize] = ResponseExpectedFlag::False;
321 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SwitchSocketB) as usize] = ResponseExpectedFlag::False;
322 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::DimSocketB) as usize] = ResponseExpectedFlag::False;
323 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SwitchSocketC) as usize] = ResponseExpectedFlag::False;
324 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SetRemoteConfiguration) as usize] =
325 ResponseExpectedFlag::False;
326 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetRemoteConfiguration) as usize] =
327 ResponseExpectedFlag::AlwaysTrue;
328 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetRemoteStatusA) as usize] =
329 ResponseExpectedFlag::AlwaysTrue;
330 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetRemoteStatusB) as usize] =
331 ResponseExpectedFlag::AlwaysTrue;
332 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetRemoteStatusC) as usize] =
333 ResponseExpectedFlag::AlwaysTrue;
334 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetSpitfpErrorCount) as usize] =
335 ResponseExpectedFlag::AlwaysTrue;
336 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SetBootloaderMode) as usize] =
337 ResponseExpectedFlag::AlwaysTrue;
338 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetBootloaderMode) as usize] =
339 ResponseExpectedFlag::AlwaysTrue;
340 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
341 ResponseExpectedFlag::False;
342 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::WriteFirmware) as usize] =
343 ResponseExpectedFlag::AlwaysTrue;
344 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::SetStatusLedConfig) as usize] =
345 ResponseExpectedFlag::False;
346 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetStatusLedConfig) as usize] =
347 ResponseExpectedFlag::AlwaysTrue;
348 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetChipTemperature) as usize] =
349 ResponseExpectedFlag::AlwaysTrue;
350 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
351 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
352 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
353 result.device.response_expected[u8::from(RemoteSwitchV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
354 result
355 }
356
357 pub fn get_response_expected(&mut self, fun: RemoteSwitchV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
372 self.device.get_response_expected(u8::from(fun))
373 }
374
375 pub fn set_response_expected(
384 &mut self,
385 fun: RemoteSwitchV2BrickletFunction,
386 response_expected: bool,
387 ) -> Result<(), SetResponseExpectedError> {
388 self.device.set_response_expected(u8::from(fun), response_expected)
389 }
390
391 pub fn set_response_expected_all(&mut self, response_expected: bool) {
393 self.device.set_response_expected_all(response_expected)
394 }
395
396 pub fn get_api_version(&self) -> [u8; 3] {
399 self.device.api_version
400 }
401
402 pub async fn get_switching_done_callback_receiver(&mut self) -> impl Stream<Item = ()> {
407 self.device.get_callback_receiver(u8::from(RemoteSwitchV2BrickletFunction::CallbackSwitchingDone)).await.map(|_p| ())
408 }
409
410 pub async fn get_remote_status_a_callback_receiver(&mut self) -> impl Stream<Item = RemoteStatusAEvent> {
420 self.device
421 .get_callback_receiver(u8::from(RemoteSwitchV2BrickletFunction::CallbackRemoteStatusA))
422 .await
423 .map(|p| RemoteStatusAEvent::from_le_byte_slice(p.body()))
424 }
425
426 pub async fn get_remote_status_b_callback_receiver(&mut self) -> impl Stream<Item = RemoteStatusBEvent> {
438 self.device
439 .get_callback_receiver(u8::from(RemoteSwitchV2BrickletFunction::CallbackRemoteStatusB))
440 .await
441 .map(|p| RemoteStatusBEvent::from_le_byte_slice(p.body()))
442 }
443
444 pub async fn get_remote_status_c_callback_receiver(&mut self) -> impl Stream<Item = RemoteStatusCEvent> {
454 self.device
455 .get_callback_receiver(u8::from(RemoteSwitchV2BrickletFunction::CallbackRemoteStatusC))
456 .await
457 .map(|p| RemoteStatusCEvent::from_le_byte_slice(p.body()))
458 }
459
460 pub async fn get_switching_state(&mut self) -> Result<u8, TinkerforgeError> {
471 let payload = [0; 0];
472
473 #[allow(unused_variables)]
474 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetSwitchingState), &payload).await?;
475 Ok(u8::from_le_byte_slice(result.body()))
476 }
477
478 pub async fn set_repeats(&mut self, repeats: u8) -> Result<(), TinkerforgeError> {
485 let mut payload = [0; 1];
486 repeats.write_to_slice(&mut payload[0..1]);
487
488 #[allow(unused_variables)]
489 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::SetRepeats), &payload).await?;
490 Ok(())
491 }
492
493 pub async fn get_repeats(&mut self) -> Result<u8, TinkerforgeError> {
495 let payload = [0; 0];
496
497 #[allow(unused_variables)]
498 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetRepeats), &payload).await?;
499 Ok(u8::from_le_byte_slice(result.body()))
500 }
501
502 pub async fn switch_socket_a(&mut self, house_code: u8, receiver_code: u8, switch_to: u8) -> Result<(), TinkerforgeError> {
512 let mut payload = [0; 3];
513 house_code.write_to_slice(&mut payload[0..1]);
514 receiver_code.write_to_slice(&mut payload[1..2]);
515 switch_to.write_to_slice(&mut payload[2..3]);
516
517 #[allow(unused_variables)]
518 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::SwitchSocketA), &payload).await?;
519 Ok(())
520 }
521
522 pub async fn switch_socket_b(&mut self, address: u32, unit: u8, switch_to: u8) -> Result<(), TinkerforgeError> {
534 let mut payload = [0; 6];
535 address.write_to_slice(&mut payload[0..4]);
536 unit.write_to_slice(&mut payload[4..5]);
537 switch_to.write_to_slice(&mut payload[5..6]);
538
539 #[allow(unused_variables)]
540 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::SwitchSocketB), &payload).await?;
541 Ok(())
542 }
543
544 pub async fn dim_socket_b(&mut self, address: u32, unit: u8, dim_value: u8) -> Result<(), TinkerforgeError> {
550 let mut payload = [0; 6];
551 address.write_to_slice(&mut payload[0..4]);
552 unit.write_to_slice(&mut payload[4..5]);
553 dim_value.write_to_slice(&mut payload[5..6]);
554
555 #[allow(unused_variables)]
556 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::DimSocketB), &payload).await?;
557 Ok(())
558 }
559
560 pub async fn switch_socket_c(&mut self, system_code: char, device_code: u8, switch_to: u8) -> Result<(), TinkerforgeError> {
570 let mut payload = [0; 3];
571 system_code.write_to_slice(&mut payload[0..1]);
572 device_code.write_to_slice(&mut payload[1..2]);
573 switch_to.write_to_slice(&mut payload[2..3]);
574
575 #[allow(unused_variables)]
576 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::SwitchSocketC), &payload).await?;
577 Ok(())
578 }
579
580 pub async fn set_remote_configuration(
593 &mut self,
594 remote_type: u8,
595 minimum_repeats: u16,
596 callback_enabled: bool,
597 ) -> Result<(), TinkerforgeError> {
598 let mut payload = [0; 4];
599 remote_type.write_to_slice(&mut payload[0..1]);
600 minimum_repeats.write_to_slice(&mut payload[1..3]);
601 callback_enabled.write_to_slice(&mut payload[3..4]);
602
603 #[allow(unused_variables)]
604 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::SetRemoteConfiguration), &payload).await?;
605 Ok(())
606 }
607
608 pub async fn get_remote_configuration(&mut self) -> Result<RemoteConfiguration, TinkerforgeError> {
615 let payload = [0; 0];
616
617 #[allow(unused_variables)]
618 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetRemoteConfiguration), &payload).await?;
619 Ok(RemoteConfiguration::from_le_byte_slice(result.body()))
620 }
621
622 pub async fn get_remote_status_a(&mut self) -> Result<RemoteStatusA, TinkerforgeError> {
637 let payload = [0; 0];
638
639 #[allow(unused_variables)]
640 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetRemoteStatusA), &payload).await?;
641 Ok(RemoteStatusA::from_le_byte_slice(result.body()))
642 }
643
644 pub async fn get_remote_status_b(&mut self) -> Result<RemoteStatusB, TinkerforgeError> {
660 let payload = [0; 0];
661
662 #[allow(unused_variables)]
663 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetRemoteStatusB), &payload).await?;
664 Ok(RemoteStatusB::from_le_byte_slice(result.body()))
665 }
666
667 pub async fn get_remote_status_c(&mut self) -> Result<RemoteStatusC, TinkerforgeError> {
681 let payload = [0; 0];
682
683 #[allow(unused_variables)]
684 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetRemoteStatusC), &payload).await?;
685 Ok(RemoteStatusC::from_le_byte_slice(result.body()))
686 }
687
688 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
700 let payload = [0; 0];
701
702 #[allow(unused_variables)]
703 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
704 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
705 }
706
707 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
730 let mut payload = [0; 1];
731 mode.write_to_slice(&mut payload[0..1]);
732
733 #[allow(unused_variables)]
734 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::SetBootloaderMode), &payload).await?;
735 Ok(u8::from_le_byte_slice(result.body()))
736 }
737
738 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
747 let payload = [0; 0];
748
749 #[allow(unused_variables)]
750 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetBootloaderMode), &payload).await?;
751 Ok(u8::from_le_byte_slice(result.body()))
752 }
753
754 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
761 let mut payload = [0; 4];
762 pointer.write_to_slice(&mut payload[0..4]);
763
764 #[allow(unused_variables)]
765 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
766 Ok(())
767 }
768
769 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
778 let mut payload = [0; 64];
779 data.write_to_slice(&mut payload[0..64]);
780
781 #[allow(unused_variables)]
782 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::WriteFirmware), &payload).await?;
783 Ok(u8::from_le_byte_slice(result.body()))
784 }
785
786 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
800 let mut payload = [0; 1];
801 config.write_to_slice(&mut payload[0..1]);
802
803 #[allow(unused_variables)]
804 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::SetStatusLedConfig), &payload).await?;
805 Ok(())
806 }
807
808 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
816 let payload = [0; 0];
817
818 #[allow(unused_variables)]
819 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetStatusLedConfig), &payload).await?;
820 Ok(u8::from_le_byte_slice(result.body()))
821 }
822
823 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
830 let payload = [0; 0];
831
832 #[allow(unused_variables)]
833 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetChipTemperature), &payload).await?;
834 Ok(i16::from_le_byte_slice(result.body()))
835 }
836
837 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
844 let payload = [0; 0];
845
846 #[allow(unused_variables)]
847 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::Reset), &payload).await?;
848 Ok(())
849 }
850
851 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
857 let mut payload = [0; 4];
858 uid.write_to_slice(&mut payload[0..4]);
859
860 #[allow(unused_variables)]
861 let result = self.device.set(u8::from(RemoteSwitchV2BrickletFunction::WriteUid), &payload).await?;
862 Ok(())
863 }
864
865 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
868 let payload = [0; 0];
869
870 #[allow(unused_variables)]
871 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::ReadUid), &payload).await?;
872 Ok(u32::from_le_byte_slice(result.body()))
873 }
874
875 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
886 let payload = [0; 0];
887
888 #[allow(unused_variables)]
889 let result = self.device.get(u8::from(RemoteSwitchV2BrickletFunction::GetIdentity), &payload).await?;
890 Ok(Identity::from_le_byte_slice(result.body()))
891 }
892}