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 IndustrialDualAcInBrickletFunction {
24 GetValue,
25 SetValueCallbackConfiguration,
26 GetValueCallbackConfiguration,
27 SetAllValueCallbackConfiguration,
28 GetAllValueCallbackConfiguration,
29 SetChannelLedConfig,
30 GetChannelLedConfig,
31 GetSpitfpErrorCount,
32 SetBootloaderMode,
33 GetBootloaderMode,
34 SetWriteFirmwarePointer,
35 WriteFirmware,
36 SetStatusLedConfig,
37 GetStatusLedConfig,
38 GetChipTemperature,
39 Reset,
40 WriteUid,
41 ReadUid,
42 GetIdentity,
43 CallbackValue,
44 CallbackAllValue,
45}
46impl From<IndustrialDualAcInBrickletFunction> for u8 {
47 fn from(fun: IndustrialDualAcInBrickletFunction) -> Self {
48 match fun {
49 IndustrialDualAcInBrickletFunction::GetValue => 1,
50 IndustrialDualAcInBrickletFunction::SetValueCallbackConfiguration => 2,
51 IndustrialDualAcInBrickletFunction::GetValueCallbackConfiguration => 3,
52 IndustrialDualAcInBrickletFunction::SetAllValueCallbackConfiguration => 4,
53 IndustrialDualAcInBrickletFunction::GetAllValueCallbackConfiguration => 5,
54 IndustrialDualAcInBrickletFunction::SetChannelLedConfig => 6,
55 IndustrialDualAcInBrickletFunction::GetChannelLedConfig => 7,
56 IndustrialDualAcInBrickletFunction::GetSpitfpErrorCount => 234,
57 IndustrialDualAcInBrickletFunction::SetBootloaderMode => 235,
58 IndustrialDualAcInBrickletFunction::GetBootloaderMode => 236,
59 IndustrialDualAcInBrickletFunction::SetWriteFirmwarePointer => 237,
60 IndustrialDualAcInBrickletFunction::WriteFirmware => 238,
61 IndustrialDualAcInBrickletFunction::SetStatusLedConfig => 239,
62 IndustrialDualAcInBrickletFunction::GetStatusLedConfig => 240,
63 IndustrialDualAcInBrickletFunction::GetChipTemperature => 242,
64 IndustrialDualAcInBrickletFunction::Reset => 243,
65 IndustrialDualAcInBrickletFunction::WriteUid => 248,
66 IndustrialDualAcInBrickletFunction::ReadUid => 249,
67 IndustrialDualAcInBrickletFunction::GetIdentity => 255,
68 IndustrialDualAcInBrickletFunction::CallbackValue => 8,
69 IndustrialDualAcInBrickletFunction::CallbackAllValue => 9,
70 }
71 }
72}
73pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_CHANNEL_0: u8 = 0;
74pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_CHANNEL_1: u8 = 1;
75pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_CHANNEL_LED_CONFIG_OFF: u8 = 0;
76pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_CHANNEL_LED_CONFIG_ON: u8 = 1;
77pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
78pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS: u8 = 3;
79pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
80pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
81pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
82pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
83pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
84pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
85pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
86pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
87pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
88pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
89pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
90pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
91pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
92pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
93pub const INDUSTRIAL_DUAL_AC_IN_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
94
95#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
96pub struct ValueCallbackConfiguration {
97 pub period: u32,
98 pub value_has_to_change: bool,
99}
100impl FromByteSlice for ValueCallbackConfiguration {
101 fn bytes_expected() -> usize {
102 5
103 }
104 fn from_le_byte_slice(bytes: &[u8]) -> ValueCallbackConfiguration {
105 ValueCallbackConfiguration {
106 period: <u32>::from_le_byte_slice(&bytes[0..4]),
107 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
108 }
109 }
110}
111
112#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
113pub struct AllValueCallbackConfiguration {
114 pub period: u32,
115 pub value_has_to_change: bool,
116}
117impl FromByteSlice for AllValueCallbackConfiguration {
118 fn bytes_expected() -> usize {
119 5
120 }
121 fn from_le_byte_slice(bytes: &[u8]) -> AllValueCallbackConfiguration {
122 AllValueCallbackConfiguration {
123 period: <u32>::from_le_byte_slice(&bytes[0..4]),
124 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
125 }
126 }
127}
128
129#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
130pub struct ValueEvent {
131 pub channel: u8,
132 pub changed: bool,
133 pub value: bool,
134}
135impl FromByteSlice for ValueEvent {
136 fn bytes_expected() -> usize {
137 3
138 }
139 fn from_le_byte_slice(bytes: &[u8]) -> ValueEvent {
140 ValueEvent {
141 channel: <u8>::from_le_byte_slice(&bytes[0..1]),
142 changed: <bool>::from_le_byte_slice(&bytes[1..2]),
143 value: <bool>::from_le_byte_slice(&bytes[2..3]),
144 }
145 }
146}
147
148#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
149pub struct AllValueEvent {
150 pub changed: [bool; 2],
151 pub value: [bool; 2],
152}
153impl FromByteSlice for AllValueEvent {
154 fn bytes_expected() -> usize {
155 2
156 }
157 fn from_le_byte_slice(bytes: &[u8]) -> AllValueEvent {
158 AllValueEvent { changed: <[bool; 2]>::from_le_byte_slice(&bytes[0..1]), value: <[bool; 2]>::from_le_byte_slice(&bytes[1..2]) }
159 }
160}
161
162#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
163pub struct SpitfpErrorCount {
164 pub error_count_ack_checksum: u32,
165 pub error_count_message_checksum: u32,
166 pub error_count_frame: u32,
167 pub error_count_overflow: u32,
168}
169impl FromByteSlice for SpitfpErrorCount {
170 fn bytes_expected() -> usize {
171 16
172 }
173 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
174 SpitfpErrorCount {
175 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
176 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
177 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
178 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
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#[derive(Clone)]
210pub struct IndustrialDualAcInBricklet {
211 device: Device,
212}
213impl IndustrialDualAcInBricklet {
214 pub const DEVICE_IDENTIFIER: u16 = 2174;
215 pub const DEVICE_DISPLAY_NAME: &'static str = "Industrial Dual AC In Bricklet";
216 pub fn new(uid: Uid, connection: AsyncIpConnection) -> IndustrialDualAcInBricklet {
218 let mut result = IndustrialDualAcInBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
219 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetValue) as usize] = ResponseExpectedFlag::AlwaysTrue;
220 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::SetValueCallbackConfiguration) as usize] =
221 ResponseExpectedFlag::True;
222 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetValueCallbackConfiguration) as usize] =
223 ResponseExpectedFlag::AlwaysTrue;
224 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::SetAllValueCallbackConfiguration) as usize] =
225 ResponseExpectedFlag::True;
226 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetAllValueCallbackConfiguration) as usize] =
227 ResponseExpectedFlag::AlwaysTrue;
228 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::SetChannelLedConfig) as usize] =
229 ResponseExpectedFlag::False;
230 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetChannelLedConfig) as usize] =
231 ResponseExpectedFlag::AlwaysTrue;
232 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetSpitfpErrorCount) as usize] =
233 ResponseExpectedFlag::AlwaysTrue;
234 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::SetBootloaderMode) as usize] =
235 ResponseExpectedFlag::AlwaysTrue;
236 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetBootloaderMode) as usize] =
237 ResponseExpectedFlag::AlwaysTrue;
238 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::SetWriteFirmwarePointer) as usize] =
239 ResponseExpectedFlag::False;
240 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::WriteFirmware) as usize] =
241 ResponseExpectedFlag::AlwaysTrue;
242 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::SetStatusLedConfig) as usize] =
243 ResponseExpectedFlag::False;
244 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetStatusLedConfig) as usize] =
245 ResponseExpectedFlag::AlwaysTrue;
246 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetChipTemperature) as usize] =
247 ResponseExpectedFlag::AlwaysTrue;
248 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
249 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
250 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
251 result.device.response_expected[u8::from(IndustrialDualAcInBrickletFunction::GetIdentity) as usize] =
252 ResponseExpectedFlag::AlwaysTrue;
253 result
254 }
255
256 pub fn get_response_expected(&mut self, fun: IndustrialDualAcInBrickletFunction) -> Result<bool, GetResponseExpectedError> {
271 self.device.get_response_expected(u8::from(fun))
272 }
273
274 pub fn set_response_expected(
283 &mut self,
284 fun: IndustrialDualAcInBrickletFunction,
285 response_expected: bool,
286 ) -> Result<(), SetResponseExpectedError> {
287 self.device.set_response_expected(u8::from(fun), response_expected)
288 }
289
290 pub fn set_response_expected_all(&mut self, response_expected: bool) {
292 self.device.set_response_expected_all(response_expected)
293 }
294
295 pub fn get_api_version(&self) -> [u8; 3] {
298 self.device.api_version
299 }
300
301 pub async fn get_value_callback_receiver(&mut self) -> impl Stream<Item = ValueEvent> {
310 self.device
311 .get_callback_receiver(u8::from(IndustrialDualAcInBrickletFunction::CallbackValue))
312 .await
313 .map(|p| ValueEvent::from_le_byte_slice(p.body()))
314 }
315
316 pub async fn get_all_value_callback_receiver(&mut self) -> impl Stream<Item = AllValueEvent> {
323 self.device
324 .get_callback_receiver(u8::from(IndustrialDualAcInBrickletFunction::CallbackAllValue))
325 .await
326 .map(|p| AllValueEvent::from_le_byte_slice(p.body()))
327 }
328
329 pub async fn get_value(&mut self) -> Result<Box<[bool; 2]>, TinkerforgeError> {
331 let payload = [0; 0];
332
333 #[allow(unused_variables)]
334 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetValue), &payload).await?;
335 Ok(Box::<[bool; 2]>::from_le_byte_slice(result.body()))
336 }
337
338 pub async fn set_value_callback_configuration(
354 &mut self,
355 channel: u8,
356 period: u32,
357 value_has_to_change: bool,
358 ) -> Result<(), TinkerforgeError> {
359 let mut payload = [0; 6];
360 channel.write_to_slice(&mut payload[0..1]);
361 period.write_to_slice(&mut payload[1..5]);
362 value_has_to_change.write_to_slice(&mut payload[5..6]);
363
364 #[allow(unused_variables)]
365 let result = self.device.set(u8::from(IndustrialDualAcInBrickletFunction::SetValueCallbackConfiguration), &payload).await?;
366 Ok(())
367 }
368
369 pub async fn get_value_callback_configuration(&mut self, channel: u8) -> Result<ValueCallbackConfiguration, TinkerforgeError> {
376 let mut payload = [0; 1];
377 channel.write_to_slice(&mut payload[0..1]);
378
379 #[allow(unused_variables)]
380 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetValueCallbackConfiguration), &payload).await?;
381 Ok(ValueCallbackConfiguration::from_le_byte_slice(result.body()))
382 }
383
384 pub async fn set_all_value_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
394 let mut payload = [0; 5];
395 period.write_to_slice(&mut payload[0..4]);
396 value_has_to_change.write_to_slice(&mut payload[4..5]);
397
398 #[allow(unused_variables)]
399 let result = self.device.set(u8::from(IndustrialDualAcInBrickletFunction::SetAllValueCallbackConfiguration), &payload).await?;
400 Ok(())
401 }
402
403 pub async fn get_all_value_callback_configuration(&mut self) -> Result<AllValueCallbackConfiguration, TinkerforgeError> {
406 let payload = [0; 0];
407
408 #[allow(unused_variables)]
409 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetAllValueCallbackConfiguration), &payload).await?;
410 Ok(AllValueCallbackConfiguration::from_le_byte_slice(result.body()))
411 }
412
413 pub async fn set_channel_led_config(&mut self, channel: u8, config: u8) -> Result<(), TinkerforgeError> {
427 let mut payload = [0; 2];
428 channel.write_to_slice(&mut payload[0..1]);
429 config.write_to_slice(&mut payload[1..2]);
430
431 #[allow(unused_variables)]
432 let result = self.device.set(u8::from(IndustrialDualAcInBrickletFunction::SetChannelLedConfig), &payload).await?;
433 Ok(())
434 }
435
436 pub async fn get_channel_led_config(&mut self, channel: u8) -> Result<u8, TinkerforgeError> {
446 let mut payload = [0; 1];
447 channel.write_to_slice(&mut payload[0..1]);
448
449 #[allow(unused_variables)]
450 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetChannelLedConfig), &payload).await?;
451 Ok(u8::from_le_byte_slice(result.body()))
452 }
453
454 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
466 let payload = [0; 0];
467
468 #[allow(unused_variables)]
469 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetSpitfpErrorCount), &payload).await?;
470 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
471 }
472
473 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
496 let mut payload = [0; 1];
497 mode.write_to_slice(&mut payload[0..1]);
498
499 #[allow(unused_variables)]
500 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::SetBootloaderMode), &payload).await?;
501 Ok(u8::from_le_byte_slice(result.body()))
502 }
503
504 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
513 let payload = [0; 0];
514
515 #[allow(unused_variables)]
516 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetBootloaderMode), &payload).await?;
517 Ok(u8::from_le_byte_slice(result.body()))
518 }
519
520 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
527 let mut payload = [0; 4];
528 pointer.write_to_slice(&mut payload[0..4]);
529
530 #[allow(unused_variables)]
531 let result = self.device.set(u8::from(IndustrialDualAcInBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
532 Ok(())
533 }
534
535 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
544 let mut payload = [0; 64];
545 data.write_to_slice(&mut payload[0..64]);
546
547 #[allow(unused_variables)]
548 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::WriteFirmware), &payload).await?;
549 Ok(u8::from_le_byte_slice(result.body()))
550 }
551
552 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
566 let mut payload = [0; 1];
567 config.write_to_slice(&mut payload[0..1]);
568
569 #[allow(unused_variables)]
570 let result = self.device.set(u8::from(IndustrialDualAcInBrickletFunction::SetStatusLedConfig), &payload).await?;
571 Ok(())
572 }
573
574 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
582 let payload = [0; 0];
583
584 #[allow(unused_variables)]
585 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetStatusLedConfig), &payload).await?;
586 Ok(u8::from_le_byte_slice(result.body()))
587 }
588
589 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
596 let payload = [0; 0];
597
598 #[allow(unused_variables)]
599 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetChipTemperature), &payload).await?;
600 Ok(i16::from_le_byte_slice(result.body()))
601 }
602
603 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
610 let payload = [0; 0];
611
612 #[allow(unused_variables)]
613 let result = self.device.set(u8::from(IndustrialDualAcInBrickletFunction::Reset), &payload).await?;
614 Ok(())
615 }
616
617 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
623 let mut payload = [0; 4];
624 uid.write_to_slice(&mut payload[0..4]);
625
626 #[allow(unused_variables)]
627 let result = self.device.set(u8::from(IndustrialDualAcInBrickletFunction::WriteUid), &payload).await?;
628 Ok(())
629 }
630
631 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
634 let payload = [0; 0];
635
636 #[allow(unused_variables)]
637 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::ReadUid), &payload).await?;
638 Ok(u32::from_le_byte_slice(result.body()))
639 }
640
641 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
652 let payload = [0; 0];
653
654 #[allow(unused_variables)]
655 let result = self.device.get(u8::from(IndustrialDualAcInBrickletFunction::GetIdentity), &payload).await?;
656 Ok(Identity::from_le_byte_slice(result.body()))
657 }
658}