tinkerforge_async/bindings/
gps_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/GPS_Bricklet_Rust.html).
14#[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 GpsBrickletFunction {
24    GetCoordinates,
25    GetStatus,
26    GetAltitude,
27    GetMotion,
28    GetDateTime,
29    Restart,
30    SetCoordinatesCallbackPeriod,
31    GetCoordinatesCallbackPeriod,
32    SetStatusCallbackPeriod,
33    GetStatusCallbackPeriod,
34    SetAltitudeCallbackPeriod,
35    GetAltitudeCallbackPeriod,
36    SetMotionCallbackPeriod,
37    GetMotionCallbackPeriod,
38    SetDateTimeCallbackPeriod,
39    GetDateTimeCallbackPeriod,
40    GetIdentity,
41    CallbackCoordinates,
42    CallbackStatus,
43    CallbackAltitude,
44    CallbackMotion,
45    CallbackDateTime,
46}
47impl From<GpsBrickletFunction> for u8 {
48    fn from(fun: GpsBrickletFunction) -> Self {
49        match fun {
50            GpsBrickletFunction::GetCoordinates => 1,
51            GpsBrickletFunction::GetStatus => 2,
52            GpsBrickletFunction::GetAltitude => 3,
53            GpsBrickletFunction::GetMotion => 4,
54            GpsBrickletFunction::GetDateTime => 5,
55            GpsBrickletFunction::Restart => 6,
56            GpsBrickletFunction::SetCoordinatesCallbackPeriod => 7,
57            GpsBrickletFunction::GetCoordinatesCallbackPeriod => 8,
58            GpsBrickletFunction::SetStatusCallbackPeriod => 9,
59            GpsBrickletFunction::GetStatusCallbackPeriod => 10,
60            GpsBrickletFunction::SetAltitudeCallbackPeriod => 11,
61            GpsBrickletFunction::GetAltitudeCallbackPeriod => 12,
62            GpsBrickletFunction::SetMotionCallbackPeriod => 13,
63            GpsBrickletFunction::GetMotionCallbackPeriod => 14,
64            GpsBrickletFunction::SetDateTimeCallbackPeriod => 15,
65            GpsBrickletFunction::GetDateTimeCallbackPeriod => 16,
66            GpsBrickletFunction::GetIdentity => 255,
67            GpsBrickletFunction::CallbackCoordinates => 17,
68            GpsBrickletFunction::CallbackStatus => 18,
69            GpsBrickletFunction::CallbackAltitude => 19,
70            GpsBrickletFunction::CallbackMotion => 20,
71            GpsBrickletFunction::CallbackDateTime => 21,
72        }
73    }
74}
75pub const GPS_BRICKLET_FIX_NO_FIX: u8 = 1;
76pub const GPS_BRICKLET_FIX_2D_FIX: u8 = 2;
77pub const GPS_BRICKLET_FIX_3D_FIX: u8 = 3;
78pub const GPS_BRICKLET_RESTART_TYPE_HOT_START: u8 = 0;
79pub const GPS_BRICKLET_RESTART_TYPE_WARM_START: u8 = 1;
80pub const GPS_BRICKLET_RESTART_TYPE_COLD_START: u8 = 2;
81pub const GPS_BRICKLET_RESTART_TYPE_FACTORY_RESET: u8 = 3;
82
83#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
84pub struct Coordinates {
85    pub latitude: u32,
86    pub ns: char,
87    pub longitude: u32,
88    pub ew: char,
89    pub pdop: u16,
90    pub hdop: u16,
91    pub vdop: u16,
92    pub epe: u16,
93}
94impl FromByteSlice for Coordinates {
95    fn bytes_expected() -> usize {
96        18
97    }
98    fn from_le_byte_slice(bytes: &[u8]) -> Coordinates {
99        Coordinates {
100            latitude: <u32>::from_le_byte_slice(&bytes[0..4]),
101            ns: <char>::from_le_byte_slice(&bytes[4..5]),
102            longitude: <u32>::from_le_byte_slice(&bytes[5..9]),
103            ew: <char>::from_le_byte_slice(&bytes[9..10]),
104            pdop: <u16>::from_le_byte_slice(&bytes[10..12]),
105            hdop: <u16>::from_le_byte_slice(&bytes[12..14]),
106            vdop: <u16>::from_le_byte_slice(&bytes[14..16]),
107            epe: <u16>::from_le_byte_slice(&bytes[16..18]),
108        }
109    }
110}
111
112#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
113pub struct Status {
114    pub fix: u8,
115    pub satellites_view: u8,
116    pub satellites_used: u8,
117}
118impl FromByteSlice for Status {
119    fn bytes_expected() -> usize {
120        3
121    }
122    fn from_le_byte_slice(bytes: &[u8]) -> Status {
123        Status {
124            fix: <u8>::from_le_byte_slice(&bytes[0..1]),
125            satellites_view: <u8>::from_le_byte_slice(&bytes[1..2]),
126            satellites_used: <u8>::from_le_byte_slice(&bytes[2..3]),
127        }
128    }
129}
130
131#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
132pub struct Altitude {
133    pub altitude: i32,
134    pub geoidal_separation: i32,
135}
136impl FromByteSlice for Altitude {
137    fn bytes_expected() -> usize {
138        8
139    }
140    fn from_le_byte_slice(bytes: &[u8]) -> Altitude {
141        Altitude { altitude: <i32>::from_le_byte_slice(&bytes[0..4]), geoidal_separation: <i32>::from_le_byte_slice(&bytes[4..8]) }
142    }
143}
144
145#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
146pub struct Motion {
147    pub course: u32,
148    pub speed: u32,
149}
150impl FromByteSlice for Motion {
151    fn bytes_expected() -> usize {
152        8
153    }
154    fn from_le_byte_slice(bytes: &[u8]) -> Motion {
155        Motion { course: <u32>::from_le_byte_slice(&bytes[0..4]), speed: <u32>::from_le_byte_slice(&bytes[4..8]) }
156    }
157}
158
159#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
160pub struct DateTime {
161    pub date: u32,
162    pub time: u32,
163}
164impl FromByteSlice for DateTime {
165    fn bytes_expected() -> usize {
166        8
167    }
168    fn from_le_byte_slice(bytes: &[u8]) -> DateTime {
169        DateTime { date: <u32>::from_le_byte_slice(&bytes[0..4]), time: <u32>::from_le_byte_slice(&bytes[4..8]) }
170    }
171}
172
173#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
174pub struct CoordinatesEvent {
175    pub latitude: u32,
176    pub ns: char,
177    pub longitude: u32,
178    pub ew: char,
179    pub pdop: u16,
180    pub hdop: u16,
181    pub vdop: u16,
182    pub epe: u16,
183}
184impl FromByteSlice for CoordinatesEvent {
185    fn bytes_expected() -> usize {
186        18
187    }
188    fn from_le_byte_slice(bytes: &[u8]) -> CoordinatesEvent {
189        CoordinatesEvent {
190            latitude: <u32>::from_le_byte_slice(&bytes[0..4]),
191            ns: <char>::from_le_byte_slice(&bytes[4..5]),
192            longitude: <u32>::from_le_byte_slice(&bytes[5..9]),
193            ew: <char>::from_le_byte_slice(&bytes[9..10]),
194            pdop: <u16>::from_le_byte_slice(&bytes[10..12]),
195            hdop: <u16>::from_le_byte_slice(&bytes[12..14]),
196            vdop: <u16>::from_le_byte_slice(&bytes[14..16]),
197            epe: <u16>::from_le_byte_slice(&bytes[16..18]),
198        }
199    }
200}
201
202#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
203pub struct StatusEvent {
204    pub fix: u8,
205    pub satellites_view: u8,
206    pub satellites_used: u8,
207}
208impl FromByteSlice for StatusEvent {
209    fn bytes_expected() -> usize {
210        3
211    }
212    fn from_le_byte_slice(bytes: &[u8]) -> StatusEvent {
213        StatusEvent {
214            fix: <u8>::from_le_byte_slice(&bytes[0..1]),
215            satellites_view: <u8>::from_le_byte_slice(&bytes[1..2]),
216            satellites_used: <u8>::from_le_byte_slice(&bytes[2..3]),
217        }
218    }
219}
220
221#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
222pub struct AltitudeEvent {
223    pub altitude: i32,
224    pub geoidal_separation: i32,
225}
226impl FromByteSlice for AltitudeEvent {
227    fn bytes_expected() -> usize {
228        8
229    }
230    fn from_le_byte_slice(bytes: &[u8]) -> AltitudeEvent {
231        AltitudeEvent { altitude: <i32>::from_le_byte_slice(&bytes[0..4]), geoidal_separation: <i32>::from_le_byte_slice(&bytes[4..8]) }
232    }
233}
234
235#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
236pub struct MotionEvent {
237    pub course: u32,
238    pub speed: u32,
239}
240impl FromByteSlice for MotionEvent {
241    fn bytes_expected() -> usize {
242        8
243    }
244    fn from_le_byte_slice(bytes: &[u8]) -> MotionEvent {
245        MotionEvent { course: <u32>::from_le_byte_slice(&bytes[0..4]), speed: <u32>::from_le_byte_slice(&bytes[4..8]) }
246    }
247}
248
249#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
250pub struct DateTimeEvent {
251    pub date: u32,
252    pub time: u32,
253}
254impl FromByteSlice for DateTimeEvent {
255    fn bytes_expected() -> usize {
256        8
257    }
258    fn from_le_byte_slice(bytes: &[u8]) -> DateTimeEvent {
259        DateTimeEvent { date: <u32>::from_le_byte_slice(&bytes[0..4]), time: <u32>::from_le_byte_slice(&bytes[4..8]) }
260    }
261}
262
263#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
264pub struct Identity {
265    pub uid: String,
266    pub connected_uid: String,
267    pub position: char,
268    pub hardware_version: [u8; 3],
269    pub firmware_version: [u8; 3],
270    pub device_identifier: u16,
271}
272impl FromByteSlice for Identity {
273    fn bytes_expected() -> usize {
274        25
275    }
276    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
277        Identity {
278            uid: <String>::from_le_byte_slice(&bytes[0..8]),
279            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
280            position: <char>::from_le_byte_slice(&bytes[16..17]),
281            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
282            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
283            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
284        }
285    }
286}
287
288/// Determine position, velocity and altitude using GPS
289#[derive(Clone)]
290pub struct GpsBricklet {
291    device: Device,
292}
293impl GpsBricklet {
294    pub const DEVICE_IDENTIFIER: u16 = 222;
295    pub const DEVICE_DISPLAY_NAME: &'static str = "GPS Bricklet";
296    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
297    pub fn new(uid: Uid, connection: AsyncIpConnection) -> GpsBricklet {
298        let mut result = GpsBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
299        result.device.response_expected[u8::from(GpsBrickletFunction::GetCoordinates) as usize] = ResponseExpectedFlag::AlwaysTrue;
300        result.device.response_expected[u8::from(GpsBrickletFunction::GetStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
301        result.device.response_expected[u8::from(GpsBrickletFunction::GetAltitude) as usize] = ResponseExpectedFlag::AlwaysTrue;
302        result.device.response_expected[u8::from(GpsBrickletFunction::GetMotion) as usize] = ResponseExpectedFlag::AlwaysTrue;
303        result.device.response_expected[u8::from(GpsBrickletFunction::GetDateTime) as usize] = ResponseExpectedFlag::AlwaysTrue;
304        result.device.response_expected[u8::from(GpsBrickletFunction::Restart) as usize] = ResponseExpectedFlag::False;
305        result.device.response_expected[u8::from(GpsBrickletFunction::SetCoordinatesCallbackPeriod) as usize] = ResponseExpectedFlag::True;
306        result.device.response_expected[u8::from(GpsBrickletFunction::GetCoordinatesCallbackPeriod) as usize] =
307            ResponseExpectedFlag::AlwaysTrue;
308        result.device.response_expected[u8::from(GpsBrickletFunction::SetStatusCallbackPeriod) as usize] = ResponseExpectedFlag::True;
309        result.device.response_expected[u8::from(GpsBrickletFunction::GetStatusCallbackPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
310        result.device.response_expected[u8::from(GpsBrickletFunction::SetAltitudeCallbackPeriod) as usize] = ResponseExpectedFlag::True;
311        result.device.response_expected[u8::from(GpsBrickletFunction::GetAltitudeCallbackPeriod) as usize] =
312            ResponseExpectedFlag::AlwaysTrue;
313        result.device.response_expected[u8::from(GpsBrickletFunction::SetMotionCallbackPeriod) as usize] = ResponseExpectedFlag::True;
314        result.device.response_expected[u8::from(GpsBrickletFunction::GetMotionCallbackPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
315        result.device.response_expected[u8::from(GpsBrickletFunction::SetDateTimeCallbackPeriod) as usize] = ResponseExpectedFlag::True;
316        result.device.response_expected[u8::from(GpsBrickletFunction::GetDateTimeCallbackPeriod) as usize] =
317            ResponseExpectedFlag::AlwaysTrue;
318        result.device.response_expected[u8::from(GpsBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
319        result
320    }
321
322    /// Returns the response expected flag for the function specified by the function ID parameter.
323    /// It is true if the function is expected to send a response, false otherwise.
324    ///
325    /// For getter functions this is enabled by default and cannot be disabled, because those
326    /// functions will always send a response. For callback configuration functions it is enabled
327    /// by default too, but can be disabled by [`set_response_expected`](crate::gps_bricklet::GpsBricklet::set_response_expected).
328    /// For setter functions it is disabled by default and can be enabled.
329    ///
330    /// Enabling the response expected flag for a setter function allows to detect timeouts
331    /// and other error conditions calls of this setter as well. The device will then send a response
332    /// for this purpose. If this flag is disabled for a setter function then no response is sent
333    /// and errors are silently ignored, because they cannot be detected.
334    ///
335    /// See [`set_response_expected`](crate::gps_bricklet::GpsBricklet::set_response_expected) for the list of function ID constants available for this function.
336    pub fn get_response_expected(&mut self, fun: GpsBrickletFunction) -> Result<bool, GetResponseExpectedError> {
337        self.device.get_response_expected(u8::from(fun))
338    }
339
340    /// Changes the response expected flag of the function specified by the function ID parameter.
341    /// This flag can only be changed for setter (default value: false) and callback configuration
342    /// functions (default value: true). For getter functions it is always enabled.
343    ///
344    /// Enabling the response expected flag for a setter function allows to detect timeouts and
345    /// other error conditions calls of this setter as well. The device will then send a response
346    /// for this purpose. If this flag is disabled for a setter function then no response is sent
347    /// and errors are silently ignored, because they cannot be detected.
348    pub fn set_response_expected(&mut self, fun: GpsBrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
349        self.device.set_response_expected(u8::from(fun), response_expected)
350    }
351
352    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
353    pub fn set_response_expected_all(&mut self, response_expected: bool) {
354        self.device.set_response_expected_all(response_expected)
355    }
356
357    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
358    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
359    pub fn get_api_version(&self) -> [u8; 3] {
360        self.device.api_version
361    }
362
363    /// This receiver is triggered periodically with the period that is set by
364    /// [`set_coordinates_callback_period`]. The parameters are the same
365    /// as for [`get_coordinates`].
366    ///
367    /// The [`get_coordinates_callback_receiver`] receiver is only triggered if the coordinates changed
368    /// since the last triggering and if there is currently a fix as indicated by
369    /// [`get_status`].
370    ///
371    /// [`get_coordinates`]: #method.get_coordinates
372    /// [`get_status`]: #method.get_status
373    /// [`set_coordinates_callback_period`]: #method.set_coordinates_callback_period
374    /// [`get_coordinates_callback_receiver`]: #method.get_coordinates_callback_receiver
375    pub async fn get_coordinates_callback_receiver(&mut self) -> impl Stream<Item = CoordinatesEvent> {
376        self.device
377            .get_callback_receiver(u8::from(GpsBrickletFunction::CallbackCoordinates))
378            .await
379            .map(|p| CoordinatesEvent::from_le_byte_slice(p.body()))
380    }
381
382    /// This receiver is triggered periodically with the period that is set by
383    /// [`set_status_callback_period`]. The parameters are the same
384    /// as for [`get_status`].
385    ///
386    /// The [`get_status_callback_receiver`] receiver is only triggered if the status changed since the
387    /// last triggering.
388    pub async fn get_status_callback_receiver(&mut self) -> impl Stream<Item = StatusEvent> {
389        self.device
390            .get_callback_receiver(u8::from(GpsBrickletFunction::CallbackStatus))
391            .await
392            .map(|p| StatusEvent::from_le_byte_slice(p.body()))
393    }
394
395    /// This receiver is triggered periodically with the period that is set by
396    /// [`set_altitude_callback_period`]. The parameters are the same
397    /// as for [`get_altitude`].
398    ///
399    /// The [`get_altitude_callback_receiver`] receiver is only triggered if the altitude changed since
400    /// the last triggering and if there is currently a fix as indicated by
401    /// [`get_status`].
402    pub async fn get_altitude_callback_receiver(&mut self) -> impl Stream<Item = AltitudeEvent> {
403        self.device
404            .get_callback_receiver(u8::from(GpsBrickletFunction::CallbackAltitude))
405            .await
406            .map(|p| AltitudeEvent::from_le_byte_slice(p.body()))
407    }
408
409    /// This receiver is triggered periodically with the period that is set by
410    /// [`set_motion_callback_period`]. The parameters are the same
411    /// as for [`get_motion`].
412    ///
413    /// The [`get_motion_callback_receiver`] receiver is only triggered if the motion changed since the
414    /// last triggering and if there is currently a fix as indicated by
415    /// [`get_status`].
416    pub async fn get_motion_callback_receiver(&mut self) -> impl Stream<Item = MotionEvent> {
417        self.device
418            .get_callback_receiver(u8::from(GpsBrickletFunction::CallbackMotion))
419            .await
420            .map(|p| MotionEvent::from_le_byte_slice(p.body()))
421    }
422
423    /// This receiver is triggered periodically with the period that is set by
424    /// [`set_date_time_callback_period`]. The parameters are the same
425    /// as for [`get_date_time`].
426    ///
427    /// The [`get_date_time_callback_receiver`] receiver is only triggered if the date or time changed
428    /// since the last triggering.
429    pub async fn get_date_time_callback_receiver(&mut self) -> impl Stream<Item = DateTimeEvent> {
430        self.device
431            .get_callback_receiver(u8::from(GpsBrickletFunction::CallbackDateTime))
432            .await
433            .map(|p| DateTimeEvent::from_le_byte_slice(p.body()))
434    }
435
436    /// Returns the GPS coordinates. Latitude and longitude are given in the
437    /// [`DD.dddddd°`` format, the value 57123468 means 57.123468°.
438    /// The parameter ``ns`` and ``ew`` are the cardinal directions for
439    /// latitude and longitude. Possible values for ``ns`` and ``ew`` are 'N', 'S', 'E'
440    /// and 'W' (north, south, east and west).
441    ///
442    /// PDOP, HDOP and VDOP are the dilution of precision (DOP) values. They specify
443    /// the additional multiplicative effect of GPS satellite geometry on GPS
444    /// precision. See
445    /// `here](https://en.wikipedia.org/wiki/Dilution_of_precision_(GPS))__
446    /// for more information.
447    ///
448    /// EPE is the Estimated Position Error. This is not the
449    /// absolute maximum error, it is the error with a specific confidence. See
450    /// [here](https://www.nps.gov/gis/gps/WhatisEPE.html)__ for more information.
451    ///
452    /// This data is only valid if there is currently a fix as indicated by
453    /// [`get_status`].
454    pub async fn get_coordinates(&mut self) -> Result<Coordinates, TinkerforgeError> {
455        let payload = [0; 0];
456
457        #[allow(unused_variables)]
458        let result = self.device.get(u8::from(GpsBrickletFunction::GetCoordinates), &payload).await?;
459        Ok(Coordinates::from_le_byte_slice(result.body()))
460    }
461
462    /// Returns the current fix status, the number of satellites that are in view and
463    /// the number of satellites that are currently used.
464    ///
465    /// Possible fix status values can be:
466    ///
467    ///  Value| Description
468    ///  --- | ---
469    ///  1| No Fix| :func:[Get Coordinates`| [`get_altitude`] and [`get_motion`] return invalid data
470    ///  2| 2D Fix| only [`get_coordinates`] and [`get_motion`] return valid data
471    ///  3| 3D Fix| [`get_coordinates`]| [`get_altitude`] and [`get_motion`] return valid data
472    ///
473    /// There is also a `blue LED](gps_bricklet_fix_led) on the Bricklet that
474    /// indicates the fix status.
475    ///
476    /// Associated constants:
477    /// * GPS_BRICKLET_FIX_NO_FIX
478    ///	* GPS_BRICKLET_FIX_2D_FIX
479    ///	* GPS_BRICKLET_FIX_3D_FIX
480    pub async fn get_status(&mut self) -> Result<Status, TinkerforgeError> {
481        let payload = [0; 0];
482
483        #[allow(unused_variables)]
484        let result = self.device.get(u8::from(GpsBrickletFunction::GetStatus), &payload).await?;
485        Ok(Status::from_le_byte_slice(result.body()))
486    }
487
488    /// Returns the current altitude and corresponding geoidal separation.
489    ///
490    /// This data is only valid if there is currently a fix as indicated by
491    /// [`get_status`].
492    pub async fn get_altitude(&mut self) -> Result<Altitude, TinkerforgeError> {
493        let payload = [0; 0];
494
495        #[allow(unused_variables)]
496        let result = self.device.get(u8::from(GpsBrickletFunction::GetAltitude), &payload).await?;
497        Ok(Altitude::from_le_byte_slice(result.body()))
498    }
499
500    /// Returns the current course and speed. A course of 0° means the Bricklet is
501    /// traveling north bound and 90° means it is traveling east bound.
502    ///
503    /// Please note that this only returns useful values if an actual movement
504    /// is present.
505    ///
506    /// This data is only valid if there is currently a fix as indicated by
507    /// [`get_status`].
508    pub async fn get_motion(&mut self) -> Result<Motion, TinkerforgeError> {
509        let payload = [0; 0];
510
511        #[allow(unused_variables)]
512        let result = self.device.get(u8::from(GpsBrickletFunction::GetMotion), &payload).await?;
513        Ok(Motion::from_le_byte_slice(result.body()))
514    }
515
516    /// Returns the current date and time. The date is
517    /// given in the format ``ddmmyy`` and the time is given
518    /// in the format ``hhmmss.sss``. For example, 140713 means
519    /// 14.07.13 as date and 195923568 means 19:59:23.568 as time.
520    pub async fn get_date_time(&mut self) -> Result<DateTime, TinkerforgeError> {
521        let payload = [0; 0];
522
523        #[allow(unused_variables)]
524        let result = self.device.get(u8::from(GpsBrickletFunction::GetDateTime), &payload).await?;
525        Ok(DateTime::from_le_byte_slice(result.body()))
526    }
527
528    /// Restarts the GPS Bricklet, the following restart types are available:
529    ///
530    ///  Value| Description
531    ///  --- | ---
532    ///  0| Hot start (use all available data in the NV store)
533    ///  1| Warm start (don't use ephemeris at restart)
534    ///  2| Cold start (don't use time| position| almanacs and ephemeris at restart)
535    ///  3| Factory reset (clear all system/user configurations at restart)
536    ///
537    /// Associated constants:
538    /// * GPS_BRICKLET_RESTART_TYPE_HOT_START
539    ///	* GPS_BRICKLET_RESTART_TYPE_WARM_START
540    ///	* GPS_BRICKLET_RESTART_TYPE_COLD_START
541    ///	* GPS_BRICKLET_RESTART_TYPE_FACTORY_RESET
542    pub async fn restart(&mut self, restart_type: u8) -> Result<(), TinkerforgeError> {
543        let mut payload = [0; 1];
544        restart_type.write_to_slice(&mut payload[0..1]);
545
546        #[allow(unused_variables)]
547        let result = self.device.set(u8::from(GpsBrickletFunction::Restart), &payload).await?;
548        Ok(())
549    }
550
551    /// Sets the period with which the [`get_coordinates_callback_receiver`] receiver is triggered
552    /// periodically. A value of 0 turns the receiver off.
553    ///
554    /// The [`get_coordinates_callback_receiver`] receiver is only triggered if the coordinates changed
555    /// since the last triggering.
556    pub async fn set_coordinates_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
557        let mut payload = [0; 4];
558        period.write_to_slice(&mut payload[0..4]);
559
560        #[allow(unused_variables)]
561        let result = self.device.set(u8::from(GpsBrickletFunction::SetCoordinatesCallbackPeriod), &payload).await?;
562        Ok(())
563    }
564
565    /// Returns the period as set by [`set_coordinates_callback_period`].
566    pub async fn get_coordinates_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
567        let payload = [0; 0];
568
569        #[allow(unused_variables)]
570        let result = self.device.get(u8::from(GpsBrickletFunction::GetCoordinatesCallbackPeriod), &payload).await?;
571        Ok(u32::from_le_byte_slice(result.body()))
572    }
573
574    /// Sets the period with which the [`get_status_callback_receiver`] receiver is triggered
575    /// periodically. A value of 0 turns the receiver off.
576    ///
577    /// The [`get_status_callback_receiver`] receiver is only triggered if the status changed since the
578    /// last triggering.
579    pub async fn set_status_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
580        let mut payload = [0; 4];
581        period.write_to_slice(&mut payload[0..4]);
582
583        #[allow(unused_variables)]
584        let result = self.device.set(u8::from(GpsBrickletFunction::SetStatusCallbackPeriod), &payload).await?;
585        Ok(())
586    }
587
588    /// Returns the period as set by [`set_status_callback_period`].
589    pub async fn get_status_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
590        let payload = [0; 0];
591
592        #[allow(unused_variables)]
593        let result = self.device.get(u8::from(GpsBrickletFunction::GetStatusCallbackPeriod), &payload).await?;
594        Ok(u32::from_le_byte_slice(result.body()))
595    }
596
597    /// Sets the period with which the [`get_altitude_callback_receiver`] receiver is triggered
598    /// periodically. A value of 0 turns the receiver off.
599    ///
600    /// The [`get_altitude_callback_receiver`] receiver is only triggered if the altitude changed since
601    /// the last triggering.
602    pub async fn set_altitude_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
603        let mut payload = [0; 4];
604        period.write_to_slice(&mut payload[0..4]);
605
606        #[allow(unused_variables)]
607        let result = self.device.set(u8::from(GpsBrickletFunction::SetAltitudeCallbackPeriod), &payload).await?;
608        Ok(())
609    }
610
611    /// Returns the period as set by [`set_altitude_callback_period`].
612    pub async fn get_altitude_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
613        let payload = [0; 0];
614
615        #[allow(unused_variables)]
616        let result = self.device.get(u8::from(GpsBrickletFunction::GetAltitudeCallbackPeriod), &payload).await?;
617        Ok(u32::from_le_byte_slice(result.body()))
618    }
619
620    /// Sets the period with which the [`get_motion_callback_receiver`] receiver is triggered
621    /// periodically. A value of 0 turns the receiver off.
622    ///
623    /// The [`get_motion_callback_receiver`] receiver is only triggered if the motion changed since the
624    /// last triggering.
625    pub async fn set_motion_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
626        let mut payload = [0; 4];
627        period.write_to_slice(&mut payload[0..4]);
628
629        #[allow(unused_variables)]
630        let result = self.device.set(u8::from(GpsBrickletFunction::SetMotionCallbackPeriod), &payload).await?;
631        Ok(())
632    }
633
634    /// Returns the period as set by [`set_motion_callback_period`].
635    pub async fn get_motion_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
636        let payload = [0; 0];
637
638        #[allow(unused_variables)]
639        let result = self.device.get(u8::from(GpsBrickletFunction::GetMotionCallbackPeriod), &payload).await?;
640        Ok(u32::from_le_byte_slice(result.body()))
641    }
642
643    /// Sets the period with which the [`get_date_time_callback_receiver`] receiver is triggered
644    /// periodically. A value of 0 turns the receiver off.
645    ///
646    /// The [`get_date_time_callback_receiver`] receiver is only triggered if the date or time changed
647    /// since the last triggering.
648    pub async fn set_date_time_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
649        let mut payload = [0; 4];
650        period.write_to_slice(&mut payload[0..4]);
651
652        #[allow(unused_variables)]
653        let result = self.device.set(u8::from(GpsBrickletFunction::SetDateTimeCallbackPeriod), &payload).await?;
654        Ok(())
655    }
656
657    /// Returns the period as set by [`set_date_time_callback_period`].
658    pub async fn get_date_time_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
659        let payload = [0; 0];
660
661        #[allow(unused_variables)]
662        let result = self.device.get(u8::from(GpsBrickletFunction::GetDateTimeCallbackPeriod), &payload).await?;
663        Ok(u32::from_le_byte_slice(result.body()))
664    }
665
666    /// Returns the UID, the UID where the Bricklet is connected to,
667    /// the position, the hardware and firmware version as well as the
668    /// device identifier.
669    ///
670    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
671    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
672    /// position 'z'.
673    ///
674    /// The device identifier numbers can be found [here](device_identifier).
675    /// |device_identifier_constant|
676    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
677        let payload = [0; 0];
678
679        #[allow(unused_variables)]
680        let result = self.device.get(u8::from(GpsBrickletFunction::GetIdentity), &payload).await?;
681        Ok(Identity::from_le_byte_slice(result.body()))
682    }
683}