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 IndustrialCounterBrickletFunction {
24 GetCounter,
25 GetAllCounter,
26 SetCounter,
27 SetAllCounter,
28 GetSignalData,
29 GetAllSignalData,
30 SetCounterActive,
31 SetAllCounterActive,
32 GetCounterActive,
33 GetAllCounterActive,
34 SetCounterConfiguration,
35 GetCounterConfiguration,
36 SetAllCounterCallbackConfiguration,
37 GetAllCounterCallbackConfiguration,
38 SetAllSignalDataCallbackConfiguration,
39 GetAllSignalDataCallbackConfiguration,
40 SetChannelLedConfig,
41 GetChannelLedConfig,
42 GetSpitfpErrorCount,
43 SetBootloaderMode,
44 GetBootloaderMode,
45 SetWriteFirmwarePointer,
46 WriteFirmware,
47 SetStatusLedConfig,
48 GetStatusLedConfig,
49 GetChipTemperature,
50 Reset,
51 WriteUid,
52 ReadUid,
53 GetIdentity,
54 CallbackAllCounter,
55 CallbackAllSignalData,
56}
57impl From<IndustrialCounterBrickletFunction> for u8 {
58 fn from(fun: IndustrialCounterBrickletFunction) -> Self {
59 match fun {
60 IndustrialCounterBrickletFunction::GetCounter => 1,
61 IndustrialCounterBrickletFunction::GetAllCounter => 2,
62 IndustrialCounterBrickletFunction::SetCounter => 3,
63 IndustrialCounterBrickletFunction::SetAllCounter => 4,
64 IndustrialCounterBrickletFunction::GetSignalData => 5,
65 IndustrialCounterBrickletFunction::GetAllSignalData => 6,
66 IndustrialCounterBrickletFunction::SetCounterActive => 7,
67 IndustrialCounterBrickletFunction::SetAllCounterActive => 8,
68 IndustrialCounterBrickletFunction::GetCounterActive => 9,
69 IndustrialCounterBrickletFunction::GetAllCounterActive => 10,
70 IndustrialCounterBrickletFunction::SetCounterConfiguration => 11,
71 IndustrialCounterBrickletFunction::GetCounterConfiguration => 12,
72 IndustrialCounterBrickletFunction::SetAllCounterCallbackConfiguration => 13,
73 IndustrialCounterBrickletFunction::GetAllCounterCallbackConfiguration => 14,
74 IndustrialCounterBrickletFunction::SetAllSignalDataCallbackConfiguration => 15,
75 IndustrialCounterBrickletFunction::GetAllSignalDataCallbackConfiguration => 16,
76 IndustrialCounterBrickletFunction::SetChannelLedConfig => 17,
77 IndustrialCounterBrickletFunction::GetChannelLedConfig => 18,
78 IndustrialCounterBrickletFunction::GetSpitfpErrorCount => 234,
79 IndustrialCounterBrickletFunction::SetBootloaderMode => 235,
80 IndustrialCounterBrickletFunction::GetBootloaderMode => 236,
81 IndustrialCounterBrickletFunction::SetWriteFirmwarePointer => 237,
82 IndustrialCounterBrickletFunction::WriteFirmware => 238,
83 IndustrialCounterBrickletFunction::SetStatusLedConfig => 239,
84 IndustrialCounterBrickletFunction::GetStatusLedConfig => 240,
85 IndustrialCounterBrickletFunction::GetChipTemperature => 242,
86 IndustrialCounterBrickletFunction::Reset => 243,
87 IndustrialCounterBrickletFunction::WriteUid => 248,
88 IndustrialCounterBrickletFunction::ReadUid => 249,
89 IndustrialCounterBrickletFunction::GetIdentity => 255,
90 IndustrialCounterBrickletFunction::CallbackAllCounter => 19,
91 IndustrialCounterBrickletFunction::CallbackAllSignalData => 20,
92 }
93 }
94}
95pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0: u8 = 0;
96pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1: u8 = 1;
97pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2: u8 = 2;
98pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3: u8 = 3;
99pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_RISING: u8 = 0;
100pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_FALLING: u8 = 1;
101pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_BOTH: u8 = 2;
102pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_UP: u8 = 0;
103pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_DOWN: u8 = 1;
104pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_UP: u8 = 2;
105pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_DOWN: u8 = 3;
106pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1: u8 = 0;
107pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2: u8 = 1;
108pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4: u8 = 2;
109pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8: u8 = 3;
110pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16: u8 = 4;
111pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32: u8 = 5;
112pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_64: u8 = 6;
113pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_128: u8 = 7;
114pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_256: u8 = 8;
115pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_512: u8 = 9;
116pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1024: u8 = 10;
117pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2048: u8 = 11;
118pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4096: u8 = 12;
119pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8192: u8 = 13;
120pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16384: u8 = 14;
121pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32768: u8 = 15;
122pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_128_MS: u8 = 0;
123pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_256_MS: u8 = 1;
124pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_512_MS: u8 = 2;
125pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_1024_MS: u8 = 3;
126pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_2048_MS: u8 = 4;
127pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_4096_MS: u8 = 5;
128pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_8192_MS: u8 = 6;
129pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_16384_MS: u8 = 7;
130pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_32768_MS: u8 = 8;
131pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_OFF: u8 = 0;
132pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_ON: u8 = 1;
133pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
134pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS: u8 = 3;
135pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
136pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
137pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
138pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
139pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
140pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
141pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
142pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
143pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
144pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
145pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
146pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
147pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
148pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
149pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
150
151#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
152pub struct SignalData {
153 pub duty_cycle: u16,
154 pub period: u64,
155 pub frequency: u32,
156 pub value: bool,
157}
158impl FromByteSlice for SignalData {
159 fn bytes_expected() -> usize {
160 15
161 }
162 fn from_le_byte_slice(bytes: &[u8]) -> SignalData {
163 SignalData {
164 duty_cycle: <u16>::from_le_byte_slice(&bytes[0..2]),
165 period: <u64>::from_le_byte_slice(&bytes[2..10]),
166 frequency: <u32>::from_le_byte_slice(&bytes[10..14]),
167 value: <bool>::from_le_byte_slice(&bytes[14..15]),
168 }
169 }
170}
171
172#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
173pub struct AllSignalData {
174 pub duty_cycle: [u16; 4],
175 pub period: [u64; 4],
176 pub frequency: [u32; 4],
177 pub value: [bool; 4],
178}
179impl FromByteSlice for AllSignalData {
180 fn bytes_expected() -> usize {
181 57
182 }
183 fn from_le_byte_slice(bytes: &[u8]) -> AllSignalData {
184 AllSignalData {
185 duty_cycle: <[u16; 4]>::from_le_byte_slice(&bytes[0..8]),
186 period: <[u64; 4]>::from_le_byte_slice(&bytes[8..40]),
187 frequency: <[u32; 4]>::from_le_byte_slice(&bytes[40..56]),
188 value: <[bool; 4]>::from_le_byte_slice(&bytes[56..57]),
189 }
190 }
191}
192
193#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
194pub struct CounterConfiguration {
195 pub count_edge: u8,
196 pub count_direction: u8,
197 pub duty_cycle_prescaler: u8,
198 pub frequency_integration_time: u8,
199}
200impl FromByteSlice for CounterConfiguration {
201 fn bytes_expected() -> usize {
202 4
203 }
204 fn from_le_byte_slice(bytes: &[u8]) -> CounterConfiguration {
205 CounterConfiguration {
206 count_edge: <u8>::from_le_byte_slice(&bytes[0..1]),
207 count_direction: <u8>::from_le_byte_slice(&bytes[1..2]),
208 duty_cycle_prescaler: <u8>::from_le_byte_slice(&bytes[2..3]),
209 frequency_integration_time: <u8>::from_le_byte_slice(&bytes[3..4]),
210 }
211 }
212}
213
214#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
215pub struct AllCounterCallbackConfiguration {
216 pub period: u32,
217 pub value_has_to_change: bool,
218}
219impl FromByteSlice for AllCounterCallbackConfiguration {
220 fn bytes_expected() -> usize {
221 5
222 }
223 fn from_le_byte_slice(bytes: &[u8]) -> AllCounterCallbackConfiguration {
224 AllCounterCallbackConfiguration {
225 period: <u32>::from_le_byte_slice(&bytes[0..4]),
226 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
227 }
228 }
229}
230
231#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
232pub struct AllSignalDataCallbackConfiguration {
233 pub period: u32,
234 pub value_has_to_change: bool,
235}
236impl FromByteSlice for AllSignalDataCallbackConfiguration {
237 fn bytes_expected() -> usize {
238 5
239 }
240 fn from_le_byte_slice(bytes: &[u8]) -> AllSignalDataCallbackConfiguration {
241 AllSignalDataCallbackConfiguration {
242 period: <u32>::from_le_byte_slice(&bytes[0..4]),
243 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
244 }
245 }
246}
247
248#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
249pub struct AllSignalDataEvent {
250 pub duty_cycle: [u16; 4],
251 pub period: [u64; 4],
252 pub frequency: [u32; 4],
253 pub value: [bool; 4],
254}
255impl FromByteSlice for AllSignalDataEvent {
256 fn bytes_expected() -> usize {
257 57
258 }
259 fn from_le_byte_slice(bytes: &[u8]) -> AllSignalDataEvent {
260 AllSignalDataEvent {
261 duty_cycle: <[u16; 4]>::from_le_byte_slice(&bytes[0..8]),
262 period: <[u64; 4]>::from_le_byte_slice(&bytes[8..40]),
263 frequency: <[u32; 4]>::from_le_byte_slice(&bytes[40..56]),
264 value: <[bool; 4]>::from_le_byte_slice(&bytes[56..57]),
265 }
266 }
267}
268
269#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
270pub struct SpitfpErrorCount {
271 pub error_count_ack_checksum: u32,
272 pub error_count_message_checksum: u32,
273 pub error_count_frame: u32,
274 pub error_count_overflow: u32,
275}
276impl FromByteSlice for SpitfpErrorCount {
277 fn bytes_expected() -> usize {
278 16
279 }
280 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
281 SpitfpErrorCount {
282 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
283 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
284 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
285 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
286 }
287 }
288}
289
290#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
291pub struct Identity {
292 pub uid: String,
293 pub connected_uid: String,
294 pub position: char,
295 pub hardware_version: [u8; 3],
296 pub firmware_version: [u8; 3],
297 pub device_identifier: u16,
298}
299impl FromByteSlice for Identity {
300 fn bytes_expected() -> usize {
301 25
302 }
303 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
304 Identity {
305 uid: <String>::from_le_byte_slice(&bytes[0..8]),
306 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
307 position: <char>::from_le_byte_slice(&bytes[16..17]),
308 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
309 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
310 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
311 }
312 }
313}
314
315#[derive(Clone)]
317pub struct IndustrialCounterBricklet {
318 device: Device,
319}
320impl IndustrialCounterBricklet {
321 pub const DEVICE_IDENTIFIER: u16 = 293;
322 pub const DEVICE_DISPLAY_NAME: &'static str = "Industrial Counter Bricklet";
323 pub fn new(uid: Uid, connection: AsyncIpConnection) -> IndustrialCounterBricklet {
325 let mut result = IndustrialCounterBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
326 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetCounter) as usize] =
327 ResponseExpectedFlag::AlwaysTrue;
328 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllCounter) as usize] =
329 ResponseExpectedFlag::AlwaysTrue;
330 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetCounter) as usize] = ResponseExpectedFlag::False;
331 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllCounter) as usize] = ResponseExpectedFlag::False;
332 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetSignalData) as usize] =
333 ResponseExpectedFlag::AlwaysTrue;
334 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllSignalData) as usize] =
335 ResponseExpectedFlag::AlwaysTrue;
336 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetCounterActive) as usize] =
337 ResponseExpectedFlag::False;
338 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllCounterActive) as usize] =
339 ResponseExpectedFlag::False;
340 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetCounterActive) as usize] =
341 ResponseExpectedFlag::AlwaysTrue;
342 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllCounterActive) as usize] =
343 ResponseExpectedFlag::AlwaysTrue;
344 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetCounterConfiguration) as usize] =
345 ResponseExpectedFlag::False;
346 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetCounterConfiguration) as usize] =
347 ResponseExpectedFlag::AlwaysTrue;
348 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllCounterCallbackConfiguration) as usize] =
349 ResponseExpectedFlag::True;
350 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllCounterCallbackConfiguration) as usize] =
351 ResponseExpectedFlag::AlwaysTrue;
352 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllSignalDataCallbackConfiguration) as usize] =
353 ResponseExpectedFlag::True;
354 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllSignalDataCallbackConfiguration) as usize] =
355 ResponseExpectedFlag::AlwaysTrue;
356 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetChannelLedConfig) as usize] =
357 ResponseExpectedFlag::False;
358 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetChannelLedConfig) as usize] =
359 ResponseExpectedFlag::AlwaysTrue;
360 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetSpitfpErrorCount) as usize] =
361 ResponseExpectedFlag::AlwaysTrue;
362 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetBootloaderMode) as usize] =
363 ResponseExpectedFlag::AlwaysTrue;
364 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetBootloaderMode) as usize] =
365 ResponseExpectedFlag::AlwaysTrue;
366 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetWriteFirmwarePointer) as usize] =
367 ResponseExpectedFlag::False;
368 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::WriteFirmware) as usize] =
369 ResponseExpectedFlag::AlwaysTrue;
370 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetStatusLedConfig) as usize] =
371 ResponseExpectedFlag::False;
372 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetStatusLedConfig) as usize] =
373 ResponseExpectedFlag::AlwaysTrue;
374 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetChipTemperature) as usize] =
375 ResponseExpectedFlag::AlwaysTrue;
376 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
377 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
378 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
379 result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetIdentity) as usize] =
380 ResponseExpectedFlag::AlwaysTrue;
381 result
382 }
383
384 pub fn get_response_expected(&mut self, fun: IndustrialCounterBrickletFunction) -> Result<bool, GetResponseExpectedError> {
399 self.device.get_response_expected(u8::from(fun))
400 }
401
402 pub fn set_response_expected(
411 &mut self,
412 fun: IndustrialCounterBrickletFunction,
413 response_expected: bool,
414 ) -> Result<(), SetResponseExpectedError> {
415 self.device.set_response_expected(u8::from(fun), response_expected)
416 }
417
418 pub fn set_response_expected_all(&mut self, response_expected: bool) {
420 self.device.set_response_expected_all(response_expected)
421 }
422
423 pub fn get_api_version(&self) -> [u8; 3] {
426 self.device.api_version
427 }
428
429 pub async fn get_all_counter_callback_receiver(&mut self) -> impl Stream<Item = [i64; 4]> {
437 self.device
438 .get_callback_receiver(u8::from(IndustrialCounterBrickletFunction::CallbackAllCounter))
439 .await
440 .map(|p| <[i64; 4]>::from_le_byte_slice(p.body()))
441 }
442
443 pub async fn get_all_signal_data_callback_receiver(&mut self) -> impl Stream<Item = AllSignalDataEvent> {
448 self.device
449 .get_callback_receiver(u8::from(IndustrialCounterBrickletFunction::CallbackAllSignalData))
450 .await
451 .map(|p| AllSignalDataEvent::from_le_byte_slice(p.body()))
452 }
453
454 pub async fn get_counter(&mut self, channel: u8) -> Result<i64, TinkerforgeError> {
462 let mut payload = [0; 1];
463 channel.write_to_slice(&mut payload[0..1]);
464
465 #[allow(unused_variables)]
466 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetCounter), &payload).await?;
467 Ok(i64::from_le_byte_slice(result.body()))
468 }
469
470 pub async fn get_all_counter(&mut self) -> Result<Box<[i64; 4]>, TinkerforgeError> {
472 let payload = [0; 0];
473
474 #[allow(unused_variables)]
475 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllCounter), &payload).await?;
476 Ok(Box::<[i64; 4]>::from_le_byte_slice(result.body()))
477 }
478
479 pub async fn set_counter(&mut self, channel: u8, counter: i64) -> Result<(), TinkerforgeError> {
489 let mut payload = [0; 9];
490 channel.write_to_slice(&mut payload[0..1]);
491 counter.write_to_slice(&mut payload[1..9]);
492
493 #[allow(unused_variables)]
494 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetCounter), &payload).await?;
495 Ok(())
496 }
497
498 pub async fn set_all_counter(&mut self, counter: &[i64; 4]) -> Result<(), TinkerforgeError> {
502 let mut payload = [0; 32];
503 counter.write_to_slice(&mut payload[0..32]);
504
505 #[allow(unused_variables)]
506 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllCounter), &payload).await?;
507 Ok(())
508 }
509
510 pub async fn get_signal_data(&mut self, channel: u8) -> Result<SignalData, TinkerforgeError> {
519 let mut payload = [0; 1];
520 channel.write_to_slice(&mut payload[0..1]);
521
522 #[allow(unused_variables)]
523 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetSignalData), &payload).await?;
524 Ok(SignalData::from_le_byte_slice(result.body()))
525 }
526
527 pub async fn get_all_signal_data(&mut self) -> Result<AllSignalData, TinkerforgeError> {
530 let payload = [0; 0];
531
532 #[allow(unused_variables)]
533 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllSignalData), &payload).await?;
534 Ok(AllSignalData::from_le_byte_slice(result.body()))
535 }
536
537 pub async fn set_counter_active(&mut self, channel: u8, active: bool) -> Result<(), TinkerforgeError> {
549 let mut payload = [0; 2];
550 channel.write_to_slice(&mut payload[0..1]);
551 active.write_to_slice(&mut payload[1..2]);
552
553 #[allow(unused_variables)]
554 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetCounterActive), &payload).await?;
555 Ok(())
556 }
557
558 pub async fn set_all_counter_active(&mut self, active: &[bool; 4]) -> Result<(), TinkerforgeError> {
564 let mut payload = [0; 1];
565 active.write_to_slice(&mut payload[0..1]);
566
567 #[allow(unused_variables)]
568 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllCounterActive), &payload).await?;
569 Ok(())
570 }
571
572 pub async fn get_counter_active(&mut self, channel: u8) -> Result<bool, TinkerforgeError> {
582 let mut payload = [0; 1];
583 channel.write_to_slice(&mut payload[0..1]);
584
585 #[allow(unused_variables)]
586 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetCounterActive), &payload).await?;
587 Ok(bool::from_le_byte_slice(result.body()))
588 }
589
590 pub async fn get_all_counter_active(&mut self) -> Result<Box<[bool; 4]>, TinkerforgeError> {
594 let payload = [0; 0];
595
596 #[allow(unused_variables)]
597 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllCounterActive), &payload).await?;
598 Ok(Box::<[bool; 4]>::from_le_byte_slice(result.body()))
599 }
600
601 pub async fn set_counter_configuration(
654 &mut self,
655 channel: u8,
656 count_edge: u8,
657 count_direction: u8,
658 duty_cycle_prescaler: u8,
659 frequency_integration_time: u8,
660 ) -> Result<(), TinkerforgeError> {
661 let mut payload = [0; 5];
662 channel.write_to_slice(&mut payload[0..1]);
663 count_edge.write_to_slice(&mut payload[1..2]);
664 count_direction.write_to_slice(&mut payload[2..3]);
665 duty_cycle_prescaler.write_to_slice(&mut payload[3..4]);
666 frequency_integration_time.write_to_slice(&mut payload[4..5]);
667
668 #[allow(unused_variables)]
669 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetCounterConfiguration), &payload).await?;
670 Ok(())
671 }
672
673 pub async fn get_counter_configuration(&mut self, channel: u8) -> Result<CounterConfiguration, TinkerforgeError> {
713 let mut payload = [0; 1];
714 channel.write_to_slice(&mut payload[0..1]);
715
716 #[allow(unused_variables)]
717 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetCounterConfiguration), &payload).await?;
718 Ok(CounterConfiguration::from_le_byte_slice(result.body()))
719 }
720
721 pub async fn set_all_counter_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
731 let mut payload = [0; 5];
732 period.write_to_slice(&mut payload[0..4]);
733 value_has_to_change.write_to_slice(&mut payload[4..5]);
734
735 #[allow(unused_variables)]
736 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllCounterCallbackConfiguration), &payload).await?;
737 Ok(())
738 }
739
740 pub async fn get_all_counter_callback_configuration(&mut self) -> Result<AllCounterCallbackConfiguration, TinkerforgeError> {
743 let payload = [0; 0];
744
745 #[allow(unused_variables)]
746 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllCounterCallbackConfiguration), &payload).await?;
747 Ok(AllCounterCallbackConfiguration::from_le_byte_slice(result.body()))
748 }
749
750 pub async fn set_all_signal_data_callback_configuration(
760 &mut self,
761 period: u32,
762 value_has_to_change: bool,
763 ) -> Result<(), TinkerforgeError> {
764 let mut payload = [0; 5];
765 period.write_to_slice(&mut payload[0..4]);
766 value_has_to_change.write_to_slice(&mut payload[4..5]);
767
768 #[allow(unused_variables)]
769 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllSignalDataCallbackConfiguration), &payload).await?;
770 Ok(())
771 }
772
773 pub async fn get_all_signal_data_callback_configuration(&mut self) -> Result<AllSignalDataCallbackConfiguration, TinkerforgeError> {
776 let payload = [0; 0];
777
778 #[allow(unused_variables)]
779 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllSignalDataCallbackConfiguration), &payload).await?;
780 Ok(AllSignalDataCallbackConfiguration::from_le_byte_slice(result.body()))
781 }
782
783 pub async fn set_channel_led_config(&mut self, channel: u8, config: u8) -> Result<(), TinkerforgeError> {
797 let mut payload = [0; 2];
798 channel.write_to_slice(&mut payload[0..1]);
799 config.write_to_slice(&mut payload[1..2]);
800
801 #[allow(unused_variables)]
802 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetChannelLedConfig), &payload).await?;
803 Ok(())
804 }
805
806 pub async fn get_channel_led_config(&mut self, channel: u8) -> Result<u8, TinkerforgeError> {
818 let mut payload = [0; 1];
819 channel.write_to_slice(&mut payload[0..1]);
820
821 #[allow(unused_variables)]
822 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetChannelLedConfig), &payload).await?;
823 Ok(u8::from_le_byte_slice(result.body()))
824 }
825
826 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
838 let payload = [0; 0];
839
840 #[allow(unused_variables)]
841 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetSpitfpErrorCount), &payload).await?;
842 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
843 }
844
845 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
868 let mut payload = [0; 1];
869 mode.write_to_slice(&mut payload[0..1]);
870
871 #[allow(unused_variables)]
872 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::SetBootloaderMode), &payload).await?;
873 Ok(u8::from_le_byte_slice(result.body()))
874 }
875
876 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
885 let payload = [0; 0];
886
887 #[allow(unused_variables)]
888 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetBootloaderMode), &payload).await?;
889 Ok(u8::from_le_byte_slice(result.body()))
890 }
891
892 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
899 let mut payload = [0; 4];
900 pointer.write_to_slice(&mut payload[0..4]);
901
902 #[allow(unused_variables)]
903 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
904 Ok(())
905 }
906
907 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
916 let mut payload = [0; 64];
917 data.write_to_slice(&mut payload[0..64]);
918
919 #[allow(unused_variables)]
920 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::WriteFirmware), &payload).await?;
921 Ok(u8::from_le_byte_slice(result.body()))
922 }
923
924 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
938 let mut payload = [0; 1];
939 config.write_to_slice(&mut payload[0..1]);
940
941 #[allow(unused_variables)]
942 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetStatusLedConfig), &payload).await?;
943 Ok(())
944 }
945
946 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
954 let payload = [0; 0];
955
956 #[allow(unused_variables)]
957 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetStatusLedConfig), &payload).await?;
958 Ok(u8::from_le_byte_slice(result.body()))
959 }
960
961 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
968 let payload = [0; 0];
969
970 #[allow(unused_variables)]
971 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetChipTemperature), &payload).await?;
972 Ok(i16::from_le_byte_slice(result.body()))
973 }
974
975 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
982 let payload = [0; 0];
983
984 #[allow(unused_variables)]
985 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::Reset), &payload).await?;
986 Ok(())
987 }
988
989 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
995 let mut payload = [0; 4];
996 uid.write_to_slice(&mut payload[0..4]);
997
998 #[allow(unused_variables)]
999 let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::WriteUid), &payload).await?;
1000 Ok(())
1001 }
1002
1003 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
1006 let payload = [0; 0];
1007
1008 #[allow(unused_variables)]
1009 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::ReadUid), &payload).await?;
1010 Ok(u32::from_le_byte_slice(result.body()))
1011 }
1012
1013 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
1024 let payload = [0; 0];
1025
1026 #[allow(unused_variables)]
1027 let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetIdentity), &payload).await?;
1028 Ok(Identity::from_le_byte_slice(result.body()))
1029 }
1030}