tinkerforge/bindings/
gps_v2_bricklet.rs

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