tinkerforge_async/bindings/
gps_v3_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! Determine position, velocity and altitude using GPS.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/GPSV3_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, converting_receiver::BrickletRecvTimeoutError, device::*, error::TinkerforgeError,
17    ip_connection::async_io::AsyncIpConnection, low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum GpsV3BrickletFunction {
24    GetCoordinates,
25    GetStatus,
26    GetAltitude,
27    GetMotion,
28    GetDateTime,
29    Restart,
30    GetSatelliteSystemStatusLowLevel,
31    GetSatelliteStatus,
32    SetFixLedConfig,
33    GetFixLedConfig,
34    SetCoordinatesCallbackPeriod,
35    GetCoordinatesCallbackPeriod,
36    SetStatusCallbackPeriod,
37    GetStatusCallbackPeriod,
38    SetAltitudeCallbackPeriod,
39    GetAltitudeCallbackPeriod,
40    SetMotionCallbackPeriod,
41    GetMotionCallbackPeriod,
42    SetDateTimeCallbackPeriod,
43    GetDateTimeCallbackPeriod,
44    SetSbasConfig,
45    GetSbasConfig,
46    GetSpitfpErrorCount,
47    SetBootloaderMode,
48    GetBootloaderMode,
49    SetWriteFirmwarePointer,
50    WriteFirmware,
51    SetStatusLedConfig,
52    GetStatusLedConfig,
53    GetChipTemperature,
54    Reset,
55    WriteUid,
56    ReadUid,
57    GetIdentity,
58    CallbackPulsePerSecond,
59    CallbackCoordinates,
60    CallbackStatus,
61    CallbackAltitude,
62    CallbackMotion,
63    CallbackDateTime,
64}
65impl From<GpsV3BrickletFunction> for u8 {
66    fn from(fun: GpsV3BrickletFunction) -> Self {
67        match fun {
68            GpsV3BrickletFunction::GetCoordinates => 1,
69            GpsV3BrickletFunction::GetStatus => 2,
70            GpsV3BrickletFunction::GetAltitude => 3,
71            GpsV3BrickletFunction::GetMotion => 4,
72            GpsV3BrickletFunction::GetDateTime => 5,
73            GpsV3BrickletFunction::Restart => 6,
74            GpsV3BrickletFunction::GetSatelliteSystemStatusLowLevel => 7,
75            GpsV3BrickletFunction::GetSatelliteStatus => 8,
76            GpsV3BrickletFunction::SetFixLedConfig => 9,
77            GpsV3BrickletFunction::GetFixLedConfig => 10,
78            GpsV3BrickletFunction::SetCoordinatesCallbackPeriod => 11,
79            GpsV3BrickletFunction::GetCoordinatesCallbackPeriod => 12,
80            GpsV3BrickletFunction::SetStatusCallbackPeriod => 13,
81            GpsV3BrickletFunction::GetStatusCallbackPeriod => 14,
82            GpsV3BrickletFunction::SetAltitudeCallbackPeriod => 15,
83            GpsV3BrickletFunction::GetAltitudeCallbackPeriod => 16,
84            GpsV3BrickletFunction::SetMotionCallbackPeriod => 17,
85            GpsV3BrickletFunction::GetMotionCallbackPeriod => 18,
86            GpsV3BrickletFunction::SetDateTimeCallbackPeriod => 19,
87            GpsV3BrickletFunction::GetDateTimeCallbackPeriod => 20,
88            GpsV3BrickletFunction::SetSbasConfig => 27,
89            GpsV3BrickletFunction::GetSbasConfig => 28,
90            GpsV3BrickletFunction::GetSpitfpErrorCount => 234,
91            GpsV3BrickletFunction::SetBootloaderMode => 235,
92            GpsV3BrickletFunction::GetBootloaderMode => 236,
93            GpsV3BrickletFunction::SetWriteFirmwarePointer => 237,
94            GpsV3BrickletFunction::WriteFirmware => 238,
95            GpsV3BrickletFunction::SetStatusLedConfig => 239,
96            GpsV3BrickletFunction::GetStatusLedConfig => 240,
97            GpsV3BrickletFunction::GetChipTemperature => 242,
98            GpsV3BrickletFunction::Reset => 243,
99            GpsV3BrickletFunction::WriteUid => 248,
100            GpsV3BrickletFunction::ReadUid => 249,
101            GpsV3BrickletFunction::GetIdentity => 255,
102            GpsV3BrickletFunction::CallbackPulsePerSecond => 21,
103            GpsV3BrickletFunction::CallbackCoordinates => 22,
104            GpsV3BrickletFunction::CallbackStatus => 23,
105            GpsV3BrickletFunction::CallbackAltitude => 24,
106            GpsV3BrickletFunction::CallbackMotion => 25,
107            GpsV3BrickletFunction::CallbackDateTime => 26,
108        }
109    }
110}
111pub const GPS_V3_BRICKLET_RESTART_TYPE_HOT_START: u8 = 0;
112pub const GPS_V3_BRICKLET_RESTART_TYPE_WARM_START: u8 = 1;
113pub const GPS_V3_BRICKLET_RESTART_TYPE_COLD_START: u8 = 2;
114pub const GPS_V3_BRICKLET_RESTART_TYPE_FACTORY_RESET: u8 = 3;
115pub const GPS_V3_BRICKLET_SATELLITE_SYSTEM_GPS: u8 = 0;
116pub const GPS_V3_BRICKLET_SATELLITE_SYSTEM_GLONASS: u8 = 1;
117pub const GPS_V3_BRICKLET_SATELLITE_SYSTEM_GALILEO: u8 = 2;
118pub const GPS_V3_BRICKLET_FIX_NO_FIX: u8 = 1;
119pub const GPS_V3_BRICKLET_FIX_2D_FIX: u8 = 2;
120pub const GPS_V3_BRICKLET_FIX_3D_FIX: u8 = 3;
121pub const GPS_V3_BRICKLET_FIX_LED_CONFIG_OFF: u8 = 0;
122pub const GPS_V3_BRICKLET_FIX_LED_CONFIG_ON: u8 = 1;
123pub const GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
124pub const GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_FIX: u8 = 3;
125pub const GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_PPS: u8 = 4;
126pub const GPS_V3_BRICKLET_SBAS_ENABLED: u8 = 0;
127pub const GPS_V3_BRICKLET_SBAS_DISABLED: u8 = 1;
128pub const GPS_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
129pub const GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
130pub const GPS_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
131pub const GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
132pub const GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
133pub const GPS_V3_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
134pub const GPS_V3_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
135pub const GPS_V3_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
136pub const GPS_V3_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
137pub const GPS_V3_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
138pub const GPS_V3_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
139pub const GPS_V3_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
140pub const GPS_V3_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
141pub const GPS_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
142pub const GPS_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
143
144#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
145pub struct Coordinates {
146    pub latitude: u32,
147    pub ns: char,
148    pub longitude: u32,
149    pub ew: char,
150}
151impl FromByteSlice for Coordinates {
152    fn bytes_expected() -> usize {
153        10
154    }
155    fn from_le_byte_slice(bytes: &[u8]) -> Coordinates {
156        Coordinates {
157            latitude: <u32>::from_le_byte_slice(&bytes[0..4]),
158            ns: <char>::from_le_byte_slice(&bytes[4..5]),
159            longitude: <u32>::from_le_byte_slice(&bytes[5..9]),
160            ew: <char>::from_le_byte_slice(&bytes[9..10]),
161        }
162    }
163}
164
165#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
166pub struct Status {
167    pub has_fix: bool,
168    pub satellites_view: u8,
169}
170impl FromByteSlice for Status {
171    fn bytes_expected() -> usize {
172        2
173    }
174    fn from_le_byte_slice(bytes: &[u8]) -> Status {
175        Status { has_fix: <bool>::from_le_byte_slice(&bytes[0..1]), satellites_view: <u8>::from_le_byte_slice(&bytes[1..2]) }
176    }
177}
178
179#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
180pub struct Altitude {
181    pub altitude: i32,
182    pub geoidal_separation: i32,
183}
184impl FromByteSlice for Altitude {
185    fn bytes_expected() -> usize {
186        8
187    }
188    fn from_le_byte_slice(bytes: &[u8]) -> Altitude {
189        Altitude { altitude: <i32>::from_le_byte_slice(&bytes[0..4]), geoidal_separation: <i32>::from_le_byte_slice(&bytes[4..8]) }
190    }
191}
192
193#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
194pub struct Motion {
195    pub course: u32,
196    pub speed: u32,
197}
198impl FromByteSlice for Motion {
199    fn bytes_expected() -> usize {
200        8
201    }
202    fn from_le_byte_slice(bytes: &[u8]) -> Motion {
203        Motion { course: <u32>::from_le_byte_slice(&bytes[0..4]), speed: <u32>::from_le_byte_slice(&bytes[4..8]) }
204    }
205}
206
207#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
208pub struct DateTime {
209    pub date: u32,
210    pub time: u32,
211}
212impl FromByteSlice for DateTime {
213    fn bytes_expected() -> usize {
214        8
215    }
216    fn from_le_byte_slice(bytes: &[u8]) -> DateTime {
217        DateTime { date: <u32>::from_le_byte_slice(&bytes[0..4]), time: <u32>::from_le_byte_slice(&bytes[4..8]) }
218    }
219}
220
221#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
222pub struct SatelliteSystemStatusLowLevel {
223    pub satellite_numbers_length: u8,
224    pub satellite_numbers_data: [u8; 12],
225    pub fix: u8,
226    pub pdop: u16,
227    pub hdop: u16,
228    pub vdop: u16,
229}
230impl FromByteSlice for SatelliteSystemStatusLowLevel {
231    fn bytes_expected() -> usize {
232        20
233    }
234    fn from_le_byte_slice(bytes: &[u8]) -> SatelliteSystemStatusLowLevel {
235        SatelliteSystemStatusLowLevel {
236            satellite_numbers_length: <u8>::from_le_byte_slice(&bytes[0..1]),
237            satellite_numbers_data: <[u8; 12]>::from_le_byte_slice(&bytes[1..13]),
238            fix: <u8>::from_le_byte_slice(&bytes[13..14]),
239            pdop: <u16>::from_le_byte_slice(&bytes[14..16]),
240            hdop: <u16>::from_le_byte_slice(&bytes[16..18]),
241            vdop: <u16>::from_le_byte_slice(&bytes[18..20]),
242        }
243    }
244}
245impl LowLevelRead<u8, SatelliteSystemStatusResult> for SatelliteSystemStatusLowLevel {
246    fn ll_message_length(&self) -> usize {
247        self.satellite_numbers_length as usize
248    }
249
250    fn ll_message_chunk_offset(&self) -> usize {
251        0
252    }
253
254    fn ll_message_chunk_data(&self) -> &[u8] {
255        &self.satellite_numbers_data
256    }
257
258    fn get_result(&self) -> SatelliteSystemStatusResult {
259        SatelliteSystemStatusResult { fix: self.fix, pdop: self.pdop, hdop: self.hdop, vdop: self.vdop }
260    }
261}
262
263#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
264pub struct SatelliteStatus {
265    pub elevation: i16,
266    pub azimuth: i16,
267    pub snr: i16,
268}
269impl FromByteSlice for SatelliteStatus {
270    fn bytes_expected() -> usize {
271        6
272    }
273    fn from_le_byte_slice(bytes: &[u8]) -> SatelliteStatus {
274        SatelliteStatus {
275            elevation: <i16>::from_le_byte_slice(&bytes[0..2]),
276            azimuth: <i16>::from_le_byte_slice(&bytes[2..4]),
277            snr: <i16>::from_le_byte_slice(&bytes[4..6]),
278        }
279    }
280}
281
282#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
283pub struct CoordinatesEvent {
284    pub latitude: u32,
285    pub ns: char,
286    pub longitude: u32,
287    pub ew: char,
288}
289impl FromByteSlice for CoordinatesEvent {
290    fn bytes_expected() -> usize {
291        10
292    }
293    fn from_le_byte_slice(bytes: &[u8]) -> CoordinatesEvent {
294        CoordinatesEvent {
295            latitude: <u32>::from_le_byte_slice(&bytes[0..4]),
296            ns: <char>::from_le_byte_slice(&bytes[4..5]),
297            longitude: <u32>::from_le_byte_slice(&bytes[5..9]),
298            ew: <char>::from_le_byte_slice(&bytes[9..10]),
299        }
300    }
301}
302
303#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
304pub struct StatusEvent {
305    pub has_fix: bool,
306    pub satellites_view: u8,
307}
308impl FromByteSlice for StatusEvent {
309    fn bytes_expected() -> usize {
310        2
311    }
312    fn from_le_byte_slice(bytes: &[u8]) -> StatusEvent {
313        StatusEvent { has_fix: <bool>::from_le_byte_slice(&bytes[0..1]), satellites_view: <u8>::from_le_byte_slice(&bytes[1..2]) }
314    }
315}
316
317#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
318pub struct AltitudeEvent {
319    pub altitude: i32,
320    pub geoidal_separation: i32,
321}
322impl FromByteSlice for AltitudeEvent {
323    fn bytes_expected() -> usize {
324        8
325    }
326    fn from_le_byte_slice(bytes: &[u8]) -> AltitudeEvent {
327        AltitudeEvent { altitude: <i32>::from_le_byte_slice(&bytes[0..4]), geoidal_separation: <i32>::from_le_byte_slice(&bytes[4..8]) }
328    }
329}
330
331#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
332pub struct MotionEvent {
333    pub course: u32,
334    pub speed: u32,
335}
336impl FromByteSlice for MotionEvent {
337    fn bytes_expected() -> usize {
338        8
339    }
340    fn from_le_byte_slice(bytes: &[u8]) -> MotionEvent {
341        MotionEvent { course: <u32>::from_le_byte_slice(&bytes[0..4]), speed: <u32>::from_le_byte_slice(&bytes[4..8]) }
342    }
343}
344
345#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
346pub struct DateTimeEvent {
347    pub date: u32,
348    pub time: u32,
349}
350impl FromByteSlice for DateTimeEvent {
351    fn bytes_expected() -> usize {
352        8
353    }
354    fn from_le_byte_slice(bytes: &[u8]) -> DateTimeEvent {
355        DateTimeEvent { date: <u32>::from_le_byte_slice(&bytes[0..4]), time: <u32>::from_le_byte_slice(&bytes[4..8]) }
356    }
357}
358
359#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
360pub struct SpitfpErrorCount {
361    pub error_count_ack_checksum: u32,
362    pub error_count_message_checksum: u32,
363    pub error_count_frame: u32,
364    pub error_count_overflow: u32,
365}
366impl FromByteSlice for SpitfpErrorCount {
367    fn bytes_expected() -> usize {
368        16
369    }
370    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
371        SpitfpErrorCount {
372            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
373            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
374            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
375            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
376        }
377    }
378}
379
380#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
381pub struct Identity {
382    pub uid: String,
383    pub connected_uid: String,
384    pub position: char,
385    pub hardware_version: [u8; 3],
386    pub firmware_version: [u8; 3],
387    pub device_identifier: u16,
388}
389impl FromByteSlice for Identity {
390    fn bytes_expected() -> usize {
391        25
392    }
393    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
394        Identity {
395            uid: <String>::from_le_byte_slice(&bytes[0..8]),
396            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
397            position: <char>::from_le_byte_slice(&bytes[16..17]),
398            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
399            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
400            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
401        }
402    }
403}
404
405#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
406pub struct SatelliteSystemStatusResult {
407    pub fix: u8,
408    pub pdop: u16,
409    pub hdop: u16,
410    pub vdop: u16,
411}
412
413/// Determine position, velocity and altitude using GPS
414#[derive(Clone)]
415pub struct GpsV3Bricklet {
416    device: Device,
417}
418impl GpsV3Bricklet {
419    pub const DEVICE_IDENTIFIER: u16 = 2171;
420    pub const DEVICE_DISPLAY_NAME: &'static str = "GPS Bricklet 3.0";
421    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
422    pub fn new(uid: Uid, connection: AsyncIpConnection) -> GpsV3Bricklet {
423        let mut result = GpsV3Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
424        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetCoordinates) as usize] = ResponseExpectedFlag::AlwaysTrue;
425        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
426        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetAltitude) as usize] = ResponseExpectedFlag::AlwaysTrue;
427        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetMotion) as usize] = ResponseExpectedFlag::AlwaysTrue;
428        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetDateTime) as usize] = ResponseExpectedFlag::AlwaysTrue;
429        result.device.response_expected[u8::from(GpsV3BrickletFunction::Restart) as usize] = ResponseExpectedFlag::False;
430        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetSatelliteSystemStatusLowLevel) as usize] =
431            ResponseExpectedFlag::AlwaysTrue;
432        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetSatelliteStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
433        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetFixLedConfig) as usize] = ResponseExpectedFlag::False;
434        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetFixLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
435        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetCoordinatesCallbackPeriod) as usize] =
436            ResponseExpectedFlag::True;
437        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetCoordinatesCallbackPeriod) as usize] =
438            ResponseExpectedFlag::AlwaysTrue;
439        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetStatusCallbackPeriod) as usize] = ResponseExpectedFlag::True;
440        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetStatusCallbackPeriod) as usize] =
441            ResponseExpectedFlag::AlwaysTrue;
442        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetAltitudeCallbackPeriod) as usize] = ResponseExpectedFlag::True;
443        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetAltitudeCallbackPeriod) as usize] =
444            ResponseExpectedFlag::AlwaysTrue;
445        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetMotionCallbackPeriod) as usize] = ResponseExpectedFlag::True;
446        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetMotionCallbackPeriod) as usize] =
447            ResponseExpectedFlag::AlwaysTrue;
448        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetDateTimeCallbackPeriod) as usize] = ResponseExpectedFlag::True;
449        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetDateTimeCallbackPeriod) as usize] =
450            ResponseExpectedFlag::AlwaysTrue;
451        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetSbasConfig) as usize] = ResponseExpectedFlag::False;
452        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetSbasConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
453        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
454        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
455        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
456        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
457        result.device.response_expected[u8::from(GpsV3BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
458        result.device.response_expected[u8::from(GpsV3BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
459        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
460        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
461        result.device.response_expected[u8::from(GpsV3BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
462        result.device.response_expected[u8::from(GpsV3BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
463        result.device.response_expected[u8::from(GpsV3BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
464        result.device.response_expected[u8::from(GpsV3BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
465        result
466    }
467
468    /// Returns the response expected flag for the function specified by the function ID parameter.
469    /// It is true if the function is expected to send a response, false otherwise.
470    ///
471    /// For getter functions this is enabled by default and cannot be disabled, because those
472    /// functions will always send a response. For callback configuration functions it is enabled
473    /// by default too, but can be disabled by [`set_response_expected`](crate::gps_v3_bricklet::GpsV3Bricklet::set_response_expected).
474    /// For setter functions it is disabled by default and can be enabled.
475    ///
476    /// Enabling the response expected flag for a setter function allows to detect timeouts
477    /// and other error conditions calls of this setter as well. The device will then send a response
478    /// for this purpose. If this flag is disabled for a setter function then no response is sent
479    /// and errors are silently ignored, because they cannot be detected.
480    ///
481    /// See [`set_response_expected`](crate::gps_v3_bricklet::GpsV3Bricklet::set_response_expected) for the list of function ID constants available for this function.
482    pub fn get_response_expected(&mut self, fun: GpsV3BrickletFunction) -> Result<bool, GetResponseExpectedError> {
483        self.device.get_response_expected(u8::from(fun))
484    }
485
486    /// Changes the response expected flag of the function specified by the function ID parameter.
487    /// This flag can only be changed for setter (default value: false) and callback configuration
488    /// functions (default value: true). For getter functions it is always enabled.
489    ///
490    /// Enabling the response expected flag for a setter function allows to detect timeouts and
491    /// other error conditions calls of this setter as well. The device will then send a response
492    /// for this purpose. If this flag is disabled for a setter function then no response is sent
493    /// and errors are silently ignored, because they cannot be detected.
494    pub fn set_response_expected(&mut self, fun: GpsV3BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
495        self.device.set_response_expected(u8::from(fun), response_expected)
496    }
497
498    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
499    pub fn set_response_expected_all(&mut self, response_expected: bool) {
500        self.device.set_response_expected_all(response_expected)
501    }
502
503    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
504    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
505    pub fn get_api_version(&self) -> [u8; 3] {
506        self.device.api_version
507    }
508
509    /// This receiver is triggered precisely once per second,
510    /// see [PPS](https://en.wikipedia.org/wiki/Pulse-per-second_signal)__.
511    ///
512    /// The precision of two subsequent pulses will be skewed because
513    /// of the latency in the USB/RS485/Ethernet connection. But in the
514    /// long run this will be very precise. For example a count of
515    /// 3600 pulses will take exactly 1 hour.
516    pub async fn get_pulse_per_second_callback_receiver(&mut self) -> impl Stream<Item = ()> {
517        self.device.get_callback_receiver(u8::from(GpsV3BrickletFunction::CallbackPulsePerSecond)).await.map(|_p| ())
518    }
519
520    /// This receiver is triggered periodically with the period that is set by
521    /// [`set_coordinates_callback_period`]. The parameters are the same
522    /// as for [`get_coordinates`].
523    ///
524    /// The [`get_coordinates_callback_receiver`] receiver is only triggered if the coordinates changed
525    /// since the last triggering and if there is currently a fix as indicated by
526    /// [`get_status`].
527    pub async fn get_coordinates_callback_receiver(&mut self) -> impl Stream<Item = CoordinatesEvent> {
528        self.device
529            .get_callback_receiver(u8::from(GpsV3BrickletFunction::CallbackCoordinates))
530            .await
531            .map(|p| CoordinatesEvent::from_le_byte_slice(p.body()))
532    }
533
534    /// This receiver is triggered periodically with the period that is set by
535    /// [`set_status_callback_period`]. The parameters are the same
536    /// as for [`get_status`].
537    ///
538    /// The [`get_status_callback_receiver`] receiver is only triggered if the status changed since the
539    /// last triggering.
540    pub async fn get_status_callback_receiver(&mut self) -> impl Stream<Item = StatusEvent> {
541        self.device
542            .get_callback_receiver(u8::from(GpsV3BrickletFunction::CallbackStatus))
543            .await
544            .map(|p| StatusEvent::from_le_byte_slice(p.body()))
545    }
546
547    /// This receiver is triggered periodically with the period that is set by
548    /// [`set_altitude_callback_period`]. The parameters are the same
549    /// as for [`get_altitude`].
550    ///
551    /// The [`get_altitude_callback_receiver`] receiver is only triggered if the altitude changed since the
552    /// last triggering and if there is currently a fix as indicated by
553    /// [`get_status`].
554    pub async fn get_altitude_callback_receiver(&mut self) -> impl Stream<Item = AltitudeEvent> {
555        self.device
556            .get_callback_receiver(u8::from(GpsV3BrickletFunction::CallbackAltitude))
557            .await
558            .map(|p| AltitudeEvent::from_le_byte_slice(p.body()))
559    }
560
561    /// This receiver is triggered periodically with the period that is set by
562    /// [`set_motion_callback_period`]. The parameters are the same
563    /// as for [`get_motion`].
564    ///
565    /// The [`get_motion_callback_receiver`] receiver is only triggered if the motion changed since the
566    /// last triggering and if there is currently a fix as indicated by
567    /// [`get_status`].
568    pub async fn get_motion_callback_receiver(&mut self) -> impl Stream<Item = MotionEvent> {
569        self.device
570            .get_callback_receiver(u8::from(GpsV3BrickletFunction::CallbackMotion))
571            .await
572            .map(|p| MotionEvent::from_le_byte_slice(p.body()))
573    }
574
575    /// This receiver is triggered periodically with the period that is set by
576    /// [`set_date_time_callback_period`]. The parameters are the same
577    /// as for [`get_date_time`].
578    ///
579    /// The [`get_date_time_callback_receiver`] receiver is only triggered if the date or time changed
580    /// since the last triggering.
581    pub async fn get_date_time_callback_receiver(&mut self) -> impl Stream<Item = DateTimeEvent> {
582        self.device
583            .get_callback_receiver(u8::from(GpsV3BrickletFunction::CallbackDateTime))
584            .await
585            .map(|p| DateTimeEvent::from_le_byte_slice(p.body()))
586    }
587
588    /// Returns the GPS coordinates. Latitude and longitude are given in the
589    /// ``DD.dddddd°`` format, the value 57123468 means 57.123468°.
590    /// The parameter ``ns`` and ``ew`` are the cardinal directions for
591    /// latitude and longitude. Possible values for ``ns`` and ``ew`` are 'N', 'S', 'E'
592    /// and 'W' (north, south, east and west).
593    ///
594    /// This data is only valid if there is currently a fix as indicated by
595    /// [`get_status`].
596    pub async fn get_coordinates(&mut self) -> Result<Coordinates, TinkerforgeError> {
597        let payload = [0; 0];
598
599        #[allow(unused_variables)]
600        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetCoordinates), &payload).await?;
601        Ok(Coordinates::from_le_byte_slice(result.body()))
602    }
603
604    /// Returns if a fix is currently available as well as the number of
605    /// satellites that are in view.
606    ///
607    /// There is also a [green LED](gps_v2_bricklet_fix_led) on the Bricklet that
608    /// indicates the fix status.
609    pub async fn get_status(&mut self) -> Result<Status, TinkerforgeError> {
610        let payload = [0; 0];
611
612        #[allow(unused_variables)]
613        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetStatus), &payload).await?;
614        Ok(Status::from_le_byte_slice(result.body()))
615    }
616
617    /// Returns the current altitude and corresponding geoidal separation.
618    ///
619    /// This data is only valid if there is currently a fix as indicated by
620    /// [`get_status`].
621    pub async fn get_altitude(&mut self) -> Result<Altitude, TinkerforgeError> {
622        let payload = [0; 0];
623
624        #[allow(unused_variables)]
625        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetAltitude), &payload).await?;
626        Ok(Altitude::from_le_byte_slice(result.body()))
627    }
628
629    /// Returns the current course and speed. A course of 0° means the Bricklet is
630    /// traveling north bound and 90° means it is traveling east bound.
631    ///
632    /// Please note that this only returns useful values if an actual movement
633    /// is present.
634    ///
635    /// This data is only valid if there is currently a fix as indicated by
636    /// [`get_status`].
637    pub async fn get_motion(&mut self) -> Result<Motion, TinkerforgeError> {
638        let payload = [0; 0];
639
640        #[allow(unused_variables)]
641        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetMotion), &payload).await?;
642        Ok(Motion::from_le_byte_slice(result.body()))
643    }
644
645    /// Returns the current date and time. The date is
646    /// given in the format ``ddmmyy`` and the time is given
647    /// in the format ``hhmmss.sss``. For example, 140713 means
648    /// 14.07.13 as date and 195923568 means 19:59:23.568 as time.
649    pub async fn get_date_time(&mut self) -> Result<DateTime, TinkerforgeError> {
650        let payload = [0; 0];
651
652        #[allow(unused_variables)]
653        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetDateTime), &payload).await?;
654        Ok(DateTime::from_le_byte_slice(result.body()))
655    }
656
657    /// Restarts the GPS Bricklet, the following restart types are available:
658    ///
659    ///  Value| Description
660    ///  --- | ---
661    ///  0| Hot start (use all available data in the NV store)
662    ///  1| Warm start (don't use ephemeris at restart)
663    ///  2| Cold start (don't use time| position| almanacs and ephemeris at restart)
664    ///  3| Factory reset (clear all system/user configurations at restart)
665    ///
666    /// Associated constants:
667    /// * GPS_V3_BRICKLET_RESTART_TYPE_HOT_START
668    ///	* GPS_V3_BRICKLET_RESTART_TYPE_WARM_START
669    ///	* GPS_V3_BRICKLET_RESTART_TYPE_COLD_START
670    ///	* GPS_V3_BRICKLET_RESTART_TYPE_FACTORY_RESET
671    pub async fn restart(&mut self, restart_type: u8) -> Result<(), TinkerforgeError> {
672        let mut payload = [0; 1];
673        restart_type.write_to_slice(&mut payload[0..1]);
674
675        #[allow(unused_variables)]
676        let result = self.device.set(u8::from(GpsV3BrickletFunction::Restart), &payload).await?;
677        Ok(())
678    }
679
680    /// Returns the
681    ///
682    /// * satellite numbers list (up to 12 items)
683    /// * fix value,
684    /// * PDOP value,
685    /// * HDOP value and
686    /// * VDOP value
687    ///
688    /// for a given satellite system. Currently GPS and GLONASS are supported, Galileo
689    /// is not yet supported.
690    ///
691    /// The GPS and GLONASS satellites have unique numbers and the satellite list gives
692    /// the numbers of the satellites that are currently utilized. The number 0 is not
693    /// a valid satellite number and can be ignored in the list.
694    ///
695    /// Associated constants:
696    /// * GPS_V3_BRICKLET_SATELLITE_SYSTEM_GPS
697    ///	* GPS_V3_BRICKLET_SATELLITE_SYSTEM_GLONASS
698    ///	* GPS_V3_BRICKLET_SATELLITE_SYSTEM_GALILEO
699    ///	* GPS_V3_BRICKLET_FIX_NO_FIX
700    ///	* GPS_V3_BRICKLET_FIX_2D_FIX
701    ///	* GPS_V3_BRICKLET_FIX_3D_FIX
702    pub async fn get_satellite_system_status_low_level(
703        &mut self,
704        satellite_system: u8,
705    ) -> Result<SatelliteSystemStatusLowLevel, TinkerforgeError> {
706        let mut payload = [0; 1];
707        satellite_system.write_to_slice(&mut payload[0..1]);
708
709        #[allow(unused_variables)]
710        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetSatelliteSystemStatusLowLevel), &payload).await?;
711        Ok(SatelliteSystemStatusLowLevel::from_le_byte_slice(result.body()))
712    }
713
714    /// Returns the current elevation, azimuth and SNR
715    /// for a given satellite and satellite system.
716    ///
717    /// The satellite number here always goes from 1 to 32. For GLONASS it corresponds to
718    /// the satellites 65-96.
719    ///
720    /// Galileo is not yet supported.
721    ///
722    /// Associated constants:
723    /// * GPS_V3_BRICKLET_SATELLITE_SYSTEM_GPS
724    ///	* GPS_V3_BRICKLET_SATELLITE_SYSTEM_GLONASS
725    ///	* GPS_V3_BRICKLET_SATELLITE_SYSTEM_GALILEO
726    pub async fn get_satellite_status(&mut self, satellite_system: u8, satellite_number: u8) -> Result<SatelliteStatus, TinkerforgeError> {
727        let mut payload = [0; 2];
728        satellite_system.write_to_slice(&mut payload[0..1]);
729        satellite_number.write_to_slice(&mut payload[1..2]);
730
731        #[allow(unused_variables)]
732        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetSatelliteStatus), &payload).await?;
733        Ok(SatelliteStatus::from_le_byte_slice(result.body()))
734    }
735
736    /// Sets the fix LED configuration. By default the LED shows if
737    /// the Bricklet got a GPS fix yet. If a fix is established the LED turns on.
738    /// If there is no fix then the LED is turned off.
739    ///
740    /// You can also turn the LED permanently on/off, show a heartbeat or let it blink
741    /// in sync with the PPS (pulse per second) output of the GPS module.
742    ///
743    /// If the Bricklet is in bootloader mode, the LED is off.
744    ///
745    /// Associated constants:
746    /// * GPS_V3_BRICKLET_FIX_LED_CONFIG_OFF
747    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_ON
748    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_HEARTBEAT
749    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_FIX
750    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_PPS
751    pub async fn set_fix_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
752        let mut payload = [0; 1];
753        config.write_to_slice(&mut payload[0..1]);
754
755        #[allow(unused_variables)]
756        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetFixLedConfig), &payload).await?;
757        Ok(())
758    }
759
760    /// Returns the configuration as set by [`set_fix_led_config`]
761    ///
762    /// Associated constants:
763    /// * GPS_V3_BRICKLET_FIX_LED_CONFIG_OFF
764    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_ON
765    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_HEARTBEAT
766    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_FIX
767    ///	* GPS_V3_BRICKLET_FIX_LED_CONFIG_SHOW_PPS
768    pub async fn get_fix_led_config(&mut self) -> Result<u8, TinkerforgeError> {
769        let payload = [0; 0];
770
771        #[allow(unused_variables)]
772        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetFixLedConfig), &payload).await?;
773        Ok(u8::from_le_byte_slice(result.body()))
774    }
775
776    /// Sets the period with which the [`get_coordinates_callback_receiver`] receiver is triggered
777    /// periodically. A value of 0 turns the receiver off.
778    ///
779    /// The [`get_coordinates_callback_receiver`] receiver is only triggered if the coordinates changed
780    /// since the last triggering.
781    pub async fn set_coordinates_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
782        let mut payload = [0; 4];
783        period.write_to_slice(&mut payload[0..4]);
784
785        #[allow(unused_variables)]
786        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetCoordinatesCallbackPeriod), &payload).await?;
787        Ok(())
788    }
789
790    /// Returns the period as set by [`set_coordinates_callback_period`].
791    pub async fn get_coordinates_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
792        let payload = [0; 0];
793
794        #[allow(unused_variables)]
795        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetCoordinatesCallbackPeriod), &payload).await?;
796        Ok(u32::from_le_byte_slice(result.body()))
797    }
798
799    /// Sets the period with which the [`get_status_callback_receiver`] receiver is triggered
800    /// periodically. A value of 0 turns the receiver off.
801    ///
802    /// The [`get_status_callback_receiver`] receiver is only triggered if the status changed since the
803    /// last triggering.
804    pub async fn set_status_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
805        let mut payload = [0; 4];
806        period.write_to_slice(&mut payload[0..4]);
807
808        #[allow(unused_variables)]
809        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetStatusCallbackPeriod), &payload).await?;
810        Ok(())
811    }
812
813    /// Returns the period as set by [`set_status_callback_period`].
814    pub async fn get_status_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
815        let payload = [0; 0];
816
817        #[allow(unused_variables)]
818        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetStatusCallbackPeriod), &payload).await?;
819        Ok(u32::from_le_byte_slice(result.body()))
820    }
821
822    /// Sets the period with which the [`get_altitude_callback_receiver`] receiver is triggered
823    /// periodically. A value of 0 turns the receiver off.
824    ///
825    /// The [`get_altitude_callback_receiver`] receiver is only triggered if the altitude changed since the
826    /// last triggering.
827    pub async fn set_altitude_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
828        let mut payload = [0; 4];
829        period.write_to_slice(&mut payload[0..4]);
830
831        #[allow(unused_variables)]
832        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetAltitudeCallbackPeriod), &payload).await?;
833        Ok(())
834    }
835
836    /// Returns the period as set by [`set_altitude_callback_period`].
837    pub async fn get_altitude_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
838        let payload = [0; 0];
839
840        #[allow(unused_variables)]
841        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetAltitudeCallbackPeriod), &payload).await?;
842        Ok(u32::from_le_byte_slice(result.body()))
843    }
844
845    /// Sets the period with which the [`get_motion_callback_receiver`] receiver is triggered
846    /// periodically. A value of 0 turns the receiver off.
847    ///
848    /// The [`get_motion_callback_receiver`] receiver is only triggered if the motion changed since the
849    /// last triggering.
850    pub async fn set_motion_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
851        let mut payload = [0; 4];
852        period.write_to_slice(&mut payload[0..4]);
853
854        #[allow(unused_variables)]
855        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetMotionCallbackPeriod), &payload).await?;
856        Ok(())
857    }
858
859    /// Returns the period as set by [`set_motion_callback_period`].
860    pub async fn get_motion_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
861        let payload = [0; 0];
862
863        #[allow(unused_variables)]
864        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetMotionCallbackPeriod), &payload).await?;
865        Ok(u32::from_le_byte_slice(result.body()))
866    }
867
868    /// Sets the period with which the [`get_date_time_callback_receiver`] receiver is triggered
869    /// periodically. A value of 0 turns the receiver off.
870    ///
871    /// The [`get_date_time_callback_receiver`] receiver is only triggered if the date or time changed
872    /// since the last triggering.
873    pub async fn set_date_time_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
874        let mut payload = [0; 4];
875        period.write_to_slice(&mut payload[0..4]);
876
877        #[allow(unused_variables)]
878        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetDateTimeCallbackPeriod), &payload).await?;
879        Ok(())
880    }
881
882    /// Returns the period as set by [`set_date_time_callback_period`].
883    pub async fn get_date_time_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
884        let payload = [0; 0];
885
886        #[allow(unused_variables)]
887        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetDateTimeCallbackPeriod), &payload).await?;
888        Ok(u32::from_le_byte_slice(result.body()))
889    }
890
891    /// If [SBAS](https://en.wikipedia.org/wiki/GNSS_augmentation#Satellite-based_augmentation_system)__ is enabled,
892    /// the position accuracy increases (if SBAS satellites are in view),
893    /// but the update rate is limited to 5Hz. With SBAS disabled the update rate is increased to 10Hz.
894    ///
895    /// Associated constants:
896    /// * GPS_V3_BRICKLET_SBAS_ENABLED
897    ///	* GPS_V3_BRICKLET_SBAS_DISABLED
898    pub async fn set_sbas_config(&mut self, sbas_config: u8) -> Result<(), TinkerforgeError> {
899        let mut payload = [0; 1];
900        sbas_config.write_to_slice(&mut payload[0..1]);
901
902        #[allow(unused_variables)]
903        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetSbasConfig), &payload).await?;
904        Ok(())
905    }
906
907    /// Returns the SBAS configuration as set by [`set_sbas_config`]
908    ///
909    /// Associated constants:
910    /// * GPS_V3_BRICKLET_SBAS_ENABLED
911    ///	* GPS_V3_BRICKLET_SBAS_DISABLED
912    pub async fn get_sbas_config(&mut self) -> Result<u8, TinkerforgeError> {
913        let payload = [0; 0];
914
915        #[allow(unused_variables)]
916        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetSbasConfig), &payload).await?;
917        Ok(u8::from_le_byte_slice(result.body()))
918    }
919
920    /// Returns the error count for the communication between Brick and Bricklet.
921    ///
922    /// The errors are divided into
923    ///
924    /// * ACK checksum errors,
925    /// * message checksum errors,
926    /// * framing errors and
927    /// * overflow errors.
928    ///
929    /// The errors counts are for errors that occur on the Bricklet side. All
930    /// Bricks have a similar function that returns the errors on the Brick side.
931    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
932        let payload = [0; 0];
933
934        #[allow(unused_variables)]
935        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetSpitfpErrorCount), &payload).await?;
936        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
937    }
938
939    /// Sets the bootloader mode and returns the status after the requested
940    /// mode change was instigated.
941    ///
942    /// You can change from bootloader mode to firmware mode and vice versa. A change
943    /// from bootloader mode to firmware mode will only take place if the entry function,
944    /// device identifier and CRC are present and correct.
945    ///
946    /// This function is used by Brick Viewer during flashing. It should not be
947    /// necessary to call it in a normal user program.
948    ///
949    /// Associated constants:
950    /// * GPS_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
951    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE
952    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
953    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
954    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
955    ///	* GPS_V3_BRICKLET_BOOTLOADER_STATUS_OK
956    ///	* GPS_V3_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
957    ///	* GPS_V3_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
958    ///	* GPS_V3_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
959    ///	* GPS_V3_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
960    ///	* GPS_V3_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
961    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
962        let mut payload = [0; 1];
963        mode.write_to_slice(&mut payload[0..1]);
964
965        #[allow(unused_variables)]
966        let result = self.device.get(u8::from(GpsV3BrickletFunction::SetBootloaderMode), &payload).await?;
967        Ok(u8::from_le_byte_slice(result.body()))
968    }
969
970    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
971    ///
972    /// Associated constants:
973    /// * GPS_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
974    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE
975    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
976    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
977    ///	* GPS_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
978    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
979        let payload = [0; 0];
980
981        #[allow(unused_variables)]
982        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetBootloaderMode), &payload).await?;
983        Ok(u8::from_le_byte_slice(result.body()))
984    }
985
986    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
987    /// to be increased by chunks of size 64. The data is written to flash
988    /// every 4 chunks (which equals to one page of size 256).
989    ///
990    /// This function is used by Brick Viewer during flashing. It should not be
991    /// necessary to call it in a normal user program.
992    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
993        let mut payload = [0; 4];
994        pointer.write_to_slice(&mut payload[0..4]);
995
996        #[allow(unused_variables)]
997        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
998        Ok(())
999    }
1000
1001    /// Writes 64 Bytes of firmware at the position as written by
1002    /// [`set_write_firmware_pointer`] before. The firmware is written
1003    /// to flash every 4 chunks.
1004    ///
1005    /// You can only write firmware in bootloader mode.
1006    ///
1007    /// This function is used by Brick Viewer during flashing. It should not be
1008    /// necessary to call it in a normal user program.
1009    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
1010        let mut payload = [0; 64];
1011        data.write_to_slice(&mut payload[0..64]);
1012
1013        #[allow(unused_variables)]
1014        let result = self.device.get(u8::from(GpsV3BrickletFunction::WriteFirmware), &payload).await?;
1015        Ok(u8::from_le_byte_slice(result.body()))
1016    }
1017
1018    /// Sets the status LED configuration. By default the LED shows
1019    /// communication traffic between Brick and Bricklet, it flickers once
1020    /// for every 10 received data packets.
1021    ///
1022    /// You can also turn the LED permanently on/off or show a heartbeat.
1023    ///
1024    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
1025    ///
1026    /// Associated constants:
1027    /// * GPS_V3_BRICKLET_STATUS_LED_CONFIG_OFF
1028    ///	* GPS_V3_BRICKLET_STATUS_LED_CONFIG_ON
1029    ///	* GPS_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
1030    ///	* GPS_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
1031    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
1032        let mut payload = [0; 1];
1033        config.write_to_slice(&mut payload[0..1]);
1034
1035        #[allow(unused_variables)]
1036        let result = self.device.set(u8::from(GpsV3BrickletFunction::SetStatusLedConfig), &payload).await?;
1037        Ok(())
1038    }
1039
1040    /// Returns the configuration as set by [`set_status_led_config`]
1041    ///
1042    /// Associated constants:
1043    /// * GPS_V3_BRICKLET_STATUS_LED_CONFIG_OFF
1044    ///	* GPS_V3_BRICKLET_STATUS_LED_CONFIG_ON
1045    ///	* GPS_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
1046    ///	* GPS_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
1047    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
1048        let payload = [0; 0];
1049
1050        #[allow(unused_variables)]
1051        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetStatusLedConfig), &payload).await?;
1052        Ok(u8::from_le_byte_slice(result.body()))
1053    }
1054
1055    /// Returns the temperature as measured inside the microcontroller. The
1056    /// value returned is not the ambient temperature!
1057    ///
1058    /// The temperature is only proportional to the real temperature and it has bad
1059    /// accuracy. Practically it is only useful as an indicator for
1060    /// temperature changes.
1061    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
1062        let payload = [0; 0];
1063
1064        #[allow(unused_variables)]
1065        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetChipTemperature), &payload).await?;
1066        Ok(i16::from_le_byte_slice(result.body()))
1067    }
1068
1069    /// Calling this function will reset the Bricklet. All configurations
1070    /// will be lost.
1071    ///
1072    /// After a reset you have to create new device objects,
1073    /// calling functions on the existing ones will result in
1074    /// undefined behavior!
1075    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
1076        let payload = [0; 0];
1077
1078        #[allow(unused_variables)]
1079        let result = self.device.set(u8::from(GpsV3BrickletFunction::Reset), &payload).await?;
1080        Ok(())
1081    }
1082
1083    /// Writes a new UID into flash. If you want to set a new UID
1084    /// you have to decode the Base58 encoded UID string into an
1085    /// integer first.
1086    ///
1087    /// We recommend that you use Brick Viewer to change the UID.
1088    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
1089        let mut payload = [0; 4];
1090        uid.write_to_slice(&mut payload[0..4]);
1091
1092        #[allow(unused_variables)]
1093        let result = self.device.set(u8::from(GpsV3BrickletFunction::WriteUid), &payload).await?;
1094        Ok(())
1095    }
1096
1097    /// Returns the current UID as an integer. Encode as
1098    /// Base58 to get the usual string version.
1099    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
1100        let payload = [0; 0];
1101
1102        #[allow(unused_variables)]
1103        let result = self.device.get(u8::from(GpsV3BrickletFunction::ReadUid), &payload).await?;
1104        Ok(u32::from_le_byte_slice(result.body()))
1105    }
1106
1107    /// Returns the UID, the UID where the Bricklet is connected to,
1108    /// the position, the hardware and firmware version as well as the
1109    /// device identifier.
1110    ///
1111    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
1112    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
1113    /// position 'z'.
1114    ///
1115    /// The device identifier numbers can be found [here](device_identifier).
1116    /// |device_identifier_constant|
1117    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
1118        let payload = [0; 0];
1119
1120        #[allow(unused_variables)]
1121        let result = self.device.get(u8::from(GpsV3BrickletFunction::GetIdentity), &payload).await?;
1122        Ok(Identity::from_le_byte_slice(result.body()))
1123    }
1124}